Quellcode durchsuchen

server: Start roughly hacking in new message-tags support

tags/v0.6.0
Daniel Oaks vor 7 Jahren
Ursprung
Commit
92626a178d
6 geänderte Dateien mit 58 neuen und 35 gelöschten Zeilen
  1. 1
    1
      irc/capability.go
  2. 19
    15
      irc/client.go
  3. 15
    10
      irc/config.go
  4. 2
    1
      irc/constants.go
  5. 15
    7
      irc/server.go
  6. 6
    1
      oragono.yaml

+ 1
- 1
irc/capability.go Datei anzeigen

@@ -23,7 +23,7 @@ const (
23 23
 	ExtendedJoin    Capability = "extended-join"
24 24
 	InviteNotify    Capability = "invite-notify"
25 25
 	MaxLine         Capability = "draft/maxline"
26
-	MessageTags     Capability = "draft/message-tags"
26
+	MessageTags     Capability = "draft/message-tags-0.2"
27 27
 	MultiPrefix     Capability = "multi-prefix"
28 28
 	SASL            Capability = "sasl"
29 29
 	ServerTime      Capability = "server-time"

+ 19
- 15
irc/client.go Datei anzeigen

@@ -135,6 +135,21 @@ func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
135 135
 // command goroutine
136 136
 //
137 137
 
138
+func (client *Client) maxlens() (int, int) {
139
+	maxlenTags := 512
140
+	maxlenRest := 512
141
+	if client.capabilities[MessageTags] {
142
+		maxlenTags = 4096
143
+	}
144
+	if client.capabilities[MaxLine] {
145
+		if maxLineTagsLength > maxlenTags {
146
+			maxlenTags = maxLineTagsLength
147
+		}
148
+		maxlenRest = maxLineRestLength
149
+	}
150
+	return maxlenTags, maxlenRest
151
+}
152
+
138 153
 func (client *Client) run() {
139 154
 	var err error
140 155
 	var isExiting bool
@@ -152,14 +167,9 @@ func (client *Client) run() {
152 167
 			break
153 168
 		}
154 169
 
155
-		var maxLen int
156
-		if client.capabilities[MaxLine] {
157
-			maxLen = maxLineLength
158
-		} else {
159
-			maxLen = 512
160
-		}
170
+		maxlenTags, maxlenRest := client.maxlens()
161 171
 
162
-		msg, err = ircmsg.ParseLineMaxLen(line, maxLen)
172
+		msg, err = ircmsg.ParseLineMaxLen(line, maxlenTags, maxlenRest)
163 173
 		if err != nil {
164 174
 			client.Quit("received malformed line")
165 175
 			break
@@ -512,16 +522,10 @@ func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, comm
512 522
 		}
513 523
 	}
514 524
 
515
-	var maxLen int
516
-	if client.capabilities[MaxLine] {
517
-		maxLen = maxLineLength
518
-	} else {
519
-		maxLen = 512
520
-	}
521
-
522 525
 	// send out the message
523 526
 	message := ircmsg.MakeMessage(tags, prefix, command, params...)
524
-	line, err := message.LineMaxLen(maxLen)
527
+	maxlenTags, maxlenRest := client.maxlens()
528
+	line, err := message.LineMaxLen(maxlenTags, maxlenRest)
525 529
 	if err != nil {
526 530
 		// try not to fail quietly - especially useful when running tests, as a note to dig deeper
527 531
 		// log.Println("Error assembling message:")

+ 15
- 10
irc/config.go Datei anzeigen

@@ -116,6 +116,11 @@ type ConnectionThrottleConfig struct {
116 116
 	Exempted           []string
117 117
 }
118 118
 
119
+type LineLenConfig struct {
120
+	Tags int
121
+	Rest int
122
+}
123
+
119 124
 type Config struct {
120 125
 	Network struct {
121 126
 		Name string
@@ -151,15 +156,15 @@ type Config struct {
151 156
 	Opers map[string]*OperConfig
152 157
 
153 158
 	Limits struct {
154
-		AwayLen        uint `yaml:"awaylen"`
155
-		ChanListModes  uint `yaml:"chan-list-modes"`
156
-		ChannelLen     uint `yaml:"channellen"`
157
-		KickLen        uint `yaml:"kicklen"`
158
-		LineLen        uint `yaml:"linelen"`
159
-		MonitorEntries uint `yaml:"monitor-entries"`
160
-		NickLen        uint `yaml:"nicklen"`
161
-		TopicLen       uint `yaml:"topiclen"`
162
-		WhowasEntries  uint `yaml:"whowas-entries"`
159
+		AwayLen        uint          `yaml:"awaylen"`
160
+		ChanListModes  uint          `yaml:"chan-list-modes"`
161
+		ChannelLen     uint          `yaml:"channellen"`
162
+		KickLen        uint          `yaml:"kicklen"`
163
+		MonitorEntries uint          `yaml:"monitor-entries"`
164
+		NickLen        uint          `yaml:"nicklen"`
165
+		TopicLen       uint          `yaml:"topiclen"`
166
+		WhowasEntries  uint          `yaml:"whowas-entries"`
167
+		LineLen        LineLenConfig `yaml:"linelen"`
163 168
 	}
164 169
 }
165 170
 
@@ -336,7 +341,7 @@ func LoadConfig(filename string) (config *Config, err error) {
336 341
 			return nil, fmt.Errorf("Could not parse connection-throttle ban-duration: %s", err.Error())
337 342
 		}
338 343
 	}
339
-	if config.Limits.LineLen < 512 {
344
+	if config.Limits.LineLen.Tags < 512 || config.Limits.LineLen.Rest < 512 {
340 345
 		return nil, errors.New("Line length must be 512 or greater")
341 346
 	}
342 347
 

+ 2
- 1
irc/constants.go Datei anzeigen

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

+ 15
- 7
irc/server.go Datei anzeigen

@@ -37,7 +37,7 @@ var (
37 37
 	errDbOutOfDate = errors.New("Database schema is old.")
38 38
 )
39 39
 
40
-// Limits holds the maximum limits for various things such as topic lengths
40
+// Limits holds the maximum limits for various things such as topic lengths.
41 41
 type Limits struct {
42 42
 	AwayLen        int
43 43
 	ChannelLen     int
@@ -46,7 +46,13 @@ type Limits struct {
46 46
 	NickLen        int
47 47
 	TopicLen       int
48 48
 	ChanListModes  int
49
-	LineLen        int
49
+	LineLen        LineLenLimits
50
+}
51
+
52
+// LineLenLimits holds the maximum limits for IRC lines.
53
+type LineLenLimits struct {
54
+	Tags int
55
+	Rest int
50 56
 }
51 57
 
52 58
 // ListenerInterface represents an interface for a listener.
@@ -147,10 +153,9 @@ func NewServer(configFilename string, config *Config) *Server {
147 153
 		SupportedCapabilities[SASL] = true
148 154
 	}
149 155
 
150
-	if config.Limits.LineLen > 512 {
151
-		maxLineLength = int(config.Limits.LineLen)
156
+	if config.Limits.LineLen.Tags > 512 || config.Limits.LineLen.Rest > 512 {
152 157
 		SupportedCapabilities[MaxLine] = true
153
-		CapValues[MaxLine] = strconv.Itoa(int(config.Limits.LineLen))
158
+		CapValues[MaxLine] = fmt.Sprintf("%d,%d", config.Limits.LineLen.Tags, config.Limits.LineLen.Rest)
154 159
 	}
155 160
 
156 161
 	operClasses, err := config.OperatorClasses()
@@ -191,7 +196,10 @@ func NewServer(configFilename string, config *Config) *Server {
191 196
 			NickLen:        int(config.Limits.NickLen),
192 197
 			TopicLen:       int(config.Limits.TopicLen),
193 198
 			ChanListModes:  int(config.Limits.ChanListModes),
194
-			LineLen:        int(config.Limits.LineLen),
199
+			LineLen: LineLenLimits{
200
+				Tags: config.Limits.LineLen.Tags,
201
+				Rest: config.Limits.LineLen.Rest,
202
+			},
195 203
 		},
196 204
 		listeners:      make(map[string]ListenerInterface),
197 205
 		monitoring:     make(map[string][]Client),
@@ -1108,7 +1116,7 @@ func (server *Server) rehash() error {
1108 1116
 	}
1109 1117
 
1110 1118
 	// line lengths cannot be changed after launching the server
1111
-	if maxLineLength != int(config.Limits.LineLen) {
1119
+	if maxLineTagsLength != config.Limits.LineLen.Tags || maxLineRestLength != config.Limits.LineLen.Rest {
1112 1120
 		return fmt.Errorf("Maximum line length (linelen) cannot be changed after launching the server, rehash aborted")
1113 1121
 	}
1114 1122
 

+ 6
- 1
oragono.yaml Datei anzeigen

@@ -204,4 +204,9 @@ limits:
204 204
     chan-list-modes: 60
205 205
 
206 206
     # maximum length of IRC lines
207
-    linelen: 2048
207
+    linelen:
208
+        # tags section
209
+        tags: 2048
210
+
211
+        # rest of the message
212
+        rest: 2048

Laden…
Abbrechen
Speichern