-
-
Notifications
You must be signed in to change notification settings - Fork 426
Description
Right now rate limiting is hardcoded in a few places.
Would be nice to have an admin command to change the ratelimiting configuration of the server. Ideally we wouldn't have to expose fine-grained configurations for the io ratelimiting, perhaps it can be automagically extrapolated based on "number of messages"?
Something like /ratelimit 5 per 3s
The challenge is that the inputLimiter calibration was done iteratively and it will be hard to come up with a formula that will work in all cases. Perhaps a better option would be to simply toggle all of the rate limiting mechanics? Less useful for public servers, but desirable for private servers. Or maybe disable rate limiting for whitelist-enabled servers?
Off the top of my head, these sections would need to be updated:
Line 182 in 4fe4374
| ratelimit := rateio.NewSimpleLimiter(3, time.Second*3) |
Lines 31 to 34 in 5af617f
| if l.RateLimit != nil { | |
| // TODO: Configurable Limiter? | |
| conn = ReadLimitConn(conn, l.RateLimit()) | |
| } |
Lines 42 to 53 in 5af617f
| // NewInputLimiter returns a rateio.Limiter with sensible defaults for | |
| // differentiating between humans typing and bots spamming. | |
| func NewInputLimiter() rateio.Limiter { | |
| grace := time.Second * 3 | |
| return &inputLimiter{ | |
| Amount: 2 << 14, // ~16kb, should be plenty for a high typing rate/copypasta/large key handshakes. | |
| Frequency: time.Minute * 1, | |
| readCap: 128, // Allow up to 128 bytes per read (anecdotally, 1 character = 52 bytes over ssh) | |
| numRead: -1024 * 1024, // Start with a 1mb grace | |
| timeRead: time.Now().Add(grace), | |
| } | |
| } |
(Prompted by #363)