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"
)
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)

View File

@ -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 {

View File

@ -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),
),
),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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)

View File

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

View File

@ -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
}