diff --git a/core/Makefile b/core/Makefile index 0fde7d7..8dac3a1 100644 --- a/core/Makefile +++ b/core/Makefile @@ -7,7 +7,7 @@ endif LFLAGS = DEPS = builder.h ipfs_node.h -OBJS = builder.o daemon.o null.o ping.o bootstrap.o ipfs_node.o +OBJS = builder.o daemon.o null.o ping.o bootstrap.o ipfs_node.o api.o %.o: %.c $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) diff --git a/core/api.c b/core/api.c index e296276..010a11d 100644 --- a/core/api.c +++ b/core/api.c @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -44,7 +45,7 @@ int find_chunk(char *buf, const size_t buf_size, size_t *pos, size_t *size) char *p = NULL; *size = strtol(buf, &p, 16); - if (*size < 0 || !p || p < buf || p > (buf + 10)) { + if (!p || p < buf || p > (buf + 10)) { return 0; } *pos = (int)(p - buf); diff --git a/include/ipfs/core/api.h b/include/ipfs/core/api.h index b5597c4..b1852d9 100644 --- a/include/ipfs/core/api.h +++ b/include/ipfs/core/api.h @@ -1,5 +1,7 @@ #pragma once +#include + #ifdef __x86_64__ #define INT_TYPE uint64_t #else diff --git a/main/Makefile b/main/Makefile index b194bd6..aff6171 100644 --- a/main/Makefile +++ b/main/Makefile @@ -7,7 +7,7 @@ OBJS = main.o \ ../cid/cid.o \ ../cmd/ipfs/init.o \ ../commands/argument.o ../commands/command_option.o ../commands/command.o ../commands/cli/parse.o \ - ../core/builder.o ../core/daemon.o ../core/null.o ../core/ping.o ../core/bootstrap.o ../core/ipfs_node.o \ + ../core/*.o \ ../datastore/ds_helper.o \ ../datastore/key.o \ ../dnslink/*.o \ diff --git a/test/Makefile b/test/Makefile index 50c5abf..c11c531 100644 --- a/test/Makefile +++ b/test/Makefile @@ -7,12 +7,7 @@ OBJS = testit.o test_helper.o \ ../cid/cid.o \ ../cmd/ipfs/init.o \ ../commands/argument.o ../commands/command_option.o ../commands/command.o ../commands/cli/parse.o \ - ../core/builder.o \ - ../core/daemon.o \ - ../core/null.o \ - ../core/bootstrap.o \ - ../core/ping.o \ - ../core/ipfs_node.o \ + ../core/*.o \ ../datastore/ds_helper.o \ ../exchange/bitswap/*.o \ ../flatfs/flatfs.o \ diff --git a/test/core/test_api.h b/test/core/test_api.h new file mode 100644 index 0000000..2e79384 --- /dev/null +++ b/test/core/test_api.h @@ -0,0 +1,15 @@ +#include "ipfs/core/api.h" +#include "libp2p/utils/logger.h" + +int test_core_api_startup_shutdown() { + if (!api_start(1234, 10, 5)) { + libp2p_logger_error("test_api", "api_start failed.\n"); + return 0; + } + sleep(5); + if (!api_stop()) { + libp2p_logger_error("test_api", "api_stop failed.\n"); + return 0; + } + return 1; +} diff --git a/test/core/test_null.h b/test/core/test_null.h index 85027d5..15612d2 100644 --- a/test/core/test_null.h +++ b/test/core/test_null.h @@ -1,4 +1,5 @@ #include +#include "ipfs/importer/importer.h" int test_null_add_provider() { int retVal = 0; @@ -17,7 +18,7 @@ int test_null_add_provider() { 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; @@ -35,7 +36,7 @@ int test_null_add_provider() { 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; // wait for everything to start up diff --git a/test/testit.c b/test/testit.c index 38560ac..686c129 100644 --- a/test/testit.c +++ b/test/testit.c @@ -1,5 +1,10 @@ #include "cid/test_cid.h" #include "cmd/ipfs/test_init.h" +#include "core/test_api.h" +#include "core/test_ping.h" +#include "core/test_null.h" +#include "core/test_daemon.h" +#include "core/test_node.h" #include "exchange/test_bitswap.h" #include "exchange/test_bitswap_request_queue.h" #include "flatfs/test_flatfs.h" @@ -18,10 +23,6 @@ #include "storage/test_datastore.h" #include "storage/test_blocks.h" #include "storage/test_unixfs.h" -#include "core/test_ping.h" -#include "core/test_null.h" -#include "core/test_daemon.h" -#include "core/test_node.h" #include "libp2p/utils/logger.h" int testit(const char* name, int (*func)(void)) { @@ -45,6 +46,7 @@ const char* names[] = { "test_cid_cast_multihash", "test_cid_cast_non_multihash", "test_cid_protobuf_encode_decode", + "test_core_api_startup_shutdown", "test_daemon_startup_shutdown", "test_datastore_list_journal", "test_journal_encode_decode", @@ -105,6 +107,7 @@ int (*funcs[])(void) = { test_cid_cast_multihash, test_cid_cast_non_multihash, test_cid_protobuf_encode_decode, + test_core_api_startup_shutdown, test_daemon_startup_shutdown, test_datastore_list_journal, test_journal_encode_decode,