mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	Don't crash if Yggdrasil is started with no router adapter
This commit is contained in:
		
							parent
							
								
									dd05a7f2a8
								
							
						
					
					
						commit
						a830521078
					
				
					 3 changed files with 14 additions and 8 deletions
				
			
		| 
						 | 
					@ -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,10 +220,12 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) (*config.NodeState,
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if c.router.adapter != nil {
 | 
				
			||||||
		if err := c.router.adapter.Start(c.router.addr, c.router.subnet); err != nil {
 | 
							if err := c.router.adapter.Start(c.router.addr, c.router.subnet); err != nil {
 | 
				
			||||||
			c.log.Errorln("Failed to start TUN/TAP")
 | 
								c.log.Errorln("Failed to start TUN/TAP")
 | 
				
			||||||
			return nil, err
 | 
								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...")
 | 
				
			||||||
 | 
						if c.router.adapter != nil {
 | 
				
			||||||
		c.router.adapter.Close()
 | 
							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)
 | 
				
			||||||
 | 
						if r.adapter != nil {
 | 
				
			||||||
		r.adapter.Init(&r.core.config, r.core.log, send, recv, reject)
 | 
							r.adapter.Init(&r.core.config, r.core.log, send, recv, reject)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Starts the mainLoop goroutine.
 | 
					// Starts the mainLoop goroutine.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue