-skeletons for transport-ng
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet_connection.c
index 54b7561edfd12518ed53ee6e01c039605193aaaa..188041feb235a536aa65c0f6e826b45c33bff3a5 100644 (file)
@@ -463,20 +463,6 @@ connection_get (const struct GNUNET_CADET_Hash *cid)
 }
 
 
-/**
- * Mark a connection as "destroyed", to send all pending traffic and freeing
- * all associated resources, without accepting new status changes on it.
- *
- * @param c Connection to mark as destroyed.
- */
-static void
-mark_destroyed (struct CadetConnection *c)
-{
-  c->destroy = GNUNET_YES;
-  connection_change_state (c, CADET_CONNECTION_DESTROYED);
-}
-
-
 /**
  * Change the connection state. Cannot change a connection marked as destroyed.
  *
@@ -501,6 +487,20 @@ connection_change_state (struct CadetConnection* c,
 }
 
 
+/**
+ * Mark a connection as "destroyed", to send all pending traffic and freeing
+ * all associated resources, without accepting new status changes on it.
+ *
+ * @param c Connection to mark as destroyed.
+ */
+static void
+mark_destroyed (struct CadetConnection *c)
+{
+  c->destroy = GNUNET_YES;
+  connection_change_state (c, CADET_CONNECTION_DESTROYED);
+}
+
+
 /**
  * Callback called when a queued ACK message is sent.
  *
@@ -1053,6 +1053,7 @@ send_broken_unknown (const struct GNUNET_CADET_Hash *connection_id,
                      const struct GNUNET_PeerIdentity *peer_id)
 {
   struct GNUNET_CADET_ConnectionBroken *msg;
+  struct CadetPeerQueue *q;
   struct CadetPeer *neighbor;
 
   GCC_check_connections ();
@@ -1070,10 +1071,12 @@ send_broken_unknown (const struct GNUNET_CADET_Hash *connection_id,
     memset (&msg->peer2, 0, sizeof (msg->peer2));
   neighbor = GCP_get (peer_id, GNUNET_NO); /* We MUST know neighbor. */
   GNUNET_assert (NULL != neighbor);
-  GCP_queue_add (neighbor, msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN,
-                 UINT16_MAX, 2, sizeof (struct GNUNET_CADET_ConnectionBroken),
-                 NULL, GNUNET_SYSERR, /* connection, fwd */
-                 NULL, NULL); /* continuation */
+  q = GCP_queue_add (neighbor, msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN,
+                     UINT16_MAX, 2,
+                     sizeof (struct GNUNET_CADET_ConnectionBroken),
+                     NULL, GNUNET_SYSERR, /* connection, fwd */
+                     NULL, NULL); /* continuation */
+  GNUNET_assert (NULL != q);
   GCC_check_connections ();
 }
 
@@ -1189,11 +1192,10 @@ connection_maintain (struct CadetConnection *c, int fwd)
  *
  * @param c Connection to keep alive.
  * @param fwd Direction.
