mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-23 08:45:39 +00:00
remove peer timeout logic from the switch, so switch peer entrires are only removed when the peer struct is removed
This commit is contained in:
parent
3b783fbf97
commit
85afe187ff
@ -150,6 +150,9 @@ func (ps *peers) removePeer(port switchPort) {
|
||||
if port == 0 {
|
||||
return
|
||||
} // Can't remove self peer
|
||||
ps.core.router.doAdmin(func() {
|
||||
ps.core.switchTable.removePeer(port)
|
||||
})
|
||||
ps.mutex.Lock()
|
||||
oldPorts := ps.getPorts()
|
||||
p, isIn := oldPorts[port]
|
||||
@ -160,8 +163,11 @@ func (ps *peers) removePeer(port switchPort) {
|
||||
delete(newPorts, port)
|
||||
ps.putPorts(newPorts)
|
||||
ps.mutex.Unlock()
|
||||
if isIn && p.close != nil {
|
||||
p.close()
|
||||
if isIn {
|
||||
if p.close != nil {
|
||||
p.close()
|
||||
}
|
||||
close(p.linkIn)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,7 +181,6 @@ func (t *switchTable) doMaintenance() {
|
||||
t.mutex.Lock() // Write lock
|
||||
defer t.mutex.Unlock() // Release lock when we're done
|
||||
t.cleanRoot()
|
||||
t.cleanPeers()
|
||||
t.cleanDropped()
|
||||
}
|
||||
|
||||
@ -227,19 +226,9 @@ func (t *switchTable) cleanRoot() {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *switchTable) cleanPeers() {
|
||||
now := time.Now()
|
||||
changed := false
|
||||
for idx, info := range t.data.peers {
|
||||
if info.port != switchPort(0) && now.Sub(info.time) > 6*time.Second /*switch_timeout*/ {
|
||||
//fmt.Println("peer timed out", t.key, info.locator)
|
||||
delete(t.data.peers, idx)
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
t.updater.Store(&sync.Once{})
|
||||
}
|
||||
func (t *switchTable) removePeer(port switchPort) {
|
||||
delete(t.data.peers, port)
|
||||
t.updater.Store(&sync.Once{})
|
||||
}
|
||||
|
||||
func (t *switchTable) cleanDropped() {
|
||||
|
@ -279,7 +279,6 @@ func (iface *tcpInterface) handler(sock net.Conn, incoming bool) {
|
||||
defer func() {
|
||||
// Put all of our cleanup here...
|
||||
p.core.peers.removePeer(p.port)
|
||||
close(p.linkIn)
|
||||
}()
|
||||
them, _, _ := net.SplitHostPort(sock.RemoteAddr().String())
|
||||
themNodeID := getNodeID(&info.box)
|
||||
|
Loading…
Reference in New Issue
Block a user