From 748e690fe49e2639076cb76e6a4a4c5eb04e130e Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Mon, 3 Jan 2011 14:21:25 +0000 Subject: [PATCH] Changed peerinfo api to distinguish between last element and timeout --- src/core/gnunet-service-core.c | 20 +++++++++-- src/dv/gnunet-service-dv.c | 11 ++++-- src/hostlist/hostlist-server.c | 20 +++++++++-- src/include/gnunet_peerinfo_service.h | 4 ++- src/peerinfo-tool/gnunet-peerinfo.c | 5 +-- src/peerinfo/peerinfo_api.c | 44 +++++++++++++++--------- src/peerinfo/peerinfo_api_notify.c | 2 +- src/peerinfo/perf_peerinfo_api.c | 3 +- src/peerinfo/test_peerinfo_api.c | 9 ++++- src/topology/gnunet-daemon-topology.c | 11 +++++- src/transport/gnunet-service-transport.c | 23 +++++++++++-- 11 files changed, 119 insertions(+), 33 deletions(-) diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 290160414..dd1937f06 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c @@ -3006,10 +3006,18 @@ handle_client_request_connect (void *cls, static void process_hello_retry_send_key (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *hello) + const struct GNUNET_HELLO_Message *hello, + const char *err_msg) { struct Neighbour *n = cls; + if (err_msg != NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Error in communication with PEERINFO service\n")); + /* return; */ + } + if (peer == NULL) { #if DEBUG_CORE @@ -3318,11 +3326,19 @@ handle_set_key (struct Neighbour *n, static void process_hello_retry_handle_set_key (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *hello) + const struct GNUNET_HELLO_Message *hello, + const char *err_msg) { struct Neighbour *n = cls; struct SetKeyMessage *sm = n->skm; + if (err_msg != NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Error in communication with PEERINFO service\n")); + /* return; */ + } + if (peer == NULL) { n->skm = NULL; diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index cd54686f3..223b95fed 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c @@ -2806,11 +2806,13 @@ add_all_direct_neighbors (void *cls, * @param cls closure * @param peer id of the peer, NULL for last call * @param hello hello message for the peer (can be NULL) + * @param err_msg NULL if successful, otherwise contains error message */ static void process_peerinfo (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *hello) + const struct GNUNET_HELLO_Message *hello, + const char *err_msg) { struct PeerIteratorContext *peerinfo_iterator = cls; struct DirectNeighbor *neighbor = peerinfo_iterator->neighbor; @@ -2819,7 +2821,12 @@ process_peerinfo (void *cls, char *neighbor_pid; #endif int sent; - + if (err_msg != NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Error in communication with PEERINFO service\n")); + /* return; */ + } if (peer == NULL) { if (distant->pkey == NULL) diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index 95272a555..4c88ae317 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c @@ -178,13 +178,21 @@ check_has_addr (void *cls, static void host_processor (void *cls, const struct GNUNET_PeerIdentity * peer, - const struct GNUNET_HELLO_Message *hello) + const struct GNUNET_HELLO_Message *hello, + const char *err_msg) { struct HostSet *results = cls; size_t old; size_t s; int has_addr; + if (err_msg != NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Error in communication with PEERINFO service:\n `%s'"), err_msg); + return; + } + if (peer == NULL) { pitr = NULL; @@ -439,17 +447,25 @@ disconnect_handler (void *cls, * @param cls closure (not used) * @param peer potential peer to connect to * @param hello HELLO for this peer (or NULL) + * @param err_msg NULL if successful, otherwise contains error message */ static void process_notify (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *hello) + const struct GNUNET_HELLO_Message *hello, + const char *err_msg) { struct HostSet *results; #if DEBUG_HOSTLIST_SERVER GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peerinfo is notifying us to rebuild our hostlist\n"); #endif + if (err_msg != NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Error in communication with PEERINFO service\n")); + /* return; */ + } results = GNUNET_malloc(sizeof(struct HostSet)); GNUNET_assert (peerinfo != NULL); pitr = GNUNET_PEERINFO_iterate (peerinfo, diff --git a/src/include/gnunet_peerinfo_service.h b/src/include/gnunet_peerinfo_service.h index 1c34d83bb..1411168c0 100644 --- a/src/include/gnunet_peerinfo_service.h +++ b/src/include/gnunet_peerinfo_service.h @@ -95,11 +95,13 @@ GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h, * @param cls closure * @param peer id of the peer, NULL for last call * @param hello hello message for the peer (can be NULL) + * @param error message */ typedef void (*GNUNET_PEERINFO_Processor) (void *cls, const struct GNUNET_PeerIdentity * peer, - const struct GNUNET_HELLO_Message * hello); + const struct GNUNET_HELLO_Message * hello, + const char * err_msg); /** diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c index 42adcaad8..48cbb6038 100644 --- a/src/peerinfo-tool/gnunet-peerinfo.c +++ b/src/peerinfo-tool/gnunet-peerinfo.c @@ -157,14 +157,15 @@ print_address (void *cls, static void print_peer_info (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *hello) + const struct GNUNET_HELLO_Message *hello, + const char * err_msg) { struct GNUNET_CRYPTO_HashAsciiEncoded enc; struct PrintContext *pc; if (peer == NULL) { - fprintf (stderr,_("Error in communication with PEERINFO service\n")); + if (err_msg != NULL) fprintf (stderr,_("Error in communication with PEERINFO service\n")); GNUNET_PEERINFO_disconnect (peerinfo); return; } diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c index c2e091f00..a3a396d90 100644 --- a/src/peerinfo/peerinfo_api.c +++ b/src/peerinfo/peerinfo_api.c @@ -385,15 +385,16 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) ic->h->in_receive = GNUNET_NO; if (msg == NULL) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - _("Failed to receive response from `%s' service.\n"), - "PEERINFO"); + char * err_msg; + GNUNET_asprintf(&err_msg,_("Failed to receive response from `%s' service.\n"),"PEERINFO"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,err_msg); reconnect (ic->h); trigger_transmit (ic->h); if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (ic->timeout_task); if (ic->callback != NULL) - ic->callback (ic->callback_cls, NULL, NULL); + ic->callback (ic->callback_cls, NULL, NULL, err_msg); + GNUNET_free (err_msg); GNUNET_free (ic); return; } @@ -408,7 +409,7 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (ic->timeout_task); if (ic->callback != NULL) - ic->callback (ic->callback_cls, NULL, NULL); + ic->callback (ic->callback_cls, NULL, NULL, NULL); GNUNET_free (ic); return; } @@ -416,13 +417,17 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) if ((ms < sizeof (struct InfoMessage)) || (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_PEERINFO_INFO)) { + char * err_msg; + GNUNET_asprintf(&err_msg,_("Received invalid message from `%s' service.\n"),"PEERINFO"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,err_msg); GNUNET_break (0); reconnect (ic->h); trigger_transmit (ic->h); if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (ic->timeout_task); if (ic->callback != NULL) - ic->callback (ic->callback_cls, NULL, NULL); + ic->callback (ic->callback_cls, NULL, NULL, err_msg); + GNUNET_free (err_msg); GNUNET_free (ic); return; } @@ -434,14 +439,17 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) hello = (const struct GNUNET_HELLO_Message *) &im[1]; if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello)) { - GNUNET_break (0); + char * err_msg; + GNUNET_asprintf(&err_msg,_("Received invalid message from `%s' service.\n"),"PEERINFO"); + GNUNET_break (0); reconnect (ic->h); trigger_transmit (ic->h); if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (ic->timeout_task); if (ic->callback != NULL) - ic->callback (ic->callback_cls, NULL, NULL); + ic->callback (ic->callback_cls, NULL, NULL, err_msg); GNUNET_free (ic); + GNUNET_free (err_msg); return; } } @@ -455,7 +463,7 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) #endif ic->h->in_receive = GNUNET_YES; if (ic->callback != NULL) - ic->callback (ic->callback_cls, &im->peer, hello); + ic->callback (ic->callback_cls, &im->peer, hello, NULL); GNUNET_CLIENT_receive (ic->h->client, &peerinfo_handler, ic, @@ -478,10 +486,9 @@ iterator_start_receive (void *cls, if (GNUNET_OK != transmit_success) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Failed to transmit iteration request to `%s' service (%d).\n"), - "PEERINFO", - transmit_success); + char * err_msg; + GNUNET_asprintf(&err_msg,_("Failed to transmit iteration request to `%s' service (%d).\n"),"PEERINFO",transmit_success); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING,err_msg); if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (ic->timeout_task); @@ -490,7 +497,8 @@ iterator_start_receive (void *cls, reconnect (ic->h); trigger_transmit (ic->h); if (ic->callback != NULL) - ic->callback (ic->callback_cls, NULL, NULL); + ic->callback (ic->callback_cls, NULL, NULL, err_msg); + GNUNET_free (err_msg); GNUNET_free (ic); return; } @@ -520,19 +528,21 @@ signal_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_PEERINFO_IteratorContext *ic = cls; + char * err_msg; - GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, - _("Timeout transmitting iteration request to `%s' service.\n"), + GNUNET_asprintf(&err_msg,_("Timeout transmitting iteration request to `%s' service.\n"), "PEERINFO"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,err_msg); ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; if (! ic->in_receive) GNUNET_CONTAINER_DLL_remove (ic->h->tq_head, ic->h->tq_tail, ic->tqe); reconnect (ic->h); - ic->callback (ic->callback_cls, NULL, NULL); + ic->callback (ic->callback_cls, NULL, NULL,err_msg); ic->callback = NULL; GNUNET_free_non_null (ic->tqe); + GNUNET_free (err_msg); GNUNET_free (ic); } diff --git a/src/peerinfo/peerinfo_api_notify.c b/src/peerinfo/peerinfo_api_notify.c index 25f2b9d5e..ab0d13f66 100644 --- a/src/peerinfo/peerinfo_api_notify.c +++ b/src/peerinfo/peerinfo_api_notify.c @@ -138,7 +138,7 @@ process_notification (void *cls, "Received information about peer `%s' from peerinfo database\n", GNUNET_i2s (&im->peer)); #endif - nc->callback (nc->callback_cls, &im->peer, hello); + nc->callback (nc->callback_cls, &im->peer, hello, NULL); receive_notifications (nc); } diff --git a/src/peerinfo/perf_peerinfo_api.c b/src/peerinfo/perf_peerinfo_api.c index 1de0f4615..4cae7ab60 100755 --- a/src/peerinfo/perf_peerinfo_api.c +++ b/src/peerinfo/perf_peerinfo_api.c @@ -107,7 +107,8 @@ add_peer (size_t i) static void process (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *hello) + const struct GNUNET_HELLO_Message *hello, + const char * err_msg) { if (peer == NULL) { diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c index 4030820d7..460a3764d 100644 --- a/src/peerinfo/test_peerinfo_api.c +++ b/src/peerinfo/test_peerinfo_api.c @@ -100,11 +100,18 @@ add_peer () static void process (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *hello) + const struct GNUNET_HELLO_Message *hello, + const char * err_msg) { int *ok = cls; unsigned int agc; + if (err_msg != NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Error in communication with PEERINFO service\n")); + } + if (peer == NULL) { ic = NULL; diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index 4bbe4e19a..7cab16d15 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c @@ -924,14 +924,23 @@ consider_for_advertising (const struct GNUNET_HELLO_Message *hello) * @param cls closure (not used) * @param peer potential peer to connect to * @param hello HELLO for this peer (or NULL) + * @param err_msg NULL if successful, otherwise contains error message */ static void process_peer (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *hello) + const struct GNUNET_HELLO_Message *hello, + const char *err_msg) { struct Peer *pos; + if (err_msg != NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Error in communication with PEERINFO service\n")); + /* return; */ + } + GNUNET_assert (peer != NULL); if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index b2e0c2ee4..43001dbc7 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -2710,15 +2710,23 @@ add_to_foreign_address_list (void *cls, * @param cls closure ('struct NeighbourList*') * @param peer id of the peer, NULL for last call * @param h hello message for the peer (can be NULL) + * @param err_msg NULL if successful, otherwise contains error message */ static void add_hello_for_peer (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *h) + const struct GNUNET_HELLO_Message *h, + const char *err_msg) { struct NeighbourList *n = cls; - if (peer == NULL) + if (err_msg != NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Error in communication with PEERINFO service\n")); + /* return; */ + } + if ((peer == NULL)) { GNUNET_STATISTICS_update (stats, gettext_noop ("# outstanding peerinfo iterate requests"), @@ -4029,11 +4037,13 @@ run_validation (void *cls, * @param cls closure * @param peer id of the peer, NULL for last call * @param h hello message for the peer (can be NULL) + * @param err_msg NULL if successful, otherwise contains error message */ static void check_hello_validated (void *cls, const struct GNUNET_PeerIdentity *peer, - const struct GNUNET_HELLO_Message *h) + const struct GNUNET_HELLO_Message *h, + const char *err_msg) { struct CheckHelloValidatedContext *chvc = cls; struct GNUNET_HELLO_Message *plain_hello; @@ -4041,6 +4051,13 @@ check_hello_validated (void *cls, struct GNUNET_PeerIdentity target; struct NeighbourList *n; + if (err_msg != NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Error in communication with PEERINFO service\n")); + /* return; */ + } + if (peer == NULL) { GNUNET_STATISTICS_update (stats, -- 2.25.1