5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 10:41:40 +00:00

Shut down listeners when stopping

This commit is contained in:
Neil Alexander 2019-09-18 16:32:22 +01:00
parent b0df9e2f31
commit b959f53fee
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
3 changed files with 16 additions and 0 deletions

View File

@ -194,7 +194,9 @@ func (c *Core) _stop() {
if c.addPeerTimer != nil { if c.addPeerTimer != nil {
c.addPeerTimer.Stop() c.addPeerTimer.Stop()
} }
c.link.stop()
for _, peer := range c.GetPeers() { for _, peer := range c.GetPeers() {
c.DisconnectPeer(peer.Port) c.DisconnectPeer(peer.Port)
} }
c.log.Infoln("Stopped")
} }

View File

@ -134,6 +134,13 @@ func (l *link) create(msgIO linkInterfaceMsgIO, name, linkType, local, remote st
return &intf, nil return &intf, nil
} }
func (l *link) stop() error {
if err := l.tcp.stop(); err != nil {
return err
}
return nil
}
func (intf *linkInterface) handler() error { func (intf *linkInterface) handler() error {
// TODO split some of this into shorter functions, so it's easier to read, and for the FIXME duplicate peer issue mentioned later // TODO split some of this into shorter functions, so it's easier to read, and for the FIXME duplicate peer issue mentioned later
myLinkPub, myLinkPriv := crypto.NewBoxKeys() myLinkPub, myLinkPriv := crypto.NewBoxKeys()

View File

@ -96,6 +96,13 @@ func (t *tcp) init(l *link) error {
return nil return nil
} }
func (t *tcp) stop() error {
for _, listener := range t.listeners {
close(listener.Stop)
}
return nil
}
func (t *tcp) reconfigure() { func (t *tcp) reconfigure() {
t.link.core.config.Mutex.RLock() t.link.core.config.Mutex.RLock()
added := util.Difference(t.link.core.config.Current.Listen, t.link.core.config.Previous.Listen) added := util.Difference(t.link.core.config.Current.Listen, t.link.core.config.Previous.Listen)