Updating tests
This commit is contained in:
parent
fc8fc582b1
commit
acf506296e
6 changed files with 29 additions and 66 deletions
|
@ -362,7 +362,7 @@ int ipfs_journal_handle_message(const uint8_t* incoming, size_t incoming_size, s
|
|||
}
|
||||
break;
|
||||
case (JOURNAL_REMOTE_NEEDS): {
|
||||
|
||||
// next time we sync, let them know that this file is available
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -230,7 +230,8 @@ int ipfs_namesys_publisher_publish(struct IpfsNode* local_node, struct Cid* cid)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int retVal = libp2p_routing_dht_send_message(local_node->identity->peer, local_node->providerstore, msg);
|
||||
int retVal = libp2p_routing_dht_send_message_nearest_x(&local_node->identity->private_key, local_node->peerstore, local_node->repo->config->datastore, msg, 10);
|
||||
|
||||
libp2p_message_free(msg);
|
||||
return retVal;
|
||||
}
|
||||
|
|
|
@ -23,51 +23,17 @@
|
|||
* @returns what was received
|
||||
*/
|
||||
struct KademliaMessage* ipfs_routing_online_send_receive_message(struct SessionContext* sessionContext, struct KademliaMessage* message) {
|
||||
size_t protobuf_size = 0, results_size = 0;
|
||||
unsigned char* protobuf = NULL, *results = NULL;
|
||||
struct KademliaMessage* return_message = NULL;
|
||||
//unsigned char* protocol = (unsigned char*)"/ipfs/kad/1.0.0\n";
|
||||
|
||||
protobuf_size = libp2p_message_protobuf_encode_size(message);
|
||||
protobuf = (unsigned char*)malloc(protobuf_size);
|
||||
libp2p_message_protobuf_encode(message, &protobuf[0], protobuf_size, &protobuf_size);
|
||||
|
||||
|
||||
// upgrade to kademlia protocol
|
||||
if (!libp2p_routing_dht_upgrade_stream(sessionContext)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
//if (!sessionContext->default_stream->write(sessionContext, protocol, strlen( (char*)protocol))) {
|
||||
// libp2p_logger_error("online", "Unable to switch to kademlia protocol.\n");
|
||||
//}
|
||||
|
||||
// send the message, and expect the same back
|
||||
if (!sessionContext->default_stream->write(sessionContext, protobuf, protobuf_size)) {
|
||||
if (!libp2p_routing_dht_send_message(sessionContext, message)) {
|
||||
libp2p_logger_error("online", "Attempted to write to Kademlia stream, but could not.\n");
|
||||
goto exit;
|
||||
} else {
|
||||
if (!libp2p_routing_dht_receive_message(sessionContext, &return_message)) {
|
||||
libp2p_logger_error("online", "Unable to receive kademlia message.\n");
|
||||
}
|
||||
}
|
||||
if (!sessionContext->default_stream->read(sessionContext, &results, &results_size, 5)) {
|
||||
libp2p_logger_error("online", "Attempted to read from Kademlia stream, but could not.\n");
|
||||
}
|
||||
|
||||
if (results_size == 0) {
|
||||
libp2p_logger_error("online", "reading kademlia header response returned nothing.\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// see if we can unprotobuf
|
||||
if (!libp2p_message_protobuf_decode(results, results_size, &return_message)) {
|
||||
libp2p_logger_error("online", "Received kademlia response, but cannot decode it.\n");
|
||||
goto exit;
|
||||
}
|
||||
exit:
|
||||
|
||||
if (protobuf != NULL)
|
||||
free(protobuf);
|
||||
if (results != NULL)
|
||||
free(results);
|
||||
|
||||
return return_message;
|
||||
}
|
||||
|
||||
|
|
|
@ -199,7 +199,7 @@ int test_bitswap_retrieve_file_remote() {
|
|||
ipfs_node_online_new(ipfs_path, &ipfs_node1);
|
||||
ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, ipfs_node1, &bytes_written, 0);
|
||||
// start the daemon in a separate thread
|
||||
if (pthread_create(&thread1, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0) {
|
||||
if (pthread_create(&thread1, NULL, test_daemon_start, (void*)ipfs_path) < 0) {
|
||||
libp2p_logger_error("test_bitswap", "Unable to start thread 1\n");
|
||||
goto exit;
|
||||
}
|
||||
|
@ -398,7 +398,7 @@ int test_bitswap_retrieve_file_third_party() {
|
|||
sprintf(multiaddress_string, "/ip4/127.0.0.1/tcp/4001/ipfs/%s", peer_id_1);
|
||||
ma_peer1 = multiaddress_new_from_string(multiaddress_string);
|
||||
// start the daemon in a separate thread
|
||||
if (pthread_create(&thread1, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0) {
|
||||
if (pthread_create(&thread1, NULL, test_daemon_start, (void*)ipfs_path) < 0) {
|
||||
libp2p_logger_error("test_bitswap", "Unable to start thread 1\n");
|
||||
goto exit;
|
||||
}
|
||||
|
@ -424,7 +424,7 @@ int test_bitswap_retrieve_file_third_party() {
|
|||
ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, ipfs_node2, &bytes_written, 0);
|
||||
ipfs_node_free(ipfs_node2);
|
||||
// start the daemon in a separate thread
|
||||
if (pthread_create(&thread2, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0) {
|
||||
if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0) {
|
||||
libp2p_logger_error("test_bitswap", "Unable to start thread 2\n");
|
||||
goto exit;
|
||||
}
|
||||
|
|
|
@ -76,11 +76,6 @@ int test_resolver_get() {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
void* test_resolver_daemon_start(void* arg) {
|
||||
ipfs_daemon_start((char*)arg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int test_resolver_remote_get() {
|
||||
// clean out repository
|
||||
const char* ipfs_path = "/tmp";
|
||||
|
@ -107,7 +102,7 @@ int test_resolver_remote_get() {
|
|||
drop_and_build_repository(ipfs_path, 4001, NULL, NULL);
|
||||
|
||||
// start the daemon in a separate thread
|
||||
if (pthread_create(&thread, NULL, test_resolver_daemon_start, (void*)ipfs_path) < 0)
|
||||
if (pthread_create(&thread, NULL, test_daemon_start, (void*)ipfs_path) < 0)
|
||||
goto exit;
|
||||
thread_started = 1;
|
||||
|
||||
|
|
|
@ -16,10 +16,6 @@
|
|||
|
||||
#include "../test_helper.h"
|
||||
|
||||
void* test_routing_daemon_start(void* arg) {
|
||||
ipfs_daemon_start((char*)arg);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/***
|
||||
* "publish" a hash to the datastore (for ipns)
|
||||
|
@ -44,7 +40,7 @@ int test_routing_put_value() {
|
|||
ma_publisher = multiaddress_new_from_string(multiaddress_string);
|
||||
char* args[] = { "ipfs", "--config", ipfs_path_publisher, "add", "-r", "~/site"};
|
||||
ipfs_import_files(6, args);
|
||||
if (!pthread_create(&thread_publisher, NULL, test_routing_daemon_start, (void*)ipfs_path_publisher)) {
|
||||
if (!pthread_create(&thread_publisher, NULL, test_daemon_start, (void*)ipfs_path_publisher)) {
|
||||
goto exit;
|
||||
}
|
||||
publisher_thread_started = 1;
|
||||
|
@ -53,13 +49,15 @@ int test_routing_put_value() {
|
|||
ma_vector = libp2p_utils_vector_new(1);
|
||||
libp2p_utils_vector_add(ma_vector, ma_publisher);
|
||||
drop_and_build_repository(ipfs_path_consumer, 4002, ma_vector, &peer_id_consumer);
|
||||
if (pthread_create(&thread_consumer, NULL, test_routing_daemon_start, (void*)ipfs_path_consumer) < 0)
|
||||
if (pthread_create(&thread_consumer, NULL, test_daemon_start, (void*)ipfs_path_consumer) < 0)
|
||||
goto exit;
|
||||
consumer_thread_started = 1;
|
||||
|
||||
// wait for everything to fire up
|
||||
sleep(5);
|
||||
|
||||
/* this area is for when we get the command line interface closer to completion... So skip for now and do it at a lower level
|
||||
|
||||
// now "publish" to publisher, and verify that "consumer" receives the message
|
||||
char* args2[] = {"ipfs" "--config", ipfs_path_publisher, "name", "publish", "QmZtAEqmnXMZkwVPKdyMGxUoo35cQMzNhmq6CN3DvgRwAD" };
|
||||
//ipfs_name_publish(6, args2);
|
||||
|
@ -71,6 +69,9 @@ int test_routing_put_value() {
|
|||
char* args3[] = {"ipfs", "--config", ipfs_path_consumer, "resolve", peer_id_publisher};
|
||||
char* results = NULL;
|
||||
//ipfs_resolve(5, args3, &results);
|
||||
*/
|
||||
|
||||
ipfs_namesys_publisher_publish();
|
||||
|
||||
retVal = 1;
|
||||
exit:
|
||||
|
@ -115,7 +116,7 @@ int test_routing_find_peer() {
|
|||
sprintf(multiaddress_string, "/ip4/127.0.0.1/tcp/4001/ipfs/%s", peer_id_1);
|
||||
ma_peer1 = multiaddress_new_from_string(multiaddress_string);
|
||||
// start the daemon in a separate thread
|
||||
if (pthread_create(&thread1, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0)
|
||||
if (pthread_create(&thread1, NULL, test_daemon_start, (void*)ipfs_path) < 0)
|
||||
goto exit;
|
||||
thread1_started = 1;
|
||||
|
||||
|
@ -135,7 +136,7 @@ int test_routing_find_peer() {
|
|||
ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, local_node2, &bytes_written, 0);
|
||||
ipfs_node_free(local_node2);
|
||||
// start the daemon in a separate thread
|
||||
if (pthread_create(&thread2, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0)
|
||||
if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0)
|
||||
goto exit;
|
||||
thread2_started = 1;
|
||||
|
||||
|
@ -231,7 +232,7 @@ int test_routing_find_providers() {
|
|||
sprintf(multiaddress_string, "/ip4/127.0.0.1/tcp/4001/ipfs/%s", peer_id_1);
|
||||
ma_peer1 = multiaddress_new_from_string(multiaddress_string);
|
||||
// start the daemon in a separate thread
|
||||
if (pthread_create(&thread1, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0) {
|
||||
if (pthread_create(&thread1, NULL, test_daemon_start, (void*)ipfs_path) < 0) {
|
||||
fprintf(stderr, "Unable to start thread 1\n");
|
||||
goto exit;
|
||||
}
|
||||
|
@ -252,7 +253,7 @@ int test_routing_find_providers() {
|
|||
ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, local_node2, &bytes_written, 0);
|
||||
ipfs_node_free(local_node2);
|
||||
// start the daemon in a separate thread
|
||||
if (pthread_create(&thread2, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0) {
|
||||
if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0) {
|
||||
fprintf(stderr, "Unable to start thread 2\n");
|
||||
goto exit;
|
||||
}
|
||||
|
@ -386,7 +387,7 @@ int test_routing_provide() {
|
|||
sprintf(multiaddress_string, "/ip4/127.0.0.1/tcp/4001/ipfs/%s", peer_id_1);
|
||||
ma_peer1 = multiaddress_new_from_string(multiaddress_string);
|
||||
// start the daemon in a separate thread
|
||||
if (pthread_create(&thread1, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0) {
|
||||
if (pthread_create(&thread1, NULL, test_daemon_start, (void*)ipfs_path) < 0) {
|
||||
fprintf(stderr, "Unable to start thread 1\n");
|
||||
goto exit;
|
||||
}
|
||||
|
@ -407,7 +408,7 @@ int test_routing_provide() {
|
|||
ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, local_node2, &bytes_written, 0);
|
||||
ipfs_node_free(local_node2);
|
||||
// start the daemon in a separate thread
|
||||
if (pthread_create(&thread2, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0) {
|
||||
if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0) {
|
||||
fprintf(stderr, "Unable to start thread 2\n");
|
||||
goto exit;
|
||||
}
|
||||
|
@ -474,7 +475,7 @@ int test_routing_retrieve_file_third_party() {
|
|||
ma_peer1 = multiaddress_new_from_string(multiaddress_string);
|
||||
// start the daemon in a separate thread
|
||||
libp2p_logger_debug("test_routing", "Firing up daemon 1.\n");
|
||||
if (pthread_create(&thread1, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0) {
|
||||
if (pthread_create(&thread1, NULL, test_daemon_start, (void*)ipfs_path) < 0) {
|
||||
fprintf(stderr, "Unable to start thread 1\n");
|
||||
goto exit;
|
||||
}
|
||||
|
@ -502,7 +503,7 @@ int test_routing_retrieve_file_third_party() {
|
|||
ipfs_node_free(ipfs_node2);
|
||||
// start the daemon in a separate thread
|
||||
libp2p_logger_debug("test_routing", "Firing up daemon 2.\n");
|
||||
if (pthread_create(&thread2, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0) {
|
||||
if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0) {
|
||||
fprintf(stderr, "Unable to start thread 2\n");
|
||||
goto exit;
|
||||
}
|
||||
|
@ -608,7 +609,7 @@ int test_routing_retrieve_large_file() {
|
|||
ma_peer1 = multiaddress_new_from_string(multiaddress_string);
|
||||
// start the daemon in a separate thread
|
||||
libp2p_logger_debug("test_routing", "Firing up daemon 1.\n");
|
||||
if (pthread_create(&thread1, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0) {
|
||||
if (pthread_create(&thread1, NULL, test_daemon_start, (void*)ipfs_path) < 0) {
|
||||
fprintf(stderr, "Unable to start thread 1\n");
|
||||
goto exit;
|
||||
}
|
||||
|
@ -636,7 +637,7 @@ int test_routing_retrieve_large_file() {
|
|||
ipfs_node_free(ipfs_node2);
|
||||
// start the daemon in a separate thread
|
||||
libp2p_logger_debug("test_routing", "Firing up daemon 2.\n");
|
||||
if (pthread_create(&thread2, NULL, test_routing_daemon_start, (void*)ipfs_path) < 0) {
|
||||
if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0) {
|
||||
fprintf(stderr, "Unable to start thread 2\n");
|
||||
goto exit;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue