mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-24 00:39:26 +00:00
p2p/discover: make discv5 response timeout configurable (#31119)
This commit is contained in:
parent
d2ca7cf9f1
commit
22b9354494
2 changed files with 9 additions and 5 deletions
|
|
@ -49,8 +49,9 @@ type Config struct {
|
||||||
// All remaining settings are optional.
|
// All remaining settings are optional.
|
||||||
|
|
||||||
// Packet handling configuration:
|
// Packet handling configuration:
|
||||||
NetRestrict *netutil.Netlist // list of allowed IP networks
|
NetRestrict *netutil.Netlist // list of allowed IP networks
|
||||||
Unhandled chan<- ReadPacket // unhandled packets are sent on this channel
|
Unhandled chan<- ReadPacket // unhandled packets are sent on this channel
|
||||||
|
V5RespTimeout time.Duration // timeout for v5 queries
|
||||||
|
|
||||||
// Node table configuration:
|
// Node table configuration:
|
||||||
Bootnodes []*enode.Node // list of bootstrap nodes
|
Bootnodes []*enode.Node // list of bootstrap nodes
|
||||||
|
|
@ -73,6 +74,9 @@ func (cfg Config) withDefaults() Config {
|
||||||
if cfg.RefreshInterval == 0 {
|
if cfg.RefreshInterval == 0 {
|
||||||
cfg.RefreshInterval = 30 * time.Minute
|
cfg.RefreshInterval = 30 * time.Minute
|
||||||
}
|
}
|
||||||
|
if cfg.V5RespTimeout == 0 {
|
||||||
|
cfg.V5RespTimeout = 700 * time.Millisecond
|
||||||
|
}
|
||||||
|
|
||||||
// Debug/test settings:
|
// Debug/test settings:
|
||||||
if cfg.Log == nil {
|
if cfg.Log == nil {
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,6 @@ const (
|
||||||
lookupRequestLimit = 3 // max requests against a single node during lookup
|
lookupRequestLimit = 3 // max requests against a single node during lookup
|
||||||
findnodeResultLimit = 16 // applies in FINDNODE handler
|
findnodeResultLimit = 16 // applies in FINDNODE handler
|
||||||
totalNodesResponseLimit = 5 // applies in waitForNodes
|
totalNodesResponseLimit = 5 // applies in waitForNodes
|
||||||
|
|
||||||
respTimeoutV5 = 700 * time.Millisecond
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// codecV5 is implemented by v5wire.Codec (and testCodec).
|
// codecV5 is implemented by v5wire.Codec (and testCodec).
|
||||||
|
|
@ -71,6 +69,7 @@ type UDPv5 struct {
|
||||||
log log.Logger
|
log log.Logger
|
||||||
clock mclock.Clock
|
clock mclock.Clock
|
||||||
validSchemes enr.IdentityScheme
|
validSchemes enr.IdentityScheme
|
||||||
|
respTimeout time.Duration
|
||||||
|
|
||||||
// misc buffers used during message handling
|
// misc buffers used during message handling
|
||||||
logcontext []interface{}
|
logcontext []interface{}
|
||||||
|
|
@ -158,6 +157,7 @@ func newUDPv5(conn UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv5, error) {
|
||||||
log: cfg.Log,
|
log: cfg.Log,
|
||||||
validSchemes: cfg.ValidSchemes,
|
validSchemes: cfg.ValidSchemes,
|
||||||
clock: cfg.Clock,
|
clock: cfg.Clock,
|
||||||
|
respTimeout: cfg.V5RespTimeout,
|
||||||
// channels into dispatch
|
// channels into dispatch
|
||||||
packetInCh: make(chan ReadPacket, 1),
|
packetInCh: make(chan ReadPacket, 1),
|
||||||
readNextCh: make(chan struct{}, 1),
|
readNextCh: make(chan struct{}, 1),
|
||||||
|
|
@ -576,7 +576,7 @@ func (t *UDPv5) startResponseTimeout(c *callV5) {
|
||||||
timer mclock.Timer
|
timer mclock.Timer
|
||||||
done = make(chan struct{})
|
done = make(chan struct{})
|
||||||
)
|
)
|
||||||
timer = t.clock.AfterFunc(respTimeoutV5, func() {
|
timer = t.clock.AfterFunc(t.respTimeout, func() {
|
||||||
<-done
|
<-done
|
||||||
select {
|
select {
|
||||||
case t.respTimeoutCh <- &callTimeout{c, timer}:
|
case t.respTimeoutCh <- &callTimeout{c, timer}:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue