feat_: Add WS settings to the node config (#5346)

* feat_: add ability to enable http and ws connections from the client app
* feat_: add websocket option for api config
* fix_: use new api options in statusd
* chore_: add test for `overrideApiConfig`
This commit is contained in:
Mikhail Rogachev 2024-06-26 16:33:22 +02:00 committed by GitHub
parent 8480429cbb
commit 1ba4b86c7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 104 additions and 14 deletions

45
api/default_test.go Normal file
View File

@ -0,0 +1,45 @@
package api
import (
"testing"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/protocol/requests"
"github.com/stretchr/testify/require"
)
func TestOverrideApiConfig(t *testing.T) {
newNodeConfig := &params.NodeConfig{
APIModules: "test, eth, wakuv2",
ConnectorConfig: params.ConnectorConfig{Enabled: true},
HTTPEnabled: true,
HTTPHost: "0.0.0.0",
HTTPPort: 8545,
WSEnabled: false,
WSHost: "127.0.0.1",
WSPort: 8586,
}
apiConfig := &requests.APIConfig{
APIModules: "connector",
ConnectorEnabled: false,
HTTPEnabled: false,
HTTPHost: "127.0.0.1",
HTTPPort: 8080,
WSEnabled: true,
WSHost: "192.168.0.1",
WSPort: 7777,
}
overrideApiConfig(newNodeConfig, apiConfig)
require.Equal(t, apiConfig.APIModules, newNodeConfig.APIModules)
require.Equal(t, apiConfig.ConnectorEnabled, newNodeConfig.ConnectorConfig.Enabled)
require.Equal(t, apiConfig.HTTPEnabled, newNodeConfig.HTTPEnabled)
require.Equal(t, apiConfig.HTTPHost, newNodeConfig.HTTPHost)
require.Equal(t, apiConfig.HTTPPort, newNodeConfig.HTTPPort)
require.Equal(t, apiConfig.WSEnabled, newNodeConfig.WSEnabled)
require.Equal(t, apiConfig.WSHost, newNodeConfig.WSHost)
require.Equal(t, apiConfig.WSPort, newNodeConfig.WSPort)
}

View File

@ -215,6 +215,19 @@ func buildWalletConfig(request *requests.WalletSecretsConfig) params.WalletConfi
return walletConfig
}
func overrideApiConfig(nodeConfig *params.NodeConfig, config *requests.APIConfig) {
nodeConfig.APIModules = config.APIModules
nodeConfig.ConnectorConfig.Enabled = config.ConnectorEnabled
nodeConfig.HTTPEnabled = config.HTTPEnabled
nodeConfig.HTTPHost = config.HTTPHost
nodeConfig.HTTPPort = config.HTTPPort
nodeConfig.WSEnabled = config.WSEnabled
nodeConfig.WSHost = config.WSHost
nodeConfig.WSPort = config.WSPort
}
func defaultNodeConfig(installationID string, request *requests.CreateAccount, opts ...params.Option) (*params.NodeConfig, error) {
// Set mainnet
nodeConfig := &params.NodeConfig{}
@ -339,10 +352,7 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount, o
}
if request.APIConfig != nil {
nodeConfig.HTTPEnabled = true
nodeConfig.HTTPHost = request.APIConfig.HTTPHost
nodeConfig.HTTPPort = request.APIConfig.HTTPPort
nodeConfig.APIModules = request.APIConfig.APIModules
overrideApiConfig(nodeConfig, request.APIConfig)
}
for _, opt := range opts {

View File

@ -601,6 +601,10 @@ func (b *GethStatusBackend) loginAccount(request *requests.Login) error {
b.overrideNetworks(b.config, request)
if request.APIConfig != nil {
overrideApiConfig(b.config, request.APIConfig)
}
err = b.setupLogSettings()
if err != nil {
return errors.Wrap(err, "failed to setup log settings")

View File

@ -154,6 +154,9 @@ func randomNodeConfig() *params.NodeConfig {
HTTPPort: randomInt(math.MaxInt64),
HTTPVirtualHosts: randomStringSlice(),
HTTPCors: randomStringSlice(),
WSEnabled: false, // NOTE: leaving ws field idle since we are moving away from the storing the whole config
WSHost: "",
WSPort: 0,
IPCEnabled: randomBool(),
IPCFile: randomString(),
LogEnabled: randomBool(),

View File

@ -138,9 +138,10 @@ func createAccountAndLogin(b *api.GethStatusBackend, name, rootDataDir, password
RootDataDir: rootDataDir,
LogFilePath: "log",
APIConfig: &requests.APIConfig{
APIModules: apiModules,
HTTPHost: "127.0.0.1",
HTTPPort: port,
APIModules: apiModules,
HTTPEnabled: true,
HTTPHost: "127.0.0.1",
HTTPPort: port,
},
TelemetryServerURL: telemetryUrl,
}

View File

@ -211,9 +211,14 @@ func main() {
CustomizationColor: "0x000000",
BackupDisabledDataDir: config.DataDir,
APIConfig: &requests.APIConfig{
HTTPHost: config.HTTPHost,
HTTPPort: config.HTTPPort,
APIModules: config.APIModules,
ConnectorEnabled: config.ClusterConfig.Enabled,
HTTPEnabled: config.HTTPEnabled,
HTTPHost: config.HTTPHost,
HTTPPort: config.HTTPPort,
WSEnabled: config.WSEnabled,
WSHost: config.WSHost,
WSPort: config.WSPort,
APIModules: config.APIModules,
},
NetworkID: &config.NetworkID,
TestOverrideNetworks: config.Networks,

View File

@ -94,7 +94,6 @@ func newGethNodeConfig(config *params.NodeConfig) (*node.Config, error) {
MaxPeers: maxPeers,
MaxPendingPeers: maxPendingPeers,
},
HTTPModules: config.FormatAPIModules(),
}
if config.IPCEnabled {
@ -107,12 +106,19 @@ func newGethNodeConfig(config *params.NodeConfig) (*node.Config, error) {
}
if config.HTTPEnabled {
nc.HTTPModules = config.FormatAPIModules()
nc.HTTPHost = config.HTTPHost
nc.HTTPPort = config.HTTPPort
nc.HTTPVirtualHosts = config.HTTPVirtualHosts
nc.HTTPCors = config.HTTPCors
}
if config.WSEnabled {
nc.WSModules = config.FormatAPIModules()
nc.WSHost = config.WSHost
nc.WSPort = config.WSPort
}
if config.ClusterConfig.Enabled {
nc.P2P.BootstrapNodesV5 = parseNodesV5(config.ClusterConfig.BootNodes)
nc.P2P.StaticNodes = parseNodes(config.ClusterConfig.StaticNodes)

View File

@ -375,6 +375,15 @@ type NodeConfig struct {
// HTTPPort is the TCP port number on which to start the Geth's HTTP RPC server.
HTTPPort int
// WSEnabled specifies whether the Websocket RPC server is to be enabled by default.
WSEnabled bool
// WSHost is the host interface on which to start Geth's Websocket RPC server.
WSHost string
// WSPort is the TCP port number on which to start the Geth's Websocket RPC server.
WSPort int
// HTTPVirtualHosts is the list of virtual hostnames which are allowed on incoming requests.
// This is by default {'localhost'}. Using this prevents attacks like
// DNS rebinding, which bypasses SOP by simply masquerading as being within the same

View File

@ -21,9 +21,14 @@ type ImageCropRectangle struct {
}
type APIConfig struct {
APIModules string `json:"apiModules"`
HTTPHost string `json:"httpHost"`
HTTPPort int `json:"httpPort"`
APIModules string `json:"apiModules"`
ConnectorEnabled bool `json:"connectorEnabled"`
HTTPEnabled bool `json:"httpEnabled"`
HTTPHost string `json:"httpHost"`
HTTPPort int `json:"httpPort"`
WSEnabled bool `json:"wsEnabled"`
WSHost string `json:"wsHost"`
WSPort int `json:"wsPort"`
}
type CreateAccount struct {

View File

@ -34,6 +34,8 @@ type Login struct {
Mnemonic string `json:"mnemonic"`
WalletSecretsConfig
APIConfig *APIConfig `json:"apiConfig"`
}
func (c *Login) Validate() error {