daemon: allow setting listen addr

This commit is contained in:
Łukasz Magiera 2019-07-08 22:50:13 +02:00
parent cdca2ff2c7
commit f9b5343430
3 changed files with 10 additions and 6 deletions

View File

@ -32,7 +32,6 @@ var netPeers = &cli.Command{
},
}
var netConnect = &cli.Command{
Name: "connect",
Usage: "Connect to a peer",
@ -57,7 +56,6 @@ var netConnect = &cli.Command{
},
}
// parseAddresses is a function that takes in a slice of string peer addresses
// (multiaddr + peerid) and returns a slice of properly constructed peers
func parseAddresses(ctx context.Context, addrs []string) ([]peer.AddrInfo, error) {
@ -133,4 +131,4 @@ func resolveAddresses(ctx context.Context, addrs []string) ([]ma.Multiaddr, erro
}
return maddrs, nil
}
}

View File

@ -13,6 +13,12 @@ import (
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 {
ctx := context.Background()
@ -26,6 +32,6 @@ var Cmd = &cli.Command{
return err
}
return serveRPC(api)
return serveRPC(api, cctx.String("api"))
},
}

View File

@ -7,9 +7,9 @@ import (
"github.com/filecoin-project/go-lotus/lib/jsonrpc"
)
func serveRPC(api api.API) error {
func serveRPC(api api.API, addr string) error {
rpcServer := jsonrpc.NewServer()
rpcServer.Register("Filecoin", api)
http.Handle("/rpc/v0", rpcServer)
return http.ListenAndServe(":1234", http.DefaultServeMux)
return http.ListenAndServe(addr, http.DefaultServeMux)
}