diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2006-07-19 16:55:09 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2006-07-19 16:55:09 +0000 |
commit | 63d19509dd6858dca025b68e3557914fa5e4cc18 (patch) | |
tree | be3043c5afc946651f8d75347cf3528dc5faa69c /lib/rbot/ircsocket.rb | |
parent | 455eaba9fcc043cd0e7f497626555af8a5281a2b (diff) |
Fine-tune byterate throttling flood prevention. Better than before, but still not there.
Diffstat (limited to 'lib/rbot/ircsocket.rb')
-rw-r--r-- | lib/rbot/ircsocket.rb | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/rbot/ircsocket.rb b/lib/rbot/ircsocket.rb index e9fc884f..2a1549a2 100644 --- a/lib/rbot/ircsocket.rb +++ b/lib/rbot/ircsocket.rb @@ -22,6 +22,10 @@ module Irc # accumulator for the throttle attr_reader :throttle_bytes + # byterate components + attr_reader :bytes_per + attr_reader :seconds_per + # delay between lines sent attr_reader :sendq_delay @@ -179,9 +183,12 @@ module Irc end now = Time.new if @throttle_bytes > 0 - @throttle_bytes -= (now - @last_throttle)*@bytes_per/@seconds_per - @throttle_bytes = 0 if @throttle_bytes < 0 - @last_throttle = now + delta = ((now - @last_throttle)*@bytes_per/@seconds_per).floor + if delta > 0 + @throttle_bytes -= delta + @throttle_bytes = 0 if @throttle_bytes < 0 + @last_throttle = now + end end if (now >= (@last_send + @sendq_delay)) # reset burst counter after @sendq_delay has passed @@ -200,9 +207,8 @@ module Irc if @throttle_bytes == 0 or mess.length+@throttle_bytes < @bytes_per puts_critical(@sendq.shift) else - debug "(flood protection: breaking at message of length #{mess.length})" - debug "(Throttle bytes: #{@throttle_bytes})" - debug "(Byterate: #{byterate})" + debug "(flood protection: throttling message of length #{mess.length})" + debug "(byterate: #{byterate}, throttle bytes: #{@throttle_bytes})" break end end @@ -250,7 +256,8 @@ module Irc @last_send = Time.new @lines_sent += 1 @burst += 1 - @throttle_bytes += message.length + @throttle_bytes += message.length + 1 + @last_throttle = Time.new end end |