From 36b60a0ac26d8102667c590587b8a0d33c203cc9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 1 Feb 2010 13:02:01 +0000 Subject: [PATCH] die nicely --- src/fs/fs_download.c | 3 +- src/fs/gnunet-service-fs.c | 47 ++++++++++++++++++++++++++++--- src/fs/test_fs_download.c | 57 +++++++++++++++++++++++++++++--------- 3 files changed, 88 insertions(+), 19 deletions(-) diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 4b3d96082..b0e981b80 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -627,8 +627,7 @@ transmit_download_request (void *cls, /** - * Reconnect to the FS service and transmit - * our queries NOW. + * Reconnect to the FS service and transmit our queries NOW. * * @param cls our download context * @param tc unused diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 6860c377a..ead8ea17d 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -46,6 +46,8 @@ #include "gnunet-service-fs_indexing.h" #include "fs.h" +#define DEBUG_FS GNUNET_YES + /** * Maximum number of outgoing messages we queue per peer. * FIXME: set to a tiny value for testing; make configurable. @@ -53,7 +55,6 @@ #define MAX_QUEUE_PER_PEER 2 - /** * Maximum number of requests (from other peers) that we're * willing to have pending at any given point in time. @@ -1661,7 +1662,11 @@ process_reply (void *cls, size_t msize; uint32_t prio; - +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Matched result for query `%s' with pending request\n", + GNUNET_h2s (key)); +#endif GNUNET_CRYPTO_hash (prq->data, prq->size, &chash); @@ -1717,6 +1722,11 @@ process_reply (void *cls, pr->remaining_priority = 0; if (pr->client_request_list != NULL) { +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transmitting result for query `%s' to local client\n", + GNUNET_h2s (key)); +#endif cl = pr->client_request_list->client_list; msize = sizeof (struct PutMessage) + prq->size; creply = GNUNET_malloc (msize + sizeof (struct ClientResponseMessage)); @@ -1743,6 +1753,12 @@ process_reply (void *cls, else { cp = pr->pht_entry->cp; +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Transmitting result for query `%s' to other peer (PID=%u)\n", + GNUNET_h2s (key), + (unsigned int) cp->pid); +#endif msize = sizeof (struct ContentMessage) + prq->size; reply = GNUNET_malloc (msize + sizeof (struct PendingMessage)); reply->cont = &transmit_reply_continuation; @@ -1834,6 +1850,12 @@ handle_p2p_put (void *cls, return GNUNET_SYSERR; } +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received result for query `%s' from peer `%4s'\n", + GNUNET_h2s (&query), + GNUNET_i2s (other)); +#endif /* now, lookup 'query' */ prq.data = (const void*) &put[1]; prq.size = dsize; @@ -1921,11 +1943,16 @@ process_local_reply (void *cls, { #if DEBUG_FS GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Result from datastore filtered by bloomfilter.\n"); + "Result from datastore filtered by bloomfilter (duplicate).\n"); #endif GNUNET_FS_drq_get_next (GNUNET_YES); return; } +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Found result for query `%s' in local datastore\n", + GNUNET_h2s (key)); +#endif pr->results_found++; if ( (pr->type == GNUNET_DATASTORE_BLOCKTYPE_KBLOCK) || (pr->type == GNUNET_DATASTORE_BLOCKTYPE_SBLOCK) || @@ -2104,6 +2131,13 @@ handle_p2p_get (void *cls, return GNUNET_OK; } +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received request for `%s' of type %u from peer `%4s'\n", + GNUNET_h2s (&gm->query), + (unsigned int) ntohl (gm->type), + GNUNET_i2s (other)); +#endif pr = GNUNET_malloc (sizeof (struct PendingRequest) + (bm & GET_MESSAGE_BIT_SKS_NAMESPACE)?sizeof(GNUNET_HashCode):0); if ((bm & GET_MESSAGE_BIT_SKS_NAMESPACE)) @@ -2259,7 +2293,12 @@ handle_start_search (void *cls, client_list = cl; } type = ntohl (sm->type); - +#if DEBUG_FS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received request for `%s' of type %u from local client\n", + GNUNET_h2s (&sm->query), + (unsigned int) type); +#endif /* FIXME: detect duplicate request; if duplicate, simply update (merge) 'pr->replies_seen'! */ pr = GNUNET_malloc (sizeof (struct PendingRequest) + diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c index f528203ad..5cb9e4111 100644 --- a/src/fs/test_fs_download.c +++ b/src/fs/test_fs_download.c @@ -68,15 +68,39 @@ static struct GNUNET_FS_DownloadContext *download; static struct GNUNET_FS_PublishContext *publish; +static GNUNET_SCHEDULER_TaskIdentifier timeout_kill; + static char *fn; +static int err; + +static void +timeout_kill_task (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + if (publish != NULL) + { + GNUNET_FS_publish_stop (publish); + publish = NULL; + } + if (download != NULL) + { + GNUNET_FS_download_stop (download, GNUNET_YES); + download = NULL; + } + timeout_kill = GNUNET_SCHEDULER_NO_TASK; + err = 1; +} static void abort_publish_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - GNUNET_FS_publish_stop (publish); - publish = NULL; + if (publish != NULL) + { + GNUNET_FS_publish_stop (publish); + publish = NULL; + } } @@ -86,13 +110,18 @@ abort_download_task (void *cls, { uint64_t size; - GNUNET_FS_download_stop (download, GNUNET_YES); - download = NULL; + if (download != NULL) + { + GNUNET_FS_download_stop (download, GNUNET_YES); + download = NULL; + } GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_size (fn, &size, GNUNET_YES)); GNUNET_assert (size == FILESIZE); GNUNET_DISK_directory_remove (fn); GNUNET_free (fn); fn = NULL; + GNUNET_SCHEDULER_cancel (sched, timeout_kill); + timeout_kill = GNUNET_SCHEDULER_NO_TASK; } @@ -132,10 +161,9 @@ progress_cb (void *cls, case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: printf ("Download complete, %llu kbps.\n", (unsigned long long) (FILESIZE * 1000 / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024)); - GNUNET_SCHEDULER_add_continuation (sched, - &abort_download_task, - NULL, - GNUNET_SCHEDULER_REASON_PREREQ_DONE); + GNUNET_SCHEDULER_add_now (sched, + &abort_download_task, + NULL); break; case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: GNUNET_assert (download == event->value.download.dc); @@ -161,10 +189,9 @@ progress_cb (void *cls, fprintf (stderr, "Error downloading file: %s\n", event->value.download.specifics.error.message); - GNUNET_SCHEDULER_add_continuation (sched, - &abort_download_task, - NULL, - GNUNET_SCHEDULER_REASON_PREREQ_DONE); + GNUNET_SCHEDULER_add_now (sched, + &abort_download_task, + NULL); break; case GNUNET_FS_STATUS_PUBLISH_START: GNUNET_assert (0 == strcmp ("publish-context", event->value.publish.cctx)); @@ -282,6 +309,10 @@ run (void *cls, GNUNET_FS_uri_destroy (kuri); GNUNET_CONTAINER_meta_data_destroy (meta); GNUNET_assert (NULL != fi); + timeout_kill = GNUNET_SCHEDULER_add_delayed (sched, + TIMEOUT, + &timeout_kill_task, + NULL); start = GNUNET_TIME_absolute_get (); publish = GNUNET_FS_publish_start (fs, fi, @@ -319,7 +350,7 @@ main (int argc, char *argv[]) "nohelp", options, &run, NULL); stop_arm (&p1); GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/"); - return 0; + return err; } /* end of test_fs_download.c */ -- 2.25.1