Project

General

Profile

« Previous | Next » 

Revision a089227c

Added by Marc Dequènes about 13 years ago

  • ID a089227ca94121115f46e5998b497fa102787398

[fix/evol] work on better Interface/Task/Conversation/… sync and bot stop action in order to avoid races and locks

View differences:

lib/cyborghood/cyborg/botnet/dsl.rb
module DSL
module BotnetTask
def ask(peer, key, cmd, *args)
_add_subtask_using_peer(peer) do |subtask, conv_thread|
action_name = ['ask', cmd, *args].hash
_add_subtask_using_peer(action_name, peer) do |subtask, conv_thread|
conv_thread.call(cmd, *args) do |reply|
case reply[:status]
when :ok
......
end
def know?(peer, key, cmd)
_add_subtask_using_peer(peer) do |subtask, conv_thread|
action_name = ['know', cmd].hash
_add_subtask_using_peer(action_name, peer) do |subtask, conv_thread|
conv_thread.exists?(cmd) do |reply|
case reply[:status]
when :ok
......
end
end
def _add_subtask_using_peer(peer)
_add_subtask("botnet/peer/#{peer}/out") do |subtask|
def _add_subtask_using_peer(action_name, peer)
subtask_name = "botnet/peer/#{peer}/#{action_name}/out"
_add_subtask(subtask_name) do |subtask|
logger.debug "Task '#{@name}': Trying to contact peer '#{peer}'"
# callback to end peer action and subtask
# (used when shooting the task)
defuse_peer_action_cb = Proc.new do
logger.debug "Task '#{@name}': defusing subtask '#{subtask.name}'"
subtask.finish unless subtask.finished?
# we already own the mutex here
registered_resources.delete(subtask_name)
end
# register peer action in the task
tasks_info_mutex.synchronize do
registered_resources[subtask_name] = defuse_peer_action_cb
end
@bot.contact_peer(peer) do |conv|
if conv
logger.debug "Task '#{@name}': Peer '#{peer}' contacted, starting conversation"
logger.debug "Task '#{@name}': subtask '#{subtask.name}': peer '#{peer}' contacted, starting conversation"
@peer_contacted << peer
......
def _finished
super
# close opened thread
cb = Proc.new do |conv|
conv.close_thread(@notification_name)
end
# loop on all contacted peers to close the thread
@peer_contacted.each do |peer|
@bot.contact_peer(peer, true, &cb)
end

Also available in: Unified diff