aboutsummaryrefslogtreecommitdiffstats
path: root/node/config.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-02-05 19:45:36 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-02-05 19:45:36 +0800
commita13bc9d7a1bc96fab93ace40045c0f0fea4da836 (patch)
treec6bd5be2e3e1ce06450a8611b2f1253b2ac18351 /node/config.go
parentba7c125153ce1be30985784a18edf38645406d03 (diff)
downloadgo-tangerine-a13bc9d7a1bc96fab93ace40045c0f0fea4da836.tar
go-tangerine-a13bc9d7a1bc96fab93ace40045c0f0fea4da836.tar.gz
go-tangerine-a13bc9d7a1bc96fab93ace40045c0f0fea4da836.tar.bz2
go-tangerine-a13bc9d7a1bc96fab93ace40045c0f0fea4da836.tar.lz
go-tangerine-a13bc9d7a1bc96fab93ace40045c0f0fea4da836.tar.xz
go-tangerine-a13bc9d7a1bc96fab93ace40045c0f0fea4da836.tar.zst
go-tangerine-a13bc9d7a1bc96fab93ace40045c0f0fea4da836.zip
cmd, common, node, rpc: move HTTP RPC into node, drop singletone aspect
Diffstat (limited to 'node/config.go')
-rw-r--r--node/config.go37
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.