Explorar el Código

default fakelag to off, add explicit cooldown config

tags/v0.11.0-beta
Shivaram Lingamneni hace 6 años
padre
commit
36018174b0
Se han modificado 5 ficheros con 16 adiciones y 11 borrados
  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 Ver fichero

158
 			return nil
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
 	client.stateMutex.Lock()
164
 	client.stateMutex.Lock()

+ 1
- 0
irc/config.go Ver fichero

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

+ 6
- 5
irc/fakelag.go Ver fichero

27
 	window                    time.Duration
27
 	window                    time.Duration
28
 	burstLimit                uint
28
 	burstLimit                uint
29
 	throttleMessagesPerWindow uint
29
 	throttleMessagesPerWindow uint
30
+	cooldown                  time.Duration
30
 	nowFunc                   func() time.Time
31
 	nowFunc                   func() time.Time
31
 	sleepFunc                 func(time.Duration)
32
 	sleepFunc                 func(time.Duration)
32
 
33
 
35
 	lastTouch  time.Time
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
 	return &Fakelag{
40
 	return &Fakelag{
40
 		window:                    window,
41
 		window:                    window,
41
 		burstLimit:                burstLimit,
42
 		burstLimit:                burstLimit,
42
 		throttleMessagesPerWindow: throttleMessagesPerWindow,
43
 		throttleMessagesPerWindow: throttleMessagesPerWindow,
44
+		cooldown:                  cooldown,
43
 		nowFunc:                   time.Now,
45
 		nowFunc:                   time.Now,
44
 		sleepFunc:                 time.Sleep,
46
 		sleepFunc:                 time.Sleep,
45
 		state:                     FakelagBursting,
47
 		state:                     FakelagBursting,
59
 
61
 
60
 	if fl.state == FakelagBursting {
62
 	if fl.state == FakelagBursting {
61
 		// determine if the previous burst is over
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
 			fl.burstCount = 0
65
 			fl.burstCount = 0
65
 		}
66
 		}
66
 
67
 
77
 	}
78
 	}
78
 
79
 
79
 	if fl.state == FakelagThrottled {
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
 			fl.state = FakelagBursting
83
 			fl.state = FakelagBursting
83
 			return
84
 			return
84
 		}
85
 		}

+ 3
- 3
irc/fakelag_test.go Ver fichero

39
 	return
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
 	mt := new(mockTime)
44
 	mt := new(mockTime)
45
 	mt.now, _ = time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Jan 2 15:04:05 -0700 MST 2006")
45
 	mt.now, _ = time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Jan 2 15:04:05 -0700 MST 2006")
46
 	mt.lastCheckedSleep = -1
46
 	mt.lastCheckedSleep = -1
51
 
51
 
52
 func TestFakelag(t *testing.T) {
52
 func TestFakelag(t *testing.T) {
53
 	window, _ := time.ParseDuration("1s")
53
 	window, _ := time.ParseDuration("1s")
54
-	fl, mt := newFakelagForTesting(window, 3, 2)
54
+	fl, mt := newFakelagForTesting(window, 3, 2, window)
55
 
55
 
56
 	fl.Touch()
56
 	fl.Touch()
57
 	slept, _ := mt.lastSleep()
57
 	slept, _ := mt.lastSleep()

+ 5
- 2
oragono.yaml Ver fichero

392
 # fakelag: prevents clients from spamming commands too rapidly
392
 # fakelag: prevents clients from spamming commands too rapidly
393
 fakelag:
393
 fakelag:
394
     # whether to enforce fakelag
394
     # whether to enforce fakelag
395
-    enabled: true
395
+    enabled: false
396
 
396
 
397
     # time unit for counting command rates
397
     # time unit for counting command rates
398
     window: 1s
398
     window: 1s
399
 
399
 
400
     # clients can send this many commands without fakelag being imposed
400
     # clients can send this many commands without fakelag being imposed
401
-    # (resets after a period of `window` elapses without any commands)
402
     burst-limit: 5
401
     burst-limit: 5
403
 
402
 
404
     # once clients have exceeded their burst allowance, they can send only
403
     # once clients have exceeded their burst allowance, they can send only
405
     # this many commands per `window`:
404
     # this many commands per `window`:
406
     messages-per-window: 2
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…
Cancelar
Guardar