topology option support for GNUNET_TESTBED_run() via configuration
[oweals/gnunet.git] / src / testbed / gnunet-service-testbed.c
index ac0ff756206be21927fadd13196880395c05a02b..ec3e000ee8fdd36cc0cf851a5e53c67fb59d5f93 100644 (file)
@@ -600,11 +600,6 @@ struct OverlayConnectContext
    */
   uint32_t other_peer_id;
 
-  /**
-   * Number of times we tried to send hello; used to increase delay in offering
-   * hellos
-   */
-  uint16_t retries;
 };
 
 
@@ -651,12 +646,6 @@ struct RequestOverlayConnectContext
    */
   GNUNET_SCHEDULER_TaskIdentifier timeout_rocc_task_id;
   
-  /**
-   * Number of times we tried to send hello; used to increase delay in offering
-   * hellos
-   */
-  uint16_t retries;
-  
 };
 
 
@@ -1817,7 +1806,7 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
   master_context->client = client;
   master_context->host_id = ntohl (msg->host_id);
   master_context->master_ip = GNUNET_strdup (controller_hostname);
-  LOG_DEBUG ("Master Controller IP: %s\n", master_context->master_ip);
+  LOG_DEBUG ("Our IP: %s\n", master_context->master_ip);
   master_context->system =
       GNUNET_TESTING_system_create ("testbed", master_context->master_ip, hostname);
   host =
@@ -2250,7 +2239,7 @@ peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
 /**
  * Function to destroy a peer
  *
- * @param the peer structure to destroy
+ * @param peer the peer structure to destroy
  */
 static void
 destroy_peer (struct Peer *peer)
@@ -2919,7 +2908,8 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     occ->send_hello_task =
         GNUNET_SCHEDULER_add_delayed
         (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
-                                        100 * (pow (2, occ->retries++))),
+                                        100 + GNUNET_CRYPTO_random_u32
+                                        (GNUNET_CRYPTO_QUALITY_WEAK, 500)),
          &send_hello, occ);
   }
   GNUNET_free (other_peer_str);  
@@ -3275,22 +3265,19 @@ handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
           /* rhc is now set to the existing one from the hash map by
              reghost_match_iterator() */
           /* if queue is empty then ignore creating focc and proceed with
-             normal forwarding */
-          if (NULL == rhc->focc_dll_head)
+             normal forwarding */                
+          if (RHC_OL_CONNECT == rhc->state)
             skip_focc = GNUNET_YES;
         }
         if (GNUNET_NO == skip_focc)
         {
           struct ForwardedOverlayConnectContext *focc;
-          uint16_t msize;
 
-          msize = sizeof (struct GNUNET_TESTBED_OverlayConnectMessage);
           focc = GNUNET_malloc (sizeof (struct ForwardedOverlayConnectContext));
           focc->peer1 = p1;
           focc->peer2 = p2;
           focc->peer2_host_id = peer2_host_id;
-          focc->orig_msg = GNUNET_malloc (msize);
-          (void) memcpy (focc->orig_msg, message, msize);
+          focc->orig_msg = GNUNET_copy_message (message);
           focc->operation_id = operation_id;
           GNUNET_CONTAINER_DLL_insert_tail (rhc->focc_dll_head,
                                             rhc->focc_dll_tail,
@@ -3324,31 +3311,18 @@ handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
     if ((peer2_host_id >= slave_list_size)
        || (NULL ==slave_list[peer2_host_id]))
     {
-      struct GNUNET_TESTBED_NeedControllerConfig *reply;
-
-      LOG_DEBUG ("Need controller configuration for connecting peers %u and %u\n",
-                p1, p2);
-      reply = GNUNET_malloc (sizeof (struct
-                                     GNUNET_TESTBED_NeedControllerConfig)); 
-      reply->header.size = htons (sizeof (struct
-                                          GNUNET_TESTBED_NeedControllerConfig));
-      reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_NEEDCONTROLLERCONFIG);
-      reply->controller_host_id = msg->peer2_host_id;
-      reply->operation_id = msg->operation_id;
-      queue_message (client, &reply->header);      
-      GNUNET_SERVER_receive_done (client, GNUNET_OK);
+      LOG (GNUNET_ERROR_TYPE_WARNING,
+           "Configuration of peer2's controller missing for connecting peers"
+           "%u and %u\n", p1, p2);      
+      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
       return;
     }
-    else
+    peer2_controller = slave_list[peer2_host_id]->controller;
+    if (NULL == peer2_controller)
     {
-      //occ->peer2_controller = slave_list[peer2_host_id]->controller;
-      peer2_controller = slave_list[peer2_host_id]->controller;
-      if (NULL == peer2_controller)
-      {
-        GNUNET_break (0);       /* What's going on? */
-        GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-        return;
-      }
+      GNUNET_break (0);       /* What's going on? */
+      GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+      return;
     }
   }
   else
@@ -3488,7 +3462,8 @@ attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   rocc->attempt_connect_task_id = 
       GNUNET_SCHEDULER_add_delayed 
       (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
-                                      100 * (pow (2, rocc->retries++))),
+                                      100 + GNUNET_CRYPTO_random_u32
+                                      (GNUNET_CRYPTO_QUALITY_WEAK, 500)),
        &attempt_connect_task, rocc);
 }
 
@@ -3684,7 +3659,7 @@ reghost_free_iterator (void *cls,
     cleanup_focc (focc);
   }
   if (NULL != rhc->sub_op)
-    GNUNET_TESTBED_operation_cancel (rhc->sub_op);
+    GNUNET_TESTBED_operation_done (rhc->sub_op);
   if (NULL != rhc->client)
   GNUNET_SERVER_client_drop (rhc->client);
   GNUNET_free (value);
@@ -3842,7 +3817,6 @@ client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
   if (client == master_context->client)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "Master client disconnected\n");
-    GNUNET_SERVER_client_drop (client);
     /* should not be needed as we're terminated by failure to read
      * from stdin, but if stdin fails for some reason, this shouldn't
      * hurt for now --- might need to revise this later if we ever