Skip to content
Snippets Groups Projects
Commit c40ba83c authored by Adrien Béraud's avatar Adrien Béraud
Browse files

c: support building with autotools

parent 7dc5aa9d
Branches
Tags
No related merge requests found
...@@ -4,6 +4,10 @@ SUBDIRS = ...@@ -4,6 +4,10 @@ SUBDIRS =
SUBDIRS += src SUBDIRS += src
if ENABLE_C
SUBDIRS += c
endif
if ENABLE_TOOLS if ENABLE_TOOLS
SUBDIRS += tools SUBDIRS += tools
endif endif
......
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
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
extern "C" { extern "C" {
#endif #endif
#include "def.h" #include <opendht/def.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <stdbool.h> #include <stdbool.h>
......
...@@ -32,6 +32,13 @@ AS_IF([test "x$enable_logs" != "xno"], [ ...@@ -32,6 +32,13 @@ AS_IF([test "x$enable_logs" != "xno"], [
AC_DEFINE([OPENDHT_LOG], [false], [Define if DHT logs are enabled]) 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 dnl Check for indexation
AC_ARG_ENABLE([indexation], [AS_HELP_STRING([--disable-indexation], [Disable DHT indexation])]) AC_ARG_ENABLE([indexation], [AS_HELP_STRING([--disable-indexation], [Disable DHT indexation])])
AM_CONDITIONAL(ENABLE_INDEXATION, test x$enable_indexation != "xno") AM_CONDITIONAL(ENABLE_INDEXATION, test x$enable_indexation != "xno")
...@@ -198,6 +205,7 @@ AC_SUBST(PROJECT_BINARY_DIR, "../src/.libs") ...@@ -198,6 +205,7 @@ AC_SUBST(PROJECT_BINARY_DIR, "../src/.libs")
AC_CONFIG_FILES([Makefile AC_CONFIG_FILES([Makefile
src/Makefile src/Makefile
c/Makefile
tools/Makefile tools/Makefile
python/Makefile python/Makefile
python/setup.py python/setup.py
......
...@@ -11,3 +11,10 @@ dhtchat_LDFLAGS = -lopendht -lreadline -L@top_builddir@/src/.libs @GnuTLS_LIBS@ ...@@ -11,3 +11,10 @@ dhtchat_LDFLAGS = -lopendht -lreadline -L@top_builddir@/src/.libs @GnuTLS_LIBS@
dhtscanner_SOURCES = dhtscanner.cpp dhtscanner_SOURCES = dhtscanner.cpp
dhtscanner_LDFLAGS = -lopendht -lreadline -L@top_builddir@/src/.libs @GnuTLS_LIBS@ 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
...@@ -75,37 +75,41 @@ int main() ...@@ -75,37 +75,41 @@ int main()
pk_id = dht_publickey_get_id(pk); pk_id = dht_publickey_get_id(pk);
printf("Key ID: %s\n", dht_infohash_print(&pk_id)); printf("Key ID: %s\n", dht_infohash_print(&pk_id));
dht_publickey_delete(pk); dht_publickey_delete(pk);
dht_identity_delete(&id); dht_identity_delete(&id);
dht_runner* runner = dht_runner_new();
dht_runner_run(runner, 4040);
dht_infohash h; dht_infohash h;
dht_infohash_random(&h); //dht_infohash_random(&h);
dht_infohash_get_from_string(&h, "bad_actors_test");
printf("random hash: %s\n", dht_infohash_print(&h)); printf("hash: %s\n", dht_infohash_print(&h));
// Put data // Put data
const char* data_str = "yo, this is some data"; const char* data_str = "yo, this is some data";
dht_value* val = dht_value_new_from_string(data_str); 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)); struct op_context* ctx = malloc(sizeof(struct op_context));
ctx->runner = runner; ctx->runner = runner;
ctx->d = 42; 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_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); struct sockaddr** addrs = dht_runner_get_public_address(runner);
for (struct sockaddr** addrIt = addrs; *addrIt; addrIt++) { for (struct sockaddr** addrIt = addrs; *addrIt; addrIt++) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment