-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cmd | node/rpc): Make RPC port configurable and ensure port 0 used f…
…or swamp (#617)
- Loading branch information
Showing
14 changed files
with
117 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
flag "github.com/spf13/pflag" | ||
|
||
"github.com/celestiaorg/celestia-node/node" | ||
) | ||
|
||
var ( | ||
addrFlag = "rpc.addr" | ||
portFlag = "rpc.port" | ||
) | ||
|
||
// RPCFlags gives a set of hardcoded node/rpc package flags. | ||
func RPCFlags() *flag.FlagSet { | ||
flags := &flag.FlagSet{} | ||
|
||
flags.String( | ||
addrFlag, | ||
"", | ||
"Set a custom RPC listen address (default: localhost)", | ||
) | ||
flags.String( | ||
portFlag, | ||
"", | ||
"Set a custom RPC port (default: 26658)", | ||
) | ||
|
||
return flags | ||
} | ||
|
||
// ParseRPCFlags parses RPC flags from the given cmd and applies values to Env. | ||
func ParseRPCFlags(cmd *cobra.Command, env *Env) error { | ||
addr := cmd.Flag(addrFlag).Value.String() | ||
if addr != "" { | ||
env.AddOptions(node.WithRPCAddress(addr)) | ||
} | ||
port := cmd.Flag(portFlag).Value.String() | ||
if port != "" { | ||
env.AddOptions(node.WithRPCPort(port)) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package rpc | ||
|
||
import ( | ||
"go.uber.org/fx" | ||
) | ||
|
||
// ServerComponent constructs a new RPC Server from the given Config. | ||
// TODO @renaynay @Wondertan: this component is meant to be removed on implementation | ||
// of https://github.com/celestiaorg/celestia-node/pull/506. | ||
func ServerComponent(cfg Config) func(lc fx.Lifecycle) *Server { | ||
return func(lc fx.Lifecycle) *Server { | ||
serv := NewServer(cfg) | ||
lc.Append(fx.Hook{ | ||
OnStart: serv.Start, | ||
OnStop: serv.Stop, | ||
}) | ||
return serv | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
package rpc | ||
|
||
type Config struct { | ||
ListenAddr string | ||
Address string | ||
Port string | ||
} | ||
|
||
func DefaultConfig() Config { | ||
return Config{ | ||
Address: "0.0.0.0", | ||
// do NOT expose the same port as celestia-core by default so that both can run on the same machine | ||
ListenAddr: "0.0.0.0:26658", | ||
Port: "26658", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters