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] 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=