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 {