mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
lightnodes should be omitted from the addressbook
This commit is contained in:
parent
3fae03a6b7
commit
608ac82f53
2 changed files with 40 additions and 12 deletions
|
|
@ -261,7 +261,7 @@ func (k *Kademlia) On(p *Peer) (uint8, bool) {
|
||||||
// found among live peers, do nothing
|
// found among live peers, do nothing
|
||||||
return v
|
return v
|
||||||
})
|
})
|
||||||
if ins {
|
if ins && !p.BzzPeer.LightNode {
|
||||||
a := newEntry(p.BzzAddr)
|
a := newEntry(p.BzzAddr)
|
||||||
a.conn = p
|
a.conn = p
|
||||||
// insert new online peer into addrs
|
// insert new online peer into addrs
|
||||||
|
|
@ -329,14 +329,18 @@ func (k *Kademlia) Off(p *Peer) {
|
||||||
k.lock.Lock()
|
k.lock.Lock()
|
||||||
defer k.lock.Unlock()
|
defer k.lock.Unlock()
|
||||||
var del bool
|
var del bool
|
||||||
k.addrs, _, _, _ = pot.Swap(k.addrs, p, pof, func(v pot.Val) pot.Val {
|
if !p.BzzPeer.LightNode {
|
||||||
// v cannot be nil, must check otherwise we overwrite entry
|
k.addrs, _, _, _ = pot.Swap(k.addrs, p, pof, func(v pot.Val) pot.Val {
|
||||||
if v == nil {
|
// v cannot be nil, must check otherwise we overwrite entry
|
||||||
panic(fmt.Sprintf("connected peer not found %v", p))
|
if v == nil {
|
||||||
}
|
panic(fmt.Sprintf("connected peer not found %v", p))
|
||||||
|
}
|
||||||
|
del = true
|
||||||
|
return newEntry(p.BzzAddr)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
del = true
|
del = true
|
||||||
return newEntry(p.BzzAddr)
|
}
|
||||||
})
|
|
||||||
|
|
||||||
if del {
|
if del {
|
||||||
k.conns, _, _, _ = pot.Swap(k.conns, p, pof, func(_ pot.Val) pot.Val {
|
k.conns, _, _, _ = pot.Swap(k.conns, p, pof, func(_ pot.Val) pot.Val {
|
||||||
|
|
|
||||||
|
|
@ -46,19 +46,19 @@ func newTestKademlia(b string) *Kademlia {
|
||||||
return NewKademlia(base, params)
|
return NewKademlia(base, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestKadPeer(k *Kademlia, s string) *Peer {
|
func newTestKadPeer(k *Kademlia, s string, lightNode bool) *Peer {
|
||||||
return NewPeer(&BzzPeer{BzzAddr: testKadPeerAddr(s)}, k)
|
return NewPeer(&BzzPeer{BzzAddr: testKadPeerAddr(s), LightNode: lightNode}, k)
|
||||||
}
|
}
|
||||||
|
|
||||||
func On(k *Kademlia, ons ...string) {
|
func On(k *Kademlia, ons ...string) {
|
||||||
for _, s := range ons {
|
for _, s := range ons {
|
||||||
k.On(newTestKadPeer(k, s))
|
k.On(newTestKadPeer(k, s, false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Off(k *Kademlia, offs ...string) {
|
func Off(k *Kademlia, offs ...string) {
|
||||||
for _, s := range offs {
|
for _, s := range offs {
|
||||||
k.Off(newTestKadPeer(k, s))
|
k.Off(newTestKadPeer(k, s, false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -254,6 +254,30 @@ func TestSuggestPeerFindPeers(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOffEffectingAddressBookNormalNode(t *testing.T) {
|
||||||
|
k := newTestKademlia("00000000")
|
||||||
|
k.On(newTestKadPeer(k, "01000000", false))
|
||||||
|
if k.addrs.Size() != 1 {
|
||||||
|
t.Fatal("known peer addresses should contain 1 entry")
|
||||||
|
}
|
||||||
|
k.Off(newTestKadPeer(k, "01000000", false))
|
||||||
|
if k.addrs.Size() != 1 {
|
||||||
|
t.Fatal("known peer addresses should contain 1 entry")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOffEffectingAddressBookLightNode(t *testing.T) {
|
||||||
|
k := newTestKademlia("00000000")
|
||||||
|
k.On(newTestKadPeer(k, "01000000", true))
|
||||||
|
if k.addrs.Size() != 0 {
|
||||||
|
t.Fatal("known peer addresses should contain 0 entry")
|
||||||
|
}
|
||||||
|
k.Off(newTestKadPeer(k, "01000000", true))
|
||||||
|
if k.addrs.Size() != 0 {
|
||||||
|
t.Fatal("known peer addresses should contain 0 entry")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSuggestPeerRetries(t *testing.T) {
|
func TestSuggestPeerRetries(t *testing.T) {
|
||||||
k := newTestKademlia("00000000")
|
k := newTestKademlia("00000000")
|
||||||
k.RetryInterval = int64(300 * time.Millisecond) // cycle
|
k.RetryInterval = int64(300 * time.Millisecond) // cycle
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue