mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-30 13:35:19 +00:00
Disconnect peers when stopping, stop modules before core
This commit is contained in:
parent
846df4789a
commit
00a972b74e
@ -292,10 +292,10 @@ exit:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *node) shutdown() {
|
func (n *node) shutdown() {
|
||||||
n.core.Stop()
|
|
||||||
n.admin.Stop()
|
n.admin.Stop()
|
||||||
n.multicast.Stop()
|
n.multicast.Stop()
|
||||||
n.tuntap.Stop()
|
n.tuntap.Stop()
|
||||||
|
n.core.Stop()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,16 +21,17 @@ type Core struct {
|
|||||||
// We're going to keep our own copy of the provided config - that way we can
|
// We're going to keep our own copy of the provided config - that way we can
|
||||||
// guarantee that it will be covered by the mutex
|
// guarantee that it will be covered by the mutex
|
||||||
phony.Inbox
|
phony.Inbox
|
||||||
config config.NodeState // Config
|
config config.NodeState // Config
|
||||||
boxPub crypto.BoxPubKey
|
boxPub crypto.BoxPubKey
|
||||||
boxPriv crypto.BoxPrivKey
|
boxPriv crypto.BoxPrivKey
|
||||||
sigPub crypto.SigPubKey
|
sigPub crypto.SigPubKey
|
||||||
sigPriv crypto.SigPrivKey
|
sigPriv crypto.SigPrivKey
|
||||||
switchTable switchTable
|
switchTable switchTable
|
||||||
peers peers
|
peers peers
|
||||||
router router
|
router router
|
||||||
link link
|
link link
|
||||||
log *log.Logger
|
log *log.Logger
|
||||||
|
addPeerTimer *time.Timer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Core) _init() error {
|
func (c *Core) _init() error {
|
||||||
@ -110,7 +111,7 @@ func (c *Core) _addPeerLoop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sit for a while
|
// Sit for a while
|
||||||
time.AfterFunc(time.Minute, func() {
|
c.addPeerTimer = time.AfterFunc(time.Minute, func() {
|
||||||
c.Act(c, c._addPeerLoop)
|
c.Act(c, c._addPeerLoop)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -177,7 +178,9 @@ func (c *Core) _start(nc *config.NodeConfig, log *log.Logger) (*config.NodeState
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Act(c, c._addPeerLoop)
|
c.addPeerTimer = time.AfterFunc(time.Second, func() {
|
||||||
|
c.Act(c, c._addPeerLoop)
|
||||||
|
})
|
||||||
|
|
||||||
c.log.Infoln("Startup complete")
|
c.log.Infoln("Startup complete")
|
||||||
return &c.config, nil
|
return &c.config, nil
|
||||||
@ -191,4 +194,8 @@ 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...")
|
||||||
|
c.addPeerTimer.Stop()
|
||||||
|
for _, peer := range c.GetPeers() {
|
||||||
|
c.DisconnectPeer(peer.Port)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user