Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removed kademlia and libp2p discrepancy kludge #2429

Merged
merged 3 commits into from
Sep 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions pkg/topology/kademlia/kademlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,23 +1018,12 @@ func closestPeer(peers *pslice.PSlice, addr swarm.Address, spf sanctionedPeerFun
return closest, nil
}

func isIn(a swarm.Address, addresses []p2p.Peer) bool {
for _, v := range addresses {
if v.Address.Equal(a) {
return true
}
}
return false
}

// ClosestPeer returns the closest peer to a given address.
func (k *Kad) ClosestPeer(addr swarm.Address, includeSelf bool, skipPeers ...swarm.Address) (swarm.Address, error) {
if k.connectedPeers.Length() == 0 {
return swarm.Address{}, topology.ErrNotFound
}

peers := k.p2p.Peers()
var peersToDisconnect []swarm.Address
closest := swarm.ZeroAddress

if includeSelf {
Expand All @@ -1053,13 +1042,6 @@ func (k *Kad) ClosestPeer(addr swarm.Address, includeSelf bool, skipPeers ...swa
closest = peer
}

// kludge: hotfix for topology peer inconsistencies bug
if !isIn(peer, peers) {
a := swarm.NewAddress(peer.Bytes())
peersToDisconnect = append(peersToDisconnect, a)
return false, false, nil
}

dcmp, err := swarm.DistanceCmp(addr.Bytes(), closest.Bytes(), peer.Bytes())
if err != nil {
return false, false, err
Expand All @@ -1084,10 +1066,6 @@ func (k *Kad) ClosestPeer(addr swarm.Address, includeSelf bool, skipPeers ...swa
return swarm.Address{}, topology.ErrNotFound // only for light nodes
}

for _, v := range peersToDisconnect {
k.Disconnected(p2p.Peer{Address: v})
}

// check if self
if closest.Equal(k.base) {
return swarm.Address{}, topology.ErrWantSelf
Expand Down