From c6689c4e233c663f79cf00449e70ce3c56653f1c Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 19 Jul 2009 09:10:43 +0000 Subject: [PATCH] debug messages --- src/datastore/datastore_api.c | 40 +++++++++ src/datastore/gnunet-service-datastore.c | 100 +++++++++++++++++++++-- src/datastore/test_datastore_api.c | 46 +++++++++-- 3 files changed, 173 insertions(+), 13 deletions(-) diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c index c67b7556a..4fc719629 100644 --- a/src/datastore/datastore_api.c +++ b/src/datastore/datastore_api.c @@ -215,6 +215,12 @@ with_status_response_handler (void *cls, } } h->response_proc = NULL; +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received status %d/%s\n", + status, + emsg); +#endif cont (h->response_proc_cls, status, emsg); @@ -251,6 +257,11 @@ transmit_get_status (void *cls, } GNUNET_assert (h->message_size <= size); memcpy (buf, &h[1], h->message_size); +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transmitted %u byte message to datastore service, now waiting for status.\n", + h->message_size); +#endif h->message_size = 0; GNUNET_CLIENT_receive (h->client, &with_status_response_handler, @@ -284,6 +295,12 @@ transmit_for_status (struct GNUNET_DATASTORE_Handle *h, hdr = (const struct GNUNET_MessageHeader*) &h[1]; msize = ntohs(hdr->size); +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transmitting %u byte message of type %u to datastore service\n", + msize, + ntohs(hdr->type)); +#endif GNUNET_assert (h->response_proc == NULL); h->response_proc = cont; h->response_proc_cls = cont_cls; @@ -485,6 +502,10 @@ with_result_response_handler (void *cls, { GNUNET_break (ntohs(msg->size) == sizeof(struct GNUNET_MessageHeader)); h->response_proc = NULL; +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received end of result set\n"); +#endif cont (h->response_proc_cls, NULL, 0, NULL, 0, 0, 0, zero, 0); return; @@ -512,6 +533,14 @@ with_result_response_handler (void *cls, NULL, 0, NULL, 0, 0, 0, zero, 0); return; } +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received result %llu with type %u and size %u with key %s\n", + (unsigned long long) GNUNET_ntohll(dm->uid), + ntohl(dm->type), + msize, + GNUNET_h2s(&dm->key)); +#endif cont (h->response_proc_cls, &dm->key, msize, @@ -558,6 +587,11 @@ transmit_get_result (void *cls, } GNUNET_assert (h->message_size <= size); memcpy (buf, &h[1], h->message_size); +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transmitted %u byte message to datastore service, now waiting for result.\n", + h->message_size); +#endif h->message_size = 0; GNUNET_CLIENT_receive (h->client, &with_result_response_handler, @@ -592,6 +626,12 @@ transmit_for_result (struct GNUNET_DATASTORE_Handle *h, hdr = (const struct GNUNET_MessageHeader*) &h[1]; msize = ntohs(hdr->size); +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transmitting %u byte message of type %u to datastore service\n", + msize, + ntohs(hdr->type)); +#endif GNUNET_assert (h->response_proc == NULL); h->response_proc = cont; h->response_proc_cls = cont_cls; diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index 9d13db05e..70d349693 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c @@ -38,6 +38,8 @@ #include "plugin_datastore.h" #include "datastore.h" +#define DEBUG_DATASTORE GNUNET_YES + /** * How many messages do we queue at most per client? */ @@ -197,10 +199,20 @@ transmit_callback (void *cls, msize = ntohs(tcc->msg->size); if (size == 0) { +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Transmission failed.\n"); +#endif if (tcc->tc != NULL) tcc->tc (tcc->tc_cls, GNUNET_SYSERR); if (GNUNET_YES == tcc->end) - GNUNET_SERVER_receive_done (tcc->client, GNUNET_SYSERR); + { +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Disconnecting client.\n"); +#endif + GNUNET_SERVER_receive_done (tcc->client, GNUNET_SYSERR); + } GNUNET_free (tcc->msg); GNUNET_free (tcc); return 0; @@ -210,7 +222,20 @@ transmit_callback (void *cls, if (tcc->tc != NULL) tcc->tc (tcc->tc_cls, GNUNET_OK); if (GNUNET_YES == tcc->end) - GNUNET_SERVER_receive_done (tcc->client, GNUNET_OK); + { +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Request completed, ready for the next request!\n"); +#endif + GNUNET_SERVER_receive_done (tcc->client, GNUNET_OK); + } + else + { +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Response transmitted, more pending!\n"); +#endif + } GNUNET_free (tcc->msg); GNUNET_free (tcc); return msize; @@ -251,7 +276,13 @@ transmit (struct GNUNET_SERVER_Client *client, { GNUNET_break (0); if (GNUNET_YES == end) - GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + { +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Disconnecting client.\n"); +#endif + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + } if (NULL != tc) tc (tc_cls, GNUNET_SYSERR); GNUNET_free (msg); @@ -275,6 +306,13 @@ transmit_status (struct GNUNET_SERVER_Client *client, struct StatusMessage *sm; size_t slen; +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transmitting `s' message with value %d and message %s\n", + "STATUS", + code, + msg); +#endif slen = (msg == NULL) ? 0 : strlen(msg) + 1; sm = GNUNET_malloc (sizeof(struct StatusMessage) + slen); sm->header.size = htons(sizeof(struct StatusMessage) + slen); @@ -345,6 +383,11 @@ transmit_item (void *cls, if (key == NULL) { /* transmit 'DATA_END' */ +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transmitting `%s' message\n", + "DATA_END"); +#endif end = GNUNET_malloc (sizeof(struct GNUNET_MessageHeader)); end->size = htons(sizeof(struct GNUNET_MessageHeader)); end->type = htons(GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END); @@ -364,6 +407,11 @@ transmit_item (void *cls, dm->uid = GNUNET_htonll(uid); dm->key = *key; memcpy (&dm[1], data, size); +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transmitting `%s' message\n", + "DATA"); +#endif transmit (client, &dm->header, &get_next, next_cls, GNUNET_NO); return GNUNET_OK; } @@ -384,7 +432,12 @@ handle_reserve (void *cls, const struct ReserveMessage *msg = (const struct ReserveMessage*) message; struct ReservationList *e; - /* FIXME: check if we have that much space... */ +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Processing `%s' request\n", + "RESERVE"); +#endif + /* FIXME: check if we have that much space... */ e = GNUNET_malloc (sizeof(struct ReservationList)); e->next = reservations; reservations = e; @@ -414,8 +467,13 @@ handle_release_reserve (void *cls, struct ReservationList *pos; struct ReservationList *prev; struct ReservationList *next; - int rid = ntohl(msg->rid); + +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Processing `%s' request\n", + "RELEASE_RESERVE"); +#endif next = reservations; prev = NULL; while (NULL != (pos = next)) @@ -490,6 +548,11 @@ handle_put (void *cls, int ret; int rid; +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Processing `%s' request\n", + "PUT"); +#endif if (dm == NULL) { GNUNET_break (0); @@ -537,6 +600,11 @@ handle_get (void *cls, const struct GetMessage *msg; uint16_t size; +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Processing `%s' request\n", + "GET"); +#endif size = ntohs(message->size); if ( (size != sizeof(struct GetMessage)) && (size != sizeof(struct GetMessage) - sizeof(GNUNET_HashCode)) ) @@ -581,6 +649,11 @@ handle_update (void *cls, int ret; char *emsg; +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Processing `%s' request\n", + "UPDATE"); +#endif msg = (const struct UpdateMessage*) message; emsg = NULL; ret = plugin->api->update (plugin->api->cls, @@ -605,7 +678,12 @@ handle_get_random (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { - GNUNET_SERVER_client_drop (client); +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Processing `%s' request\n", + "GET_RANDOM"); +#endif + GNUNET_SERVER_client_drop (client); // FIXME: WTF? plugin->api->iter_migration_order (plugin->api->cls, 0, &transmit_item, @@ -681,6 +759,11 @@ handle_remove (void *cls, GNUNET_HashCode vhash; struct RemoveContext *rc; +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Processing `%s' request\n", + "REMOVE"); +#endif if (dm == NULL) { GNUNET_break (0); @@ -714,6 +797,11 @@ handle_drop (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { +#if DEBUG_DATASTORE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Processing `%s' request\n", + "DROP"); +#endif plugin->api->drop (plugin->api->cls); GNUNET_SERVER_receive_done (client, GNUNET_OK); } diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index afc36b708..e9545bbf1 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.c @@ -33,11 +33,15 @@ #include "gnunet_protocols.h" #include "gnunet_datastore_service.h" +#define VERBOSE GNUNET_YES + /** * How long until we give up on transmitting the message? */ #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) +#define ITERATIONS 256 + static struct GNUNET_DATASTORE_Handle *datastore; static struct GNUNET_TIME_Absolute now; @@ -250,7 +254,13 @@ run_continuation (void *cls, switch (crc->phase) { case RP_PUT: - memset (&crc->key, 256 - crc->i, sizeof (GNUNET_HashCode)); +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Executing `%s' number %u\n", + "PUT", + crc->i); +#endif + memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode)); GNUNET_DATASTORE_put (datastore, 0, &crc->key, @@ -264,12 +274,18 @@ run_continuation (void *cls, &check_success, crc); crc->i++; - if (crc->i == 256) + if (crc->i == ITERATIONS) crc->phase = RP_GET; break; case RP_GET: crc->i--; - memset (&crc->key, 256 - crc->i, sizeof (GNUNET_HashCode)); +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Executing `%s' number %u\n", + "GET", + crc->i); +#endif + memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode)); GNUNET_DATASTORE_get (datastore, &crc->key, get_type (crc->i), @@ -279,12 +295,18 @@ run_continuation (void *cls, if (crc->i == 0) { crc->phase = RP_DEL; - crc->i = 256; + crc->i = ITERATIONS; } break; case RP_DEL: crc->i--; - memset (&crc->key, 256 - crc->i, sizeof (GNUNET_HashCode)); +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Executing `%s' number %u\n", + "DEL", + crc->i); +#endif + memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode)); GNUNET_DATASTORE_get (datastore, &crc->key, get_type (crc->i), @@ -294,12 +316,18 @@ run_continuation (void *cls, if (crc->i == 0) { crc->phase = RP_DELVALIDATE; - crc->i = 256; + crc->i = ITERATIONS; } break; case RP_DELVALIDATE: crc->i--; - memset (&crc->key, 256 - crc->i, sizeof (GNUNET_HashCode)); +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Executing `%s' number %u\n", + "DEL-VALIDATE", + crc->i); +#endif + memset (&crc->key, ITERATIONS - crc->i, sizeof (GNUNET_HashCode)); GNUNET_DATASTORE_get (datastore, &crc->key, get_type (crc->i), @@ -315,6 +343,10 @@ run_continuation (void *cls, /* check update */ /* test multiple results */ case RP_DONE: +#if VERBOSE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Finished, disconnecting\n"); +#endif GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); ok = 0; } -- 2.25.1