2017-04-17 04:47:53 +00:00
|
|
|
#include <stdlib.h>
|
2017-09-20 14:11:01 +00:00
|
|
|
#include <pthread.h>
|
2017-09-13 10:02:59 +00:00
|
|
|
#include "ipfs/importer/importer.h"
|
2017-04-17 04:47:53 +00:00
|
|
|
|
|
|
|
int test_null_add_provider() {
|
|
|
|
int retVal = 0;
|
|
|
|
char* peer_id_1;
|
|
|
|
char* peer_id_2;
|
2017-04-20 22:56:03 +00:00
|
|
|
struct IpfsNode *local_node2 = NULL;
|
2017-04-27 16:35:26 +00:00
|
|
|
pthread_t thread1, thread2;
|
|
|
|
int thread1_started = 0, thread2_started = 0;
|
2017-04-17 04:47:53 +00:00
|
|
|
struct MultiAddress* ma_peer1;
|
|
|
|
char* ipfs_path = "/tmp/test1";
|
|
|
|
|
|
|
|
// create peer 1 that will be the "server" for this test
|
|
|
|
os_utils_setenv("IPFS_PATH", ipfs_path, 1);
|
|
|
|
drop_and_build_repository(ipfs_path, 4001, NULL, &peer_id_1);
|
|
|
|
char multiaddress_string[255];
|
|
|
|
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
|
2017-09-13 10:02:59 +00:00
|
|
|
if (pthread_create(&thread1, NULL, test_daemon_start, (void*)ipfs_path) < 0)
|
2017-04-17 04:47:53 +00:00
|
|
|
goto exit;
|
2017-04-27 16:35:26 +00:00
|
|
|
thread1_started = 1;
|
2017-04-17 04:47:53 +00:00
|
|
|
|
|
|
|
// create peer 2 that will be the "client" for this test
|
|
|
|
ipfs_path = "/tmp/test2";
|
|
|
|
os_utils_setenv("IPFS_PATH", ipfs_path, 1);
|
|
|
|
struct Libp2pVector* ma_vector = libp2p_utils_vector_new(1);
|
|
|
|
libp2p_utils_vector_add(ma_vector, ma_peer1);
|
|
|
|
drop_and_build_repository(ipfs_path, 4002, ma_vector, &peer_id_2);
|
|
|
|
// add a file, to prime the connection to peer 1
|
|
|
|
//TODO: Find a better way to do this...
|
|
|
|
size_t bytes_written = 0;
|
2017-09-25 13:55:42 +00:00
|
|
|
ipfs_node_online_new(ipfs_path, &local_node2);
|
2017-04-20 22:56:03 +00:00
|
|
|
struct HashtableNode* node = NULL;
|
|
|
|
ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, local_node2, &bytes_written, 0);
|
2017-09-25 13:55:42 +00:00
|
|
|
ipfs_node_free(local_node2);
|
2017-04-17 04:47:53 +00:00
|
|
|
// start the daemon in a separate thread
|
2017-09-13 10:02:59 +00:00
|
|
|
if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0)
|
2017-04-17 04:47:53 +00:00
|
|
|
goto exit;
|
2017-04-27 16:35:26 +00:00
|
|
|
thread2_started = 1;
|
2017-04-17 04:47:53 +00:00
|
|
|
// wait for everything to start up
|
|
|
|
// JMJ debugging
|
|
|
|
sleep(60);
|
|
|
|
|
|
|
|
//TODO: verify that the server (peer 1) has the client and his file
|
|
|
|
|
|
|
|
retVal = 1;
|
|
|
|
exit:
|
2017-04-20 22:56:03 +00:00
|
|
|
if (local_node2 != NULL)
|
2017-09-25 13:55:42 +00:00
|
|
|
ipfs_node_free(local_node2);
|
2017-04-17 04:47:53 +00:00
|
|
|
if (ma_peer1 != NULL)
|
|
|
|
multiaddress_free(ma_peer1);
|
2017-04-27 16:35:26 +00:00
|
|
|
ipfs_daemon_stop();
|
|
|
|
if (thread1_started)
|
|
|
|
pthread_join(thread1, NULL);
|
|
|
|
if (thread2_started)
|
|
|
|
pthread_join(thread2, NULL);
|
2017-04-17 04:47:53 +00:00
|
|
|
return retVal;
|
|
|
|
}
|