adjust code to new peerinfo API
authorChristian Grothoff <christian@grothoff.org>
Fri, 15 Jan 2010 10:07:52 +0000 (10:07 +0000)
committerChristian Grothoff <christian@grothoff.org>
Fri, 15 Jan 2010 10:07:52 +0000 (10:07 +0000)
src/core/gnunet-service-core.c
src/hostlist/hostlist-server.c
src/topology/gnunet-daemon-topology.c

index c766ceb30114bcc9f70e01019f875a826c6f5efc..56ea6d30def3f4ae28db3c2c0fafeb7b67462a84 100644 (file)
@@ -359,6 +359,18 @@ struct Neighbour
    */
   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.
    */
@@ -2005,13 +2017,13 @@ process_hello_retry_send_key (void *cls,
                               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 @@ send_key (struct Neighbour *n)
                   "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,18 +2216,14 @@ process_hello_retry_handle_set_key (void *cls,
                                     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);
-      return;
-    }
-  n = find_neighbour (peer);
-  if (n == NULL)
-    {
-      GNUNET_break (0);
+      n->skm = NULL;
+      n->pitr = NULL;
       return;
     }
   if (n->public_key != NULL)
@@ -2341,12 +2350,15 @@ handle_set_key (struct Neighbour *n, const struct SetKeyMessage *m)
       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 @@ free_neighbour (struct Neighbour *n)
 {
   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;
index 06a17a2ef2daa79d7125fd7b0986fe37e77b3721..817a11bfc5d301ffb3fd46a72cc9638b3c562bf4 100644 (file)
@@ -77,6 +77,11 @@ static GNUNET_SCHEDULER_TaskIdentifier response_task;
  */
 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.
  */
@@ -151,6 +156,7 @@ host_processor (void *cls,
   
   if (peer == NULL)
     {
+      pitr = NULL;
       finish_response (results);
       return;
     }
@@ -183,12 +189,12 @@ update_response (void *cls,
 
   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_HOSTLIST_server_stop ()
       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);
index 40582029d869fb12fffe67913987e7c359464231..880f8603c97c85bde4a902c621a57b8f8e77ddb4 100644 (file)
@@ -219,10 +219,16 @@ static unsigned int friend_count;
 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;
 
 
 
@@ -642,6 +648,7 @@ process_peer (void *cls,
 
   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 @@ find_more_peers (void *cls,
              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 @@ gather_hello_callback (void *cls,
 {
   if (peer == NULL)
     {
-      hello_gathering_active = GNUNET_NO;
+      pitr = NULL;
       return;
     }
 #if DEBUG_TOPOLOGY
@@ -1139,7 +1146,7 @@ hello_advertising (void *cls,
 #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_advertising (void *cls,
                  "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 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
       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)