c-ipfs/test/core/test_compat_go.h

60 lines
1.6 KiB
C
Raw Permalink Normal View History

2017-11-23 12:45:06 +00:00
#include "stdio.h"
#include "libp2p/utils/logger.h"
#include "ipfs/core/daemon.h"
#include "ipfs/core/swarm.h"
// forward declarations
int ipfs_swarm_connect(struct IpfsNode* local_node, const char* address);
int test_compat_go_join_swarm() {
int retVal = 0;
char* ipfs_path1 = "/tmp/ipfs_1";
char* config_file1 = "config.test1.wo_journal";
pthread_t daemon_thread;
struct FSRepo* fs_repo = NULL;
2017-11-29 04:42:17 +00:00
/*
2017-11-27 14:06:57 +00:00
libp2p_logger_add_class("test_api");
libp2p_logger_add_class("identify");
libp2p_logger_add_class("null");
2017-11-29 03:44:45 +00:00
libp2p_logger_add_class("multistream");
libp2p_logger_add_class("swarm");
libp2p_logger_add_class("secio");
2017-11-29 04:42:17 +00:00
*/
libp2p_logger_add_class("dialer");
libp2p_logger_add_class("yamux");
2017-11-27 14:06:57 +00:00
2017-11-23 12:45:06 +00:00
// Here is the connection information for the GO version:
char* remote_string = "/ip4/10.211.55.2/tcp/4001/ipfs/QmacSE6bCZiAu7nrYkhPATaSoL2q9BszkKzbX6fCiXuBGA";
// build repo
if (!drop_build_open_repo(ipfs_path1, &fs_repo, config_file1)) {
ipfs_repo_fsrepo_free(fs_repo);
libp2p_logger_error("test_api", "Unable to drop and build repository at %s\n", ipfs_path1);
goto exit;
}
ipfs_repo_fsrepo_free(fs_repo);
// start daemon
pthread_create(&daemon_thread, NULL, test_daemon_start, (void*)ipfs_path1);
sleep(3);
// try to connect to a remote swarm
struct IpfsNode *local_node = NULL;
ipfs_node_offline_new(ipfs_path1, &local_node);
2017-11-27 14:06:57 +00:00
if (!ipfs_swarm_connect(local_node, remote_string)) {
libp2p_logger_error("test_api", "Unable to do swarm connect.\n");
goto exit;
}
// see what the remote will do
sleep(20);
2017-11-23 12:45:06 +00:00
retVal = 1;
exit:
ipfs_daemon_stop();
pthread_join(daemon_thread, NULL);
return retVal;
}