Continue to listen to connected peers within bitswap engine
This commit is contained in:
parent
9131559a04
commit
e5e565272e
4 changed files with 38 additions and 9 deletions
|
@ -1,4 +1,5 @@
|
|||
#include <unistd.h>
|
||||
#include "ipfs/core/null.h"
|
||||
#include "ipfs/exchange/bitswap/engine.h"
|
||||
#include "ipfs/exchange/bitswap/wantlist_queue.h"
|
||||
#include "ipfs/exchange/bitswap/peer_request_queue.h"
|
||||
|
@ -59,6 +60,15 @@ 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;
|
||||
if (item->peer->sessionContext->default_stream->read(item->peer->sessionContext, &buffer, &buffer_len, 1)) {
|
||||
// handle it
|
||||
ipfs_multistream_marshal(buffer, buffer_len, item->peer->sessionContext, context->ipfsNode);
|
||||
}
|
||||
|
||||
// if there is something on the queue process it.
|
||||
ipfs_bitswap_peer_request_process_entry(context, item);
|
||||
} else {
|
||||
|
|
|
@ -184,6 +184,7 @@ int ipfs_bitswap_peer_request_cids_waiting(struct Libp2pVector* cidEntries) {
|
|||
int ipfs_bitswap_peer_request_something_to_do(struct PeerRequestEntry* entry) {
|
||||
if (entry != NULL) {
|
||||
struct PeerRequest* request = entry->current;
|
||||
// do we have something in the queue?
|
||||
if (request->blocks_we_want_to_send->total > 0)
|
||||
return 1;
|
||||
if (request->cids_we_want->total > 0)
|
||||
|
@ -204,9 +205,14 @@ struct PeerRequest* ipfs_bitswap_peer_request_queue_pop(struct PeerRequestQueue*
|
|||
if (queue != NULL) {
|
||||
pthread_mutex_lock(&queue->queue_mutex);
|
||||
struct PeerRequestEntry* entry = queue->first;
|
||||
if (entry != NULL && ipfs_bitswap_peer_request_something_to_do(entry)) {
|
||||
retVal = entry->current;
|
||||
queue->first = queue->first->next;
|
||||
if (entry != NULL) {
|
||||
if (ipfs_bitswap_peer_request_something_to_do(entry)) {
|
||||
retVal = entry->current;
|
||||
// move to the end of the queue
|
||||
queue->first = queue->first->next;
|
||||
queue->last->next = entry;
|
||||
queue->last = entry;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&queue->queue_mutex);
|
||||
// disable temporarily
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue