aboutsummaryrefslogtreecommitdiffstats
path: root/node
diff options
context:
space:
mode:
authorRyan Schneider <ryanleeschneider@gmail.com>2018-07-31 17:16:14 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-07-31 17:16:14 +0800
commit5d7e18539e32cb4f1aafab8e977e28a7cd34da9c (patch)
treee79ed9d9659c68f7961cca6c8fa84492c49e5084 /node
parentc4a1d4fecf5efcf5095c667b7b311061173799b4 (diff)
downloaddexon-5d7e18539e32cb4f1aafab8e977e28a7cd34da9c.tar
dexon-5d7e18539e32cb4f1aafab8e977e28a7cd34da9c.tar.gz
dexon-5d7e18539e32cb4f1aafab8e977e28a7cd34da9c.tar.bz2
dexon-5d7e18539e32cb4f1aafab8e977e28a7cd34da9c.tar.lz
dexon-5d7e18539e32cb4f1aafab8e977e28a7cd34da9c.tar.xz
dexon-5d7e18539e32cb4f1aafab8e977e28a7cd34da9c.tar.zst
dexon-5d7e18539e32cb4f1aafab8e977e28a7cd34da9c.zip
rpc: make HTTP RPC timeouts configurable, raise defaults (#17240)
* rpc: Make HTTP server timeout values configurable * rpc: Remove flags for setting HTTP Timeouts, configuring via .toml is sufficient. * rpc: Replace separate constants with a single default struct. * rpc: Update HTTP Server Read and Write Timeouts to 30s. * rpc: Remove redundant NewDefaultHTTPTimeouts function. * rpc: document HTTPTimeouts. * rpc: sanitize timeout values for library use
Diffstat (limited to 'node')
-rw-r--r--node/api.go2
-rw-r--r--node/config.go5
-rw-r--r--node/defaults.go2
-rw-r--r--node/node.go6
4 files changed, 11 insertions, 4 deletions
diff --git a/node/api.go b/node/api.go
index 117b76b6d..f44c99153 100644
--- a/node/api.go
+++ b/node/api.go
@@ -157,7 +157,7 @@ func (api *PrivateAdminAPI) StartRPC(host *string, port *int, cors *string, apis
}
}
- if err := api.node.startHTTP(fmt.Sprintf("%s:%d", *host, *port), api.node.rpcAPIs, modules, allowedOrigins, allowedVHosts); err != nil {
+ if err := api.node.startHTTP(fmt.Sprintf("%s:%d", *host, *port), api.node.rpcAPIs, modules, allowedOrigins, allowedVHosts, api.node.config.HTTPTimeouts); err != nil {
return false, err
}
return true, nil
diff --git a/node/config.go b/node/config.go
index 1b75baaeb..a4d5920a8 100644
--- a/node/config.go
+++ b/node/config.go
@@ -33,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover"
+ "github.com/ethereum/go-ethereum/rpc"
)
const (
@@ -119,6 +120,10 @@ type Config struct {
// exposed.
HTTPModules []string `toml:",omitempty"`
+ // HTTPTimeouts allows for customization of the timeout values used by the HTTP RPC
+ // interface.
+ HTTPTimeouts rpc.HTTPTimeouts
+
// 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 `toml:",omitempty"`
diff --git a/node/defaults.go b/node/defaults.go
index 887560580..c1376dba0 100644
--- a/node/defaults.go
+++ b/node/defaults.go
@@ -24,6 +24,7 @@ import (
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/nat"
+ "github.com/ethereum/go-ethereum/rpc"
)
const (
@@ -39,6 +40,7 @@ var DefaultConfig = Config{
HTTPPort: DefaultHTTPPort,
HTTPModules: []string{"net", "web3"},
HTTPVirtualHosts: []string{"localhost"},
+ HTTPTimeouts: rpc.DefaultHTTPTimeouts,
WSPort: DefaultWSPort,
WSModules: []string{"net", "web3"},
P2P: p2p.Config{
diff --git a/node/node.go b/node/node.go
index 7cc11b781..ada383721 100644
--- a/node/node.go
+++ b/node/node.go
@@ -263,7 +263,7 @@ func (n *Node) startRPC(services map[reflect.Type]Service) error {
n.stopInProc()
return err
}
- if err := n.startHTTP(n.httpEndpoint, apis, n.config.HTTPModules, n.config.HTTPCors, n.config.HTTPVirtualHosts); err != nil {
+ if err := n.startHTTP(n.httpEndpoint, apis, n.config.HTTPModules, n.config.HTTPCors, n.config.HTTPVirtualHosts, n.config.HTTPTimeouts); err != nil {
n.stopIPC()
n.stopInProc()
return err
@@ -331,12 +331,12 @@ func (n *Node) stopIPC() {
}
// startHTTP initializes and starts the HTTP RPC endpoint.
-func (n *Node) startHTTP(endpoint string, apis []rpc.API, modules []string, cors []string, vhosts []string) error {
+func (n *Node) startHTTP(endpoint string, apis []rpc.API, modules []string, cors []string, vhosts []string, timeouts rpc.HTTPTimeouts) error {
// Short circuit if the HTTP endpoint isn't being exposed
if endpoint == "" {
return nil
}
- listener, handler, err := rpc.StartHTTPEndpoint(endpoint, apis, modules, cors, vhosts)
+ listener, handler, err := rpc.StartHTTPEndpoint(endpoint, apis, modules, cors, vhosts, timeouts)
if err != nil {
return err
}