From f9b5343430a5f012ef92b783b584b114d9628da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 8 Jul 2019 22:50:13 +0200 Subject: [PATCH] daemon: allow setting listen addr --- cli/net.go | 4 +--- daemon/cmd.go | 8 +++++++- daemon/rpc.go | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cli/net.go b/cli/net.go index 2e1047589..16eaed2fd 100644 --- a/cli/net.go +++ b/cli/net.go @@ -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 -} \ No newline at end of file +} diff --git a/daemon/cmd.go b/daemon/cmd.go index 6e8ac2270..949d7001e 100644 --- a/daemon/cmd.go +++ b/daemon/cmd.go @@ -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")) }, } diff --git a/daemon/rpc.go b/daemon/rpc.go index 1426f38ce..48906cf55 100644 --- a/daemon/rpc.go +++ b/daemon/rpc.go @@ -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) }