*/
#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
cont = pm->cont;
cont_cls = pm->cont_cls;
destroy_pending_message_list_entry (pml);
- cont (cont_cls, 0);
+ cont (cont_cls, tpid);
}
/**
* 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)));
}
/* 1) check if we have already (recently) forwarded to this peer */
for (i=0;i<pr->used_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!
{
#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 (),
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;
"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);
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,