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

Only stop timers if they are running

This commit is contained in:
Neil Alexander 2019-09-18 15:34:26 +01:00
parent 366fe7e772
commit c78a4cb28f
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
2 changed files with 10 additions and 7 deletions

View File

@ -75,8 +75,12 @@ func (m *Multicast) Start() error {
// Stop is not implemented for multicast yet. // Stop is not implemented for multicast yet.
func (m *Multicast) Stop() error { func (m *Multicast) Stop() error {
m.isOpen = false m.isOpen = false
if m.announcer != nil {
m.announcer.Stop() m.announcer.Stop()
}
if m.platformhandler != nil {
m.platformhandler.Stop() m.platformhandler.Stop()
}
m.sock.Close() m.sock.Close()
return nil return nil
} }

View File

@ -110,7 +110,6 @@ func (c *Core) _addPeerLoop() {
} }
} }
// Sit for a while
c.addPeerTimer = time.AfterFunc(time.Minute, func() { c.addPeerTimer = time.AfterFunc(time.Minute, func() {
c.Act(c, c._addPeerLoop) c.Act(c, c._addPeerLoop)
}) })
@ -178,9 +177,7 @@ func (c *Core) _start(nc *config.NodeConfig, log *log.Logger) (*config.NodeState
return nil, err return nil, err
} }
c.addPeerTimer = time.AfterFunc(time.Second, func() {
c.Act(c, c._addPeerLoop) c.Act(c, c._addPeerLoop)
})
c.log.Infoln("Startup complete") c.log.Infoln("Startup complete")
return &c.config, nil return &c.config, nil
@ -194,7 +191,9 @@ func (c *Core) Stop() {
// This function is unsafe and should only be ran by the core actor. // This function is unsafe and should only be ran by the core actor.
func (c *Core) _stop() { func (c *Core) _stop() {
c.log.Infoln("Stopping...") c.log.Infoln("Stopping...")
if c.addPeerTimer != nil {
c.addPeerTimer.Stop() c.addPeerTimer.Stop()
}
for _, peer := range c.GetPeers() { for _, peer := range c.GetPeers() {
c.DisconnectPeer(peer.Port) c.DisconnectPeer(peer.Port)
} }