Kaynağa Gözat

remove more indirections

tags/v1.1.0-rc1
Shivaram Lingamneni 5 yıl önce
ebeveyn
işleme
80a594802f

+ 4
- 11
irc/connection_limits/limiter.go Dosyayı Görüntüle

98
 	}
98
 	}
99
 }
99
 }
100
 
100
 
101
-// NewLimiter returns a new connection limit handler.
102
-// The handler is functional, but disabled; it can be enabled via `ApplyConfig`.
103
-func NewLimiter() *Limiter {
104
-	var cl Limiter
105
-
106
-	// initialize empty population; all other state is configurable
107
-	cl.population = make(map[string]int)
108
-
109
-	return &cl
110
-}
111
-
112
 // ApplyConfig atomically applies a config update to a connection limit handler
101
 // ApplyConfig atomically applies a config update to a connection limit handler
113
 func (cl *Limiter) ApplyConfig(config LimiterConfig) error {
102
 func (cl *Limiter) ApplyConfig(config LimiterConfig) error {
114
 	// assemble exempted nets
103
 	// assemble exempted nets
120
 	cl.Lock()
109
 	cl.Lock()
121
 	defer cl.Unlock()
110
 	defer cl.Unlock()
122
 
111
 
112
+	if cl.population == nil {
113
+		cl.population = make(map[string]int)
114
+	}
115
+
123
 	cl.enabled = config.Enabled
116
 	cl.enabled = config.Enabled
124
 	cl.ipv4Mask = net.CIDRMask(config.CidrLenIPv4, 32)
117
 	cl.ipv4Mask = net.CIDRMask(config.CidrLenIPv4, 32)
125
 	cl.ipv6Mask = net.CIDRMask(config.CidrLenIPv6, 128)
118
 	cl.ipv6Mask = net.CIDRMask(config.CidrLenIPv6, 128)

+ 4
- 11
irc/connection_limits/throttler.go Dosyayı Görüntüle

150
 	return ct.banMessage
150
 	return ct.banMessage
151
 }
151
 }
152
 
152
 
153
-// NewThrottler returns a new client connection throttler.
154
-// The throttler is functional, but disabled; it can be enabled via `ApplyConfig`.
155
-func NewThrottler() *Throttler {
156
-	var ct Throttler
157
-
158
-	// initialize empty population; all other state is configurable
159
-	ct.population = make(map[string]ThrottleDetails)
160
-
161
-	return &ct
162
-}
163
-
164
 // ApplyConfig atomically applies a config update to a throttler
153
 // ApplyConfig atomically applies a config update to a throttler
165
 func (ct *Throttler) ApplyConfig(config ThrottlerConfig) error {
154
 func (ct *Throttler) ApplyConfig(config ThrottlerConfig) error {
166
 	// assemble exempted nets
155
 	// assemble exempted nets
172
 	ct.Lock()
161
 	ct.Lock()
173
 	defer ct.Unlock()
162
 	defer ct.Unlock()
174
 
163
 
164
+	if ct.population == nil {
165
+		ct.population = make(map[string]ThrottleDetails)
166
+	}
167
+
175
 	ct.enabled = config.Enabled
168
 	ct.enabled = config.Enabled
176
 	ct.ipv4Mask = net.CIDRMask(config.CidrLenIPv4, 32)
169
 	ct.ipv4Mask = net.CIDRMask(config.CidrLenIPv4, 32)
177
 	ct.ipv6Mask = net.CIDRMask(config.CidrLenIPv6, 128)
170
 	ct.ipv6Mask = net.CIDRMask(config.CidrLenIPv6, 128)

+ 2
- 2
irc/connection_limits/throttler_test.go Dosyayı Görüntüle

72
 		ConnectionsPerCidr: maxConnections,
72
 		ConnectionsPerCidr: maxConnections,
73
 		Duration:           minute,
73
 		Duration:           minute,
74
 	}
74
 	}
75
-	throttler := NewThrottler()
75
+	var throttler Throttler
76
 	throttler.ApplyConfig(config)
76
 	throttler.ApplyConfig(config)
77
-	return throttler
77
+	return &throttler
78
 }
78
 }
79
 
79
 
80
 func TestConnectionThrottle(t *testing.T) {
80
 func TestConnectionThrottle(t *testing.T) {

+ 3
- 7
irc/monitor.go Dosyayı Görüntüle

19
 	// (all nicks must be normalized externally by casefolding)
19
 	// (all nicks must be normalized externally by casefolding)
20
 }
20
 }
21
 
21
 
22
-// NewMonitorManager returns a new MonitorManager.
23
-func NewMonitorManager() *MonitorManager {
24
-	mm := MonitorManager{
25
-		watching:  make(map[*Client]map[string]bool),
26
-		watchedby: make(map[string]map[*Client]bool),
27
-	}
28
-	return &mm
22
+func (mm *MonitorManager) Initialize() {
23
+	mm.watching = make(map[*Client]map[string]bool)
24
+	mm.watchedby = make(map[string]map[*Client]bool)
29
 }
25
 }
