diff --git a/Makefile.am b/Makefile.am index 7ba6efbb258e792adaac69173394c7a6a3064b09..498329ba2a189a8aba1e651970f02829d9076a23 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,10 @@ SUBDIRS = SUBDIRS += src +if ENABLE_C +SUBDIRS += c +endif + if ENABLE_TOOLS SUBDIRS += tools endif diff --git a/c/Makefile.am b/c/Makefile.am new file mode 100644 index 0000000000000000000000000000000000000000..4e690d7932e7b1d5ff883ee5c3a0817f461eac63 --- /dev/null +++ b/c/Makefile.am @@ -0,0 +1,12 @@ +lib_LTLIBRARIES = libopendht-c.la +noinst_HEADERS = opendht_c.h + +AM_CPPFLAGS = -isystem @top_srcdir@/include @JsonCpp_CFLAGS@ @MsgPack_CFLAGS@ + +libopendht_c_la_LIBADD = $(LIBOBJS) ../src/.libs/libopendht.la + +libopendht_c_la_SOURCES = \ + opendht.cpp + +nobase_include_HEADERS = \ + opendht_c.h diff --git a/c/opendht_c.h b/c/opendht_c.h index 3d2c72abf2a4e9c43a69aaf7e12bc7406c0e0b05..4b3bb729285d7b8e47a9a43ae7889c6b8d836029 100644 --- a/c/opendht_c.h +++ b/c/opendht_c.h @@ -22,7 +22,7 @@ extern "C" { #endif -#include "def.h" +#include <opendht/def.h> #include <sys/socket.h> #include <netinet/in.h> #include <stdbool.h> diff --git a/configure.ac b/configure.ac index 1e006df79569d29848286ce3ed0141e12ecc36e2..b424b802b786d48882aeec38cc501fb5ce0853d2 100644 --- a/configure.ac +++ b/configure.ac @@ -32,6 +32,13 @@ AS_IF([test "x$enable_logs" != "xno"], [ AC_DEFINE([OPENDHT_LOG], [false], [Define if DHT logs are enabled]) ]) +dnl Check for C binding +AC_ARG_ENABLE([c], [AS_HELP_STRING([--disable-c], [Disable DHT C binding])]) +AM_CONDITIONAL(ENABLE_C, test x$enable_c != "xno") +AM_COND_IF(ENABLE_C, [ + AC_DEFINE([OPENDHT_C], [], [Define if DHT C biding is enabled]) +]) + dnl Check for indexation AC_ARG_ENABLE([indexation], [AS_HELP_STRING([--disable-indexation], [Disable DHT indexation])]) AM_CONDITIONAL(ENABLE_INDEXATION, test x$enable_indexation != "xno") @@ -198,6 +205,7 @@ AC_SUBST(PROJECT_BINARY_DIR, "../src/.libs") AC_CONFIG_FILES([Makefile src/Makefile + c/Makefile tools/Makefile python/Makefile python/setup.py diff --git a/tools/Makefile.am b/tools/Makefile.am index 14284d02a96a5c15d73a0c4bd045e93ee262886c..0e8ec15a404f8a7b999e8fc5a17919562967698f 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -11,3 +11,10 @@ dhtchat_LDFLAGS = -lopendht -lreadline -L@top_builddir@/src/.libs @GnuTLS_LIBS@ dhtscanner_SOURCES = dhtscanner.cpp dhtscanner_LDFLAGS = -lopendht -lreadline -L@top_builddir@/src/.libs @GnuTLS_LIBS@ + +if ENABLE_C +bin_PROGRAMS += dhtcnode +dhtcnode_CFLAGS = -isystem @top_srcdir@/c -isystem @top_srcdir@/include +dhtcnode_SOURCES = dhtcnode.c +dhtcnode_LDFLAGS = -lopendht-c -L@top_builddir@/c/.libs +endif diff --git a/tools/dhtcnode.c b/tools/dhtcnode.c index 7a7df77c865a48aef823331175aaac2dfd3f99d0..21d9da86bc06bb03311c92cef58ac8bc131bf33d 100644 --- a/tools/dhtcnode.c +++ b/tools/dhtcnode.c @@ -75,37 +75,41 @@ int main() pk_id = dht_publickey_get_id(pk); printf("Key ID: %s\n", dht_infohash_print(&pk_id)); dht_publickey_delete(pk); - dht_identity_delete(&id); - dht_runner* runner = dht_runner_new(); - dht_runner_run(runner, 4040); - dht_infohash h; - dht_infohash_random(&h); - - printf("random hash: %s\n", dht_infohash_print(&h)); + //dht_infohash_random(&h); + dht_infohash_get_from_string(&h, "bad_actors_test"); + printf("hash: %s\n", dht_infohash_print(&h)); // Put data const char* data_str = "yo, this is some data"; dht_value* val = dht_value_new_from_string(data_str); - dht_runner_put(runner, &h, val, dht_done_callback, runner, false); - dht_value_unref(val); - // Get data - dht_runner_get(runner, &h, dht_get_callback, dht_done_callback, runner); - - // Listen for data struct op_context* ctx = malloc(sizeof(struct op_context)); ctx->runner = runner; ctx->d = 42; - dht_op_token* token = dht_runner_listen(runner, &h, dht_value_callback, op_context_free, ctx); - sleep(1); + dht_runner* runner = dht_runner_new(); + dht_runner_config dht_config; + dht_runner_config_default(&dht_config); + dht_config.peer_discovery = true; // Look for other peers on the network + dht_config.peer_publish = true; // Publish our own peer info + dht_runner_run_config(runner, 4040, &dht_config); + + + // Get data + //dht_runner_get(runner, &h, dht_get_callback, dht_done_callback, runner); + // Listen for data + dht_op_token* token = dht_runner_listen(runner, &h, dht_value_callback, op_context_free, ctx); dht_runner_bootstrap(runner, "bootstrap.jami.net", NULL); + dht_runner_put(runner, &h, val, dht_done_callback, runner, true); + dht_runner_get(runner, &h, dht_get_callback, dht_done_callback, runner); + dht_value_unref(val); - sleep(2); + //sleep(1); + //sleep(20); struct sockaddr** addrs = dht_runner_get_public_address(runner); for (struct sockaddr** addrIt = addrs; *addrIt; addrIt++) {