summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-08-19 20:19:45 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-08-19 20:19:45 +0200
commit43b5cd9777cc13c6d3ac14a4015a0c8e8d9e5b50 (patch)
treefe0435f849ec3dc429512171b23b02b60feb948d /lib/rbot
parent9340ab24696230a7f5debecf272b44ad91886b9c (diff)
IRC socket: get rid of delay/burst
The penalty system should be enough to prevent the bot from being disconnected because of excess flood, making the old sendq delay/burst code unnecessary. So get rid of the latter altogether. (If the penalty system as implemented ever happens to be insufficient as implemented, it should just get fixed rather than rely on the sendq delay/burst assistance.)
Diffstat (limited to 'lib/rbot')
-rw-r--r--lib/rbot/ircbot.rb10
-rw-r--r--lib/rbot/ircsocket.rb47
2 files changed, 8 insertions, 49 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index 4f5018e3..55b10d41 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -277,14 +277,6 @@ class Bot
Config.register Config::IntegerValue.new('server.reconnect_wait',
:default => 5, :validate => Proc.new{|v| v >= 0},
:desc => "Seconds to wait before attempting to reconnect, on disconnect")
- Config.register Config::FloatValue.new('server.sendq_delay',
- :default => 2.0, :validate => Proc.new{|v| v >= 0},
- :desc => "(flood prevention) the delay between sending messages to the server (in seconds)",
- :on_change => Proc.new {|bot, v| bot.socket.sendq_delay = v })
- Config.register Config::IntegerValue.new('server.sendq_burst',
- :default => 4, :validate => Proc.new{|v| v >= 0},
- :desc => "(flood prevention) max lines to burst to the server before throttling. Most ircd's allow bursts of up 5 lines",
- :on_change => Proc.new {|bot, v| bot.socket.sendq_burst = v })
Config.register Config::IntegerValue.new('server.ping_timeout',
:default => 30, :validate => Proc.new{|v| v >= 0},
:desc => "reconnect if server doesn't respond to PING within this many seconds (set to 0 to disable)")
@@ -589,7 +581,7 @@ class Bot
debug "server.list is now #{@config['server.list'].inspect}"
end
- @socket = Irc::Socket.new(@config['server.list'], @config['server.bindhost'], @config['server.sendq_delay'], @config['server.sendq_burst'], :ssl => @config['server.ssl'])
+ @socket = Irc::Socket.new(@config['server.list'], @config['server.bindhost'], :ssl => @config['server.ssl'])
@client = Client.new
@plugins.scan
diff --git a/lib/rbot/ircsocket.rb b/lib/rbot/ircsocket.rb
index 4ac98da3..81a7fd16 100644
--- a/lib/rbot/ircsocket.rb
+++ b/lib/rbot/ircsocket.rb
@@ -231,12 +231,6 @@ module Irc
# accumulator for the throttle
attr_reader :throttle_bytes
- # delay between lines sent
- attr_accessor :sendq_delay
-
- # max lines to burst
- attr_accessor :sendq_burst
-
# an optional filter object. we call @filter.in(data) for
# all incoming data and @filter.out(data) for all outgoing data
attr_reader :filter
@@ -263,7 +257,7 @@ module Irc
# server_list:: list of servers to connect to
# host:: optional local host to bind to (ruby 1.7+ required)
# create a new Irc::Socket
- def initialize(server_list, host, sendq_delay=2, sendq_burst=4, opts={})
+ def initialize(server_list, host, opts={})
@server_list = server_list.dup
@server_uri = nil
@conn_count = 0
@@ -278,17 +272,6 @@ module Irc
else
@ssl = false
end
-
- if sendq_delay
- @sendq_delay = sendq_delay.to_f
- else
- @sendq_delay = 2
- end
- if sendq_burst
- @sendq_burst = sendq_burst.to_i
- else
- @sendq_burst = 4
- end
end
def connected?
@@ -330,9 +313,8 @@ module Irc
sock.connect
end
@sock = sock
- @last_send = Time.new - @sendq_delay
+ @last_send = Time.new
@flood_send = Time.new
- @last_throttle = Time.new
@burst = 0
@sock.extend(MonitorMixin)
@sendq = MessageQueue.new
@@ -405,7 +387,6 @@ module Irc
error "error while shutting down: #{e.pretty_inspect}"
end
@sock = nil
- @burst = 0
@sendq.clear
end
@@ -413,30 +394,17 @@ module Irc
def writer_loop
loop do
- # we could wait for the message, then calculate the delay and sleep
- # if necessary. however, if high-priority message is enqueued while
- # we sleep, it won't be the first to go out when the sleep is over.
- # thus, we have to call Time.now() twice, once to calculate the delay
- # and once to adjust @burst / @flood_send.
begin
now = Time.now
- if @sendq_delay > 0
- burst_delay = 0
- if @burst > @sendq_burst
- burst_delay = @last_send + @sendq_delay - now
- end
-
- flood_delay = @flood_send - MAX_IRC_SEND_PENALTY - now
- delay = [burst_delay, flood_delay, 0].max
- if delay > 0
- debug "sleep(#{delay}) # (f: #{flood_delay}, b: #{burst_delay})"
- sleep(delay)
- end
+ flood_delay = @flood_send - MAX_IRC_SEND_PENALTY - now
+ delay = [flood_delay, 0].max
+ if delay > 0
+ debug "sleep(#{delay}) # (f: #{flood_delay})"
+ sleep(delay)
end
msg = @sendq.shift
now = Time.now
@flood_send = now if @flood_send < now
- @burst = 0 if @last_send + @sendq_delay < now
debug "got #{msg.inspect} from queue, sending"
emergency_puts(msg, true)
rescue Exception => e
@@ -463,7 +431,6 @@ module Irc
@last_send = Time.new
@flood_send += message.irc_send_penalty if penalty
@lines_sent += 1
- @burst += 1
end
rescue Exception => e
handle_socket_error(:SEND, e)