Revision 14dd8318
Added by Marc Dequènes about 13 years ago
- ID 14dd8318e224f9eb83792c48db9e7c91e4ba8ce8
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|
|
||
conv_thread.call(cmd, *args) do |reply|
|
||
case reply[:status]
|
||
when :ok
|
||
subtask.results = {key => reply[:result]}
|
||
when :decline
|
||
# TODO: remove this case ???
|
||
when :error
|
||
subtask.errors << reply[:exception]
|
||
end
|
||
|
||
subtask.finish
|
||
end
|
||
end
|
||
end
|
||
|
||
def know?(peer, key, cmd)
|
||
_add_subtask_using_peer(peer) do |subtask, conv_thread|
|
||
conv_thread.exists?(cmd) do |reply|
|
||
case reply[:status]
|
||
when :ok
|
||
subtask.results = {key => reply[:result]}
|
||
when :decline
|
||
# TODO: remove this case ???
|
||
when :error
|
||
subtask.errors << reply[:exception]
|
||
end
|
||
|
||
subtask.finish
|
||
end
|
||
end
|
||
end
|
||
|
||
def _add_subtask_using_peer(peer)
|
||
_add_subtask("botnet/peer/#{peer}/out") do |subtask|
|
||
logger.debug "Task '#{@name}': Trying to contact peer '#{peer}'"
|
||
@bot.contact_peer(peer) do |conv|
|
||
... | ... | |
|
||
# don't use the block call to leave the conversation thread open
|
||
conv_thread = conv.thread(@notification_name)
|
||
conv_thread.call(cmd, *args) do |reply|
|
||
case reply[:status]
|
||
when :ok
|
||
subtask.results = {key => reply[:result]}
|
||
when :decline
|
||
# TODO: remove this case ???
|
||
when :error
|
||
subtask.errors << reply[:exception]
|
||
end
|
||
|
||
subtask.finish
|
||
end
|
||
yield(subtask, conv_thread)
|
||
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
[evol] Protocol/DSL: implemented node existence check