mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 09:30:28 +00:00
Don't crash if Yggdrasil is started with no router adapter
This commit is contained in:
parent
dd05a7f2a8
commit
a830521078
@ -248,10 +248,10 @@ func main() {
|
||||
// Setup the Yggdrasil node itself. The node{} type includes a Core, so we
|
||||
// don't need to create this manually.
|
||||
n := node{}
|
||||
// Now that we have a working configuration, we can now actually start
|
||||
// Yggdrasil. This will start the router, switch, DHT node, TCP and UDP
|
||||
// sockets, TUN/TAP adapter and multicast discovery port.
|
||||
// Before we start the node, set the TUN/TAP to be our router adapter
|
||||
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)
|
||||
if err != nil {
|
||||
logger.Errorln("An error occurred during startup")
|
||||
|
@ -220,9 +220,11 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) (*config.NodeState,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := c.router.adapter.Start(c.router.addr, c.router.subnet); err != nil {
|
||||
c.log.Errorln("Failed to start TUN/TAP")
|
||||
return nil, err
|
||||
if c.router.adapter != nil {
|
||||
if err := c.router.adapter.Start(c.router.addr, c.router.subnet); err != nil {
|
||||
c.log.Errorln("Failed to start TUN/TAP")
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
go c.addPeerLoop()
|
||||
@ -234,7 +236,9 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) (*config.NodeState,
|
||||
// Stops the Yggdrasil node.
|
||||
func (c *Core) Stop() {
|
||||
c.log.Infoln("Stopping...")
|
||||
c.router.adapter.Close()
|
||||
if c.router.adapter != nil {
|
||||
c.router.adapter.Close()
|
||||
}
|
||||
c.admin.close()
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,9 @@ func (r *router) init(core *Core) {
|
||||
r.nodeinfo.setNodeInfo(r.core.config.Current.NodeInfo, r.core.config.Current.NodeInfoPrivacy)
|
||||
r.core.config.Mutex.RUnlock()
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user