gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r10044 - gnunet/src/topology


From: gnunet
Subject: [GNUnet-SVN] r10044 - gnunet/src/topology
Date: Mon, 18 Jan 2010 11:21:20 +0100

Author: grothoff
Date: 2010-01-18 11:21:20 +0100 (Mon, 18 Jan 2010)
New Revision: 10044

Modified:
   gnunet/src/topology/gnunet-daemon-topology.c
Log:
cleaner shutdown

Modified: gnunet/src/topology/gnunet-daemon-topology.c
===================================================================
--- gnunet/src/topology/gnunet-daemon-topology.c        2010-01-18 10:21:07 UTC 
(rev 10043)
+++ gnunet/src/topology/gnunet-daemon-topology.c        2010-01-18 10:21:20 UTC 
(rev 10044)
@@ -231,22 +231,98 @@
 static struct GNUNET_PEERINFO_IteratorContext *pitr_more;
 
 
+/**
+ * Entry in linked list of active 'disconnect' requests that we have issued.
+ */
+struct DisconnectList
+{
+  /**
+   * This is a doubly-linked list.
+   */
+  struct DisconnectList *next;
 
+  /**
+   * This is a doubly-linked list.
+   */
+  struct DisconnectList *prev;
+  
+  /**
+   * Our request handle.
+   */
+  struct GNUNET_CORE_InformationRequestContext *rh;
+
+  /**
+   * Peer we tried to disconnect.
+   */
+  struct GNUNET_PeerIdentity peer;
+
+};
+
+
 /**
+ * Head of doubly-linked list of active 'disconnect' requests that we have 
issued.
+ */
+static struct DisconnectList *disconnect_head;
+
+/**
+ * Head of doubly-linked list of active 'disconnect' requests that we have 
issued.
+ */
+static struct DisconnectList *disconnect_tail;
+
+
+/**
+ * Function called once our request to 'disconnect' a peer
+ * has completed.
+ *
+ * @param cls our 'struct DisconnectList'
+ * @param peer NULL on error (then what?)
+ * @param bpm_in set to the current bandwidth limit (receiving) for this peer
+ * @param bpm_out set to the current bandwidth limit (sending) for this peer
+ * @param latency current latency estimate, "FOREVER" if we have been
+ *                disconnected
+ * @param amount set to the amount that was actually reserved or unreserved
+ * @param preference current traffic preference for the given peer
+ */
+static void
+disconnect_done (void *cls,
+                const struct
+                GNUNET_PeerIdentity * peer,
+                unsigned int bpm_in,
+                unsigned int bpm_out,
+                struct GNUNET_TIME_Relative
+                latency, int amount,
+                unsigned long long preference)
+{
+  struct DisconnectList *dl = cls;
+
+  GNUNET_CONTAINER_DLL_remove (disconnect_head,
+                              disconnect_tail,
+                              dl);
+  GNUNET_free (dl);
+}
+
+
+/**
  * Force a disconnect from the specified peer.
  */
 static void
 force_disconnect (const struct GNUNET_PeerIdentity *peer)
 {
-  // FIXME: do something with return value!
-  GNUNET_CORE_peer_get_info (sched, cfg,
-                            peer,
-                            GNUNET_TIME_UNIT_FOREVER_REL,
-                            0,
-                            0,
-                            0,
-                            NULL,
-                            NULL);
+  struct DisconnectList *dl;
+
+  dl = GNUNET_malloc (sizeof (struct DisconnectList));
+  dl->peer = *peer;
+  GNUNET_CONTAINER_DLL_insert (disconnect_head,
+                              disconnect_tail,
+                              dl);
+  dl->rh = GNUNET_CORE_peer_get_info (sched, cfg,
+                                     peer,
+                                     GNUNET_TIME_UNIT_FOREVER_REL,
+                                     0,
+                                     0,
+                                     0,
+                                     &disconnect_done,
+                                     dl);
 }
 
 
@@ -1177,6 +1253,7 @@
 cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct PeerList *pl;
+  struct DisconnectList *dl;
 
   if (NULL != peerinfo_notify)
     {
@@ -1205,6 +1282,14 @@
       friends = pl->next;
       GNUNET_free (pl);
     }  
+  while (NULL != (dl = disconnect_head))
+    {
+      GNUNET_CONTAINER_DLL_remove (disconnect_head,
+                                  disconnect_tail,
+                                  dl);
+      GNUNET_CORE_peer_get_info_cancel (dl->rh);
+      GNUNET_free (dl);
+    }
 }
 
 





reply via email to

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