Skip to content

Commit

Permalink
fix: removed kludge
Browse files Browse the repository at this point in the history
  • Loading branch information
istae committed Aug 25, 2021
1 parent 802a2c5 commit 222fe72
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 30 deletions.
23 changes: 0 additions & 23 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,14 +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) {
k.metrics.P2PKademliaDiscrepancy.Inc()
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 @@ -1085,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
7 changes: 0 additions & 7 deletions pkg/topology/kademlia/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type metrics struct {
TotalOutboundConnectionFailedAttempts prometheus.Counter
TotalBootNodesConnectionAttempts prometheus.Counter
StartAddAddressBookOverlaysTime prometheus.Histogram
P2PKademliaDiscrepancy prometheus.Counter
}

// newMetrics is a convenient constructor for creating new metrics.
Expand Down Expand Up @@ -131,12 +130,6 @@ func newMetrics() metrics {
Name: "start_add_addressbook_overlays_time",
Help: "The time spent adding overlays peers from addressbook on kademlia start.",
}),
P2PKademliaDiscrepancy: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "p2p_kademlia_discrepancy",
Help: "Discrepancy counter between lists of peers in kademlia and libp2p",
}),
}
}

Expand Down

0 comments on commit 222fe72

Please sign in to comment.