mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
close long-dead connections in link.go instead of in switch.go, this is important in case a connection opens but never bothers to send even one switch message
This commit is contained in:
parent
bb3edd5e55
commit
654407dc6d
2 changed files with 11 additions and 24 deletions
|
@ -215,7 +215,6 @@ func (t *switchTable) doMaintenance() {
|
|||
defer t.mutex.Unlock() // Release lock when we're done
|
||||
t.cleanRoot()
|
||||
t.cleanDropped()
|
||||
t.cleanPeers()
|
||||
}
|
||||
|
||||
// Updates the root periodically if it is ourself, or promotes ourself to root if we're better than the current root or if the current root has timed out.
|
||||
|
@ -272,28 +271,6 @@ func (t *switchTable) forgetPeer(port switchPort) {
|
|||
}
|
||||
}
|
||||
|
||||
// Clean all unresponsive peers from the table, needed in case a peer stops updating.
|
||||
// Needed in case a non-parent peer keeps the connection open but stops sending updates.
|
||||
// Also reclaims space from deleted peers by copying the map.
|
||||
func (t *switchTable) cleanPeers() {
|
||||
now := time.Now()
|
||||
for port, peer := range t.data.peers {
|
||||
if now.Sub(peer.time) > switch_timeout+switch_throttle {
|
||||
// Longer than switch_timeout to make sure we don't remove a working peer because the root stopped responding.
|
||||
delete(t.data.peers, port)
|
||||
go t.core.peers.removePeer(port) // TODO figure out if it's safe to do this without a goroutine, or make it safe
|
||||
}
|
||||
}
|
||||
if _, isIn := t.data.peers[t.parent]; !isIn {
|
||||
// The root timestamp would probably time out before this happens, but better safe than sorry.
|
||||
// We removed the current parent, so find a new one.
|
||||
t.parent = 0
|
||||
for _, peer := range t.data.peers {
|
||||
t.unlockedHandleMsg(&peer.msg, peer.port, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dropped is a list of roots that are better than the current root, but stopped sending new timestamps.
|
||||
// If we switch to a new root, and that root is better than an old root that previously timed out, then we can clean up the old dropped root infos.
|
||||
// This function is called periodically to do that cleanup.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue