mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	Remove reconfiguration on SIGHUP - it didn't work reliably anyway
This commit is contained in:
		
							parent
							
								
									e12c639c21
								
							
						
					
					
						commit
						57ea61b338
					
				
					 6 changed files with 2 additions and 97 deletions
				
			
		| 
						 | 
					@ -323,31 +323,10 @@ func main() {
 | 
				
			||||||
	logger.Infof("Your IPv6 subnet is %s", subnet.String())
 | 
						logger.Infof("Your IPv6 subnet is %s", subnet.String())
 | 
				
			||||||
	// Catch interrupts from the operating system to exit gracefully.
 | 
						// Catch interrupts from the operating system to exit gracefully.
 | 
				
			||||||
	c := make(chan os.Signal, 1)
 | 
						c := make(chan os.Signal, 1)
 | 
				
			||||||
	r := make(chan os.Signal, 1)
 | 
					 | 
				
			||||||
	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
 | 
						signal.Notify(c, os.Interrupt, syscall.SIGTERM)
 | 
				
			||||||
	signal.Notify(r, os.Interrupt, syscall.SIGHUP)
 | 
					 | 
				
			||||||
	// Capture the service being stopped on Windows.
 | 
						// Capture the service being stopped on Windows.
 | 
				
			||||||
	minwinsvc.SetOnExit(n.shutdown)
 | 
						minwinsvc.SetOnExit(n.shutdown)
 | 
				
			||||||
	defer n.shutdown()
 | 
						n.shutdown()
 | 
				
			||||||
	// Wait for the terminate/interrupt signal. Once a signal is received, the
 | 
					 | 
				
			||||||
	// deferred Stop function above will run which will shut down TUN/TAP.
 | 
					 | 
				
			||||||
	for {
 | 
					 | 
				
			||||||
		select {
 | 
					 | 
				
			||||||
		case <-c:
 | 
					 | 
				
			||||||
			goto exit
 | 
					 | 
				
			||||||
		case <-r:
 | 
					 | 
				
			||||||
			if *useconffile != "" {
 | 
					 | 
				
			||||||
				cfg = readConfig(useconf, useconffile, normaliseconf)
 | 
					 | 
				
			||||||
				logger.Infoln("Reloading configuration from", *useconffile)
 | 
					 | 
				
			||||||
				n.core.UpdateConfig(cfg)
 | 
					 | 
				
			||||||
				n.tuntap.UpdateConfig(cfg)
 | 
					 | 
				
			||||||
				n.multicast.UpdateConfig(cfg)
 | 
					 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				logger.Errorln("Reloading config at runtime is only possible with -useconffile")
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
exit:
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (n *node) shutdown() {
 | 
					func (n *node) shutdown() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,7 @@ import (
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"net/url"
 | 
						"net/url"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//"strconv"
 | 
						//"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
| 
						 | 
					@ -70,17 +71,6 @@ func (a *AdminSocket) Init(c *yggdrasil.Core, state *config.NodeState, log *log.
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (a *AdminSocket) UpdateConfig(config *config.NodeConfig) {
 | 
					 | 
				
			||||||
	a.log.Debugln("Reloading admin configuration...")
 | 
					 | 
				
			||||||
	if a.listenaddr != config.AdminListen {
 | 
					 | 
				
			||||||
		a.listenaddr = config.AdminListen
 | 
					 | 
				
			||||||
		if a.IsStarted() {
 | 
					 | 
				
			||||||
			a.Stop()
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		a.Start()
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (a *AdminSocket) SetupAdminHandlers(na *AdminSocket) {
 | 
					func (a *AdminSocket) SetupAdminHandlers(na *AdminSocket) {
 | 
				
			||||||
	/* TODO
 | 
						/* TODO
 | 
				
			||||||
	a.AddHandler("getSelf", []string{}, func(in Info) (Info, error) {
 | 
						a.AddHandler("getSelf", []string{}, func(in Info) (Info, error) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,7 +14,6 @@ type Module interface {
 | 
				
			||||||
	Init(core *yggdrasil.Core, state *config.NodeState, log *log.Logger, options interface{}) error
 | 
						Init(core *yggdrasil.Core, state *config.NodeState, log *log.Logger, options interface{}) error
 | 
				
			||||||
	Start() error
 | 
						Start() error
 | 
				
			||||||
	Stop() error
 | 
						Stop() error
 | 
				
			||||||
	UpdateConfig(config *config.NodeConfig)
 | 
					 | 
				
			||||||
	SetupAdminHandlers(a *admin.AdminSocket)
 | 
						SetupAdminHandlers(a *admin.AdminSocket)
 | 
				
			||||||
	IsStarted() bool
 | 
						IsStarted() bool
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -129,32 +129,6 @@ func (m *Multicast) _stop() error {
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UpdateConfig updates the multicast module with the provided config.NodeConfig
 | 
					 | 
				
			||||||
// and then signals the various module goroutines to reconfigure themselves if
 | 
					 | 
				
			||||||
// needed.
 | 
					 | 
				
			||||||
func (m *Multicast) UpdateConfig(config *config.NodeConfig) {
 | 
					 | 
				
			||||||
	m.Act(nil, func() { m._updateConfig(config) })
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (m *Multicast) _updateConfig(config *config.NodeConfig) {
 | 
					 | 
				
			||||||
	m.log.Infoln("Reloading multicast configuration...")
 | 
					 | 
				
			||||||
	if m.isOpen {
 | 
					 | 
				
			||||||
		if len(config.MulticastInterfaces) == 0 || config.LinkLocalTCPPort != m.listenPort {
 | 
					 | 
				
			||||||
			if err := m._stop(); err != nil {
 | 
					 | 
				
			||||||
				m.log.Errorln("Error stopping multicast module:", err)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	m.config.Replace(*config)
 | 
					 | 
				
			||||||
	m.listenPort = config.LinkLocalTCPPort
 | 
					 | 
				
			||||||
	if !m.isOpen && len(config.MulticastInterfaces) > 0 {
 | 
					 | 
				
			||||||
		if err := m._start(); err != nil {
 | 
					 | 
				
			||||||
			m.log.Errorln("Error starting multicast module:", err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	m.log.Debugln("Reloaded multicast configuration successfully")
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (m *Multicast) _updateInterfaces() {
 | 
					func (m *Multicast) _updateInterfaces() {
 | 
				
			||||||
	interfaces := make(map[string]interfaceInfo)
 | 
						interfaces := make(map[string]interfaceInfo)
 | 
				
			||||||
	intfs := m.getAllowedInterfaces()
 | 
						intfs := m.getAllowedInterfaces()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,7 +40,6 @@ type TunAdapter struct {
 | 
				
			||||||
	store       keyStore
 | 
						store       keyStore
 | 
				
			||||||
	config      *config.NodeState
 | 
						config      *config.NodeState
 | 
				
			||||||
	log         *log.Logger
 | 
						log         *log.Logger
 | 
				
			||||||
	reconfigure chan chan error
 | 
					 | 
				
			||||||
	addr        address.Address
 | 
						addr        address.Address
 | 
				
			||||||
	subnet      address.Subnet
 | 
						subnet      address.Subnet
 | 
				
			||||||
	ckr         cryptokey
 | 
						ckr         cryptokey
 | 
				
			||||||
| 
						 | 
					@ -197,25 +196,6 @@ func (tun *TunAdapter) _stop() error {
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UpdateConfig updates the TUN module with the provided config.NodeConfig
 | 
					 | 
				
			||||||
// and then signals the various module goroutines to reconfigure themselves if
 | 
					 | 
				
			||||||
// needed.
 | 
					 | 
				
			||||||
func (tun *TunAdapter) UpdateConfig(config *config.NodeConfig) {
 | 
					 | 
				
			||||||
	tun.log.Debugln("Reloading TUN configuration...")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Replace the active configuration with the supplied one
 | 
					 | 
				
			||||||
	tun.config.Replace(*config)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// If the MTU has changed in the TUN module then this is where we would
 | 
					 | 
				
			||||||
	// tell the router so that updated session pings can be sent. However, we
 | 
					 | 
				
			||||||
	// don't currently update the MTU of the adapter once it has been created so
 | 
					 | 
				
			||||||
	// this doesn't actually happen in the real world yet.
 | 
					 | 
				
			||||||
	//   tun.core.SetMaximumSessionMTU(...)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Notify children about the configuration change
 | 
					 | 
				
			||||||
	tun.Act(nil, tun.ckr.configure)
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (tun *TunAdapter) oobHandler(fromKey, toKey ed25519.PublicKey, data []byte) {
 | 
					func (tun *TunAdapter) oobHandler(fromKey, toKey ed25519.PublicKey, data []byte) {
 | 
				
			||||||
	if len(data) != 1+ed25519.SignatureSize {
 | 
						if len(data) != 1+ed25519.SignatureSize {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -90,23 +90,6 @@ func (c *Core) _addPeerLoop() {
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UpdateConfig updates the configuration in Core with the provided
 | 
					 | 
				
			||||||
// config.NodeConfig and then signals the various module goroutines to
 | 
					 | 
				
			||||||
// reconfigure themselves if needed.
 | 
					 | 
				
			||||||
func (c *Core) UpdateConfig(config *config.NodeConfig) {
 | 
					 | 
				
			||||||
	c.Act(nil, func() {
 | 
					 | 
				
			||||||
		c.log.Debugln("Reloading node configuration...")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Replace the active configuration with the supplied one
 | 
					 | 
				
			||||||
		c.config.Replace(*config)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Notify the router and switch about the new configuration
 | 
					 | 
				
			||||||
		panic("TODO")
 | 
					 | 
				
			||||||
		//c.router.Act(c, c.router.reconfigure)
 | 
					 | 
				
			||||||
		//c.switchTable.Act(c, c.switchTable.reconfigure)
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Start starts up Yggdrasil using the provided config.NodeConfig, and outputs
 | 
					// Start starts up Yggdrasil using the provided config.NodeConfig, and outputs
 | 
				
			||||||
// debug logging through the provided log.Logger. The started stack will include
 | 
					// debug logging through the provided log.Logger. The started stack will include
 | 
				
			||||||
// TCP and UDP sockets, a multicast discovery socket, an admin socket, router,
 | 
					// TCP and UDP sockets, a multicast discovery socket, an admin socket, router,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue