1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 05:52:20 +08:00

if bucket doesnt have enough peers, grab more elsewhere

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
Jeromy
2015-11-13 14:36:13 -08:00
parent 5e99be9899
commit 18099abb93
2 changed files with 4 additions and 9 deletions

View File

@ -32,10 +32,6 @@ func copyPeersFromList(target ID, peerArr peerSorterArr, peerList *list.List) pe
distance: xor(target, pID),
}
peerArr = append(peerArr, &pd)
if e == nil {
log.Debug("list element was nil")
return peerArr
}
}
return peerArr
}

View File

@ -155,9 +155,10 @@ func (rt *RoutingTable) NearestPeers(id ID, count int) []peer.ID {
bucket = rt.Buckets[cpl]
var peerArr peerSorterArr
if bucket.Len() == 0 {
// In the case of an unusual split, one bucket may be empty.
// if this happens, search both surrounding buckets for nearest peer
peerArr = copyPeersFromList(id, peerArr, bucket.list)
if len(peerArr) < count {
// In the case of an unusual split, one bucket may be short or empty.
// if this happens, search both surrounding buckets for nearby peers
if cpl > 0 {
plist := rt.Buckets[cpl-1].list
peerArr = copyPeersFromList(id, peerArr, plist)
@ -167,8 +168,6 @@ func (rt *RoutingTable) NearestPeers(id ID, count int) []peer.ID {
plist := rt.Buckets[cpl+1].list
peerArr = copyPeersFromList(id, peerArr, plist)
}
} else {
peerArr = copyPeersFromList(id, peerArr, bucket.list)
}
// Sort by distance to local peer