Browse Source

Merge pull request #1651 from slingamn/configurable_linelen

make MaxLineLen configurable
tags/v2.7.0-rc1
Shivaram Lingamneni 3 years ago
parent
commit
588efd29b4
No account linked to committer's email address
7 changed files with 30 additions and 5 deletions
  1. 5
    0
      default.yaml
  2. 6
    2
      irc/client.go
  3. 4
    0
      irc/config.go
  4. 6
    2
      irc/ircconn.go
  5. 1
    1
      irc/listeners.go
  6. 3
    0
      irc/server.go
  7. 5
    0
      traditional.yaml

+ 5
- 0
default.yaml View File

360
     # e.g., `NickServ!NickServ@localhost`. uncomment this to override:
360
     # e.g., `NickServ!NickServ@localhost`. uncomment this to override:
361
     #override-services-hostname: "example.network"
361
     #override-services-hostname: "example.network"
362
 
362
 
363
+    # in a "closed-loop" system where you control the server and all the clients,
364
+    # you may want to increase the maximum (non-tag) length of an IRC line from
365
+    # the default value of 512. DO NOT change this on a public server:
366
+    # max-line-len: 512
367
+
363
 # account options
368
 # account options
364
 accounts:
369
 accounts:
365
     # is account authentication enabled, i.e., can users log into existing accounts?
370
     # is account authentication enabled, i.e., can users log into existing accounts?

+ 6
- 2
irc/client.go View File

31
 )
31
 )
32
 
32
 
33
 const (
33
 const (
34
-	// maximum line length not including tags; don't change this for a public server
35
-	MaxLineLen = 512
34
+	// maximum IRC line length, not including tags
35
+	DefaultMaxLineLen = 512
36
 
36
 
37
 	// IdentTimeout is how long before our ident (username) check times out.
37
 	// IdentTimeout is how long before our ident (username) check times out.
38
 	IdentTimeout         = time.Second + 500*time.Millisecond
38
 	IdentTimeout         = time.Second + 500*time.Millisecond
61
 	PingCoalesceThreshold = time.Second
61
 	PingCoalesceThreshold = time.Second
62
 )
62
 )
63
 
63
 
64
+var (
65
+	MaxLineLen = DefaultMaxLineLen
66
+)
67
+
64
 // Client is an IRC client.
68
 // Client is an IRC client.
65
 type Client struct {
69
 type Client struct {
66
 	account            string
70
 	account            string

+ 4
- 0
irc/config.go View File

590
 		OutputPath               string       `yaml:"output-path"`
590
 		OutputPath               string       `yaml:"output-path"`
591
 		IPCheckScript            ScriptConfig `yaml:"ip-check-script"`
591
 		IPCheckScript            ScriptConfig `yaml:"ip-check-script"`
592
 		OverrideServicesHostname string       `yaml:"override-services-hostname"`
592
 		OverrideServicesHostname string       `yaml:"override-services-hostname"`
593
+		MaxLineLen               int          `yaml:"max-line-len"`
593
 	}
594
 	}
594
 
595
 
