gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r10011 - in gnunet/src: core hostlist topology


From: gnunet
Subject: [GNUnet-SVN] r10011 - in gnunet/src: core hostlist topology
Date: Fri, 15 Jan 2010 11:07:52 +0100

Author: grothoff
Date: 2010-01-15 11:07:52 +0100 (Fri, 15 Jan 2010)
New Revision: 10011

Modified:
   gnunet/src/core/gnunet-service-core.c
   gnunet/src/hostlist/hostlist-server.c
   gnunet/src/topology/gnunet-daemon-topology.c
Log:
adjust code to new peerinfo API

Modified: gnunet/src/core/gnunet-service-core.c
===================================================================
--- gnunet/src/core/gnunet-service-core.c       2010-01-15 10:07:44 UTC (rev 
10010)
+++ gnunet/src/core/gnunet-service-core.c       2010-01-15 10:07:52 UTC (rev 
10011)
@@ -360,6 +360,18 @@
   struct PingMessage *pending_ping;
 
   /**
+   * Non-NULL if we are currently looking up HELLOs for this peer.
+   * for this peer.
+   */
+  struct GNUNET_PEERINFO_IteratorContext *pitr;
+
+  /**
+   * SetKeyMessage to transmit, NULL if we are not currently trying
+   * to send one.
+   */
+  struct SetKeyMessage *skm;
+
+  /**
    * Identity of the neighbour.
    */
   struct GNUNET_PeerIdentity peer;
@@ -2005,13 +2017,13 @@
                               const struct GNUNET_HELLO_Message *hello,
                               uint32_t trust)
 {
-  struct Neighbour *n;
+  struct Neighbour *n = cls;
 
   if (peer == NULL)
-    return;
-  n = find_neighbour (peer);
-  if (n == NULL)
-    return;
+    {
+      n->pitr = NULL;
+      return;
+    }
   if (n->public_key != NULL)
     return;
 #if DEBUG_CORE
@@ -2074,12 +2086,13 @@
                   "Lacking public key for `%4s', trying to obtain one.\n",
                   GNUNET_i2s (&n->peer));
 #endif
-      GNUNET_PEERINFO_for_all (cfg,
-                               sched,
-                               &n->peer,
-                               0,
-                               GNUNET_TIME_UNIT_MINUTES,
-                               &process_hello_retry_send_key, NULL);
+      GNUNET_assert (n->pitr == NULL);
+      n->pitr = GNUNET_PEERINFO_iterate (cfg,
+                                        sched,
+                                        &n->peer,
+                                        0,
+                                        GNUNET_TIME_UNIT_MINUTES,
+                                        &process_hello_retry_send_key, n);
       return;
     }
   /* first, set key message */
