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.
This commit is contained in:
Andrew Bettison 2012-11-12 16:21:38 +10:30
parent 2993ee46c7
commit b66d8d6c5b
3 changed files with 19 additions and 4 deletions

View File

@ -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;

View File

@ -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();
}

View File

@ -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 <andrew@servalproject.com>
*/
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 */