commit 14dd8318e224f9eb83792c48db9e7c91e4ba8ce8
Author: Marc Dequènes (Duck) <Duck@DuckCorp.org>
Date:   Sat Feb 26 20:38:13 2011 +0100

    [evol] Protocol/DSL: implemented node existence check

diff --git a/bin/test_client b/bin/test_client
index d3fbac9..9faa314 100755
--- a/bin/test_client
+++ b/bin/test_client
@@ -41,6 +41,8 @@ module CyborgHood
           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
diff --git a/lib/cyborghood/cyborg/botnet/conversation.rb b/lib/cyborghood/cyborg/botnet/conversation.rb
index c96bab9..2741291 100644
--- a/lib/cyborghood/cyborg/botnet/conversation.rb
+++ b/lib/cyborghood/cyborg/botnet/conversation.rb
@@ -62,6 +62,11 @@ module CyborgHood
       @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)
diff --git a/lib/cyborghood/cyborg/botnet/dsl.rb b/lib/cyborghood/cyborg/botnet/dsl.rb
index cb9b5fa..0f48fd6 100644
--- a/lib/cyborghood/cyborg/botnet/dsl.rb
+++ b/lib/cyborghood/cyborg/botnet/dsl.rb
@@ -21,6 +21,40 @@ module CyborgHood
   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|
@@ -31,18 +65,8 @@ module CyborgHood
 
               # 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}'")
diff --git a/lib/cyborghood/cyborg/botnet/protocol.rb b/lib/cyborghood/cyborg/botnet/protocol.rb
index b2bc8a4..8a2ecd7 100644
--- a/lib/cyborghood/cyborg/botnet/protocol.rb
+++ b/lib/cyborghood/cyborg/botnet/protocol.rb
@@ -132,14 +132,11 @@ module CyborgHood
       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
@@ -241,7 +238,7 @@ module CyborgHood
       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
