make rehash-enable logic a little more uniform

This commit is contained in:
Shivaram Lingamneni 2019-12-22 08:17:56 -05:00
parent bd6c2117e8
commit 76a8768d05
2 changed files with 48 additions and 66 deletions

View File

@ -30,12 +30,14 @@ func (cm *ChannelManager) Initialize(server *Server) {
cm.chans = make(map[string]*channelManagerEntry) cm.chans = make(map[string]*channelManagerEntry)
cm.server = server cm.server = server
if server.Config().Channels.Registration.Enabled { cm.loadRegisteredChannels(server.Config())
cm.loadRegisteredChannels() }
}
func (cm *ChannelManager) loadRegisteredChannels(config *Config) {
if !config.Channels.Registration.Enabled {
return
} }
func (cm *ChannelManager) loadRegisteredChannels() {
registeredChannels := cm.server.channelRegistry.AllChannels() registeredChannels := cm.server.channelRegistry.AllChannels()
cm.Lock() cm.Lock()
defer cm.Unlock() defer cm.Unlock()

View File

@ -611,18 +611,10 @@ func (server *Server) applyConfig(config *Config, initial bool) (err error) {
} }
} }
// sanity checks complete, start modifying server state
server.logger.Info("server", "Using config file", server.configFilename) server.logger.Info("server", "Using config file", server.configFilename)
oldConfig := server.Config() oldConfig := server.Config()
// first, reload config sections for functionality implemented in subpackages: // first, reload config sections for functionality implemented in subpackages:
server.connectionLimiter.ApplyConfig(&config.Server.IPLimits)
tlConf := &config.Server.TorListeners
server.torLimiter.Configure(tlConf.MaxConnections, tlConf.ThrottleDuration, tlConf.MaxConnectionsPerDuration)
// reload logging config
wasLoggingRawIO := !initial && server.logger.IsLoggingRawIO() wasLoggingRawIO := !initial && server.logger.IsLoggingRawIO()
err = server.logger.ApplyConfig(config.Logging) err = server.logger.ApplyConfig(config.Logging)
if err != nil { if err != nil {
@ -632,6 +624,11 @@ func (server *Server) applyConfig(config *Config, initial bool) (err error) {
// notify existing clients if raw i/o logging was enabled by a rehash // notify existing clients if raw i/o logging was enabled by a rehash
sendRawOutputNotice := !wasLoggingRawIO && nowLoggingRawIO sendRawOutputNotice := !wasLoggingRawIO && nowLoggingRawIO
server.connectionLimiter.ApplyConfig(&config.Server.IPLimits)
tlConf := &config.Server.TorListeners
server.torLimiter.Configure(tlConf.MaxConnections, tlConf.ThrottleDuration, tlConf.MaxConnectionsPerDuration)
// setup new and removed caps // setup new and removed caps
addedCaps := caps.NewSet() addedCaps := caps.NewSet()
removedCaps := caps.NewSet() removedCaps := caps.NewSet()
@ -641,62 +638,44 @@ func (server *Server) applyConfig(config *Config, initial bool) (err error) {
server.logger.Debug("server", "Regenerating HELP indexes for new languages") server.logger.Debug("server", "Regenerating HELP indexes for new languages")
server.helpIndexManager.GenerateIndices(config.languageManager) server.helpIndexManager.GenerateIndices(config.languageManager)
if oldConfig != nil && config.Server.capValues[caps.Languages] != oldConfig.Server.capValues[caps.Languages] { if oldConfig != nil {
// cap changes
if oldConfig.Server.capValues[caps.Languages] != config.Server.capValues[caps.Languages] {
updatedCaps.Add(caps.Languages) updatedCaps.Add(caps.Languages)
} }
// SASL if !oldConfig.Accounts.AuthenticationEnabled && config.Accounts.AuthenticationEnabled {
authPreviouslyEnabled := oldConfig != nil && oldConfig.Accounts.AuthenticationEnabled
if config.Accounts.AuthenticationEnabled && (oldConfig == nil || !authPreviouslyEnabled) {
// enabling SASL
addedCaps.Add(caps.SASL) addedCaps.Add(caps.SASL)
} else if !config.Accounts.AuthenticationEnabled && (oldConfig == nil || authPreviouslyEnabled) { } else if oldConfig.Accounts.AuthenticationEnabled && !config.Accounts.AuthenticationEnabled {
// disabling SASL
removedCaps.Add(caps.SASL) removedCaps.Add(caps.SASL)
} }
nickReservationPreviouslyDisabled := oldConfig != nil && !oldConfig.Accounts.NickReservation.Enabled if !oldConfig.Accounts.Bouncer.Enabled && config.Accounts.Bouncer.Enabled {
nickReservationNowEnabled := config.Accounts.NickReservation.Enabled addedCaps.Add(caps.Bouncer)
if nickReservationPreviouslyDisabled && nickReservationNowEnabled { } else if oldConfig.Accounts.Bouncer.Enabled && !config.Accounts.Bouncer.Enabled {
server.accounts.buildNickToAccountIndex(config) removedCaps.Add(caps.Bouncer)
} }
hsPreviouslyDisabled := oldConfig != nil && !oldConfig.Accounts.VHosts.Enabled if oldConfig.Server.STS.Enabled != config.Server.STS.Enabled || oldConfig.Server.capValues[caps.STS] != config.Server.capValues[caps.STS] {
hsNowEnabled := config.Accounts.VHosts.Enabled
if hsPreviouslyDisabled && hsNowEnabled {
server.accounts.initVHostRequestQueue(config)
}
chanRegPreviouslyDisabled := oldConfig != nil && !oldConfig.Channels.Registration.Enabled
chanRegNowEnabled := config.Channels.Registration.Enabled
if chanRegPreviouslyDisabled && chanRegNowEnabled {
server.channels.loadRegisteredChannels()
}
// STS
stsPreviouslyEnabled := oldConfig != nil && oldConfig.Server.STS.Enabled
stsValue := config.Server.capValues[caps.STS]
stsCurrentCapValue := ""
if oldConfig != nil {
stsCurrentCapValue = oldConfig.Server.capValues[caps.STS]
}
server.logger.Debug("server", "STS Vals", stsCurrentCapValue, stsValue, fmt.Sprintf("server[%v] config[%v]", stsPreviouslyEnabled, config.Server.STS.Enabled))
if (config.Server.STS.Enabled != stsPreviouslyEnabled) || (stsValue != stsCurrentCapValue) {
// XXX: STS is always removed by CAP NEW sts=duration=0, not CAP DEL // XXX: STS is always removed by CAP NEW sts=duration=0, not CAP DEL
// so the appropriate notify is always a CAP NEW; put it in addedCaps for any change // so the appropriate notify is always a CAP NEW; put it in addedCaps for any change
addedCaps.Add(caps.STS) addedCaps.Add(caps.STS)
} }
if oldConfig != nil && config.Accounts.Bouncer.Enabled != oldConfig.Accounts.Bouncer.Enabled { // if certain features were enabled by rehash, we need to load the corresponding data
if config.Accounts.Bouncer.Enabled { // from the store
addedCaps.Add(caps.Bouncer) if !oldConfig.Accounts.NickReservation.Enabled {
} else { server.accounts.buildNickToAccountIndex(config)
removedCaps.Add(caps.Bouncer)
} }
if !oldConfig.Accounts.VHosts.Enabled {
server.accounts.initVHostRequestQueue(config)
}
if !oldConfig.Channels.Registration.Enabled {
server.channels.loadRegisteredChannels(config)
} }
// resize history buffers as needed // resize history buffers as needed
if oldConfig != nil && oldConfig.History != config.History { if oldConfig.History != config.History {
for _, channel := range server.channels.Channels() { for _, channel := range server.channels.Channels() {
channel.history.Resize(config.History.ChannelLength, config.History.AutoresizeWindow) channel.history.Resize(config.History.ChannelLength, config.History.AutoresizeWindow)
} }
@ -704,6 +683,7 @@ func (server *Server) applyConfig(config *Config, initial bool) (err error) {
client.history.Resize(config.History.ClientLength, config.History.AutoresizeWindow) client.history.Resize(config.History.ClientLength, config.History.AutoresizeWindow)
} }
} }
}
// activate the new config // activate the new config
server.SetConfig(config) server.SetConfig(config)