Browse Source

default fakelag to off, add explicit cooldown config

tags/v0.11.0-beta
Shivaram Lingamneni 6 years ago
parent
commit
36018174b0
5 changed files with 16 additions and 11 deletions
  1. 1
    1
      irc/client.go
  2. 1
    0
      irc/config.go
  3. 6
    5
      irc/fakelag.go
  4. 3
    3
      irc/fakelag_test.go
  5. 5
    2
      oragono.yaml

+ 1
- 1
irc/client.go View File

@@ -158,7 +158,7 @@ func (client *Client) resetFakelag() {
158 158
 			return nil
159 159
 		}
160 160
 
161
-		return NewFakelag(flc.Window, flc.BurstLimit, flc.MessagesPerWindow)
161
+		return NewFakelag(flc.Window, flc.BurstLimit, flc.MessagesPerWindow, flc.Cooldown)
162 162
 	}()
163 163
 
164 164
 	client.stateMutex.Lock()

+ 1
- 0
irc/config.go View File

@@ -194,6 +194,7 @@ type FakelagConfig struct {
194 194
 	Window            time.Duration
195 195
 	BurstLimit        uint `yaml:"burst-limit"`
196 196
 	MessagesPerWindow uint `yaml:"messages-per-window"`
197
+	Cooldown          time.Duration
197 198
 }
198 199
 
199 200
 // Config defines the overall configuration.

+ 6
- 5
irc/fakelag.go View File

@@ -27,6 +27,7 @@ type Fakelag struct {
27 27
 	window                    time.Duration
28 28
 	burstLimit                uint
29 29
 	throttleMessagesPerWindow uint
30
+	cooldown                  time.Duration
30 31
 	nowFunc                   func() time.Time
31 32
 	sleepFunc                 func(time.Duration)
32 33
 
@@ -35,11 +36,12 @@ type Fakelag struct {
35 36
 	lastTouch  time.Time
36 37
 }
37 38
 
38
-func NewFakelag(window time.Duration, burstLimit uint, throttleMessagesPerWindow uint) *Fakelag {
39
+func NewFakelag(window time.Duration, burstLimit uint, throttleMessagesPerWindow uint, cooldown time.Duration) *Fakelag {
39 40
 	return &Fakelag{
40 41
 		window:                    window,
41 42
 		burstLimit:                burstLimit,
42 43
 		throttleMessagesPerWindow: throttleMessagesPerWindow,
44
+		cooldown:                  cooldown,
43 45
 		nowFunc:                   time.Now,
44 46
 		sleepFunc:                 time.Sleep,
45 47
 		state:                     FakelagBursting,
@@ -59,8 +61,7 @@ func (fl *Fakelag) Touch() {
59 61
 
60 62
 	if fl.state == FakelagBursting {
61 63
 		// determine if the previous burst is over
62
-		// (we could use 2*window instead)
63
-		if elapsed > fl.window {
64
+		if elapsed > fl.cooldown {
64 65
 			fl.burstCount = 0
65 66
 		}
66 67
 
@@ -77,8 +78,8 @@ func (fl *Fakelag) Touch() {
77 78
 	}
78 79
 
79 80
 	if fl.state == FakelagThrottled {
80
-		if elapsed > fl.window {
81
-			// let them burst again (as above, we could use 2*window instead)
81
+		if elapsed > fl.cooldown {
82
+			// let them burst again
82 83
 			fl.state = FakelagBursting
83 84
 			return
84 85
 		}

+ 3
- 3
irc/fakelag_test.go View File

@@ -39,8 +39,8 @@ func (mt *mockTime) lastSleep() (slept bool, duration time.Duration) {
39 39
 	return
40 40
 }
41 41
 
42
-func newFakelagForTesting(window time.Duration, burstLimit uint, throttleMessagesPerWindow uint) (*Fakelag, *mockTime) {
43
-	fl := NewFakelag(window, burstLimit, throttleMessagesPerWindow)
42
+func newFakelagForTesting(window time.Duration, burstLimit uint, throttleMessagesPerWindow uint, cooldown time.Duration) (*Fakelag, *mockTime) {
43
+	fl := NewFakelag(window, burstLimit, throttleMessagesPerWindow, cooldown)
44 44
 	mt := new(mockTime)
45 45
 	mt.now, _ = time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Jan 2 15:04:05 -0700 MST 2006")
46 46
 	mt.lastCheckedSleep = -1
@@ -51,7 +51,7 @@ func newFakelagForTesting(window time.Duration, burstLimit uint, throttleMessage
51 51
 
52 52
 func TestFakelag(t *testing.T) {
53 53
 	window, _ := time.ParseDuration("1s")
54
-	fl, mt := newFakelagForTesting(window, 3, 2)
54
+	fl, mt := newFakelagForTesting(window, 3, 2, window)
55 55
 
56 56
 	fl.Touch()
57 57
 	slept, _ := mt.lastSleep()

+ 5
- 2
oragono.yaml View File

@@ -392,15 +392,18 @@ limits:
392 392
 # fakelag: prevents clients from spamming commands too rapidly
393 393
 fakelag:
394 394
     # whether to enforce fakelag
395
-    enabled: true
395
+    enabled: false
396 396
 
397 397
     # time unit for counting command rates
398 398
     window: 1s
399 399
 
400 400
     # clients can send this many commands without fakelag being imposed
401
-    # (resets after a period of `window` elapses without any commands)
402 401
     burst-limit: 5
403 402
 
404 403
     # once clients have exceeded their burst allowance, they can send only
405 404
     # this many commands per `window`:
406 405
     messages-per-window: 2
406
+
407
+    # client status resets to the default state if they go this long without
408
+    # sending any commands:
409
+    cooldown: 1s

Loading…
Cancel
Save