From f96209fc4b115c043c2262ec16bac861b8186256 Mon Sep 17 00:00:00 2001 From: John Jones Date: Thu, 23 Nov 2017 07:45:06 -0500 Subject: [PATCH] Minor fixes for yamux testing with GO --- core/swarm.c | 6 ++++++ test/core/test_compat_go.h | 42 ++++++++++++++++++++++++++++++++++++++ test/testit.c | 3 ++- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 test/core/test_compat_go.h diff --git a/core/swarm.c b/core/swarm.c index 1c924e2..ab3a7e1 100644 --- a/core/swarm.c +++ b/core/swarm.c @@ -6,6 +6,12 @@ #include "ipfs/core/swarm.h" #include "ipfs/core/http_request.h" +/*** + * Connect to a swarm + * @param local_node the local node + * @param address the address of the remote + * @returns true(1) on success, false(0) otherwise + */ int ipfs_swarm_connect(struct IpfsNode* local_node, const char* address) { char* response = NULL; size_t response_size; diff --git a/test/core/test_compat_go.h b/test/core/test_compat_go.h new file mode 100644 index 0000000..222e64f --- /dev/null +++ b/test/core/test_compat_go.h @@ -0,0 +1,42 @@ +#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; + + // 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); + ipfs_swarm_connect(local_node, remote_string); + + retVal = 1; + exit: + ipfs_daemon_stop(); + pthread_join(daemon_thread, NULL); + return retVal; +} diff --git a/test/testit.c b/test/testit.c index 5235b26..43b631b 100644 --- a/test/testit.c +++ b/test/testit.c @@ -7,6 +7,7 @@ #include "core/test_null.h" #include "core/test_daemon.h" #include "core/test_node.h" +#include "core/test_compat_go.h" #include "exchange/test_bitswap.h" #include "exchange/test_bitswap_request_queue.h" #include "flatfs/test_flatfs.h" @@ -124,7 +125,6 @@ int build_test_collection() { add_test("test_merkledag_get_data", test_merkledag_get_data, 1); add_test("test_merkledag_add_node", test_merkledag_add_node, 1); add_test("test_merkledag_add_node_with_links", test_merkledag_add_node_with_links, 1); - // 50 below add_test("test_namesys_publisher_publish", test_namesys_publisher_publish, 1); add_test("test_namesys_resolver_resolve", test_namesys_resolver_resolve, 1); add_test("test_resolver_get", test_resolver_get, 0); // not working (test directory does not exist) @@ -142,6 +142,7 @@ int build_test_collection() { add_test("test_ping", test_ping, 0); // socket connect failed add_test("test_ping_remote", test_ping_remote, 0); // need to test more add_test("test_null_add_provider", test_null_add_provider, 0); // need to test more + add_test("test_compat_go_join_swarm", test_compat_go_join_swarm, 0); // remote must be running return 1; }