595
 	Roleplay struct {
596
 	Roleplay struct {
1132
 	if config.Limits.RegistrationMessages == 0 {
1133
 	if config.Limits.RegistrationMessages == 0 {
1133
 		config.Limits.RegistrationMessages = 1024
1134
 		config.Limits.RegistrationMessages = 1024
1134
 	}
1135
 	}
1136
+	if config.Server.MaxLineLen < DefaultMaxLineLen {
1137
+		config.Server.MaxLineLen = DefaultMaxLineLen
1138
+	}
1135
 	if config.Datastore.MySQL.Enabled {
1139
 	if config.Datastore.MySQL.Enabled {
1136
 		if config.Limits.NickLen > mysql.MaxTargetLength || config.Limits.ChannelLen > mysql.MaxTargetLength {
1140
 		if config.Limits.NickLen > mysql.MaxTargetLength || config.Limits.ChannelLen > mysql.MaxTargetLength {
1137
 			return nil, fmt.Errorf("to use MySQL, nick and channel length limits must be %d or lower", mysql.MaxTargetLength)
1141
 			return nil, fmt.Errorf("to use MySQL, nick and channel length limits must be %d or lower", mysql.MaxTargetLength)

+ 6
- 2
irc/ircconn.go View File

16
 )
16
 )
17
 
17
 
18
 const (
18
 const (
19
-	maxReadQBytes     = ircmsg.MaxlenTagsFromClient + MaxLineLen + 1024
20
 	initialBufferSize = 1024
19
 	initialBufferSize = 1024
21
 )
20
 )
22
 
21
 
24
 	crlf = []byte{'\r', '\n'}
23
 	crlf = []byte{'\r', '\n'}
25
 )
24
 )
26
 
25
 
26
+// maximum total length, in bytes, of a single IRC message:
27
+func maxReadQBytes() int {
28
+	return ircmsg.MaxlenTagsFromClient + MaxLineLen + 1024
29
+}
30
+
27
 // IRCConn abstracts away the distinction between a regular
31
 // IRCConn abstracts away the distinction between a regular
28
 // net.Conn (which includes both raw TCP and TLS) and a websocket.
32
 // net.Conn (which includes both raw TCP and TLS) and a websocket.
29
 // it doesn't expose the net.Conn, io.Reader, or io.Writer interfaces
33
 // it doesn't expose the net.Conn, io.Reader, or io.Writer interfaces
51
 func NewIRCStreamConn(conn *utils.WrappedConn) *IRCStreamConn {
55
 func NewIRCStreamConn(conn *utils.WrappedConn) *IRCStreamConn {
52
 	var c IRCStreamConn
56
 	var c IRCStreamConn
53
 	c.conn = conn
57
 	c.conn = conn
54
-	c.reader.Initialize(conn.Conn, initialBufferSize, maxReadQBytes)
58
+	c.reader.Initialize(conn.Conn, initialBufferSize, maxReadQBytes())
55
 	return &c
59
 	return &c
56
 }
60
 }
57
 
61
 

+ 1
- 1
irc/listeners.go View File

185
 	confirmProxyData(wConn, remoteAddr, xff, xfp, config)
185
 	confirmProxyData(wConn, remoteAddr, xff, xfp, config)
186
 
186
 
187
 	// avoid a DoS attack from buffering excessively large messages:
187
 	// avoid a DoS attack from buffering excessively large messages:
188
-	conn.SetReadLimit(maxReadQBytes)
188
+	conn.SetReadLimit(int64(maxReadQBytes()))
189
 
189
 
190
 	go wl.server.RunClient(NewIRCWSConn(conn))
190
 	go wl.server.RunClient(NewIRCWSConn(conn))
191
 }
191
 }

+ 3
- 0
irc/server.go View File

554
 		server.nameCasefolded = config.Server.nameCasefolded
554
 		server.nameCasefolded = config.Server.nameCasefolded
555
 		globalCasemappingSetting = config.Server.Casemapping
555
 		globalCasemappingSetting = config.Server.Casemapping
556
 		globalUtf8EnforcementSetting = config.Server.EnforceUtf8
556
 		globalUtf8EnforcementSetting = config.Server.EnforceUtf8
557
+		MaxLineLen = config.Server.MaxLineLen
557
 	} else {
558
 	} else {
558
 		// enforce configs that can't be changed after launch:
559
 		// enforce configs that can't be changed after launch:
559
 		if server.name != config.Server.Name {
560
 		if server.name != config.Server.Name {
577
 			return fmt.Errorf("Cannot change override-services-hostname after launching the server, rehash aborted")
578
 			return fmt.Errorf("Cannot change override-services-hostname after launching the server, rehash aborted")
578
 		} else if !oldConfig.Datastore.MySQL.Enabled && config.Datastore.MySQL.Enabled {
579
 		} else if !oldConfig.Datastore.MySQL.Enabled && config.Datastore.MySQL.Enabled {
579
 			return fmt.Errorf("Cannot enable MySQL after launching the server, rehash aborted")
580
 			return fmt.Errorf("Cannot enable MySQL after launching the server, rehash aborted")
581
+		} else if oldConfig.Server.MaxLineLen != config.Server.MaxLineLen {
582
+			return fmt.Errorf("Cannot change max-line-len after launching the server, rehash aborted")
580
 		}
583
 		}
581
 	}
584
 	}
582
 
585
 

+ 5
- 0
traditional.yaml View File

332
     # e.g., `NickServ!NickServ@localhost`. uncomment this to override:
332
     # e.g., `NickServ!NickServ@localhost`. uncomment this to override:
333
     #override-services-hostname: "example.network"
333
     #override-services-hostname: "example.network"
334
 
334
 
335
+    # in a "closed-loop" system where you control the server and all the clients,
336
+    # you may want to increase the maximum (non-tag) length of an IRC line from
337
+    # the default value of 512. DO NOT change this on a public server:
338
+    # max-line-len: 512
339
+
335
 # account options
340
 # account options
336
 accounts:
341
 accounts:
337
     # is account authentication enabled, i.e., can users log into existing accounts?
342
     # is account authentication enabled, i.e., can users log into existing accounts?

Loading…
Cancel
Save