Handle entry in WantlistQueue only once if we found provider

This commit is contained in:
John Jones 2017-08-02 11:43:48 -05:00
parent 3fa822aed6
commit e58909b875
4 changed files with 14 additions and 4 deletions

View file

@ -127,7 +127,7 @@ int ipfs_bitswap_get_block(struct Exchange* exchange, struct Cid* cid, struct Bl
// loop waiting for it to fill
while(1) {
if (want_entry->block != NULL) {
*block = ipfs_block_copy(want_entry->block);
*block = want_entry->block;
// error or not, we no longer need the block (decrement reference count)
ipfs_bitswap_want_manager_remove(bitswapContext, cid);
if (*block == NULL) {

View file

@ -134,8 +134,14 @@ struct WantListQueueEntry* ipfs_bitswap_wantlist_queue_pop(struct WantListQueue*
//TODO: This should be a linked list, not an array
pthread_mutex_lock(&wantlist->wantlist_mutex);
entry = (struct WantListQueueEntry*)libp2p_utils_vector_get(wantlist->queue, 0);
libp2p_utils_vector_delete(wantlist->queue, 0);
for(int i = 0; i < wantlist->queue->total; i++) {
struct WantListQueueEntry* current = (struct WantListQueueEntry*)libp2p_utils_vector_get(wantlist->queue, i);
if (current->block == NULL && !current->asked_network) {
entry = current;
break;
}
}
//libp2p_utils_vector_delete(wantlist->queue, 0);
pthread_mutex_unlock(&wantlist->wantlist_mutex);
return entry;
}
@ -156,6 +162,7 @@ struct WantListQueueEntry* ipfs_bitswap_wantlist_queue_entry_new() {
entry->cid = NULL;
entry->priority = 0;
entry->attempts = 0;
entry->asked_network = 0;
}
return entry;
}
@ -284,6 +291,8 @@ int ipfs_bitswap_wantlist_process_entry(struct BitswapContext* context, struct W
// a final decision. Maybe lower the priority?
entry->attempts++;
return 0;
} else {
entry->asked_network = 1;
}
}
if (entry->block != NULL) {

View file

@ -23,6 +23,7 @@ struct WantListQueueEntry {
// a vector of WantListSessions
struct Libp2pVector* sessionsRequesting;
struct Block* block;
int asked_network;
int attempts;
};

View file

@ -322,7 +322,7 @@ int test_bitswap_retrieve_file_known_remote() {
goto exit;
}
if (strlen(hello_world_hash) != result->cid->hash_length) {
if (cid->hash_length != result->cid->hash_length) {
libp2p_logger_error("test_bitswap", "Node hash sizes do not match. Should be %lu but is %lu\n", strlen(hello_world_hash), result->cid->hash_length);
goto exit;
}