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.
|
* adds the block to the blockstore. This still has to be sorted.
|
||||||
*/
|
*/
|
||||||
int ipfs_bitswap_has_block(struct Exchange* exchange, struct Block* block) {
|
int ipfs_bitswap_has_block(struct Exchange* exchange, struct Block* block) {
|
||||||
//TODO: Implement this method
|
// add the block to the blockstore
|
||||||
// NOTE: The GO version adds the block to the blockstore. I have yet to
|
struct BitswapContext* context = exchange->exchangeContext;
|
||||||
// understand the flow and if this is correct for us.
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,6 @@ void* ipfs_bitswap_engine_peer_request_processor_start(void* ctx) {
|
||||||
while (!context->bitswap_engine->shutting_down) {
|
while (!context->bitswap_engine->shutting_down) {
|
||||||
struct PeerRequest* item = ipfs_bitswap_peer_request_queue_pop(context->peerRequestQueue);
|
struct PeerRequest* item = ipfs_bitswap_peer_request_queue_pop(context->peerRequestQueue);
|
||||||
if (item != NULL) {
|
if (item != NULL) {
|
||||||
// Do they have something on the network to process?
|
|
||||||
// did they send us something over the network?
|
// did they send us something over the network?
|
||||||
unsigned char* buffer = NULL;
|
unsigned char* buffer = NULL;
|
||||||
size_t buffer_len = 0;
|
size_t buffer_len = 0;
|
||||||
|
|
|
@ -206,12 +206,14 @@ struct PeerRequest* ipfs_bitswap_peer_request_queue_pop(struct PeerRequestQueue*
|
||||||
pthread_mutex_lock(&queue->queue_mutex);
|
pthread_mutex_lock(&queue->queue_mutex);
|
||||||
struct PeerRequestEntry* entry = queue->first;
|
struct PeerRequestEntry* entry = queue->first;
|
||||||
if (entry != NULL) {
|
if (entry != NULL) {
|
||||||
|
retVal = entry->current;
|
||||||
if (ipfs_bitswap_peer_request_something_to_do(entry)) {
|
if (ipfs_bitswap_peer_request_something_to_do(entry)) {
|
||||||
retVal = entry->current;
|
|
||||||
// move to the end of the queue
|
// move to the end of the queue
|
||||||
queue->first = queue->first->next;
|
if (queue->first->next != NULL) {
|
||||||
queue->last->next = entry;
|
queue->first = queue->first->next;
|
||||||
queue->last = entry;
|
queue->last->next = entry;
|
||||||
|
queue->last = entry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&queue->queue_mutex);
|
pthread_mutex_unlock(&queue->queue_mutex);
|
||||||
|
@ -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 = ipfs_bitswap_peer_request_entry_new();
|
||||||
entry->current = ipfs_bitswap_peer_request_new();
|
entry->current = ipfs_bitswap_peer_request_new();
|
||||||
entry->current->peer = peer;
|
entry->current->peer = peer;
|
||||||
|
// attach it to the queue
|
||||||
|
if (queue->first == NULL)
|
||||||
|
queue->first = entry;
|
||||||
entry->prior = queue->last;
|
entry->prior = queue->last;
|
||||||
queue->last = entry;
|
queue->last = entry;
|
||||||
|
|
||||||
|
|
|
@ -293,7 +293,7 @@ int ipfs_bitswap_wantlist_process_entry(struct BitswapContext* context, struct W
|
||||||
// TODO: Review this code.
|
// TODO: Review this code.
|
||||||
struct WantListSession* session = (struct WantListSession*) libp2p_utils_vector_get(entry->sessionsRequesting, i);
|
struct WantListSession* session = (struct WantListSession*) libp2p_utils_vector_get(entry->sessionsRequesting, i);
|
||||||
if (session->type == WANTLIST_SESSION_TYPE_LOCAL) {
|
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 {
|
} else {
|
||||||
struct Libp2pPeer* peer = (struct Libp2pPeer*) session->context;
|
struct Libp2pPeer* peer = (struct Libp2pPeer*) session->context;
|
||||||
ipfs_bitswap_peer_request_queue_fill(context->peerRequestQueue, peer, entry->block);
|
ipfs_bitswap_peer_request_queue_fill(context->peerRequestQueue, peer, entry->block);
|
||||||
|
|
Loading…
Reference in a new issue