From: Christian Grothoff Date: Fri, 15 Jan 2010 10:07:52 +0000 (+0000) Subject: adjust code to new peerinfo API X-Git-Tag: initial-import-from-subversion-38251~22966 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=4d84bdf0cb7e3368948d77c7183ec127c2e9306d;p=oweals%2Fgnunet.git adjust code to new peerinfo API --- diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index c766ceb30..56ea6d30d 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c @@ -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; diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index 06a17a2ef..817a11bfc 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c @@ -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); diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index 40582029d..880f8603c 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c @@ -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)