5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 01:20:29 +00:00

fix debug rpcs and cleanup core.Close/core.Stop

This commit is contained in:
Arceliar 2021-07-06 19:45:12 -05:00
parent e224c02d6d
commit 3704ebf4cb
4 changed files with 19 additions and 18 deletions

View File

@ -239,11 +239,6 @@ func (c *Core) PublicKey() ed25519.PublicKey {
return c.public return c.public
} }
func (c *Core) Close() error {
c.Stop()
return nil
}
// Hack to get the admin stuff working, TODO something cleaner // Hack to get the admin stuff working, TODO something cleaner
type AddHandler interface { type AddHandler interface {

View File

@ -161,25 +161,31 @@ func (c *Core) _start(nc *config.NodeConfig, log *log.Logger) error {
// Stop shuts down the Yggdrasil node. // Stop shuts down the Yggdrasil node.
func (c *Core) Stop() { func (c *Core) Stop() {
phony.Block(c, c._stop) phony.Block(c, func() {
c.log.Infoln("Stopping...")
c._close()
c.log.Infoln("Stopped")
})
}
func (c *Core) Close() error {
var err error
phony.Block(c, func() {
err = c._close()
})
return err
} }
// 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) _close() error {
c.log.Infoln("Stopping...")
c.ctxCancel() c.ctxCancel()
c.PacketConn.Close() // TODO make c.Close() do the right thing (act like c.Stop()) err := c.PacketConn.Close()
if c.addPeerTimer != nil { if c.addPeerTimer != nil {
c.addPeerTimer.Stop() c.addPeerTimer.Stop()
c.addPeerTimer = nil c.addPeerTimer = nil
} }
_ = c.links.stop() _ = c.links.stop()
/* FIXME this deadlocks, need a waitgroup or something to coordinate shutdown return err
for _, peer := range c.GetPeers() {
c.DisconnectPeer(peer.Port)
}
*/
c.log.Infoln("Stopped")
} }
func (c *Core) MTU() uint64 { func (c *Core) MTU() uint64 {

View File

@ -129,7 +129,7 @@ func (m *nodeinfo) _sendReq(key keyArray, callback func(nodeinfo NodeInfoPayload
if callback != nil { if callback != nil {
m._addCallback(key, callback) m._addCallback(key, callback)
} }
_, _ = m.proto.core.WriteTo([]byte{typeSessionProto, typeProtoNodeInfoRequest}, iwt.Addr(key[:])) _, _ = m.proto.core.PacketConn.WriteTo([]byte{typeSessionProto, typeProtoNodeInfoRequest}, iwt.Addr(key[:]))
} }
func (m *nodeinfo) handleReq(from phony.Actor, key keyArray) { func (m *nodeinfo) handleReq(from phony.Actor, key keyArray) {
@ -146,7 +146,7 @@ func (m *nodeinfo) handleRes(from phony.Actor, key keyArray, info NodeInfoPayloa
func (m *nodeinfo) _sendRes(key keyArray) { func (m *nodeinfo) _sendRes(key keyArray) {
bs := append([]byte{typeSessionProto, typeProtoNodeInfoResponse}, m._getNodeInfo()...) bs := append([]byte{typeSessionProto, typeProtoNodeInfoResponse}, m._getNodeInfo()...)
_, _ = m.proto.core.WriteTo(bs, iwt.Addr(key[:])) _, _ = m.proto.core.PacketConn.WriteTo(bs, iwt.Addr(key[:]))
} }
// Admin socket stuff // Admin socket stuff

View File

@ -212,7 +212,7 @@ func (p *protoHandler) _handleGetDHTResponse(key keyArray, bs []byte) {
func (p *protoHandler) _sendDebug(key keyArray, dType uint8, data []byte) { func (p *protoHandler) _sendDebug(key keyArray, dType uint8, data []byte) {
bs := append([]byte{typeSessionProto, typeProtoDebug, dType}, data...) bs := append([]byte{typeSessionProto, typeProtoDebug, dType}, data...)
_, _ = p.core.WriteTo(bs, iwt.Addr(key[:])) _, _ = p.core.PacketConn.WriteTo(bs, iwt.Addr(key[:]))
} }
// Admin socket stuff // Admin socket stuff