-more datacache integration work
[oweals/gnunet.git] / src / testbed / gnunet-service-testbed_oc.c
index 5ea6e48e1302432b36c7188e0bd775288dfdd6bc..1f5451d494219bfbec5383283cac57f177bbe4f6 100644 (file)
@@ -1,6 +1,6 @@
 /*
   This file is part of GNUnet.
-  (C) 2008--2013 Christian Grothoff (and other contributing authors)
+  Copyright (C) 2008--2013 Christian Grothoff (and other contributing authors)
 
   GNUnet is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published
@@ -65,7 +65,7 @@ struct TryConnectContext
   /**
    * The task handle
    */
-  GNUNET_SCHEDULER_TaskIdentifier task;
+  struct GNUNET_SCHEDULER_Task * task;
 
   /**
    * The id of the operation which is resposible for this context
@@ -250,17 +250,17 @@ struct OverlayConnectContext
    * The id of the task for sending HELLO of peer 2 to peer 1 and ask peer 1 to
    * connect to peer 2
    */
-  GNUNET_SCHEDULER_TaskIdentifier send_hello_task;
+  struct GNUNET_SCHEDULER_Task * send_hello_task;
 
   /**
    * The id of the overlay connect timeout task
    */
-  GNUNET_SCHEDULER_TaskIdentifier timeout_task;
+  struct GNUNET_SCHEDULER_Task * timeout_task;
 
   /**
    * The id of the cleanup task
    */
-  GNUNET_SCHEDULER_TaskIdentifier cleanup_task;
+  struct GNUNET_SCHEDULER_Task * cleanup_task;
 
   /**
    * The type of this context information
@@ -321,12 +321,12 @@ struct RemoteOverlayConnectCtx
   /**
    * Task for offering HELLO of A to B and doing try_connect
    */
-  GNUNET_SCHEDULER_TaskIdentifier attempt_connect_task_id;
+  struct GNUNET_SCHEDULER_Task * attempt_connect_task_id;
 
   /**
    * Task to timeout RequestOverlayConnect
    */
-  GNUNET_SCHEDULER_TaskIdentifier timeout_rocc_task_id;
+  struct GNUNET_SCHEDULER_Task * timeout_rocc_task_id;
 
   /**
    * The id of the operation responsible for creating this context
@@ -444,7 +444,7 @@ GST_process_next_focc (struct RegisteredHostContext *rhc)
   peer = GST_peer_list[focc->peer1];
   GNUNET_assert (GNUNET_YES == peer->is_remote);
   GNUNET_assert (NULL != (slave = peer->details.remote.slave));
-  fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
+  fopc = GNUNET_new (struct ForwardedOperationContext);
   GNUNET_SERVER_client_keep (focc->client);
   fopc->client = focc->client;
   fopc->operation_id = focc->operation_id;
@@ -478,7 +478,7 @@ cleanup_occ_lp2c (struct LocalPeer2Context *lp2c)
     GST_connection_pool_get_handle_done (lp2c->tcc.cgh_th);
   if (NULL != lp2c->tcc.tch)
     GNUNET_TRANSPORT_try_connect_cancel (lp2c->tcc.tch);
-  if (GNUNET_SCHEDULER_NO_TASK != lp2c->tcc.task)
+  if (NULL != lp2c->tcc.task)
     GNUNET_SCHEDULER_cancel (lp2c->tcc.task);
 }
 
@@ -523,11 +523,11 @@ cleanup_occ (struct OverlayConnectContext *occ)
   GNUNET_free_non_null (occ->emsg);
   GNUNET_free_non_null (occ->hello);
   GNUNET_SERVER_client_drop (occ->client);
-  if (GNUNET_SCHEDULER_NO_TASK != occ->send_hello_task)
+  if (NULL != occ->send_hello_task)
     GNUNET_SCHEDULER_cancel (occ->send_hello_task);
-  if (GNUNET_SCHEDULER_NO_TASK != occ->cleanup_task)
+  if (NULL != occ->cleanup_task)
     GNUNET_SCHEDULER_cancel (occ->cleanup_task);
-  if (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task)
+  if (NULL != occ->timeout_task)
     GNUNET_SCHEDULER_cancel (occ->timeout_task);
   if (NULL != occ->cgh_ch)
     GST_connection_pool_get_handle_done (occ->cgh_ch);
@@ -571,7 +571,7 @@ do_cleanup_occ (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct OverlayConnectContext *occ = cls;
 
-  occ->cleanup_task = GNUNET_SCHEDULER_NO_TASK;
+  occ->cleanup_task = NULL;
   cleanup_occ (occ);
 }
 
@@ -588,8 +588,8 @@ timeout_overlay_connect (void *cls,
 {
   struct OverlayConnectContext *occ = cls;
 
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task);
-  occ->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+  GNUNET_assert (NULL != occ->timeout_task);
+  occ->timeout_task = NULL;
   /* LOG (GNUNET_ERROR_TYPE_WARNING, */
   /*      "0x%llx: Timeout while connecting peers %u and %u: %s\n", occ->op_id, */
   /*      occ->peer->id, occ->other_peer_id, occ->emsg); */
@@ -605,7 +605,7 @@ send_overlay_connect_success_msg (struct OverlayConnectContext *occ)
 
   LOG_DEBUG ("0x%llx: Peers connected - Sending overlay connect success\n",
              occ->op_id);
-  msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
+  msg = GNUNET_new (struct GNUNET_TESTBED_ConnectionEventMessage);
   msg->header.size =
       htons (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT);
@@ -653,21 +653,21 @@ overlay_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer)
   LOG_DEBUG ("0x%llx: Peer %4s connected to peer %4s\n", occ->op_id,
              other_peer_str, GNUNET_i2s (&occ->peer_identity));
   GNUNET_free (other_peer_str);
-  if (GNUNET_SCHEDULER_NO_TASK != occ->send_hello_task)
+  if (NULL != occ->send_hello_task)
   {
     GNUNET_SCHEDULER_cancel (occ->send_hello_task);
-    occ->send_hello_task = GNUNET_SCHEDULER_NO_TASK;
+    occ->send_hello_task = NULL;
   }
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task);
+  GNUNET_assert (NULL != occ->timeout_task);
   GNUNET_SCHEDULER_cancel (occ->timeout_task);
-  occ->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+  occ->timeout_task = NULL;
   if (OCC_TYPE_LOCAL == occ->type)
   {
     lp2c = &occ->p2ctx.local;
-    if (GNUNET_SCHEDULER_NO_TASK != lp2c->tcc.task)
+    if (NULL != lp2c->tcc.task)
     {
       GNUNET_SCHEDULER_cancel (lp2c->tcc.task);
-      lp2c->tcc.task = GNUNET_SCHEDULER_NO_TASK;
+      lp2c->tcc.task = NULL;
     }
   }
   GNUNET_free_non_null (occ->emsg);
