Skip to content

Commit 22b9354

Browse files
authored
p2p/discover: make discv5 response timeout configurable (#31119)
1 parent d2ca7cf commit 22b9354

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

p2p/discover/common.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ type Config struct {
4949
// All remaining settings are optional.
5050

5151
// Packet handling configuration:
52-
NetRestrict *netutil.Netlist // list of allowed IP networks
53-
Unhandled chan<- ReadPacket // unhandled packets are sent on this channel
52+
NetRestrict *netutil.Netlist // list of allowed IP networks
53+
Unhandled chan<- ReadPacket // unhandled packets are sent on this channel
54+
V5RespTimeout time.Duration // timeout for v5 queries
5455

5556
// Node table configuration:
5657
Bootnodes []*enode.Node // list of bootstrap nodes
@@ -73,6 +74,9 @@ func (cfg Config) withDefaults() Config {
7374
if cfg.RefreshInterval == 0 {
7475
cfg.RefreshInterval = 30 * time.Minute
7576
}
77+
if cfg.V5RespTimeout == 0 {
78+
cfg.V5RespTimeout = 700 * time.Millisecond
79+
}
7680

7781
// Debug/test settings:
7882
if cfg.Log == nil {

p2p/discover/v5_udp.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ const (
4242
lookupRequestLimit = 3 // max requests against a single node during lookup
4343
findnodeResultLimit = 16 // applies in FINDNODE handler
4444
totalNodesResponseLimit = 5 // applies in waitForNodes
45-
46-
respTimeoutV5 = 700 * time.Millisecond
4745
)
4846

4947
// codecV5 is implemented by v5wire.Codec (and testCodec).
@@ -71,6 +69,7 @@ type UDPv5 struct {
7169
log log.Logger
7270
clock mclock.Clock
7371
validSchemes enr.IdentityScheme
72+
respTimeout time.Duration
7473

7574
// misc buffers used during message handling
7675
logcontext []interface{}
@@ -158,6 +157,7 @@ func newUDPv5(conn UDPConn, ln *enode.LocalNode, cfg Config) (*UDPv5, error) {
158157
log: cfg.Log,
159158
validSchemes: cfg.ValidSchemes,
160159
clock: cfg.Clock,
160+
respTimeout: cfg.V5RespTimeout,
161161
// channels into dispatch
162162
packetInCh: make(chan ReadPacket, 1),
163163
readNextCh: make(chan struct{}, 1),
@@ -576,7 +576,7 @@ func (t *UDPv5) startResponseTimeout(c *callV5) {
576576
timer mclock.Timer
577577
done = make(chan struct{})
578578
)
579-
timer = t.clock.AfterFunc(respTimeoutV5, func() {
579+
timer = t.clock.AfterFunc(t.respTimeout, func() {
580580
<-done
581581
select {
582582
case t.respTimeoutCh <- &callTimeout{c, timer}:

0 commit comments

Comments
 (0)