Project

General

Profile

« Previous | Next » 

Revision 0299bce8

Added by Marc Dequènes about 14 years ago

  • ID 0299bce8f0feb40db99ef1027cf50324c90606ca

[evol] connect_peer: do not open multiple connections to the same peer while one is being attempted already

View differences:

lib/cyborghood/cyborg/botnet.rb
if @comm_list.has_key? peer
block.call @comm_list[peer]
else
callback = proc do |conversation|
block.call conversation
@pending_conversation_close << conversation.peer_id
end
begin
EventMachine.connect_unix_domain(peer_socket(peer), Conversation, self, block)
rescue
block.call false
if @comm_list_attempt.has_key? peer
@comm_list_attempt[peer] << block
else
@comm_list_attempt[peer] = [block]
# demultiplex callbacks
callback = proc do |conversation|
block_list = @comm_list_attempt[peer]
# purge list at once to avoid races
@comm_list_attempt.delete(peer)
block_list.each do |block|
block.call conversation
end
end
begin
EventMachine.connect_unix_domain(peer_socket(peer), Conversation, self, callback)
rescue
# TODO: retry (wait_timer + recursive call + counter)
block.call false
end
end
end
end
......
def setup
super
@comm_list = {}
@comm_list_attempt = {}
end
# used to quit properly and later to reuse communication channels
lib/cyborghood/cyborg/botnet_dsl.rb
end
else
logger.debug "Task '#{@name}': Could not contact peer '#{peer}'"
# TODO: retry (wait_timer + recursive call + counter)
subtask.errors << CyberError.new(:unrecoverable, "botnet/client/dsl", "Task '#{@name}': could not contact peer '#{peer}'")
subtask.finish
end

Also available in: Unified diff