mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 06:35:07 +03:00
Fix configuration reloading support
This commit is contained in:
parent
71ccaf753e
commit
ae2cc13d14
4 changed files with 71 additions and 66 deletions
|
@ -41,6 +41,10 @@ func (m *Multicast) Init(core *yggdrasil.Core, state *config.NodeState, log *log
|
|||
go func() {
|
||||
for {
|
||||
e := <-m.reconfigure
|
||||
// There's nothing particularly to do here because the multicast module
|
||||
// already consults the config.NodeState when enumerating multicast
|
||||
// interfaces on each pass. We just need to return nil so that the
|
||||
// reconfiguration doesn't block indefinitely
|
||||
e <- nil
|
||||
}
|
||||
}()
|
||||
|
@ -89,6 +93,36 @@ func (m *Multicast) Stop() error {
|
|||
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.log.Debugln("Reloading multicast configuration...")
|
||||
|
||||
m.config.Replace(*config)
|
||||
|
||||
errors := 0
|
||||
|
||||
components := []chan chan error{
|
||||
m.reconfigure,
|
||||
}
|
||||
|
||||
for _, component := range components {
|
||||
response := make(chan error)
|
||||
component <- response
|
||||
if err := <-response; err != nil {
|
||||
m.log.Errorln(err)
|
||||
errors++
|
||||
}
|
||||
}
|
||||
|
||||
if errors > 0 {
|
||||
m.log.Warnln(errors, "multicast module(s) reported errors during configuration reload")
|
||||
} else {
|
||||
m.log.Infoln("Multicast configuration reloaded successfully")
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Multicast) interfaces() map[string]net.Interface {
|
||||
// Get interface expressions from config
|
||||
current, _ := m.config.Get()
|
||||
|
|
|
@ -148,6 +148,7 @@ func (tun *TunAdapter) Start() error {
|
|||
tun.mutex.Lock()
|
||||
tun.isOpen = true
|
||||
tun.send = make(chan []byte, 32) // TODO: is this a sensible value?
|
||||
tun.reconfigure = make(chan chan error)
|
||||
tun.mutex.Unlock()
|
||||
if iftapmode {
|
||||
go func() {
|
||||
|
@ -178,6 +179,37 @@ func (tun *TunAdapter) Start() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// UpdateConfig updates the TUN/TAP 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/TAP configuration...")
|
||||
|
||||
tun.config.Replace(*config)
|
||||
|
||||
errors := 0
|
||||
|
||||
components := []chan chan error{
|
||||
tun.reconfigure,
|
||||
tun.ckr.reconfigure,
|
||||
}
|
||||
|
||||
for _, component := range components {
|
||||
response := make(chan error)
|
||||
component <- response
|
||||
if err := <-response; err != nil {
|
||||
tun.log.Errorln(err)
|
||||
errors++
|
||||
}
|
||||
}
|
||||
|
||||
if errors > 0 {
|
||||
tun.log.Warnln(errors, "TUN/TAP module(s) reported errors during configuration reload")
|
||||
} else {
|
||||
tun.log.Infoln("TUN/TAP configuration reloaded successfully")
|
||||
}
|
||||
}
|
||||
|
||||
func (tun *TunAdapter) handler() error {
|
||||
for {
|
||||
// Accept the incoming connection
|
||||
|
|
|
@ -114,7 +114,7 @@ func (c *Core) addPeerLoop() {
|
|||
// config.NodeConfig and then signals the various module goroutines to
|
||||
// reconfigure themselves if needed.
|
||||
func (c *Core) UpdateConfig(config *config.NodeConfig) {
|
||||
c.log.Infoln("Reloading configuration...")
|
||||
c.log.Debugln("Reloading node configuration...")
|
||||
|
||||
c.config.Replace(*config)
|
||||
|
||||
|
@ -141,9 +141,9 @@ func (c *Core) UpdateConfig(config *config.NodeConfig) {
|
|||
}
|
||||
|
||||
if errors > 0 {
|
||||
c.log.Warnln(errors, "modules reported errors during configuration reload")
|
||||
c.log.Warnln(errors, "node module(s) reported errors during configuration reload")
|
||||
} else {
|
||||
c.log.Infoln("Configuration reloaded successfully")
|
||||
c.log.Infoln("Node configuration reloaded successfully")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue