correctly handling send of wantlist

This commit is contained in:
John Jones 2017-08-02 09:04:37 -05:00
parent 986d054c6c
commit 9131559a04
3 changed files with 18 additions and 5 deletions

View file

@ -216,7 +216,7 @@ void* ipfs_null_listen (void *ptr)
libp2p_logger_error("null", "Ipfs listening on %d\n", listen_param->port); libp2p_logger_error("null", "Ipfs listening on %d\n", listen_param->port);
for (;;) { for (;;) {
libp2p_logger_debug("null", "%s Attempting socket read\n", listen_param->local_node->identity->peer->id); libp2p_logger_debug("null", "%s Attempting socket read with fd %d.\n", listen_param->local_node->identity->peer->id, socketfd);
int numDescriptors = socket_read_select4(socketfd, 2); int numDescriptors = socket_read_select4(socketfd, 2);
if (null_shutting_down) { if (null_shutting_down) {
libp2p_logger_debug("null", "%s null_listen shutting down.\n", listen_param->local_node->identity->peer->id); libp2p_logger_debug("null", "%s null_listen shutting down.\n", listen_param->local_node->identity->peer->id);

View file

@ -4,6 +4,7 @@
#include "libp2p/utils/vector.h" #include "libp2p/utils/vector.h"
#include "ipfs/blocks/block.h" #include "ipfs/blocks/block.h"
#include "ipfs/exchange/bitswap/message.h" #include "ipfs/exchange/bitswap/message.h"
#include "ipfs/exchange/bitswap/peer_request_queue.h"
/*** /***
* Allocate memory for a struct BitswapBlock * Allocate memory for a struct BitswapBlock
@ -656,15 +657,15 @@ int ipfs_bitswap_message_add_wantlist_items(struct BitswapMessage* message, stru
return 0; return 0;
} }
for(int i = 0; i < cids->total; i++) { for(int i = 0; i < cids->total; i++) {
const struct Cid* cid = (const struct Cid*)libp2p_utils_vector_get(cids, i); const struct CidEntry* cidEntry = (const struct CidEntry*)libp2p_utils_vector_get(cids, i);
struct WantlistEntry* entry = ipfs_bitswap_wantlist_entry_new(); struct WantlistEntry* entry = ipfs_bitswap_wantlist_entry_new();
entry->block_size = ipfs_cid_protobuf_encode_size(cid); entry->block_size = ipfs_cid_protobuf_encode_size(cidEntry->cid);
entry->block = (unsigned char*) malloc(entry->block_size); entry->block = (unsigned char*) malloc(entry->block_size);
if (!ipfs_cid_protobuf_encode(cid, entry->block, entry->block_size, &entry->block_size)) { if (!ipfs_cid_protobuf_encode(cidEntry->cid, entry->block, entry->block_size, &entry->block_size)) {
// TODO: we should do more than return a half-baked list // TODO: we should do more than return a half-baked list
return 0; return 0;
} }
entry->cancel = 0; entry->cancel = cidEntry->cancel;
entry->priority = 1; entry->priority = 1;
libp2p_utils_vector_add(message->wantlist->entries, entry); libp2p_utils_vector_add(message->wantlist->entries, entry);
} }

View file

@ -269,6 +269,8 @@ int test_bitswap_retrieve_file_known_remote() {
int remote_port = 4001; int remote_port = 4001;
char* remote_peer_id = "QmZVoAZGFfinB7MQQiDzB84kWaDPQ95GLuXdemJFM2r9b4"; char* remote_peer_id = "QmZVoAZGFfinB7MQQiDzB84kWaDPQ95GLuXdemJFM2r9b4";
char* hello_world_hash = "QmTUFTVgkHT3Qdd9ospVjSLi2upd6VdkeNXZQH66cVmzja"; char* hello_world_hash = "QmTUFTVgkHT3Qdd9ospVjSLi2upd6VdkeNXZQH66cVmzja";
pthread_t thread;
int thread_started = 0;
/* /*
libp2p_logger_add_class("dht_protocol"); libp2p_logger_add_class("dht_protocol");
@ -304,6 +306,13 @@ int test_bitswap_retrieve_file_known_remote() {
multiaddress_free(ma_peer1); multiaddress_free(ma_peer1);
ipfs_node_online_new(ipfs_path, &ipfs_node2); ipfs_node_online_new(ipfs_path, &ipfs_node2);
// start the daemon in a separate thread
if (pthread_create(&thread, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0) {
libp2p_logger_error("test_bitswap", "Unable to start thread 2\n");
goto exit;
}
thread_started = 1;
if (!ipfs_cid_decode_hash_from_base58((unsigned char*)hello_world_hash, strlen(hello_world_hash), &cid)) if (!ipfs_cid_decode_hash_from_base58((unsigned char*)hello_world_hash, strlen(hello_world_hash), &cid))
goto exit; goto exit;
@ -320,6 +329,9 @@ int test_bitswap_retrieve_file_known_remote() {
retVal = 1; retVal = 1;
exit: exit:
ipfs_daemon_stop();
if (thread_started)
pthread_join(thread, NULL);
if (peer_id_1 != NULL) if (peer_id_1 != NULL)
free(peer_id_1); free(peer_id_1);
if (peer_id_2 != NULL) if (peer_id_2 != NULL)