Handle entry in WantlistQueue only once if we found provider
This commit is contained in:
parent
3fa822aed6
commit
e58909b875
4 changed files with 14 additions and 4 deletions
|
@ -127,7 +127,7 @@ int ipfs_bitswap_get_block(struct Exchange* exchange, struct Cid* cid, struct Bl
|
||||||
// loop waiting for it to fill
|
// loop waiting for it to fill
|
||||||
while(1) {
|
while(1) {
|
||||||
if (want_entry->block != NULL) {
|
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)
|
// error or not, we no longer need the block (decrement reference count)
|
||||||
ipfs_bitswap_want_manager_remove(bitswapContext, cid);
|
ipfs_bitswap_want_manager_remove(bitswapContext, cid);
|
||||||
if (*block == NULL) {
|
if (*block == NULL) {
|
||||||
|
|
|
@ -134,8 +134,14 @@ struct WantListQueueEntry* ipfs_bitswap_wantlist_queue_pop(struct WantListQueue*
|
||||||
|
|
||||||
//TODO: This should be a linked list, not an array
|
//TODO: This should be a linked list, not an array
|
||||||
pthread_mutex_lock(&wantlist->wantlist_mutex);
|
pthread_mutex_lock(&wantlist->wantlist_mutex);
|
||||||
entry = (struct WantListQueueEntry*)libp2p_utils_vector_get(wantlist->queue, 0);
|
for(int i = 0; i < wantlist->queue->total; i++) {
|
||||||
libp2p_utils_vector_delete(wantlist->queue, 0);
|
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);
|
pthread_mutex_unlock(&wantlist->wantlist_mutex);
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
@ -156,6 +162,7 @@ struct WantListQueueEntry* ipfs_bitswap_wantlist_queue_entry_new() {
|
||||||
entry->cid = NULL;
|
entry->cid = NULL;
|
||||||
entry->priority = 0;
|
entry->priority = 0;
|
||||||
entry->attempts = 0;
|
entry->attempts = 0;
|
||||||
|
entry->asked_network = 0;
|
||||||
}
|
}
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
@ -284,6 +291,8 @@ int ipfs_bitswap_wantlist_process_entry(struct BitswapContext* context, struct W
|
||||||
// a final decision. Maybe lower the priority?
|
// a final decision. Maybe lower the priority?
|
||||||
entry->attempts++;
|
entry->attempts++;
|
||||||
return 0;
|
return 0;
|
||||||
|
} else {
|
||||||
|
entry->asked_network = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (entry->block != NULL) {
|
if (entry->block != NULL) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ struct WantListQueueEntry {
|
||||||
// a vector of WantListSessions
|
// a vector of WantListSessions
|
||||||
struct Libp2pVector* sessionsRequesting;
|
struct Libp2pVector* sessionsRequesting;
|
||||||
struct Block* block;
|
struct Block* block;
|
||||||
|
int asked_network;
|
||||||
int attempts;
|
int attempts;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -322,7 +322,7 @@ int test_bitswap_retrieve_file_known_remote() {
|
||||||
goto exit;
|
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);
|
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;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue