Address review

This commit is contained in:
Łukasz Magiera 2019-07-02 14:40:25 +02:00
parent c078989281
commit 7fdd369283
15 changed files with 41 additions and 36 deletions

View File

@ -8,14 +8,14 @@ import (
"github.com/filecoin-project/go-lotus/build" "github.com/filecoin-project/go-lotus/build"
) )
type NodeBuilder func() api.API type APIBuilder func() api.API
type testSuite struct { type testSuite struct {
makeNode NodeBuilder makeNode APIBuilder
} }
func TestApis(t *testing.T, nb NodeBuilder) { func TestApis(t *testing.T, b APIBuilder) {
ts := testSuite{ ts := testSuite{
makeNode: nb, makeNode: b,
} }
t.Run("version", ts.testVersion) t.Run("version", ts.testVersion)

View File

@ -1,7 +1,7 @@
package daemon package daemon
import ( import (
goctx "context" "context"
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
@ -11,8 +11,8 @@ import (
var Cmd = &cli.Command{ var Cmd = &cli.Command{
Name: "daemon", Name: "daemon",
Usage: "Start a lotus daemon process", Usage: "Start a lotus daemon process",
Action: func(context *cli.Context) error { Action: func(cctx *cli.Context) error {
ctx := goctx.Background() ctx := context.Background()
api, err := node.New(ctx) api, err := node.New(ctx)
if err != nil { if err != nil {

View File

@ -15,7 +15,7 @@ import (
"github.com/filecoin-project/go-lotus/build" "github.com/filecoin-project/go-lotus/build"
"github.com/filecoin-project/go-lotus/node/modules" "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/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? var defaultListenAddrs = []string{ // TODO: better defaults?
@ -41,28 +41,28 @@ func New(ctx context.Context) (api.API, error) {
fx.Provide( fx.Provide(
pstoremem.NewPeerstore, pstoremem.NewPeerstore,
libp2p.DefaultTransports, lp2p.DefaultTransports,
libp2p.PNet, lp2p.PNet,
libp2p.Host, lp2p.Host,
libp2p.RoutedHost, lp2p.RoutedHost,
libp2p.DHTRouting(false), lp2p.DHTRouting(false),
libp2p.DiscoveryHandler, lp2p.DiscoveryHandler,
libp2p.AddrsFactory(nil, nil), lp2p.AddrsFactory(nil, nil),
libp2p.SmuxTransport(true), lp2p.SmuxTransport(true),
libp2p.Relay(true, false), lp2p.Relay(true, false),
libp2p.Security(true, false), lp2p.Security(true, false),
libp2p.BaseRouting, lp2p.BaseRouting,
libp2p.Routing, lp2p.Routing,
libp2p.NatPortMap, lp2p.NatPortMap,
libp2p.ConnectionManager(50, 200, 20*time.Second), lp2p.ConnectionManager(50, 200, 20*time.Second),
), ),
fx.Invoke( fx.Invoke(
libp2p.PstoreAddSelfKeys, lp2p.PstoreAddSelfKeys,
libp2p.StartListening(defaultListenAddrs), lp2p.StartListening(defaultListenAddrs),
), ),
), ),

View File

@ -1,4 +1,4 @@
package libp2p package lp2p
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package libp2p package lp2p
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package libp2p package lp2p
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package libp2p package lp2p
import ( import (
"time" "time"

View File

@ -1,4 +1,4 @@
package libp2p package lp2p
import ( import (
"github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p"

View File

@ -1,4 +1,4 @@
package libp2p package lp2p
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package libp2p package lp2p
import ( import (
host "github.com/libp2p/go-libp2p-core/host" host "github.com/libp2p/go-libp2p-core/host"

View File

@ -1,4 +1,4 @@
package libp2p package lp2p
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package libp2p package lp2p
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package libp2p package lp2p
import ( import (
"os" "os"
@ -36,7 +36,7 @@ func makeSmuxTransportOption(mplexExp bool) libp2p.Option {
for _, id := range order { for _, id := range order {
tpt, ok := muxers[id] tpt, ok := muxers[id]
if !ok { 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 continue
} }
delete(muxers, id) delete(muxers, id)

View File

@ -1,4 +1,4 @@
package libp2p package lp2p
import ( import (
"github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p"

View File

@ -66,20 +66,24 @@ type response struct {
Error *respError `json:"error,omitempty"` Error *respError `json:"error,omitempty"`
} }
// TODO: return errors to clients per spec
func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var req request var req request
if err := json.NewDecoder(r.Body).Decode(&req); err != nil { if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
fmt.Println(err)
w.WriteHeader(500) w.WriteHeader(500)
return return
} }
handler, ok := s.methods[req.Method] handler, ok := s.methods[req.Method]
if !ok { if !ok {
fmt.Println("rpcserver: unknown method")
w.WriteHeader(500) w.WriteHeader(500)
return return
} }
if len(req.Params) != handler.nParams { if len(req.Params) != handler.nParams {
fmt.Println("rpcserver: wrong param count")
w.WriteHeader(500) w.WriteHeader(500)
return return
} }
@ -125,6 +129,7 @@ func (s *RPCServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
if err := json.NewEncoder(w).Encode(resp); err != nil { if err := json.NewEncoder(w).Encode(resp); err != nil {
fmt.Println(err)
w.WriteHeader(500) w.WriteHeader(500)
return return
} }