aatxe / irc

the irc crate – usable, async IRC for Rust
Mozilla Public License 2.0
530 stars 97 forks source link

Option to throttle outgoing messages #66

Closed belst closed 7 years ago

belst commented 7 years ago

throttle burst messages to prevent kicks from the server. config example:

{
  "burst": 4, // throttle after a burst of 4 messages
  "cooldown": 4 // time in seconds after a new burst is allowed
  "throttle": 1 // time in seconds between successive messages
}
aatxe commented 7 years ago

Sounds like a good idea! Thanks for the suggestion.

aatxe commented 7 years ago

I added support for message throttling in a0f43cb80b5e92f96a68cc751c583fac55c865fc. Here's how it works: There are repeating windows of burst_window_length time (in seconds). In each window, there is a maximum number of messages that can be sent (max_messages_in_burst). If more than that number of messages are sent within one window, additional messages are held until the next window (where overflow may be continually held until the next window). Thus, the throttling is enforcing precisely the constraint that the client will send at most max_messages_in_burst messages in burst_window_length seconds.