mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-23 18:15:24 +00:00
don't allow buckets to overflow when the next bucket isn't full
This commit is contained in:
parent
8228242eed
commit
fe712d24f8
@ -234,6 +234,7 @@ 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
|
// Check if the next bucket is non-full and return early if it is
|
||||||
if bidx+1 == t.nBuckets() {
|
if bidx+1 == t.nBuckets() {
|
||||||
return
|
return
|
||||||
@ -242,6 +243,7 @@ func (t *dht) insert(info *dhtInfo, isPeer bool) {
|
|||||||
if len(bnext.other) < dht_bucket_size {
|
if len(bnext.other) < dht_bucket_size {
|
||||||
return
|
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,6 +480,7 @@ 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() {
|
if bidx+1 == t.nBuckets() {
|
||||||
add = true
|
add = true
|
||||||
}
|
}
|
||||||
@ -485,6 +488,7 @@ func (t *dht) doMaintenance() {
|
|||||||
if len(bnext.other) < dht_bucket_size {
|
if len(bnext.other) < dht_bucket_size {
|
||||||
add = true
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user