Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial structure #1

Merged
merged 32 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8417f51
Initial structure
magik6k Jun 25, 2019
3375a72
RPC server
magik6k Jun 28, 2019
b1cea1b
RPC Client / tests
magik6k Jun 28, 2019
46407e2
rpc: client errors
magik6k Jun 28, 2019
5238872
rpc: Contexts
magik6k Jun 28, 2019
795621e
Node builder structure
magik6k Jun 29, 2019
63627e8
Import libp2p modules
magik6k Jul 1, 2019
0779e7d
Build libp2p node
magik6k Jul 1, 2019
088c1e7
Confgure PNet
magik6k Jul 1, 2019
5736ac1
go fmt
Kubuxu Jul 1, 2019
126fa89
Add golint config
Kubuxu Jul 1, 2019
1716db3
Add gomod tidy check
Kubuxu Jul 2, 2019
7864ec6
Cache modules when checking mod-tidy
Kubuxu Jul 2, 2019
ef871ad
Skip TestCtx
Kubuxu Jul 2, 2019
c078989
Disable codecov comments
Kubuxu Jul 2, 2019
7fdd369
Address review
magik6k Jul 2, 2019
4fcdd4a
Address some lint warnings
magik6k Jul 2, 2019
bed044b
Fix TestCtx
magik6k Jul 2, 2019
4d15bbd
Change linters
Kubuxu Jul 2, 2019
f6450b1
Change executor to circleci
Kubuxu Jul 2, 2019
e3f6012
Fix previous change
Kubuxu Jul 2, 2019
573509b
rpclib: improve errors
magik6k Jul 2, 2019
d3a4a56
Merge branch 'feat/structure' of github.com:filecoin-project/go-lotus…
magik6k Jul 2, 2019
661c7d6
rpclib: Address review
magik6k Jul 2, 2019
0f8f61f
more lint fixes
magik6k Jul 2, 2019
5eb60c7
rpclib: Id -> ID, fix TestCtx
magik6k Jul 2, 2019
7bf2fb5
Use zap for logging
Kubuxu Jul 3, 2019
51fc7af
fixup! Use zap for logging
Kubuxu Jul 3, 2019
2a350c6
Use zap
Kubuxu Jul 3, 2019
217cb24
Move to Warnf
Kubuxu Jul 3, 2019
7ed7af0
Run go mod tidy
Kubuxu Jul 3, 2019
24abfd2
Revert goroutine counter in rpc_client
magik6k Jul 3, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ orbs:
go: gotest/tools@0.0.9


jobs:
mod-tidy-check:
executor: go/circleci-golang
steps:
- go/install-ssh
- checkout
- go/mod-tidy-check

workflows:
version: 2
ci:
jobs:
- go/lint
- go/test:
executor: go/circleci-golang
- mod-tidy-check
21 changes: 21 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
linters:
disable-all: true
enable:
- vet
- gofmt
- misspell
- goconst
- golint
- errcheck
- unconvert
- staticcheck
- varcheck
- structcheck
- deadcode

issues:
exclude-use-default: false

linters-settings:
goconst:
min-occurrences: 6
76 changes: 76 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package api

import (
"context"

"github.com/libp2p/go-libp2p-core/peer"
)

type Version struct {
Version string

// TODO: git commit / os / genesis cid?
}

type API interface {
// chain

// // head

// messages

// // wait
// // send
// // status
// // mpool
// // // ls / show / rm

// dag

// // get block
// // (cli: show / info)

// network

// // peers
// // ping
// // connect

// Struct

// miner

// // create
// // owner
// // power
// // set-price
// // set-perrid

// // UX ?

// wallet

// // import
// // export
// // list
// // (on cli - cmd to list associations)

// dht

// // need ?

// paych

// // todo

// retrieval

// // retrieve piece

// Other

// // ID (on cli - print with other info)

ID(context.Context) (peer.ID, error)
Version(context.Context) (Version, error)
}
12 changes: 12 additions & 0 deletions api/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package client

import (
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/rpclib"
)

func NewRPC(addr string) api.API {
var res api.Struct
rpclib.NewClient(addr, "Filecoin", &res.Internal)
return &res
}
24 changes: 24 additions & 0 deletions api/struct.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package api

import (
"context"

"github.com/libp2p/go-libp2p-core/peer"
)

type Struct struct {
Internal struct {
magik6k marked this conversation as resolved.
Show resolved Hide resolved
ID func(context.Context) (peer.ID, error)
Version func(context.Context) (Version, error)
}
}

func (c *Struct) ID(ctx context.Context) (peer.ID, error) {
return c.Internal.ID(ctx)
}

func (c *Struct) Version(ctx context.Context) (Version, error) {
return c.Internal.Version(ctx)
}

