From 53727760823a5ea57629b0a9a6633e29744c739a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 25 Mar 2010 14:33:27 +0000 Subject: [PATCH] consider corking --- src/fs/gnunet-service-fs.c | 29 +++++++++++++++++------- src/fs/test_fs_namespace.c | 45 +++++++++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 16 deletions(-) diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 00683ba36..7a13840a2 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -53,6 +53,13 @@ */ #define MAX_QUEUE_PER_PEER 2 +/** + * Inverse of the probability that we will submit the same query + * to the same peer again. If the same peer already got the query + * repeatedly recently, the probability is multiplied by the inverse + * of this number each time. + */ +#define RETRY_PROBABILITY_INV 8 /** * What is the maximum delay for a P2P FS message (in our interaction @@ -631,7 +638,7 @@ destroy_pending_message (struct PendingMessage *pm, cont = pm->cont; cont_cls = pm->cont_cls; destroy_pending_message_list_entry (pml); - cont (cont_cls, 0); + cont (cont_cls, tpid); } @@ -1128,19 +1135,22 @@ test_load_too_high () /** * We use a random delay to make the timing of requests less - * predictable. This function returns such a random delay. + * predictable. This function returns such a random delay. We add a base + * delay of MAX_CORK_DELAY (1s). * * FIXME: make schedule dependent on the specifics of the request? * Or bandwidth and number of connected peers and load? * - * @return random delay to use for some request, between 0 and TTL_DECREMENT ms + * @return random delay to use for some request, between 1s and 1000+TTL_DECREMENT ms */ static struct GNUNET_TIME_Relative get_processing_delay () { - return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - TTL_DECREMENT)); + return + GNUNET_TIME_relative_add (GNUNET_CONSTANTS_MAX_CORK_DELAY, + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + TTL_DECREMENT))); } @@ -1462,7 +1472,9 @@ target_peer_select_cb (void *cls, /* 1) check if we have already (recently) forwarded to this peer */ for (i=0;iused_pids_off;i++) - if (pr->used_pids[i] == cp->pid) + if ( (pr->used_pids[i] == cp->pid) && + (0 != GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + RETRY_PROBABILITY_INV)) ) return GNUNET_YES; /* skip */ // 2) calculate how much we'd like to forward to this peer score = 42; // FIXME! @@ -1513,7 +1525,8 @@ forward_request_task (void *cls, { #if DEBUG_FS GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "No peer selected for forwarding!\n"); + "No peer selected for forwarding of query `%s'!\n", + GNUNET_h2s (&pr->query)); #endif pr->task = GNUNET_SCHEDULER_add_delayed (sched, get_processing_delay (), diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c index 0972730d2..48442f855 100644 --- a/src/fs/test_fs_namespace.c +++ b/src/fs/test_fs_namespace.c @@ -99,22 +99,51 @@ spcb (void *cls, static void publish_cont (void *cls, - const struct GNUNET_FS_Uri *uri, + const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) { struct GNUNET_FS_SearchContext *search; GNUNET_assert (NULL == emsg); - fprintf (stderr, "Starting namespace search...\n"); - search = GNUNET_FS_search_start (fs, uri, 1, "ns-search"); + fprintf (stderr, "Starting keyword search...\n"); + search = GNUNET_FS_search_start (fs, ksk_uri, 1, NULL); } + +static void +sks_cont (void *cls, + const struct GNUNET_FS_Uri *uri, + const char *emsg) +{ + struct GNUNET_CONTAINER_MetaData *meta; + struct GNUNET_TIME_Absolute expiration; + struct GNUNET_FS_Uri *ksk_uri; + char * msg; + + expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); + meta = GNUNET_CONTAINER_meta_data_create (); + msg = NULL; + ksk_uri = GNUNET_FS_uri_parse ("gnunet://fs/ksk/ns-search", &msg); + GNUNET_assert (NULL == msg); + fprintf (stderr, "Advertising update 'this' namespace entry under keyword...\n"); + GNUNET_FS_publish_ksk (fs, + ksk_uri, + meta, + uri, + expiration, + 1, 1, + GNUNET_FS_PUBLISH_OPTION_NONE, + &publish_cont, + NULL); + GNUNET_CONTAINER_meta_data_destroy (meta); +} + + static void adv_cont (void *cls, const struct GNUNET_FS_Uri *uri, const char *emsg) { - struct GNUNET_FS_SearchContext *search; struct GNUNET_CONTAINER_MetaData *meta; struct GNUNET_FS_Namespace *ns; struct GNUNET_TIME_Absolute expiration; @@ -124,18 +153,17 @@ adv_cont (void *cls, "testNamespace"); meta = GNUNET_CONTAINER_meta_data_create (); GNUNET_assert (NULL == emsg); - fprintf (stderr, "Starting namespace search...\n"); - search = GNUNET_FS_search_start (fs, uri, 1, "ns-search"); + fprintf (stderr, "Advertising update 'this->next' namespace update...\n"); GNUNET_FS_publish_sks (fs, ns, "this", "next", meta, - uri, + uri, /* FIXME: this is non-sense (use CHK URI!) */ expiration, 1, 1, GNUNET_FS_PUBLISH_OPTION_NONE, - &publish_cont, + &sks_cont, NULL); GNUNET_CONTAINER_meta_data_destroy (meta); GNUNET_FS_namespace_delete (ns, GNUNET_NO); @@ -153,6 +181,7 @@ testNamespace () meta = GNUNET_CONTAINER_meta_data_create (); ns = GNUNET_FS_namespace_create (fs, "testNamespace"); + fprintf (stderr, "Advertising namespace root...\n"); GNUNET_FS_namespace_advertise (fs, ns, meta, -- 2.25.1