From 8417f515a1ccc5e9fbca393294c213ff70c43261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 25 Jun 2019 13:42:17 +0200 Subject: [PATCH 01/31] Initial structure License: MIT Signed-off-by: Jakub Sztandera --- api/api.go | 69 +++++++++++++++++++++++++++++++++++++++ api/client/client.go | 9 +++++ build/version.go | 3 ++ cli/cmd.go | 9 +++++ cli/version.go | 16 +++++++++ cmd/lotus/main.go | 31 ++++++++++++++++++ daemon/builder.go | 3 ++ daemon/cmd.go | 13 ++++++++ daemon/modules/core.go | 1 + daemon/modules/libp2p.go | 1 + daemon/modules/testing.go | 3 ++ daemon/rpc.go | 31 ++++++++++++++++++ go.mod | 12 +++++++ go.sum | 12 +++++++ 14 files changed, 213 insertions(+) create mode 100644 api/api.go create mode 100644 api/client/client.go create mode 100644 build/version.go create mode 100644 cli/cmd.go create mode 100644 cli/version.go create mode 100644 cmd/lotus/main.go create mode 100644 daemon/builder.go create mode 100644 daemon/cmd.go create mode 100644 daemon/modules/core.go create mode 100644 daemon/modules/libp2p.go create mode 100644 daemon/modules/testing.go create mode 100644 daemon/rpc.go create mode 100644 go.mod create mode 100644 go.sum diff --git a/api/api.go b/api/api.go new file mode 100644 index 000000000..990ba78c6 --- /dev/null +++ b/api/api.go @@ -0,0 +1,69 @@ +package api + +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 + + // client + + // 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) + + Version() Version +} diff --git a/api/client/client.go b/api/client/client.go new file mode 100644 index 000000000..c86373513 --- /dev/null +++ b/api/client/client.go @@ -0,0 +1,9 @@ +package client + +import ( + "github.com/filecoin-project/go-lotus/api" +) + +func NewRPC(addr string) api.API { + return nil // TODO +} diff --git a/build/version.go b/build/version.go new file mode 100644 index 000000000..35b4aab6a --- /dev/null +++ b/build/version.go @@ -0,0 +1,3 @@ +package build + +const Version = "0.0.0" diff --git a/cli/cmd.go b/cli/cmd.go new file mode 100644 index 000000000..e9bb9133b --- /dev/null +++ b/cli/cmd.go @@ -0,0 +1,9 @@ +package cli + +import ( + "gopkg.in/urfave/cli.v2" +) + +var Commands = []*cli.Command{ + versionCmd, +} \ No newline at end of file diff --git a/cli/version.go b/cli/version.go new file mode 100644 index 000000000..cb3f3c0c8 --- /dev/null +++ b/cli/version.go @@ -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 + }, +} diff --git a/cmd/lotus/main.go b/cmd/lotus/main.go new file mode 100644 index 000000000..b8df0350f --- /dev/null +++ b/cmd/lotus/main.go @@ -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 + } +} diff --git a/daemon/builder.go b/daemon/builder.go new file mode 100644 index 000000000..46fa88c82 --- /dev/null +++ b/daemon/builder.go @@ -0,0 +1,3 @@ +package daemon + + diff --git a/daemon/cmd.go b/daemon/cmd.go new file mode 100644 index 000000000..99c7907a1 --- /dev/null +++ b/daemon/cmd.go @@ -0,0 +1,13 @@ +package daemon + +import ( + "gopkg.in/urfave/cli.v2" +) + +var Cmd = &cli.Command{ + Name: "daemon", + Usage: "Start a lotus daemon process", + Action: func(context *cli.Context) error { + return serveRPC() + }, +} diff --git a/daemon/modules/core.go b/daemon/modules/core.go new file mode 100644 index 000000000..11174d7d4 --- /dev/null +++ b/daemon/modules/core.go @@ -0,0 +1 @@ +package modules diff --git a/daemon/modules/libp2p.go b/daemon/modules/libp2p.go new file mode 100644 index 000000000..11174d7d4 --- /dev/null +++ b/daemon/modules/libp2p.go @@ -0,0 +1 @@ +package modules diff --git a/daemon/modules/testing.go b/daemon/modules/testing.go new file mode 100644 index 000000000..324391f6d --- /dev/null +++ b/daemon/modules/testing.go @@ -0,0 +1,3 @@ +package modules + + diff --git a/daemon/rpc.go b/daemon/rpc.go new file mode 100644 index 000000000..c666f884d --- /dev/null +++ b/daemon/rpc.go @@ -0,0 +1,31 @@ +package daemon + +import ( + "net/http" + + "github.com/gorilla/rpc/v2" + "github.com/gorilla/rpc/v2/json" + + "github.com/filecoin-project/go-lotus/build" +) + +type Filecoin struct {} + +func (*Filecoin) ServerVersion(r *http.Request, _ *struct{}, out *string) error { + *out = build.Version + return nil +} + +func serveRPC() error { + fc := new(Filecoin) + + rpcServer := rpc.NewServer() + rpcServer.RegisterCodec(json.NewCodec(), "application/json") + if err := rpcServer.RegisterService(fc, ""); err != nil { + return err + } + + http.Handle("/rpc/v0", rpcServer) + return http.ListenAndServe(":1234", http.DefaultServeMux) +} + diff --git a/go.mod b/go.mod new file mode 100644 index 000000000..9ed8b5396 --- /dev/null +++ b/go.mod @@ -0,0 +1,12 @@ +module github.com/filecoin-project/go-lotus + +go 1.12 + +require ( + github.com/gorilla/rpc v1.2.0 + go.uber.org/atomic v1.4.0 // indirect + go.uber.org/dig v1.7.0 // indirect + go.uber.org/fx v1.9.0 // indirect + go.uber.org/multierr v1.1.0 // indirect + gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8 +) diff --git a/go.sum b/go.sum new file mode 100644 index 000000000..940a82af0 --- /dev/null +++ b/go.sum @@ -0,0 +1,12 @@ +github.com/gorilla/rpc v1.2.0 h1:WvvdC2lNeT1SP32zrIce5l0ECBfbAlmrmSBsuc57wfk= +github.com/gorilla/rpc v1.2.0/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ= +go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/dig v1.7.0 h1:E5/L92iQTNJTjfgJF2KgU+/JpMaiuvK2DHLBj0+kSZk= +go.uber.org/dig v1.7.0/go.mod h1:z+dSd2TP9Usi48jL8M3v63iSBVkiwtVyMKxMZYYauPg= +go.uber.org/fx v1.9.0 h1:7OAz8ucp35AU8eydejpYG7QrbE8rLKzGhHbZlJi5LYY= +go.uber.org/fx v1.9.0/go.mod h1:mFdUyAUuJ3w4jAckiKSKbldsxy1ojpAMJ+dVZg5Y0Aw= +go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8 h1:Ggy3mWN4l3PUFPfSG0YB3n5fVYggzysUmiUQ89SnX6Y= +gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8/go.mod h1:cKXr3E0k4aosgycml1b5z33BVV6hai1Kh7uDgFOkbcs= From 3375a72aea6f2316a585c2c0bba18b74caf73fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 28 Jun 2019 11:03:28 +0200 Subject: [PATCH 02/31] RPC server License: MIT Signed-off-by: Jakub Sztandera --- cli/cmd.go | 2 +- cli/version.go | 2 +- cmd/lotus/main.go | 4 +- daemon/builder.go | 2 - daemon/cmd.go | 2 +- daemon/modules/testing.go | 2 - daemon/rpc.go | 22 +++-- rpclib/rpc.go | 164 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 178 insertions(+), 22 deletions(-) create mode 100644 rpclib/rpc.go diff --git a/cli/cmd.go b/cli/cmd.go index e9bb9133b..f701a4401 100644 --- a/cli/cmd.go +++ b/cli/cmd.go @@ -6,4 +6,4 @@ import ( var Commands = []*cli.Command{ versionCmd, -} \ No newline at end of file +} diff --git a/cli/version.go b/cli/version.go index cb3f3c0c8..57d101d83 100644 --- a/cli/version.go +++ b/cli/version.go @@ -5,7 +5,7 @@ import ( ) var versionCmd = &cli.Command{ - Name: "version", + Name: "version", Usage: "Print version", Action: func(context *cli.Context) error { // TODO: print more useful things diff --git a/cmd/lotus/main.go b/cmd/lotus/main.go index b8df0350f..c8e168c11 100644 --- a/cmd/lotus/main.go +++ b/cmd/lotus/main.go @@ -17,8 +17,8 @@ func main() { } app := &cli.App{ - Name: "lotus", - Usage: "Filecoin decentralized storage network client", + Name: "lotus", + Usage: "Filecoin decentralized storage network client", Version: build.Version, Commands: append(local, lcli.Commands...), diff --git a/daemon/builder.go b/daemon/builder.go index 46fa88c82..9d3072094 100644 --- a/daemon/builder.go +++ b/daemon/builder.go @@ -1,3 +1 @@ package daemon - - diff --git a/daemon/cmd.go b/daemon/cmd.go index 99c7907a1..aa62f8312 100644 --- a/daemon/cmd.go +++ b/daemon/cmd.go @@ -5,7 +5,7 @@ import ( ) var Cmd = &cli.Command{ - Name: "daemon", + Name: "daemon", Usage: "Start a lotus daemon process", Action: func(context *cli.Context) error { return serveRPC() diff --git a/daemon/modules/testing.go b/daemon/modules/testing.go index 324391f6d..11174d7d4 100644 --- a/daemon/modules/testing.go +++ b/daemon/modules/testing.go @@ -1,3 +1 @@ package modules - - diff --git a/daemon/rpc.go b/daemon/rpc.go index c666f884d..3dfdbb749 100644 --- a/daemon/rpc.go +++ b/daemon/rpc.go @@ -1,31 +1,27 @@ package daemon import ( + "fmt" "net/http" - "github.com/gorilla/rpc/v2" - "github.com/gorilla/rpc/v2/json" - "github.com/filecoin-project/go-lotus/build" + "github.com/filecoin-project/go-lotus/rpclib" ) -type Filecoin struct {} +type Filecoin struct{} -func (*Filecoin) ServerVersion(r *http.Request, _ *struct{}, out *string) error { - *out = build.Version - return nil +func (*Filecoin) ServerVersion(in int) (string, error) { + fmt.Println(in) + return build.Version, nil } func serveRPC() error { fc := new(Filecoin) - rpcServer := rpc.NewServer() - rpcServer.RegisterCodec(json.NewCodec(), "application/json") - if err := rpcServer.RegisterService(fc, ""); err != nil { - return err - } + rpcServer := rpclib.NewServer() + + rpcServer.Register(fc) http.Handle("/rpc/v0", rpcServer) return http.ListenAndServe(":1234", http.DefaultServeMux) } - diff --git a/rpclib/rpc.go b/rpclib/rpc.go new file mode 100644 index 000000000..c55ec8386 --- /dev/null +++ b/rpclib/rpc.go @@ -0,0 +1,164 @@ +package rpclib + +import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + "os" + "reflect" +) + +type rpcHandler struct { + paramReceivers []reflect.Type + nParams int + + receiver reflect.Value + handlerFunc reflect.Value + + errOut int + valOut int +} + +type RPCServer struct { + methods map[string]rpcHandler +} + +func NewServer() *RPCServer { + return &RPCServer{ + methods: map[string]rpcHandler{}, + } +} + +type param struct { + data []byte +} + +func (p *param) UnmarshalJSON(raw []byte) error { + p.data = make([]byte, len(raw)) + copy(p.data, raw) + return nil +} + +type request struct { + Jsonrpc string `json:"jsonrpc"` + Id *int `json:"id,omitempty"` + Method string `json:"method"` + Params []param `json:"params"` +} + +type respError struct { + Code int `json:"code"` + Message string `json:"message"` +} + +type response struct { + Jsonrpc string `json:"jsonrpc"` + Result interface{} `json:"result"` + Id int `json:"id"` + Error *respError `json:"error,omitempty"` +} + +func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { + var req request + if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + w.WriteHeader(500) + return + } + + handler, ok := s.methods[req.Method] + if !ok { + w.WriteHeader(500) + return + } + + callParams := make([]reflect.Value, 1+handler.nParams) + callParams[0] = handler.receiver + for i := 0; i < handler.nParams; i++ { + rp := reflect.New(handler.paramReceivers[i]) + if err := json.NewDecoder(bytes.NewReader(req.Params[i].data)).Decode(rp.Interface()); err != nil { + w.WriteHeader(500) + fmt.Println(err) + return + } + + callParams[i+1] = reflect.ValueOf(rp.Elem().Interface()) + } + + callResult := handler.handlerFunc.Call(callParams) + if req.Id == nil { + return // notification + } + + resp := response{ + Jsonrpc: "2.0", + Id: *req.Id, + } + + if handler.errOut != -1 { + err := callResult[handler.errOut].Interface() + if err != nil { + resp.Error = &respError{ + Code: 1, + Message: err.(error).Error(), + } + } + } + if handler.valOut != -1 { + resp.Result = callResult[handler.valOut].Interface() + } + + json.NewEncoder(os.Stderr).Encode(resp) +} + +func (s *RPCServer) Register(r interface{}) { + val := reflect.ValueOf(r) + //TODO: expect ptr + + name := val.Type().Elem().Name() + + for i := 0; i < val.NumMethod(); i++ { + method := val.Type().Method(i) + + fmt.Println(name + "." + method.Name) + + funcType := method.Func.Type() + ins := funcType.NumIn() - 1 + recvs := make([]reflect.Type, ins) + for i := 0; i < ins; i++ { + recvs[i] = method.Type.In(i + 1) + } + + errOut := -1 + valOut := -1 + + switch funcType.NumOut() { + case 0: + case 1: + if funcType.Out(0) == reflect.TypeOf(new(error)).Elem() { + errOut = 0 + } else { + valOut = 0 + } + case 2: + valOut = 0 + errOut = 1 + if funcType.Out(1) != reflect.TypeOf(new(error)).Elem() { + panic("expected error as second return value") + } + default: + panic("too many error values") + } + + s.methods[name+"."+method.Name] = rpcHandler{ + paramReceivers: recvs, + nParams: ins, + + handlerFunc: method.Func, + receiver: val, + + errOut: errOut, + valOut: valOut, + } + } +} From b1cea1b3cab0e18f547f1386507b595995537c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 28 Jun 2019 15:49:34 +0200 Subject: [PATCH 03/31] RPC Client / tests License: MIT Signed-off-by: Jakub Sztandera --- daemon/rpc.go | 2 - rpclib/rpcClient.go | 119 ++++++++++++++++++++++++++ rpclib/{rpc.go => rpcServer.go} | 72 ++++++++++------ rpclib/rpc_test.go | 145 ++++++++++++++++++++++++++++++++ 4 files changed, 310 insertions(+), 28 deletions(-) create mode 100644 rpclib/rpcClient.go rename rpclib/{rpc.go => rpcServer.go} (73%) create mode 100644 rpclib/rpc_test.go diff --git a/daemon/rpc.go b/daemon/rpc.go index 3dfdbb749..ad707b632 100644 --- a/daemon/rpc.go +++ b/daemon/rpc.go @@ -19,9 +19,7 @@ func serveRPC() error { fc := new(Filecoin) rpcServer := rpclib.NewServer() - rpcServer.Register(fc) - http.Handle("/rpc/v0", rpcServer) return http.ListenAndServe(":1234", http.DefaultServeMux) } diff --git a/rpclib/rpcClient.go b/rpclib/rpcClient.go new file mode 100644 index 000000000..46d61b496 --- /dev/null +++ b/rpclib/rpcClient.go @@ -0,0 +1,119 @@ +package rpclib + +import ( + "bytes" + "encoding/json" + "errors" + "net/http" + "reflect" + "sync/atomic" +) + +type result reflect.Value + +func (r *result) UnmarshalJSON(raw []byte) error { + return json.Unmarshal(raw, reflect.Value(*r).Interface()) +} + +type clientResponse struct { + Jsonrpc string `json:"jsonrpc"` + Result result `json:"result"` + Id int64 `json:"id"` + Error *respError `json:"error,omitempty"` +} + +func NewClient(addr string, namespace string, handler interface{}) { + htyp := reflect.TypeOf(handler) + if htyp.Kind() != reflect.Ptr { + panic("expected handler to be a pointer") + } + typ := htyp.Elem() + if typ.Kind() != reflect.Struct { + panic("handler should be a struct") + } + + val := reflect.ValueOf(handler) + + var idCtr int64 + + for i := 0; i < typ.NumField(); i++ { + f := typ.Field(i) + ftyp := f.Type + if ftyp.Kind() != reflect.Func { + panic("handler field not a func") + } + + valOut, errOut, nout := processFuncOut(ftyp) + + processResponse := func(resp clientResponse) []reflect.Value { + out := make([]reflect.Value, nout) + + if valOut != -1 { + out[valOut] = reflect.Value(resp.Result).Elem() + } + if errOut != -1 { + out[errOut] = reflect.New(reflect.TypeOf(new(error)).Elem()).Elem() + if resp.Error != nil { + out[errOut].Set(reflect.ValueOf(errors.New(resp.Error.Message))) + } + } + + return out + } + + fn := reflect.MakeFunc(ftyp, func(args []reflect.Value) (results []reflect.Value) { + id := atomic.AddInt64(&idCtr, 1) + params := make([]param, len(args)) + for i, arg := range args { + params[i] = param{ + v: arg, + } + } + + req := request{ + Jsonrpc: "2.0", + Id: &id, + Method: namespace + "." + f.Name, + Params: params, + } + + b, err := json.Marshal(&req) + if err != nil { + // TODO: try returning an error if the method has one + panic(err) + } + + httpResp, err := http.Post(addr, "application/json", bytes.NewReader(b)) + if err != nil { + // TODO: try returning an error if the method has one + panic(err) + } + defer httpResp.Body.Close() + + if httpResp.StatusCode != 200 { + // TODO: try returning an error if the method has one + // TODO: actually parse response, it haz right errors + panic("non 200 code") + } + + var resp clientResponse + if valOut != -1 { + resp.Result = result(reflect.New(ftyp.Out(valOut))) + } + + if err := json.NewDecoder(httpResp.Body).Decode(&resp); err != nil { + // TODO: try returning an error if the method has one + panic(err) + } + + if resp.Id != *req.Id { + // TODO: try returning an error if the method has one + panic("request and response id didn't match") + } + + return processResponse(resp) + }) + + val.Elem().Field(i).Set(fn) + } +} diff --git a/rpclib/rpc.go b/rpclib/rpcServer.go similarity index 73% rename from rpclib/rpc.go rename to rpclib/rpcServer.go index c55ec8386..fece92f09 100644 --- a/rpclib/rpc.go +++ b/rpclib/rpcServer.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - "os" "reflect" ) @@ -31,7 +30,9 @@ func NewServer() *RPCServer { } type param struct { - data []byte + data []byte // from unmarshal + + v reflect.Value // to marshal } func (p *param) UnmarshalJSON(raw []byte) error { @@ -40,9 +41,13 @@ func (p *param) UnmarshalJSON(raw []byte) error { return nil } +func (p *param) MarshalJSON() ([]byte, error) { + return json.Marshal(p.v.Interface()) +} + type request struct { Jsonrpc string `json:"jsonrpc"` - Id *int `json:"id,omitempty"` + Id *int64 `json:"id,omitempty"` Method string `json:"method"` Params []param `json:"params"` } @@ -54,8 +59,8 @@ type respError struct { type response struct { Jsonrpc string `json:"jsonrpc"` - Result interface{} `json:"result"` - Id int `json:"id"` + Result interface{} `json:"result,omitempty"` + Id int64 `json:"id"` Error *respError `json:"error,omitempty"` } @@ -72,6 +77,11 @@ func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } + if len(req.Params) != handler.nParams { + w.WriteHeader(500) + return + } + callParams := make([]reflect.Value, 1+handler.nParams) callParams[0] = handler.receiver for i := 0; i < handler.nParams; i++ { @@ -108,7 +118,10 @@ func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { resp.Result = callResult[handler.valOut].Interface() } - json.NewEncoder(os.Stderr).Encode(resp) + if err := json.NewEncoder(w).Encode(resp); err != nil { + w.WriteHeader(500) + return + } } func (s *RPCServer) Register(r interface{}) { @@ -129,26 +142,7 @@ func (s *RPCServer) Register(r interface{}) { recvs[i] = method.Type.In(i + 1) } - errOut := -1 - valOut := -1 - - switch funcType.NumOut() { - case 0: - case 1: - if funcType.Out(0) == reflect.TypeOf(new(error)).Elem() { - errOut = 0 - } else { - valOut = 0 - } - case 2: - valOut = 0 - errOut = 1 - if funcType.Out(1) != reflect.TypeOf(new(error)).Elem() { - panic("expected error as second return value") - } - default: - panic("too many error values") - } + valOut, errOut, _ := processFuncOut(funcType) s.methods[name+"."+method.Name] = rpcHandler{ paramReceivers: recvs, @@ -162,3 +156,29 @@ func (s *RPCServer) Register(r interface{}) { } } } + +func processFuncOut(funcType reflect.Type) (valOut int, errOut int, n int) { + errOut = -1 + valOut = -1 + n = funcType.NumOut() + + switch n { + case 0: + case 1: + if funcType.Out(0) == reflect.TypeOf(new(error)).Elem() { + errOut = 0 + } else { + valOut = 0 + } + case 2: + valOut = 0 + errOut = 1 + if funcType.Out(1) != reflect.TypeOf(new(error)).Elem() { + panic("expected error as second return value") + } + default: + panic("too many error values") + } + + return +} diff --git a/rpclib/rpc_test.go b/rpclib/rpc_test.go new file mode 100644 index 000000000..fd387cf4a --- /dev/null +++ b/rpclib/rpc_test.go @@ -0,0 +1,145 @@ +package rpclib + +import ( + "errors" + "net/http/httptest" + "strconv" + "testing" +) + +type SimpleServerHandler struct { + n int +} + +type TestType struct { + S string + I int +} + +type TestOut struct { + TestType + Ok bool +} + +func (h *SimpleServerHandler) Add(in int) error { + if in == -3546 { + return errors.New("test") + } + + h.n += in + + return nil +} + +func (h *SimpleServerHandler) AddGet(in int) int { + h.n += in + return h.n +} + +func (h *SimpleServerHandler) StringMatch(t TestType, i2 int64) (out TestOut, err error) { + if strconv.FormatInt(i2, 10) == t.S { + out.Ok = true + } + if i2 != int64(t.I) { + return TestOut{}, errors.New(":(") + } + out.I = t.I + out.S = t.S + return +} + +func TestRPC(t *testing.T) { + // setup server + + serverHandler := &SimpleServerHandler{} + + rpcServer := NewServer() + rpcServer.Register(serverHandler) + + // httptest stuff + testServ := httptest.NewServer(rpcServer) + defer testServ.Close() + + // setup client + + var client struct { + Add func(int) error + AddGet func(int) int + StringMatch func(t TestType, i2 int64) (out TestOut, err error) + } + NewClient(testServ.URL, "SimpleServerHandler", &client) + + // Add(int) error + + if err := client.Add(2); err != nil { + t.Fatal(err) + } + + if serverHandler.n != 2 { + t.Error("expected 2") + } + + err := client.Add(-3546) + if err == nil { + t.Fatal("expected error") + } + if err.Error() != "test" { + t.Fatal("wrong error") + } + + // AddGet(int) int + + n := client.AddGet(3) + if n != 5 { + t.Error("wrong n") + } + + if serverHandler.n != 5 { + t.Error("expected 5") + } + + // StringMatch + + o, err := client.StringMatch(TestType{S: "0"}, 0) + if err != nil { + t.Error(err) + } + if o.S != "0" || o.I != 0 { + t.Error("wrong result") + } + + _, err = client.StringMatch(TestType{S: "5"}, 5) + if err == nil || err.Error() != ":(" { + t.Error("wrong err") + } + + o, err = client.StringMatch(TestType{S: "8", I: 8}, 8) + if err != nil { + t.Error(err) + } + if o.S != "8" || o.I != 8 { + t.Error("wrong result") + } + + // Invalid client handlers + + var noret struct { + Add func(int) + } + NewClient(testServ.URL, "SimpleServerHandler", &noret) + + // this one should actually work + noret.Add(4) + if serverHandler.n != 9 { + t.Error("expected 9") + } + + var noparam struct { + Add func() + } + NewClient(testServ.URL, "SimpleServerHandler", &noparam) + + // shouldn't panic + noparam.Add() + +} From 46407e2033476b29ed9d5fa0464af3163a3b08e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 28 Jun 2019 16:05:10 +0200 Subject: [PATCH 04/31] rpc: client errors License: MIT Signed-off-by: Jakub Sztandera --- rpclib/rpcClient.go | 44 +++++++++++++++++++++++++++++++++----------- rpclib/rpc_test.go | 19 +++++++++++++++++++ 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/rpclib/rpcClient.go b/rpclib/rpcClient.go index 46d61b496..9b416cfc7 100644 --- a/rpclib/rpcClient.go +++ b/rpclib/rpcClient.go @@ -4,11 +4,24 @@ import ( "bytes" "encoding/json" "errors" + "fmt" "net/http" "reflect" "sync/atomic" ) +type ErrClient struct { + err error +} + +func (e *ErrClient) Error() string { + return fmt.Sprintf("RPC client error: %s", e.err) +} + +func (e *ErrClient) Unwrap(err error) error { + return e.err +} + type result reflect.Value func (r *result) UnmarshalJSON(raw []byte) error { @@ -61,6 +74,20 @@ func NewClient(addr string, namespace string, handler interface{}) { return out } + processError := func(err error) []reflect.Value{ + out := make([]reflect.Value, nout) + + if valOut != -1 { + out[valOut] = reflect.New(ftyp.Out(valOut)).Elem() + } + if errOut != -1 { + out[errOut] = reflect.New(reflect.TypeOf(new(error)).Elem()).Elem() + out[errOut].Set(reflect.ValueOf(&ErrClient{err})) + } + + return out + } + fn := reflect.MakeFunc(ftyp, func(args []reflect.Value) (results []reflect.Value) { id := atomic.AddInt64(&idCtr, 1) params := make([]param, len(args)) @@ -79,21 +106,18 @@ func NewClient(addr string, namespace string, handler interface{}) { b, err := json.Marshal(&req) if err != nil { - // TODO: try returning an error if the method has one - panic(err) + return processError(err) } httpResp, err := http.Post(addr, "application/json", bytes.NewReader(b)) if err != nil { - // TODO: try returning an error if the method has one - panic(err) + return processError(err) } defer httpResp.Body.Close() + // TODO: check error codes in spec if httpResp.StatusCode != 200 { - // TODO: try returning an error if the method has one - // TODO: actually parse response, it haz right errors - panic("non 200 code") + return processError(errors.New("non 200 response code")) } var resp clientResponse @@ -102,13 +126,11 @@ func NewClient(addr string, namespace string, handler interface{}) { } if err := json.NewDecoder(httpResp.Body).Decode(&resp); err != nil { - // TODO: try returning an error if the method has one - panic(err) + return processError(err) } if resp.Id != *req.Id { - // TODO: try returning an error if the method has one - panic("request and response id didn't match") + return processError(errors.New("request and response id didn't match")) } return processResponse(resp) diff --git a/rpclib/rpc_test.go b/rpclib/rpc_test.go index fd387cf4a..6f8a9d143 100644 --- a/rpclib/rpc_test.go +++ b/rpclib/rpc_test.go @@ -142,4 +142,23 @@ func TestRPC(t *testing.T) { // shouldn't panic noparam.Add() + var erronly struct { + Add func() error + } + NewClient(testServ.URL, "SimpleServerHandler", &erronly) + + err = erronly.Add() + if err == nil || err.Error() != "RPC client error: non 200 response code" { + t.Error("wrong error") + } + + var wrongtype struct { + Add func(string) error + } + NewClient(testServ.URL, "SimpleServerHandler", &wrongtype) + + err = wrongtype.Add("not an int") + if err == nil || err.Error() != "RPC client error: non 200 response code" { + t.Error("wrong error") + } } From 5238872c02c86eeba71bb850c204bf0b89a9c1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 28 Jun 2019 16:53:01 +0200 Subject: [PATCH 05/31] rpc: Contexts License: MIT Signed-off-by: Jakub Sztandera --- rpclib/rpcClient.go | 34 +++++++++++++++++++++---- rpclib/rpcServer.go | 27 ++++++++++++++------ rpclib/rpc_test.go | 62 +++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 108 insertions(+), 15 deletions(-) diff --git a/rpclib/rpcClient.go b/rpclib/rpcClient.go index 9b416cfc7..5607863b0 100644 --- a/rpclib/rpcClient.go +++ b/rpclib/rpcClient.go @@ -2,6 +2,7 @@ package rpclib import ( "bytes" + "context" "encoding/json" "errors" "fmt" @@ -10,6 +11,11 @@ import ( "sync/atomic" ) +var ( + errorType = reflect.TypeOf(new(error)).Elem() + contextType = reflect.TypeOf(new(context.Context)).Elem() +) + type ErrClient struct { err error } @@ -65,7 +71,7 @@ func NewClient(addr string, namespace string, handler interface{}) { out[valOut] = reflect.Value(resp.Result).Elem() } if errOut != -1 { - out[errOut] = reflect.New(reflect.TypeOf(new(error)).Elem()).Elem() + out[errOut] = reflect.New(errorType).Elem() if resp.Error != nil { out[errOut].Set(reflect.ValueOf(errors.New(resp.Error.Message))) } @@ -81,17 +87,22 @@ func NewClient(addr string, namespace string, handler interface{}) { out[valOut] = reflect.New(ftyp.Out(valOut)).Elem() } if errOut != -1 { - out[errOut] = reflect.New(reflect.TypeOf(new(error)).Elem()).Elem() + out[errOut] = reflect.New(errorType).Elem() out[errOut].Set(reflect.ValueOf(&ErrClient{err})) } return out } + hasCtx := 0 + if ftyp.NumIn() > 0 && ftyp.In(0) == contextType { + hasCtx = 1 + } + fn := reflect.MakeFunc(ftyp, func(args []reflect.Value) (results []reflect.Value) { id := atomic.AddInt64(&idCtr, 1) - params := make([]param, len(args)) - for i, arg := range args { + params := make([]param, len(args) - hasCtx) + for i, arg := range args[hasCtx:] { params[i] = param{ v: arg, } @@ -109,12 +120,25 @@ func NewClient(addr string, namespace string, handler interface{}) { return processError(err) } - httpResp, err := http.Post(addr, "application/json", bytes.NewReader(b)) + // prepare / execute http request + + hreq, err := http.NewRequest("POST", addr, bytes.NewReader(b)) + if err != nil { + return processError(err) + } + if hasCtx == 1 { + hreq = hreq.WithContext(args[0].Interface().(context.Context)) + } + hreq.Header.Set("Content-Type", "application/json") + + httpResp, err := http.DefaultClient.Do(hreq) if err != nil { return processError(err) } defer httpResp.Body.Close() + // process response + // TODO: check error codes in spec if httpResp.StatusCode != 200 { return processError(errors.New("non 200 response code")) diff --git a/rpclib/rpcServer.go b/rpclib/rpcServer.go index fece92f09..1237497ee 100644 --- a/rpclib/rpcServer.go +++ b/rpclib/rpcServer.go @@ -15,6 +15,8 @@ type rpcHandler struct { receiver reflect.Value handlerFunc reflect.Value + hasCtx int + errOut int valOut int } @@ -82,8 +84,12 @@ func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - callParams := make([]reflect.Value, 1+handler.nParams) + callParams := make([]reflect.Value, 1+handler.hasCtx+handler.nParams) callParams[0] = handler.receiver + if handler.hasCtx == 1 { + callParams[1] = reflect.ValueOf(r.Context()) + } + for i := 0; i < handler.nParams; i++ { rp := reflect.New(handler.paramReceivers[i]) if err := json.NewDecoder(bytes.NewReader(req.Params[i].data)).Decode(rp.Interface()); err != nil { @@ -92,7 +98,7 @@ func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - callParams[i+1] = reflect.ValueOf(rp.Elem().Interface()) + callParams[i+1+handler.hasCtx] = reflect.ValueOf(rp.Elem().Interface()) } callResult := handler.handlerFunc.Call(callParams) @@ -133,13 +139,16 @@ func (s *RPCServer) Register(r interface{}) { for i := 0; i < val.NumMethod(); i++ { method := val.Type().Method(i) - fmt.Println(name + "." + method.Name) - funcType := method.Func.Type() - ins := funcType.NumIn() - 1 + hasCtx := 0 + if funcType.NumIn() >= 2 && funcType.In(1) == contextType { + hasCtx = 1 + } + + ins := funcType.NumIn() - 1 - hasCtx recvs := make([]reflect.Type, ins) for i := 0; i < ins; i++ { - recvs[i] = method.Type.In(i + 1) + recvs[i] = method.Type.In(i + 1 + hasCtx) } valOut, errOut, _ := processFuncOut(funcType) @@ -151,6 +160,8 @@ func (s *RPCServer) Register(r interface{}) { handlerFunc: method.Func, receiver: val, + hasCtx: hasCtx, + errOut: errOut, valOut: valOut, } @@ -165,7 +176,7 @@ func processFuncOut(funcType reflect.Type) (valOut int, errOut int, n int) { switch n { case 0: case 1: - if funcType.Out(0) == reflect.TypeOf(new(error)).Elem() { + if funcType.Out(0) == errorType { errOut = 0 } else { valOut = 0 @@ -173,7 +184,7 @@ func processFuncOut(funcType reflect.Type) (valOut int, errOut int, n int) { case 2: valOut = 0 errOut = 1 - if funcType.Out(1) != reflect.TypeOf(new(error)).Elem() { + if funcType.Out(1) != errorType { panic("expected error as second return value") } default: diff --git a/rpclib/rpc_test.go b/rpclib/rpc_test.go index 6f8a9d143..2e890b5ac 100644 --- a/rpclib/rpc_test.go +++ b/rpclib/rpc_test.go @@ -1,10 +1,12 @@ package rpclib import ( + "context" "errors" "net/http/httptest" "strconv" "testing" + "time" ) type SimpleServerHandler struct { @@ -143,11 +145,11 @@ func TestRPC(t *testing.T) { noparam.Add() var erronly struct { - Add func() error + AddGet func() (int, error) } NewClient(testServ.URL, "SimpleServerHandler", &erronly) - err = erronly.Add() + _, err = erronly.AddGet() if err == nil || err.Error() != "RPC client error: non 200 response code" { t.Error("wrong error") } @@ -162,3 +164,59 @@ func TestRPC(t *testing.T) { t.Error("wrong error") } } + +type CtxHandler struct { + cancelled bool + i int +} + +func (h *CtxHandler) Test(ctx context.Context) { + timeout := time.After(300 * time.Millisecond) + h.i++ + + select { + case <-timeout: + case <-ctx.Done(): + h.cancelled = true + } +} + +func TestCtx(t *testing.T) { + // setup server + + serverHandler := &CtxHandler{} + + rpcServer := NewServer() + rpcServer.Register(serverHandler) + + // httptest stuff + testServ := httptest.NewServer(rpcServer) + defer testServ.Close() + + // setup client + + var client struct { + Test func(ctx context.Context) + } + NewClient(testServ.URL, "CtxHandler", &client) + + ctx, cancel := context.WithTimeout(context.Background(), 20 * time.Millisecond) + defer cancel() + + client.Test(ctx) + if !serverHandler.cancelled { + t.Error("expected cancellation on the server side") + } + + serverHandler.cancelled = false + + var noCtxClient struct { + Test func() + } + NewClient(testServ.URL, "CtxHandler", &noCtxClient) + + noCtxClient.Test() + if serverHandler.cancelled || serverHandler.i != 2 { + t.Error("wrong serverHandler state") + } +} \ No newline at end of file From 795621ed277e8548026308ae904dfc847b29a863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sat, 29 Jun 2019 11:19:06 +0200 Subject: [PATCH 06/31] Node builder structure License: MIT Signed-off-by: Jakub Sztandera --- api/api.go | 11 +++- api/client/client.go | 7 +- api/struct.go | 24 +++++++ api/test/test.go | 35 ++++++++++ daemon/builder.go | 1 - daemon/cmd.go | 13 +++- daemon/modules/testing.go | 1 - daemon/rpc.go | 15 +---- go.mod | 4 +- go.sum | 101 +++++++++++++++++++++++++++++ node/builder.go | 48 ++++++++++++++ {daemon => node}/modules/core.go | 0 {daemon => node}/modules/libp2p.go | 0 node/modules/testing.go | 22 +++++++ rpclib/rpcServer.go | 8 +-- rpclib/rpc_test.go | 4 +- 16 files changed, 268 insertions(+), 26 deletions(-) create mode 100644 api/struct.go create mode 100644 api/test/test.go delete mode 100644 daemon/builder.go delete mode 100644 daemon/modules/testing.go create mode 100644 node/builder.go rename {daemon => node}/modules/core.go (100%) rename {daemon => node}/modules/libp2p.go (100%) create mode 100644 node/modules/testing.go diff --git a/api/api.go b/api/api.go index 990ba78c6..9f100546a 100644 --- a/api/api.go +++ b/api/api.go @@ -1,5 +1,11 @@ package api +import ( + "context" + + "github.com/libp2p/go-libp2p-core/peer" +) + type Version struct { Version string @@ -30,7 +36,7 @@ type API interface { // // ping // // connect - // client + // Struct // miner @@ -65,5 +71,6 @@ type API interface { // // ID (on cli - print with other info) - Version() Version + ID(context.Context) (peer.ID, error) + Version(context.Context) (Version, error) } diff --git a/api/client/client.go b/api/client/client.go index c86373513..921c50478 100644 --- a/api/client/client.go +++ b/api/client/client.go @@ -2,8 +2,11 @@ package client import ( "github.com/filecoin-project/go-lotus/api" + "github.com/filecoin-project/go-lotus/rpclib" ) func NewRPC(addr string) api.API { - return nil // TODO -} + var res api.Struct + rpclib.NewClient(addr, "Filecoin", &res.Internal) + return &res +} \ No newline at end of file diff --git a/api/struct.go b/api/struct.go new file mode 100644 index 000000000..e2c91b49b --- /dev/null +++ b/api/struct.go @@ -0,0 +1,24 @@ +package api + +import ( + "context" + + "github.com/libp2p/go-libp2p-core/peer" +) + +type Struct struct { + Internal struct{ + 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{} \ No newline at end of file diff --git a/api/test/test.go b/api/test/test.go new file mode 100644 index 000000000..6efa25196 --- /dev/null +++ b/api/test/test.go @@ -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 +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") + } +} diff --git a/daemon/builder.go b/daemon/builder.go deleted file mode 100644 index 9d3072094..000000000 --- a/daemon/builder.go +++ /dev/null @@ -1 +0,0 @@ -package daemon diff --git a/daemon/cmd.go b/daemon/cmd.go index aa62f8312..c73a66774 100644 --- a/daemon/cmd.go +++ b/daemon/cmd.go @@ -1,13 +1,24 @@ package daemon import ( + goctx "context" + "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 { - return serveRPC() + ctx := goctx.Background() + + api, err := node.New(ctx) + if err != nil { + return err + } + + return serveRPC(api) }, } diff --git a/daemon/modules/testing.go b/daemon/modules/testing.go deleted file mode 100644 index 11174d7d4..000000000 --- a/daemon/modules/testing.go +++ /dev/null @@ -1 +0,0 @@ -package modules diff --git a/daemon/rpc.go b/daemon/rpc.go index ad707b632..bc383cdbe 100644 --- a/daemon/rpc.go +++ b/daemon/rpc.go @@ -1,25 +1,16 @@ package daemon import ( - "fmt" "net/http" - "github.com/filecoin-project/go-lotus/build" + "github.com/filecoin-project/go-lotus/api" "github.com/filecoin-project/go-lotus/rpclib" ) -type Filecoin struct{} - -func (*Filecoin) ServerVersion(in int) (string, error) { - fmt.Println(in) - return build.Version, nil -} - -func serveRPC() error { - fc := new(Filecoin) +func serveRPC(api api.API) error { rpcServer := rpclib.NewServer() - rpcServer.Register(fc) + rpcServer.Register("Filecoin", api) http.Handle("/rpc/v0", rpcServer) return http.ListenAndServe(":1234", http.DefaultServeMux) } diff --git a/go.mod b/go.mod index 9ed8b5396..2beb4558f 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,11 @@ go 1.12 require ( github.com/gorilla/rpc v1.2.0 + github.com/libp2p/go-libp2p-core v0.0.6 + github.com/multiformats/go-multihash v0.0.5 go.uber.org/atomic v1.4.0 // indirect go.uber.org/dig v1.7.0 // indirect - go.uber.org/fx v1.9.0 // indirect + go.uber.org/fx v1.9.0 go.uber.org/multierr v1.1.0 // indirect gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8 ) diff --git a/go.sum b/go.sum index 940a82af0..c73d772f2 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,67 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= +github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c h1:aEbSeNALREWXk0G7UdNhR3ayBV7tZ4M2PNmnrCAph6Q= +github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= +github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= +github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= +github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= +github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= +github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/gorilla/rpc v1.2.0 h1:WvvdC2lNeT1SP32zrIce5l0ECBfbAlmrmSBsuc57wfk= github.com/gorilla/rpc v1.2.0/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ= +github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= +github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= +github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= +github.com/jbenet/goprocess v0.1.3 h1:YKyIEECS/XvcfHtBzxtjBBbWK+MbvA6dG8ASiqwvr10= +github.com/jbenet/goprocess v0.1.3/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= +github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= +github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8= +github.com/libp2p/go-libp2p-core v0.0.6 h1:SsYhfWJ47vLP1Rd9/0hqEm/W/PlFbC/3YLZyLCcvo1w= +github.com/libp2p/go-libp2p-core v0.0.6/go.mod h1:0d9xmaYAVY5qmbp/fcgxHT3ZJsLjYeYPMJAUKpaCHrE= +github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= +github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= +github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= +github.com/minio/sha256-simd v0.0.0-20190328051042-05b4dd3047e5/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= +github.com/minio/sha256-simd v0.1.0 h1:U41/2erhAKcmSI14xh/ZTUdBPOzDOIfS93ibzUSl8KM= +github.com/minio/sha256-simd v0.1.0/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= +github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= +github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78= +github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= +github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= +github.com/multiformats/go-multiaddr v0.0.4 h1:WgMSI84/eRLdbptXMkMWDXPjPq7SPLIgGUVm2eroyU4= +github.com/multiformats/go-multiaddr v0.0.4/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= +github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= +github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= +github.com/multiformats/go-multihash v0.0.5 h1:1wxmCvTXAifAepIMyF39vZinRw5sbqjPs/UIi93+uik= +github.com/multiformats/go-multihash v0.0.5/go.mod h1:lt/HCbqlQwlPBz7lv0sQCdtfcMtlJvakRUn/0Ual8po= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0= +github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc= +github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= +github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/dig v1.7.0 h1:E5/L92iQTNJTjfgJF2KgU+/JpMaiuvK2DHLBj0+kSZk= @@ -8,5 +70,44 @@ go.uber.org/fx v1.9.0 h1:7OAz8ucp35AU8eydejpYG7QrbE8rLKzGhHbZlJi5LYY= go.uber.org/fx v1.9.0/go.mod h1:mFdUyAUuJ3w4jAckiKSKbldsxy1ojpAMJ+dVZg5Y0Aw= go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443 h1:IcSOAf4PyMp3U3XbIEj1/xJ2BjNN2jWv7JoyOsMxXUU= +golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8 h1:Ggy3mWN4l3PUFPfSG0YB3n5fVYggzysUmiUQ89SnX6Y= gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8/go.mod h1:cKXr3E0k4aosgycml1b5z33BVV6hai1Kh7uDgFOkbcs= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/node/builder.go b/node/builder.go new file mode 100644 index 000000000..fb5ae6b78 --- /dev/null +++ b/node/builder.go @@ -0,0 +1,48 @@ +package node + +import ( + "context" + + "github.com/libp2p/go-libp2p-core/peer" + "go.uber.org/fx" + + "github.com/filecoin-project/go-lotus/api" + "github.com/filecoin-project/go-lotus/build" + "github.com/filecoin-project/go-lotus/node/modules" +) + +func New(ctx context.Context) (api.API, error) { + var resApi api.Struct + + app := fx.New( + fx.Provide(modules.RandomPeerID), + + fx.Invoke(versionApi(&resApi.Internal.Version)), + fx.Invoke(idApi(&resApi.Internal.ID)), + ) + + if err := app.Start(ctx); err != nil { + return nil, err + } + + return &resApi, nil +} + +// TODO: figure out a better way, this isn't usable in long term +func idApi(set *func(ctx context.Context) (peer.ID, error)) func(id peer.ID) { + return func(id peer.ID) { + *set = func(ctx context.Context) (peer.ID, error) { + return id, nil + } + } +} + +func versionApi(set *func(context.Context) (api.Version, error)) func() { + return func() { + *set = func(context.Context) (api.Version, error) { + return api.Version{ + Version: build.Version, + }, nil + } + } +} diff --git a/daemon/modules/core.go b/node/modules/core.go similarity index 100% rename from daemon/modules/core.go rename to node/modules/core.go diff --git a/daemon/modules/libp2p.go b/node/modules/libp2p.go similarity index 100% rename from daemon/modules/libp2p.go rename to node/modules/libp2p.go diff --git a/node/modules/testing.go b/node/modules/testing.go new file mode 100644 index 000000000..a8b4b3a1e --- /dev/null +++ b/node/modules/testing.go @@ -0,0 +1,22 @@ +package modules + +import ( + "crypto/rand" + "io" + "io/ioutil" + + "github.com/libp2p/go-libp2p-core/peer" + mh "github.com/multiformats/go-multihash" +) + +func RandomPeerID() (peer.ID, error) { + b, err := ioutil.ReadAll(io.LimitReader(rand.Reader, 32)) + if err != nil { + return "", err + } + hash, err := mh.Sum(b, mh.SHA2_256, -1) + if err != nil { + return "", err + } + return peer.ID(hash), nil +} \ No newline at end of file diff --git a/rpclib/rpcServer.go b/rpclib/rpcServer.go index 1237497ee..b0e039bfd 100644 --- a/rpclib/rpcServer.go +++ b/rpclib/rpcServer.go @@ -130,12 +130,10 @@ func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } -func (s *RPCServer) Register(r interface{}) { +func (s *RPCServer) Register(namespace string, r interface{}) { val := reflect.ValueOf(r) //TODO: expect ptr - name := val.Type().Elem().Name() - for i := 0; i < val.NumMethod(); i++ { method := val.Type().Method(i) @@ -153,7 +151,9 @@ func (s *RPCServer) Register(r interface{}) { valOut, errOut, _ := processFuncOut(funcType) - s.methods[name+"."+method.Name] = rpcHandler{ + fmt.Println(namespace+"."+method.Name) + + s.methods[namespace+"."+method.Name] = rpcHandler{ paramReceivers: recvs, nParams: ins, diff --git a/rpclib/rpc_test.go b/rpclib/rpc_test.go index 2e890b5ac..7eb82b7c6 100644 --- a/rpclib/rpc_test.go +++ b/rpclib/rpc_test.go @@ -56,7 +56,7 @@ func TestRPC(t *testing.T) { serverHandler := &SimpleServerHandler{} rpcServer := NewServer() - rpcServer.Register(serverHandler) + rpcServer.Register("SimpleServerHandler", serverHandler) // httptest stuff testServ := httptest.NewServer(rpcServer) @@ -187,7 +187,7 @@ func TestCtx(t *testing.T) { serverHandler := &CtxHandler{} rpcServer := NewServer() - rpcServer.Register(serverHandler) + rpcServer.Register("SimpleServerHandler", serverHandler) // httptest stuff testServ := httptest.NewServer(rpcServer) From 63627e863e7562e022271f79c837132d50bf0ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 1 Jul 2019 11:09:48 +0200 Subject: [PATCH 07/31] Import libp2p modules License: MIT Signed-off-by: Jakub Sztandera --- go.mod | 9 ++ go.sum | 219 +++++++++++++++++++++++++++++++ node/modules/helpers/helpers.go | 25 ++++ node/modules/libp2p.go | 1 - node/modules/libp2p/addrs.go | 117 +++++++++++++++++ node/modules/libp2p/discovery.go | 53 ++++++++ node/modules/libp2p/host.go | 98 ++++++++++++++ node/modules/libp2p/libp2p.go | 46 +++++++ node/modules/libp2p/nat.go | 34 +++++ node/modules/libp2p/pnet.go | 71 ++++++++++ node/modules/libp2p/pubsub.go | 21 +++ node/modules/libp2p/relay.go | 56 ++++++++ node/modules/libp2p/routing.go | 70 ++++++++++ node/modules/libp2p/smux.go | 54 ++++++++ node/modules/libp2p/transport.go | 38 ++++++ 15 files changed, 911 insertions(+), 1 deletion(-) create mode 100644 node/modules/helpers/helpers.go delete mode 100644 node/modules/libp2p.go create mode 100644 node/modules/libp2p/addrs.go create mode 100644 node/modules/libp2p/discovery.go create mode 100644 node/modules/libp2p/host.go create mode 100644 node/modules/libp2p/libp2p.go create mode 100644 node/modules/libp2p/nat.go create mode 100644 node/modules/libp2p/pnet.go create mode 100644 node/modules/libp2p/pubsub.go create mode 100644 node/modules/libp2p/relay.go create mode 100644 node/modules/libp2p/routing.go create mode 100644 node/modules/libp2p/smux.go create mode 100644 node/modules/libp2p/transport.go diff --git a/go.mod b/go.mod index 2beb4558f..1b4a74f64 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,16 @@ go 1.12 require ( github.com/gorilla/rpc v1.2.0 + github.com/ipfs/go-ipfs-routing v0.1.0 // indirect + github.com/libp2p/go-libp2p v0.2.0 // indirect + github.com/libp2p/go-libp2p-autonat-svc v0.1.0 // indirect + github.com/libp2p/go-libp2p-connmgr v0.1.0 // indirect github.com/libp2p/go-libp2p-core v0.0.6 + github.com/libp2p/go-libp2p-kad-dht v0.1.1 // indirect + github.com/libp2p/go-libp2p-pubsub v0.1.0 // indirect + github.com/libp2p/go-libp2p-quic-transport v0.1.1 // indirect + github.com/libp2p/go-libp2p-routing-helpers v0.1.0 // indirect + github.com/libp2p/go-libp2p-tls v0.1.0 // indirect github.com/multiformats/go-multihash v0.0.5 go.uber.org/atomic v1.4.0 // indirect go.uber.org/dig v1.7.0 // indirect diff --git a/go.sum b/go.sum index c73d772f2..2fc8bcfb2 100644 --- a/go.sum +++ b/go.sum @@ -1,33 +1,88 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= +github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8= github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c h1:aEbSeNALREWXk0G7UdNhR3ayBV7tZ4M2PNmnrCAph6Q= github.com/btcsuite/btcd v0.0.0-20190523000118-16327141da8c/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= +github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= +github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE= +github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ= +github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= +github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/rpc v1.2.0 h1:WvvdC2lNeT1SP32zrIce5l0ECBfbAlmrmSBsuc57wfk= github.com/gorilla/rpc v1.2.0/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ= +github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo= +github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc= +github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= +github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= +github.com/ipfs/go-cid v0.0.2 h1:tuuKaZPU1M6HcejsO3AcYWW8sZ8MTvyxfc4uqB4eFE8= github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= +github.com/ipfs/go-datastore v0.0.1/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= +github.com/ipfs/go-datastore v0.0.5 h1:q3OfiOZV5rlsK1H5V8benjeUApRfMGs4Mrhmr6NriQo= +github.com/ipfs/go-datastore v0.0.5/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= +github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= +github.com/ipfs/go-ds-badger v0.0.2/go.mod h1:Y3QpeSFWQf6MopLTiZD+VT6IC1yZqaGmjvRcKeSGij8= +github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc= +github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= +github.com/ipfs/go-ipfs-delay v0.0.1/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= +github.com/ipfs/go-ipfs-ds-help v0.0.1/go.mod h1:gtP9xRaZXqIQRh1HRpp595KbBEdgqWFxefeVKOV8sxo= +github.com/ipfs/go-ipfs-routing v0.1.0 h1:gAJTT1cEeeLj6/DlLX6t+NxD9fQe2ymTO6qWRDI/HQQ= +github.com/ipfs/go-ipfs-routing v0.1.0/go.mod h1:hYoUkJLyAUKhF58tysKpids8RNDPO42BVMgK5dNsoqY= +github.com/ipfs/go-ipfs-util v0.0.1 h1:Wz9bL2wB2YBJqggkA4dD7oSmqB4cAnpNbGrlHJulv50= +github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc= +github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc= +github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= +github.com/ipfs/go-todocounter v0.0.1 h1:kITWA5ZcQZfrUnDNkRn04Xzh0YFaDFXsoO2A81Eb6Lw= +github.com/ipfs/go-todocounter v0.0.1/go.mod h1:l5aErvQc8qKE2r7NDMjmq5UNAvuZy0rC8BHOplkWvZ4= +github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc= +github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA= +github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA= +github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= +github.com/jbenet/go-cienv v0.0.0-20150120210510-1bb1476777ec/go.mod h1:rGaEvXB4uRSZMmzKNLoXvTu1sfx+1kv/DojUlPrSZGs= github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= +github.com/jbenet/go-temp-err-catcher v0.0.0-20150120210811-aac704a3f4f2 h1:vhC1OXXiT9R2pczegwz6moDvuRpggaroAXhPIseh57A= +github.com/jbenet/go-temp-err-catcher v0.0.0-20150120210811-aac704a3f4f2/go.mod h1:8GXXJV31xl8whumTzdZsTt3RnUIiPqzkyf7mxToRCMs= +github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8/go.mod h1:Ly/wlsjFq/qrU3Rar62tu1gASgGw6chQbSh/XgIIXCY= github.com/jbenet/goprocess v0.1.3 h1:YKyIEECS/XvcfHtBzxtjBBbWK+MbvA6dG8ASiqwvr10= github.com/jbenet/goprocess v0.1.3/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -35,9 +90,118 @@ github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlT github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= +github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b h1:wxtKgYHEncAU00muMD06dzLiahtGM1eouRNOzVV7tdQ= +github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/libp2p/go-addr-util v0.0.1 h1:TpTQm9cXVRVSKsYbgQ7GKc3KbbHVTnbostgGaDEP+88= +github.com/libp2p/go-addr-util v0.0.1/go.mod h1:4ac6O7n9rIAKB1dnd+s8IbbMXkt+oBpzX4/+RACcnlQ= +github.com/libp2p/go-buffer-pool v0.0.1/go.mod h1:xtyIz9PMobb13WaxR6Zo1Pd1zXJKYg0a8KiIvDp3TzQ= +github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOSqcmlfs= +github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM= +github.com/libp2p/go-conn-security-multistream v0.1.0 h1:aqGmto+ttL/uJgX0JtQI0tD21CIEy5eYd1Hlp0juHY0= +github.com/libp2p/go-conn-security-multistream v0.1.0/go.mod h1:aw6eD7LOsHEX7+2hJkDxw1MteijaVcI+/eP2/x3J1xc= +github.com/libp2p/go-eventbus v0.0.2 h1:L9eslON8FjFBJlyUs9fyEZKnxSqZd2AMDUNldPrqmZI= +github.com/libp2p/go-eventbus v0.0.2/go.mod h1:Hr/yGlwxA/stuLnpMiu82lpNKpvRy3EaJxPu40XYOwk= +github.com/libp2p/go-flow-metrics v0.0.1 h1:0gxuFd2GuK7IIP5pKljLwps6TvcuYgvG7Atqi3INF5s= github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8= +github.com/libp2p/go-libp2p v0.1.0/go.mod h1:6D/2OBauqLUoqcADOJpn9WbKqvaM07tDw68qHM0BxUM= +github.com/libp2p/go-libp2p v0.2.0 h1:hYJgMZYdcwHzDHKb/nLePrtuSP3LqkGIFOQ2aIbKOCM= +github.com/libp2p/go-libp2p v0.2.0/go.mod h1:5nXHmf4Hs+NmkaMsmWcFJgUHTbYNpCfxr20lwus0p1c= +github.com/libp2p/go-libp2p-autonat v0.1.0 h1:aCWAu43Ri4nU0ZPO7NyLzUvvfqd0nE3dX0R/ZGYVgOU= +github.com/libp2p/go-libp2p-autonat v0.1.0/go.mod h1:1tLf2yXxiE/oKGtDwPYWTSYG3PtvYlJmg7NeVtPRqH8= +github.com/libp2p/go-libp2p-autonat-svc v0.1.0 h1:28IM7iWMDclZeVkpiFQaWVANwXwE7zLlpbnS7yXxrfs= +github.com/libp2p/go-libp2p-autonat-svc v0.1.0/go.mod h1:fqi8Obl/z3R4PFVLm8xFtZ6PBL9MlV/xumymRFkKq5A= +github.com/libp2p/go-libp2p-blankhost v0.1.1/go.mod h1:pf2fvdLJPsC1FsVrNP3DUUvMzUts2dsLLBEpo1vW1ro= +github.com/libp2p/go-libp2p-blankhost v0.1.3/go.mod h1:KML1//wiKR8vuuJO0y3LUd1uLv+tlkGTAr3jC0S5cLg= +github.com/libp2p/go-libp2p-circuit v0.1.0 h1:eniLL3Y9aq/sryfyV1IAHj5rlvuyj3b7iz8tSiZpdhY= +github.com/libp2p/go-libp2p-circuit v0.1.0/go.mod h1:Ahq4cY3V9VJcHcn1SBXjr78AbFkZeIRmfunbA7pmFh8= +github.com/libp2p/go-libp2p-connmgr v0.1.0 h1:vp0t0F0EuT3rrlTtnMnIyyzCnly7nIlRoEbhJpgp0qU= +github.com/libp2p/go-libp2p-connmgr v0.1.0/go.mod h1:wZxh8veAmU5qdrfJ0ZBLcU8oJe9L82ciVP/fl1VHjXk= +github.com/libp2p/go-libp2p-core v0.0.1/go.mod h1:g/VxnTZ/1ygHxH3dKok7Vno1VfpvGcGip57wjTU4fco= +github.com/libp2p/go-libp2p-core v0.0.2/go.mod h1:9dAcntw/n46XycV4RnlBq3BpgrmyUi9LuoTNdPrbUco= +github.com/libp2p/go-libp2p-core v0.0.4/go.mod h1:jyuCQP356gzfCFtRKyvAbNkyeuxb7OlyhWZ3nls5d2I= github.com/libp2p/go-libp2p-core v0.0.6 h1:SsYhfWJ47vLP1Rd9/0hqEm/W/PlFbC/3YLZyLCcvo1w= github.com/libp2p/go-libp2p-core v0.0.6/go.mod h1:0d9xmaYAVY5qmbp/fcgxHT3ZJsLjYeYPMJAUKpaCHrE= +github.com/libp2p/go-libp2p-crypto v0.1.0 h1:k9MFy+o2zGDNGsaoZl0MA3iZ75qXxr9OOoAZF+sD5OQ= +github.com/libp2p/go-libp2p-crypto v0.1.0/go.mod h1:sPUokVISZiy+nNuTTH/TY+leRSxnFj/2GLjtOTW90hI= +github.com/libp2p/go-libp2p-discovery v0.1.0 h1:j+R6cokKcGbnZLf4kcNwpx6mDEUPF3N6SrqMymQhmvs= +github.com/libp2p/go-libp2p-discovery v0.1.0/go.mod h1:4F/x+aldVHjHDHuX85x1zWoFTGElt8HnoDzwkFZm29g= +github.com/libp2p/go-libp2p-kad-dht v0.1.1 h1:IH6NQuoUv5w5e1O8Jc3KyVDtr0rNd0G9aaADpLI1xVo= +github.com/libp2p/go-libp2p-kad-dht v0.1.1/go.mod h1:1kj2Rk5pX3/0RwqMm9AMNCT7DzcMHYhgDN5VTi+cY0M= +github.com/libp2p/go-libp2p-kbucket v0.2.0 h1:FB2a0VkOTNGTP5gu/I444u4WabNM9V1zCkQcWb7zajI= +github.com/libp2p/go-libp2p-kbucket v0.2.0/go.mod h1:JNymBToym3QXKBMKGy3m29+xprg0EVr/GJFHxFEdgh8= +github.com/libp2p/go-libp2p-loggables v0.1.0 h1:h3w8QFfCt2UJl/0/NW4K829HX/0S4KD31PQ7m8UXXO8= +github.com/libp2p/go-libp2p-loggables v0.1.0/go.mod h1:EyumB2Y6PrYjr55Q3/tiJ/o3xoDasoRYM7nOzEpoa90= +github.com/libp2p/go-libp2p-mplex v0.2.0/go.mod h1:Ejl9IyjvXJ0T9iqUTE1jpYATQ9NM3g+OtR+EMMODbKo= +github.com/libp2p/go-libp2p-mplex v0.2.1 h1:E1xaJBQnbSiTHGI1gaBKmKhu1TUKkErKJnE8iGvirYI= +github.com/libp2p/go-libp2p-mplex v0.2.1/go.mod h1:SC99Rxs8Vuzrf/6WhmH41kNn13TiYdAWNYHrwImKLnE= +github.com/libp2p/go-libp2p-nat v0.0.4 h1:+KXK324yaY701On8a0aGjTnw8467kW3ExKcqW2wwmyw= +github.com/libp2p/go-libp2p-nat v0.0.4/go.mod h1:N9Js/zVtAXqaeT99cXgTV9e75KpnWCvVOiGzlcHmBbY= +github.com/libp2p/go-libp2p-netutil v0.1.0/go.mod h1:3Qv/aDqtMLTUyQeundkKsA+YCThNdbQD54k3TqjpbFU= +github.com/libp2p/go-libp2p-peer v0.2.0/go.mod h1:RCffaCvUyW2CJmG2gAWVqwePwW7JMgxjsHm7+J5kjWY= +github.com/libp2p/go-libp2p-peerstore v0.1.0/go.mod h1:2CeHkQsr8svp4fZ+Oi9ykN1HBb6u0MOvdJ7YIsmcwtY= +github.com/libp2p/go-libp2p-peerstore v0.1.1 h1:AJZF2sPpVo+0aAr3IrRiGVsPjJm1INlUQ9EGClgXJ4M= +github.com/libp2p/go-libp2p-peerstore v0.1.1/go.mod h1:ojEWnwG7JpJLkJ9REWYXQslyu9ZLrPWPEcCdiZzEbSM= +github.com/libp2p/go-libp2p-pubsub v0.1.0 h1:SmQeMa7IUv5vadh0fYgYsafWCBA1sCy5d/68kIYqGcU= +github.com/libp2p/go-libp2p-pubsub v0.1.0/go.mod h1:ZwlKzRSe1eGvSIdU5bD7+8RZN/Uzw0t1Bp9R1znpR/Q= +github.com/libp2p/go-libp2p-quic-transport v0.1.1 h1:MFMJzvsxIEDEVKzO89BnB/FgvMj9WI4GDGUW2ArDPUA= +github.com/libp2p/go-libp2p-quic-transport v0.1.1/go.mod h1:wqG/jzhF3Pu2NrhJEvE+IE0NTHNXslOPn9JQzyCAxzU= +github.com/libp2p/go-libp2p-record v0.1.0 h1:wHwBGbFzymoIl69BpgwIu0O6ta3TXGcMPvHUAcodzRc= +github.com/libp2p/go-libp2p-record v0.1.0/go.mod h1:ujNc8iuE5dlKWVy6wuL6dd58t0n7xI4hAIl8pE6wu5Q= +github.com/libp2p/go-libp2p-routing v0.1.0 h1:hFnj3WR3E2tOcKaGpyzfP4gvFZ3t8JkQmbapN0Ct+oU= +github.com/libp2p/go-libp2p-routing v0.1.0/go.mod h1:zfLhI1RI8RLEzmEaaPwzonRvXeeSHddONWkcTcB54nE= +github.com/libp2p/go-libp2p-routing-helpers v0.1.0 h1:BaFvpyv8TyhCN7TihawTiKuzeu8/Pyw7ZnMA4IvqIN8= +github.com/libp2p/go-libp2p-routing-helpers v0.1.0/go.mod h1:oUs0h39vNwYtYXnQWOTU5BaafbedSyWCCal3gqHuoOQ= +github.com/libp2p/go-libp2p-secio v0.1.0 h1:NNP5KLxuP97sE5Bu3iuwOWyT/dKEGMN5zSLMWdB7GTQ= +github.com/libp2p/go-libp2p-secio v0.1.0/go.mod h1:tMJo2w7h3+wN4pgU2LSYeiKPrfqBgkOsdiKK77hE7c8= +github.com/libp2p/go-libp2p-swarm v0.1.0 h1:HrFk2p0awrGEgch9JXK/qp/hfjqQfgNxpLWnCiWPg5s= +github.com/libp2p/go-libp2p-swarm v0.1.0/go.mod h1:wQVsCdjsuZoc730CgOvh5ox6K8evllckjebkdiY5ta4= +github.com/libp2p/go-libp2p-testing v0.0.2/go.mod h1:gvchhf3FQOtBdr+eFUABet5a4MBLK8jM3V4Zghvmi+E= +github.com/libp2p/go-libp2p-testing v0.0.3/go.mod h1:gvchhf3FQOtBdr+eFUABet5a4MBLK8jM3V4Zghvmi+E= +github.com/libp2p/go-libp2p-testing v0.0.4/go.mod h1:gvchhf3FQOtBdr+eFUABet5a4MBLK8jM3V4Zghvmi+E= +github.com/libp2p/go-libp2p-tls v0.1.0 h1:o4bjjAdnUjNgJoPoDd0wUaZH7K+EenlNWJpgyXB3ulA= +github.com/libp2p/go-libp2p-tls v0.1.0/go.mod h1:VZdoSWQDeNpIIAFJFv+6uqTqpnIIDHcqZQSTC/A1TT0= +github.com/libp2p/go-libp2p-transport-upgrader v0.1.1 h1:PZMS9lhjK9VytzMCW3tWHAXtKXmlURSc3ZdvwEcKCzw= +github.com/libp2p/go-libp2p-transport-upgrader v0.1.1/go.mod h1:IEtA6or8JUbsV07qPW4r01GnTenLW4oi3lOPbUMGJJA= +github.com/libp2p/go-libp2p-yamux v0.2.0/go.mod h1:Db2gU+XfLpm6E4rG5uGCFX6uXA8MEXOxFcRoXUODaK8= +github.com/libp2p/go-libp2p-yamux v0.2.1 h1:Q3XYNiKCC2vIxrvUJL+Jg1kiyeEaIDNKLjgEjo3VQdI= +github.com/libp2p/go-libp2p-yamux v0.2.1/go.mod h1:1FBXiHDk1VyRM1C0aez2bCfHQ4vMZKkAQzZbkSQt5fI= +github.com/libp2p/go-maddr-filter v0.0.4 h1:hx8HIuuwk34KePddrp2mM5ivgPkZ09JH4AvsALRbFUs= +github.com/libp2p/go-maddr-filter v0.0.4/go.mod h1:6eT12kSQMA9x2pvFQa+xesMKUBlj9VImZbj3B9FBH/Q= +github.com/libp2p/go-mplex v0.0.3/go.mod h1:pK5yMLmOoBR1pNCqDlA2GQrdAVTMkqFalaTWe7l4Yd0= +github.com/libp2p/go-mplex v0.1.0 h1:/nBTy5+1yRyY82YaO6HXQRnO5IAGsXTjEJaR3LdTPc0= +github.com/libp2p/go-mplex v0.1.0/go.mod h1:SXgmdki2kwCUlCCbfGLEgHjC4pFqhTp0ZoV6aiKgxDU= +github.com/libp2p/go-msgio v0.0.2 h1:ivPvEKHxmVkTClHzg6RXTYHqaJQ0V9cDbq+6lKb3UV0= +github.com/libp2p/go-msgio v0.0.2/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= +github.com/libp2p/go-msgio v0.0.4 h1:agEFehY3zWJFUHK6SEMR7UYmk2z6kC3oeCM7ybLhguA= +github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= +github.com/libp2p/go-nat v0.0.3 h1:l6fKV+p0Xa354EqQOQP+d8CivdLM4kl5GxC1hSc/UeI= +github.com/libp2p/go-nat v0.0.3/go.mod h1:88nUEt0k0JD45Bk93NIwDqjlhiOwOoV36GchpcVc1yI= +github.com/libp2p/go-reuseport v0.0.1 h1:7PhkfH73VXfPJYKQ6JwS5I/eVcoyYi9IMNGc6FWpFLw= +github.com/libp2p/go-reuseport v0.0.1/go.mod h1:jn6RmB1ufnQwl0Q1f+YxAj8isJgDCQzaaxIFYDhcYEA= +github.com/libp2p/go-reuseport-transport v0.0.2 h1:WglMwyXyBu61CMkjCCtnmqNqnjib0GIEjMiHTwR/KN4= +github.com/libp2p/go-reuseport-transport v0.0.2/go.mod h1:YkbSDrvjUVDL6b8XqriyA20obEtsW9BLkuOUyQAOCbs= +github.com/libp2p/go-stream-muxer v0.0.1/go.mod h1:bAo8x7YkSpadMTbtTaxGVHWUQsR/l5MEaHbKaliuT14= +github.com/libp2p/go-stream-muxer-multistream v0.2.0 h1:714bRJ4Zy9mdhyTLJ+ZKiROmAFwUHpeRidG+q7LTQOg= +github.com/libp2p/go-stream-muxer-multistream v0.2.0/go.mod h1:j9eyPol/LLRqT+GPLSxvimPhNph4sfYfMoDPd7HkzIc= +github.com/libp2p/go-tcp-transport v0.1.0 h1:IGhowvEqyMFknOar4FWCKSWE0zL36UFKQtiRQD60/8o= +github.com/libp2p/go-tcp-transport v0.1.0/go.mod h1:oJ8I5VXryj493DEJ7OsBieu8fcg2nHGctwtInJVpipc= +github.com/libp2p/go-ws-transport v0.1.0 h1:F+0OvvdmPTDsVc4AjPHjV7L7Pk1B7D5QwtDcKE2oag4= +github.com/libp2p/go-ws-transport v0.1.0/go.mod h1:rjw1MG1LU9YDC6gzmwObkPd/Sqwhw7yT74kj3raBFuo= +github.com/libp2p/go-yamux v1.2.2/go.mod h1:FGTiPvoV/3DVdgWpX+tM0OW3tsM+W5bSE3gZwqQTcow= +github.com/libp2p/go-yamux v1.2.3 h1:xX8A36vpXb59frIzWFdEgptLMsOANMFq2K7fPRlunYI= +github.com/libp2p/go-yamux v1.2.3/go.mod h1:FGTiPvoV/3DVdgWpX+tM0OW3tsM+W5bSE3gZwqQTcow= +github.com/lucas-clemente/quic-go v0.11.2 h1:Mop0ac3zALaBR3wGs6j8OYe/tcFvFsxTUFMkE/7yUOI= +github.com/lucas-clemente/quic-go v0.11.2/go.mod h1:PpMmPfPKO9nKJ/psF49ESTAGQSdfXxlg1otPbEB2nOw= +github.com/marten-seemann/qtls v0.2.3 h1:0yWJ43C62LsZt08vuQJDK1uC1czUc3FJeCLPoNAI4vA= +github.com/marten-seemann/qtls v0.2.3/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk= +github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg= +github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= +github.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw= +github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/miekg/dns v1.1.12/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= @@ -45,22 +209,62 @@ github.com/minio/sha256-simd v0.0.0-20190328051042-05b4dd3047e5/go.mod h1:2FMWW+ github.com/minio/sha256-simd v0.1.0 h1:U41/2erhAKcmSI14xh/ZTUdBPOzDOIfS93ibzUSl8KM= github.com/minio/sha256-simd v0.1.0/go.mod h1:2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U= github.com/mr-tron/base58 v1.1.0/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= +github.com/mr-tron/base58 v1.1.1/go.mod h1:xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8= github.com/mr-tron/base58 v1.1.2 h1:ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78= github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= +github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI= github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA= +github.com/multiformats/go-multiaddr v0.0.1/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= +github.com/multiformats/go-multiaddr v0.0.2/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= github.com/multiformats/go-multiaddr v0.0.4 h1:WgMSI84/eRLdbptXMkMWDXPjPq7SPLIgGUVm2eroyU4= github.com/multiformats/go-multiaddr v0.0.4/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44= +github.com/multiformats/go-multiaddr-dns v0.0.1/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= +github.com/multiformats/go-multiaddr-dns v0.0.2 h1:/Bbsgsy3R6e3jf2qBahzNHzww6usYaZ0NhNH3sqdFS8= +github.com/multiformats/go-multiaddr-dns v0.0.2/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= +github.com/multiformats/go-multiaddr-fmt v0.0.1 h1:5YjeOIzbX8OTKVaN72aOzGIYW7PnrZrnkDyOfAWRSMA= +github.com/multiformats/go-multiaddr-fmt v0.0.1/go.mod h1:aBYjqL4T/7j4Qx+R73XSv/8JsgnRFlf0w2KGLCmXl3Q= +github.com/multiformats/go-multiaddr-net v0.0.1 h1:76O59E3FavvHqNg7jvzWzsPSW5JSi/ek0E4eiDVbg9g= +github.com/multiformats/go-multiaddr-net v0.0.1/go.mod h1:nw6HSxNmCIQH27XPGBuX+d1tnvM7ihcFwHMSstNAVUU= +github.com/multiformats/go-multibase v0.0.1 h1:PN9/v21eLywrFWdFNsFKaU04kLJzuYzmrJR+ubhT9qA= github.com/multiformats/go-multibase v0.0.1/go.mod h1:bja2MqRZ3ggyXtZSEDKpl0uO/gviWFaSteVbWT51qgs= github.com/multiformats/go-multihash v0.0.1/go.mod h1:w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U= github.com/multiformats/go-multihash v0.0.5 h1:1wxmCvTXAifAepIMyF39vZinRw5sbqjPs/UIi93+uik= github.com/multiformats/go-multihash v0.0.5/go.mod h1:lt/HCbqlQwlPBz7lv0sQCdtfcMtlJvakRUn/0Ual8po= +github.com/multiformats/go-multistream v0.1.0 h1:UpO6jrsjqs46mqAK3n6wKRYFhugss9ArzbyUzU+4wkQ= +github.com/multiformats/go-multistream v0.1.0/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg= +github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0= github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= +github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc h1:BCPnHtcboadS0DvysUuJXZ4lWVv5Bh5i7+tbIyi+ck4= +github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc/go.mod h1:r45hJU7yEoA81k6MWNhpMj/kms0n14dkzkxYHoB96UM= +github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k= +github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc= +github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc h1:9lDbC6Rz4bwmou+oE6Dt4Cb2BGMur5eR/GYptkKUVHo= +github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM= +github.com/whyrusleeping/go-notifier v0.0.0-20170827234753-097c5d47330f h1:M/lL30eFZTKnomXY6huvM6G0+gVquFNf6mxghaWlFUg= +github.com/whyrusleeping/go-notifier v0.0.0-20170827234753-097c5d47330f/go.mod h1:cZNvX9cFybI01GriPRMXDtczuvUhgbcYr9iCGaNlRv8= +github.com/whyrusleeping/mafmt v1.2.8 h1:TCghSl5kkwEE0j+sU/gudyhVMRlpBin8fMBBHg59EbA= +github.com/whyrusleeping/mafmt v1.2.8/go.mod h1:faQJFPbLSxzD9xpA02ttW/tS9vZykNvXwGvqIpk20FA= +github.com/whyrusleeping/mdns v0.0.0-20180901202407-ef14215e6b30/go.mod h1:j4l84WPFclQPj320J9gp0XwNKBb3U0zt5CBqjPp22G4= +github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 h1:E9S12nwJwEOXe2d6gT6qxdvqMnNq+VnSsKPgm2ZZNds= +github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7/go.mod h1:X2c0RVCI1eSUFI8eLcY3c0423ykwiUdxLJtkDvruhjI= +github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee h1:lYbXeSvJi5zk5GLKVuid9TVjS9a0OmLIDKTfoZBL6Ow= +github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee/go.mod h1:m2aV4LZI4Aez7dP5PMyVKEHhUyEJ/RjmPEDOpDvudHg= +go.opencensus.io v0.21.0 h1:mU6zScU4U1YAFPHEHYk+3JC4SY7JxgkqS10ZOSyksNg= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= @@ -72,8 +276,11 @@ go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443 h1:IcSOAf4PyMp3U3XbIEj1/xJ2BjNN2jWv7JoyOsMxXUU= golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -82,8 +289,11 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190227160552-c95aed5357e7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -93,18 +303,27 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190526052359-791d8a0f4d09 h1:IlD35wZE03o2qJy2o37WIskL33b7PT6cHdGnE8bieZs= +golang.org/x/sys v0.0.0-20190526052359-791d8a0f4d09/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522 h1:bhOzK9QyoD0ogCnFro1m2mz41+Ib0oOhfJnBp5MR4K4= +golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8 h1:Ggy3mWN4l3PUFPfSG0YB3n5fVYggzysUmiUQ89SnX6Y= diff --git a/node/modules/helpers/helpers.go b/node/modules/helpers/helpers.go new file mode 100644 index 000000000..745bfcf46 --- /dev/null +++ b/node/modules/helpers/helpers.go @@ -0,0 +1,25 @@ +package helpers + +import ( + "context" + + "go.uber.org/fx" +) + +type MetricsCtx context.Context + +// LifecycleCtx creates a context which will be cancelled when lifecycle stops +// +// This is a hack which we need because most of our services use contexts in a +// wrong way +func LifecycleCtx(mctx MetricsCtx, lc fx.Lifecycle) context.Context { + ctx, cancel := context.WithCancel(mctx) + lc.Append(fx.Hook{ + OnStop: func(_ context.Context) error { + cancel() + return nil + }, + }) + return ctx +} + diff --git a/node/modules/libp2p.go b/node/modules/libp2p.go deleted file mode 100644 index 11174d7d4..000000000 --- a/node/modules/libp2p.go +++ /dev/null @@ -1 +0,0 @@ -package modules diff --git a/node/modules/libp2p/addrs.go b/node/modules/libp2p/addrs.go new file mode 100644 index 000000000..703a959cb --- /dev/null +++ b/node/modules/libp2p/addrs.go @@ -0,0 +1,117 @@ +package libp2p + +import ( + "fmt" + + "github.com/libp2p/go-libp2p" + host "github.com/libp2p/go-libp2p-core/host" + p2pbhost "github.com/libp2p/go-libp2p/p2p/host/basic" + mafilter "github.com/libp2p/go-maddr-filter" + ma "github.com/multiformats/go-multiaddr" + mamask "github.com/whyrusleeping/multiaddr-filter" +) + +func AddrFilters(filters []string) func() (opts Libp2pOpts, err error) { + return func() (opts Libp2pOpts, err error) { + for _, s := range filters { + f, err := mamask.NewMask(s) + if err != nil { + return opts, fmt.Errorf("incorrectly formatted address filter in config: %s", s) + } + opts.Opts = append(opts.Opts, libp2p.FilterAddresses(f)) + } + return opts, nil + } +} + +func makeAddrsFactory(announce []string, noAnnounce []string) (p2pbhost.AddrsFactory, error) { + var annAddrs []ma.Multiaddr + for _, addr := range announce { + maddr, err := ma.NewMultiaddr(addr) + if err != nil { + return nil, err + } + annAddrs = append(annAddrs, maddr) + } + + filters := mafilter.NewFilters() + noAnnAddrs := map[string]bool{} + for _, addr := range noAnnounce { + f, err := mamask.NewMask(addr) + if err == nil { + filters.AddFilter(*f, mafilter.ActionDeny) + continue + } + maddr, err := ma.NewMultiaddr(addr) + if err != nil { + return nil, err + } + noAnnAddrs[string(maddr.Bytes())] = true + } + + return func(allAddrs []ma.Multiaddr) []ma.Multiaddr { + var addrs []ma.Multiaddr + if len(annAddrs) > 0 { + addrs = annAddrs + } else { + addrs = allAddrs + } + + var out []ma.Multiaddr + for _, maddr := range addrs { + // check for exact matches + ok := noAnnAddrs[string(maddr.Bytes())] + // check for /ipcidr matches + if !ok && !filters.AddrBlocked(maddr) { + out = append(out, maddr) + } + } + return out + }, nil +} + +func AddrsFactory(announce []string, noAnnounce []string) func() (opts Libp2pOpts, err error) { + return func() (opts Libp2pOpts, err error) { + addrsFactory, err := makeAddrsFactory(announce, noAnnounce) + if err != nil { + return opts, err + } + opts.Opts = append(opts.Opts, libp2p.AddrsFactory(addrsFactory)) + return + } +} + +func listenAddresses(addresses []string) ([]ma.Multiaddr, error) { + var listen []ma.Multiaddr + for _, addr := range addresses { + maddr, err := ma.NewMultiaddr(addr) + if err != nil { + return nil, fmt.Errorf("failure to parse config.Addresses.Swarm: %s", addresses) + } + listen = append(listen, maddr) + } + + return listen, nil +} + +func StartListening(addresses []string) func(host host.Host) error { + return func(host host.Host) error { + listenAddrs, err := listenAddresses(addresses) + if err != nil { + return err + } + + // Actually start listening: + if err := host.Network().Listen(listenAddrs...); err != nil { + return err + } + + // list out our addresses + addrs, err := host.Network().InterfaceListenAddresses() + if err != nil { + return err + } + log.Infof("Swarm listening at: %s", addrs) + return nil + } +} diff --git a/node/modules/libp2p/discovery.go b/node/modules/libp2p/discovery.go new file mode 100644 index 000000000..a3bc4903e --- /dev/null +++ b/node/modules/libp2p/discovery.go @@ -0,0 +1,53 @@ +package libp2p + +import ( + "context" + "time" + + "github.com/libp2p/go-libp2p-core/host" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p/p2p/discovery" + "go.uber.org/fx" + + "github.com/filecoin-project/go-lotus/node/modules/helpers" +) + +const discoveryConnTimeout = time.Second * 30 + +type discoveryHandler struct { + ctx context.Context + host host.Host +} + +func (dh *discoveryHandler) HandlePeerFound(p peer.AddrInfo) { + log.Warning("trying peer info: ", p) + ctx, cancel := context.WithTimeout(dh.ctx, discoveryConnTimeout) + defer cancel() + if err := dh.host.Connect(ctx, p); err != nil { + log.Warning("Failed to connect to peer found by discovery: ", err) + } +} + +func DiscoveryHandler(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host) *discoveryHandler { + return &discoveryHandler{ + ctx: helpers.LifecycleCtx(mctx, lc), + host: host, + } +} + +func SetupDiscovery(mdns bool, mdnsInterval int) func(helpers.MetricsCtx, fx.Lifecycle, host.Host, *discoveryHandler) error { + return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, handler *discoveryHandler) error { + if mdns { + if mdnsInterval == 0 { + mdnsInterval = 5 + } + service, err := discovery.NewMdnsService(helpers.LifecycleCtx(mctx, lc), host, time.Duration(mdnsInterval)*time.Second, discovery.ServiceTag) + if err != nil { + log.Error("mdns error: ", err) + return nil + } + service.RegisterNotifee(handler) + } + return nil + } +} diff --git a/node/modules/libp2p/host.go b/node/modules/libp2p/host.go new file mode 100644 index 000000000..10a830e97 --- /dev/null +++ b/node/modules/libp2p/host.go @@ -0,0 +1,98 @@ +package libp2p + +import ( + "context" + "fmt" + + "github.com/ipfs/go-datastore" + nilrouting "github.com/ipfs/go-ipfs-routing/none" + "github.com/libp2p/go-libp2p" + host "github.com/libp2p/go-libp2p-core/host" + peer "github.com/libp2p/go-libp2p-core/peer" + peerstore "github.com/libp2p/go-libp2p-core/peerstore" + dht "github.com/libp2p/go-libp2p-kad-dht" + dhtopts "github.com/libp2p/go-libp2p-kad-dht/opts" + record "github.com/libp2p/go-libp2p-record" + routedhost "github.com/libp2p/go-libp2p/p2p/host/routed" + mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" + "go.uber.org/fx" + + "github.com/filecoin-project/go-lotus/node/modules/helpers" +) + +type P2PHostIn struct { + fx.In + + ID peer.ID + Peerstore peerstore.Peerstore + + Opts [][]libp2p.Option `group:"libp2p"` +} + +// //////////////////////// + +type RawHost host.Host + +func Host(mctx helpers.MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (RawHost, error) { + ctx := helpers.LifecycleCtx(mctx, lc) + + pkey := params.Peerstore.PrivKey(params.ID) + if pkey == nil { + return nil, fmt.Errorf("missing private key for node ID: %s", params.ID.Pretty()) + } + + opts := []libp2p.Option{libp2p.Identity(pkey), libp2p.Peerstore(params.Peerstore), libp2p.NoListenAddrs} + for _, o := range params.Opts { + opts = append(opts, o...) + } + + h, err := libp2p.New(ctx, opts...) + if err != nil { + return nil, err + } + + lc.Append(fx.Hook{ + OnStop: func(ctx context.Context) error { + return h.Close() + }, + }) + + return h, nil +} + +func MockHost(mn mocknet.Mocknet, id peer.ID, ps peerstore.Peerstore) (RawHost, error) { + return mn.AddPeerWithPeerstore(id, ps) +} + +func DHTRouting(client bool) interface{} { + return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host RawHost, dstore datastore.Batching, validator record.Validator) (BaseIpfsRouting, error) { + ctx := helpers.LifecycleCtx(mctx, lc) + + d, err := dht.New( + ctx, host, + dhtopts.Client(client), + dhtopts.Datastore(dstore), + dhtopts.Validator(validator), + ) + + if err != nil { + return nil, err + } + + lc.Append(fx.Hook{ + OnStop: func(ctx context.Context) error { + return d.Close() + }, + }) + + return d, nil + } +} + +func NilRouting(mctx helpers.MetricsCtx) (BaseIpfsRouting, error) { + return nilrouting.ConstructNilRouting(mctx, nil, nil, nil) +} + +func RoutedHost(rh RawHost, r BaseIpfsRouting) host.Host { + return routedhost.Wrap(rh, r) +} diff --git a/node/modules/libp2p/libp2p.go b/node/modules/libp2p/libp2p.go new file mode 100644 index 000000000..f0c840279 --- /dev/null +++ b/node/modules/libp2p/libp2p.go @@ -0,0 +1,46 @@ +package libp2p + +import ( + "time" + + logging "github.com/ipfs/go-log" + "github.com/libp2p/go-libp2p" + "github.com/libp2p/go-libp2p-connmgr" + "github.com/libp2p/go-libp2p-core/crypto" + "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p-core/peerstore" + "go.uber.org/fx" +) + +var log = logging.Logger("p2pnode") + +type Libp2pOpts struct { + fx.Out + + Opts []libp2p.Option `group:"libp2p"` +} + +// Misc options + +func ConnectionManager(low, high int, grace time.Duration) func() (opts Libp2pOpts, err error) { + return func() (opts Libp2pOpts, err error) { + cm := connmgr.NewConnManager(low, high, grace) + opts.Opts = append(opts.Opts, libp2p.ConnectionManager(cm)) + return + } +} + +func PstoreAddSelfKeys(id peer.ID, sk crypto.PrivKey, ps peerstore.Peerstore) error { + if err := ps.AddPubKey(id, sk.GetPublic()); err != nil { + return err + } + + return ps.AddPrivKey(id, sk) +} + +func simpleOpt(opt libp2p.Option) func() (opts Libp2pOpts, err error) { + return func() (opts Libp2pOpts, err error) { + opts.Opts = append(opts.Opts, opt) + return + } +} diff --git a/node/modules/libp2p/nat.go b/node/modules/libp2p/nat.go new file mode 100644 index 000000000..c9507c6e8 --- /dev/null +++ b/node/modules/libp2p/nat.go @@ -0,0 +1,34 @@ +package libp2p + +/*import ( + "github.com/libp2p/go-libp2p" + autonat "github.com/libp2p/go-libp2p-autonat-svc" + host "github.com/libp2p/go-libp2p-core/host" + libp2pquic "github.com/libp2p/go-libp2p-quic-transport" + "go.uber.org/fx" + + "github.com/ipfs/go-ipfs/repo" + + "github.com/filecoin-project/go-lotus/node/modules/helpers" +) + +var NatPortMap = simpleOpt(libp2p.NATPortMap()) + +func AutoNATService(quic bool) func(repo repo.Repo, mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host) error { + return func(repo repo.Repo, mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host) error { + // collect private net option in case swarm.key is presented + opts, _, err := PNet(repo) + if err != nil { + // swarm key exists but was failed to decode + return err + } + + if quic { + opts.Opts = append(opts.Opts, libp2p.DefaultTransports, libp2p.Transport(libp2pquic.NewTransport)) + } + + _, err = autonat.NewAutoNATService(helpers.LifecycleCtx(mctx, lc), host, opts.Opts...) + return err + } +} +*/ \ No newline at end of file diff --git a/node/modules/libp2p/pnet.go b/node/modules/libp2p/pnet.go new file mode 100644 index 000000000..78769f9d8 --- /dev/null +++ b/node/modules/libp2p/pnet.go @@ -0,0 +1,71 @@ +package libp2p + +/*import ( + "bytes" + "context" + "fmt" + "time" + + "github.com/libp2p/go-libp2p" + host "github.com/libp2p/go-libp2p-core/host" + pnet "github.com/libp2p/go-libp2p-pnet" + "go.uber.org/fx" + + "github.com/ipfs/go-ipfs/repo" +) + +type PNetFingerprint []byte + +func PNet(repo repo.Repo) (opts Libp2pOpts, fp PNetFingerprint, err error) { + swarmkey, err := repo.SwarmKey() + if err != nil || swarmkey == nil { + return opts, nil, err + } + + protec, err := pnet.NewProtector(bytes.NewReader(swarmkey)) + if err != nil { + return opts, nil, fmt.Errorf("failed to configure private network: %s", err) + } + fp = protec.Fingerprint() + + opts.Opts = append(opts.Opts, libp2p.PrivateNetwork(protec)) + return opts, fp, nil +} + +func PNetChecker(repo repo.Repo, ph host.Host, lc fx.Lifecycle) error { + // TODO: better check? + swarmkey, err := repo.SwarmKey() + if err != nil || swarmkey == nil { + return err + } + + done := make(chan struct{}) + lc.Append(fx.Hook{ + OnStart: func(_ context.Context) error { + go func() { + t := time.NewTicker(30 * time.Second) + defer t.Stop() + + <-t.C // swallow one tick + for { + select { + case <-t.C: + if len(ph.Network().Peers()) == 0 { + log.Warning("We are in private network and have no peers.") + log.Warning("This might be configuration mistake.") + } + case <-done: + return + } + } + }() + return nil + }, + OnStop: func(_ context.Context) error { + close(done) + return nil + }, + }) + return nil +} +*/ \ No newline at end of file diff --git a/node/modules/libp2p/pubsub.go b/node/modules/libp2p/pubsub.go new file mode 100644 index 000000000..cd2a821cf --- /dev/null +++ b/node/modules/libp2p/pubsub.go @@ -0,0 +1,21 @@ +package libp2p + +import ( + host "github.com/libp2p/go-libp2p-core/host" + pubsub "github.com/libp2p/go-libp2p-pubsub" + "go.uber.org/fx" + + "github.com/filecoin-project/go-lotus/node/modules/helpers" +) + +func FloodSub(pubsubOptions ...pubsub.Option) interface{} { + return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host) (service *pubsub.PubSub, err error) { + return pubsub.NewFloodSub(helpers.LifecycleCtx(mctx, lc), host, pubsubOptions...) + } +} + +func GossipSub(pubsubOptions ...pubsub.Option) interface{} { + return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host) (service *pubsub.PubSub, err error) { + return pubsub.NewGossipSub(helpers.LifecycleCtx(mctx, lc), host, pubsubOptions...) + } +} diff --git a/node/modules/libp2p/relay.go b/node/modules/libp2p/relay.go new file mode 100644 index 000000000..7786316b3 --- /dev/null +++ b/node/modules/libp2p/relay.go @@ -0,0 +1,56 @@ +package libp2p + +import ( + "fmt" + + "github.com/libp2p/go-libp2p" + circuit "github.com/libp2p/go-libp2p-circuit" + coredisc "github.com/libp2p/go-libp2p-core/discovery" + routing "github.com/libp2p/go-libp2p-core/routing" + discovery "github.com/libp2p/go-libp2p-discovery" + basichost "github.com/libp2p/go-libp2p/p2p/host/basic" + relay "github.com/libp2p/go-libp2p/p2p/host/relay" + "go.uber.org/fx" + + "github.com/filecoin-project/go-lotus/node/modules/helpers" +) + +func Relay(disable, enableHop bool) func() (opts Libp2pOpts, err error) { + return func() (opts Libp2pOpts, err error) { + if disable { + // Enabled by default. + opts.Opts = append(opts.Opts, libp2p.DisableRelay()) + } else { + relayOpts := []circuit.RelayOpt{circuit.OptDiscovery} + if enableHop { + relayOpts = append(relayOpts, circuit.OptHop) + } + opts.Opts = append(opts.Opts, libp2p.EnableRelay(relayOpts...)) + } + return + } +} + +// TODO: should be use baseRouting or can we use higher level router here? +func Discovery(router BaseIpfsRouting) (coredisc.Discovery, error) { + crouter, ok := router.(routing.ContentRouting) + if !ok { + return nil, fmt.Errorf("no suitable routing for discovery") + } + + return discovery.NewRoutingDiscovery(crouter), nil +} + +// NOTE: only set when relayHop is set +func AdvertiseRelay(mctx helpers.MetricsCtx, d coredisc.Discovery) { + relay.Advertise(mctx, d) +} + +// NOTE: only set when relayHop is not set +func AutoRelay(mctx helpers.MetricsCtx, lc fx.Lifecycle, router BaseIpfsRouting, h RawHost, d coredisc.Discovery) error { + ctx := helpers.LifecycleCtx(mctx, lc) + + // TODO: review: LibP2P doesn't set this as host in config.go, why? + _ = relay.NewAutoRelay(ctx, h.(*basichost.BasicHost), d, router) + return nil +} diff --git a/node/modules/libp2p/routing.go b/node/modules/libp2p/routing.go new file mode 100644 index 000000000..c7f70d85f --- /dev/null +++ b/node/modules/libp2p/routing.go @@ -0,0 +1,70 @@ +package libp2p + +import ( + "context" + "sort" + + routing "github.com/libp2p/go-libp2p-core/routing" + dht "github.com/libp2p/go-libp2p-kad-dht" + record "github.com/libp2p/go-libp2p-record" + routinghelpers "github.com/libp2p/go-libp2p-routing-helpers" + "go.uber.org/fx" +) + +type BaseIpfsRouting routing.Routing + +type Router struct { + routing.Routing + + Priority int // less = more important +} + +type p2pRouterOut struct { + fx.Out + + Router Router `group:"routers"` +} + +func BaseRouting(lc fx.Lifecycle, in BaseIpfsRouting) (out p2pRouterOut, dr *dht.IpfsDHT) { + if dht, ok := in.(*dht.IpfsDHT); ok { + dr = dht + + lc.Append(fx.Hook{ + OnStop: func(ctx context.Context) error { + return dr.Close() + }, + }) + } + + return p2pRouterOut{ + Router: Router{ + Priority: 1000, + Routing: in, + }, + }, dr +} + +type p2pOnlineRoutingIn struct { + fx.In + + Routers []Router `group:"routers"` + Validator record.Validator +} + +func Routing(in p2pOnlineRoutingIn) routing.Routing { + routers := in.Routers + + sort.SliceStable(routers, func(i, j int) bool { + return routers[i].Priority < routers[j].Priority + }) + + irouters := make([]routing.Routing, len(routers)) + for i, v := range routers { + irouters[i] = v.Routing + } + + return routinghelpers.Tiered{ + Routers: irouters, + Validator: in.Validator, + } +} diff --git a/node/modules/libp2p/smux.go b/node/modules/libp2p/smux.go new file mode 100644 index 000000000..95e599ec2 --- /dev/null +++ b/node/modules/libp2p/smux.go @@ -0,0 +1,54 @@ +package libp2p + +import ( + "os" + "strings" + + "github.com/libp2p/go-libp2p" + smux "github.com/libp2p/go-libp2p-core/mux" + mplex "github.com/libp2p/go-libp2p-mplex" + yamux "github.com/libp2p/go-libp2p-yamux" +) + +func makeSmuxTransportOption(mplexExp bool) libp2p.Option { + const yamuxID = "/yamux/1.0.0" + const mplexID = "/mplex/6.7.0" + + ymxtpt := *yamux.DefaultTransport + ymxtpt.AcceptBacklog = 512 + + if os.Getenv("YAMUX_DEBUG") != "" { + ymxtpt.LogOutput = os.Stderr + } + + muxers := map[string]smux.Multiplexer{yamuxID: &ymxtpt} + if mplexExp { + muxers[mplexID] = mplex.DefaultTransport + } + + // Allow muxer preference order overriding + order := []string{yamuxID, mplexID} + if prefs := os.Getenv("LIBP2P_MUX_PREFS"); prefs != "" { + order = strings.Fields(prefs) + } + + opts := make([]libp2p.Option, 0, len(order)) + for _, id := range order { + tpt, ok := muxers[id] + if !ok { + log.Warning("unknown or duplicate muxer in LIBP2P_MUX_PREFS: %s", id) + continue + } + delete(muxers, id) + opts = append(opts, libp2p.Muxer(id, tpt)) + } + + return libp2p.ChainOptions(opts...) +} + +func SmuxTransport(mplex bool) func() (opts Libp2pOpts, err error) { + return func() (opts Libp2pOpts, err error) { + opts.Opts = append(opts.Opts, makeSmuxTransportOption(mplex)) + return + } +} diff --git a/node/modules/libp2p/transport.go b/node/modules/libp2p/transport.go new file mode 100644 index 000000000..526776ab3 --- /dev/null +++ b/node/modules/libp2p/transport.go @@ -0,0 +1,38 @@ +package libp2p + +import ( + "github.com/libp2p/go-libp2p" + metrics "github.com/libp2p/go-libp2p-core/metrics" + libp2pquic "github.com/libp2p/go-libp2p-quic-transport" + secio "github.com/libp2p/go-libp2p-secio" + tls "github.com/libp2p/go-libp2p-tls" +) + +var DefaultTransports = simpleOpt(libp2p.DefaultTransports) +var QUIC = simpleOpt(libp2p.Transport(libp2pquic.NewTransport)) + +func Security(enabled, preferTLS bool) interface{} { + if !enabled { + return func() (opts Libp2pOpts) { + // TODO: shouldn't this be Errorf to guarantee visibility? + log.Warningf(`Your IPFS node has been configured to run WITHOUT ENCRYPTED CONNECTIONS. + You will not be able to connect to any nodes configured to use encrypted connections`) + opts.Opts = append(opts.Opts, libp2p.NoSecurity) + return opts + } + } + return func() (opts Libp2pOpts) { + if preferTLS { + opts.Opts = append(opts.Opts, libp2p.ChainOptions(libp2p.Security(tls.ID, tls.New), libp2p.Security(secio.ID, secio.New))) + } else { + opts.Opts = append(opts.Opts, libp2p.ChainOptions(libp2p.Security(secio.ID, secio.New), libp2p.Security(tls.ID, tls.New))) + } + return opts + } +} + +func BandwidthCounter() (opts Libp2pOpts, reporter metrics.Reporter) { + reporter = metrics.NewBandwidthCounter() + opts.Opts = append(opts.Opts, libp2p.BandwidthReporter(reporter)) + return opts, reporter +} From 0779e7dc0078ad150c5ebd6cb25b25f4aee6b3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 1 Jul 2019 12:18:00 +0200 Subject: [PATCH 08/31] Build libp2p node License: MIT Signed-off-by: Jakub Sztandera --- go.mod | 28 +++++--- go.sum | 4 ++ node/builder.go | 137 ++++++++++++++++++++++++++++++++++++- node/modules/core.go | 12 ++++ node/modules/libp2p/nat.go | 10 ++- 5 files changed, 179 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 1b4a74f64..3ee42a8eb 100644 --- a/go.mod +++ b/go.mod @@ -4,17 +4,29 @@ go 1.12 require ( github.com/gorilla/rpc v1.2.0 - github.com/ipfs/go-ipfs-routing v0.1.0 // indirect - github.com/libp2p/go-libp2p v0.2.0 // indirect + 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-autonat-svc v0.1.0 // indirect - github.com/libp2p/go-libp2p-connmgr v0.1.0 // indirect + 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-kad-dht v0.1.1 // indirect - github.com/libp2p/go-libp2p-pubsub v0.1.0 // indirect - github.com/libp2p/go-libp2p-quic-transport v0.1.1 // indirect - github.com/libp2p/go-libp2p-routing-helpers v0.1.0 // indirect - github.com/libp2p/go-libp2p-tls v0.1.0 // indirect + 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-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 diff --git a/go.sum b/go.sum index 2fc8bcfb2..c4566263f 100644 --- a/go.sum +++ b/go.sum @@ -139,6 +139,7 @@ github.com/libp2p/go-libp2p-mplex v0.2.1 h1:E1xaJBQnbSiTHGI1gaBKmKhu1TUKkErKJnE8 github.com/libp2p/go-libp2p-mplex v0.2.1/go.mod h1:SC99Rxs8Vuzrf/6WhmH41kNn13TiYdAWNYHrwImKLnE= github.com/libp2p/go-libp2p-nat v0.0.4 h1:+KXK324yaY701On8a0aGjTnw8467kW3ExKcqW2wwmyw= github.com/libp2p/go-libp2p-nat v0.0.4/go.mod h1:N9Js/zVtAXqaeT99cXgTV9e75KpnWCvVOiGzlcHmBbY= +github.com/libp2p/go-libp2p-netutil v0.1.0 h1:zscYDNVEcGxyUpMd0JReUZTrpMfia8PmLKcKF72EAMQ= github.com/libp2p/go-libp2p-netutil v0.1.0/go.mod h1:3Qv/aDqtMLTUyQeundkKsA+YCThNdbQD54k3TqjpbFU= github.com/libp2p/go-libp2p-peer v0.2.0/go.mod h1:RCffaCvUyW2CJmG2gAWVqwePwW7JMgxjsHm7+J5kjWY= github.com/libp2p/go-libp2p-peerstore v0.1.0/go.mod h1:2CeHkQsr8svp4fZ+Oi9ykN1HBb6u0MOvdJ7YIsmcwtY= @@ -160,6 +161,7 @@ github.com/libp2p/go-libp2p-swarm v0.1.0 h1:HrFk2p0awrGEgch9JXK/qp/hfjqQfgNxpLWn github.com/libp2p/go-libp2p-swarm v0.1.0/go.mod h1:wQVsCdjsuZoc730CgOvh5ox6K8evllckjebkdiY5ta4= github.com/libp2p/go-libp2p-testing v0.0.2/go.mod h1:gvchhf3FQOtBdr+eFUABet5a4MBLK8jM3V4Zghvmi+E= github.com/libp2p/go-libp2p-testing v0.0.3/go.mod h1:gvchhf3FQOtBdr+eFUABet5a4MBLK8jM3V4Zghvmi+E= +github.com/libp2p/go-libp2p-testing v0.0.4 h1:Qev57UR47GcLPXWjrunv5aLIQGO4n9mhI/8/EIrEEFc= github.com/libp2p/go-libp2p-testing v0.0.4/go.mod h1:gvchhf3FQOtBdr+eFUABet5a4MBLK8jM3V4Zghvmi+E= github.com/libp2p/go-libp2p-tls v0.1.0 h1:o4bjjAdnUjNgJoPoDd0wUaZH7K+EenlNWJpgyXB3ulA= github.com/libp2p/go-libp2p-tls v0.1.0/go.mod h1:VZdoSWQDeNpIIAFJFv+6uqTqpnIIDHcqZQSTC/A1TT0= @@ -201,6 +203,7 @@ github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0X github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/miekg/dns v1.1.12 h1:WMhc1ik4LNkTg8U9l3hI1LvxKmIL+f1+WV/SZtCbDDA= github.com/miekg/dns v1.1.12/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= @@ -259,6 +262,7 @@ github.com/whyrusleeping/go-notifier v0.0.0-20170827234753-097c5d47330f h1:M/lL3 github.com/whyrusleeping/go-notifier v0.0.0-20170827234753-097c5d47330f/go.mod h1:cZNvX9cFybI01GriPRMXDtczuvUhgbcYr9iCGaNlRv8= github.com/whyrusleeping/mafmt v1.2.8 h1:TCghSl5kkwEE0j+sU/gudyhVMRlpBin8fMBBHg59EbA= github.com/whyrusleeping/mafmt v1.2.8/go.mod h1:faQJFPbLSxzD9xpA02ttW/tS9vZykNvXwGvqIpk20FA= +github.com/whyrusleeping/mdns v0.0.0-20180901202407-ef14215e6b30 h1:nMCC9Pwz1pxfC1Y6mYncdk+kq8d5aLx0Q+/gyZGE44M= github.com/whyrusleeping/mdns v0.0.0-20180901202407-ef14215e6b30/go.mod h1:j4l84WPFclQPj320J9gp0XwNKBb3U0zt5CBqjPp22G4= github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 h1:E9S12nwJwEOXe2d6gT6qxdvqMnNq+VnSsKPgm2ZZNds= github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7/go.mod h1:X2c0RVCI1eSUFI8eLcY3c0423ykwiUdxLJtkDvruhjI= diff --git a/node/builder.go b/node/builder.go index fb5ae6b78..74ffa6b63 100644 --- a/node/builder.go +++ b/node/builder.go @@ -2,20 +2,68 @@ package node import ( "context" + "reflect" + "time" + "github.com/ipfs/go-datastore" + ci "github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p-peerstore/pstoremem" "go.uber.org/fx" "github.com/filecoin-project/go-lotus/api" "github.com/filecoin-project/go-lotus/build" "github.com/filecoin-project/go-lotus/node/modules" + "github.com/filecoin-project/go-lotus/node/modules/helpers" + "github.com/filecoin-project/go-lotus/node/modules/libp2p" ) +var defaultListenAddrs = []string{ // TODO: better defaults? + "/ip4/0.0.0.0/tcp/4001", + "/ip6/::/tcp/4001", +} + func New(ctx context.Context) (api.API, error) { var resApi api.Struct + online := true + app := fx.New( - fx.Provide(modules.RandomPeerID), + fx.Provide(as(ctx, new(helpers.MetricsCtx))), + + //fx.Provide(modules.RandomPeerID), + randomIdentity(), + memrepo(), + + fx.Provide(modules.RecordValidator), + + ifOpt(online, + fx.Provide( + pstoremem.NewPeerstore, + + libp2p.DefaultTransports, + libp2p.Host, + libp2p.RoutedHost, + libp2p.DHTRouting(false), + + libp2p.DiscoveryHandler, + libp2p.AddrsFactory(nil, nil), + libp2p.SmuxTransport(true), + libp2p.Relay(true, false), + libp2p.Security(true, false), + + libp2p.BaseRouting, + libp2p.Routing, + + libp2p.NatPortMap, + libp2p.ConnectionManager(50, 200, 20 * time.Second), + ), + + fx.Invoke( + libp2p.PstoreAddSelfKeys, + libp2p.StartListening(defaultListenAddrs), + ), + ), fx.Invoke(versionApi(&resApi.Internal.Version)), fx.Invoke(idApi(&resApi.Internal.ID)), @@ -28,6 +76,40 @@ func New(ctx context.Context) (api.API, error) { return &resApi, nil } +// In-memory / testing + +func memrepo() fx.Option { + return fx.Provide( + func() datastore.Batching { + return datastore.NewMapDatastore() + }, + ) +} + +func randomIdentity() fx.Option { + sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512) + if err != nil { + return fx.Error(err) + } + + return fx.Options( + fx.Provide(as(sk, new(ci.PrivKey))), + fx.Provide(as(pk, new(ci.PubKey))), + fx.Provide(peer.IDFromPublicKey), + ) +} + +// UTILS + +func ifOpt(cond bool, options ...fx.Option) fx.Option { + if cond { + return fx.Options(options...) + } + return fx.Options() +} + +// API IMPL + // TODO: figure out a better way, this isn't usable in long term func idApi(set *func(ctx context.Context) (peer.ID, error)) func(id peer.ID) { return func(id peer.ID) { @@ -46,3 +128,56 @@ func versionApi(set *func(context.Context) (api.Version, error)) func() { } } } + +// from go-ipfs +// as casts input constructor to a given interface (if a value is given, it +// wraps it into a constructor). +// +// Note: this method may look like a hack, and in fact it is one. +// This is here only because https://github.com/uber-go/fx/issues/673 wasn't +// released yet +// +// Note 2: when making changes here, make sure this method stays at +// 100% coverage. This makes it less likely it will be terribly broken +func as(in interface{}, as interface{}) interface{} { + outType := reflect.TypeOf(as) + + if outType.Kind() != reflect.Ptr { + panic("outType is not a pointer") + } + + if reflect.TypeOf(in).Kind() != reflect.Func { + ctype := reflect.FuncOf(nil, []reflect.Type{outType.Elem()}, false) + + return reflect.MakeFunc(ctype, func(args []reflect.Value) (results []reflect.Value) { + out := reflect.New(outType.Elem()) + out.Elem().Set(reflect.ValueOf(in)) + + return []reflect.Value{out.Elem()} + }).Interface() + } + + inType := reflect.TypeOf(in) + + ins := make([]reflect.Type, inType.NumIn()) + outs := make([]reflect.Type, inType.NumOut()) + + for i := range ins { + ins[i] = inType.In(i) + } + outs[0] = outType.Elem() + for i := range outs[1:] { + outs[i+1] = inType.Out(i + 1) + } + + ctype := reflect.FuncOf(ins, outs, false) + + return reflect.MakeFunc(ctype, func(args []reflect.Value) (results []reflect.Value) { + outs := reflect.ValueOf(in).Call(args) + out := reflect.New(outType.Elem()) + out.Elem().Set(outs[0]) + outs[0] = out.Elem() + + return outs + }).Interface() +} diff --git a/node/modules/core.go b/node/modules/core.go index 11174d7d4..e1df17d71 100644 --- a/node/modules/core.go +++ b/node/modules/core.go @@ -1 +1,13 @@ package modules + +import ( + "github.com/libp2p/go-libp2p-core/peerstore" + record "github.com/libp2p/go-libp2p-record" +) + +// RecordValidator provides namesys compatible routing record validator +func RecordValidator(ps peerstore.Peerstore) record.Validator { + return record.NamespacedValidator{ + "pk": record.PublicKeyValidator{}, + } +} diff --git a/node/modules/libp2p/nat.go b/node/modules/libp2p/nat.go index c9507c6e8..5c37804c5 100644 --- a/node/modules/libp2p/nat.go +++ b/node/modules/libp2p/nat.go @@ -1,5 +1,9 @@ package libp2p +import ( + "github.com/libp2p/go-libp2p" +) + /*import ( "github.com/libp2p/go-libp2p" autonat "github.com/libp2p/go-libp2p-autonat-svc" @@ -12,8 +16,6 @@ package libp2p "github.com/filecoin-project/go-lotus/node/modules/helpers" ) -var NatPortMap = simpleOpt(libp2p.NATPortMap()) - func AutoNATService(quic bool) func(repo repo.Repo, mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host) error { return func(repo repo.Repo, mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host) error { // collect private net option in case swarm.key is presented @@ -31,4 +33,6 @@ func AutoNATService(quic bool) func(repo repo.Repo, mctx helpers.MetricsCtx, lc return err } } -*/ \ No newline at end of file +*/ + +var NatPortMap = simpleOpt(libp2p.NATPortMap()) From 088c1e78603a6bcdb2c744fc419c9c5d5cbd92f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 1 Jul 2019 12:53:58 +0200 Subject: [PATCH 09/31] Confgure PNet License: MIT Signed-off-by: Jakub Sztandera --- go.mod | 1 + go.sum | 4 ++++ node/builder.go | 1 + node/modules/libp2p/pnet.go | 22 +++++++--------------- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 3ee42a8eb..2c39a90e8 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( 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 diff --git a/go.sum b/go.sum index c4566263f..f576c60f7 100644 --- a/go.sum +++ b/go.sum @@ -21,6 +21,8 @@ github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmf github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018 h1:6xT9KW8zLC5IlbaIF5Q7JNieBoACT7iW0YTxQHR0in0= +github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018/go.mod h1:rQYf4tfk5sSwFsnDg3qYaBxSjsD9S8+59vW0dKUgme4= github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ= github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= @@ -145,6 +147,8 @@ github.com/libp2p/go-libp2p-peer v0.2.0/go.mod h1:RCffaCvUyW2CJmG2gAWVqwePwW7JMg github.com/libp2p/go-libp2p-peerstore v0.1.0/go.mod h1:2CeHkQsr8svp4fZ+Oi9ykN1HBb6u0MOvdJ7YIsmcwtY= github.com/libp2p/go-libp2p-peerstore v0.1.1 h1:AJZF2sPpVo+0aAr3IrRiGVsPjJm1INlUQ9EGClgXJ4M= github.com/libp2p/go-libp2p-peerstore v0.1.1/go.mod h1:ojEWnwG7JpJLkJ9REWYXQslyu9ZLrPWPEcCdiZzEbSM= +github.com/libp2p/go-libp2p-pnet v0.1.0 h1:kRUES28dktfnHNIRW4Ro78F7rKBHBiw5MJpl0ikrLIA= +github.com/libp2p/go-libp2p-pnet v0.1.0/go.mod h1:ZkyZw3d0ZFOex71halXRihWf9WH/j3OevcJdTmD0lyE= github.com/libp2p/go-libp2p-pubsub v0.1.0 h1:SmQeMa7IUv5vadh0fYgYsafWCBA1sCy5d/68kIYqGcU= github.com/libp2p/go-libp2p-pubsub v0.1.0/go.mod h1:ZwlKzRSe1eGvSIdU5bD7+8RZN/Uzw0t1Bp9R1znpR/Q= github.com/libp2p/go-libp2p-quic-transport v0.1.1 h1:MFMJzvsxIEDEVKzO89BnB/FgvMj9WI4GDGUW2ArDPUA= diff --git a/node/builder.go b/node/builder.go index 74ffa6b63..3e07fa5dd 100644 --- a/node/builder.go +++ b/node/builder.go @@ -42,6 +42,7 @@ func New(ctx context.Context) (api.API, error) { pstoremem.NewPeerstore, libp2p.DefaultTransports, + libp2p.PNet, libp2p.Host, libp2p.RoutedHost, libp2p.DHTRouting(false), diff --git a/node/modules/libp2p/pnet.go b/node/modules/libp2p/pnet.go index 78769f9d8..a3345bbdd 100644 --- a/node/modules/libp2p/pnet.go +++ b/node/modules/libp2p/pnet.go @@ -1,28 +1,19 @@ package libp2p -/*import ( - "bytes" - "context" +import ( "fmt" - "time" + "strings" "github.com/libp2p/go-libp2p" - host "github.com/libp2p/go-libp2p-core/host" pnet "github.com/libp2p/go-libp2p-pnet" - "go.uber.org/fx" - - "github.com/ipfs/go-ipfs/repo" ) +var lotusKey = "/key/swarm/psk/1.0.0/\n/base16/\n20c72398e6299c7bbc1b501fdcc8abe4f89f798e9b93b2d2bc02e3c29b6a088e" + type PNetFingerprint []byte -func PNet(repo repo.Repo) (opts Libp2pOpts, fp PNetFingerprint, err error) { - swarmkey, err := repo.SwarmKey() - if err != nil || swarmkey == nil { - return opts, nil, err - } - - protec, err := pnet.NewProtector(bytes.NewReader(swarmkey)) +func PNet() (opts Libp2pOpts, fp PNetFingerprint, err error) { + protec, err := pnet.NewProtector(strings.NewReader(lotusKey)) if err != nil { return opts, nil, fmt.Errorf("failed to configure private network: %s", err) } @@ -32,6 +23,7 @@ func PNet(repo repo.Repo) (opts Libp2pOpts, fp PNetFingerprint, err error) { return opts, fp, nil } +/* func PNetChecker(repo repo.Repo, ph host.Host, lc fx.Lifecycle) error { // TODO: better check? swarmkey, err := repo.SwarmKey() From 5736ac1d9dc3d4d8289056302c86ed00671145be Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 1 Jul 2019 22:00:22 +0200 Subject: [PATCH 10/31] go fmt License: MIT Signed-off-by: Jakub Sztandera --- api/client/client.go | 2 +- api/struct.go | 6 +++--- daemon/rpc.go | 1 - node/builder.go | 2 +- node/modules/core.go | 2 +- node/modules/helpers/helpers.go | 1 - node/modules/libp2p/pnet.go | 2 +- node/modules/testing.go | 2 +- rpclib/rpcClient.go | 6 +++--- rpclib/rpcServer.go | 2 +- rpclib/rpc_test.go | 6 +++--- 11 files changed, 15 insertions(+), 17 deletions(-) diff --git a/api/client/client.go b/api/client/client.go index 921c50478..6ffbf3437 100644 --- a/api/client/client.go +++ b/api/client/client.go @@ -9,4 +9,4 @@ func NewRPC(addr string) api.API { var res api.Struct rpclib.NewClient(addr, "Filecoin", &res.Internal) return &res -} \ No newline at end of file +} diff --git a/api/struct.go b/api/struct.go index e2c91b49b..a14982d24 100644 --- a/api/struct.go +++ b/api/struct.go @@ -7,8 +7,8 @@ import ( ) type Struct struct { - Internal struct{ - ID func(context.Context) (peer.ID, error) + Internal struct { + ID func(context.Context) (peer.ID, error) Version func(context.Context) (Version, error) } } @@ -21,4 +21,4 @@ func (c *Struct) Version(ctx context.Context) (Version, error) { return c.Internal.Version(ctx) } -var _ API = &Struct{} \ No newline at end of file +var _ API = &Struct{} diff --git a/daemon/rpc.go b/daemon/rpc.go index bc383cdbe..78df124c2 100644 --- a/daemon/rpc.go +++ b/daemon/rpc.go @@ -7,7 +7,6 @@ import ( "github.com/filecoin-project/go-lotus/rpclib" ) - func serveRPC(api api.API) error { rpcServer := rpclib.NewServer() rpcServer.Register("Filecoin", api) diff --git a/node/builder.go b/node/builder.go index 3e07fa5dd..0ddf431b6 100644 --- a/node/builder.go +++ b/node/builder.go @@ -57,7 +57,7 @@ func New(ctx context.Context) (api.API, error) { libp2p.Routing, libp2p.NatPortMap, - libp2p.ConnectionManager(50, 200, 20 * time.Second), + libp2p.ConnectionManager(50, 200, 20*time.Second), ), fx.Invoke( diff --git a/node/modules/core.go b/node/modules/core.go index e1df17d71..5bc21fcf5 100644 --- a/node/modules/core.go +++ b/node/modules/core.go @@ -8,6 +8,6 @@ import ( // RecordValidator provides namesys compatible routing record validator func RecordValidator(ps peerstore.Peerstore) record.Validator { return record.NamespacedValidator{ - "pk": record.PublicKeyValidator{}, + "pk": record.PublicKeyValidator{}, } } diff --git a/node/modules/helpers/helpers.go b/node/modules/helpers/helpers.go index 745bfcf46..4c3a04881 100644 --- a/node/modules/helpers/helpers.go +++ b/node/modules/helpers/helpers.go @@ -22,4 +22,3 @@ func LifecycleCtx(mctx MetricsCtx, lc fx.Lifecycle) context.Context { }) return ctx } - diff --git a/node/modules/libp2p/pnet.go b/node/modules/libp2p/pnet.go index a3345bbdd..805ed71bb 100644 --- a/node/modules/libp2p/pnet.go +++ b/node/modules/libp2p/pnet.go @@ -60,4 +60,4 @@ func PNetChecker(repo repo.Repo, ph host.Host, lc fx.Lifecycle) error { }) return nil } -*/ \ No newline at end of file +*/ diff --git a/node/modules/testing.go b/node/modules/testing.go index a8b4b3a1e..1634d67dd 100644 --- a/node/modules/testing.go +++ b/node/modules/testing.go @@ -19,4 +19,4 @@ func RandomPeerID() (peer.ID, error) { return "", err } return peer.ID(hash), nil -} \ No newline at end of file +} diff --git a/rpclib/rpcClient.go b/rpclib/rpcClient.go index 5607863b0..a8dc9b41e 100644 --- a/rpclib/rpcClient.go +++ b/rpclib/rpcClient.go @@ -12,7 +12,7 @@ import ( ) var ( - errorType = reflect.TypeOf(new(error)).Elem() + errorType = reflect.TypeOf(new(error)).Elem() contextType = reflect.TypeOf(new(context.Context)).Elem() ) @@ -80,7 +80,7 @@ func NewClient(addr string, namespace string, handler interface{}) { return out } - processError := func(err error) []reflect.Value{ + processError := func(err error) []reflect.Value { out := make([]reflect.Value, nout) if valOut != -1 { @@ -101,7 +101,7 @@ func NewClient(addr string, namespace string, handler interface{}) { fn := reflect.MakeFunc(ftyp, func(args []reflect.Value) (results []reflect.Value) { id := atomic.AddInt64(&idCtr, 1) - params := make([]param, len(args) - hasCtx) + params := make([]param, len(args)-hasCtx) for i, arg := range args[hasCtx:] { params[i] = param{ v: arg, diff --git a/rpclib/rpcServer.go b/rpclib/rpcServer.go index b0e039bfd..262f961df 100644 --- a/rpclib/rpcServer.go +++ b/rpclib/rpcServer.go @@ -151,7 +151,7 @@ func (s *RPCServer) Register(namespace string, r interface{}) { valOut, errOut, _ := processFuncOut(funcType) - fmt.Println(namespace+"."+method.Name) + fmt.Println(namespace + "." + method.Name) s.methods[namespace+"."+method.Name] = rpcHandler{ paramReceivers: recvs, diff --git a/rpclib/rpc_test.go b/rpclib/rpc_test.go index 7eb82b7c6..02efaf63c 100644 --- a/rpclib/rpc_test.go +++ b/rpclib/rpc_test.go @@ -167,7 +167,7 @@ func TestRPC(t *testing.T) { type CtxHandler struct { cancelled bool - i int + i int } func (h *CtxHandler) Test(ctx context.Context) { @@ -200,7 +200,7 @@ func TestCtx(t *testing.T) { } NewClient(testServ.URL, "CtxHandler", &client) - ctx, cancel := context.WithTimeout(context.Background(), 20 * time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Millisecond) defer cancel() client.Test(ctx) @@ -219,4 +219,4 @@ func TestCtx(t *testing.T) { if serverHandler.cancelled || serverHandler.i != 2 { t.Error("wrong serverHandler state") } -} \ No newline at end of file +} From 126fa8913a418fdc3c563791afe771f50532f3be Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Mon, 1 Jul 2019 22:26:59 +0200 Subject: [PATCH 11/31] Add golint config License: MIT Signed-off-by: Jakub Sztandera --- .golangci.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..d40bbb3a1 --- /dev/null +++ b/.golangci.yml @@ -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 From 1716db3d76eadf8f68272f606122a47c4fb9e72c Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 2 Jul 2019 11:19:48 +0200 Subject: [PATCH 12/31] Add gomod tidy check License: MIT Signed-off-by: Jakub Sztandera --- .circleci/config.yml | 9 +++++++++ go.mod | 3 +-- go.sum | 29 +++++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5e5b2b2a4..eb5503b96 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,6 +3,14 @@ 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: @@ -10,3 +18,4 @@ workflows: - go/lint - go/test: executor: go/circleci-golang + - mod-tidy-check diff --git a/go.mod b/go.mod index 2c39a90e8..5342528d4 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,10 @@ module github.com/filecoin-project/go-lotus go 1.12 require ( - github.com/gorilla/rpc v1.2.0 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-autonat-svc v0.1.0 // indirect 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 @@ -31,6 +29,7 @@ require ( 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 ) diff --git a/go.sum b/go.sum index f576c60f7..67b0c8bc9 100644 --- a/go.sum +++ b/go.sum @@ -20,27 +20,31 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018 h1:6xT9KW8zLC5IlbaIF5Q7JNieBoACT7iW0YTxQHR0in0= github.com/davidlazar/go-crypto v0.0.0-20170701192655-dcfb0a7ac018/go.mod h1:rQYf4tfk5sSwFsnDg3qYaBxSjsD9S8+59vW0dKUgme4= github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ= github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/go-check/check v0.0.0-20180628173108-788fd7840127 h1:0gkP6mzaMqkmpcJYCFOLkIBwI7xFExG03bbkOkCvUPI= github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk= github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/rpc v1.2.0 h1:WvvdC2lNeT1SP32zrIce5l0ECBfbAlmrmSBsuc57wfk= -github.com/gorilla/rpc v1.2.0/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= @@ -52,6 +56,7 @@ github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHh github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo= github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc= @@ -62,6 +67,7 @@ github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUP github.com/ipfs/go-datastore v0.0.1/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= github.com/ipfs/go-datastore v0.0.5 h1:q3OfiOZV5rlsK1H5V8benjeUApRfMGs4Mrhmr6NriQo= github.com/ipfs/go-datastore v0.0.5/go.mod h1:d4KVXhMt913cLBEI/PXAy6ko+W7e9AhyAKBGh803qeE= +github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps= github.com/ipfs/go-ds-badger v0.0.2/go.mod h1:Y3QpeSFWQf6MopLTiZD+VT6IC1yZqaGmjvRcKeSGij8= github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIykR4L04tMOYc= @@ -81,6 +87,7 @@ github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQ github.com/jackpal/go-nat-pmp v1.0.1 h1:i0LektDkO1QlrTm/cSuP+PyBCDnYvjPLGl4LdWEMiaA= github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jbenet/go-cienv v0.0.0-20150120210510-1bb1476777ec/go.mod h1:rGaEvXB4uRSZMmzKNLoXvTu1sfx+1kv/DojUlPrSZGs= +github.com/jbenet/go-cienv v0.1.0 h1:Vc/s0QbQtoxX8MwwSLWWh+xNNZvM3Lw7NsTcHrvvhMc= github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= github.com/jbenet/go-temp-err-catcher v0.0.0-20150120210811-aac704a3f4f2 h1:vhC1OXXiT9R2pczegwz6moDvuRpggaroAXhPIseh57A= github.com/jbenet/go-temp-err-catcher v0.0.0-20150120210811-aac704a3f4f2/go.mod h1:8GXXJV31xl8whumTzdZsTt3RnUIiPqzkyf7mxToRCMs= @@ -94,8 +101,10 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b h1:wxtKgYHEncAU00muMD06dzLiahtGM1eouRNOzVV7tdQ= github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/libp2p/go-addr-util v0.0.1 h1:TpTQm9cXVRVSKsYbgQ7GKc3KbbHVTnbostgGaDEP+88= github.com/libp2p/go-addr-util v0.0.1/go.mod h1:4ac6O7n9rIAKB1dnd+s8IbbMXkt+oBpzX4/+RACcnlQ= @@ -113,9 +122,8 @@ github.com/libp2p/go-libp2p v0.2.0 h1:hYJgMZYdcwHzDHKb/nLePrtuSP3LqkGIFOQ2aIbKOC github.com/libp2p/go-libp2p v0.2.0/go.mod h1:5nXHmf4Hs+NmkaMsmWcFJgUHTbYNpCfxr20lwus0p1c= github.com/libp2p/go-libp2p-autonat v0.1.0 h1:aCWAu43Ri4nU0ZPO7NyLzUvvfqd0nE3dX0R/ZGYVgOU= github.com/libp2p/go-libp2p-autonat v0.1.0/go.mod h1:1tLf2yXxiE/oKGtDwPYWTSYG3PtvYlJmg7NeVtPRqH8= -github.com/libp2p/go-libp2p-autonat-svc v0.1.0 h1:28IM7iWMDclZeVkpiFQaWVANwXwE7zLlpbnS7yXxrfs= -github.com/libp2p/go-libp2p-autonat-svc v0.1.0/go.mod h1:fqi8Obl/z3R4PFVLm8xFtZ6PBL9MlV/xumymRFkKq5A= github.com/libp2p/go-libp2p-blankhost v0.1.1/go.mod h1:pf2fvdLJPsC1FsVrNP3DUUvMzUts2dsLLBEpo1vW1ro= +github.com/libp2p/go-libp2p-blankhost v0.1.3 h1:0KycuXvPDhmehw0ASsg+s1o3IfXgCUDqfzAl94KEBOg= github.com/libp2p/go-libp2p-blankhost v0.1.3/go.mod h1:KML1//wiKR8vuuJO0y3LUd1uLv+tlkGTAr3jC0S5cLg= github.com/libp2p/go-libp2p-circuit v0.1.0 h1:eniLL3Y9aq/sryfyV1IAHj5rlvuyj3b7iz8tSiZpdhY= github.com/libp2p/go-libp2p-circuit v0.1.0/go.mod h1:Ahq4cY3V9VJcHcn1SBXjr78AbFkZeIRmfunbA7pmFh8= @@ -241,19 +249,25 @@ github.com/multiformats/go-multistream v0.1.0 h1:UpO6jrsjqs46mqAK3n6wKRYFhugss9A github.com/multiformats/go-multistream v0.1.0/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a h1:/eS3yfGjQKG+9kayBkj0ip1BGhq6zJ3eaVksphxAaek= github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0= +github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU= github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc h1:BCPnHtcboadS0DvysUuJXZ4lWVv5Bh5i7+tbIyi+ck4= @@ -280,6 +294,8 @@ go.uber.org/dig v1.7.0 h1:E5/L92iQTNJTjfgJF2KgU+/JpMaiuvK2DHLBj0+kSZk= go.uber.org/dig v1.7.0/go.mod h1:z+dSd2TP9Usi48jL8M3v63iSBVkiwtVyMKxMZYYauPg= go.uber.org/fx v1.9.0 h1:7OAz8ucp35AU8eydejpYG7QrbE8rLKzGhHbZlJi5LYY= go.uber.org/fx v1.9.0/go.mod h1:mFdUyAUuJ3w4jAckiKSKbldsxy1ojpAMJ+dVZg5Y0Aw= +go.uber.org/goleak v0.10.0 h1:G3eWbSNIskeRqtsN/1uI5B+eP73y3JUuBsv9AZjehb4= +go.uber.org/goleak v0.10.0/go.mod h1:VCZuO8V8mFPlL0F5J5GK1rtHV3DrFcQ1R8ryq7FK0aI= go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -306,6 +322,7 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -331,10 +348,14 @@ google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoA google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8 h1:Ggy3mWN4l3PUFPfSG0YB3n5fVYggzysUmiUQ89SnX6Y= gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8/go.mod h1:cKXr3E0k4aosgycml1b5z33BVV6hai1Kh7uDgFOkbcs= +gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 7864ec6ff31f19209c4079874770da025314b964 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 2 Jul 2019 11:42:22 +0200 Subject: [PATCH 13/31] Cache modules when checking mod-tidy License: MIT Signed-off-by: Jakub Sztandera --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index eb5503b96..10ad38c56 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,6 +9,7 @@ jobs: steps: - go/install-ssh - checkout + - go/mod-download - go/mod-tidy-check workflows: @@ -18,4 +19,5 @@ workflows: - go/lint - go/test: executor: go/circleci-golang + codecov-upload: true - mod-tidy-check From ef871ad997f35482ae5ed4541def2deebfe2fbfa Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 2 Jul 2019 11:47:41 +0200 Subject: [PATCH 14/31] Skip TestCtx License: MIT Signed-off-by: Jakub Sztandera --- rpclib/rpc_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/rpclib/rpc_test.go b/rpclib/rpc_test.go index 02efaf63c..84686f2cf 100644 --- a/rpclib/rpc_test.go +++ b/rpclib/rpc_test.go @@ -182,6 +182,7 @@ func (h *CtxHandler) Test(ctx context.Context) { } func TestCtx(t *testing.T) { + t.SkipNow() // setup server serverHandler := &CtxHandler{} From c0789892810eff8a65073537e6a91525dee5a4f1 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 2 Jul 2019 11:55:12 +0200 Subject: [PATCH 15/31] Disable codecov comments License: MIT Signed-off-by: Jakub Sztandera --- .codecov.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .codecov.yml diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 000000000..db2472009 --- /dev/null +++ b/.codecov.yml @@ -0,0 +1 @@ +comment: off From 7fdd369283ffadc6a12ade1013c2d1b6399b4ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 2 Jul 2019 14:40:25 +0200 Subject: [PATCH 16/31] Address review --- api/test/test.go | 8 ++--- daemon/cmd.go | 6 ++-- node/builder.go | 34 +++++++++++----------- node/modules/{libp2p => lp2p}/addrs.go | 2 +- node/modules/{libp2p => lp2p}/discovery.go | 2 +- node/modules/{libp2p => lp2p}/host.go | 2 +- node/modules/{libp2p => lp2p}/libp2p.go | 2 +- node/modules/{libp2p => lp2p}/nat.go | 2 +- node/modules/{libp2p => lp2p}/pnet.go | 2 +- node/modules/{libp2p => lp2p}/pubsub.go | 2 +- node/modules/{libp2p => lp2p}/relay.go | 2 +- node/modules/{libp2p => lp2p}/routing.go | 2 +- node/modules/{libp2p => lp2p}/smux.go | 4 +-- node/modules/{libp2p => lp2p}/transport.go | 2 +- rpclib/rpcServer.go | 5 ++++ 15 files changed, 41 insertions(+), 36 deletions(-) rename node/modules/{libp2p => lp2p}/addrs.go (99%) rename node/modules/{libp2p => lp2p}/discovery.go (98%) rename node/modules/{libp2p => lp2p}/host.go (99%) rename node/modules/{libp2p => lp2p}/libp2p.go (98%) rename node/modules/{libp2p => lp2p}/nat.go (98%) rename node/modules/{libp2p => lp2p}/pnet.go (98%) rename node/modules/{libp2p => lp2p}/pubsub.go (97%) rename node/modules/{libp2p => lp2p}/relay.go (99%) rename node/modules/{libp2p => lp2p}/routing.go (98%) rename node/modules/{libp2p => lp2p}/smux.go (93%) rename node/modules/{libp2p => lp2p}/transport.go (98%) diff --git a/api/test/test.go b/api/test/test.go index 6efa25196..8aa9bb1c4 100644 --- a/api/test/test.go +++ b/api/test/test.go @@ -8,14 +8,14 @@ import ( "github.com/filecoin-project/go-lotus/build" ) -type NodeBuilder func() api.API +type APIBuilder func() api.API type testSuite struct { - makeNode NodeBuilder + makeNode APIBuilder } -func TestApis(t *testing.T, nb NodeBuilder) { +func TestApis(t *testing.T, b APIBuilder) { ts := testSuite{ - makeNode: nb, + makeNode: b, } t.Run("version", ts.testVersion) diff --git a/daemon/cmd.go b/daemon/cmd.go index c73a66774..ab1ebd3c0 100644 --- a/daemon/cmd.go +++ b/daemon/cmd.go @@ -1,7 +1,7 @@ package daemon import ( - goctx "context" + "context" "gopkg.in/urfave/cli.v2" @@ -11,8 +11,8 @@ import ( var Cmd = &cli.Command{ Name: "daemon", Usage: "Start a lotus daemon process", - Action: func(context *cli.Context) error { - ctx := goctx.Background() + Action: func(cctx *cli.Context) error { + ctx := context.Background() api, err := node.New(ctx) if err != nil { diff --git a/node/builder.go b/node/builder.go index 0ddf431b6..6f6aea7ab 100644 --- a/node/builder.go +++ b/node/builder.go @@ -15,7 +15,7 @@ import ( "github.com/filecoin-project/go-lotus/build" "github.com/filecoin-project/go-lotus/node/modules" "github.com/filecoin-project/go-lotus/node/modules/helpers" - "github.com/filecoin-project/go-lotus/node/modules/libp2p" + "github.com/filecoin-project/go-lotus/node/modules/lp2p" ) var defaultListenAddrs = []string{ // TODO: better defaults? @@ -41,28 +41,28 @@ func New(ctx context.Context) (api.API, error) { fx.Provide( pstoremem.NewPeerstore, - libp2p.DefaultTransports, - libp2p.PNet, - libp2p.Host, - libp2p.RoutedHost, - libp2p.DHTRouting(false), + lp2p.DefaultTransports, + lp2p.PNet, + lp2p.Host, + lp2p.RoutedHost, + lp2p.DHTRouting(false), - libp2p.DiscoveryHandler, - libp2p.AddrsFactory(nil, nil), - libp2p.SmuxTransport(true), - libp2p.Relay(true, false), - libp2p.Security(true, false), + lp2p.DiscoveryHandler, + lp2p.AddrsFactory(nil, nil), + lp2p.SmuxTransport(true), + lp2p.Relay(true, false), + lp2p.Security(true, false), - libp2p.BaseRouting, - libp2p.Routing, + lp2p.BaseRouting, + lp2p.Routing, - libp2p.NatPortMap, - libp2p.ConnectionManager(50, 200, 20*time.Second), + lp2p.NatPortMap, + lp2p.ConnectionManager(50, 200, 20*time.Second), ), fx.Invoke( - libp2p.PstoreAddSelfKeys, - libp2p.StartListening(defaultListenAddrs), + lp2p.PstoreAddSelfKeys, + lp2p.StartListening(defaultListenAddrs), ), ), diff --git a/node/modules/libp2p/addrs.go b/node/modules/lp2p/addrs.go similarity index 99% rename from node/modules/libp2p/addrs.go rename to node/modules/lp2p/addrs.go index 703a959cb..8d34ef94e 100644 --- a/node/modules/libp2p/addrs.go +++ b/node/modules/lp2p/addrs.go @@ -1,4 +1,4 @@ -package libp2p +package lp2p import ( "fmt" diff --git a/node/modules/libp2p/discovery.go b/node/modules/lp2p/discovery.go similarity index 98% rename from node/modules/libp2p/discovery.go rename to node/modules/lp2p/discovery.go index a3bc4903e..8a96eff39 100644 --- a/node/modules/libp2p/discovery.go +++ b/node/modules/lp2p/discovery.go @@ -1,4 +1,4 @@ -package libp2p +package lp2p import ( "context" diff --git a/node/modules/libp2p/host.go b/node/modules/lp2p/host.go similarity index 99% rename from node/modules/libp2p/host.go rename to node/modules/lp2p/host.go index 10a830e97..0c7862742 100644 --- a/node/modules/libp2p/host.go +++ b/node/modules/lp2p/host.go @@ -1,4 +1,4 @@ -package libp2p +package lp2p import ( "context" diff --git a/node/modules/libp2p/libp2p.go b/node/modules/lp2p/libp2p.go similarity index 98% rename from node/modules/libp2p/libp2p.go rename to node/modules/lp2p/libp2p.go index f0c840279..229f05afe 100644 --- a/node/modules/libp2p/libp2p.go +++ b/node/modules/lp2p/libp2p.go @@ -1,4 +1,4 @@ -package libp2p +package lp2p import ( "time" diff --git a/node/modules/libp2p/nat.go b/node/modules/lp2p/nat.go similarity index 98% rename from node/modules/libp2p/nat.go rename to node/modules/lp2p/nat.go index 5c37804c5..4b77dc113 100644 --- a/node/modules/libp2p/nat.go +++ b/node/modules/lp2p/nat.go @@ -1,4 +1,4 @@ -package libp2p +package lp2p import ( "github.com/libp2p/go-libp2p" diff --git a/node/modules/libp2p/pnet.go b/node/modules/lp2p/pnet.go similarity index 98% rename from node/modules/libp2p/pnet.go rename to node/modules/lp2p/pnet.go index 805ed71bb..c388448c2 100644 --- a/node/modules/libp2p/pnet.go +++ b/node/modules/lp2p/pnet.go @@ -1,4 +1,4 @@ -package libp2p +package lp2p import ( "fmt" diff --git a/node/modules/libp2p/pubsub.go b/node/modules/lp2p/pubsub.go similarity index 97% rename from node/modules/libp2p/pubsub.go rename to node/modules/lp2p/pubsub.go index cd2a821cf..b8ecbc0c8 100644 --- a/node/modules/libp2p/pubsub.go +++ b/node/modules/lp2p/pubsub.go @@ -1,4 +1,4 @@ -package libp2p +package lp2p import ( host "github.com/libp2p/go-libp2p-core/host" diff --git a/node/modules/libp2p/relay.go b/node/modules/lp2p/relay.go similarity index 99% rename from node/modules/libp2p/relay.go rename to node/modules/lp2p/relay.go index 7786316b3..651ac0b47 100644 --- a/node/modules/libp2p/relay.go +++ b/node/modules/lp2p/relay.go @@ -1,4 +1,4 @@ -package libp2p +package lp2p import ( "fmt" diff --git a/node/modules/libp2p/routing.go b/node/modules/lp2p/routing.go similarity index 98% rename from node/modules/libp2p/routing.go rename to node/modules/lp2p/routing.go index c7f70d85f..fe7f9d3f3 100644 --- a/node/modules/libp2p/routing.go +++ b/node/modules/lp2p/routing.go @@ -1,4 +1,4 @@ -package libp2p +package lp2p import ( "context" diff --git a/node/modules/libp2p/smux.go b/node/modules/lp2p/smux.go similarity index 93% rename from node/modules/libp2p/smux.go rename to node/modules/lp2p/smux.go index 95e599ec2..7b5f6847a 100644 --- a/node/modules/libp2p/smux.go +++ b/node/modules/lp2p/smux.go @@ -1,4 +1,4 @@ -package libp2p +package lp2p import ( "os" @@ -36,7 +36,7 @@ func makeSmuxTransportOption(mplexExp bool) libp2p.Option { for _, id := range order { tpt, ok := muxers[id] if !ok { - log.Warning("unknown or duplicate muxer in LIBP2P_MUX_PREFS: %s", id) + log.Warningf("unknown or duplicate muxer in LIBP2P_MUX_PREFS: %s", id) continue } delete(muxers, id) diff --git a/node/modules/libp2p/transport.go b/node/modules/lp2p/transport.go similarity index 98% rename from node/modules/libp2p/transport.go rename to node/modules/lp2p/transport.go index 526776ab3..b99e69468 100644 --- a/node/modules/libp2p/transport.go +++ b/node/modules/lp2p/transport.go @@ -1,4 +1,4 @@ -package libp2p +package lp2p import ( "github.com/libp2p/go-libp2p" diff --git a/rpclib/rpcServer.go b/rpclib/rpcServer.go index 262f961df..fde02bd1e 100644 --- a/rpclib/rpcServer.go +++ b/rpclib/rpcServer.go @@ -66,20 +66,24 @@ type response struct { Error *respError `json:"error,omitempty"` } +// TODO: return errors to clients per spec func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { var req request if err := json.NewDecoder(r.Body).Decode(&req); err != nil { + fmt.Println(err) w.WriteHeader(500) return } handler, ok := s.methods[req.Method] if !ok { + fmt.Println("rpcserver: unknown method") w.WriteHeader(500) return } if len(req.Params) != handler.nParams { + fmt.Println("rpcserver: wrong param count") w.WriteHeader(500) return } @@ -125,6 +129,7 @@ func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if err := json.NewEncoder(w).Encode(resp); err != nil { + fmt.Println(err) w.WriteHeader(500) return } From 4fcdd4a400f1641ca6bf73cf5a84435f534cd8dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 2 Jul 2019 15:05:43 +0200 Subject: [PATCH 17/31] Address some lint warnings --- api/api.go | 5 +++++ api/struct.go | 3 +++ api/test/test.go | 3 +++ cli/cmd.go | 1 + daemon/cmd.go | 1 + node/builder.go | 13 +++++++------ node/modules/testing.go | 1 + 7 files changed, 21 insertions(+), 6 deletions(-) diff --git a/api/api.go b/api/api.go index 9f100546a..0b39ac0ba 100644 --- a/api/api.go +++ b/api/api.go @@ -6,12 +6,14 @@ import ( "github.com/libp2p/go-libp2p-core/peer" ) +// Version provides various build-time information type Version struct { Version string // TODO: git commit / os / genesis cid? } +// API is a low-level interface to the Filecoin network type API interface { // chain @@ -71,6 +73,9 @@ type API interface { // // ID (on cli - print with other info) + // ID returns peerID of libp2p node backing this API ID(context.Context) (peer.ID, error) + + // Version provides information about API provider Version(context.Context) (Version, error) } diff --git a/api/struct.go b/api/struct.go index a14982d24..bd917f7cb 100644 --- a/api/struct.go +++ b/api/struct.go @@ -6,6 +6,7 @@ import ( "github.com/libp2p/go-libp2p-core/peer" ) +// Struct implements API passing calls to user-provided function values. type Struct struct { Internal struct { ID func(context.Context) (peer.ID, error) @@ -13,10 +14,12 @@ type Struct struct { } } +// ID implements API.ID func (c *Struct) ID(ctx context.Context) (peer.ID, error) { return c.Internal.ID(ctx) } +// Version implements API.Version func (c *Struct) Version(ctx context.Context) (Version, error) { return c.Internal.Version(ctx) } diff --git a/api/test/test.go b/api/test/test.go index 8aa9bb1c4..ecb298cf5 100644 --- a/api/test/test.go +++ b/api/test/test.go @@ -8,11 +8,14 @@ import ( "github.com/filecoin-project/go-lotus/build" ) +// APIBuilder is a function which is invoked in test suite to provide +// test nodes and networks type APIBuilder func() api.API type testSuite struct { makeNode APIBuilder } +// TestApis is the entry point to API test suite func TestApis(t *testing.T, b APIBuilder) { ts := testSuite{ makeNode: b, diff --git a/cli/cmd.go b/cli/cmd.go index f701a4401..994b47b4d 100644 --- a/cli/cmd.go +++ b/cli/cmd.go @@ -4,6 +4,7 @@ import ( "gopkg.in/urfave/cli.v2" ) +// Commands is the root group of CLI commands var Commands = []*cli.Command{ versionCmd, } diff --git a/daemon/cmd.go b/daemon/cmd.go index ab1ebd3c0..4e46e39ca 100644 --- a/daemon/cmd.go +++ b/daemon/cmd.go @@ -8,6 +8,7 @@ import ( "github.com/filecoin-project/go-lotus/node" ) +// Cmd is the `go-lotus daemon` command var Cmd = &cli.Command{ Name: "daemon", Usage: "Start a lotus daemon process", diff --git a/node/builder.go b/node/builder.go index 6f6aea7ab..5b94dcae1 100644 --- a/node/builder.go +++ b/node/builder.go @@ -23,8 +23,9 @@ var defaultListenAddrs = []string{ // TODO: better defaults? "/ip6/::/tcp/4001", } +// New builds and starts new Filecoin node func New(ctx context.Context) (api.API, error) { - var resApi api.Struct + var resAPI api.Struct online := true @@ -66,15 +67,15 @@ func New(ctx context.Context) (api.API, error) { ), ), - fx.Invoke(versionApi(&resApi.Internal.Version)), - fx.Invoke(idApi(&resApi.Internal.ID)), + fx.Invoke(versionAPI(&resAPI.Internal.Version)), + fx.Invoke(idAPI(&resAPI.Internal.ID)), ) if err := app.Start(ctx); err != nil { return nil, err } - return &resApi, nil + return &resAPI, nil } // In-memory / testing @@ -112,7 +113,7 @@ func ifOpt(cond bool, options ...fx.Option) fx.Option { // API IMPL // TODO: figure out a better way, this isn't usable in long term -func idApi(set *func(ctx context.Context) (peer.ID, error)) func(id peer.ID) { +func idAPI(set *func(ctx context.Context) (peer.ID, error)) func(id peer.ID) { return func(id peer.ID) { *set = func(ctx context.Context) (peer.ID, error) { return id, nil @@ -120,7 +121,7 @@ func idApi(set *func(ctx context.Context) (peer.ID, error)) func(id peer.ID) { } } -func versionApi(set *func(context.Context) (api.Version, error)) func() { +func versionAPI(set *func(context.Context) (api.Version, error)) func() { return func() { *set = func(context.Context) (api.Version, error) { return api.Version{ diff --git a/node/modules/testing.go b/node/modules/testing.go index 1634d67dd..814a2fb0b 100644 --- a/node/modules/testing.go +++ b/node/modules/testing.go @@ -9,6 +9,7 @@ import ( mh "github.com/multiformats/go-multihash" ) +// RandomPeerID generates random peer id func RandomPeerID() (peer.ID, error) { b, err := ioutil.ReadAll(io.LimitReader(rand.Reader, 32)) if err != nil { From bed044b5a1a0ee89a492496e01a303f4c4f532e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 2 Jul 2019 15:20:33 +0200 Subject: [PATCH 18/31] Fix TestCtx --- rpclib/rpcServer.go | 2 +- rpclib/rpc_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/rpclib/rpcServer.go b/rpclib/rpcServer.go index fde02bd1e..967ca1edf 100644 --- a/rpclib/rpcServer.go +++ b/rpclib/rpcServer.go @@ -77,7 +77,7 @@ func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { handler, ok := s.methods[req.Method] if !ok { - fmt.Println("rpcserver: unknown method") + fmt.Printf("rpcserver: unknown method %s\n", req.Method) w.WriteHeader(500) return } diff --git a/rpclib/rpc_test.go b/rpclib/rpc_test.go index 84686f2cf..df628c401 100644 --- a/rpclib/rpc_test.go +++ b/rpclib/rpc_test.go @@ -5,6 +5,7 @@ import ( "errors" "net/http/httptest" "strconv" + "sync/atomic" "testing" "time" ) @@ -167,12 +168,12 @@ func TestRPC(t *testing.T) { type CtxHandler struct { cancelled bool - i int + i int32 } func (h *CtxHandler) Test(ctx context.Context) { timeout := time.After(300 * time.Millisecond) - h.i++ + atomic.AddInt32(&h.i, 1) select { case <-timeout: @@ -182,13 +183,12 @@ func (h *CtxHandler) Test(ctx context.Context) { } func TestCtx(t *testing.T) { - t.SkipNow() // setup server serverHandler := &CtxHandler{} rpcServer := NewServer() - rpcServer.Register("SimpleServerHandler", serverHandler) + rpcServer.Register("CtxHandler", serverHandler) // httptest stuff testServ := httptest.NewServer(rpcServer) @@ -201,7 +201,7 @@ func TestCtx(t *testing.T) { } NewClient(testServ.URL, "CtxHandler", &client) - ctx, cancel := context.WithTimeout(context.Background(), 20*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) defer cancel() client.Test(ctx) @@ -217,7 +217,7 @@ func TestCtx(t *testing.T) { NewClient(testServ.URL, "CtxHandler", &noCtxClient) noCtxClient.Test() - if serverHandler.cancelled || serverHandler.i != 2 { + if serverHandler.cancelled || atomic.LoadInt32(&serverHandler.i) != 2 { t.Error("wrong serverHandler state") } } From 4d15bbdc6ff27682d4e68e1c256ec3fabc95284f Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 2 Jul 2019 15:25:00 +0200 Subject: [PATCH 19/31] Change linters License: MIT Signed-off-by: Jakub Sztandera --- .golangci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index d40bbb3a1..6ffacd4b2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,14 +7,23 @@ linters: - goconst - golint - errcheck + - gosec - unconvert - staticcheck - varcheck - structcheck - deadcode + issues: + exclude: + - "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this" + exclude-use-default: false + exclude-rules: + - path: node/modules/lp2p + linters: + - golint linters-settings: goconst: From f6450b1c1e4ef0856987fac54a5d1142ba5e8b9c Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 2 Jul 2019 15:29:30 +0200 Subject: [PATCH 20/31] Change executor to circleci License: MIT Signed-off-by: Jakub Sztandera --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 10ad38c56..0e8477fc2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,6 +17,7 @@ workflows: ci: jobs: - go/lint + executor: go/circleci-golang - go/test: executor: go/circleci-golang codecov-upload: true From e3f601263e58e544641afe7a16287cc4cf2e058c Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 2 Jul 2019 15:31:00 +0200 Subject: [PATCH 21/31] Fix previous change License: MIT Signed-off-by: Jakub Sztandera --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0e8477fc2..d2d6e997b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,7 +16,7 @@ workflows: version: 2 ci: jobs: - - go/lint + - go/lint: executor: go/circleci-golang - go/test: executor: go/circleci-golang From 573509b3e697c35d8c289fd11c36259e43b840e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 2 Jul 2019 15:49:10 +0200 Subject: [PATCH 22/31] rpclib: improve errors --- rpclib/rpcClient.go | 11 +++-------- rpclib/rpcServer.go | 48 ++++++++++++++++++++++++++++++++++++--------- rpclib/rpc_test.go | 20 ++++++++++++++----- 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/rpclib/rpcClient.go b/rpclib/rpcClient.go index a8dc9b41e..71175072a 100644 --- a/rpclib/rpcClient.go +++ b/rpclib/rpcClient.go @@ -64,7 +64,7 @@ func NewClient(addr string, namespace string, handler interface{}) { valOut, errOut, nout := processFuncOut(ftyp) - processResponse := func(resp clientResponse) []reflect.Value { + processResponse := func(resp clientResponse, code int) []reflect.Value { out := make([]reflect.Value, nout) if valOut != -1 { @@ -73,7 +73,7 @@ func NewClient(addr string, namespace string, handler interface{}) { if errOut != -1 { out[errOut] = reflect.New(errorType).Elem() if resp.Error != nil { - out[errOut].Set(reflect.ValueOf(errors.New(resp.Error.Message))) + out[errOut].Set(reflect.ValueOf(resp.Error)) } } @@ -139,11 +139,6 @@ func NewClient(addr string, namespace string, handler interface{}) { // process response - // TODO: check error codes in spec - if httpResp.StatusCode != 200 { - return processError(errors.New("non 200 response code")) - } - var resp clientResponse if valOut != -1 { resp.Result = result(reflect.New(ftyp.Out(valOut))) @@ -157,7 +152,7 @@ func NewClient(addr string, namespace string, handler interface{}) { return processError(errors.New("request and response id didn't match")) } - return processResponse(resp) + return processResponse(resp, httpResp.StatusCode) }) val.Elem().Field(i).Set(fn) diff --git a/rpclib/rpcServer.go b/rpclib/rpcServer.go index 967ca1edf..cb47898c0 100644 --- a/rpclib/rpcServer.go +++ b/rpclib/rpcServer.go @@ -8,6 +8,14 @@ import ( "reflect" ) +const ( + rpcParseError = -32700 + rpcInvalidRequest = -32600 + rpcMethodNotFound = -32601 + rpcInvalidParams = -32602 + rpcInternalError = -32603 +) + type rpcHandler struct { paramReceivers []reflect.Type nParams int @@ -59,6 +67,13 @@ type respError struct { Message string `json:"message"` } +func (e *respError) Error() string { + if e.Code >= -32768 && e.Code <= -32000 { + return fmt.Sprintf("RPC error (%d): %s", e.Code, e.Message) + } + return e.Message +} + type response struct { Jsonrpc string `json:"jsonrpc"` Result interface{} `json:"result,omitempty"` @@ -70,21 +85,18 @@ type response struct { func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { var req request if err := json.NewDecoder(r.Body).Decode(&req); err != nil { - fmt.Println(err) - w.WriteHeader(500) + s.rpcError(w, &req, rpcParseError, err) return } handler, ok := s.methods[req.Method] if !ok { - fmt.Printf("rpcserver: unknown method %s\n", req.Method) - w.WriteHeader(500) + s.rpcError(w, &req, rpcMethodNotFound, fmt.Errorf("method '%s' not found", req.Method)) return } if len(req.Params) != handler.nParams { - fmt.Println("rpcserver: wrong param count") - w.WriteHeader(500) + s.rpcError(w, &req, rpcInvalidParams, fmt.Errorf("wrong param count")) return } @@ -97,8 +109,7 @@ func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { for i := 0; i < handler.nParams; i++ { rp := reflect.New(handler.paramReceivers[i]) if err := json.NewDecoder(bytes.NewReader(req.Params[i].data)).Decode(rp.Interface()); err != nil { - w.WriteHeader(500) - fmt.Println(err) + s.rpcError(w, &req, rpcParseError, err) return } @@ -130,11 +141,28 @@ func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { if err := json.NewEncoder(w).Encode(resp); err != nil { fmt.Println(err) - w.WriteHeader(500) return } } +func (s *RPCServer) rpcError(w http.ResponseWriter, req *request, code int, err error) { + w.WriteHeader(500) + if req.Id == nil { // notification + return + } + + resp := response{ + Jsonrpc: "2.0", + Id: *req.Id, + Error: &respError{ + Code: code, + Message: err.(error).Error(), + }, + } + + _ = json.NewEncoder(w).Encode(resp) +} + func (s *RPCServer) Register(namespace string, r interface{}) { val := reflect.ValueOf(r) //TODO: expect ptr @@ -198,3 +226,5 @@ func processFuncOut(funcType reflect.Type) (valOut int, errOut int, n int) { return } + +var _ error = &respError{} diff --git a/rpclib/rpc_test.go b/rpclib/rpc_test.go index df628c401..cba6b870d 100644 --- a/rpclib/rpc_test.go +++ b/rpclib/rpc_test.go @@ -87,7 +87,7 @@ func TestRPC(t *testing.T) { t.Fatal("expected error") } if err.Error() != "test" { - t.Fatal("wrong error") + t.Fatal("wrong error", err) } // AddGet(int) int @@ -151,8 +151,8 @@ func TestRPC(t *testing.T) { NewClient(testServ.URL, "SimpleServerHandler", &erronly) _, err = erronly.AddGet() - if err == nil || err.Error() != "RPC client error: non 200 response code" { - t.Error("wrong error") + if err == nil || err.Error() != "RPC error (-32602): wrong param count" { + t.Error("wrong error:", err) } var wrongtype struct { @@ -161,8 +161,18 @@ func TestRPC(t *testing.T) { NewClient(testServ.URL, "SimpleServerHandler", &wrongtype) err = wrongtype.Add("not an int") - if err == nil || err.Error() != "RPC client error: non 200 response code" { - t.Error("wrong error") + if err == nil || err.Error() != "RPC error (-32700): json: cannot unmarshal string into Go value of type int" { + t.Error("wrong error:", err) + } + + var notfound struct { + NotThere func(string) error + } + NewClient(testServ.URL, "SimpleServerHandler", ¬found) + + err = notfound.NotThere("hello?") + if err == nil || err.Error() != "RPC error (-32601): method 'SimpleServerHandler.NotThere' not found" { + t.Error("wrong error:", err) } } From 661c7d633917a32aa5c41ec1213e28f696652d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 2 Jul 2019 19:30:37 +0200 Subject: [PATCH 23/31] rpclib: Address review --- rpclib/{rpcClient.go => rpc_client.go} | 0 rpclib/{rpcServer.go => rpc_server.go} | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename rpclib/{rpcClient.go => rpc_client.go} (100%) rename rpclib/{rpcServer.go => rpc_server.go} (99%) diff --git a/rpclib/rpcClient.go b/rpclib/rpc_client.go similarity index 100% rename from rpclib/rpcClient.go rename to rpclib/rpc_client.go diff --git a/rpclib/rpcServer.go b/rpclib/rpc_server.go similarity index 99% rename from rpclib/rpcServer.go rename to rpclib/rpc_server.go index cb47898c0..23abcb9bd 100644 --- a/rpclib/rpcServer.go +++ b/rpclib/rpc_server.go @@ -156,7 +156,7 @@ func (s *RPCServer) rpcError(w http.ResponseWriter, req *request, code int, err Id: *req.Id, Error: &respError{ Code: code, - Message: err.(error).Error(), + Message: err.Error(), }, } From 0f8f61fc7b476705f9821deeaf0993ed6d9f4f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 2 Jul 2019 19:45:03 +0200 Subject: [PATCH 24/31] more lint fixes --- api/client/client.go | 1 + build/version.go | 1 + node/modules/helpers/helpers.go | 1 + rpclib/rpc_client.go | 7 +++++++ rpclib/rpc_server.go | 9 +++++++-- 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/api/client/client.go b/api/client/client.go index 6ffbf3437..2aaa05579 100644 --- a/api/client/client.go +++ b/api/client/client.go @@ -5,6 +5,7 @@ import ( "github.com/filecoin-project/go-lotus/rpclib" ) +// NewRPC creates a new http jsonrpc client. func NewRPC(addr string) api.API { var res api.Struct rpclib.NewClient(addr, "Filecoin", &res.Internal) diff --git a/build/version.go b/build/version.go index 35b4aab6a..39e2ca1e2 100644 --- a/build/version.go +++ b/build/version.go @@ -1,3 +1,4 @@ package build +// Version is the local build version, set by build system const Version = "0.0.0" diff --git a/node/modules/helpers/helpers.go b/node/modules/helpers/helpers.go index 4c3a04881..f63b7eedd 100644 --- a/node/modules/helpers/helpers.go +++ b/node/modules/helpers/helpers.go @@ -6,6 +6,7 @@ import ( "go.uber.org/fx" ) +// MetricsCtx is a context wrapper with metrics type MetricsCtx context.Context // LifecycleCtx creates a context which will be cancelled when lifecycle stops diff --git a/rpclib/rpc_client.go b/rpclib/rpc_client.go index 71175072a..6e2fe8939 100644 --- a/rpclib/rpc_client.go +++ b/rpclib/rpc_client.go @@ -16,6 +16,7 @@ var ( contextType = reflect.TypeOf(new(context.Context)).Elem() ) +// ErrClient is an error which occured on the client side the library type ErrClient struct { err error } @@ -24,6 +25,7 @@ func (e *ErrClient) Error() string { return fmt.Sprintf("RPC client error: %s", e.err) } +// Unwrap unwraps the actual error func (e *ErrClient) Unwrap(err error) error { return e.err } @@ -41,6 +43,11 @@ type clientResponse struct { Error *respError `json:"error,omitempty"` } +// NewClient creates new josnrpc 2.0 client +// +// handler must be pointer to a struct with function fields +// +// TODO: Example func NewClient(addr string, namespace string, handler interface{}) { htyp := reflect.TypeOf(handler) if htyp.Kind() != reflect.Ptr { diff --git a/rpclib/rpc_server.go b/rpclib/rpc_server.go index 23abcb9bd..5d7813c6b 100644 --- a/rpclib/rpc_server.go +++ b/rpclib/rpc_server.go @@ -10,10 +10,10 @@ import ( const ( rpcParseError = -32700 - rpcInvalidRequest = -32600 +// rpcInvalidRequest = -32600 rpcMethodNotFound = -32601 rpcInvalidParams = -32602 - rpcInternalError = -32603 +// rpcInternalError = -32603 ) type rpcHandler struct { @@ -29,10 +29,12 @@ type rpcHandler struct { valOut int } +// RPCServer provides a jsonrpc 2.0 http server handler type RPCServer struct { methods map[string]rpcHandler } +// NewServer creates new RPCServer instance func NewServer() *RPCServer { return &RPCServer{ methods: map[string]rpcHandler{}, @@ -163,6 +165,9 @@ func (s *RPCServer) rpcError(w http.ResponseWriter, req *request, code int, err _ = json.NewEncoder(w).Encode(resp) } +// Register registers new RPC handler +// +// Handler is any value with methods defined func (s *RPCServer) Register(namespace string, r interface{}) { val := reflect.ValueOf(r) //TODO: expect ptr From 5eb60c7ce7c509dfb95f8e691becf084ce092a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 2 Jul 2019 21:08:30 +0200 Subject: [PATCH 25/31] rpclib: Id -> ID, fix TestCtx --- rpclib/rpc_client.go | 13 ++++++++----- rpclib/rpc_server.go | 14 ++++++-------- rpclib/rpc_test.go | 21 +++++++++++++++++---- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/rpclib/rpc_client.go b/rpclib/rpc_client.go index 6e2fe8939..7dbe60fb4 100644 --- a/rpclib/rpc_client.go +++ b/rpclib/rpc_client.go @@ -16,7 +16,7 @@ var ( contextType = reflect.TypeOf(new(context.Context)).Elem() ) -// ErrClient is an error which occured on the client side the library +// ErrClient is an error which occurred on the client side the library type ErrClient struct { err error } @@ -39,7 +39,7 @@ func (r *result) UnmarshalJSON(raw []byte) error { type clientResponse struct { Jsonrpc string `json:"jsonrpc"` Result result `json:"result"` - Id int64 `json:"id"` + ID int64 `json:"id"` Error *respError `json:"error,omitempty"` } @@ -117,7 +117,7 @@ func NewClient(addr string, namespace string, handler interface{}) { req := request{ Jsonrpc: "2.0", - Id: &id, + ID: &id, Method: namespace + "." + f.Name, Params: params, } @@ -142,7 +142,6 @@ func NewClient(addr string, namespace string, handler interface{}) { if err != nil { return processError(err) } - defer httpResp.Body.Close() // process response @@ -155,7 +154,11 @@ func NewClient(addr string, namespace string, handler interface{}) { return processError(err) } - if resp.Id != *req.Id { + if err := httpResp.Body.Close(); err != nil { + return processError(err) + } + + if resp.ID != *req.ID { return processError(errors.New("request and response id didn't match")) } diff --git a/rpclib/rpc_server.go b/rpclib/rpc_server.go index 5d7813c6b..5ef1560e7 100644 --- a/rpclib/rpc_server.go +++ b/rpclib/rpc_server.go @@ -10,10 +10,8 @@ import ( const ( rpcParseError = -32700 -// rpcInvalidRequest = -32600 rpcMethodNotFound = -32601 rpcInvalidParams = -32602 -// rpcInternalError = -32603 ) type rpcHandler struct { @@ -59,7 +57,7 @@ func (p *param) MarshalJSON() ([]byte, error) { type request struct { Jsonrpc string `json:"jsonrpc"` - Id *int64 `json:"id,omitempty"` + ID *int64 `json:"id,omitempty"` Method string `json:"method"` Params []param `json:"params"` } @@ -79,7 +77,7 @@ func (e *respError) Error() string { type response struct { Jsonrpc string `json:"jsonrpc"` Result interface{} `json:"result,omitempty"` - Id int64 `json:"id"` + ID int64 `json:"id"` Error *respError `json:"error,omitempty"` } @@ -119,13 +117,13 @@ func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { } callResult := handler.handlerFunc.Call(callParams) - if req.Id == nil { + if req.ID == nil { return // notification } resp := response{ Jsonrpc: "2.0", - Id: *req.Id, + ID: *req.ID, } if handler.errOut != -1 { @@ -149,13 +147,13 @@ func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (s *RPCServer) rpcError(w http.ResponseWriter, req *request, code int, err error) { w.WriteHeader(500) - if req.Id == nil { // notification + if req.ID == nil { // notification return } resp := response{ Jsonrpc: "2.0", - Id: *req.Id, + ID: *req.ID, Error: &respError{ Code: code, Message: err.Error(), diff --git a/rpclib/rpc_test.go b/rpclib/rpc_test.go index cba6b870d..2d39917d4 100644 --- a/rpclib/rpc_test.go +++ b/rpclib/rpc_test.go @@ -5,7 +5,7 @@ import ( "errors" "net/http/httptest" "strconv" - "sync/atomic" + "sync" "testing" "time" ) @@ -177,13 +177,17 @@ func TestRPC(t *testing.T) { } type CtxHandler struct { + lk sync.Mutex + cancelled bool - i int32 + i int } func (h *CtxHandler) Test(ctx context.Context) { + h.lk.Lock() + defer h.lk.Unlock() timeout := time.After(300 * time.Millisecond) - atomic.AddInt32(&h.i, 1) + h.i++ select { case <-timeout: @@ -215,19 +219,28 @@ func TestCtx(t *testing.T) { defer cancel() client.Test(ctx) + serverHandler.lk.Lock() + if !serverHandler.cancelled { t.Error("expected cancellation on the server side") } serverHandler.cancelled = false + serverHandler.lk.Unlock() + var noCtxClient struct { Test func() } NewClient(testServ.URL, "CtxHandler", &noCtxClient) noCtxClient.Test() - if serverHandler.cancelled || atomic.LoadInt32(&serverHandler.i) != 2 { + + serverHandler.lk.Lock() + + if serverHandler.cancelled || serverHandler.i != 2 { t.Error("wrong serverHandler state") } + + serverHandler.lk.Unlock() } From 7bf2fb52f4a2fde9ee29e1dba37d1a016c62019d Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 3 Jul 2019 13:24:20 +0200 Subject: [PATCH 26/31] Use zap for logging License: MIT Signed-off-by: Jakub Sztandera --- go.mod | 4 +--- go.sum | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5342528d4..f2f75bd9f 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ 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/ipfs/go-log v0.0.2-0.20190624152255-de7847a377fd 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 @@ -26,10 +26,8 @@ require ( 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 ) diff --git a/go.sum b/go.sum index 67b0c8bc9..5328d9873 100644 --- a/go.sum +++ b/go.sum @@ -80,6 +80,8 @@ github.com/ipfs/go-ipfs-util v0.0.1 h1:Wz9bL2wB2YBJqggkA4dD7oSmqB4cAnpNbGrlHJulv github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc= github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc= github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= +github.com/ipfs/go-log v0.0.2-0.20190624152255-de7847a377fd h1:3R1nq46WfCy1J1wD+bZHNCjvfC7uIL/L0F0hiuCVaQ0= +github.com/ipfs/go-log v0.0.2-0.20190624152255-de7847a377fd/go.mod h1:YTiqro5xwLoGra88hB8tMBlN+7ByaT3Kdaa0UqwCmI0= github.com/ipfs/go-todocounter v0.0.1 h1:kITWA5ZcQZfrUnDNkRn04Xzh0YFaDFXsoO2A81Eb6Lw= github.com/ipfs/go-todocounter v0.0.1/go.mod h1:l5aErvQc8qKE2r7NDMjmq5UNAvuZy0rC8BHOplkWvZ4= github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc= @@ -298,6 +300,8 @@ go.uber.org/goleak v0.10.0 h1:G3eWbSNIskeRqtsN/1uI5B+eP73y3JUuBsv9AZjehb4= go.uber.org/goleak v0.10.0/go.mod h1:VCZuO8V8mFPlL0F5J5GK1rtHV3DrFcQ1R8ryq7FK0aI= go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190225124518-7f87c0fbb88b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -319,6 +323,8 @@ golang.org/x/net v0.0.0-20190227160552-c95aed5357e7/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= From 51fc7af06cb48b1539cd27a0f47c798421ae7759 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 3 Jul 2019 13:37:13 +0200 Subject: [PATCH 27/31] fixup! Use zap for logging License: MIT Signed-off-by: Jakub Sztandera --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index f2f75bd9f..a729ed395 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ 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.2-0.20190624152255-de7847a377fd + github.com/ipfs/go-log v0.0.2-0.20190703113630-0c3cfb1eccc4 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 diff --git a/go.sum b/go.sum index 5328d9873..e05ad529d 100644 --- a/go.sum +++ b/go.sum @@ -82,6 +82,8 @@ github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc= github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= github.com/ipfs/go-log v0.0.2-0.20190624152255-de7847a377fd h1:3R1nq46WfCy1J1wD+bZHNCjvfC7uIL/L0F0hiuCVaQ0= github.com/ipfs/go-log v0.0.2-0.20190624152255-de7847a377fd/go.mod h1:YTiqro5xwLoGra88hB8tMBlN+7ByaT3Kdaa0UqwCmI0= +github.com/ipfs/go-log v0.0.2-0.20190703113630-0c3cfb1eccc4 h1:4GUopYwyu/8kX0UxYB7QDYOUbnt9HCg/j6J0sMqVvNQ= +github.com/ipfs/go-log v0.0.2-0.20190703113630-0c3cfb1eccc4/go.mod h1:YTiqro5xwLoGra88hB8tMBlN+7ByaT3Kdaa0UqwCmI0= github.com/ipfs/go-todocounter v0.0.1 h1:kITWA5ZcQZfrUnDNkRn04Xzh0YFaDFXsoO2A81Eb6Lw= github.com/ipfs/go-todocounter v0.0.1/go.mod h1:l5aErvQc8qKE2r7NDMjmq5UNAvuZy0rC8BHOplkWvZ4= github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc= From 2a350c6e829a326d9cf68945f8211f00aa55620d Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 3 Jul 2019 13:55:52 +0200 Subject: [PATCH 28/31] Use zap License: MIT Signed-off-by: Jakub Sztandera --- .gitignore | 1 + node/modules/lp2p/discovery.go | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..a8ed1beda --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +lotus diff --git a/node/modules/lp2p/discovery.go b/node/modules/lp2p/discovery.go index 8a96eff39..66111173d 100644 --- a/node/modules/lp2p/discovery.go +++ b/node/modules/lp2p/discovery.go @@ -20,11 +20,11 @@ type discoveryHandler struct { } func (dh *discoveryHandler) HandlePeerFound(p peer.AddrInfo) { - log.Warning("trying peer info: ", p) + log.Warnw("discovred peer", "peer", p) ctx, cancel := context.WithTimeout(dh.ctx, discoveryConnTimeout) defer cancel() if err := dh.host.Connect(ctx, p); err != nil { - log.Warning("Failed to connect to peer found by discovery: ", err) + log.Warnw("failed to connect to peer found by discovery", "error", err) } } @@ -43,7 +43,7 @@ func SetupDiscovery(mdns bool, mdnsInterval int) func(helpers.MetricsCtx, fx.Lif } service, err := discovery.NewMdnsService(helpers.LifecycleCtx(mctx, lc), host, time.Duration(mdnsInterval)*time.Second, discovery.ServiceTag) if err != nil { - log.Error("mdns error: ", err) + log.Errorw("mdns error", "error", err) return nil } service.RegisterNotifee(handler) From 217cb247a5e6bc6377535f699573511e342452b9 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 3 Jul 2019 14:30:21 +0200 Subject: [PATCH 29/31] Move to Warnf License: MIT Signed-off-by: Jakub Sztandera --- node/modules/lp2p/smux.go | 2 +- node/modules/lp2p/transport.go | 2 +- rpclib/rpc_client.go | 37 +++++++++++++++++++++++++++++----- rpclib/rpc_test.go | 24 ++++++++++++++-------- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/node/modules/lp2p/smux.go b/node/modules/lp2p/smux.go index 7b5f6847a..f5c74e18b 100644 --- a/node/modules/lp2p/smux.go +++ b/node/modules/lp2p/smux.go @@ -36,7 +36,7 @@ func makeSmuxTransportOption(mplexExp bool) libp2p.Option { for _, id := range order { tpt, ok := muxers[id] if !ok { - log.Warningf("unknown or duplicate muxer in LIBP2P_MUX_PREFS: %s", id) + log.Warnf("unknown or duplicate muxer in LIBP2P_MUX_PREFS: %s", id) continue } delete(muxers, id) diff --git a/node/modules/lp2p/transport.go b/node/modules/lp2p/transport.go index b99e69468..e4bb515fc 100644 --- a/node/modules/lp2p/transport.go +++ b/node/modules/lp2p/transport.go @@ -15,7 +15,7 @@ func Security(enabled, preferTLS bool) interface{} { if !enabled { return func() (opts Libp2pOpts) { // TODO: shouldn't this be Errorf to guarantee visibility? - log.Warningf(`Your IPFS node has been configured to run WITHOUT ENCRYPTED CONNECTIONS. + log.Warnf(`Your IPFS node has been configured to run WITHOUT ENCRYPTED CONNECTIONS. You will not be able to connect to any nodes configured to use encrypted connections`) opts.Opts = append(opts.Opts, libp2p.NoSecurity) return opts diff --git a/rpclib/rpc_client.go b/rpclib/rpc_client.go index 7dbe60fb4..073549e30 100644 --- a/rpclib/rpc_client.go +++ b/rpclib/rpc_client.go @@ -8,7 +8,6 @@ import ( "fmt" "net/http" "reflect" - "sync/atomic" ) var ( @@ -43,12 +42,15 @@ type clientResponse struct { Error *respError `json:"error,omitempty"` } +// ClientCloser is used to close Client from further use +type ClientCloser func() + // NewClient creates new josnrpc 2.0 client // // handler must be pointer to a struct with function fields -// +// Returned value closes the client from further use // TODO: Example -func NewClient(addr string, namespace string, handler interface{}) { +func NewClient(addr string, namespace string, handler interface{}) ClientCloser { htyp := reflect.TypeOf(handler) if htyp.Kind() != reflect.Ptr { panic("expected handler to be a pointer") @@ -58,9 +60,33 @@ func NewClient(addr string, namespace string, handler interface{}) { panic("handler should be a struct") } + closeChan := make(chan struct{}) + closer := func() { + close(closeChan) + } + val := reflect.ValueOf(handler) - var idCtr int64 + var ids <-chan int64 + { + idsChan := make(chan int64, 64) + + go func() { + var id int64 + + for { + select { + case idsChan <- id: + id++ + case _, ok := <-closeChan: + if !ok { + return + } + } + } + }() + ids = idsChan + } for i := 0; i < typ.NumField(); i++ { f := typ.Field(i) @@ -107,7 +133,7 @@ func NewClient(addr string, namespace string, handler interface{}) { } fn := reflect.MakeFunc(ftyp, func(args []reflect.Value) (results []reflect.Value) { - id := atomic.AddInt64(&idCtr, 1) + id := <-ids params := make([]param, len(args)-hasCtx) for i, arg := range args[hasCtx:] { params[i] = param{ @@ -167,4 +193,5 @@ func NewClient(addr string, namespace string, handler interface{}) { val.Elem().Field(i).Set(fn) } + return closer } diff --git a/rpclib/rpc_test.go b/rpclib/rpc_test.go index 2d39917d4..4879a3e3e 100644 --- a/rpclib/rpc_test.go +++ b/rpclib/rpc_test.go @@ -70,7 +70,8 @@ func TestRPC(t *testing.T) { AddGet func(int) int StringMatch func(t TestType, i2 int64) (out TestOut, err error) } - NewClient(testServ.URL, "SimpleServerHandler", &client) + closer := NewClient(testServ.URL, "SimpleServerHandler", &client) + defer closer() // Add(int) error @@ -129,51 +130,56 @@ func TestRPC(t *testing.T) { var noret struct { Add func(int) } - NewClient(testServ.URL, "SimpleServerHandler", &noret) + closer = NewClient(testServ.URL, "SimpleServerHandler", &noret) // this one should actually work noret.Add(4) if serverHandler.n != 9 { t.Error("expected 9") } + closer() var noparam struct { Add func() } - NewClient(testServ.URL, "SimpleServerHandler", &noparam) + closer = NewClient(testServ.URL, "SimpleServerHandler", &noparam) // shouldn't panic noparam.Add() + closer() var erronly struct { AddGet func() (int, error) } - NewClient(testServ.URL, "SimpleServerHandler", &erronly) + closer = NewClient(testServ.URL, "SimpleServerHandler", &erronly) _, err = erronly.AddGet() if err == nil || err.Error() != "RPC error (-32602): wrong param count" { t.Error("wrong error:", err) } + closer() var wrongtype struct { Add func(string) error } - NewClient(testServ.URL, "SimpleServerHandler", &wrongtype) + closer = NewClient(testServ.URL, "SimpleServerHandler", &wrongtype) err = wrongtype.Add("not an int") if err == nil || err.Error() != "RPC error (-32700): json: cannot unmarshal string into Go value of type int" { t.Error("wrong error:", err) } + closer() var notfound struct { NotThere func(string) error } - NewClient(testServ.URL, "SimpleServerHandler", ¬found) + closer = NewClient(testServ.URL, "SimpleServerHandler", ¬found) err = notfound.NotThere("hello?") if err == nil || err.Error() != "RPC error (-32601): method 'SimpleServerHandler.NotThere' not found" { t.Error("wrong error:", err) } + closer() } type CtxHandler struct { @@ -213,7 +219,7 @@ func TestCtx(t *testing.T) { var client struct { Test func(ctx context.Context) } - NewClient(testServ.URL, "CtxHandler", &client) + closer := NewClient(testServ.URL, "CtxHandler", &client) ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) defer cancel() @@ -228,11 +234,12 @@ func TestCtx(t *testing.T) { serverHandler.cancelled = false serverHandler.lk.Unlock() + closer() var noCtxClient struct { Test func() } - NewClient(testServ.URL, "CtxHandler", &noCtxClient) + closer = NewClient(testServ.URL, "CtxHandler", &noCtxClient) noCtxClient.Test() @@ -243,4 +250,5 @@ func TestCtx(t *testing.T) { } serverHandler.lk.Unlock() + closer() } From 7ed7af09fec3b947247e255649a3a74d9fe168d1 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 3 Jul 2019 14:38:43 +0200 Subject: [PATCH 30/31] Run go mod tidy License: MIT Signed-off-by: Jakub Sztandera --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index e05ad529d..513d9e062 100644 --- a/go.sum +++ b/go.sum @@ -80,8 +80,6 @@ github.com/ipfs/go-ipfs-util v0.0.1 h1:Wz9bL2wB2YBJqggkA4dD7oSmqB4cAnpNbGrlHJulv github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc= github.com/ipfs/go-log v0.0.1 h1:9XTUN/rW64BCG1YhPK9Hoy3q8nr4gOmHHBpgFdfw6Lc= github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= -github.com/ipfs/go-log v0.0.2-0.20190624152255-de7847a377fd h1:3R1nq46WfCy1J1wD+bZHNCjvfC7uIL/L0F0hiuCVaQ0= -github.com/ipfs/go-log v0.0.2-0.20190624152255-de7847a377fd/go.mod h1:YTiqro5xwLoGra88hB8tMBlN+7ByaT3Kdaa0UqwCmI0= github.com/ipfs/go-log v0.0.2-0.20190703113630-0c3cfb1eccc4 h1:4GUopYwyu/8kX0UxYB7QDYOUbnt9HCg/j6J0sMqVvNQ= github.com/ipfs/go-log v0.0.2-0.20190703113630-0c3cfb1eccc4/go.mod h1:YTiqro5xwLoGra88hB8tMBlN+7ByaT3Kdaa0UqwCmI0= github.com/ipfs/go-todocounter v0.0.1 h1:kITWA5ZcQZfrUnDNkRn04Xzh0YFaDFXsoO2A81Eb6Lw= From 24abfd22b800cbed2f2111cb6fa7870a3ec94872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 3 Jul 2019 16:32:31 +0200 Subject: [PATCH 31/31] Revert goroutine counter in rpc_client --- rpclib/rpc_client.go | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/rpclib/rpc_client.go b/rpclib/rpc_client.go index 073549e30..f8116c825 100644 --- a/rpclib/rpc_client.go +++ b/rpclib/rpc_client.go @@ -8,6 +8,7 @@ import ( "fmt" "net/http" "reflect" + "sync/atomic" ) var ( @@ -48,7 +49,7 @@ type ClientCloser func() // NewClient creates new josnrpc 2.0 client // // handler must be pointer to a struct with function fields -// Returned value closes the client from further use +// Returned value closes the client connection // TODO: Example func NewClient(addr string, namespace string, handler interface{}) ClientCloser { htyp := reflect.TypeOf(handler) @@ -60,33 +61,9 @@ func NewClient(addr string, namespace string, handler interface{}) ClientCloser panic("handler should be a struct") } - closeChan := make(chan struct{}) - closer := func() { - close(closeChan) - } - val := reflect.ValueOf(handler) - var ids <-chan int64 - { - idsChan := make(chan int64, 64) - - go func() { - var id int64 - - for { - select { - case idsChan <- id: - id++ - case _, ok := <-closeChan: - if !ok { - return - } - } - } - }() - ids = idsChan - } + var idCtr int64 for i := 0; i < typ.NumField(); i++ { f := typ.Field(i) @@ -133,7 +110,7 @@ func NewClient(addr string, namespace string, handler interface{}) ClientCloser } fn := reflect.MakeFunc(ftyp, func(args []reflect.Value) (results []reflect.Value) { - id := <-ids + id := atomic.AddInt64(&idCtr, 1) params := make([]param, len(args)-hasCtx) for i, arg := range args[hasCtx:] { params[i] = param{ @@ -193,5 +170,7 @@ func NewClient(addr string, namespace string, handler interface{}) ClientCloser val.Elem().Field(i).Set(fn) } - return closer + + // TODO: if this is still unused as of 2020, remove the closer stuff + return func() {} // noop for now, not for long though }