30
 
26
 
31
 // AlertAbout alerts everyone monitoring `client`'s nick that `client` is now {on,off}line.
27
 // AlertAbout alerts everyone monitoring `client`'s nick that `client` is now {on,off}line.

+ 11
- 13
irc/server.go Dosyayı Görüntüle

67
 	clients             ClientManager
67
 	clients             ClientManager
68
 	config              unsafe.Pointer
68
 	config              unsafe.Pointer
69
 	configFilename      string
69
 	configFilename      string
70
-	connectionLimiter   *connection_limits.Limiter
71
-	connectionThrottler *connection_limits.Throttler
70
+	connectionLimiter   connection_limits.Limiter
71
+	connectionThrottler connection_limits.Throttler
72
 	ctime               time.Time
72
 	ctime               time.Time
73
 	dlines              *DLineManager
73
 	dlines              *DLineManager
74
 	helpIndexManager    HelpIndexManager
74
 	helpIndexManager    HelpIndexManager
75
 	klines              *KLineManager
75
 	klines              *KLineManager
76
 	listeners           map[string]*ListenerWrapper
76
 	listeners           map[string]*ListenerWrapper
77
 	logger              *logger.Manager
77
 	logger              *logger.Manager
78
-	monitorManager      *MonitorManager
78
+	monitorManager      MonitorManager
79
 	name                string
79
 	name                string
80
 	nameCasefolded      string
80
 	nameCasefolded      string
81
 	rehashMutex         sync.Mutex // tier 4
81
 	rehashMutex         sync.Mutex // tier 4
83
 	pprofServer         *http.Server
83
 	pprofServer         *http.Server
84
 	resumeManager       ResumeManager
84
 	resumeManager       ResumeManager
85
 	signals             chan os.Signal
85
 	signals             chan os.Signal
86
-	snomasks            *SnoManager
86
+	snomasks            SnoManager
87
 	store               *buntdb.DB
87
 	store               *buntdb.DB
88
 	torLimiter          connection_limits.TorLimiter
88
 	torLimiter          connection_limits.TorLimiter
89
 	whoWas              WhoWasList
89
 	whoWas              WhoWasList
110
 func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
110
 func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
111
 	// initialize data structures
111
 	// initialize data structures
112
 	server := &Server{
112
 	server := &Server{
113
-		ctime:               time.Now().UTC(),
114
-		connectionLimiter:   connection_limits.NewLimiter(),
115
-		connectionThrottler: connection_limits.NewThrottler(),
116
-		listeners:           make(map[string]*ListenerWrapper),
117
-		logger:              logger,
118
-		monitorManager:      NewMonitorManager(),
119
-		rehashSignal:        make(chan os.Signal, 1),
120
-		signals:             make(chan os.Signal, len(ServerExitSignals)),
121
-		snomasks:            NewSnoManager(),
113
+		ctime:        time.Now().UTC(),
114
+		listeners:    make(map[string]*ListenerWrapper),
115
+		logger:       logger,
116
+		rehashSignal: make(chan os.Signal, 1),
117
+		signals:      make(chan os.Signal, len(ServerExitSignals)),
122
 	}
118
 	}
123
 
119
 
124
 	server.clients.Initialize()
120
 	server.clients.Initialize()
125
 	server.semaphores.Initialize()
121
 	server.semaphores.Initialize()
126
 	server.resumeManager.Initialize(server)
122
 	server.resumeManager.Initialize(server)
127
 	server.whoWas.Initialize(config.Limits.WhowasEntries)
123
 	server.whoWas.Initialize(config.Limits.WhowasEntries)
124
+	server.monitorManager.Initialize()
125
+	server.snomasks.Initialize()
128
 
126
 
129
 	if err := server.applyConfig(config, true); err != nil {
127
 	if err := server.applyConfig(config, true); err != nil {
130
 		return nil, err
128
 		return nil, err

+ 1
- 4
irc/snomanager.go Dosyayı Görüntüle

14
 	sendLists     map[sno.Mask]map[*Client]bool
14
 	sendLists     map[sno.Mask]map[*Client]bool
15
 }
15
 }
16
 
16
 
17
-// NewSnoManager returns a new SnoManager
18
-func NewSnoManager() *SnoManager {
19
-	var m SnoManager
17
+func (m *SnoManager) Initialize() {
20
 	m.sendLists = make(map[sno.Mask]map[*Client]bool)
18
 	m.sendLists = make(map[sno.Mask]map[*Client]bool)
21
-	return &m
22
 }
19
 }
23
 
20
 
24
 // AddMasks adds the given snomasks to the client.
21
 // AddMasks adds the given snomasks to the client.

Loading…
İptal
Kaydet