Kaynağa Gözat

make MaxLineLen configurable

tags/v2.7.0-rc1
Shivaram Lingamneni 3 yıl önce
ebeveyn
işleme
7c5a8f2013
7 değiştirilmiş dosya ile 30 ekleme ve 5 silme
  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 Dosyayı Görüntüle

@@ -360,6 +360,11 @@ server:
360 360
     # e.g., `NickServ!NickServ@localhost`. uncomment this to override:
361 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 do this on a public server:
366
+    # max-line-len: 512
367
+
363 368
 # account options
364 369
 accounts:
365 370
     # is account authentication enabled, i.e., can users log into existing accounts?

+ 6
- 2
irc/client.go Dosyayı Görüntüle

@@ -31,8 +31,8 @@ import (
31 31
 )
32 32
 
33 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 37
 	// IdentTimeout is how long before our ident (username) check times out.
38 38
 	IdentTimeout         = time.Second + 500*time.Millisecond
@@ -61,6 +61,10 @@ const (
61 61
 	PingCoalesceThreshold = time.Second
62 62
 )
63 63
 
64
+var (
65
+	MaxLineLen = DefaultMaxLineLen
66
+)
67
+
64 68
 // Client is an IRC client.
65 69
 type Client struct {
66 70
 	account            string

+ 4
- 0
irc/config.go Dosyayı Görüntüle

@@ -590,6 +590,7 @@ type Config struct {
590 590
 		OutputPath               string       `yaml:"output-path"`
591 591
 		IPCheckScript            ScriptConfig `yaml:"ip-check-script"`
592 592
 		OverrideServicesHostname string       `yaml:"override-services-hostname"`
593
+		MaxLineLen               int          `yaml:"max-line-len"`
593 594
 	}
594 595
 
595 596
 	Roleplay struct {
@@ -1132,6 +1133,9 @@ func LoadConfig(filename string) (config *Config, err error) {
1132 1133
 	if config.Limits.RegistrationMessages == 0 {
1133 1134
 		config.Limits.RegistrationMessages = 1024
1134 1135
 	}
1136
+	if config.Server.MaxLineLen < DefaultMaxLineLen {
1137
+		config.Server.MaxLineLen = DefaultMaxLineLen
1138
+	}
1135 1139
 	if config.Datastore.MySQL.Enabled {
1136 1140
 		if config.Limits.NickLen > mysql.MaxTargetLength || config.Limits.ChannelLen > mysql.MaxTargetLength {
1137 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 Dosyayı Görüntüle

@@ -16,7 +16,6 @@ import (
16 16
 )
17 17
 
18 18
 const (
19
-	maxReadQBytes     = ircmsg.MaxlenTagsFromClient + MaxLineLen + 1024
20 19
 	initialBufferSize = 1024
21 20
 )
22 21
 
@@ -24,6 +23,11 @@ var (
24 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 31
 // IRCConn abstracts away the distinction between a regular
28 32
 // net.Conn (which includes both raw TCP and TLS) and a websocket.
29 33
 // it doesn't expose the net.Conn, io.Reader, or io.Writer interfaces
@@ -51,7 +55,7 @@ type IRCStreamConn struct {
51 55
 func NewIRCStreamConn(conn *utils.WrappedConn) *IRCStreamConn {
52 56
 	var c IRCStreamConn
53 57
 	c.conn = conn
54
-	c.reader.Initialize(conn.Conn, initialBufferSize, maxReadQBytes)
58
+	c.reader.Initialize(conn.Conn, initialBufferSize, maxReadQBytes())
55 59
 	return &c
56 60
 }
57 61
 

+ 1
- 1
irc/listeners.go Dosyayı Görüntüle

@@ -185,7 +185,7 @@ func (wl *WSListener) handle(w http.ResponseWriter, r *http.Request) {
185 185
 	confirmProxyData(wConn, remoteAddr, xff, xfp, config)
186 186
 
187 187
 	// avoid a DoS attack from buffering excessively large messages:
188
-	conn.SetReadLimit(maxReadQBytes)
188
+	conn.SetReadLimit(int64(maxReadQBytes()))
189 189
 
190 190
 	go wl.server.RunClient(NewIRCWSConn(conn))
191 191
 }

+ 3
- 0
irc/server.go Dosyayı Görüntüle

@@ -554,6 +554,7 @@ func (server *Server) applyConfig(config *Config) (err error) {
554 554
 		server.nameCasefolded = config.Server.nameCasefolded
555 555
 		globalCasemappingSetting = config.Server.Casemapping
556 556
 		globalUtf8EnforcementSetting = config.Server.EnforceUtf8
557
+		MaxLineLen = config.Server.MaxLineLen
557 558
 	} else {
558 559
 		// enforce configs that can't be changed after launch:
559 560
 		if server.name != config.Server.Name {
@@ -577,6 +578,8 @@ func (server *Server) applyConfig(config *Config) (err error) {
577 578
 			return fmt.Errorf("Cannot change override-services-hostname after launching the server, rehash aborted")
578 579
 		} else if !oldConfig.Datastore.MySQL.Enabled && config.Datastore.MySQL.Enabled {
579 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 Dosyayı Görüntüle

@@ -332,6 +332,11 @@ server:
332 332
     # e.g., `NickServ!NickServ@localhost`. uncomment this to override:
333 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 do this on a public server:
338
+    # max-line-len: 512
339
+
335 340
 # account options
336 341
 accounts:
337 342
     # is account authentication enabled, i.e., can users log into existing accounts?

Loading…
İptal
Kaydet