stuff
authorChristian Grothoff <christian@grothoff.org>
Sun, 7 Aug 2011 14:29:39 +0000 (14:29 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 7 Aug 2011 14:29:39 +0000 (14:29 +0000)
src/transport/gnunet-service-transport_neighbours.c
src/transport/gnunet-service-transport_validation.c

index db2a40a70ed1d55d3afdecb0cad9a0f312db014f..a8302bc569131a6797e9d77c7e73b0dd499ad848 100644 (file)
@@ -321,8 +321,12 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
 {
   struct MessageQueue *mq;
 
-  disconnect_notify_cb (callback_cls,
-                       &n->id);
+  if (n->is_connected)
+    {
+      disconnect_notify_cb (callback_cls,
+                           &n->id);
+      n->is_connected = GNUNET_NO;
+    }
   GNUNET_assert (GNUNET_YES ==
                 GNUNET_CONTAINER_multihashmap_remove (neighbours,
                                                       &n->id.hashPubKey,
@@ -666,6 +670,23 @@ GST_neighbours_iterate (GST_NeighbourIterator cb,
 }
 
 
+/**
+ * Peer has been idle for too long. Disconnect.
+ *
+ * @param cls the 'struct NeighbourMapEntry' of the neighbour that went idle
+ * @param tc scheduler context
+ */
+static void
+neighbour_idle_timeout_task (void *cls,
+                            const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct NeighbourMapEntry *n = cls;
+
+  n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+  disconnect_neighbour (n);
+}
+
+
 /**
  * We have received a CONNECT.  Set the peer to connected.
  *
@@ -697,7 +718,7 @@ GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender,
     {
       GNUNET_break (0);
       return GNUNET_SYSERR;
-    }
+    } 
   n = lookup_neighbour (sender);
   if ( (NULL != n) ||
        (n->is_connected == GNUNET_YES) )
@@ -745,7 +766,13 @@ GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender,
       // FIXME: ATS: switch session!?
       // n->session = session;
     }
-  n->is_connected = GNUNET_YES;
+  n->peer_timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+  if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
+    GNUNET_SCHEDULER_cancel (n->timeout_task);
+  n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+                                                 &neighbour_idle_timeout_task,
+                                                 n);
+  n->is_connected = GNUNET_YES;  
   connect_notify_cb (callback_cls,
                     sender,
                     n->ats,
index db6f03dc594ee67225e3090c1a3c8971bcef91b1..76edf189150289f9479a64d8b260a2937af4d745 100644 (file)
@@ -32,6 +32,7 @@
 #include "gnunet_peerinfo_service.h"
 #include "gnunet_signatures.h"
 
+// TODO: send our HELLO with the PING!
 
 /**
  * How long is a PONG signature valid?  We'll recycle a signature until