Skip to content

Commit

Permalink
feat(kademlia): allow light nodes to be picked in oversaturated bins (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
istae committed Apr 19, 2023
1 parent e1320fa commit 7347d01
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/topology/kademlia/kademlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,8 +1136,8 @@ func (k *Kad) AddPeers(addrs ...swarm.Address) {

func (k *Kad) Pick(peer p2p.Peer) bool {
k.metrics.PickCalls.Inc()
if k.bootnode {
// shortcircuit for bootnode mode - always accept connections,
if k.bootnode || !peer.FullNode {
// shortcircuit for bootnode mode AND light node peers - always accept connections,
// at least until we find a better solution.
return true
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/topology/kademlia/kademlia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,12 @@ func TestOversaturation(t *testing.T) {
// if error is not as specified, connectOne goes fatal
connectOne(t, signer, kad, ab, addr, topology.ErrOversaturated)
// check that pick works correctly
if kad.Pick(p2p.Peer{Address: addr}) {
if kad.Pick(p2p.Peer{Address: addr, FullNode: true}) {
t.Fatal("should not pick the peer")
}
if !kad.Pick(p2p.Peer{Address: addr, FullNode: false}) {
t.Fatal("should pick the peer")
}
}
// see depth is still as expected
kDepth(t, kad, 5)
Expand Down

0 comments on commit 7347d01

Please sign in to comment.