From d7d47265d3680eee277723f420db1baa455ccbb8 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 19 Oct 2009 15:34:53 +0000 Subject: [PATCH] debug code and fixes --- src/fs/fs_download.c | 42 ++++++++++++++++++++++++++--- src/fs/gnunet-service-fs.c | 44 +++++++++++++++++++++++++++++++ src/fs/test_fs_download_data.conf | 1 + 3 files changed, 83 insertions(+), 4 deletions(-) diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 6d3886c70..e6342a067 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -302,8 +302,15 @@ process_result (struct GNUNET_FS_DownloadContext *dc, struct ContentHashKey *chk; char *emsg; + GNUNET_CRYPTO_hash (data, size, &query); - sm = GNUNET_CONTAINER_multihashmap_get (dc->active, +#if DEBUG_DOWNLOAD + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received result for query `%s' from `%s'-service\n", + GNUNET_h2s (&query), + "FS"); +#endif + sm = GNUNET_CONTAINER_multihashmap_get (dc->active, &query); if (NULL == sm) { @@ -315,6 +322,10 @@ process_result (struct GNUNET_FS_DownloadContext *dc, sm->offset, sm->depth)) { +#if DEBUG_DOWNLOAD + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Internal error or bogus download URI\n"); +#endif dc->emsg = GNUNET_strdup ("Internal error or bogus download URI"); /* signal error */ pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR; @@ -347,6 +358,11 @@ process_result (struct GNUNET_FS_DownloadContext *dc, sm->depth, dc->treedepth); emsg = NULL; +#if DEBUG_DOWNLOAD + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Saving decrypted block to disk at offset %llu\n", + (unsigned long long) off); +#endif if ( (off != GNUNET_DISK_file_seek (dc->handle, off, @@ -415,6 +431,11 @@ process_result (struct GNUNET_FS_DownloadContext *dc, GNUNET_assert (dc->completed <= dc->length); if (dc->completed == dc->length) { +#if DEBUG_DOWNLOAD + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Download completed, truncating file to desired length %llu\n", + (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length)); +#endif /* truncate file to size (since we store IBlocks at the end) */ if (dc->handle != NULL) { @@ -436,6 +457,11 @@ process_result (struct GNUNET_FS_DownloadContext *dc, // FIXME: make persistent if (sm->depth == dc->treedepth) return; +#if DEBUG_DOWNLOAD + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Triggering downloads of children (this block was at level %u)\n", + dc->treedepth); +#endif GNUNET_assert (0 == (size % sizeof(struct ContentHashKey))); chk = (struct ContentHashKey*) pt; for (i=0;i<(size / sizeof(struct ContentHashKey));i++) @@ -519,9 +545,15 @@ transmit_download_request (void *cls, GNUNET_assert (size >= sizeof (struct SearchMessage)); msize = 0; sm = buf; - while ( (dc->pending == NULL) && + while ( (dc->pending != NULL) && (size > msize + sizeof (struct SearchMessage)) ) { +#if DEBUG_DOWNLOAD + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transmitting download request for `%s' to `%s'-service\n", + GNUNET_h2s (&dc->pending->chk.query), + "FS"); +#endif memset (sm, 0, sizeof (struct SearchMessage)); sm->header.size = htons (sizeof (struct SearchMessage)); sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); @@ -557,6 +589,9 @@ do_reconnect (void *cls, dc->h->cfg); if (NULL == client) { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Connecting to `%s'-service failed, will try again.\n", + "FS"); try_reconnect (dc); return; } @@ -574,8 +609,7 @@ do_reconnect (void *cls, /** - * Add entries that are not yet pending back to - * the pending list. + * Add entries that are not yet pending back to the pending list. * * @param cls our download context * @param key unused diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index b01a4f29e..ac2f9f408 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -1312,6 +1312,10 @@ transmit_local_result (void *cls, if (NULL == buf) { +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Failed to transmit result to local client, aborting datastore iteration.\n"); +#endif /* error, abort! */ GNUNET_free (lgc->result); lgc->result = NULL; @@ -1319,6 +1323,11 @@ transmit_local_result (void *cls, return 0; } msize = ntohs (lgc->result->header.size); +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transmitting %u bytes of result to local client.\n", + msize); +#endif GNUNET_assert (max >= msize); memcpy (buf, lgc->result, msize); GNUNET_free (lgc->result); @@ -1895,6 +1904,11 @@ process_local_get_result (void *cls, if (key == NULL) { +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received last result for `%s' from local datastore, deciding what to do next.\n", + GNUNET_h2s (&lgc->query)); +#endif /* no further results from datastore; continue processing further requests from the client and allow the next task to use the datastore; also, @@ -1907,6 +1921,11 @@ process_local_get_result (void *cls, (lgc->type == GNUNET_DATASTORE_BLOCKTYPE_SBLOCK) || (lgc->type == GNUNET_DATASTORE_BLOCKTYPE_SKBLOCK) ) { +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Forwarding query for `%s' to network.\n", + GNUNET_h2s (&lgc->query)); +#endif cl = clients; while ( (NULL != cl) && (cl->client != lgc->client) ) @@ -1960,11 +1979,21 @@ process_local_get_result (void *cls, return; } /* got all possible results, clean up! */ +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Found all possible results for query for `%s', done!\n", + GNUNET_h2s (&lgc->query)); +#endif local_get_context_free (lgc); return; } if (type == GNUNET_DATASTORE_BLOCKTYPE_ONDEMAND) { +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received on-demand block for `%s' from local datastore, fetching data.\n", + GNUNET_h2s (&lgc->query)); +#endif handle_on_demand_block (key, size, data, type, priority, anonymity, expiration, uid, &process_local_get_result, @@ -1977,6 +2006,11 @@ process_local_get_result (void *cls, query hash being identical to KBLOCK/SBLOCK query hash); nevertheless, if it happens, the correct thing is to simply skip the result. */ +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received block of unexpected type for `%s' from local datastore, ignoring.\n", + GNUNET_h2s (&lgc->query)); +#endif GNUNET_DATASTORE_get_next (dsh, GNUNET_YES); return; } @@ -1987,6 +2021,11 @@ process_local_get_result (void *cls, &lgc->results[i], sizeof (GNUNET_HashCode))) { +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received duplicate result for `%s' from local datastore, ignoring.\n", + GNUNET_h2s (&lgc->query)); +#endif GNUNET_DATASTORE_get_next (dsh, GNUNET_YES); return; } @@ -2007,6 +2046,11 @@ process_local_get_result (void *cls, memcpy (&lgc->result[1], data, size); +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received new result for `%s' from local datastore, passing to client.\n", + GNUNET_h2s (&lgc->query)); +#endif GNUNET_SERVER_notify_transmit_ready (lgc->client, msize, GNUNET_TIME_UNIT_FOREVER_REL, diff --git a/src/fs/test_fs_download_data.conf b/src/fs/test_fs_download_data.conf index 312c33d22..41678142c 100644 --- a/src/fs/test_fs_download_data.conf +++ b/src/fs/test_fs_download_data.conf @@ -36,6 +36,7 @@ HOSTNAME = localhost [fs] PORT = 42471 HOSTNAME = localhost +DEBUG = YES [testing] WEAKRANDOM = YES -- 2.25.1