cmd, node, rpc: move websockets into node, break singleton

This commit is contained in:
Péter Szilágyi
2016-02-05 15:08:48 +02:00
parent a13bc9d7a1
commit 7486904b92
11 changed files with 194 additions and 292 deletions

View File

@@ -117,6 +117,25 @@ type Config struct {
// If the module list is empty, all RPC API endpoints designated public will be
// exposed.
HttpModules []string
// WsHost is the host interface on which to start the websocket RPC server. If
// this field is empty, no websocket API endpoint will be started.
WsHost string
// WsPort is the TCP port number on which to start the websocket RPC server. The
// default zero value is/ valid and will pick a port number randomly (useful for
// ephemeral nodes).
WsPort int
// WsCors 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 websocket clients.
WsCors string
// WsModules is a list of API modules to expose via the websocket RPC interface.
// If the module list is empty, all RPC API endpoints designated public will be
// exposed.
WsModules []string
}
// IpcEndpoint resolves an IPC endpoint based on a configured value, taking into
@@ -165,6 +184,21 @@ func DefaultHttpEndpoint() string {
return config.HttpEndpoint()
}
// WsEndpoint resolves an websocket endpoint based on the configured host interface
// and port parameters.
func (c *Config) WsEndpoint() string {
if c.WsHost == "" {
return ""
}
return fmt.Sprintf("%s:%d", c.WsHost, c.WsPort)
}
// DefaultWsEndpoint returns the websocket endpoint used by default.
func DefaultWsEndpoint() string {
config := &Config{WsHost: common.DefaultWsHost, WsPort: common.DefaultWsPort}
return config.WsEndpoint()
}
// 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.