소스 검색

remove more indirections

tags/v1.1.0-rc1
Shivaram Lingamneni 5 년 전
부모
커밋
80a594802f
6개의 변경된 파일25개의 추가작업 그리고 48개의 파일을 삭제
  1. 4
    11
      irc/connection_limits/limiter.go
  2. 4
    11
      irc/connection_limits/throttler.go
  3. 2
    2
      irc/connection_limits/throttler_test.go
  4. 3
    7
      irc/monitor.go
  5. 11
    13
      irc/server.go
  6. 1
    4
      irc/snomanager.go

+ 4
- 11
irc/connection_limits/limiter.go 파일 보기

@@ -98,17 +98,6 @@ func (cl *Limiter) RemoveClient(addr net.IP) {
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 101
 // ApplyConfig atomically applies a config update to a connection limit handler
113 102
 func (cl *Limiter) ApplyConfig(config LimiterConfig) error {
114 103
 	// assemble exempted nets
@@ -120,6 +109,10 @@ func (cl *Limiter) ApplyConfig(config LimiterConfig) error {
120 109
 	cl.Lock()
121 110
 	defer cl.Unlock()
122 111
 
112
+	if cl.population == nil {
113
+		cl.population = make(map[string]int)
114
+	}
115
+
123 116
 	cl.enabled = config.Enabled
124 117
 	cl.ipv4Mask = net.CIDRMask(config.CidrLenIPv4, 32)
125 118
 	cl.ipv6Mask = net.CIDRMask(config.CidrLenIPv6, 128)

+ 4
- 11
irc/connection_limits/throttler.go 파일 보기

@@ -150,17 +150,6 @@ func (ct *Throttler) BanMessage() string {
150 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 153
 // ApplyConfig atomically applies a config update to a throttler
165 154
 func (ct *Throttler) ApplyConfig(config ThrottlerConfig) error {
166 155
 	// assemble exempted nets
@@ -172,6 +161,10 @@ func (ct *Throttler) ApplyConfig(config ThrottlerConfig) error {
172 161
 	ct.Lock()
173 162
 	defer ct.Unlock()
174 163
 
164
+	if ct.population == nil {
165
+		ct.population = make(map[string]ThrottleDetails)
166
+	}
167
+
175 168
 	ct.enabled = config.Enabled
176 169
 	ct.ipv4Mask = net.CIDRMask(config.CidrLenIPv4, 32)
177 170
 	ct.ipv6Mask = net.CIDRMask(config.CidrLenIPv6, 128)

+ 2
- 2
irc/connection_limits/throttler_test.go 파일 보기

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

+ 3
- 7
irc/monitor.go 파일 보기

@@ -19,13 +19,9 @@ type MonitorManager struct {
19 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 27
 // AlertAbout alerts everyone monitoring `client`'s nick that `client` is now {on,off}line.

+ 11
- 13
irc/server.go 파일 보기

@@ -67,15 +67,15 @@ type Server struct {
67 67
 	clients             ClientManager
68 68
 	config              unsafe.Pointer
69 69
 	configFilename      string
70
-	connectionLimiter   *connection_limits.Limiter
71
-	connectionThrottler *connection_limits.Throttler
70
+	connectionLimiter   connection_limits.Limiter
71
+	connectionThrottler connection_limits.Throttler
72 72
 	ctime               time.Time
73 73
 	dlines              *DLineManager
74 74
 	helpIndexManager    HelpIndexManager
75 75
 	klines              *KLineManager
76 76
 	listeners           map[string]*ListenerWrapper
77 77
 	logger              *logger.Manager
78
-	monitorManager      *MonitorManager
78
+	monitorManager      MonitorManager
79 79
 	name                string
80 80
 	nameCasefolded      string
81 81
 	rehashMutex         sync.Mutex // tier 4
@@ -83,7 +83,7 @@ type Server struct {
83 83
 	pprofServer         *http.Server
84 84
 	resumeManager       ResumeManager
85 85
 	signals             chan os.Signal
86
-	snomasks            *SnoManager
86
+	snomasks            SnoManager
87 87
 	store               *buntdb.DB
88 88
 	torLimiter          connection_limits.TorLimiter
89 89
 	whoWas              WhoWasList
@@ -110,21 +110,19 @@ type clientConn struct {
110 110
 func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
111 111
 	// initialize data structures
112 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 120
 	server.clients.Initialize()
125 121
 	server.semaphores.Initialize()
126 122
 	server.resumeManager.Initialize(server)
127 123
 	server.whoWas.Initialize(config.Limits.WhowasEntries)
124
+	server.monitorManager.Initialize()
125
+	server.snomasks.Initialize()
128 126
 
129 127
 	if err := server.applyConfig(config, true); err != nil {
130 128
 		return nil, err

+ 1
- 4
irc/snomanager.go 파일 보기

@@ -14,11 +14,8 @@ type SnoManager struct {
14 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 18
 	m.sendLists = make(map[sno.Mask]map[*Client]bool)
21
-	return &m
22 19
 }
23 20
 
24 21
 // AddMasks adds the given snomasks to the client.

Loading…
취소
저장