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

move special peer/dht insert logic form router.go to dht.go

This commit is contained in:
Arceliar 2018-12-20 17:37:59 -06:00
parent e65910806c
commit dfcdafa55c
2 changed files with 10 additions and 6 deletions

View File

@ -134,6 +134,15 @@ func (t *dht) insert(info *dhtInfo) {
t.table[*info.getNodeID()] = info 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. // Return true if first/second/third are (partially) ordered correctly.
func dht_ordered(first, second, third *crypto.NodeID) bool { func dht_ordered(first, second, third *crypto.NodeID) bool {
lessOrEqual := func(first, second *crypto.NodeID) bool { lessOrEqual := func(first, second *crypto.NodeID) bool {

View File

@ -110,12 +110,7 @@ func (r *router) mainLoop() {
case p := <-r.send: case p := <-r.send:
r.sendPacket(p) r.sendPacket(p)
case info := <-r.core.dht.peers: case info := <-r.core.dht.peers:
now := time.Now() r.core.dht.insertPeer(info)
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
}
case <-r.reset: case <-r.reset:
r.core.sessions.resetInits() r.core.sessions.resetInits()
r.core.dht.reset() r.core.dht.reset()