mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 14:15:06 +03:00
more insertIfNew bugfixes, and add peerOnly to getDHT output (true if a node is in the bucket.peers slice instead of bucket.others--it means they're not regularly pinged, they're only there to make sure DHT lookups include them as a result, for bootstrapping reasons)
This commit is contained in:
parent
fe518f4e3f
commit
ec8fe338d5
2 changed files with 13 additions and 6 deletions
|
@ -197,8 +197,14 @@ func (t *dht) nBuckets() int {
|
|||
|
||||
func (t *dht) insertIfNew(info *dhtInfo, isPeer bool) {
|
||||
//fmt.Println("DEBUG: dht insertIfNew:", info.getNodeID(), info.coords)
|
||||
// Always inserts peers, inserts other nodes if not already present
|
||||
if isPeer || t.shouldInsert(info) {
|
||||
// Insert if no "other" entry already exists
|
||||
nodeID := info.getNodeID()
|
||||
bidx, isOK := t.getBucketIndex(nodeID)
|
||||
if !isOK {
|
||||
return
|
||||
}
|
||||
b := t.getBucket(bidx)
|
||||
if (isPeer && !b.containsOther(info)) || t.shouldInsert(info) {
|
||||
// We've never heard this node before
|
||||
// TODO is there a better time than "now" to set send/recv to?
|
||||
// (Is there another "natural" choice that bootstraps faster?)
|
||||
|
@ -222,7 +228,7 @@ func (t *dht) insert(info *dhtInfo, isPeer bool) {
|
|||
if !isPeer && !b.containsOther(info) {
|
||||
// This is a new entry, give it an old age so it's pinged sooner
|
||||
// This speeds up bootstrapping
|
||||
info.recv = info.recv.Add(-time.Minute)
|
||||
info.recv = info.recv.Add(-time.Hour)
|
||||
}
|
||||
// First drop any existing entry from the bucket
|
||||
b.drop(&info.key)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue