Skip to content

Commit 9123ece

Browse files
fjlkaralabe
authored andcommitted
p2p, p2p/discover: misc connectivity improvements (#16069)
* p2p: add DialRatio for configuration of inbound vs. dialed connections * p2p: add connection flags to PeerInfo * p2p/netutil: add SameNet, DistinctNetSet * p2p/discover: improve revalidation and seeding This changes node revalidation to be periodic instead of on-demand. This should prevent issues where dead nodes get stuck in closer buckets because no other node will ever come along to replace them. Every 5 seconds (on average), the last node in a random bucket is checked and moved to the front of the bucket if it is still responding. If revalidation fails, the last node is replaced by an entry of the 'replacement list' containing recently-seen nodes. Most close buckets are removed because it's very unlikely we'll ever encounter a node that would fall into any of those buckets. Table seeding is also improved: we now require a few minutes of table membership before considering a node as a potential seed node. This should make it less likely to store short-lived nodes as potential seeds. * p2p/discover: fix nits in UDP transport We would skip sending neighbors replies if there were fewer than maxNeighbors results and CheckRelayIP returned an error for the last one. While here, also resolve a TODO about pong reply tokens.
1 parent 1d39912 commit 9123ece

File tree

10 files changed

+801
-277
lines changed

10 files changed

+801
-277
lines changed

cmd/bootnode/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ func main() {
122122
utils.Fatalf("%v", err)
123123
}
124124
} else {
125-
if _, err := discover.ListenUDP(nodeKey, conn, realaddr, nil, "", restrictList); err != nil {
125+
cfg := discover.Config{
126+
PrivateKey: nodeKey,
127+
AnnounceAddr: realaddr,
128+
NetRestrict: restrictList,
129+
}
130+
if _, err := discover.ListenUDP(conn, cfg); err != nil {
126131
utils.Fatalf("%v", err)
127132
}
128133
}

p2p/discover/node.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"regexp"
3030
"strconv"
3131
"strings"
32+
"time"
3233

3334
"github.com/ethereum/go-ethereum/common"
3435
"github.com/ethereum/go-ethereum/crypto"
@@ -51,9 +52,8 @@ type Node struct {
5152
// with ID.
5253
sha common.Hash
5354

54-
// whether this node is currently being pinged in order to replace
55-
// it in a bucket
56-
contested bool
55+
// Time when the node was added to the table.
56+
addedAt time.Time
5757
}
5858

5959
// NewNode creates a new node. It is mostly meant to be used for

0 commit comments

Comments
 (0)