mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 03:40:28 +00:00
move special peer/dht insert logic form router.go to dht.go
This commit is contained in:
parent
e65910806c
commit
dfcdafa55c
@ -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 {
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user