diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index 8682f75b..3270365c 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -344,20 +344,21 @@ func (a *admin) getData_getDHT() []admin_nodeInfo { getDHT := func() { for i := 0; i < a.core.dht.nBuckets(); i++ { b := a.core.dht.getBucket(i) - getInfo := func(vs []*dhtInfo) { + getInfo := func(vs []*dhtInfo, isPeer bool) { for _, v := range vs { addr := *address_addrForNodeID(v.getNodeID()) info := admin_nodeInfo{ {"IP", net.IP(addr[:]).String()}, {"coords", fmt.Sprint(v.coords)}, {"bucket", fmt.Sprint(i)}, + {"peerOnly", fmt.Sprint(isPeer)}, {"lastSeen", fmt.Sprint(now.Sub(v.recv))}, } infos = append(infos, info) } } - getInfo(b.other) - getInfo(b.peers) + getInfo(b.other, false) + getInfo(b.peers, true) } } a.core.router.doAdmin(getDHT) diff --git a/src/yggdrasil/dht.go b/src/yggdrasil/dht.go index 90df62b3..1f03bee5 100644 --- a/src/yggdrasil/dht.go +++ b/src/yggdrasil/dht.go @@ -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)