Return a copy of the block from the exchange, not the block itself
Returning the block itself will cause problems when a client deallocates the block.
This commit is contained in:
parent
f69ab92469
commit
98b1e0fef4
3 changed files with 9 additions and 4 deletions
|
@ -183,7 +183,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 = want_entry->block;
|
||||
*block = ipfs_block_copy(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) {
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
int ipfs_bitswap_network_send_message(const struct BitswapContext* context, struct Libp2pPeer* peer, const struct BitswapMessage* message) {
|
||||
libp2p_logger_debug("bitswap_network", "Sending bitswap message to %s.\n", libp2p_peer_id_to_string(peer));
|
||||
// get a connection to the peer
|
||||
if (peer->connection_type != CONNECTION_TYPE_CONNECTED) {
|
||||
if (peer->connection_type != CONNECTION_TYPE_CONNECTED || peer->sessionContext == NULL) {
|
||||
libp2p_peer_connect(&context->ipfsNode->identity->private_key, peer, context->ipfsNode->peerstore, context->ipfsNode->repo->config->datastore, 10);
|
||||
if(peer->connection_type != CONNECTION_TYPE_CONNECTED)
|
||||
return 0;
|
||||
|
|
|
@ -381,8 +381,9 @@ int test_bitswap_retrieve_file_third_party() {
|
|||
libp2p_logger_add_class("providerstore");
|
||||
libp2p_logger_add_class("peerstore");
|
||||
libp2p_logger_add_class("exporter");
|
||||
libp2p_logger_add_class("peer");
|
||||
*/
|
||||
libp2p_logger_add_class("peer");
|
||||
libp2p_logger_add_class("bitswap_network");
|
||||
libp2p_logger_add_class("test_bitswap");
|
||||
libp2p_logger_add_class("null");
|
||||
libp2p_logger_add_class("online");
|
||||
|
@ -398,6 +399,7 @@ int test_bitswap_retrieve_file_third_party() {
|
|||
struct Libp2pVector* ma_vector2 = NULL, *ma_vector3 = NULL;
|
||||
struct HashtableNode* node = NULL;
|
||||
struct Block* result = NULL;
|
||||
struct HashtableNode* result_node = NULL;
|
||||
struct Cid* cid = NULL;
|
||||
|
||||
// create peer 1
|
||||
|
@ -468,7 +470,8 @@ int test_bitswap_retrieve_file_third_party() {
|
|||
goto exit;
|
||||
}
|
||||
|
||||
if (node->data_size != result->data_length) {
|
||||
ipfs_merkledag_convert_block_to_node(result, &result_node);
|
||||
if (node->data_size != result_node->data_size) {
|
||||
libp2p_logger_error("test_bitswap", "Result sizes do not match. Should be %lu but is %lu\n", node->data_size, result->data_length);
|
||||
goto exit;
|
||||
}
|
||||
|
@ -498,6 +501,8 @@ int test_bitswap_retrieve_file_third_party() {
|
|||
ipfs_hashtable_node_free(node);
|
||||
if (result != NULL)
|
||||
ipfs_block_free(result);
|
||||
if (result_node != NULL)
|
||||
ipfs_hashtable_node_free(result_node);
|
||||
if (cid != NULL)
|
||||
ipfs_cid_free(cid);
|
||||
return retVal;
|
||||
|
|
Loading…
Reference in a new issue