diff options
Diffstat (limited to 'node/config.go')
-rw-r--r-- | node/config.go | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/node/config.go b/node/config.go index d3eb1c78b..94c6e2e56 100644 --- a/node/config.go +++ b/node/config.go @@ -19,6 +19,7 @@ package node import ( "crypto/ecdsa" "encoding/json" + "fmt" "io/ioutil" "net" "os" @@ -97,6 +98,25 @@ type Config struct { // handshake phase, counted separately for inbound and outbound connections. // Zero defaults to preset values. MaxPendingPeers int + + // HttpHost is the host interface on which to start the HTTP RPC server. If this + // field is empty, no HTTP API endpoint will be started. + HttpHost string + + // HttpPort is the TCP port number on which to start the HTTP RPC server. The + // default zero value is/ valid and will pick a port number randomly (useful + // for ephemeral nodes). + HttpPort int + + // HttpCors is the Cross-Origin Resource Sharing header to send to requesting + // clients. Please be aware that CORS is a browser enforced security, it's fully + // useless for custom HTTP clients. + HttpCors string + + // HttpModules is a list of API modules to expose via the HTTP RPC interface. + // If the module list is empty, all RPC API endpoints designated public will be + // exposed. + HttpModules []string } // IpcEndpoint resolves an IPC endpoint based on a configured value, taking into @@ -126,10 +146,25 @@ func (c *Config) IpcEndpoint() string { // DefaultIpcEndpoint returns the IPC path used by default. func DefaultIpcEndpoint() string { - config := &Config{DataDir: common.DefaultDataDir(), IpcPath: common.DefaultIpcSocket()} + config := &Config{DataDir: common.DefaultDataDir(), IpcPath: common.DefaultIpcSocket} return config.IpcEndpoint() } +// HttpEndpoint resolves an HTTP endpoint based on the configured host interface +// and port parameters. +func (c *Config) HttpEndpoint() string { + if c.HttpHost == "" { + return "" + } + return fmt.Sprintf("%s:%d", c.HttpHost, c.HttpPort) +} + +// DefaultHttpEndpoint returns the HTTP endpoint used by default. +func DefaultHttpEndpoint() string { + config := &Config{HttpHost: common.DefaultHttpHost, HttpPort: common.DefaultHttpPort} + return config.HttpEndpoint() +} + // NodeKey retrieves the currently configured private key of the node, checking // first any manually set key, falling back to the one found in the configured // data folder. If no key can be found, a new one is generated. |