Browse Source

make rehash-enable logic a little more uniform

tags/v2.0.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
76a8768d05
2 changed files with 48 additions and 66 deletions
  1. 6
    4
      irc/channelmanager.go
  2. 42
    62
      irc/server.go

+ 6
- 4
irc/channelmanager.go View File

@@ -30,12 +30,14 @@ func (cm *ChannelManager) Initialize(server *Server) {
30 30
 	cm.chans = make(map[string]*channelManagerEntry)
31 31
 	cm.server = server
32 32
 
33
-	if server.Config().Channels.Registration.Enabled {
34
-		cm.loadRegisteredChannels()
35
-	}
33
+	cm.loadRegisteredChannels(server.Config())
36 34
 }
37 35
 
38
-func (cm *ChannelManager) loadRegisteredChannels() {
36
+func (cm *ChannelManager) loadRegisteredChannels(config *Config) {
37
+	if !config.Channels.Registration.Enabled {
38
+		return
39
+	}
40
+
39 41
 	registeredChannels := cm.server.channelRegistry.AllChannels()
40 42
 	cm.Lock()
41 43
 	defer cm.Unlock()

+ 42
- 62
irc/server.go View File

@@ -611,18 +611,10 @@ func (server *Server) applyConfig(config *Config, initial bool) (err error) {
611 611
 		}
612 612
 	}
613 613
 
614
-	// sanity checks complete, start modifying server state
615 614
 	server.logger.Info("server", "Using config file", server.configFilename)
616 615
 	oldConfig := server.Config()
617 616
 
618 617
 	// first, reload config sections for functionality implemented in subpackages:
619
-
620
-	server.connectionLimiter.ApplyConfig(&config.Server.IPLimits)
621
-
622
-	tlConf := &config.Server.TorListeners
623
-	server.torLimiter.Configure(tlConf.MaxConnections, tlConf.ThrottleDuration, tlConf.MaxConnectionsPerDuration)
624
-
625
-	// reload logging config
626 618
 	wasLoggingRawIO := !initial && server.logger.IsLoggingRawIO()
627 619
 	err = server.logger.ApplyConfig(config.Logging)
628 620
 	if err != nil {
@@ -632,6 +624,11 @@ func (server *Server) applyConfig(config *Config, initial bool) (err error) {
632 624
 	// notify existing clients if raw i/o logging was enabled by a rehash
633 625
 	sendRawOutputNotice := !wasLoggingRawIO && nowLoggingRawIO
634 626
 
627
+	server.connectionLimiter.ApplyConfig(&config.Server.IPLimits)
628
+
629
+	tlConf := &config.Server.TorListeners
630
+	server.torLimiter.Configure(tlConf.MaxConnections, tlConf.ThrottleDuration, tlConf.MaxConnectionsPerDuration)
631
+
635 632
 	// setup new and removed caps
636 633
 	addedCaps := caps.NewSet()
637 634
 	removedCaps := caps.NewSet()
@@ -641,67 +638,50 @@ func (server *Server) applyConfig(config *Config, initial bool) (err error) {
641 638
 	server.logger.Debug("server", "Regenerating HELP indexes for new languages")
642 639
 	server.helpIndexManager.GenerateIndices(config.languageManager)
643 640
 
644
-	if oldConfig != nil && config.Server.capValues[caps.Languages] != oldConfig.Server.capValues[caps.Languages] {
645
-		updatedCaps.Add(caps.Languages)
646
-	}
647
-
648
-	// SASL
649
-	authPreviouslyEnabled := oldConfig != nil && oldConfig.Accounts.AuthenticationEnabled
650
-	if config.Accounts.AuthenticationEnabled && (oldConfig == nil || !authPreviouslyEnabled) {
651
-		// enabling SASL
652
-		addedCaps.Add(caps.SASL)
653
-	} else if !config.Accounts.AuthenticationEnabled && (oldConfig == nil || authPreviouslyEnabled) {
654
-		// disabling SASL
655
-		removedCaps.Add(caps.SASL)
656
-	}
657
-
658
-	nickReservationPreviouslyDisabled := oldConfig != nil && !oldConfig.Accounts.NickReservation.Enabled
659
-	nickReservationNowEnabled := config.Accounts.NickReservation.Enabled
660
-	if nickReservationPreviouslyDisabled && nickReservationNowEnabled {
661
-		server.accounts.buildNickToAccountIndex(config)
662
-	}
663
-
664
-	hsPreviouslyDisabled := oldConfig != nil && !oldConfig.Accounts.VHosts.Enabled
665
-	hsNowEnabled := config.Accounts.VHosts.Enabled
666
-	if hsPreviouslyDisabled && hsNowEnabled {
667
-		server.accounts.initVHostRequestQueue(config)
668
-	}
669
-
670
-	chanRegPreviouslyDisabled := oldConfig != nil && !oldConfig.Channels.Registration.Enabled
671
-	chanRegNowEnabled := config.Channels.Registration.Enabled
672
-	if chanRegPreviouslyDisabled && chanRegNowEnabled {
673
-		server.channels.loadRegisteredChannels()
674
-	}
675
-
676
-	// STS
677
-	stsPreviouslyEnabled := oldConfig != nil && oldConfig.Server.STS.Enabled
678
-	stsValue := config.Server.capValues[caps.STS]
679
-	stsCurrentCapValue := ""
680 641
 	if oldConfig != nil {
681
-		stsCurrentCapValue = oldConfig.Server.capValues[caps.STS]
682
-	}
683
-	server.logger.Debug("server", "STS Vals", stsCurrentCapValue, stsValue, fmt.Sprintf("server[%v] config[%v]", stsPreviouslyEnabled, config.Server.STS.Enabled))
684
-	if (config.Server.STS.Enabled != stsPreviouslyEnabled) || (stsValue != stsCurrentCapValue) {
685
-		// XXX: STS is always removed by CAP NEW sts=duration=0, not CAP DEL
686
-		// so the appropriate notify is always a CAP NEW; put it in addedCaps for any change
687
-		addedCaps.Add(caps.STS)
688
-	}
642
+		// cap changes
643
+		if oldConfig.Server.capValues[caps.Languages] != config.Server.capValues[caps.Languages] {
644
+			updatedCaps.Add(caps.Languages)
645
+		}
646
+
647
+		if !oldConfig.Accounts.AuthenticationEnabled && config.Accounts.AuthenticationEnabled {
648
+			addedCaps.Add(caps.SASL)
649
+		} else if oldConfig.Accounts.AuthenticationEnabled && !config.Accounts.AuthenticationEnabled {
650
+			removedCaps.Add(caps.SASL)
651
+		}
689 652
 
690
-	if oldConfig != nil && config.Accounts.Bouncer.Enabled != oldConfig.Accounts.Bouncer.Enabled {
691
-		if config.Accounts.Bouncer.Enabled {
653
+		if !oldConfig.Accounts.Bouncer.Enabled && config.Accounts.Bouncer.Enabled {
692 654
 			addedCaps.Add(caps.Bouncer)
693
-		} else {
655
+		} else if oldConfig.Accounts.Bouncer.Enabled && !config.Accounts.Bouncer.Enabled {
694 656
 			removedCaps.Add(caps.Bouncer)
695 657
 		}
696
-	}
697 658
 
698
-	// resize history buffers as needed
699
-	if oldConfig != nil && oldConfig.History != config.History {
700
-		for _, channel := range server.channels.Channels() {
701
-			channel.history.Resize(config.History.ChannelLength, config.History.AutoresizeWindow)
659
+		if oldConfig.Server.STS.Enabled != config.Server.STS.Enabled || oldConfig.Server.capValues[caps.STS] != config.Server.capValues[caps.STS] {
660
+			// XXX: STS is always removed by CAP NEW sts=duration=0, not CAP DEL
661
+			// so the appropriate notify is always a CAP NEW; put it in addedCaps for any change
662
+			addedCaps.Add(caps.STS)
663
+		}
664
+
665
+		// if certain features were enabled by rehash, we need to load the corresponding data
666
+		// from the store
667
+		if !oldConfig.Accounts.NickReservation.Enabled {
668
+			server.accounts.buildNickToAccountIndex(config)
669
+		}
670
+		if !oldConfig.Accounts.VHosts.Enabled {
671
+			server.accounts.initVHostRequestQueue(config)
702 672
 		}
703
-		for _, client := range server.clients.AllClients() {
704
-			client.history.Resize(config.History.ClientLength, config.History.AutoresizeWindow)
673
+		if !oldConfig.Channels.Registration.Enabled {
674
+			server.channels.loadRegisteredChannels(config)
675
+		}
676
+
677
+		// resize history buffers as needed
678
+		if oldConfig.History != config.History {
679
+			for _, channel := range server.channels.Channels() {
680
+				channel.history.Resize(config.History.ChannelLength, config.History.AutoresizeWindow)
681
+			}
682
+			for _, client := range server.clients.AllClients() {
683
+				client.history.Resize(config.History.ClientLength, config.History.AutoresizeWindow)
684
+			}
705 685
 		}
706 686
 	}
707 687
 

Loading…
Cancel
Save