mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2025-09-18 08:42:30 +00:00
make removePeers work for TCP connections and minor admin cleanup
This commit is contained in:
@@ -73,6 +73,8 @@ type peer struct {
|
||||
// Specifically, processing switch messages, signing, and verifying sigs
|
||||
// Resets at the start of each tick
|
||||
throttle uint8
|
||||
// Called when a peer is removed, to close the underlying connection, or via admin api
|
||||
close func()
|
||||
}
|
||||
|
||||
const peer_Throttle = 1
|
||||
@@ -123,6 +125,26 @@ func (ps *peers) newPeer(box *boxPubKey,
|
||||
return &p
|
||||
}
|
||||
|
||||
func (ps *peers) removePeer(port switchPort) {
|
||||
// TODO? store linkIn in the peer struct, close it here? (once)
|
||||
if port == 0 {
|
||||
return
|
||||
} // Can't remove self peer
|
||||
ps.mutex.Lock()
|
||||
oldPorts := ps.getPorts()
|
||||
p, isIn := oldPorts[port]
|
||||
newPorts := make(map[switchPort]*peer)
|
||||
for k, v := range oldPorts {
|
||||
newPorts[k] = v
|
||||
}
|
||||
delete(newPorts, port)
|
||||
ps.putPorts(newPorts)
|
||||
ps.mutex.Unlock()
|
||||
if isIn && p.close != nil {
|
||||
p.close()
|
||||
}
|
||||
}
|
||||
|
||||
func (p *peer) linkLoop(in <-chan []byte) {
|
||||
ticker := time.NewTicker(time.Second)
|
||||
defer ticker.Stop()
|
||||
|
Reference in New Issue
Block a user