diff --git a/cmd/yggdrasil/main.go b/cmd/yggdrasil/main.go index 72f02840..9278867b 100644 --- a/cmd/yggdrasil/main.go +++ b/cmd/yggdrasil/main.go @@ -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") diff --git a/src/yggdrasil/core.go b/src/yggdrasil/core.go index dbc893a8..0e9b251e 100644 --- a/src/yggdrasil/core.go +++ b/src/yggdrasil/core.go @@ -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() } diff --git a/src/yggdrasil/router.go b/src/yggdrasil/router.go index 6314cb12..bef564fd 100644 --- a/src/yggdrasil/router.go +++ b/src/yggdrasil/router.go @@ -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.