mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 12:28:42 +00:00
c: support building with autotools
This commit is contained in:
1 parent
7dc5aa9dfd
commit
c40ba83cb3
6 files changed
+53
-18
No files matched your search
@@ -4,6 +4,10 @@ SUBDIRS =
|
||||
|
||||
SUBDIRS += src
|
||||
|
||||
if ENABLE_C
|
||||
SUBDIRS += c
|
||||
endif
|
||||
|
||||
if ENABLE_TOOLS
|
||||
SUBDIRS += tools
|
||||
endif
|
||||
|
||||
@@ -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
|
||||
+1
-1
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
+21
-17
@@ -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_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);
|
||||
|
||||
sleep(1);
|
||||
|
||||
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++) {
|
||||
|
||||
Reference in new issue
Block a user