From 2e0897995fd89619b9da5050372239736bf87d68 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 25 Oct 2011 12:57:18 +0000 Subject: put ifdefs around DEBUG logs --- src/dht/dht_api.c | 20 +++++++++++++++ src/dht/gnunet-service-dht.h | 2 ++ src/dht/gnunet-service-dht_clients.c | 30 ++++++++++++++++++++++ src/dht/gnunet-service-dht_datacache.c | 6 +++-- src/dht/gnunet-service-dht_neighbours.c | 44 +++++++++++++++++++++++++++------ 5 files changed, 92 insertions(+), 10 deletions(-) diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index ee91c6f06..720e82a41 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c @@ -250,10 +250,12 @@ add_request_to_pending (void *cls, const GNUNET_HashCode * key, void *value) if (GNUNET_NO == rh->message->in_pending_queue) { +#if DEBUG_DHT LOG (GNUNET_ERROR_TYPE_DEBUG, "Retransmitting request related to %s to DHT %p\n", GNUNET_h2s (key), handle); +#endif GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, rh->message); rh->message->in_pending_queue = GNUNET_YES; @@ -281,9 +283,11 @@ try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_DHT_Handle *handle = cls; +#if DEBUG_DHT LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting with DHT %p\n", handle); +#endif handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; if (handle->retry_time.rel_value < GNUNET_CONSTANTS_SERVICE_RETRY.rel_value) handle->retry_time = GNUNET_CONSTANTS_SERVICE_RETRY; @@ -294,7 +298,9 @@ try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; if (GNUNET_YES != try_connect (handle)) { +#if DEBUG_DHT LOG (GNUNET_ERROR_TYPE_DEBUG, "dht reconnect failed(!)\n"); +#endif return; } GNUNET_CONTAINER_multihashmap_iterate (handle->active_requests, @@ -380,8 +386,10 @@ transmit_pending (void *cls, size_t size, void *buf) handle->th = NULL; if (buf == NULL) { +#if DEBUG_DHT LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmission to DHT service failed! Reconnecting!\n"); +#endif do_disconnect (handle); return 0; } @@ -457,10 +465,12 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value) if (dht_msg->unique_id != get_handle->unique_id) { /* UID mismatch */ +#if DEBUG_DHT LOG (GNUNET_ERROR_TYPE_DEBUG, "Ignoring reply for %s: UID mismatch: %llu/%llu\n", GNUNET_h2s (key), dht_msg->unique_id, get_handle->unique_id); +#endif return GNUNET_YES; } msize = ntohs (dht_msg->header.size); @@ -479,10 +489,12 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value) return GNUNET_NO; } data_length = msize - meta_length; +#if DEBUG_DHT LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving %u byte reply for %s to application\n", (unsigned int) data_length, GNUNET_h2s (key)); +#endif put_path = (const struct GNUNET_PeerIdentity *) &dht_msg[1]; get_path = &put_path[put_path_length]; data = &get_path[get_path_length]; @@ -509,8 +521,10 @@ service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg) if (msg == NULL) { +#if DEBUG_DHT LOG (GNUNET_ERROR_TYPE_DEBUG, "Error receiving data from DHT service, reconnecting\n"); +#endif do_disconnect (handle); return; } @@ -527,10 +541,12 @@ service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg) return; } dht_msg = (const struct GNUNET_DHT_ClientResultMessage *) msg; +#if DEBUG_DHT LOG (GNUNET_ERROR_TYPE_DEBUG, "Received reply for `%s' from DHT service %p\n", GNUNET_h2s (&dht_msg->key), handle); +#endif GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests, &dht_msg->key, &process_reply, (void *) dht_msg); @@ -735,10 +751,12 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, GNUNET_break (0); return NULL; } +#if DEBUG_DHT LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending query for %s to DHT %p\n", GNUNET_h2s (key), handle); +#endif pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize); get_msg = (struct GNUNET_DHT_ClientGetMessage *) &pending[1]; pending->msg = &get_msg->header; @@ -784,10 +802,12 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle) handle = get_handle->message->handle; get_msg = (const struct GNUNET_DHT_ClientGetMessage *) get_handle->message->msg; +#if DEBUG_DHT LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending STOP for %s to DHT via %p\n", GNUNET_h2s (&get_msg->key), handle); +#endif /* generate STOP */ pending = GNUNET_malloc (sizeof (struct PendingMessage) + diff --git a/src/dht/gnunet-service-dht.h b/src/dht/gnunet-service-dht.h index 2877a156b..f06b24b74 100644 --- a/src/dht/gnunet-service-dht.h +++ b/src/dht/gnunet-service-dht.h @@ -30,6 +30,8 @@ #include "gnunet_statistics_service.h" #include "gnunet_transport_service.h" +#define DEBUG_DHT GNUNET_EXTRA_LOGGING + /** * Configuration we use. */ diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c index 6f7c1daae..4b9eecc58 100644 --- a/src/dht/gnunet-service-dht_clients.c +++ b/src/dht/gnunet-service-dht_clients.c @@ -248,10 +248,12 @@ remove_client_records (void *cls, const GNUNET_HashCode * key, void *value) if (record->client != client) return GNUNET_YES; +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing client %p's record for key %s\n", client, GNUNET_h2s (key)); +#endif GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (forward_map, key, record)); @@ -280,9 +282,11 @@ handle_client_disconnect (void *cls, struct ClientList *pos; struct PendingMessage *reply; +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Local client %p disconnects\n", client); +#endif pos = find_active_client (client); GNUNET_CONTAINER_DLL_remove (client_head, client_tail, @@ -410,10 +414,12 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_NO); dht_msg = (const struct GNUNET_DHT_ClientPutMessage *) message; /* give to local clients */ +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Handling local PUT of %u-bytes for query %s\n", size - sizeof (struct GNUNET_DHT_ClientPutMessage), GNUNET_h2s (&dht_msg->key)); +#endif GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (dht_msg->expiration), &dht_msg->key, 0, NULL, @@ -479,10 +485,12 @@ handle_dht_local_get (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# GET requests received from clients"), 1, GNUNET_NO); +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received request for %s from local client %p\n", GNUNET_h2s (&get->key), client); +#endif cqr = GNUNET_malloc (sizeof (struct ClientQueryRecord) + xquery_size); cqr->key = get->key; cqr->client = find_active_client (client); @@ -546,10 +554,12 @@ remove_by_unique_id (void *cls, const GNUNET_HashCode * key, void *value) if (record->unique_id != ctx->unique_id) return GNUNET_YES; +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing client %p's record for key %s (by unique id)\n", ctx->client->client_handle, GNUNET_h2s (key)); +#endif return remove_client_records (ctx->client, key, record); } @@ -574,10 +584,12 @@ handle_dht_local_get_stop (void *cls, struct GNUNET_SERVER_Client *client, GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# GET STOP requests received from clients"), 1, GNUNET_NO); +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p stopped request for key %s\n", client, GNUNET_h2s (&dht_stop_msg->key)); +#endif ctx.client = find_active_client (client); ctx.unique_id = dht_stop_msg->unique_id; GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, @@ -622,9 +634,11 @@ send_reply_to_client (void *cls, size_t size, void *buf) if (buf == NULL) { /* client disconnected */ +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected, pending messages will be discarded\n", client->client_handle); +#endif return 0; } off = 0; @@ -635,18 +649,22 @@ send_reply_to_client (void *cls, size_t size, void *buf) reply); memcpy (&cbuf[off], reply->msg, msize); GNUNET_free (reply); +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes to client %p\n", msize, client->client_handle); +#endif off += msize; } process_pending_messages (client); +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitted %u/%u bytes to client %p\n", (unsigned int) off, (unsigned int) size, client->client_handle); +#endif return off; } @@ -661,19 +679,23 @@ process_pending_messages (struct ClientList *client) { if ((client->pending_head == NULL) || (client->transmit_handle != NULL)) { +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not asking for transmission to %p now: %s\n", client->client_handle, client->pending_head == NULL ? "no more messages" : "request already pending"); +#endif return; } +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking for transmission of %u bytes to client %p\n", ntohs (client->pending_head-> msg->size), client->client_handle); +#endif client->transmit_handle = GNUNET_SERVER_notify_transmit_ready (client->client_handle, ntohs (client->pending_head-> @@ -759,9 +781,11 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) if ( (record->type != GNUNET_BLOCK_TYPE_ANY) && (record->type != frc->type) ) { +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record type missmatch, not passing request for key %s to local client\n", GNUNET_h2s (key)); +#endif GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Key match, type mismatches in REPLY to CLIENT"), 1, GNUNET_NO); @@ -775,9 +799,11 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) &ch, sizeof (GNUNET_HashCode))) { +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Duplicate reply, not passing request for key %s to local client\n", GNUNET_h2s (key)); +#endif GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Duplicate REPLIES to CLIENT request dropped"), 1, GNUNET_NO); @@ -791,10 +817,12 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) record->xquery_size, frc->data, frc->data_size); +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Evaluation result is %d for key %s for local client's query\n", (int) eval, GNUNET_h2s (key)); +#endif switch (eval) { case GNUNET_BLOCK_EVALUATION_OK_LAST: @@ -848,10 +876,12 @@ forward_reply (void *cls, const GNUNET_HashCode * key, void *value) GNUNET_NO); reply = (struct GNUNET_DHT_ClientResultMessage*) &pm[1]; reply->unique_id = record->unique_id; +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing reply to query %s for client %p\n", GNUNET_h2s (key), record->client->client_handle); +#endif add_pending_message (record->client, pm); if (GNUNET_YES == do_free) remove_client_records (record->client, key, record); diff --git a/src/dht/gnunet-service-dht_datacache.c b/src/dht/gnunet-service-dht_datacache.c index 8876aeea4..f3b2e5b2f 100644 --- a/src/dht/gnunet-service-dht_datacache.c +++ b/src/dht/gnunet-service-dht_datacache.c @@ -89,7 +89,7 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration, if (datacache == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "%s request received, but have no datacache!\n", + _("%s request received, but have no datacache!\n"), "PUT"); return; } @@ -199,10 +199,12 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, ctx->xquery_size, rdata, rdata_size); +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found reply for query %s in datacache, evaluation result is %d\n", GNUNET_h2s (key), (int) eval); +#endif ctx->eval = eval; switch (eval) { @@ -243,7 +245,7 @@ datacache_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, gettext_noop ("# Unsupported RESULTS found in datacache"), 1, GNUNET_NO); GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Unsupported block type (%u) in local response!\n", + _("Unsupported block type (%u) in local response!\n"), type); break; } diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c index 45df22b89..637c9ecc7 100644 --- a/src/dht/gnunet-service-dht_neighbours.c +++ b/src/dht/gnunet-service-dht_neighbours.c @@ -523,10 +523,12 @@ add_known_to_bloom (void *cls, const GNUNET_HashCode * key, void *value) GNUNET_HashCode mh; GNUNET_BLOCK_mingle_hash (key, ctx->bf_mutator, &mh); +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding known peer (%s) to bloomfilter for FIND PEER with mutation %u\n", GNUNET_h2s (key), ctx->bf_mutator); +#endif GNUNET_CONTAINER_bloomfilter_add (ctx->bloom, &mh); return GNUNET_YES; } @@ -613,10 +615,12 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, /* Check for connect to self message */ if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) return; +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected %s to %s\n", GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey)); +#endif if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (all_known_peers, &peer->hashPubKey)) @@ -676,10 +680,12 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) /* Check for disconnect from self message */ if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) return; +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnected %s from %s\n", GNUNET_i2s (&my_identity), GNUNET_h2s (&peer->hashPubKey)); +#endif to_remove = GNUNET_CONTAINER_multihashmap_get (all_known_peers, &peer->hashPubKey); if (NULL == to_remove) @@ -1035,10 +1041,12 @@ select_peer (const GNUNET_HashCode *key, } else { +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Excluded peer `%s' due to BF match in greedy routing for %s\n", GNUNET_i2s (&pos->id), GNUNET_h2s (key)); +#endif GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1, GNUNET_NO); @@ -1069,10 +1077,12 @@ select_peer (const GNUNET_HashCode *key, GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# Peers excluded from routing due to Bloomfilter"), 1, GNUNET_NO); +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Excluded peer `%s' due to BF match in random routing for %s\n", GNUNET_i2s (&pos->id), GNUNET_h2s (key)); +#endif pos = pos->next; continue; /* Ignore bloomfiltered peers */ } @@ -1155,6 +1165,7 @@ get_target_peers (const GNUNET_HashCode *key, GNUNET_CONTAINER_bloomfilter_test (bloom, &nxt->id.hashPubKey)); GNUNET_CONTAINER_bloomfilter_add (bloom, &rtargets[off]->id.hashPubKey); } +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Selected %u/%u peers at hop %u for %s (target was %u)\n", off, @@ -1162,6 +1173,7 @@ get_target_peers (const GNUNET_HashCode *key, (unsigned int) hop_count, GNUNET_h2s (key), ret); +#endif if (0 == off) { GNUNET_free (rtargets); @@ -1215,10 +1227,12 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, struct GNUNET_PeerIdentity *pp; GNUNET_assert (NULL != bf); +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding myself (%s) to PUT bloomfilter for %s\n", GNUNET_i2s (&my_identity), GNUNET_h2s (key)); +#endif GNUNET_CONTAINER_bloomfilter_add (bf, &my_identity.hashPubKey); GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# PUT requests routed"), 1, @@ -1228,11 +1242,13 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, &targets); if (0 == target_count) { +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Routing PUT for %s terminates after %u hops at %s\n", GNUNET_h2s (key), (unsigned int) hop_count, GNUNET_i2s (&my_identity)); +#endif return; } msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + sizeof (struct PeerPutMessage); @@ -1253,11 +1269,13 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, for (i=0;iid)); +#endif pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); pending->importance = 0; /* FIXME */ pending->timeout = expiration_time; @@ -1336,20 +1354,24 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, target_count = get_target_peers (key, peer_bf, hop_count, desired_replication_level, &targets); +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding myself (%s) to GET bloomfilter for %s\n", GNUNET_i2s (&my_identity), GNUNET_h2s (key)); +#endif GNUNET_CONTAINER_bloomfilter_add (peer_bf, &my_identity.hashPubKey); if (0 == target_count) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Routing GET for %s terminates after %u hops at %s\n", - GNUNET_h2s (key), - (unsigned int) hop_count, - GNUNET_i2s (&my_identity)); - return; - } + { +#if DEBUG_DHT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Routing GET for %s terminates after %u hops at %s\n", + GNUNET_h2s (key), + (unsigned int) hop_count, + GNUNET_i2s (&my_identity)); +#endif + return; + } reply_bf_size = GNUNET_CONTAINER_bloomfilter_get_size (reply_bf); msize = xquery_size + sizeof (struct PeerGetMessage) + reply_bf_size; if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) @@ -1365,11 +1387,13 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, for (i=0;iid)); +#endif pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); pending->importance = 0; /* FIXME */ pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); @@ -1573,10 +1597,12 @@ handle_dht_p2p_put (void *cls, /* cannot verify, good luck */ break; } +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PUT for %s at %s\n", GNUNET_h2s (&put->key), GNUNET_i2s (&my_identity)); +#endif bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, DHT_BLOOM_SIZE, GNUNET_CONSTANTS_BLOOMFILTER_K); @@ -1809,11 +1835,13 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer, &get->key, xquery, xquery_size, reply_bf, get->bf_mutator); +#if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET for %s at %s after %u hops\n", GNUNET_h2s (&get->key), GNUNET_i2s (&my_identity), (unsigned int) ntohl (get->hop_count)); +#endif /* local lookup (this may update the reply_bf) */ if ( (0 != (options & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) || (am_closest_peer (&get->key, -- cgit v1.2.3