Browse Source

maintain lenBytes as a running count

tags/v2.1.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
8efbc4bc32
3 changed files with 7 additions and 16 deletions
  1. 2
    1
      irc/client.go
  2. 5
    1
      irc/handlers.go
  3. 0
    14
      irc/utils/text.go

+ 2
- 1
irc/client.go View File

146
 	target        string
146
 	target        string
147
 	responseLabel string // this is the value of the labeled-response tag sent with BATCH
147
 	responseLabel string // this is the value of the labeled-response tag sent with BATCH
148
 	message       utils.SplitMessage
148
 	message       utils.SplitMessage
149
+	lenBytes      int
149
 	tags          map[string]string
150
 	tags          map[string]string
150
 }
151
 }
151
 
152
 
168
 	s.fakelag.Unsuspend()
169
 	s.fakelag.Unsuspend()
169
 
170
 
170
 	// heuristics to estimate how much data they used while fakelag was suspended
171
 	// heuristics to estimate how much data they used while fakelag was suspended
171
-	fakelagBill := (batch.message.LenBytes() / 512) + 1
172
+	fakelagBill := (batch.lenBytes / 512) + 1
172
 	fakelagBillLines := (batch.message.LenLines() * 60) / 512
173
 	fakelagBillLines := (batch.message.LenLines() * 60) / 512
173
 	if fakelagBill < fakelagBillLines {
174
 	if fakelagBill < fakelagBillLines {
174
 		fakelagBill = fakelagBillLines
175
 		fakelagBill = fakelagBillLines

+ 5
- 1
irc/handlers.go View File

1816
 		errorCode, errorMessage = "MULTILINE_INVALID", client.t("Cannot send a blank line with the multiline concat tag")
1816
 		errorCode, errorMessage = "MULTILINE_INVALID", client.t("Cannot send a blank line with the multiline concat tag")
1817
 		return
1817
 		return
1818
 	}
1818
 	}
1819
+	if !isConcat && len(rb.session.batch.message.Split) != 0 {
1820
+		rb.session.batch.lenBytes++ // bill for the newline
1821
+	}
1819
 	rb.session.batch.message.Append(msg.Params[1], isConcat)
1822
 	rb.session.batch.message.Append(msg.Params[1], isConcat)
1823
+	rb.session.batch.lenBytes += len(msg.Params[1])
1820
 	config := server.Config()
1824
 	config := server.Config()
1821
-	if config.Limits.Multiline.MaxBytes < rb.session.batch.message.LenBytes() {
1825
+	if config.Limits.Multiline.MaxBytes < rb.session.batch.lenBytes {
1822
 		errorCode, errorMessage = "MULTILINE_MAX_BYTES", strconv.Itoa(config.Limits.Multiline.MaxBytes)
1826
 		errorCode, errorMessage = "MULTILINE_MAX_BYTES", strconv.Itoa(config.Limits.Multiline.MaxBytes)
1823
 	} else if config.Limits.Multiline.MaxLines != 0 && config.Limits.Multiline.MaxLines < rb.session.batch.message.LenLines() {
1827
 	} else if config.Limits.Multiline.MaxLines != 0 && config.Limits.Multiline.MaxLines < rb.session.batch.message.LenLines() {
1824
 		errorCode, errorMessage = "MULTILINE_MAX_LINES", strconv.Itoa(config.Limits.Multiline.MaxLines)
1828
 		errorCode, errorMessage = "MULTILINE_MAX_LINES", strconv.Itoa(config.Limits.Multiline.MaxLines)

+ 0
- 14
irc/utils/text.go View File

67
 	return len(sm.Split)
67
 	return len(sm.Split)
68
 }
68
 }
69
 
69
 
70
-func (sm *SplitMessage) LenBytes() (result int) {
71
-	if sm.Split == nil {
72
-		return len(sm.Message)
73
-	}
74
-	for i := 0; i < len(sm.Split); i++ {
75
-		result += len(sm.Split[i].Message)
76
-		// bill for the joining newline if necessary
77
-		if i != 0 && !sm.Split[i].Concat {
78
-			result += 1
79
-		}
80
-	}
81
-	return
82
-}
83
-
84
 func (sm *SplitMessage) ValidMultiline() bool {
70
 func (sm *SplitMessage) ValidMultiline() bool {
85
 	// must contain at least one nonblank line
71
 	// must contain at least one nonblank line
86
 	for i := 0; i < len(sm.Split); i++ {
72
 	for i := 0; i < len(sm.Split); i++ {

Loading…
Cancel
Save