var _ API = &Struct{}
35 changes: 35 additions & 0 deletions api/test/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package test

import (
"context"
"testing"

"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/build"
)

type NodeBuilder func() api.API
magik6k marked this conversation as resolved.
Show resolved Hide resolved
type testSuite struct {
makeNode NodeBuilder
}

func TestApis(t *testing.T, nb NodeBuilder) {
ts := testSuite{
makeNode: nb,
}

t.Run("version", ts.testVersion)
}

func (ts *testSuite) testVersion(t *testing.T) {
ctx := context.Background()
fc := ts.makeNode()

v, err := fc.Version(ctx)
if err != nil {
t.Fatal(err)
}
if v.Version != build.Version {
t.Error("Version didn't work properly")
}
}
3 changes: 3 additions & 0 deletions build/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package build

const Version = "0.0.0"
9 changes: 9 additions & 0 deletions cli/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cli

import (
"gopkg.in/urfave/cli.v2"
)

var Commands = []*cli.Command{
versionCmd,
}
16 changes: 16 additions & 0 deletions cli/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cli

import (
"gopkg.in/urfave/cli.v2"
)

var versionCmd = &cli.Command{
Name: "version",
Usage: "Print version",
Action: func(context *cli.Context) error {
// TODO: print more useful things

cli.VersionPrinter(context)
return nil
},
}
31 changes: 31 additions & 0 deletions cmd/lotus/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"log"
"os"

"gopkg.in/urfave/cli.v2"

"github.com/filecoin-project/go-lotus/build"
lcli "github.com/filecoin-project/go-lotus/cli"
"github.com/filecoin-project/go-lotus/daemon"
)

func main() {
local := []*cli.Command{
daemon.Cmd,
}

app := &cli.App{
Name: "lotus",
Usage: "Filecoin decentralized storage network client",
Version: build.Version,

Commands: append(local, lcli.Commands...),
}

if err := app.Run(os.Args); err != nil {
log.Println(err)
return
}
}
24 changes: 24 additions & 0 deletions daemon/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package daemon

import (
goctx "context"
magik6k marked this conversation as resolved.
Show resolved Hide resolved

"gopkg.in/urfave/cli.v2"

"github.com/filecoin-project/go-lotus/node"
)

var Cmd = &cli.Command{
Name: "daemon",
Usage: "Start a lotus daemon process",
Action: func(context *cli.Context) error {
ctx := goctx.Background()

api, err := node.New(ctx)
if err != nil {
return err
}

return serveRPC(api)
},
}
15 changes: 15 additions & 0 deletions daemon/rpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package daemon

import (
"net/http"

"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/rpclib"
)

func serveRPC(api api.API) error {
rpcServer := rpclib.NewServer()
rpcServer.Register("Filecoin", api)
http.Handle("/rpc/v0", rpcServer)
return http.ListenAndServe(":1234", http.DefaultServeMux)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have the http muxer in DI. We will do it when the time comes.

}
35 changes: 35 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module github.com/filecoin-project/go-lotus

go 1.12

require (
github.com/ipfs/go-datastore v0.0.5
github.com/ipfs/go-ipfs-routing v0.1.0
github.com/ipfs/go-log v0.0.1
github.com/libp2p/go-libp2p v0.2.0
github.com/libp2p/go-libp2p-circuit v0.1.0
github.com/libp2p/go-libp2p-connmgr v0.1.0
github.com/libp2p/go-libp2p-core v0.0.6
github.com/libp2p/go-libp2p-discovery v0.1.0
github.com/libp2p/go-libp2p-kad-dht v0.1.1
github.com/libp2p/go-libp2p-mplex v0.2.1
github.com/libp2p/go-libp2p-peerstore v0.1.1
github.com/libp2p/go-libp2p-pnet v0.1.0
github.com/libp2p/go-libp2p-pubsub v0.1.0
github.com/libp2p/go-libp2p-quic-transport v0.1.1
github.com/libp2p/go-libp2p-record v0.1.0
github.com/libp2p/go-libp2p-routing-helpers v0.1.0
github.com/libp2p/go-libp2p-secio v0.1.0
github.com/libp2p/go-libp2p-tls v0.1.0
github.com/libp2p/go-libp2p-yamux v0.2.1
github.com/libp2p/go-maddr-filter v0.0.4
github.com/multiformats/go-multiaddr v0.0.4
github.com/multiformats/go-multihash v0.0.5
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7
go.uber.org/atomic v1.4.0 // indirect
go.uber.org/dig v1.7.0 // indirect
go.uber.org/fx v1.9.0
go.uber.org/goleak v0.10.0 // indirect
go.uber.org/multierr v1.1.0 // indirect
gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8
)
Loading