Add missing daemon files
This commit is contained in:
parent
145814d5c4
commit
a5441f8d17
54
cmd/lotus/daemon.go
Normal file
54
cmd/lotus/daemon.go
Normal file
@ -0,0 +1,54 @@
|
||||
// +build !nodaemon
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/multiformats/go-multiaddr"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
|
||||
"github.com/filecoin-project/go-lotus/node"
|
||||
"github.com/filecoin-project/go-lotus/node/repo"
|
||||
)
|
||||
|
||||
// DaemonCmd is the `go-lotus daemon` command
|
||||
var DaemonCmd = &cli.Command{
|
||||
Name: "daemon",
|
||||
Usage: "Start a lotus daemon process",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "api",
|
||||
Value: "1234",
|
||||
},
|
||||
},
|
||||
Action: func(cctx *cli.Context) error {
|
||||
ctx := context.Background()
|
||||
r, err := repo.NewFS(cctx.String("repo"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := r.Init(); err != nil && err != repo.ErrRepoExists {
|
||||
return err
|
||||
}
|
||||
|
||||
api, err := node.New(ctx,
|
||||
node.Online(),
|
||||
node.Repo(r),
|
||||
|
||||
node.Override(node.SetApiEndpointKey, func(lr repo.LockedRepo) error {
|
||||
apima, err := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/" + cctx.String("api"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return lr.SetAPIEndpoint(apima)
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: properly parse api endpoint (or make it a URL)
|
||||
return serveRPC(api, "127.0.0.1:"+cctx.String("api"))
|
||||
},
|
||||
}
|
24
cmd/lotus/daemon_nodaemon.go
Normal file
24
cmd/lotus/daemon_nodaemon.go
Normal file
@ -0,0 +1,24 @@
|
||||
// +build nodaemon
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
// DaemonCmd is the `go-lotus daemon` command
|
||||
var Cmd = &cli.Command{
|
||||
Name: "daemon",
|
||||
Usage: "Start a lotus daemon process",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "api",
|
||||
Value: ":1234",
|
||||
},
|
||||
},
|
||||
Action: func(cctx *cli.Context) error {
|
||||
return errors.New("daemon support not included in this binary")
|
||||
},
|
||||
}
|
15
cmd/lotus/rpc.go
Normal file
15
cmd/lotus/rpc.go
Normal file
@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/filecoin-project/go-lotus/api"
|
||||
"github.com/filecoin-project/go-lotus/lib/jsonrpc"
|
||||
)
|
||||
|
||||
func serveRPC(api api.API, addr string) error {
|
||||
rpcServer := jsonrpc.NewServer()
|
||||
rpcServer.Register("Filecoin", api)
|
||||
http.Handle("/rpc/v0", rpcServer)
|
||||
return http.ListenAndServe(addr, http.DefaultServeMux)
|
||||
}
|
Loading…
Reference in New Issue
Block a user