aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/network/kademlia.go
diff options
context:
space:
mode:
authorMark Vujevits <vujevits.mark@gmail.com>2018-11-08 03:33:36 +0800
committerViktor TrĂ³n <viktor.tron@gmail.com>2018-11-08 03:33:36 +0800
commit81533deae5ee4a7ec08842e2b6647f3affde5a71 (patch)
tree442d2eddd4f25fc1b0a9d153a36bda39399692fa /swarm/network/kademlia.go
parent0bcff8f52505fa1eece6c8fbfc5cab8aa9d9ed5d (diff)
downloaddexon-81533deae5ee4a7ec08842e2b6647f3affde5a71.tar
dexon-81533deae5ee4a7ec08842e2b6647f3affde5a71.tar.gz
dexon-81533deae5ee4a7ec08842e2b6647f3affde5a71.tar.bz2
dexon-81533deae5ee4a7ec08842e2b6647f3affde5a71.tar.lz
dexon-81533deae5ee4a7ec08842e2b6647f3affde5a71.tar.xz
dexon-81533deae5ee4a7ec08842e2b6647f3affde5a71.tar.zst
dexon-81533deae5ee4a7ec08842e2b6647f3affde5a71.zip
swarm/network: light nodes are not dialed, saved and requested from (#17975)
* RequestFromPeers does not use peers marked as lightnode * fix warning about variable name * write tests for RequestFromPeers * lightnodes should be omitted from the addressbook * resolve pr comments regarding logging, formatting and comments * resolve pr comments regarding comments and added a missing newline * add assertions to check peers in live connections
Diffstat (limited to 'swarm/network/kademlia.go')
-rw-r--r--swarm/network/kademlia.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/swarm/network/kademlia.go b/swarm/network/kademlia.go
index 55a0c6f13..cd94741be 100644
--- a/swarm/network/kademlia.go
+++ b/swarm/network/kademlia.go
@@ -261,7 +261,7 @@ func (k *Kademlia) On(p *Peer) (uint8, bool) {
// found among live peers, do nothing
return v
})
- if ins {
+ if ins && !p.BzzPeer.LightNode {
a := newEntry(p.BzzAddr)
a.conn = p
// insert new online peer into addrs
@@ -329,14 +329,18 @@ func (k *Kademlia) Off(p *Peer) {
k.lock.Lock()
defer k.lock.Unlock()
var del bool
- k.addrs, _, _, _ = pot.Swap(k.addrs, p, pof, func(v pot.Val) pot.Val {
- // v cannot be nil, must check otherwise we overwrite entry
- if v == nil {
- panic(fmt.Sprintf("connected peer not found %v", p))
- }
+ if !p.BzzPeer.LightNode {
+ k.addrs, _, _, _ = pot.Swap(k.addrs, p, pof, func(v pot.Val) pot.Val {
+ // v cannot be nil, must check otherwise we overwrite entry
+ if v == nil {
+ panic(fmt.Sprintf("connected peer not found %v", p))
+ }
+ del = true
+ return newEntry(p.BzzAddr)
+ })
+ } else {
del = true
- return newEntry(p.BzzAddr)
- })
+ }
if del {
k.conns, _, _, _ = pot.Swap(k.conns, p, pof, func(_ pot.Val) pot.Val {