Browse Source

review fix: rename various packages and objects

tags/v0.10.0
Shivaram Lingamneni 6 years ago
parent
commit
d66470f1c4
5 changed files with 70 additions and 70 deletions
  1. 1
    1
      irc/client.go
  2. 17
    17
      irc/config.go
  3. 12
    12
      irc/connection_limits/limiter.go
  4. 14
    14
      irc/connection_limits/throttler.go
  5. 26
    26
      irc/server.go

+ 1
- 1
irc/client.go View File

@@ -542,7 +542,7 @@ func (client *Client) destroy() {
542 542
 	ipaddr := client.IP()
543 543
 	// this check shouldn't be required but eh
544 544
 	if ipaddr != nil {
545
-		client.server.connectionLimits.RemoveClient(ipaddr)
545
+		client.server.connectionLimiter.RemoveClient(ipaddr)
546 546
 	}
547 547
 
548 548
 	// alert monitors

+ 17
- 17
irc/config.go View File

@@ -15,7 +15,7 @@ import (
15 15
 	"time"
16 16
 
17 17
 	"code.cloudfoundry.org/bytefmt"
18
-	"github.com/oragono/oragono/irc/connection_limiting"
18
+	"github.com/oragono/oragono/irc/connection_limits"
19 19
 	"github.com/oragono/oragono/irc/custime"
20 20
 	"github.com/oragono/oragono/irc/logger"
21 21
 	"github.com/oragono/oragono/irc/passwd"
@@ -151,19 +151,19 @@ type Config struct {
151 151
 
152 152
 	Server struct {
153 153
 		PassConfig
154
-		Password           string
155
-		Name               string
156
-		Listen             []string
157
-		TLSListeners       map[string]*TLSListenConfig `yaml:"tls-listeners"`
158
-		STS                STSConfig
159
-		CheckIdent         bool `yaml:"check-ident"`
160
-		MOTD               string
161
-		MOTDFormatting     bool     `yaml:"motd-formatting"`
162
-		ProxyAllowedFrom   []string `yaml:"proxy-allowed-from"`
163
-		MaxSendQString     string   `yaml:"max-sendq"`
164
-		MaxSendQBytes      uint64
165
-		ConnectionLimits   connection_limiting.ConnectionLimitsConfig   `yaml:"connection-limits"`
166
-		ConnectionThrottle connection_limiting.ConnectionThrottleConfig `yaml:"connection-throttling"`
154
+		Password            string
155
+		Name                string
156
+		Listen              []string
157
+		TLSListeners        map[string]*TLSListenConfig `yaml:"tls-listeners"`
158
+		STS                 STSConfig
159
+		CheckIdent          bool `yaml:"check-ident"`
160
+		MOTD                string
161
+		MOTDFormatting      bool     `yaml:"motd-formatting"`
162
+		ProxyAllowedFrom    []string `yaml:"proxy-allowed-from"`
163
+		MaxSendQString      string   `yaml:"max-sendq"`
164
+		MaxSendQBytes       uint64
165
+		ConnectionLimiter   connection_limits.LimiterConfig   `yaml:"connection-limits"`
166
+		ConnectionThrottler connection_limits.ThrottlerConfig `yaml:"connection-throttling"`
167 167
 	}
168 168
 
169 169
 	Datastore struct {
@@ -383,12 +383,12 @@ func LoadConfig(filename string) (config *Config, err error) {
383 383
 			return nil, fmt.Errorf("STS port is incorrect, should be 0 if disabled: %d", config.Server.STS.Port)
384 384
 		}
385 385
 	}
386
-	if config.Server.ConnectionThrottle.Enabled {
387
-		config.Server.ConnectionThrottle.Duration, err = time.ParseDuration(config.Server.ConnectionThrottle.DurationString)
386
+	if config.Server.ConnectionThrottler.Enabled {
387
+		config.Server.ConnectionThrottler.Duration, err = time.ParseDuration(config.Server.ConnectionThrottler.DurationString)
388 388
 		if err != nil {
389 389
 			return nil, fmt.Errorf("Could not parse connection-throttle duration: %s", err.Error())
390 390
 		}
391
-		config.Server.ConnectionThrottle.BanDuration, err = time.ParseDuration(config.Server.ConnectionThrottle.BanDurationString)
391
+		config.Server.ConnectionThrottler.BanDuration, err = time.ParseDuration(config.Server.ConnectionThrottler.BanDurationString)
392 392
 		if err != nil {
393 393
 			return nil, fmt.Errorf("Could not parse connection-throttle ban-duration: %s", err.Error())
394 394
 		}

irc/connection_limiting/limits.go → irc/connection_limits/limiter.go View File

@@ -1,7 +1,7 @@
1 1
 // Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
2 2
 // released under the MIT license
3 3
 
4
-package connection_limiting
4
+package connection_limits
5 5
 
6 6
 import (
7 7
 	"errors"
@@ -10,8 +10,8 @@ import (
10 10
 	"sync"
11 11
 )
12 12
 
13
-// ConnectionLimitsConfig controls the automated connection limits.
14
-type ConnectionLimitsConfig struct {
13
+// LimiterConfig controls the automated connection limits.
14
+type LimiterConfig struct {
15 15
 	Enabled     bool
16 16
 	CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
17 17
 	CidrLenIPv6 int `yaml:"cidr-len-ipv6"`
@@ -23,8 +23,8 @@ var (
23 23
 	errTooManyClients = errors.New("Too many clients in subnet")
24 24
 )
25 25
 
26
-// ConnectionLimits manages the automated client connection limits.
27
-type ConnectionLimits struct {
26
+// Limiter manages the automated client connection limits.
27
+type Limiter struct {
28 28
 	sync.Mutex
29 29
 
30 30
 	enabled  bool
@@ -42,7 +42,7 @@ type ConnectionLimits struct {
42 42
 }
43 43
 
44 44
 // maskAddr masks the given IPv4/6 address with our cidr limit masks.
45
-func (cl *ConnectionLimits) maskAddr(addr net.IP) net.IP {
45
+func (cl *Limiter) maskAddr(addr net.IP) net.IP {
46 46
 	if addr.To4() == nil {
47 47
 		// IPv6 addr
48 48
 		addr = addr.Mask(cl.ipv6Mask)
@@ -56,7 +56,7 @@ func (cl *ConnectionLimits) maskAddr(addr net.IP) net.IP {
56 56
 
57 57
 // AddClient adds a client to our population if possible. If we can't, throws an error instead.
58 58
 // 'force' is used to add already-existing clients (i.e. ones that are already on the network).
59
-func (cl *ConnectionLimits) AddClient(addr net.IP, force bool) error {
59
+func (cl *Limiter) AddClient(addr net.IP, force bool) error {
60 60
 	cl.Lock()
61 61
 	defer cl.Unlock()
62 62
 
@@ -89,7 +89,7 @@ func (cl *ConnectionLimits) AddClient(addr net.IP, force bool) error {
89 89
 }
90 90
 
91 91
 // RemoveClient removes the given address from our population
92
-func (cl *ConnectionLimits) RemoveClient(addr net.IP) {
92
+func (cl *Limiter) RemoveClient(addr net.IP) {
93 93
 	cl.Lock()
94 94
 	defer cl.Unlock()
95 95
 
@@ -106,10 +106,10 @@ func (cl *ConnectionLimits) RemoveClient(addr net.IP) {
106 106
 	}
107 107
 }
108 108
 
109
-// NewConnectionLimits returns a new connection limit handler.
109
+// NewLimiter returns a new connection limit handler.
110 110
 // The handler is functional, but disabled; it can be enabled via `ApplyConfig`.
111
-func NewConnectionLimits() *ConnectionLimits {
112
-	var cl ConnectionLimits
111
+func NewLimiter() *Limiter {
112
+	var cl Limiter
113 113
 
114 114
 	// initialize empty population; all other state is configurable
115 115
 	cl.population = make(map[string]int)
@@ -118,7 +118,7 @@ func NewConnectionLimits() *ConnectionLimits {
118 118
 }
119 119
 
120 120
 // ApplyConfig atomically applies a config update to a connection limit handler
121
-func (cl *ConnectionLimits) ApplyConfig(config ConnectionLimitsConfig) error {
121
+func (cl *Limiter) ApplyConfig(config LimiterConfig) error {
122 122
 	// assemble exempted nets
123 123
 	exemptedIPs := make(map[string]bool)
124 124
 	var exemptedNets []net.IPNet

irc/connection_limiting/throttle.go → irc/connection_limits/throttler.go View File

@@ -1,7 +1,7 @@
1 1
 // Copyright (c) 2016-2017 Daniel Oaks <daniel@danieloaks.net>
2 2
 // released under the MIT license
3 3
 
4
-package connection_limiting
4
+package connection_limits
5 5
 
6 6
 import (
7 7
 	"fmt"
@@ -10,8 +10,8 @@ import (
10 10
 	"time"
11 11
 )
12 12
 
13
-// ConnectionThrottleConfig controls the automated connection throttling.
14
-type ConnectionThrottleConfig struct {
13
+// ThrottlerConfig controls the automated connection throttling.
14
+type ThrottlerConfig struct {
15 15
 	Enabled            bool
16 16
 	CidrLenIPv4        int           `yaml:"cidr-len-ipv4"`
17 17
 	CidrLenIPv6        int           `yaml:"cidr-len-ipv6"`
@@ -30,8 +30,8 @@ type ThrottleDetails struct {
30 30
 	ClientCount int
31 31
 }
32 32
 
33
-// ConnectionThrottle manages automated client connection throttling.
34
-type ConnectionThrottle struct {
33
+// Throttler manages automated client connection throttling.
34
+type Throttler struct {
35 35
 	sync.RWMutex
36 36
 
37 37
 	enabled     bool
@@ -52,7 +52,7 @@ type ConnectionThrottle struct {
52 52
 }
53 53
 
54 54
 // maskAddr masks the given IPv4/6 address with our cidr limit masks.
55
-func (ct *ConnectionThrottle) maskAddr(addr net.IP) net.IP {
55
+func (ct *Throttler) maskAddr(addr net.IP) net.IP {
56 56
 	if addr.To4() == nil {
57 57
 		// IPv6 addr
58 58
 		addr = addr.Mask(ct.ipv6Mask)
@@ -65,7 +65,7 @@ func (ct *ConnectionThrottle) maskAddr(addr net.IP) net.IP {
65 65
 }
66 66
 
67 67
 // ResetFor removes any existing count for the given address.
68
-func (ct *ConnectionThrottle) ResetFor(addr net.IP) {
68
+func (ct *Throttler) ResetFor(addr net.IP) {
69 69
 	ct.Lock()
70 70
 	defer ct.Unlock()
71 71
 
@@ -80,7 +80,7 @@ func (ct *ConnectionThrottle) ResetFor(addr net.IP) {
80 80
 }
81 81
 
82 82
 // AddClient introduces a new client connection if possible. If we can't, throws an error instead.
83
-func (ct *ConnectionThrottle) AddClient(addr net.IP) error {
83
+func (ct *Throttler) AddClient(addr net.IP) error {
84 84
 	ct.Lock()
85 85
 	defer ct.Unlock()
86 86
 
@@ -119,24 +119,24 @@ func (ct *ConnectionThrottle) AddClient(addr net.IP) error {
119 119
 	return nil
120 120
 }
121 121
 
122
-func (ct *ConnectionThrottle) BanDuration() time.Duration {
122
+func (ct *Throttler) BanDuration() time.Duration {
123 123
 	ct.RLock()
124 124
 	defer ct.RUnlock()
125 125
 
126 126
 	return ct.banDuration
127 127
 }
128 128
 
129
-func (ct *ConnectionThrottle) BanMessage() string {
129
+func (ct *Throttler) BanMessage() string {
130 130
 	ct.RLock()
131 131
 	defer ct.RUnlock()
132 132
 
133 133
 	return ct.banMessage
134 134
 }
135 135
 
136
-// NewConnectionThrottle returns a new client connection throttler.
136
+// NewThrottler returns a new client connection throttler.
137 137
 // The throttler is functional, but disabled; it can be enabled via `ApplyConfig`.
138
-func NewConnectionThrottle() *ConnectionThrottle {
139
-	var ct ConnectionThrottle
138
+func NewThrottler() *Throttler {
139
+	var ct Throttler
140 140
 
141 141
 	// initialize empty population; all other state is configurable
142 142
 	ct.population = make(map[string]ThrottleDetails)
@@ -145,7 +145,7 @@ func NewConnectionThrottle() *ConnectionThrottle {
145 145
 }
146 146
 
147 147
 // ApplyConfig atomically applies a config update to a throttler
148
-func (ct *ConnectionThrottle) ApplyConfig(config ConnectionThrottleConfig) error {
148
+func (ct *Throttler) ApplyConfig(config ThrottlerConfig) error {
149 149
 	// assemble exempted nets
150 150
 	exemptedIPs := make(map[string]bool)
151 151
 	var exemptedNets []net.IPNet

+ 26
- 26
irc/server.go View File

@@ -24,7 +24,7 @@ import (
24 24
 	"github.com/goshuirc/irc-go/ircfmt"
25 25
 	"github.com/goshuirc/irc-go/ircmsg"
26 26
 	"github.com/oragono/oragono/irc/caps"
27
-	"github.com/oragono/oragono/irc/connection_limiting"
27
+	"github.com/oragono/oragono/irc/connection_limits"
28 28
 	"github.com/oragono/oragono/irc/isupport"
29 29
 	"github.com/oragono/oragono/irc/logger"
30 30
 	"github.com/oragono/oragono/irc/passwd"
@@ -87,8 +87,8 @@ type Server struct {
87 87
 	commands                     chan Command
88 88
 	configFilename               string
89 89
 	configurableStateMutex       sync.RWMutex // generic protection for server state modified by rehash()
90
-	connectionLimits             *connection_limiting.ConnectionLimits
91
-	connectionThrottle           *connection_limiting.ConnectionThrottle
90
+	connectionLimiter            *connection_limits.Limiter
91
+	connectionThrottler          *connection_limits.Throttler
92 92
 	ctime                        time.Time
93 93
 	defaultChannelModes          Modes
94 94
 	dlines                       *DLineManager
@@ -144,21 +144,21 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
144 144
 
145 145
 	// initialize data structures
146 146
 	server := &Server{
147
-		accounts:           make(map[string]*ClientAccount),
148
-		channels:           *NewChannelNameMap(),
149
-		clients:            NewClientLookupSet(),
150
-		commands:           make(chan Command),
151
-		connectionLimits:   connection_limiting.NewConnectionLimits(),
152
-		connectionThrottle: connection_limiting.NewConnectionThrottle(),
153
-		listeners:          make(map[string]*ListenerWrapper),
154
-		logger:             logger,
155
-		monitorManager:     NewMonitorManager(),
156
-		newConns:           make(chan clientConn),
157
-		registeredChannels: make(map[string]*RegisteredChannel),
158
-		rehashSignal:       make(chan os.Signal, 1),
159
-		signals:            make(chan os.Signal, len(ServerExitSignals)),
160
-		snomasks:           NewSnoManager(),
161
-		whoWas:             NewWhoWasList(config.Limits.WhowasEntries),
147
+		accounts:            make(map[string]*ClientAccount),
148
+		channels:            *NewChannelNameMap(),
149
+		clients:             NewClientLookupSet(),
150
+		commands:            make(chan Command),
151
+		connectionLimiter:   connection_limits.NewLimiter(),
152
+		connectionThrottler: connection_limits.NewThrottler(),
153
+		listeners:           make(map[string]*ListenerWrapper),
154
+		logger:              logger,
155
+		monitorManager:      NewMonitorManager(),
156
+		newConns:            make(chan clientConn),
157
+		registeredChannels:  make(map[string]*RegisteredChannel),
158
+		rehashSignal:        make(chan os.Signal, 1),
159
+		signals:             make(chan os.Signal, len(ServerExitSignals)),
160
+		snomasks:            NewSnoManager(),
161
+		whoWas:              NewWhoWasList(config.Limits.WhowasEntries),
162 162
 	}
163 163
 
164 164
 	if err := server.applyConfig(config, true); err != nil {
@@ -303,7 +303,7 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
303 303
 	}
304 304
 
305 305
 	// check connection limits
306
-	err := server.connectionLimits.AddClient(ipaddr, false)
306
+	err := server.connectionLimiter.AddClient(ipaddr, false)
307 307
 	if err != nil {
308 308
 		// too many connections from one client, tell the client and close the connection
309 309
 		server.logger.Info("localconnect-ip", fmt.Sprintf("Client from %v rejected for connection limit", ipaddr))
@@ -311,25 +311,25 @@ func (server *Server) checkBans(ipaddr net.IP) (banned bool, message string) {
311 311
 	}
312 312
 
313 313
 	// check connection throttle
314
-	err = server.connectionThrottle.AddClient(ipaddr)
314
+	err = server.connectionThrottler.AddClient(ipaddr)
315 315
 	if err != nil {
316 316
 		// too many connections too quickly from client, tell them and close the connection
317
-		duration := server.connectionThrottle.BanDuration()
317
+		duration := server.connectionThrottler.BanDuration()
318 318
 		length := &IPRestrictTime{
319 319
 			Duration: duration,
320 320
 			Expires:  time.Now().Add(duration),
321 321
 		}
322
-		server.dlines.AddIP(ipaddr, length, server.connectionThrottle.BanMessage(), "Exceeded automated connection throttle")
322
+		server.dlines.AddIP(ipaddr, length, server.connectionThrottler.BanMessage(), "Exceeded automated connection throttle")
323 323
 
324 324
 		// they're DLINE'd for 15 minutes or whatever, so we can reset the connection throttle now,
325 325
 		// and once their temporary DLINE is finished they can fill up the throttler again
326
-		server.connectionThrottle.ResetFor(ipaddr)
326
+		server.connectionThrottler.ResetFor(ipaddr)
327 327
 
328 328
 		// this might not show up properly on some clients, but our objective here is just to close it out before it has a load impact on us
329 329
 		server.logger.Info(
330 330
 			"localconnect-ip",
331 331
 			fmt.Sprintf("Client from %v exceeded connection throttle, d-lining for %v", ipaddr, duration))
332
-		return true, server.connectionThrottle.BanMessage()
332
+		return true, server.connectionThrottler.BanMessage()
333 333
 	}
334 334
 
335 335
 	return false, ""
@@ -1263,12 +1263,12 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
1263 1263
 	// apply new PROXY command restrictions
1264 1264
 	server.proxyAllowedFrom = config.Server.ProxyAllowedFrom
1265 1265
 
1266
-	err = server.connectionLimits.ApplyConfig(config.Server.ConnectionLimits)
1266
+	err = server.connectionLimiter.ApplyConfig(config.Server.ConnectionLimiter)
1267 1267
 	if err != nil {
1268 1268
 		return err
1269 1269
 	}
1270 1270
 
1271
-	err = server.connectionThrottle.ApplyConfig(config.Server.ConnectionThrottle)
1271
+	err = server.connectionThrottler.ApplyConfig(config.Server.ConnectionThrottler)
1272 1272
 	if err != nil {
1273 1273
 		return err
1274 1274
 	}

Loading…
Cancel
Save