Project

General

Profile

« Previous | Next » 

Revision 258a439a

Added by Marc Dequènes about 13 years ago

  • ID 258a439a59e2be7ce7dcb2e68acf3b744e01f91f

[evol] Botnet: propagate API calls environment (user token and language prefs at the moment), propagate session a bit further too in order to implement a more dynamic API tree

View differences:

lib/cyborghood/cyborg/botnet/dsl.rb
def ask(peer, key, cmd, *args)
action_name = ['ask', cmd, *args].hash
_add_subtask_using_peer(action_name, peer) do |subtask, conv_thread|
conv_thread.call(cmd, *args) do |reply|
_add_subtask_using_peer(action_name, peer) do |subtask, conv_thread, env|
cmd = cmd.call if cmd.is_a? Proc
args.collect!{|a| a.is_a?(Proc) ? a.call : a }
conv_thread.call(env, cmd, *args) do |reply|
case reply[:status]
when :ok
subtask.results = {key => reply[:result]}
......
def know?(peer, key, cmd)
action_name = ['know', cmd].hash
_add_subtask_using_peer(action_name, peer) do |subtask, conv_thread|
conv_thread.exists?(cmd) do |reply|
_add_subtask_using_peer(action_name, peer) do |subtask, conv_thread, env|
cmd = cmd.call if cmd.is_a? Proc
conv_thread.exists?(env, cmd) do |reply|
case reply[:status]
when :ok
subtask.results = {key => reply[:result]}
......
registered_resources[subtask_name] = defuse_peer_action_cb
end
# catch current environment to transmit it
env = {
:preferred_locales => @preferred_locales,
:user => @user
}
@bot.contact_peer(peer) do |conv|
if conv
logger.debug "Task '#{@name}': subtask '#{subtask.name}': peer '#{peer}' contacted, starting conversation"
......
# don't use the block call to leave the conversation thread open
conv_thread = conv.thread(@notification_name)
yield(subtask, conv_thread)
yield(subtask, conv_thread, env)
else
logger.debug "Task '#{@name}': Could not contact peer '#{peer}'"
subtask.errors << CyberError.new(:unrecoverable, "botnet/client/dsl", "Task '#{@name}': could not contact peer '#{peer}'")

Also available in: Unified diff