- * @param shutdown Are we shutting down? (Don't send traffic)
- *                 Non-zero value for true, not necessarily GNUNET_YES.
  */
 static void
-connection_keepalive (struct CadetConnection *c, int fwd, int shutdown)
+connection_keepalive (struct CadetConnection *c,
+                     int fwd)
 {
   GCC_check_connections ();
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1204,10 +1206,6 @@ connection_keepalive (struct CadetConnection *c, int fwd, int shutdown)
     c->fwd_maintenance_task = NULL;
   else
     c->bck_maintenance_task = NULL;
-
-  if (GNUNET_NO != shutdown)
-    return;
-
   connection_maintain (c, fwd);
   GCC_check_connections ();
   /* Next execution will be scheduled by message_sent or _maintain*/
@@ -1218,16 +1216,15 @@ connection_keepalive (struct CadetConnection *c, int fwd, int shutdown)
  * Keep the connection alive in the FWD direction.
  *
  * @param cls Closure (connection to keepalive).
- * @param tc TaskContext.
  */
 static void
-connection_fwd_keepalive (void *cls,
-                          const struct GNUNET_SCHEDULER_TaskContext *tc)
+connection_fwd_keepalive (void *cls)
 {
+  struct CadetConnection *c = cls;
+
   GCC_check_connections ();
-  connection_keepalive ((struct CadetConnection *) cls,
-                        GNUNET_YES,
-                        tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN);
+  connection_keepalive (c,
+                        GNUNET_YES);
   GCC_check_connections ();
 }
 
@@ -1236,16 +1233,15 @@ connection_fwd_keepalive (void *cls,
  * Keep the connection alive in the BCK direction.
  *
  * @param cls Closure (connection to keepalive).
- * @param tc TaskContext.
  */
 static void
-connection_bck_keepalive (void *cls,
-                          const struct GNUNET_SCHEDULER_TaskContext *tc)
+connection_bck_keepalive (void *cls)
 {
+  struct CadetConnection *c = cls;
+
   GCC_check_connections ();
-  connection_keepalive ((struct CadetConnection *) cls,
-                        GNUNET_NO,
-                        tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN);
+  connection_keepalive (c,
+                        GNUNET_NO);
   GCC_check_connections ();
 }
 
@@ -1397,11 +1393,9 @@ connection_cancel_queues (struct CadetConnection *c,
  * possibly due to a missed ACK. Poll the neighbor about its ACK status.
  *
  * @param cls Closure (poll ctx).
- * @param tc TaskContext.
  */
 static void
-connection_poll (void *cls,
-                 const struct GNUNET_SCHEDULER_TaskContext *tc);
+connection_poll (void *cls);
 
 
 /**
@@ -1450,10 +1444,9 @@ poll_sent (void *cls,
  * possibly due to a missed ACK. Poll the neighbor about its ACK status.
  *
  * @param cls Closure (poll ctx).
- * @param tc TaskContext.
  */
 static void
-connection_poll (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+connection_poll (void *cls)
 {
   struct CadetFlowControl *fc = cls;
   struct GNUNET_CADET_Poll msg;
@@ -1462,11 +1455,6 @@ connection_poll (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 
   fc->poll_task = NULL;
   GCC_check_connections ();
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-  {
-    return;
-  }
-
   c = fc->c;
   fwd = fc == &c->fwd_fc;
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Polling connection %s %s\n",
@@ -1561,7 +1549,7 @@ connection_timeout (struct CadetConnection *c, int fwd)
   }
 
   /* If dest, salvage queued traffic. */
-  if (GCC_is_origin (c, !fwd))
+  if (GCC_is_terminal (c, fwd))
   {
     const struct GNUNET_PeerIdentity *next_hop;
 
@@ -1583,17 +1571,13 @@ connection_timeout (struct CadetConnection *c, int fwd)
  * Destroys connection if called.
  *
  * @param cls Closure (connection to destroy).
- * @param tc TaskContext.
  */
 static void
-connection_fwd_timeout (void *cls,
-                        const struct GNUNET_SCHEDULER_TaskContext *tc)
+connection_fwd_timeout (void *cls)
 {
   struct CadetConnection *c = cls;
 
   c->fwd_maintenance_task = NULL;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   GCC_check_connections ();
   connection_timeout (c, GNUNET_YES);
   GCC_check_connections ();
@@ -1605,17 +1589,13 @@ connection_fwd_timeout (void *cls,
  * Destroys connection if called.
  *
  * @param cls Closure (connection to destroy).
- * @param tc TaskContext
  */
 static void
-connection_bck_timeout (void *cls,
-                        const struct GNUNET_SCHEDULER_TaskContext *tc)
+connection_bck_timeout (void *cls)
 {
   struct CadetConnection *c = cls;
 
   c->bck_maintenance_task = NULL;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
   GCC_check_connections ();
   connection_timeout (c, GNUNET_NO);
   GCC_check_connections ();
@@ -1758,17 +1738,13 @@ does_connection_exist (struct CadetConnection *conn)
  * connection with the same path, and destroy one if so.
  *
  * @param cls Closure (connection to check).
- * @param tc Task context.
  */
 static void
-check_duplicates (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+check_duplicates (void *cls)
 {
   struct CadetConnection *c = cls;
 
   c->check_duplicates_task = NULL;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
-
   if (GNUNET_YES == does_connection_exist (c))
   {
     GCT_debug (c->t, GNUNET_ERROR_TYPE_DEBUG);
@@ -1778,7 +1754,6 @@ check_duplicates (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 }
 
 
-
 /**
  * Wait for enough time to let any dead connections time out and check for
  * any remaining duplicates.
@@ -1792,7 +1767,6 @@ schedule_check_duplicates (struct CadetConnection *c)
 
   if (NULL != c->check_duplicates_task)
     return;
-
   delay = GNUNET_TIME_relative_multiply (refresh_connection_time, 5);
   c->check_duplicates_task = GNUNET_SCHEDULER_add_delayed (delay,
                                                            &check_duplicates,
@@ -1800,7 +1774,6 @@ schedule_check_duplicates (struct CadetConnection *c)
 }
 
 
-
 /**
  * Add the connection to the list of both neighbors.
  *
@@ -1898,7 +1871,8 @@ unregister_neighbors (struct CadetConnection *c)
  * @param disconnected Peer that disconnected.
  */
 static void
-invalidate_paths (struct CadetConnection *c, struct CadetPeer *disconnected)
+invalidate_paths (struct CadetConnection *c,
+                 struct CadetPeer *disconnected)
 {
   struct CadetPeer *peer;
   unsigned int i;