Revision 14dd8318
Added by Marc Dequènes over 13 years ago
- ID 14dd8318e224f9eb83792c48db9e7c91e4ba8ce8
bin/test_client | ||
---|---|---|
ask "Librarian", :info2, "/_cyborg_"
|
||
ask "MapMaker", :zones, "/DNS/Zones"
|
||
ask "MapMaker", :zone_mp, "/DNS/Zones/milkypond.org"
|
||
know? "MapMaker", :k1, "/DNS/Zones"
|
||
know? "MapMaker", :k2, "/prout"
|
||
on_error do
|
||
puts "PLOUF"
|
||
pp errors
|
lib/cyborghood/cyborg/botnet/conversation.rb | ||
---|---|---|
@conversation.protocol.send_request_call(self, *args, &callback)
|
||
end
|
||
|
||
# convenience method
|
||
def exists?(node, &callback)
|
||
@conversation.protocol.send_request_exists(self, node, &callback)
|
||
end
|
||
|
||
# convenience method
|
||
def notify(event_name, event_info)
|
||
@conversation.protocol.send_notify_event(self, event_name, event_info)
|
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}'")
|
lib/cyborghood/cyborg/botnet/protocol.rb | ||
---|---|---|
if message.action_parameters.nil?
|
||
return send_error_action(message, "missing parameters")
|
||
end
|
||
unless @conversation.bot.interface._is_node?(message.conv_thread.session, message.action_parameters[:node])
|
||
return send_error_action(message, "bad node")
|
||
end
|
||
send_reply_ack(message)
|
||
@conversation.bot.schedule_task(@@request_callback) do
|
||
{
|
||
:reply_message => message,
|
||
:action_result => @conversation.bot.interface.has_node?(message.action_parameters[:node])
|
||
:action_result => @conversation.bot.interface._is_node?(message.conv_thread.session, message.action_parameters[:node])
|
||
}
|
||
end
|
||
end
|
||
... | ... | |
message.register_callback(callback)
|
||
end
|
||
|
||
def send_request_exists(conv_thread, node)
|
||
def send_request_exists(conv_thread, node, &callback)
|
||
message = conv_thread.new_message("REQUEST EXISTS", { :node => node }).send
|
||
message.register_callback(callback)
|
||
end
|
Also available in: Unified diff
[evol] Protocol/DSL: implemented node existence check