- docs
[oweals/gnunet.git] / src / testbed / testbed_api.c
index 80f940467d6b09d54e52dbe907cc5f6f8821ab14..d7578756f2d582797ce91f611e8e9962a3da1991 100644 (file)
@@ -559,6 +559,7 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c,
   void *pcc_cls;
   struct GNUNET_TESTBED_EventInformation event;
   uint64_t op_id;
+  uint64_t mask;
 
   GNUNET_assert (sizeof (struct GNUNET_TESTBED_PeerEventMessage) ==
                  ntohs (msg->header.size));
@@ -602,9 +603,9 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c,
   GNUNET_TESTBED_remove_opc_ (opc->c, opc);
   opc->state = OPC_STATE_FINISHED;
   exop_insert (event.op);
-  if (0 !=
-      ((GNUNET_TESTBED_ET_PEER_START | GNUNET_TESTBED_ET_PEER_STOP) &
-       c->event_mask))
+  mask = 1LL << GNUNET_TESTBED_ET_PEER_START;
+  mask |= 1LL << GNUNET_TESTBED_ET_PEER_STOP;
+  if (0 != (mask & c->event_mask))
   {
     if (NULL != c->cc)
       c->cc (c->cc_cls, &event);    
@@ -638,6 +639,7 @@ handle_peer_conevent (struct GNUNET_TESTBED_Controller *c,
   void *cb_cls;
   struct GNUNET_TESTBED_EventInformation event;
   uint64_t op_id;
+  uint64_t mask;
 
   op_id = GNUNET_ntohll (msg->operation_id);
   if (NULL == (opc = find_opc (c, op_id)))
@@ -676,9 +678,9 @@ handle_peer_conevent (struct GNUNET_TESTBED_Controller *c,
   GNUNET_TESTBED_remove_opc_ (opc->c, opc);
   opc->state = OPC_STATE_FINISHED;
   exop_insert (event.op);
-  if (0 !=
-      ((GNUNET_TESTBED_ET_CONNECT | GNUNET_TESTBED_ET_DISCONNECT) &
-       c->event_mask))
+  mask = 1LL << GNUNET_TESTBED_ET_CONNECT;
+  mask |= 1LL << GNUNET_TESTBED_ET_DISCONNECT;
+  if (0 != (mask & c->event_mask))
   {
     if (NULL != c->cc)
       c->cc (c->cc_cls, &event);
@@ -940,6 +942,7 @@ handle_slave_config (struct GNUNET_TESTBED_Controller *c,
 {
   struct OperationContext *opc;
   uint64_t op_id;
+  uint64_t mask;
   struct GNUNET_TESTBED_EventInformation event;
 
   op_id = GNUNET_ntohll (msg->operation_id);
@@ -955,7 +958,8 @@ handle_slave_config (struct GNUNET_TESTBED_Controller *c,
   }
   opc->state = OPC_STATE_FINISHED;
   GNUNET_TESTBED_remove_opc_ (opc->c, opc);
-  if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) &&
+  mask = 1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED;
+  if ((0 != (mask & c->event_mask)) &&
       (NULL != c->cc))
   {
     opc->data = GNUNET_TESTBED_extract_config_ (&msg->header);
@@ -1436,9 +1440,10 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
                                    GNUNET_TESTBED_ControllerCallback cc,
                                    void *cc_cls)
 {
-  struct GNUNET_TESTBED_Controller *c;
+  struct GNUNET_TESTBED_Controller *controller;
   struct GNUNET_TESTBED_InitMessage *msg;
   const struct GNUNET_CONFIGURATION_Handle *cfg;
+  const char *controller_hostname;
   unsigned long long max_parallel_operations;
   unsigned long long max_parallel_service_connections;
   unsigned long long max_parallel_topology_config_operations;
@@ -1468,35 +1473,44 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host,
     GNUNET_break (0);
     return NULL;
   }
-  c = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Controller));
-  c->cc = cc;
-  c->cc_cls = cc_cls;
-  c->event_mask = event_mask;
-  c->cfg = GNUNET_CONFIGURATION_dup (cfg);
-  c->client = GNUNET_CLIENT_connect ("testbed", c->cfg);
-  if (NULL == c->client)
+  controller = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Controller));
+  controller->cc = cc;
+  controller->cc_cls = cc_cls;
+  controller->event_mask = event_mask;
+  controller->cfg = GNUNET_CONFIGURATION_dup (cfg);
+  controller->client = GNUNET_CLIENT_connect ("testbed", controller->cfg);
+  if (NULL == controller->client)
   {
-    GNUNET_TESTBED_controller_disconnect (c);
+    GNUNET_TESTBED_controller_disconnect (controller);
     return NULL;
   }
-  GNUNET_TESTBED_mark_host_registered_at_ (host, c);
-  c->host = host;
-  c->opq_parallel_operations =
+  GNUNET_TESTBED_mark_host_registered_at_ (host, controller);
+  controller->host = host;
+  controller->opq_parallel_operations =
       GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
                                               max_parallel_operations);
-  c->opq_parallel_service_connections =
+  controller->opq_parallel_service_connections =
       GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
                                               max_parallel_service_connections);
-  c->opq_parallel_topology_config_operations =
+  controller->opq_parallel_topology_config_operations =
       GNUNET_TESTBED_operation_queue_create_ ((unsigned int)
                                               max_parallel_topology_config_operations);
-  msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage));
+  controller_hostname = GNUNET_TESTBED_host_get_hostname (host);
+  if (NULL == controller_hostname)
+    controller_hostname = "127.0.0.1";
+  msg =
+      GNUNET_malloc (sizeof (struct GNUNET_TESTBED_InitMessage) +
+                     strlen (controller_hostname) + 1);
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_INIT);
-  msg->header.size = htons (sizeof (struct GNUNET_TESTBED_InitMessage));
+  msg->header.size =
+      htons (sizeof (struct GNUNET_TESTBED_InitMessage) +
+             strlen (controller_hostname) + 1);
   msg->host_id = htonl (GNUNET_TESTBED_host_get_id_ (host));
-  msg->event_mask = GNUNET_htonll (c->event_mask);
-  GNUNET_TESTBED_queue_message_ (c, &msg->header);
-  return c;
+  msg->event_mask = GNUNET_htonll (controller->event_mask);
+  strcpy ((char *) &msg[1], controller_hostname);
+  GNUNET_TESTBED_queue_message_ (controller,
+                                 (struct GNUNET_MessageHeader *) msg);
+  return controller;
 }
 
 
@@ -1518,9 +1532,9 @@ opc_free_iterator (void *cls, uint32_t key, void *value)
 
   GNUNET_assert (NULL != opc);
   GNUNET_break (0);
-  GNUNET_free (opc);
   GNUNET_assert (GNUNET_YES == 
                  GNUNET_CONTAINER_multihashmap32_remove (map, key, value));
+  GNUNET_free (opc);
   return GNUNET_YES;
 }