diff --git a/src/yggdrasil/dht.go b/src/yggdrasil/dht.go index af104f51..ef835985 100644 --- a/src/yggdrasil/dht.go +++ b/src/yggdrasil/dht.go @@ -134,6 +134,15 @@ func (t *dht) insert(info *dhtInfo) { t.table[*info.getNodeID()] = info } +// Insert a peer into the table if it hasn't been pinged lately, to keep peers from dropping +func (t *dht) insertPeer(info *dhtInfo) { + oldInfo, isIn := t.table[*info.getNodeID()] + if !isIn || time.Since(oldInfo.recv) > 45*time.Second { + // TODO? also check coords? + t.insert(info) + } +} + // Return true if first/second/third are (partially) ordered correctly. func dht_ordered(first, second, third *crypto.NodeID) bool { lessOrEqual := func(first, second *crypto.NodeID) bool { diff --git a/src/yggdrasil/router.go b/src/yggdrasil/router.go index 6c928696..87da8829 100644 --- a/src/yggdrasil/router.go +++ b/src/yggdrasil/router.go @@ -110,12 +110,7 @@ func (r *router) mainLoop() { case p := <-r.send: r.sendPacket(p) case info := <-r.core.dht.peers: - now := time.Now() - oldInfo, isIn := r.core.dht.table[*info.getNodeID()] - r.core.dht.insert(info) - if isIn && now.Sub(oldInfo.recv) < 45*time.Second { - info.recv = oldInfo.recv - } + r.core.dht.insertPeer(info) case <-r.reset: r.core.sessions.resetInits() r.core.dht.reset()