bug fixes to client side bitswap

This commit is contained in:
John Jones 2017-07-31 10:01:06 -05:00
parent 9bceade4d8
commit e22da601ea
6 changed files with 202 additions and 7 deletions

View file

@ -7,6 +7,7 @@
#include "ipfs/exchange/exchange.h"
#include "ipfs/exchange/bitswap/bitswap.h"
#include "ipfs/exchange/bitswap/message.h"
#include "ipfs/exchange/bitswap/peer_request_queue.h"
#include "ipfs/exchange/bitswap/want_manager.h"
/**
@ -28,8 +29,8 @@ struct Exchange* ipfs_bitswap_new(struct IpfsNode* ipfs_node) {
free(exchange);
return NULL;
}
bitswapContext->localWantlist = NULL;
bitswapContext->peerRequestQueue = NULL;
bitswapContext->localWantlist = ipfs_bitswap_wantlist_queue_new();
bitswapContext->peerRequestQueue = ipfs_bitswap_peer_request_queue_new();
bitswapContext->ipfsNode = ipfs_node;
exchange->exchangeContext = (void*) bitswapContext;
@ -109,7 +110,7 @@ int ipfs_bitswap_get_block(struct Exchange* exchange, struct Cid* cid, struct Bl
return 1;
// now ask the network
//NOTE: this timeout should be configurable
int timeout = 10;
int timeout = 60;
int waitSecs = 1;
int timeTaken = 0;
struct WantListSession wantlist_session;

View file

@ -139,10 +139,13 @@ struct PeerRequest* ipfs_bitswap_peer_request_queue_pop(struct PeerRequestQueue*
if (queue != NULL) {
pthread_mutex_lock(&queue->queue_mutex);
struct PeerRequestEntry* entry = queue->first;
retVal = entry->current;
queue->first = queue->first->next;
if (entry != NULL) {
retVal = entry->current;
queue->first = queue->first->next;
}
pthread_mutex_unlock(&queue->queue_mutex);
ipfs_bitswap_peer_request_entry_free(entry);
if (entry != NULL)
ipfs_bitswap_peer_request_entry_free(entry);
}
return retVal;
}

View file

@ -147,10 +147,14 @@ struct WantListQueueEntry* ipfs_bitswap_wantlist_queue_pop(struct WantListQueue*
struct WantListQueueEntry* ipfs_bitswap_wantlist_queue_entry_new() {
struct WantListQueueEntry* entry = (struct WantListQueueEntry*) malloc(sizeof(struct WantListQueueEntry));
if (entry != NULL) {
entry->sessionsRequesting = libp2p_utils_vector_new(1);
if (entry->sessionsRequesting == NULL) {
free(entry);
return NULL;
}
entry->block = NULL;
entry->cid = NULL;
entry->priority = 0;
entry->sessionsRequesting = NULL;
entry->attempts = 0;
}
return entry;