mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15: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()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue