mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-23 18:15:24 +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
|
// 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")
|
||||||
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user