Clean up when we receive a block we wanted
This commit is contained in:
parent
e5e565272e
commit
5910d63c3d
4 changed files with 20 additions and 9 deletions
|
@ -87,9 +87,15 @@ int ipfs_bitswap_close(struct Exchange* exchange) {
|
|||
* adds the block to the blockstore. This still has to be sorted.
|
||||
*/
|
||||
int ipfs_bitswap_has_block(struct Exchange* exchange, struct Block* block) {
|
||||
//TODO: Implement this method
|
||||
// NOTE: The GO version adds the block to the blockstore. I have yet to
|
||||
// understand the flow and if this is correct for us.
|
||||
// add the block to the blockstore
|
||||
struct BitswapContext* context = exchange->exchangeContext;
|
||||
context->ipfsNode->blockstore->Put(context->ipfsNode->blockstore->blockstoreContext, block);
|
||||
// update requests
|
||||
struct WantListQueueEntry* queueEntry = ipfs_bitswap_wantlist_queue_find(context->localWantlist, block->cid);
|
||||
if (queueEntry != NULL) {
|
||||
queueEntry->block = block;
|
||||
}
|
||||
// TODO: Announce to world that we now have the block
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,6 @@ void* ipfs_bitswap_engine_peer_request_processor_start(void* ctx) {
|
|||
while (!context->bitswap_engine->shutting_down) {
|
||||
struct PeerRequest* item = ipfs_bitswap_peer_request_queue_pop(context->peerRequestQueue);
|
||||
if (item != NULL) {
|
||||
// Do they have something on the network to process?
|
||||
// did they send us something over the network?
|
||||
unsigned char* buffer = NULL;
|
||||
size_t buffer_len = 0;
|
||||
|
|
|
@ -206,14 +206,16 @@ struct PeerRequest* ipfs_bitswap_peer_request_queue_pop(struct PeerRequestQueue*
|
|||
pthread_mutex_lock(&queue->queue_mutex);
|
||||
struct PeerRequestEntry* entry = queue->first;
|
||||
if (entry != NULL) {
|
||||
if (ipfs_bitswap_peer_request_something_to_do(entry)) {
|
||||
retVal = entry->current;
|
||||
if (ipfs_bitswap_peer_request_something_to_do(entry)) {
|
||||
// move to the end of the queue
|
||||
if (queue->first->next != NULL) {
|
||||
queue->first = queue->first->next;
|
||||
queue->last->next = entry;
|
||||
queue->last = entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&queue->queue_mutex);
|
||||
// disable temporarily
|
||||
// JMJ Debugging
|
||||
|
@ -348,9 +350,13 @@ struct PeerRequest* ipfs_peer_request_queue_find_peer(struct PeerRequestQueue* q
|
|||
}
|
||||
}
|
||||
|
||||
// we didn't find one, so create one
|
||||
entry = ipfs_bitswap_peer_request_entry_new();
|
||||
entry->current = ipfs_bitswap_peer_request_new();
|
||||
entry->current->peer = peer;
|
||||
// attach it to the queue
|
||||
if (queue->first == NULL)
|
||||
queue->first = entry;
|
||||
entry->prior = queue->last;
|
||||
queue->last = entry;
|
||||
|
||||
|
|
|
@ -293,7 +293,7 @@ int ipfs_bitswap_wantlist_process_entry(struct BitswapContext* context, struct W
|
|||
// TODO: Review this code.
|
||||
struct WantListSession* session = (struct WantListSession*) libp2p_utils_vector_get(entry->sessionsRequesting, i);
|
||||
if (session->type == WANTLIST_SESSION_TYPE_LOCAL) {
|
||||
context->ipfsNode->exchange->HasBlock(context->ipfsNode->exchange, entry->block);
|
||||
//context->ipfsNode->exchange->HasBlock(context->ipfsNode->exchange, entry->block);
|
||||
} else {
|
||||
struct Libp2pPeer* peer = (struct Libp2pPeer*) session->context;
|
||||
ipfs_bitswap_peer_request_queue_fill(context->peerRequestQueue, peer, entry->block);
|
||||
|
|
Loading…
Reference in a new issue