@@ -2203,20 +2216,16 @@
                                     const struct GNUNET_HELLO_Message *hello,
                                     uint32_t trust)
 {
-  struct SetKeyMessage *sm = cls;
-  struct Neighbour *n;
+  struct Neighbour *n = cls;
+  struct SetKeyMessage *sm = n->skm;
 
   if (peer == NULL)
     {
       GNUNET_free (sm);
+      n->skm = NULL;
+      n->pitr = NULL;
       return;
     }
-  n = find_neighbour (peer);
-  if (n == NULL)
-    {
-      GNUNET_break (0);
-      return;
-    }
   if (n->public_key != NULL)
     return;                     /* multiple HELLOs match!? */
   n->public_key =
@@ -2341,12 +2350,15 @@
       m_cpy = GNUNET_malloc (sizeof (struct SetKeyMessage));
       memcpy (m_cpy, m, sizeof (struct SetKeyMessage));
       /* lookup n's public key, then try again */
-      GNUNET_PEERINFO_for_all (cfg,
-                               sched,
-                               &n->peer,
-                               0,
-                               GNUNET_TIME_UNIT_MINUTES,
-                               &process_hello_retry_handle_set_key, m_cpy);
+      GNUNET_assert (n->pitr == NULL);
+      GNUNET_assert (n->skm == NULL);
+      n->skm = m_cpy;
+      n->pitr = GNUNET_PEERINFO_iterate (cfg,
+                                        sched,
+                                        &n->peer,
+                                        0,
+                                        GNUNET_TIME_UNIT_MINUTES,
+                                        &process_hello_retry_handle_set_key, 
n);
       return;
     }
   if (0 != memcmp (&m->target,
@@ -3036,6 +3048,16 @@
 {
   struct MessageEntry *m;
 
+  if (n->pitr != NULL)
+    {
+      GNUNET_PEERINFO_iterate_cancel (n->pitr);
+      n->pitr = NULL;
+    }
+  if (n->skm != NULL)
+    {
+      GNUNET_free (n->skm);
+      n->skm = NULL;
+    }
   while (NULL != (m = n->messages))
     {
       n->messages = m->next;

Modified: gnunet/src/hostlist/hostlist-server.c
===================================================================
--- gnunet/src/hostlist/hostlist-server.c       2010-01-15 10:07:44 UTC (rev 
10010)
+++ gnunet/src/hostlist/hostlist-server.c       2010-01-15 10:07:52 UTC (rev 
10011)
@@ -78,6 +78,11 @@
 static struct MHD_Response *response;
 
 /**
+ * NULL if we are not currenlty iterating over peer information.
+ */
+static struct GNUNET_PEERINFO_IteratorContext *pitr;
+
+/**
  * Context for host processor.
  */
 struct HostSet
@@ -151,6 +156,7 @@
   
   if (peer == NULL)
     {
+      pitr = NULL;
       finish_response (results);
       return;
     }
@@ -183,12 +189,12 @@
 
   response_task = GNUNET_SCHEDULER_NO_TASK;
   results = GNUNET_malloc(sizeof(struct HostSet));
-  GNUNET_PEERINFO_for_all (cfg, sched, 
-                          NULL,
-                          0, 
-                          GNUNET_TIME_UNIT_MINUTES,
-                          &host_processor,
-                          results);
+  pitr = GNUNET_PEERINFO_iterate (cfg, sched, 
+                                 NULL,
+                                 0, 
+                                 GNUNET_TIME_UNIT_MINUTES,
+                                 &host_processor,
+                                 results);
 }
 
 
@@ -440,6 +446,11 @@
       GNUNET_SCHEDULER_cancel (sched, hostlist_task_v4);
       hostlist_task_v4 = GNUNET_SCHEDULER_NO_TASK;
     }
+  if (pitr != NULL)
+    {
+      GNUNET_PEERINFO_iterate_cancel (pitr);
+      pitr = NULL;
+    }
   if (GNUNET_SCHEDULER_NO_TASK != response_task)
     {
       GNUNET_SCHEDULER_cancel (sched, response_task);

Modified: gnunet/src/topology/gnunet-daemon-topology.c
===================================================================
--- gnunet/src/topology/gnunet-daemon-topology.c        2010-01-15 10:07:44 UTC 
(rev 10010)
+++ gnunet/src/topology/gnunet-daemon-topology.c        2010-01-15 10:07:52 UTC 
(rev 10011)
@@ -219,13 +219,19 @@
 static int autoconnect;
 
 /**
- * Are we currently having a request pending with
+ * Non-NULL if we are currently having a request pending with
  * PEERINFO asking for HELLOs for advertising?
  */
-static int hello_gathering_active;
+static struct GNUNET_PEERINFO_IteratorContext *pitr;
 
+/**
+ * Non-NULL if we are currently having a request pending with
+ * PEERINFO looking for more peers to connect to.
+ */
+static struct GNUNET_PEERINFO_IteratorContext *pitr_more;
 
 
+
 /**
  * Force a disconnect from the specified peer.
  */
@@ -642,6 +648,7 @@
 
   if (peer == NULL)
     {
+      pitr_more = NULL;
       /* last call, schedule 'find_more_peers' again... */
       if (0 != (GNUNET_SCHEDULER_get_reason (sched) & 
GNUNET_SCHEDULER_REASON_SHUTDOWN))
        {
@@ -814,11 +821,11 @@
              target_connection_count,
              friend_count);
 #endif         
-  GNUNET_PEERINFO_for_all (cfg,
-                          sched,
-                          NULL,
-                          0, GNUNET_TIME_UNIT_FOREVER_REL,
-                          &process_peer, NULL);
+  pitr_more = GNUNET_PEERINFO_iterate (cfg,
+                                      sched,
+                                      NULL,
+                                      0, GNUNET_TIME_UNIT_FOREVER_REL,
+                                      &process_peer, NULL);
 }
 
 
@@ -1036,7 +1043,7 @@
 {
   if (peer == NULL)
     {
-      hello_gathering_active = GNUNET_NO;
+      pitr = NULL;
       return;
     }
 #if DEBUG_TOPOLOGY
@@ -1139,7 +1146,7 @@
 #endif         
       return size;
     }
-  if ( (GNUNET_NO == hello_gathering_active) &&
+  if ( (NULL == pitr) &&
        (GNUNET_TIME_absolute_get_duration (last_hello_gather_time).value >
        MIN_HELLO_GATHER_DELAY.value) )
     {
@@ -1149,13 +1156,12 @@
                  "HELLO",
                  "PEERINFO");
 #endif         
-      hello_gathering_active = GNUNET_YES;
       last_hello_gather_time = GNUNET_TIME_absolute_get();
-      GNUNET_PEERINFO_for_all (cfg,
-                              sched,
-                              NULL,
-                              0, GNUNET_TIME_UNIT_FOREVER_REL,
-                              &gather_hello_callback, NULL);
+      pitr = GNUNET_PEERINFO_iterate (cfg,
+                                     sched,
+                                     NULL,
+                                     0, GNUNET_TIME_UNIT_FOREVER_REL,
+                                     &gather_hello_callback, NULL);
     }
   return 0;
 }
@@ -1175,6 +1181,16 @@
       GNUNET_PEERINFO_notify_cancel (peerinfo_notify);
       peerinfo_notify = NULL;
     }
+  if (NULL != pitr)
+    {
+      GNUNET_PEERINFO_iterate_cancel (pitr);
+      pitr = NULL;
+    }
+  if (NULL != pitr_more)
+    {
+      GNUNET_PEERINFO_iterate_cancel (pitr_more);
+      pitr_more = NULL;
+    }
   GNUNET_TRANSPORT_disconnect (transport);
   transport = NULL;
   if (handle != NULL)





reply via email to

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