diff --git a/exchange/bitswap/bitswap.c b/exchange/bitswap/bitswap.c index b8808fb..903ef46 100644 --- a/exchange/bitswap/bitswap.c +++ b/exchange/bitswap/bitswap.c @@ -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) { diff --git a/exchange/bitswap/wantlist_queue.c b/exchange/bitswap/wantlist_queue.c index b6f2ecf..3e5d511 100644 --- a/exchange/bitswap/wantlist_queue.c +++ b/exchange/bitswap/wantlist_queue.c @@ -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) { diff --git a/include/ipfs/exchange/bitswap/wantlist_queue.h b/include/ipfs/exchange/bitswap/wantlist_queue.h index 21f6a59..2a854c5 100644 --- a/include/ipfs/exchange/bitswap/wantlist_queue.h +++ b/include/ipfs/exchange/bitswap/wantlist_queue.h @@ -23,6 +23,7 @@ struct WantListQueueEntry { // a vector of WantListSessions struct Libp2pVector* sessionsRequesting; struct Block* block; + int asked_network; int attempts; }; diff --git a/test/exchange/test_bitswap.h b/test/exchange/test_bitswap.h index d4e90db..10d0ba4 100644 --- a/test/exchange/test_bitswap.h +++ b/test/exchange/test_bitswap.h @@ -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; }