@@ -700,7 +700,7 @@ try_connect_cb (void *cls, const int result)
   struct TryConnectContext *tcc = cls;
 
   tcc->tch = NULL;
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == tcc->task);
+  GNUNET_assert (NULL == tcc->task);
   tcc->task =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                     (GNUNET_TIME_UNIT_MILLISECONDS,
@@ -720,7 +720,7 @@ try_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct TryConnectContext *tcc = cls;
 
-  tcc->task = GNUNET_SCHEDULER_NO_TASK;
+  tcc->task = NULL;
   if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
     return;
   GNUNET_assert (NULL == tcc->tch);
@@ -762,7 +762,7 @@ occ_hello_sent_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GNUNET_assert (OCC_TYPE_LOCAL == occ->type);
   lp2c = &occ->p2ctx.local;
   lp2c->ohh = NULL;
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == occ->send_hello_task);
+  GNUNET_assert (NULL == occ->send_hello_task);
   if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason)
   {
     GNUNET_free_non_null (occ->emsg);
@@ -839,7 +839,7 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct LocalPeer2Context *lp2c;
   char *other_peer_str;
 
-  occ->send_hello_task = GNUNET_SCHEDULER_NO_TASK;
+  occ->send_hello_task = NULL;
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
     return;
   GNUNET_assert (NULL != occ->hello);
@@ -1048,7 +1048,7 @@ occ_cache_get_handle_core_cb (void *cls, struct GNUNET_CORE_Handle *ch,
   struct OverlayConnectContext *occ = cls;
   const struct GNUNET_MessageHeader *hello;
 
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task);
+  GNUNET_assert (NULL != occ->timeout_task);
   GNUNET_free_non_null (occ->emsg);
   if ((NULL == ch) || (NULL == my_identity))
   {
@@ -1066,7 +1066,7 @@ occ_cache_get_handle_core_cb (void *cls, struct GNUNET_CORE_Handle *ch,
   {
     LOG_DEBUG ("0x%llx: Target peer already connected\n", occ->op_id);
     GNUNET_SCHEDULER_cancel (occ->timeout_task);
-    occ->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+    occ->timeout_task = NULL;
     send_overlay_connect_success_msg (occ);
     occ->cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup_occ, occ);
     return;
@@ -1114,7 +1114,7 @@ overlay_connect_get_config (void *cls, const struct GNUNET_MessageHeader *msg)
   GNUNET_assert (OCC_TYPE_LOCAL != occ->type);
   rp2c = &occ->p2ctx.remote;
   rp2c->opc = NULL;
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task);
+  GNUNET_assert (NULL != occ->timeout_task);
   if (GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION != ntohs (msg->type))
   {
     GNUNET_SCHEDULER_cancel (occ->timeout_task);
@@ -1223,7 +1223,7 @@ register_host (struct Slave *slave, struct GNUNET_TESTBED_Host *host)
   struct GNUNET_HashCode hash;
   struct RegisteredHostContext *rhc;
 
-  rhc = GNUNET_malloc (sizeof (struct RegisteredHostContext));
+  rhc = GNUNET_new (struct RegisteredHostContext);
   rhc->reg_host = host;
   rhc->host = GST_host_list[slave->host_id];
   GNUNET_assert (NULL != rhc->reg_host);
@@ -1304,7 +1304,7 @@ forward_overlay_connect (const struct GNUNET_TESTBED_OverlayConnectMessage *msg,
                                     GST_host_list[peer2_host_id])))
   {
     LOG_DEBUG ("Queueing forwarding FOCC for connecting peers %u and %u\n", p1, p2);
-    focc = GNUNET_malloc (sizeof (struct ForwardedOverlayConnectContext));
+    focc = GNUNET_new (struct ForwardedOverlayConnectContext);
     focc->peer1 = p1;
     focc->peer2 = p2;
     focc->peer2_host_id = peer2_host_id;
@@ -1319,7 +1319,7 @@ forward_overlay_connect (const struct GNUNET_TESTBED_OverlayConnectMessage *msg,
 
  forward:
   LOG_DEBUG ("Forwarding without FOCC for connecting peers %u and %u\n", p1, p2);
-  fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
+  fopc = GNUNET_new (struct ForwardedOperationContext);
   GNUNET_SERVER_client_keep (client);
   fopc->client = client;
   fopc->operation_id = op_id;
@@ -1429,7 +1429,7 @@ GST_handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
     return;
   }
   p2n = NULL;
-  occ = GNUNET_malloc (sizeof (struct OverlayConnectContext));
+  occ = GNUNET_new (struct OverlayConnectContext);
   occ->type = OCC_TYPE_LOCAL;
   if (!VALID_PEER_ID (p2))       /* May be peer2 is on a another controller */
   {
@@ -1462,7 +1462,7 @@ GST_handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
   GST_peer_list[p1]->reference_cnt++;
   occ->peer = GST_peer_list[p1];
   occ->op_id = operation_id;
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == occ->timeout_task);
+  GNUNET_assert (NULL == occ->timeout_task);
   occ->timeout_task =
       GNUNET_SCHEDULER_add_delayed (GST_timeout, &timeout_overlay_connect, occ);
   switch (occ->type)
@@ -1508,15 +1508,15 @@ static void
 cleanup_rocc (struct RemoteOverlayConnectCtx *rocc)
 {
   LOG_DEBUG ("0x%llx: Cleaning up rocc\n", rocc->op_id);
-  if (GNUNET_SCHEDULER_NO_TASK != rocc->attempt_connect_task_id)
+  if (NULL != rocc->attempt_connect_task_id)
     GNUNET_SCHEDULER_cancel (rocc->attempt_connect_task_id);
-  if (GNUNET_SCHEDULER_NO_TASK != rocc->timeout_rocc_task_id)
+  if (NULL != rocc->timeout_rocc_task_id)
     GNUNET_SCHEDULER_cancel (rocc->timeout_rocc_task_id);
   if (NULL != rocc->ohh)
     GNUNET_TRANSPORT_offer_hello_cancel (rocc->ohh);
   if (NULL != rocc->tcc.tch)
     GNUNET_TRANSPORT_try_connect_cancel (rocc->tcc.tch);
-  if (GNUNET_SCHEDULER_NO_TASK != rocc->tcc.task)
+  if (NULL != rocc->tcc.task)
     GNUNET_SCHEDULER_cancel (rocc->tcc.task);
   GST_connection_pool_get_handle_done (rocc->tcc.cgh_th);
   GNUNET_assert (rocc->peer->reference_cnt > 0);
@@ -1541,8 +1541,8 @@ timeout_rocc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct RemoteOverlayConnectCtx *rocc = cls;
 
-  GNUNET_assert (rocc->timeout_rocc_task_id != GNUNET_SCHEDULER_NO_TASK);
-  rocc->timeout_rocc_task_id = GNUNET_SCHEDULER_NO_TASK;
+  GNUNET_assert (rocc->timeout_rocc_task_id != NULL);
+  rocc->timeout_rocc_task_id = NULL;
   LOG_DEBUG ("0x%llx: rocc timed out\n", rocc->op_id);
   cleanup_rocc (rocc);
 }
@@ -1596,7 +1596,7 @@ rocc_hello_sent_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct RemoteOverlayConnectCtx *rocc = cls;
 
   rocc->ohh = NULL;
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == rocc->attempt_connect_task_id);
+  GNUNET_assert (NULL == rocc->attempt_connect_task_id);
   LOG_DEBUG ("0x%llx: HELLO of peer %4s sent to local peer with id: %u\n",
              rocc->op_id, GNUNET_i2s (&rocc->a_id), rocc->peer->id);
   if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason)
@@ -1627,8 +1627,8 @@ attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct RemoteOverlayConnectCtx *rocc = cls;
 
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != rocc->attempt_connect_task_id);
-  rocc->attempt_connect_task_id = GNUNET_SCHEDULER_NO_TASK;
+  GNUNET_assert (NULL != rocc->attempt_connect_task_id);
+  rocc->attempt_connect_task_id = NULL;
   LOG_DEBUG ("0x%llx: Offering HELLO of peer %4s to local peer with id: %u\n",
              rocc->op_id, GNUNET_i2s (&rocc->a_id), rocc->peer->id);
   rocc->ohh =
@@ -1743,7 +1743,7 @@ GST_handle_remote_overlay_connect (void *cls,
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
     return;
   }
-  rocc = GNUNET_malloc (sizeof (struct RemoteOverlayConnectCtx));
+  rocc = GNUNET_new (struct RemoteOverlayConnectCtx);
   rocc->op_id = GNUNET_ntohll (msg->operation_id);
   GNUNET_CONTAINER_DLL_insert_tail (roccq_head, roccq_tail, rocc);
   memcpy (&rocc->a_id, &msg->peer_identity,