Browse Source

create separate irc/connection_limiting package

tags/v0.10.0
Shivaram Lingamneni 6 years ago
parent
commit
ac9ac5ef19
4 changed files with 31 additions and 29 deletions
  1. 3
    25
      irc/config.go
  2. 10
    1
      irc/connection_limiting/limits.go
  3. 15
    1
      irc/connection_limiting/throttle.go
  4. 3
    2
      irc/server.go

+ 3
- 25
irc/config.go View File

@@ -15,6 +15,7 @@ import (
15 15
 	"time"
16 16
 
17 17
 	"code.cloudfoundry.org/bytefmt"
18
+	"github.com/oragono/oragono/irc/connection_limiting"
18 19
 	"github.com/oragono/oragono/irc/custime"
19 20
 	"github.com/oragono/oragono/irc/logger"
20 21
 	"github.com/oragono/oragono/irc/passwd"
@@ -108,29 +109,6 @@ func (conf *OperConfig) PasswordBytes() []byte {
108 109
 	return bytes
109 110
 }
110 111
 
111
-// ConnectionLimitsConfig controls the automated connection limits.
112
-type ConnectionLimitsConfig struct {
113
-	Enabled     bool
114
-	CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
115
-	CidrLenIPv6 int `yaml:"cidr-len-ipv6"`
116
-	IPsPerCidr  int `yaml:"ips-per-subnet"`
117
-	Exempted    []string
118
-}
119
-
120
-// ConnectionThrottleConfig controls the automated connection throttling.
121
-type ConnectionThrottleConfig struct {
122
-	Enabled            bool
123
-	CidrLenIPv4        int           `yaml:"cidr-len-ipv4"`
124
-	CidrLenIPv6        int           `yaml:"cidr-len-ipv6"`
125
-	ConnectionsPerCidr int           `yaml:"max-connections"`
126
-	DurationString     string        `yaml:"duration"`
127
-	Duration           time.Duration `yaml:"duration-time"`
128
-	BanDurationString  string        `yaml:"ban-duration"`
129
-	BanDuration        time.Duration
130
-	BanMessage         string `yaml:"ban-message"`
131
-	Exempted           []string
132
-}
133
-
134 112
 // LineLenConfig controls line lengths.
135 113
 type LineLenConfig struct {
136 114
 	Tags int
@@ -184,8 +162,8 @@ type Config struct {
184 162
 		ProxyAllowedFrom   []string `yaml:"proxy-allowed-from"`
185 163
 		MaxSendQString     string   `yaml:"max-sendq"`
186 164
 		MaxSendQBytes      uint64
187
-		ConnectionLimits   ConnectionLimitsConfig   `yaml:"connection-limits"`
188
-		ConnectionThrottle ConnectionThrottleConfig `yaml:"connection-throttling"`
165
+		ConnectionLimits   connection_limiting.ConnectionLimitsConfig   `yaml:"connection-limits"`
166
+		ConnectionThrottle connection_limiting.ConnectionThrottleConfig `yaml:"connection-throttling"`
189 167
 	}
190 168
 
191 169
 	Datastore struct {

irc/connection_limits.go → irc/connection_limiting/limits.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 irc
4
+package connection_limiting
5 5
 
6 6
 import (
7 7
 	"errors"
@@ -10,6 +10,15 @@ import (
10 10
 	"sync"
11 11
 )
12 12
 
13
+// ConnectionLimitsConfig controls the automated connection limits.
14
+type ConnectionLimitsConfig struct {
15
+	Enabled     bool
16
+	CidrLenIPv4 int `yaml:"cidr-len-ipv4"`
17
+	CidrLenIPv6 int `yaml:"cidr-len-ipv6"`
18
+	IPsPerCidr  int `yaml:"ips-per-subnet"`
19
+	Exempted    []string
20
+}
21
+
13 22
 var (
14 23
 	errTooManyClients = errors.New("Too many clients in subnet")
15 24
 )

irc/connection_throttling.go → irc/connection_limiting/throttle.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 irc
4
+package connection_limiting
5 5
 
6 6
 import (
7 7
 	"fmt"
@@ -10,6 +10,20 @@ import (
10 10
 	"time"
11 11
 )
12 12
 
13
+// ConnectionThrottleConfig controls the automated connection throttling.
14
+type ConnectionThrottleConfig struct {
15
+	Enabled            bool
16
+	CidrLenIPv4        int           `yaml:"cidr-len-ipv4"`
17
+	CidrLenIPv6        int           `yaml:"cidr-len-ipv6"`
18
+	ConnectionsPerCidr int           `yaml:"max-connections"`
19
+	DurationString     string        `yaml:"duration"`
20
+	Duration           time.Duration `yaml:"duration-time"`
21
+	BanDurationString  string        `yaml:"ban-duration"`
22
+	BanDuration        time.Duration
23
+	BanMessage         string `yaml:"ban-message"`
24
+	Exempted           []string
25
+}
26
+
13 27
 // ThrottleDetails holds the connection-throttling details for a subnet/IP.
14 28
 type ThrottleDetails struct {
15 29
 	Start       time.Time

+ 3
- 2
irc/server.go View File

@@ -24,6 +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 28
 	"github.com/oragono/oragono/irc/isupport"
28 29
 	"github.com/oragono/oragono/irc/logger"
29 30
 	"github.com/oragono/oragono/irc/passwd"
@@ -86,8 +87,8 @@ type Server struct {
86 87
 	commands                     chan Command
87 88
 	configFilename               string
88 89
 	configurableStateMutex       sync.RWMutex // generic protection for server state modified by rehash()
89
-	connectionLimits             *ConnectionLimits
90
-	connectionThrottle           *ConnectionThrottle
90
+	connectionLimits             *connection_limiting.ConnectionLimits
91
+	connectionThrottle           *connection_limiting.ConnectionThrottle
91 92
 	ctime                        time.Time
92 93
 	defaultChannelModes          Modes
93 94
 	dlines                       *DLineManager

Loading…
Cancel
Save