5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 14:10:28 +00:00

don't allow buckets to overflow when the next bucket isn't full

This commit is contained in:
Arceliar 2018-05-16 17:24:38 -05:00
parent 8228242eed
commit fe712d24f8

View File

@ -234,14 +234,16 @@ func (t *dht) insert(info *dhtInfo, isPeer bool) {
return return
} }
b.other = append(b.other, info) b.other = append(b.other, info)
// Check if the next bucket is non-full and return early if it is /*
if bidx+1 == t.nBuckets() { // Check if the next bucket is non-full and return early if it is
return if bidx+1 == t.nBuckets() {
} return
bnext := t.getBucket(bidx + 1) }
if len(bnext.other) < dht_bucket_size { bnext := t.getBucket(bidx + 1)
return if len(bnext.other) < dht_bucket_size {
} return
}
//*/
// Shrink from the *front* to requied size // Shrink from the *front* to requied size
for len(b.other) > dht_bucket_size { for len(b.other) > dht_bucket_size {
b.other = b.other[1:] b.other = b.other[1:]
@ -478,13 +480,15 @@ func (t *dht) doMaintenance() {
} }
// This is a good spot to check if a node is worth pinging // This is a good spot to check if a node is worth pinging
add := len(b.other) < dht_bucket_size add := len(b.other) < dht_bucket_size
if bidx+1 == t.nBuckets() { /*
add = true if bidx+1 == t.nBuckets() {
} add = true
bnext := t.getBucket(bidx + 1) }
if len(bnext.other) < dht_bucket_size { bnext := t.getBucket(bidx + 1)
add = true if len(bnext.other) < dht_bucket_size {
} add = true
}
//*/
for _, info := range b.other { for _, info := range b.other {
if dht_firstCloserThanThird(rumor.info.getNodeID(), &t.nodeID, info.getNodeID()) { if dht_firstCloserThanThird(rumor.info.getNodeID(), &t.nodeID, info.getNodeID()) {
// Add the node if they are closer to us than someone in the same bucket // Add the node if they are closer to us than someone in the same bucket