plugin datastore mysql
[oweals/gnunet.git] / src / testbed / gnunet-service-testbed_oc.c
index ff5331fe4acd9d0ac0d6d21cd0d183271344f3ae..55dd5cad944999dd33b908de568b744a415ef1e1 100644 (file)
@@ -1,6 +1,6 @@
 /*
   This file is part of GNUnet.
-  Copyright (C) 2008--2015 Christian Grothoff (and other contributing authors)
+  Copyright (C) 2008--2015 GNUnet e.V.
 
   GNUnet is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published
@@ -362,12 +362,9 @@ GST_cleanup_focc (struct ForwardedOverlayConnectContext *focc)
  * Timeout task for cancelling a forwarded overlay connect connect
  *
  * @param cls the ForwardedOverlayConnectContext
- * @param tc the task context from the scheduler
  */
 static void
-forwarded_overlay_connect_timeout (void *cls,
-                                   const struct GNUNET_SCHEDULER_TaskContext
-                                   *tc)
+forwarded_overlay_connect_timeout (void *cls)
 {
   struct ForwardedOperationContext *fopc = cls;
   struct RegisteredHostContext *rhc;
@@ -379,7 +376,7 @@ forwarded_overlay_connect_timeout (void *cls,
   LOG_DEBUG ("Overlay linking between peers %u and %u failed\n", focc->peer1,
              focc->peer2);
   GST_cleanup_focc (focc);
-  GST_forwarded_operation_timeout (fopc, tc);
+  GST_forwarded_operation_timeout (fopc);
   if (NULL != rhc->focc_dll_head)
     GST_process_next_focc (rhc);
 }
@@ -460,11 +457,25 @@ static void
 cleanup_occ_lp2c (struct LocalPeer2Context *lp2c)
 {
   if (NULL != lp2c->ohh)
+  {
     GNUNET_TRANSPORT_offer_hello_cancel (lp2c->ohh);
-  GST_connection_pool_get_handle_done (lp2c->tcc.cgh_p2_th);
-  GST_connection_pool_get_handle_done (lp2c->tcc.cgh_p2_ats);
+    lp2c->ohh = NULL;
+  }
+  if (NULL != lp2c->tcc.cgh_p2_th)
+  {
+    GST_connection_pool_get_handle_done (lp2c->tcc.cgh_p2_th);
+    lp2c->tcc.cgh_p2_th = NULL;
+  }
+  if (NULL != lp2c->tcc.cgh_p2_ats)
+  {
+    GST_connection_pool_get_handle_done (lp2c->tcc.cgh_p2_ats);
+    lp2c->tcc.cgh_p2_ats = NULL;
+  }
   if (NULL != lp2c->tcc.csh)
+  {
     GNUNET_ATS_connectivity_suggest_cancel (lp2c->tcc.csh);
+    lp2c->tcc.csh = NULL;
+  }
 }
 
 
@@ -478,11 +489,20 @@ static void
 cleanup_occ_rp2c (struct RemotePeer2Context *rp2c)
 {
   if (NULL != rp2c->opc)
+  {
     GNUNET_TESTBED_forward_operation_msg_cancel_ (rp2c->opc);
+    rp2c->opc = NULL;
+  }
   if (NULL != rp2c->ncn)
+  {
     GST_neighbour_get_connection_cancel (rp2c->ncn);
+    rp2c->ncn = NULL;
+  }
   if ( (NULL != rp2c->p2c) && (NULL != rp2c->p2n) )
+  {
     GST_neighbour_release_connection (rp2c->p2n);
+    rp2c->p2n = NULL;
+  }
 }
 
 /**
@@ -503,7 +523,8 @@ cleanup_occ (struct OverlayConnectContext *occ)
 {
   struct Peer *peer2;
 
-  LOG_DEBUG ("0x%llx: Cleaning up occ\n", occ->op_id);
+  LOG_DEBUG ("0x%llx: Cleaning up occ\n",
+             occ->op_id);
   GNUNET_free_non_null (occ->emsg);
   GNUNET_free_non_null (occ->hello);
   GNUNET_SERVER_client_drop (occ->client);
@@ -549,11 +570,9 @@ cleanup_occ (struct OverlayConnectContext *occ)
  * Task for cleaing up overlay connect context structure
  *
  * @param cls the overlay connect context
- * @param tc the task context
  */
 static void
-do_cleanup_occ (void *cls,
-                const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_cleanup_occ (void *cls)
 {
   struct OverlayConnectContext *occ = cls;
 
@@ -566,11 +585,9 @@ do_cleanup_occ (void *cls,
  * Task which will be run when overlay connect request has been timed out
  *
  * @param cls the OverlayConnectContext
- * @param tc the TaskContext
  */
 static void
-timeout_overlay_connect (void *cls,
-                         const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_overlay_connect (void *cls)
 {
   struct OverlayConnectContext *occ = cls;
 
@@ -579,11 +596,16 @@ timeout_overlay_connect (void *cls,
   /* 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); */
-  GST_send_operation_fail_msg (occ->client, occ->op_id, occ->emsg);
+  GST_send_operation_fail_msg (occ->client,
+                               occ->op_id,
+                               occ->emsg);
   cleanup_occ (occ);
 }
 
 
+/**
+ * FIXME.
+ */
 static void
 send_overlay_connect_success_msg (struct OverlayConnectContext *occ)
 {
@@ -651,10 +673,21 @@ overlay_connect_notify (void *cls,
   GNUNET_assert (NULL != occ->timeout_task);
   GNUNET_SCHEDULER_cancel (occ->timeout_task);
   occ->timeout_task = NULL;
+  switch (occ->type)
+  {
+  case OCC_TYPE_LOCAL:
+    cleanup_occ_lp2c (&occ->p2ctx.local);
+    break;
+  case OCC_TYPE_REMOTE_SLAVE:
+  case OCC_TYPE_REMOTE_LATERAL:
+    cleanup_occ_rp2c (&occ->p2ctx.remote);
+    break;
+  }
   GNUNET_free_non_null (occ->emsg);
   occ->emsg = NULL;
   send_overlay_connect_success_msg (occ);
-  occ->cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup_occ, occ);
+  occ->cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup_occ,
+                                                occ);
 }
 
 
@@ -737,30 +770,29 @@ occ_cache_get_handle_ats_rocc_cb (void *cls,
  * peer 1.
  *
  * @param cls the OverlayConnectContext
- * @param tc the TaskContext from scheduler
  */
 static void
-send_hello (void *cls,
-            const struct GNUNET_SCHEDULER_TaskContext *tc);
+send_hello (void *cls);
 
 
 /**
- * Task that is run when hello has been sent
+ * Task that is run when hello has been sent If tc->reason =
+ * #GNUNET_SCHEDULER_REASON_TIMEOUT then sending HELLO failed; if
+ * #GNUNET_SCHEDULER_REASON_READ_READY is succeeded
  *
  * @param cls the overlay connect context
- * @param tc the scheduler task context; if tc->reason =
- *          #GNUNET_SCHEDULER_REASON_TIMEOUT then sending HELLO failed; if
- *          #GNUNET_SCHEDULER_REASON_READ_READY is succeeded
  */
 static void
-occ_hello_sent_cb (void *cls,
-                   const struct GNUNET_SCHEDULER_TaskContext *tc)
+occ_hello_sent_cb (void *cls)
 {
   struct OverlayConnectContext *occ = cls;
   struct LocalPeer2Context *lp2c;
   struct Peer *peer2;
+  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
+  tc = GNUNET_SCHEDULER_get_task_context ();
   GNUNET_assert (OCC_TYPE_LOCAL == occ->type);
+  GNUNET_assert (NULL != occ->timeout_task);
   lp2c = &occ->p2ctx.local;
   lp2c->ohh = NULL;
 
@@ -840,19 +872,16 @@ send_hello_thru_rocc (struct OverlayConnectContext *occ)
  * send_hello_thru_rocc()
  *
  * @param cls the OverlayConnectContext
- * @param tc the TaskContext from scheduler
  */
 static void
-send_hello (void *cls,
-            const struct GNUNET_SCHEDULER_TaskContext *tc)
+send_hello (void *cls)
 {
   struct OverlayConnectContext *occ = cls;
   struct LocalPeer2Context *lp2c;
   char *other_peer_str;
 
   occ->send_hello_task = NULL;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
+  GNUNET_assert (NULL != occ->timeout_task);
   GNUNET_assert (NULL != occ->hello);
   if (OCC_TYPE_LOCAL != occ->type)
   {
@@ -1610,11 +1639,9 @@ cleanup_rocc (struct RemoteOverlayConnectCtx *rocc)
  * Task to timeout rocc and cleanit up
  *
  * @param cls the RemoteOverlayConnectCtx
- * @param tc the TaskContext from scheduler
  */
 static void
-timeout_rocc_task (void *cls,
-                   const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_rocc_task (void *cls)
 {
   struct RemoteOverlayConnectCtx *rocc = cls;
 
@@ -1656,26 +1683,23 @@ cache_transport_peer_connect_notify (void *cls,
  * whose identity is in RemoteOverlayConnectCtx
  *
  * @param cls the RemoteOverlayConnectCtx
- * @param tc the TaskContext from scheduler
  */
 static void
-attempt_connect_task (void *cls,
-                      const struct GNUNET_SCHEDULER_TaskContext *tc);
+attempt_connect_task (void *cls);
 
 
 /**
- * Task that is run when hello has been sent
+ * Task that is run when hello has been sent If tc->reason =
+ * #GNUNET_SCHEDULER_REASON_TIMEOUT then sending HELLO failed; if
+ * #GNUNET_SCHEDULER_REASON_READ_READY is succeeded
  *
  * @param cls the overlay connect context
- * @param tc the scheduler task context; if tc->reason =
- *          #GNUNET_SCHEDULER_REASON_TIMEOUT then sending HELLO failed; if
- *          #GNUNET_SCHEDULER_REASON_READ_READY is succeeded
  */
 static void
-rocc_hello_sent_cb (void *cls,
-                    const struct GNUNET_SCHEDULER_TaskContext *tc)
+rocc_hello_sent_cb (void *cls)
 {
   struct RemoteOverlayConnectCtx *rocc = cls;
+  const struct GNUNET_SCHEDULER_TaskContext *tc;
 
   rocc->ohh = NULL;
   GNUNET_assert (NULL == rocc->attempt_connect_task_id);
@@ -1683,6 +1707,7 @@ rocc_hello_sent_cb (void *cls,
              rocc->op_id,
              GNUNET_i2s (&rocc->a_id),
              rocc->peer->id);
+  tc = GNUNET_SCHEDULER_get_task_context ();
   if (GNUNET_SCHEDULER_REASON_TIMEOUT == tc->reason)
   {
     GNUNET_break (0);
@@ -1712,11 +1737,9 @@ rocc_hello_sent_cb (void *cls,
  * whose identity is in RemoteOverlayConnectCtx
  *
  * @param cls the RemoteOverlayConnectCtx
- * @param tc the TaskContext from scheduler
  */
 static void
-attempt_connect_task (void *cls,
-                      const struct GNUNET_SCHEDULER_TaskContext *tc)
+attempt_connect_task (void *cls)
 {
   struct RemoteOverlayConnectCtx *rocc = cls;