From b66d8d6c5b10271ed03381b191d798e7c0fd87e7 Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Mon, 12 Nov 2012 16:21:38 +1030 Subject: [PATCH] Fix bug in 'rhizome direct pull' Was not fetching payload of remote bundle, just manifest. The problem was caused by a change of logic recently to not activate any queued fetch candidates immediately, but wait until the next fd_poll(), so that parsing a single packetful of rhizome advertisments would start fetching the most important one first, instead of the first one parsed. --- rhizome.h | 1 + rhizome_direct_http.c | 2 +- rhizome_fetch.c | 20 +++++++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/rhizome.h b/rhizome.h index 00ad0758..ab421cbf 100644 --- a/rhizome.h +++ b/rhizome.h @@ -554,6 +554,7 @@ enum rhizome_start_fetch_result { enum rhizome_start_fetch_result rhizome_fetch_request_manifest_by_prefix(const struct sockaddr_in *peerip, const unsigned char *prefix, size_t prefix_length); int rhizome_any_fetch_active(); +int rhizome_any_fetch_queued(); struct http_response_parts { int code; diff --git a/rhizome_direct_http.c b/rhizome_direct_http.c index 8be65c10..a867e5c7 100644 --- a/rhizome_direct_http.c +++ b/rhizome_direct_http.c @@ -881,7 +881,7 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r) /* Fetching the manifest, and then using it to see if we want to fetch the file for import is all handled asynchronously, so just wait for it to finish. */ - while (rhizome_any_fetch_active()) + while (rhizome_any_fetch_active() || rhizome_any_fetch_queued()) fd_poll(); } diff --git a/rhizome_fetch.c b/rhizome_fetch.c index 7ca60341..cd266a39 100644 --- a/rhizome_fetch.c +++ b/rhizome_fetch.c @@ -78,6 +78,7 @@ struct rhizome_fetch_candidate queue3[2]; struct rhizome_fetch_candidate queue4[1]; #define NELS(a) (sizeof (a) / sizeof *(a)) +#define slotno(slot) ((struct rhizome_fetch_queue *)(slot) - &rhizome_fetch_queues[0]) /* Static allocation of the queue structures. Must be in order of ascending size_threshold. */ @@ -188,6 +189,19 @@ int rhizome_any_fetch_active() return 0; } +/* Return true if there are any fetches queued. + * + * @author Andrew Bettison + */ +int rhizome_any_fetch_queued() +{ + int i; + for (i = 0; i < NQUEUES; ++i) + if (rhizome_fetch_queues[i].candidate_queue[0].manifest) + return 1; + return 0; +} + /* As defined below uses 64KB */ #define RHIZOME_VERSION_CACHE_NYBLS 2 /* 256=2^8=2nybls */ #define RHIZOME_VERSION_CACHE_SHIFT 1 @@ -573,7 +587,7 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m, const struct if (debug & DEBUG_RHIZOME_RX) DEBUGF("Fetching bundle slot=%d bid=%s version=%lld size=%lld peerip=%s", - slot - &rhizome_fetch_queues[0].active, + slotno(slot), bid, m->version, m->fileLength, @@ -668,7 +682,7 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m, const struct return -1; } if (debug & DEBUG_RHIZOME_RX) - DEBUGF(" started fetch into %s, slot=%d filehash=%s", slot->manifest->dataFileName, slot - &rhizome_fetch_queues[0].active, m->fileHexHash); + DEBUGF(" started fetch into %s, slot=%d filehash=%s", slot->manifest->dataFileName, slotno(slot), m->fileHexHash); return STARTED; } @@ -895,7 +909,7 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sock static int rhizome_fetch_close(struct rhizome_fetch_slot *slot) { if (debug & DEBUG_RHIZOME_RX) - DEBUGF("Close Rhizome fetch slot=%d", slot - &rhizome_fetch_queues[0].active); + DEBUGF("close Rhizome fetch slot=%d", slotno(slot)); assert(slot->state != RHIZOME_FETCH_FREE); /* close socket and stop watching it */