gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r35920 - gnunet/src/cadet


From: gnunet
Subject: [GNUnet-SVN] r35920 - gnunet/src/cadet
Date: Wed, 10 Jun 2015 14:08:20 +0200

Author: bartpolot
Date: 2015-06-10 14:08:20 +0200 (Wed, 10 Jun 2015)
New Revision: 35920

Modified:
   gnunet/src/cadet/gnunet-service-cadet_connection.c
Log:
- refactor connection timeout into one implementation
- always send CONNECTION_BROKEN to alert of the timeout

Modified: gnunet/src/cadet/gnunet-service-cadet_connection.c
===================================================================
--- gnunet/src/cadet/gnunet-service-cadet_connection.c  2015-06-10 12:08:19 UTC 
(rev 35919)
+++ gnunet/src/cadet/gnunet-service-cadet_connection.c  2015-06-10 12:08:20 UTC 
(rev 35920)
@@ -1375,28 +1375,28 @@
 
 
 /**
- * Timeout function due to lack of keepalive/traffic from the owner.
+ * Generic connection timeout implementation.
+ *
+ * Timeout function due to lack of keepalive/traffic from an endpoint.
  * Destroys connection if called.
  *
- * @param cls Closure (connection to destroy).
- * @param tc TaskContext.
+ * @param c Connection to destroy.
+ * @param fwd Was the timeout from the origin? (FWD timeout)
  */
 static void
-connection_fwd_timeout (void *cls,
-                        const struct GNUNET_SCHEDULER_TaskContext *tc)
+connection_timeout (struct CadetConnection *c, int fwd)
 {
-  struct CadetConnection *c = cls;
+  struct CadetFlowControl *reverse_fc;
 
-  c->fwd_maintenance_task = NULL;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
+  reverse_fc = fwd ? c->bck_fc : c->fwd_fc;
 
   LOG (GNUNET_ERROR_TYPE_INFO,
-       "Connection %s FWD timed out. Destroying.\n",
-       GCC_2s (c));
+       "Connection %s %s timed out. Destroying.\n",
+       GCC_2s (c),
+       GC_f2s (fwd));
   GCC_debug (c, GNUNET_ERROR_TYPE_DEBUG);
 
-  if (GCC_is_origin (c, GNUNET_YES)) /* If local, leave. */
+  if (GCC_is_origin (c, fwd)) /* Loopback? Something is wrong! */
   {
     GNUNET_break (0);
     return;
@@ -1403,11 +1403,14 @@
   }
 
   /* If dest, salvage queued traffic. */
-  if (GCC_is_origin (c, GNUNET_NO) && 0 < c->bck_fc.queue_n)
+  if (GCC_is_origin (c, !fwd))
   {
-    send_broken_unknown (&c->id, &my_full_id, NULL,
-                         GCP_get_id( get_prev_hop (c)));
-    resend_messages_and_destroy (c, GNUNET_NO);
+    struct GNUNET_PeerIdentity *next_hop;
+
+    next_hop = fwd ? get_prev_hop (c) : get_next_hop (c);
+    send_broken_unknown (&c->id, &my_full_id, NULL, GCP_get_id (next_hop));
+    if (0 < reverse_fc->queue_n)
+      resend_messages_and_destroy (c, !fwd);
     return;
   }
 
@@ -1416,11 +1419,31 @@
 
 
 /**
+ * Timeout function due to lack of keepalive/traffic from the owner.
+ * 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)
+{
+  struct CadetConnection *c = cls;
+  struct CadetFlowControl *fc;
+
+  c->fwd_maintenance_task = NULL;
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+    return;
+
+  connection_timeout (c, GNUNET_YES);
+}
+
+
+/**
  * Timeout function due to lack of keepalive/traffic from the destination.
  * Destroys connection if called.
  *
- * FIXME refactor and merge with connection_fwd_timeout.
- *
  * @param cls Closure (connection to destroy).
  * @param tc TaskContext
  */
@@ -1434,25 +1457,7 @@
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
     return;
 
-  LOG (GNUNET_ERROR_TYPE_INFO, "Connection %s BCK timed out. Destroying.\n",
-       GCC_2s (c));
-
-  if (GCC_is_origin (c, GNUNET_NO)) /* If local, leave. */
-  {
-    GNUNET_break (0);
-    return;
-  }
-
-  /* If dest, salvage queued traffic. */
-  if (GCC_is_origin (c, GNUNET_YES) && 0 < c->fwd_fc.queue_n)
-  {
-    send_broken_unknown (&c->id, &my_full_id, NULL,
-                         GCP_get_id (get_next_hop (c)));
-    resend_messages_and_destroy (c, GNUNET_YES);
-    return;
-  }
-
-  GCC_destroy (c);
+  connection_timeout (c, GNUNET_NO);
 }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]