The API changed pthread to scope, so it can load multiple instances.

This commit is contained in:
Jose Marcial Vieira Bisneto 2017-09-20 14:39:26 -03:00
parent c06625a00e
commit a907f1dd2d
No known key found for this signature in database
GPG key ID: 103E935E7E6E831E
33 changed files with 127 additions and 81 deletions

View file

@ -1,5 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <pthread.h>
#include "ipfs/cmd/ipfs/init.h" #include "ipfs/cmd/ipfs/init.h"
#include "ipfs/commands/request.h" #include "ipfs/commands/request.h"

View file

@ -22,8 +22,6 @@
pthread_mutex_t conns_lock; pthread_mutex_t conns_lock;
int conns_count; int conns_count;
pthread_t listen_thread = 0;
struct s_list api_list; struct s_list api_list;
/** /**
@ -624,7 +622,7 @@ void *api_listen_thread (void *ptr)
* @param timeout time out of client connection. * @param timeout time out of client connection.
* @returns 0 when failure or 1 if success. * @returns 0 when failure or 1 if success.
*/ */
int api_start (struct IpfsNode* local_node, int max_conns, int timeout) int api_start (pthread_t *scope_pth, struct IpfsNode* local_node, int max_conns, int timeout)
{ {
int s; int s;
size_t alloc_size = sizeof(void*) * max_conns; size_t alloc_size = sizeof(void*) * max_conns;
@ -638,11 +636,6 @@ int api_start (struct IpfsNode* local_node, int max_conns, int timeout)
api_list.ipv4 = hostname_to_ip(ip); // api is listening only on loopback. api_list.ipv4 = hostname_to_ip(ip); // api is listening only on loopback.
api_list.port = port; api_list.port = port;
if (listen_thread != 0) {
libp2p_logger_error("api", "API already running.\n");
return 0;
}
if ((s = socket_listen(socket_tcp4(), &(api_list.ipv4), &(api_list.port))) <= 0) { if ((s = socket_listen(socket_tcp4(), &(api_list.ipv4), &(api_list.port))) <= 0) {
libp2p_logger_error("api", "Failed to init API. port: %d\n", port); libp2p_logger_error("api", "Failed to init API. port: %d\n", port);
return 0; return 0;
@ -660,11 +653,11 @@ int api_start (struct IpfsNode* local_node, int max_conns, int timeout)
} }
memset(api_list.conns, 0, alloc_size); memset(api_list.conns, 0, alloc_size);
if (pthread_create(&listen_thread, NULL, api_listen_thread, (void*)local_node)) { if (pthread_create(scope_pth, NULL, api_listen_thread, (void*)local_node)) {
close (s); close (s);
free (api_list.conns); free (api_list.conns);
api_list.conns = NULL; api_list.conns = NULL;
listen_thread = 0; *scope_pth = 0;
libp2p_logger_error("api", "Error creating thread for API.\n"); libp2p_logger_error("api", "Error creating thread for API.\n");
return 0; return 0;
} }
@ -676,14 +669,14 @@ int api_start (struct IpfsNode* local_node, int max_conns, int timeout)
* Stop API. * Stop API.
* @returns 0 when failure or 1 if success. * @returns 0 when failure or 1 if success.
*/ */
int api_stop (void) int api_stop (pthread_t *scope_pth)
{ {
if (!listen_thread) return 0; if (*scope_pth == 0) return 0;
pthread_cancel(listen_thread); pthread_cancel(*scope_pth);
api_connections_cleanup (); api_connections_cleanup ();
listen_thread = 0; *scope_pth = 0;
return 1; return 1;
} }

View file

@ -1,3 +1,4 @@
#include <pthread.h>
#include "libp2p/peer/peer.h" #include "libp2p/peer/peer.h"
#include "libp2p/utils/logger.h" #include "libp2p/utils/logger.h"

View file

@ -1,3 +1,4 @@
#include <pthread.h>
#include "ipfs/core/builder.h" #include "ipfs/core/builder.h"
int ipfs_core_builder_new_node(struct Context* context, struct BuildCfg* build_cfg, struct IpfsNode* buildConfig) { int ipfs_core_builder_new_node(struct Context* context, struct BuildCfg* build_cfg, struct IpfsNode* buildConfig) {

View file

@ -6,6 +6,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netdb.h> #include <netdb.h>
#include <pthread.h>
#include "ipfs/core/client_api.h" #include "ipfs/core/client_api.h"
#include "multiaddr/multiaddr.h" #include "multiaddr/multiaddr.h"

View file

@ -15,14 +15,14 @@
int ipfs_daemon_start(char* repo_path) { int ipfs_daemon_start(char* repo_path) {
int count_pths = 0, retVal = 0; int count_pths = 0, retVal = 0;
pthread_t work_pths[MAX]; pthread_t work_pths[MAX], api_pth = 0;
struct IpfsNodeListenParams listen_param; struct IpfsNodeListenParams listen_param;
struct MultiAddress* ma = NULL; struct MultiAddress* ma = NULL;
libp2p_logger_info("daemon", "Initializing daemon for %s...\n", repo_path); libp2p_logger_info("daemon", "Initializing daemon for %s...\n", repo_path);
struct IpfsNode* local_node = NULL; struct IpfsNode* local_node = NULL;
if (!ipfs_node_online_new(repo_path, &local_node)) if (!ipfs_node_online_new(&api_pth, repo_path, &local_node))
goto exit; goto exit;
// Set null router param // Set null router param
@ -56,7 +56,7 @@ int ipfs_daemon_start(char* repo_path) {
if (ma != NULL) if (ma != NULL)
multiaddress_free(ma); multiaddress_free(ma);
if (local_node != NULL) { if (local_node != NULL) {
ipfs_node_free(local_node); ipfs_node_free(&api_pth, local_node);
} }
return retVal; return retVal;

View file

@ -1,4 +1,5 @@
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h>
#include "libp2p/net/multistream.h" #include "libp2p/net/multistream.h"
#include "libp2p/utils/vector.h" #include "libp2p/utils/vector.h"
@ -43,7 +44,7 @@ int ipfs_node_online_protocol_handlers_free(struct Libp2pVector* handlers) {
* @param node the completed IpfsNode struct * @param node the completed IpfsNode struct
* @returns true(1) on success * @returns true(1) on success
*/ */
int ipfs_node_online_new(const char* repo_path, struct IpfsNode** node) { int ipfs_node_online_new(pthread_t *pth_scope, const char* repo_path, struct IpfsNode** node) {
struct FSRepo* fs_repo = NULL; struct FSRepo* fs_repo = NULL;
*node = (struct IpfsNode*)malloc(sizeof(struct IpfsNode)); *node = (struct IpfsNode*)malloc(sizeof(struct IpfsNode));
@ -60,13 +61,13 @@ int ipfs_node_online_new(const char* repo_path, struct IpfsNode** node) {
// build the struct // build the struct
if (!ipfs_repo_fsrepo_new(repo_path, NULL, &fs_repo)) { if (!ipfs_repo_fsrepo_new(repo_path, NULL, &fs_repo)) {
ipfs_node_free(local_node); ipfs_node_free(pth_scope, local_node);
*node = NULL; *node = NULL;
return 0; return 0;
} }
// open the repo // open the repo
if (!ipfs_repo_fsrepo_open(fs_repo)) { if (!ipfs_repo_fsrepo_open(fs_repo)) {
ipfs_node_free(local_node); ipfs_node_free(pth_scope, local_node);
*node = NULL; *node = NULL;
return 0; return 0;
} }
@ -83,7 +84,7 @@ int ipfs_node_online_new(const char* repo_path, struct IpfsNode** node) {
local_node->exchange = ipfs_bitswap_new(local_node); local_node->exchange = ipfs_bitswap_new(local_node);
// fire up the API // fire up the API
api_start(local_node, 10, 5); api_start(pth_scope, local_node, 10, 5);
return 1; return 1;
} }
@ -94,7 +95,7 @@ int ipfs_node_online_new(const char* repo_path, struct IpfsNode** node) {
* @param node the completed IpfsNode struct * @param node the completed IpfsNode struct
* @returns true(1) on success * @returns true(1) on success
*/ */
int ipfs_node_offline_new(const char* repo_path, struct IpfsNode** node) { int ipfs_node_offline_new(pthread_t *pth_scope, const char* repo_path, struct IpfsNode** node) {
struct FSRepo* fs_repo = NULL; struct FSRepo* fs_repo = NULL;
*node = (struct IpfsNode*)malloc(sizeof(struct IpfsNode)); *node = (struct IpfsNode*)malloc(sizeof(struct IpfsNode));
@ -111,13 +112,13 @@ int ipfs_node_offline_new(const char* repo_path, struct IpfsNode** node) {
// build the struct // build the struct
if (!ipfs_repo_fsrepo_new(repo_path, NULL, &fs_repo)) { if (!ipfs_repo_fsrepo_new(repo_path, NULL, &fs_repo)) {
ipfs_node_free(local_node); ipfs_node_free(pth_scope, local_node);
*node = NULL; *node = NULL;
return 0; return 0;
} }
// open the repo // open the repo
if (!ipfs_repo_fsrepo_open(fs_repo)) { if (!ipfs_repo_fsrepo_open(fs_repo)) {
ipfs_node_free(local_node); ipfs_node_free(pth_scope, local_node);
*node = NULL; *node = NULL;
return 0; return 0;
} }
@ -144,9 +145,9 @@ int ipfs_node_offline_new(const char* repo_path, struct IpfsNode** node) {
* @param node the node to free * @param node the node to free
* @returns true(1) * @returns true(1)
*/ */
int ipfs_node_free(struct IpfsNode* node) { int ipfs_node_free(pthread_t *pth_scope, struct IpfsNode* node) {
if (node != NULL) { if (node != NULL) {
api_stop(); api_stop(pth_scope);
if (node->exchange != NULL) { if (node->exchange != NULL) {
node->exchange->Close(node->exchange); node->exchange->Close(node->exchange);
} }

View file

@ -4,6 +4,7 @@
#include <unistd.h> #include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <pthread.h>
#include "libp2p/net/p2pnet.h" #include "libp2p/net/p2pnet.h"
#include "libp2p/net/multistream.h" #include "libp2p/net/multistream.h"
#include "libp2p/record/message.h" #include "libp2p/record/message.h"

View file

@ -3,6 +3,7 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> // for sleep() #include <unistd.h> // for sleep()
#include <pthread.h>
#include "libp2p/os/utils.h" #include "libp2p/os/utils.h"
#include "libp2p/utils/logger.h" #include "libp2p/utils/logger.h"
#include "ipfs/core/ipfs_node.h" #include "ipfs/core/ipfs_node.h"

View file

@ -1,4 +1,6 @@
#include <unistd.h> #include <unistd.h>
#include <pthread.h>
#include "libp2p/utils/logger.h" #include "libp2p/utils/logger.h"
#include "ipfs/core/null.h" #include "ipfs/core/null.h"
#include "ipfs/exchange/bitswap/engine.h" #include "ipfs/exchange/bitswap/engine.h"

View file

@ -5,6 +5,8 @@
* For a somewhat accurate diagram of how this may work, @see https://github.com/ipfs/js-ipfs-bitswap * For a somewhat accurate diagram of how this may work, @see https://github.com/ipfs/js-ipfs-bitswap
*/ */
#include <pthread.h>
#include "libp2p/utils/logger.h" #include "libp2p/utils/logger.h"
#include "ipfs/exchange/bitswap/network.h" #include "ipfs/exchange/bitswap/network.h"
#include "ipfs/exchange/bitswap/peer_request_queue.h" #include "ipfs/exchange/bitswap/peer_request_queue.h"

View file

@ -1,3 +1,5 @@
#include <pthread.h>
#include "ipfs/exchange/bitswap/want_manager.h" #include "ipfs/exchange/bitswap/want_manager.h"
#include "ipfs/exchange/bitswap/wantlist_queue.h" #include "ipfs/exchange/bitswap/wantlist_queue.h"

View file

@ -1,5 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <pthread.h>
#include "ipfs/cid/cid.h" #include "ipfs/cid/cid.h"
#include "ipfs/merkledag/merkledag.h" #include "ipfs/merkledag/merkledag.h"
@ -190,6 +191,7 @@ int ipfs_exporter_to_console(const unsigned char* hash, struct IpfsNode *local_n
*/ */
int ipfs_exporter_object_get(int argc, char** argv) { int ipfs_exporter_object_get(int argc, char** argv) {
char* repo_path = NULL; char* repo_path = NULL;
pthread_t api_pth = 0;
if (!ipfs_repo_get_directory(argc, argv, &repo_path)) { if (!ipfs_repo_get_directory(argc, argv, &repo_path)) {
fprintf(stderr, "Unable to open repository: %s\n", repo_path); fprintf(stderr, "Unable to open repository: %s\n", repo_path);
@ -197,13 +199,13 @@ int ipfs_exporter_object_get(int argc, char** argv) {
} }
struct IpfsNode* local_node = NULL; struct IpfsNode* local_node = NULL;
if (!ipfs_node_online_new(repo_path, &local_node)) if (!ipfs_node_online_new(&api_pth, repo_path, &local_node))
return 0; return 0;
// find hash // find hash
int retVal = ipfs_exporter_to_console((unsigned char*)argv[3], local_node); int retVal = ipfs_exporter_to_console((unsigned char*)argv[3], local_node);
ipfs_node_free(local_node); ipfs_node_free(&api_pth, local_node);
return retVal; return retVal;
} }
@ -264,13 +266,14 @@ int ipfs_exporter_object_cat_to_file(struct IpfsNode *local_node, unsigned char*
int ipfs_exporter_object_cat(int argc, char** argv) { int ipfs_exporter_object_cat(int argc, char** argv) {
struct IpfsNode *local_node = NULL; struct IpfsNode *local_node = NULL;
char* repo_dir = NULL; char* repo_dir = NULL;
pthread_t api_pth = 0;
if (!ipfs_repo_get_directory(argc, argv, &repo_dir)) { if (!ipfs_repo_get_directory(argc, argv, &repo_dir)) {
fprintf(stderr, "Unable to open repo: %s\n", repo_dir); fprintf(stderr, "Unable to open repo: %s\n", repo_dir);
return 0; return 0;
} }
if (!ipfs_node_offline_new(repo_dir, &local_node)) if (!ipfs_node_offline_new(&api_pth, repo_dir, &local_node))
return 0; return 0;
if (local_node->mode == MODE_API_AVAILABLE) { if (local_node->mode == MODE_API_AVAILABLE) {

View file

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <pthread.h>
#include "ipfs/importer/importer.h" #include "ipfs/importer/importer.h"
#include "ipfs/merkledag/merkledag.h" #include "ipfs/merkledag/merkledag.h"
@ -378,6 +379,7 @@ int ipfs_import_files(int argc, char** argv) {
char* path = NULL; char* path = NULL;
char* filename = NULL; char* filename = NULL;
struct HashtableNode* directory_entry = NULL; struct HashtableNode* directory_entry = NULL;
pthread_t api_pth = 0;
int recursive = ipfs_import_is_recursive(argc, argv); int recursive = ipfs_import_is_recursive(argc, argv);
@ -389,7 +391,7 @@ int ipfs_import_files(int argc, char** argv) {
fprintf(stderr, "Repo does not exist: %s\n", repo_path); fprintf(stderr, "Repo does not exist: %s\n", repo_path);
goto exit; goto exit;
} }
ipfs_node_online_new(repo_path, &local_node); ipfs_node_online_new(&api_pth, repo_path, &local_node);
// import the file(s) // import the file(s)
@ -419,7 +421,7 @@ int ipfs_import_files(int argc, char** argv) {
retVal = 1; retVal = 1;
exit: exit:
if (local_node != NULL) if (local_node != NULL)
ipfs_node_free(local_node); ipfs_node_free(&api_pth, local_node);
// free file list // free file list
current = first; current = first;
while (current != NULL) { while (current != NULL) {

View file

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h>
#include "ipfs/importer/resolver.h" #include "ipfs/importer/resolver.h"
#include "libp2p/utils/logger.h" #include "libp2p/utils/logger.h"

View file

@ -68,5 +68,5 @@ struct s_request {
void *api_connection_thread (void *ptr); void *api_connection_thread (void *ptr);
void api_connections_cleanup (void); void api_connections_cleanup (void);
void *api_listen_thread (void *ptr); void *api_listen_thread (void *ptr);
int api_start (struct IpfsNode* local_node, int max_conns, int timeout); int api_start (pthread_t *scope_pth, struct IpfsNode* local_node, int max_conns, int timeout);
int api_stop (void); int api_stop (pthread_t *scope_pth);

View file

@ -47,7 +47,7 @@ struct IpfsNode {
* @param node the completed IpfsNode struct * @param node the completed IpfsNode struct
* @returns true(1) on success * @returns true(1) on success
*/ */
int ipfs_node_online_new(const char* repo_path, struct IpfsNode** node); int ipfs_node_online_new(pthread_t *pth_scope, const char* repo_path, struct IpfsNode** node);
/*** /***
* build an offline IpfsNode * build an offline IpfsNode
@ -55,11 +55,11 @@ int ipfs_node_online_new(const char* repo_path, struct IpfsNode** node);
* @param node the completed IpfsNode struct * @param node the completed IpfsNode struct
* @returns true(1) on success * @returns true(1) on success
*/ */
int ipfs_node_offline_new(const char* repo_path, struct IpfsNode** node); int ipfs_node_offline_new(pthread_t *pth_scope, const char* repo_path, struct IpfsNode** node);
/*** /***
* Free resources from the creation of an IpfsNode * Free resources from the creation of an IpfsNode
* @param node the node to free * @param node the node to free
* @returns true(1) * @returns true(1)
*/ */
int ipfs_node_free(struct IpfsNode* node); int ipfs_node_free(pthread_t *pth_scope, struct IpfsNode* node);

View file

@ -1,6 +1,8 @@
/** /**
* The journal protocol attempts to keep a journal in sync with other (approved) nodes * The journal protocol attempts to keep a journal in sync with other (approved) nodes
*/ */
#include <pthread.h>
#include "libp2p/crypto/encoding/base58.h" #include "libp2p/crypto/encoding/base58.h"
#include "libp2p/os/utils.h" #include "libp2p/os/utils.h"
#include "libp2p/utils/logger.h" #include "libp2p/utils/logger.h"

View file

@ -1,5 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <pthread.h>
#include "libp2p/routing/dht_protocol.h" #include "libp2p/routing/dht_protocol.h"
#include "ipfs/util/errs.h" #include "ipfs/util/errs.h"
#include "ipfs/util/time.h" #include "ipfs/util/time.h"

View file

@ -1,3 +1,5 @@
#include <pthread.h>
#include "ipfs/routing/routing.h" #include "ipfs/routing/routing.h"
#include "libp2p/routing/kademlia.h" #include "libp2p/routing/kademlia.h"
#include "libp2p/peer/providerstore.h" #include "libp2p/peer/providerstore.h"

View file

@ -1,4 +1,5 @@
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h>
#include <ipfs/routing/routing.h> #include <ipfs/routing/routing.h>
#include <ipfs/util/errs.h> #include <ipfs/util/errs.h>
#include "libp2p/crypto/rsa.h" #include "libp2p/crypto/rsa.h"

View file

@ -1,5 +1,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include <pthread.h>
#include "libp2p/crypto/encoding/base58.h" #include "libp2p/crypto/encoding/base58.h"
#include "ipfs/routing/routing.h" #include "ipfs/routing/routing.h"

View file

@ -8,6 +8,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
//#include <string.h> //#include <string.h>
#include <pthread.h>
#include "ipfs/cmd/ipfs/init.h" #include "ipfs/cmd/ipfs/init.h"
#include "ipfs/commands/argument.h" #include "ipfs/commands/argument.h"

View file

@ -11,6 +11,7 @@ int test_core_api_startup_shutdown() {
char* repo_path = "/tmp/ipfs_1/.ipfs"; char* repo_path = "/tmp/ipfs_1/.ipfs";
char* peer_id = NULL; char* peer_id = NULL;
int retVal = 0; int retVal = 0;
pthread_t api_pth;
if (!drop_and_build_repository(repo_path, 4001, NULL, &peer_id)) if (!drop_and_build_repository(repo_path, 4001, NULL, &peer_id))
goto exit; goto exit;
@ -20,7 +21,7 @@ int test_core_api_startup_shutdown() {
sleep(3); sleep(3);
struct IpfsNode* client_node = NULL; struct IpfsNode* client_node = NULL;
if (!ipfs_node_offline_new(repo_path, &client_node)) { if (!ipfs_node_offline_new(&api_pth, repo_path, &client_node)) {
goto exit; goto exit;
} }
// test to see if it is working // test to see if it is working
@ -97,11 +98,12 @@ int test_core_api_object_cat() {
struct HashtableNode* node; struct HashtableNode* node;
size_t bytes_written; size_t bytes_written;
struct IpfsNode *local_node = NULL; struct IpfsNode *local_node = NULL;
ipfs_node_offline_new(ipfs_path1, &local_node); pthread_t api_pth = 0;
ipfs_node_offline_new(&api_pth, ipfs_path1, &local_node);
ipfs_import_file(NULL, filename, &node, local_node, &bytes_written, 0); ipfs_import_file(NULL, filename, &node, local_node, &bytes_written, 0);
memset(hash, 0, 256); memset(hash, 0, 256);
ipfs_cid_hash_to_base58(node->hash, node->hash_size, (unsigned char*)hash, 256); ipfs_cid_hash_to_base58(node->hash, node->hash_size, (unsigned char*)hash, 256);
ipfs_node_free(local_node); ipfs_node_free(&api_pth, local_node);
ipfs_hashtable_node_free(node); ipfs_hashtable_node_free(node);
libp2p_logger_debug("test_api", "*** Firing up daemons ***\n"); libp2p_logger_debug("test_api", "*** Firing up daemons ***\n");

View file

@ -1,4 +1,5 @@
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h>
#include "../test_helper.h" #include "../test_helper.h"
#include "ipfs/core/ipfs_node.h" #include "ipfs/core/ipfs_node.h"
@ -9,11 +10,12 @@ int test_node_peerstore() {
char* peer_id = NULL; char* peer_id = NULL;
struct IpfsNode *local_node = NULL; struct IpfsNode *local_node = NULL;
struct Libp2pPeer* peer = NULL; struct Libp2pPeer* peer = NULL;
pthread_t api_pth = 0;
if (!drop_and_build_repository(repo_path, 4001, NULL, &peer_id)) if (!drop_and_build_repository(repo_path, 4001, NULL, &peer_id))
goto exit; goto exit;
if (!ipfs_node_online_new(repo_path, &local_node)) if (!ipfs_node_online_new(&api_pth, repo_path, &local_node))
goto exit; goto exit;
// add a peer to the peerstore // add a peer to the peerstore
@ -47,7 +49,7 @@ int test_node_peerstore() {
if (peer != NULL) if (peer != NULL)
libp2p_peer_free(peer); libp2p_peer_free(peer);
if (local_node != NULL) if (local_node != NULL)
ipfs_node_free(local_node); ipfs_node_free(&api_pth, local_node);
return retVal; return retVal;
} }

View file

@ -32,10 +32,11 @@ int test_null_add_provider() {
// add a file, to prime the connection to peer 1 // add a file, to prime the connection to peer 1
//TODO: Find a better way to do this... //TODO: Find a better way to do this...
size_t bytes_written = 0; size_t bytes_written = 0;
ipfs_node_online_new(ipfs_path, &local_node2); pthread_t api_pth = 0;
ipfs_node_online_new(&api_pth, ipfs_path, &local_node2);
struct HashtableNode* node = NULL; struct HashtableNode* node = NULL;
ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, local_node2, &bytes_written, 0); ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, local_node2, &bytes_written, 0);
ipfs_node_free(local_node2); ipfs_node_free(&api_pth, local_node2);
// start the daemon in a separate thread // start the daemon in a separate thread
if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0) if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0)
goto exit; goto exit;
@ -49,7 +50,7 @@ int test_null_add_provider() {
retVal = 1; retVal = 1;
exit: exit:
if (local_node2 != NULL) if (local_node2 != NULL)
ipfs_node_free(local_node2); ipfs_node_free(&api_pth, local_node2);
if (ma_peer1 != NULL) if (ma_peer1 != NULL)
multiaddress_free(ma_peer1); multiaddress_free(ma_peer1);
ipfs_daemon_stop(); ipfs_daemon_stop();

View file

@ -125,11 +125,12 @@ int test_bitswap_retrieve_file()
size_t bytes_written = 0; size_t bytes_written = 0;
struct Block* block = NULL; struct Block* block = NULL;
struct Cid* cid = NULL; struct Cid* cid = NULL;
pthread_t api_pth = 0;
// build and open the new IPFS repository with no bootstrap peers // build and open the new IPFS repository with no bootstrap peers
os_utils_setenv("IPFS_PATH", ipfs_path, 1); os_utils_setenv("IPFS_PATH", ipfs_path, 1);
drop_and_build_repository(ipfs_path, 4001, NULL, NULL); drop_and_build_repository(ipfs_path, 4001, NULL, NULL);
ipfs_node_online_new(ipfs_path, &localNode); ipfs_node_online_new(&api_pth, ipfs_path, &localNode);
// add a file // add a file
localNode->routing->Bootstrap(localNode->routing); localNode->routing->Bootstrap(localNode->routing);
@ -154,7 +155,7 @@ int test_bitswap_retrieve_file()
ipfs_cid_free(cid); ipfs_cid_free(cid);
if (node != NULL) if (node != NULL)
ipfs_hashtable_node_free(node); ipfs_hashtable_node_free(node);
ipfs_node_free(localNode); ipfs_node_free(&api_pth, localNode);
return retVal; return retVal;
} }
@ -187,6 +188,7 @@ int test_bitswap_retrieve_file_remote() {
struct HashtableNode* node = NULL; struct HashtableNode* node = NULL;
struct Block* result = NULL; struct Block* result = NULL;
struct Cid* cid = NULL; struct Cid* cid = NULL;
pthread_t api_pth1 = 0, api_pth2 = 0;
// create peer 1 // create peer 1
libp2p_logger_debug("test_bitswap", "Firing up daemon 1.\n"); libp2p_logger_debug("test_bitswap", "Firing up daemon 1.\n");
@ -196,7 +198,7 @@ int test_bitswap_retrieve_file_remote() {
ma_peer1 = multiaddress_new_from_string(multiaddress_string); ma_peer1 = multiaddress_new_from_string(multiaddress_string);
// add a file // add a file
size_t bytes_written = 0; size_t bytes_written = 0;
ipfs_node_online_new(ipfs_path, &ipfs_node1); ipfs_node_online_new(&api_pth1, ipfs_path, &ipfs_node1);
ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, ipfs_node1, &bytes_written, 0); ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, ipfs_node1, &bytes_written, 0);
// start the daemon in a separate thread // start the daemon in a separate thread
if (pthread_create(&thread1, NULL, test_daemon_start, (void*)ipfs_path) < 0) { if (pthread_create(&thread1, NULL, test_daemon_start, (void*)ipfs_path) < 0) {
@ -215,7 +217,7 @@ int test_bitswap_retrieve_file_remote() {
libp2p_utils_vector_add(ma_vector2, ma_peer1); libp2p_utils_vector_add(ma_vector2, ma_peer1);
drop_and_build_repository(ipfs_path, 4002, ma_vector2, &peer_id_2); drop_and_build_repository(ipfs_path, 4002, ma_vector2, &peer_id_2);
multiaddress_free(ma_peer1); multiaddress_free(ma_peer1);
ipfs_node_online_new(ipfs_path, &ipfs_node2); ipfs_node_online_new(&api_pth2, ipfs_path, &ipfs_node2);
ipfs_node2->routing->Bootstrap(ipfs_node2->routing); ipfs_node2->routing->Bootstrap(ipfs_node2->routing);
@ -299,6 +301,7 @@ int test_bitswap_retrieve_file_known_remote() {
struct Libp2pVector* ma_vector2 = NULL; struct Libp2pVector* ma_vector2 = NULL;
struct Block* result = NULL; struct Block* result = NULL;
struct Cid* cid = NULL; struct Cid* cid = NULL;
pthread_t api_pth = 0;
// create peer 1 // create peer 1
char multiaddress_string[255]; char multiaddress_string[255];
@ -312,7 +315,7 @@ int test_bitswap_retrieve_file_known_remote() {
libp2p_utils_vector_add(ma_vector2, ma_peer1); libp2p_utils_vector_add(ma_vector2, ma_peer1);
drop_and_build_repository(ipfs_path, 4002, ma_vector2, &peer_id_2); drop_and_build_repository(ipfs_path, 4002, ma_vector2, &peer_id_2);
multiaddress_free(ma_peer1); multiaddress_free(ma_peer1);
ipfs_node_online_new(ipfs_path, &ipfs_node2); ipfs_node_online_new(&api_pth, ipfs_path, &ipfs_node2);
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;
@ -354,7 +357,7 @@ int test_bitswap_retrieve_file_known_remote() {
// ipfs_block_free(result); // ipfs_block_free(result);
if (cid != NULL) if (cid != NULL)
ipfs_cid_free(cid); ipfs_cid_free(cid);
ipfs_node_free(ipfs_node2); ipfs_node_free(&api_pth, ipfs_node2);
return retVal; return retVal;
} }
@ -390,6 +393,7 @@ int test_bitswap_retrieve_file_third_party() {
struct HashtableNode* node = NULL; struct HashtableNode* node = NULL;
struct Block* result = NULL; struct Block* result = NULL;
struct Cid* cid = NULL; struct Cid* cid = NULL;
pthread_t api_pth1 = 0, api_pth2 = 0;
// create peer 1 // create peer 1
libp2p_logger_debug("test_bitswap", "Firing up daemon 1.\n"); libp2p_logger_debug("test_bitswap", "Firing up daemon 1.\n");
@ -418,11 +422,11 @@ int test_bitswap_retrieve_file_third_party() {
// add a file, to prime the connection to peer 1 // add a file, to prime the connection to peer 1
//TODO: Find a better way to do this... //TODO: Find a better way to do this...
size_t bytes_written = 0; size_t bytes_written = 0;
if (!ipfs_node_online_new(ipfs_path, &ipfs_node2)) if (!ipfs_node_online_new(&api_pth1, ipfs_path, &ipfs_node2))
goto exit; goto exit;
ipfs_node2->routing->Bootstrap(ipfs_node2->routing); ipfs_node2->routing->Bootstrap(ipfs_node2->routing);
ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, ipfs_node2, &bytes_written, 0); ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, ipfs_node2, &bytes_written, 0);
ipfs_node_free(ipfs_node2); ipfs_node_free(&api_pth1, ipfs_node2);
// start the daemon in a separate thread // start the daemon in a separate thread
if (pthread_create(&thread2, NULL, test_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"); libp2p_logger_error("test_bitswap", "Unable to start thread 2\n");
@ -440,7 +444,7 @@ int test_bitswap_retrieve_file_third_party() {
libp2p_utils_vector_add(ma_vector3, ma_peer1); libp2p_utils_vector_add(ma_vector3, ma_peer1);
drop_and_build_repository(ipfs_path, 4003, ma_vector3, &peer_id_3); drop_and_build_repository(ipfs_path, 4003, ma_vector3, &peer_id_3);
multiaddress_free(ma_peer1); multiaddress_free(ma_peer1);
ipfs_node_online_new(ipfs_path, &ipfs_node3); ipfs_node_online_new(&api_pth2, ipfs_path, &ipfs_node3);
ipfs_node3->routing->Bootstrap(ipfs_node3->routing); ipfs_node3->routing->Bootstrap(ipfs_node3->routing);
@ -469,7 +473,7 @@ int test_bitswap_retrieve_file_third_party() {
if (thread2_started) if (thread2_started)
pthread_join(thread2, NULL); pthread_join(thread2, NULL);
if (ipfs_node3 != NULL) if (ipfs_node3 != NULL)
ipfs_node_free(ipfs_node3); ipfs_node_free(&api_pth2, ipfs_node3);
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)

View file

@ -1,4 +1,5 @@
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h>
#include "ipfs/journal/journal_entry.h" #include "ipfs/journal/journal_entry.h"
#include "ipfs/journal/journal_message.h" #include "ipfs/journal/journal_message.h"
@ -118,9 +119,10 @@ int test_journal_server_1() {
struct HashtableNode* node; struct HashtableNode* node;
size_t bytes_written; size_t bytes_written;
struct IpfsNode *local_node = NULL; struct IpfsNode *local_node = NULL;
ipfs_node_offline_new(ipfs_path, &local_node); pthread_t api_pth = 0;
ipfs_node_offline_new(&api_pth, ipfs_path, &local_node);
ipfs_import_file(NULL, filename, &node, local_node, &bytes_written, 0); ipfs_import_file(NULL, filename, &node, local_node, &bytes_written, 0);
ipfs_node_free(local_node); ipfs_node_free(&api_pth, local_node);
ipfs_hashtable_node_free(node); ipfs_hashtable_node_free(node);
libp2p_logger_debug("test_journal", "*** Firing up daemon for server 1 ***\n"); libp2p_logger_debug("test_journal", "*** Firing up daemon for server 1 ***\n");

View file

@ -1,4 +1,5 @@
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h>
#include "ipfs/cid/cid.h" #include "ipfs/cid/cid.h"
#include "ipfs/core/ipfs_node.h" #include "ipfs/core/ipfs_node.h"
@ -10,9 +11,10 @@ int test_namesys_publisher_publish() {
struct Cid* cid = NULL; struct Cid* cid = NULL;
char* hash_text = "QmZtAEqmnXMZkwVPKdyMGxUoo35cQMzNhmq6CN3DvgRwAD"; char* hash_text = "QmZtAEqmnXMZkwVPKdyMGxUoo35cQMzNhmq6CN3DvgRwAD";
char* repo_path = "/tmp/ipfs_1/.ipfs"; char* repo_path = "/tmp/ipfs_1/.ipfs";
pthread_t api_pth = 0;
// get a local node // get a local node
if (!ipfs_node_offline_new(repo_path, &local_node)) { if (!ipfs_node_offline_new(&api_pth, repo_path, &local_node)) {
libp2p_logger_error("test_publisher", "publish: Unable to open ipfs repository.\n"); libp2p_logger_error("test_publisher", "publish: Unable to open ipfs repository.\n");
goto exit; goto exit;
} }
@ -31,7 +33,7 @@ int test_namesys_publisher_publish() {
retVal = 1; retVal = 1;
exit: exit:
ipfs_node_free(local_node); ipfs_node_free(&api_pth, local_node);
ipfs_cid_free(cid); ipfs_cid_free(cid);
return retVal; return retVal;
} }

View file

@ -1,4 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <pthread.h>
#include "../test_helper.h" #include "../test_helper.h"
#include "ipfs/importer/importer.h" #include "ipfs/importer/importer.h"
@ -29,6 +30,7 @@ int test_import_large_file() {
size_t bytes_read2 = 1; size_t bytes_read2 = 1;
unsigned char buf1[100]; unsigned char buf1[100];
unsigned char buf2[100]; unsigned char buf2[100];
pthread_t api_pth = 0;
// create the necessary file // create the necessary file
create_bytes(file_bytes, bytes_size); create_bytes(file_bytes, bytes_size);
@ -40,7 +42,7 @@ int test_import_large_file() {
goto exit; goto exit;
} }
if (!ipfs_node_online_new(repo_dir, &local_node)) { if (!ipfs_node_online_new(&api_pth, repo_dir, &local_node)) {
fprintf(stderr, "Unable to create new IpfsNode\n"); fprintf(stderr, "Unable to create new IpfsNode\n");
goto exit; goto exit;
} }
@ -128,7 +130,7 @@ int test_import_large_file() {
exit: exit:
if (local_node != NULL) if (local_node != NULL)
ipfs_node_free(local_node); ipfs_node_free(&api_pth, local_node);
if (write_node != NULL) if (write_node != NULL)
ipfs_hashtable_node_free(write_node); ipfs_hashtable_node_free(write_node);
if (read_node != NULL) if (read_node != NULL)
@ -146,6 +148,7 @@ int test_import_small_file() {
const char* fileName = "/tmp/test_import_small.tmp"; const char* fileName = "/tmp/test_import_small.tmp";
const char* repo_path = "/tmp/.ipfs"; const char* repo_path = "/tmp/.ipfs";
struct IpfsNode *local_node = NULL; struct IpfsNode *local_node = NULL;
pthread_t api_pth = 0;
// create the necessary file // create the necessary file
create_bytes(file_bytes, bytes_size); create_bytes(file_bytes, bytes_size);
@ -154,13 +157,13 @@ int test_import_small_file() {
// get the repo // get the repo
drop_and_build_repository(repo_path, 4001, NULL, NULL); drop_and_build_repository(repo_path, 4001, NULL, NULL);
ipfs_node_offline_new(repo_path, &local_node); ipfs_node_offline_new(&api_pth, repo_path, &local_node);
// write to ipfs // write to ipfs
struct HashtableNode* write_node; struct HashtableNode* write_node;
size_t bytes_written; size_t bytes_written;
if (ipfs_import_file("/tmp", fileName, &write_node, local_node, &bytes_written, 1) == 0) { if (ipfs_import_file("/tmp", fileName, &write_node, local_node, &bytes_written, 1) == 0) {
ipfs_node_free(local_node); ipfs_node_free(&api_pth, local_node);
return 0; return 0;
} }
@ -171,7 +174,7 @@ int test_import_small_file() {
for(int i = 0; i < 10; i++) { for(int i = 0; i < 10; i++) {
if (write_node->hash[i] != cid_test[i]) { if (write_node->hash[i] != cid_test[i]) {
printf("Hashes do not match at position %d, should be %02x but is %02x\n", i, cid_test[i], write_node->hash[i]); printf("Hashes do not match at position %d, should be %02x but is %02x\n", i, cid_test[i], write_node->hash[i]);
ipfs_node_free(local_node); ipfs_node_free(&api_pth, local_node);
ipfs_hashtable_node_free(write_node); ipfs_hashtable_node_free(write_node);
return 0; return 0;
} }
@ -180,7 +183,7 @@ int test_import_small_file() {
// make sure all went okay // make sure all went okay
struct HashtableNode* read_node; struct HashtableNode* read_node;
if (ipfs_merkledag_get(write_node->hash, write_node->hash_size, &read_node, local_node->repo) == 0) { if (ipfs_merkledag_get(write_node->hash, write_node->hash_size, &read_node, local_node->repo) == 0) {
ipfs_node_free(local_node); ipfs_node_free(&api_pth, local_node);
ipfs_hashtable_node_free(write_node); ipfs_hashtable_node_free(write_node);
return 0; return 0;
} }
@ -188,7 +191,7 @@ int test_import_small_file() {
// compare data // compare data
if (write_node->data_size != bytes_size + 8 || write_node->data_size != read_node->data_size) { if (write_node->data_size != bytes_size + 8 || write_node->data_size != read_node->data_size) {
printf("Data size of nodes are not equal or are incorrect. Should be %lu but are %lu\n", write_node->data_size, read_node->data_size); printf("Data size of nodes are not equal or are incorrect. Should be %lu but are %lu\n", write_node->data_size, read_node->data_size);
ipfs_node_free(local_node); ipfs_node_free(&api_pth, local_node);
ipfs_hashtable_node_free(write_node); ipfs_hashtable_node_free(write_node);
ipfs_hashtable_node_free(read_node); ipfs_hashtable_node_free(read_node);
return 0; return 0;
@ -197,7 +200,7 @@ int test_import_small_file() {
for(int i = 0; i < bytes_size; i++) { for(int i = 0; i < bytes_size; i++) {
if (write_node->data[i] != read_node->data[i]) { if (write_node->data[i] != read_node->data[i]) {
printf("Data within node is different at position %d\n", i); printf("Data within node is different at position %d\n", i);
ipfs_node_free(local_node); ipfs_node_free(&api_pth, local_node);
ipfs_hashtable_node_free(write_node); ipfs_hashtable_node_free(write_node);
ipfs_hashtable_node_free(read_node); ipfs_hashtable_node_free(read_node);
return 0; return 0;
@ -217,7 +220,7 @@ int test_import_small_file() {
fprintf(stderr, "Unable to find any records in the database.\n"); fprintf(stderr, "Unable to find any records in the database.\n");
} }
ipfs_node_free(local_node); ipfs_node_free(&api_pth, local_node);
ipfs_hashtable_node_free(write_node); ipfs_hashtable_node_free(write_node);
ipfs_hashtable_node_free(read_node); ipfs_hashtable_node_free(read_node);

View file

@ -101,6 +101,7 @@ int test_routing_find_peer() {
struct Libp2pVector *ma_vector = NULL; struct Libp2pVector *ma_vector = NULL;
struct Libp2pPeer* result = NULL; struct Libp2pPeer* result = NULL;
struct HashtableNode *node = NULL; struct HashtableNode *node = NULL;
pthread_t api_pth = 0;
//libp2p_logger_add_class("online"); //libp2p_logger_add_class("online");
//libp2p_logger_add_class("null"); //libp2p_logger_add_class("null");
@ -130,10 +131,10 @@ int test_routing_find_peer() {
// add a file, to prime the connection to peer 1 // add a file, to prime the connection to peer 1
//TODO: Find a better way to do this... //TODO: Find a better way to do this...
size_t bytes_written = 0; size_t bytes_written = 0;
ipfs_node_online_new(ipfs_path, &local_node2); ipfs_node_online_new(&api_pth, ipfs_path, &local_node2);
local_node2->routing->Bootstrap(local_node2->routing); local_node2->routing->Bootstrap(local_node2->routing);
ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, local_node2, &bytes_written, 0); ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, local_node2, &bytes_written, 0);
ipfs_node_free(local_node2); ipfs_node_free(&api_pth, local_node2);
// start the daemon in a separate thread // start the daemon in a separate thread
if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0) if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0)
goto exit; goto exit;
@ -224,6 +225,7 @@ int test_routing_find_providers() {
struct FSRepo* fs_repo = NULL; struct FSRepo* fs_repo = NULL;
struct HashtableNode* node = NULL; struct HashtableNode* node = NULL;
struct Libp2pVector* result = NULL; struct Libp2pVector* result = NULL;
pthread_t api_pth = 0;
// create peer 1 // create peer 1
drop_and_build_repository(ipfs_path, 4001, NULL, &peer_id_1); drop_and_build_repository(ipfs_path, 4001, NULL, &peer_id_1);
@ -248,9 +250,9 @@ int test_routing_find_providers() {
// add a file, to prime the connection to peer 1 // add a file, to prime the connection to peer 1
//TODO: Find a better way to do this... //TODO: Find a better way to do this...
size_t bytes_written = 0; size_t bytes_written = 0;
ipfs_node_online_new(ipfs_path, &local_node2); ipfs_node_online_new(&api_pth, ipfs_path, &local_node2);
ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, local_node2, &bytes_written, 0); ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, local_node2, &bytes_written, 0);
ipfs_node_free(local_node2); ipfs_node_free(&api_pth, local_node2);
// start the daemon in a separate thread // start the daemon in a separate thread
if (pthread_create(&thread2, NULL, test_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"); fprintf(stderr, "Unable to start thread 2\n");
@ -376,6 +378,7 @@ int test_routing_provide() {
struct MultiAddress* ma_peer1 = NULL; struct MultiAddress* ma_peer1 = NULL;
struct Libp2pVector* ma_vector2 = NULL; struct Libp2pVector* ma_vector2 = NULL;
struct HashtableNode* node = NULL; struct HashtableNode* node = NULL;
pthread_t api_pth = 0;
libp2p_logger_add_class("daemon"); libp2p_logger_add_class("daemon");
libp2p_logger_add_class("null"); libp2p_logger_add_class("null");
@ -403,9 +406,9 @@ int test_routing_provide() {
// add a file, to prime the connection to peer 1 // add a file, to prime the connection to peer 1
//TODO: Find a better way to do this... //TODO: Find a better way to do this...
size_t bytes_written = 0; size_t bytes_written = 0;
ipfs_node_online_new(ipfs_path, &local_node2); ipfs_node_online_new(&api_pth, ipfs_path, &local_node2);
ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, local_node2, &bytes_written, 0); ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, local_node2, &bytes_written, 0);
ipfs_node_free(local_node2); ipfs_node_free(&api_pth, local_node2);
// start the daemon in a separate thread // start the daemon in a separate thread
if (pthread_create(&thread2, NULL, test_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"); fprintf(stderr, "Unable to start thread 2\n");
@ -466,6 +469,8 @@ int test_routing_retrieve_file_third_party() {
struct MultiAddress* ma_peer1 = NULL; struct MultiAddress* ma_peer1 = NULL;
struct Libp2pVector* ma_vector2 = NULL, *ma_vector3 = NULL; struct Libp2pVector* ma_vector2 = NULL, *ma_vector3 = NULL;
struct HashtableNode* node = NULL, *result_node = NULL; struct HashtableNode* node = NULL, *result_node = NULL;
pthread_t api_pth1 = 0;
pthread_t api_pth2 = 0;
// create peer 1 // create peer 1
drop_and_build_repository(ipfs_path, 4001, NULL, &peer_id_1); drop_and_build_repository(ipfs_path, 4001, NULL, &peer_id_1);
@ -495,11 +500,11 @@ int test_routing_retrieve_file_third_party() {
// add a file, to prime the connection to peer 1 // add a file, to prime the connection to peer 1
//TODO: Find a better way to do this... //TODO: Find a better way to do this...
size_t bytes_written = 0; size_t bytes_written = 0;
if (!ipfs_node_online_new(ipfs_path, &ipfs_node2)) if (!ipfs_node_online_new(&api_pth1, ipfs_path, &ipfs_node2))
goto exit; goto exit;
ipfs_node2->routing->Bootstrap(ipfs_node2->routing); ipfs_node2->routing->Bootstrap(ipfs_node2->routing);
ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, ipfs_node2, &bytes_written, 0); ipfs_import_file(NULL, "/home/parallels/ipfstest/hello_world.txt", &node, ipfs_node2, &bytes_written, 0);
ipfs_node_free(ipfs_node2); ipfs_node_free(&api_pth1, ipfs_node2);
// start the daemon in a separate thread // start the daemon in a separate thread
libp2p_logger_debug("test_routing", "Firing up daemon 2.\n"); libp2p_logger_debug("test_routing", "Firing up daemon 2.\n");
if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0) { if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0) {
@ -520,7 +525,7 @@ int test_routing_retrieve_file_third_party() {
libp2p_utils_vector_add(ma_vector3, ma_peer1); libp2p_utils_vector_add(ma_vector3, ma_peer1);
drop_and_build_repository(ipfs_path, 4003, ma_vector3, &peer_id_3); drop_and_build_repository(ipfs_path, 4003, ma_vector3, &peer_id_3);
multiaddress_free(ma_peer1); multiaddress_free(ma_peer1);
ipfs_node_online_new(ipfs_path, &ipfs_node3); ipfs_node_online_new(&api_pth2, ipfs_path, &ipfs_node3);
ipfs_node3->routing->Bootstrap(ipfs_node3->routing); ipfs_node3->routing->Bootstrap(ipfs_node3->routing);
@ -547,7 +552,7 @@ int test_routing_retrieve_file_third_party() {
if (thread2_started) if (thread2_started)
pthread_join(thread2, NULL); pthread_join(thread2, NULL);
if (ipfs_node3 != NULL) if (ipfs_node3 != NULL)
ipfs_node_free(ipfs_node3); ipfs_node_free(&api_pth2, ipfs_node3);
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)
@ -629,11 +634,12 @@ int test_routing_retrieve_large_file() {
// add a file, to prime the connection to peer 1 // add a file, to prime the connection to peer 1
//TODO: Find a better way to do this... //TODO: Find a better way to do this...
size_t bytes_written = 0; size_t bytes_written = 0;
if (!ipfs_node_online_new(ipfs_path, &ipfs_node2)) pthread_t api_pth1 = 0;
if (!ipfs_node_online_new(&api_pth1, ipfs_path, &ipfs_node2))
goto exit; goto exit;
ipfs_node2->routing->Bootstrap(ipfs_node2->routing); ipfs_node2->routing->Bootstrap(ipfs_node2->routing);
ipfs_import_file(NULL, "/home/parallels/ipfstest/test_import_large.tmp", &node, ipfs_node2, &bytes_written, 0); ipfs_import_file(NULL, "/home/parallels/ipfstest/test_import_large.tmp", &node, ipfs_node2, &bytes_written, 0);
ipfs_node_free(ipfs_node2); ipfs_node_free(&api_pth1, ipfs_node2);
// start the daemon in a separate thread // start the daemon in a separate thread
libp2p_logger_debug("test_routing", "Firing up daemon 2.\n"); libp2p_logger_debug("test_routing", "Firing up daemon 2.\n");
if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0) { if (pthread_create(&thread2, NULL, test_daemon_start, (void*)ipfs_path) < 0) {
@ -655,7 +661,8 @@ int test_routing_retrieve_large_file() {
libp2p_utils_vector_add(ma_vector3, ma_peer1); libp2p_utils_vector_add(ma_vector3, ma_peer1);
drop_and_build_repository(ipfs_path, 4003, ma_vector3, &peer_id_3); drop_and_build_repository(ipfs_path, 4003, ma_vector3, &peer_id_3);
multiaddress_free(ma_peer1); multiaddress_free(ma_peer1);
ipfs_node_online_new(ipfs_path, &ipfs_node3); pthread_t api_pth2 = 0;
ipfs_node_online_new(&api_pth2, ipfs_path, &ipfs_node3);
ipfs_node3->routing->Bootstrap(ipfs_node3->routing); ipfs_node3->routing->Bootstrap(ipfs_node3->routing);
@ -680,7 +687,7 @@ int test_routing_retrieve_large_file() {
if (thread2_started) if (thread2_started)
pthread_join(thread2, NULL); pthread_join(thread2, NULL);
if (ipfs_node3 != NULL) if (ipfs_node3 != NULL)
ipfs_node_free(ipfs_node3); ipfs_node_free(&api_pth2, ipfs_node3);
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)

View file

@ -4,6 +4,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <pthread.h>
#include "ipfs/repo/init.h" #include "ipfs/repo/init.h"
#include "ipfs/repo/fsrepo/fs_repo.h" #include "ipfs/repo/fsrepo/fs_repo.h"

View file

@ -1,3 +1,5 @@
#include <pthread.h>
#include "cid/test_cid.h" #include "cid/test_cid.h"
#include "cmd/ipfs/test_init.h" #include "cmd/ipfs/test_init.h"
#include "core/test_api.h" #include "core/test_api.h"