Project

General

Profile

« Previous | Next » 

Revision 429ebb9c

Added by Marc Dequènes over 13 years ago

  • ID 429ebb9c1a44108e2da28316170ad4345617a58d

[evol] BotnetTask DSL: now that we have one Task per task, close conversation thread as soon as the task is finished

View differences:

lib/cyborghood/cyborg/botnet.rb
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#++
require 'cyborghood/cyborg'
require 'cyborghood/cyborg/botnet/interface'
require 'cyborghood/cyborg/botnet/conversation'
require 'cyborghood/cyborg/botnet/dsl'
......
end
end
def contact_peer(peer, block)
if @comm_list.has_key? peer
block.call @comm_list[peer]
def contact_peer(peer, block, dont_open_new_connection = false)
return block.call @comm_list[peer] if @comm_list.has_key? peer
return if dont_open_new_connection
if @comm_list_attempt.has_key? peer
@comm_list_attempt[peer] << block
else
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
yield(callback)
rescue
# TODO: retry (wait_timer + recursive call + counter)
block.call false
@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
yield(callback)
rescue
# TODO: retry (wait_timer + recursive call + counter)
block.call false
end
end
end

Also available in: Unified diff