*/
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.
*/
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
"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 */
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)
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,
{
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;
*/
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.
*/
if (peer == NULL)
{
+ pitr = NULL;
finish_response (results);
return;
}
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);
}
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);
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;
if (peer == NULL)
{
+ pitr_more = NULL;
/* last call, schedule 'find_more_peers' again... */
if (0 != (GNUNET_SCHEDULER_get_reason (sched) & GNUNET_SCHEDULER_REASON_SHUTDOWN))
{
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);
}
{
if (peer == NULL)
{
- hello_gathering_active = GNUNET_NO;
+ pitr = NULL;
return;
}
#if DEBUG_TOPOLOGY
#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) )
{
"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;
}
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)