mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-23 00:51:35 +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 {
|
if port == 0 {
|
||||||
return
|
return
|
||||||
} // Can't remove self peer
|
} // Can't remove self peer
|
||||||
|
ps.core.router.doAdmin(func() {
|
||||||
|
ps.core.switchTable.removePeer(port)
|
||||||
|
})
|
||||||
ps.mutex.Lock()
|
ps.mutex.Lock()
|
||||||
oldPorts := ps.getPorts()
|
oldPorts := ps.getPorts()
|
||||||
p, isIn := oldPorts[port]
|
p, isIn := oldPorts[port]
|
||||||
@ -160,8 +163,11 @@ func (ps *peers) removePeer(port switchPort) {
|
|||||||
delete(newPorts, port)
|
delete(newPorts, port)
|
||||||
ps.putPorts(newPorts)
|
ps.putPorts(newPorts)
|
||||||
ps.mutex.Unlock()
|
ps.mutex.Unlock()
|
||||||
if isIn && p.close != nil {
|
if isIn {
|
||||||
p.close()
|
if p.close != nil {
|
||||||
|
p.close()
|
||||||
|
}
|
||||||
|
close(p.linkIn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +181,6 @@ func (t *switchTable) doMaintenance() {
|
|||||||
t.mutex.Lock() // Write lock
|
t.mutex.Lock() // Write lock
|
||||||
defer t.mutex.Unlock() // Release lock when we're done
|
defer t.mutex.Unlock() // Release lock when we're done
|
||||||
t.cleanRoot()
|
t.cleanRoot()
|
||||||
t.cleanPeers()
|
|
||||||
t.cleanDropped()
|
t.cleanDropped()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,19 +226,9 @@ func (t *switchTable) cleanRoot() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *switchTable) cleanPeers() {
|
func (t *switchTable) removePeer(port switchPort) {
|
||||||
now := time.Now()
|
delete(t.data.peers, port)
|
||||||
changed := false
|
t.updater.Store(&sync.Once{})
|
||||||
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) cleanDropped() {
|
func (t *switchTable) cleanDropped() {
|
||||||
|
@ -279,7 +279,6 @@ func (iface *tcpInterface) handler(sock net.Conn, incoming bool) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
// Put all of our cleanup here...
|
// Put all of our cleanup here...
|
||||||
p.core.peers.removePeer(p.port)
|
p.core.peers.removePeer(p.port)
|
||||||
close(p.linkIn)
|
|
||||||
}()
|
}()
|
||||||
them, _, _ := net.SplitHostPort(sock.RemoteAddr().String())
|
them, _, _ := net.SplitHostPort(sock.RemoteAddr().String())
|
||||||
themNodeID := getNodeID(&info.box)
|
themNodeID := getNodeID(&info.box)
|
||||||
|
Loading…
Reference in New Issue
Block a user