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

Don't crash if Yggdrasil is started with no router adapter

This commit is contained in:
Neil Alexander 2019-03-29 08:38:09 +00:00
parent dd05a7f2a8
commit a830521078
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
3 changed files with 14 additions and 8 deletions

View File

@ -248,10 +248,10 @@ func main() {
// Setup the Yggdrasil node itself. The node{} type includes a Core, so we // Setup the Yggdrasil node itself. The node{} type includes a Core, so we
// don't need to create this manually. // don't need to create this manually.
n := node{} n := node{}
// Now that we have a working configuration, we can now actually start // Before we start the node, set the TUN/TAP to be our router adapter
// Yggdrasil. This will start the router, switch, DHT node, TCP and UDP
// sockets, TUN/TAP adapter and multicast discovery port.
n.core.SetRouterAdapter(&n.tuntap) n.core.SetRouterAdapter(&n.tuntap)
// Now start Yggdrasil - this starts the DHT, router, switch and other core
// components needed for Yggdrasil to operate
state, err := n.core.Start(cfg, logger) state, err := n.core.Start(cfg, logger)
if err != nil { if err != nil {
logger.Errorln("An error occurred during startup") logger.Errorln("An error occurred during startup")

View File

@ -220,9 +220,11 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) (*config.NodeState,
return nil, err return nil, err
} }
if err := c.router.adapter.Start(c.router.addr, c.router.subnet); err != nil { if c.router.adapter != nil {
c.log.Errorln("Failed to start TUN/TAP") if err := c.router.adapter.Start(c.router.addr, c.router.subnet); err != nil {
return nil, err c.log.Errorln("Failed to start TUN/TAP")
return nil, err
}
} }
go c.addPeerLoop() go c.addPeerLoop()
@ -234,7 +236,9 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) (*config.NodeState,
// Stops the Yggdrasil node. // Stops the Yggdrasil node.
func (c *Core) Stop() { func (c *Core) Stop() {
c.log.Infoln("Stopping...") c.log.Infoln("Stopping...")
c.router.adapter.Close() if c.router.adapter != nil {
c.router.adapter.Close()
}
c.admin.close() c.admin.close()
} }

View File

@ -128,7 +128,9 @@ func (r *router) init(core *Core) {
r.nodeinfo.setNodeInfo(r.core.config.Current.NodeInfo, r.core.config.Current.NodeInfoPrivacy) r.nodeinfo.setNodeInfo(r.core.config.Current.NodeInfo, r.core.config.Current.NodeInfoPrivacy)
r.core.config.Mutex.RUnlock() r.core.config.Mutex.RUnlock()
r.cryptokey.init(r.core) r.cryptokey.init(r.core)
r.adapter.Init(&r.core.config, r.core.log, send, recv, reject) if r.adapter != nil {
r.adapter.Init(&r.core.config, r.core.log, send, recv, reject)
}
} }
// Starts the mainLoop goroutine. // Starts the mainLoop goroutine.