Browse Source

Very initial maxline work

tags/v0.6.0
Daniel Oaks 7 years ago
parent
commit
d2e18962e3
7 changed files with 50 additions and 11 deletions
  1. 1
    0
      CHANGELOG.md
  2. 4
    2
      irc/capability.go
  3. 16
    2
      irc/client.go
  4. 8
    4
      irc/config.go
  5. 2
    0
      irc/constants.go
  6. 13
    0
      irc/server.go
  7. 6
    3
      oragono.yaml

+ 1
- 0
CHANGELOG.md View File

@@ -37,6 +37,7 @@ This release also updates the database, so be sure to run the `oragono upgradedb
37 37
 ### Added
38 38
 * Added ability to ban IP addresses and networks from the server with the `DLINE` and `UNDLINE` commands.
39 39
 * Added alpha REST API (intended primarily for use with a future web interface to manage accounts, DLINEs, etc).
40
+* Added proposed IRCv3 capability [`maxline`](https://github.com/ircv3/ircv3-specifications/pull/281).
40 41
 
41 42
 ### Changed
42 43
 * Database upgraded to make handling accounts simpler.

+ 4
- 2
irc/capability.go View File

@@ -22,6 +22,7 @@ const (
22 22
 	EchoMessage     Capability = "echo-message"
23 23
 	ExtendedJoin    Capability = "extended-join"
24 24
 	InviteNotify    Capability = "invite-notify"
25
+	MaxLine         Capability = "draft/maxline"
25 26
 	MessageTags     Capability = "draft/message-tags"
26 27
 	MultiPrefix     Capability = "multi-prefix"
27 28
 	SASL            Capability = "sasl"
@@ -39,8 +40,9 @@ var (
39 40
 		EchoMessage:   true,
40 41
 		ExtendedJoin:  true,
41 42
 		InviteNotify:  true,
42
-		MessageTags:   true,
43
-		MultiPrefix:   true,
43
+		// MaxLine is set during server startup
44
+		MessageTags: true,
45
+		MultiPrefix: true,
44 46
 		// SASL is set during server startup
45 47
 		ServerTime:      true,
46 48
 		UserhostInNames: true,

+ 16
- 2
irc/client.go View File

@@ -152,7 +152,14 @@ func (client *Client) run() {
152 152
 			break
153 153
 		}
154 154
 
155
-		msg, err = ircmsg.ParseLine(line)
155
+		var maxLen int
156
+		if client.capabilities[MaxLine] {
157
+			maxLen = maxLineLength
158
+		} else {
159
+			maxLen = 512
160
+		}
161
+
162
+		msg, err = ircmsg.ParseLineMaxLen(line, maxLen)
156 163
 		if err != nil {
157 164
 			client.Quit("received malformed line")
158 165
 			break
@@ -505,9 +512,16 @@ func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, comm
505 512
 		}
506 513
 	}
507 514
 
515
+	var maxLen int
516
+	if client.capabilities[MaxLine] {
517
+		maxLen = maxLineLength
518
+	} else {
519
+		maxLen = 512
520
+	}
521
+
508 522
 	// send out the message
509 523
 	message := ircmsg.MakeMessage(tags, prefix, command, params...)
510
-	line, err := message.Line()
524
+	line, err := message.LineMaxLen(maxLen)
511 525
 	if err != nil {
512 526
 		// try not to fail quietly - especially useful when running tests, as a note to dig deeper
513 527
 		// log.Println("Error assembling message:")

+ 8
- 4
irc/config.go View File

@@ -151,14 +151,15 @@ type Config struct {
151 151
 	Opers map[string]*OperConfig
152 152
 
153 153
 	Limits struct {
154
-		NickLen        uint `yaml:"nicklen"`
155
-		ChannelLen     uint `yaml:"channellen"`
156 154
 		AwayLen        uint `yaml:"awaylen"`
155
+		ChanListModes  uint `yaml:"chan-list-modes"`
156
+		ChannelLen     uint `yaml:"channellen"`
157 157
 		KickLen        uint `yaml:"kicklen"`
158
+		LineLen        uint `yaml:"linelen"`
159
+		MonitorEntries uint `yaml:"monitor-entries"`
160
+		NickLen        uint `yaml:"nicklen"`
158 161
 		TopicLen       uint `yaml:"topiclen"`
159 162
 		WhowasEntries  uint `yaml:"whowas-entries"`
160
-		MonitorEntries uint `yaml:"monitor-entries"`
161
-		ChanListModes  uint `yaml:"chan-list-modes"`
162 163
 	}
163 164
 }
164 165
 
@@ -335,6 +336,9 @@ func LoadConfig(filename string) (config *Config, err error) {
335 336
 			return nil, fmt.Errorf("Could not parse connection-throttle ban-duration: %s", err.Error())
336 337
 		}
337 338
 	}
339
+	if config.Limits.LineLen < 512 {
340
+		return nil, errors.New("Line length must be 512 or greater")
341
+	}
338 342
 
339 343
 	return config, nil
340 344
 }

+ 2
- 0
irc/constants.go View File

@@ -16,6 +16,8 @@ var (
16 16
 	// Ver is the full version of Oragono, used in responses to clients.
17 17
 	Ver = fmt.Sprintf("oragono-%s", SemVer)
18 18
 
19
+	// Used as the standard maximum line length unless overridden at runtime.
20
+	maxLineLength = 512
19 21
 	// maxLastArgLength is used to simply cap off the final argument when creating general messages where we need to select a limit.
20 22
 	// for instance, in MONITOR lists, RPL_ISUPPORT lists, etc.
21 23
 	maxLastArgLength = 400

+ 13
- 0
irc/server.go View File

@@ -46,6 +46,7 @@ type Limits struct {
46 46
 	NickLen        int
47 47
 	TopicLen       int
48 48
 	ChanListModes  int
49
+	LineLen        int
49 50
 }
50 51
 
51 52
 // ListenerInterface represents an interface for a listener.
@@ -146,6 +147,12 @@ func NewServer(configFilename string, config *Config) *Server {
146 147
 		SupportedCapabilities[SASL] = true
147 148
 	}
148 149
 
150
+	if config.Limits.LineLen > 512 {
151
+		maxLineLength = int(config.Limits.LineLen)
152
+		SupportedCapabilities[MaxLine] = true
153
+		CapValues[MaxLine] = strconv.Itoa(int(config.Limits.LineLen))
154
+	}
155
+
149 156
 	operClasses, err := config.OperatorClasses()
150 157
 	if err != nil {
151 158
 		log.Fatal("Error loading oper classes:", err.Error())
@@ -184,6 +191,7 @@ func NewServer(configFilename string, config *Config) *Server {
184 191
 			NickLen:        int(config.Limits.NickLen),
185 192
 			TopicLen:       int(config.Limits.TopicLen),
186 193
 			ChanListModes:  int(config.Limits.ChanListModes),
194
+			LineLen:        int(config.Limits.LineLen),
187 195
 		},
188 196
 		listeners:      make(map[string]ListenerInterface),
189 197
 		monitoring:     make(map[string][]Client),
@@ -1099,6 +1107,11 @@ func (server *Server) rehash() error {
1099 1107
 		return fmt.Errorf("Error rehashing config file config: %s", err.Error())
1100 1108
 	}
1101 1109
 
1110
+	// line lengths cannot be changed after launching the server
1111
+	if maxLineLength != int(config.Limits.LineLen) {
1112
+		return fmt.Errorf("Maximum line length (linelen) cannot be changed after launching the server, rehash aborted")
1113
+	}
1114
+
1102 1115
 	// confirm connectionLimits are fine
1103 1116
 	connectionLimits, err := NewConnectionLimits(config.Server.ConnectionLimits)
1104 1117
 	if err != nil {

+ 6
- 3
oragono.yaml View File

@@ -186,13 +186,13 @@ limits:
186 186
     channellen: 64
187 187
 
188 188
     # awaylen is the maximum length of an away message
189
-    awaylen: 200
189
+    awaylen: 500
190 190
 
191 191
     # kicklen is the maximum length of a kick message
192
-    kicklen: 390
192
+    kicklen: 1000
193 193
 
194 194
     # topiclen is the maximum length of a channel topic
195
-    topiclen: 390
195
+    topiclen: 1000
196 196
 
197 197
     # maximum number of monitor entries a client can have
198 198
     monitor-entries: 100
@@ -202,3 +202,6 @@ limits:
202 202
 
203 203
     # maximum length of channel lists (beI modes)
204 204
     chan-list-modes: 60
205
+
206
+    # maximum length of IRC lines
207
+    linelen: 2048

Loading…
Cancel
Save