diff options
author | Bertrand Marc <beberking@gmail.com> | 2012-05-02 21:43:37 +0200 |
---|---|---|
committer | Bertrand Marc <beberking@gmail.com> | 2012-05-02 21:43:37 +0200 |
commit | 2b81464a43485fcc8ce079fafdee7b7a171835f4 (patch) | |
tree | 394774c0f735199b57d51a2d3840356317853fe1 /src/peerinfo |
Imported Upstream version 0.9.2upstream/0.9.2
Diffstat (limited to 'src/peerinfo')
-rw-r--r-- | src/peerinfo/Makefile.am | 69 | ||||
-rw-r--r-- | src/peerinfo/Makefile.in | 917 | ||||
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 671 | ||||
-rw-r--r-- | src/peerinfo/peerinfo.conf.in | 24 | ||||
-rw-r--r-- | src/peerinfo/peerinfo.h | 88 | ||||
-rw-r--r-- | src/peerinfo/peerinfo_api.c | 661 | ||||
-rw-r--r-- | src/peerinfo/peerinfo_api_notify.c | 292 | ||||
-rwxr-xr-x | src/peerinfo/perf_peerinfo_api.c | 217 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api.c | 220 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api_data.conf | 16 |
10 files changed, 3175 insertions, 0 deletions
diff --git a/src/peerinfo/Makefile.am b/src/peerinfo/Makefile.am new file mode 100644 index 0000000..468fab5 --- /dev/null +++ b/src/peerinfo/Makefile.am @@ -0,0 +1,69 @@ +INCLUDES = -I$(top_srcdir)/src/include + +pkgcfgdir= $(pkgdatadir)/config.d/ + +pkgcfg_DATA = \ + peerinfo.conf + +if MINGW + WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols -lole32 -lshell32 -liconv -lstdc++ -lcomdlg32 -lgdi32 +endif + +if USE_COVERAGE + AM_CFLAGS = --coverage -O0 + XLIB = -lgcov +endif + +lib_LTLIBRARIES = libgnunetpeerinfo.la + +libgnunetpeerinfo_la_SOURCES = \ + peerinfo_api.c peerinfo.h \ + peerinfo_api_notify.c +libgnunetpeerinfo_la_LIBADD = \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(XLIB) +libgnunetpeerinfo_la_LDFLAGS = \ + $(GN_LIB_LDFLAGS) $(WINFLAGS) \ + -version-info 0:0:0 + + +bin_PROGRAMS = \ + gnunet-service-peerinfo + +gnunet_service_peerinfo_SOURCES = \ + gnunet-service-peerinfo.c +gnunet_service_peerinfo_LDADD = \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/statistics/libgnunetstatistics.la \ + $(top_builddir)/src/util/libgnunetutil.la + +if HAVE_BENCHMARKS + PEERINFO_BENCHMARKS = \ + perf_peerinfo_api +endif + +check_PROGRAMS = \ + test_peerinfo_api \ + $(PEERINFO_BENCHMARKS) + +if ENABLE_TEST_RUN +TESTS = $(check_PROGRAMS) +endif + +test_peerinfo_api_SOURCES = \ + test_peerinfo_api.c +test_peerinfo_api_LDADD = \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ + $(top_builddir)/src/util/libgnunetutil.la + +perf_peerinfo_api_SOURCES = \ + perf_peerinfo_api.c +perf_peerinfo_api_LDADD = \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ + $(top_builddir)/src/util/libgnunetutil.la + +EXTRA_DIST = \ + test_peerinfo_api_data.conf diff --git a/src/peerinfo/Makefile.in b/src/peerinfo/Makefile.in new file mode 100644 index 0000000..639e43f --- /dev/null +++ b/src/peerinfo/Makefile.in @@ -0,0 +1,917 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +bin_PROGRAMS = gnunet-service-peerinfo$(EXEEXT) +check_PROGRAMS = test_peerinfo_api$(EXEEXT) $(am__EXEEXT_1) +subdir = src/peerinfo +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ + $(srcdir)/peerinfo.conf.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/absolute-header.m4 \ + $(top_srcdir)/m4/align.m4 $(top_srcdir)/m4/argz.m4 \ + $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ + $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libcurl.m4 \ + $(top_srcdir)/m4/libgcrypt.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/libunistring.m4 $(top_srcdir)/m4/ltdl.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/po.m4 \ + $(top_srcdir)/m4/progtest.m4 $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/gnunet_config.h +CONFIG_CLEAN_FILES = peerinfo.conf +CONFIG_CLEAN_VPATH_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \ + "$(DESTDIR)$(pkgcfgdir)" +LTLIBRARIES = $(lib_LTLIBRARIES) +am__DEPENDENCIES_1 = +libgnunetpeerinfo_la_DEPENDENCIES = \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(am__DEPENDENCIES_1) +am_libgnunetpeerinfo_la_OBJECTS = peerinfo_api.lo \ + peerinfo_api_notify.lo +libgnunetpeerinfo_la_OBJECTS = $(am_libgnunetpeerinfo_la_OBJECTS) +AM_V_lt = $(am__v_lt_$(V)) +am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) +am__v_lt_0 = --silent +libgnunetpeerinfo_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ + $(AM_CFLAGS) $(CFLAGS) $(libgnunetpeerinfo_la_LDFLAGS) \ + $(LDFLAGS) -o $@ +@HAVE_BENCHMARKS_TRUE@am__EXEEXT_1 = perf_peerinfo_api$(EXEEXT) +PROGRAMS = $(bin_PROGRAMS) +am_gnunet_service_peerinfo_OBJECTS = \ + gnunet-service-peerinfo.$(OBJEXT) +gnunet_service_peerinfo_OBJECTS = \ + $(am_gnunet_service_peerinfo_OBJECTS) +gnunet_service_peerinfo_DEPENDENCIES = \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/statistics/libgnunetstatistics.la \ + $(top_builddir)/src/util/libgnunetutil.la +am_perf_peerinfo_api_OBJECTS = perf_peerinfo_api.$(OBJEXT) +perf_peerinfo_api_OBJECTS = $(am_perf_peerinfo_api_OBJECTS) +perf_peerinfo_api_DEPENDENCIES = \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ + $(top_builddir)/src/util/libgnunetutil.la +am_test_peerinfo_api_OBJECTS = test_peerinfo_api.$(OBJEXT) +test_peerinfo_api_OBJECTS = $(am_test_peerinfo_api_OBJECTS) +test_peerinfo_api_DEPENDENCIES = \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ + $(top_builddir)/src/util/libgnunetutil.la +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +SOURCES = $(libgnunetpeerinfo_la_SOURCES) \ + $(gnunet_service_peerinfo_SOURCES) \ + $(perf_peerinfo_api_SOURCES) $(test_peerinfo_api_SOURCES) +DIST_SOURCES = $(libgnunetpeerinfo_la_SOURCES) \ + $(gnunet_service_peerinfo_SOURCES) \ + $(perf_peerinfo_api_SOURCES) $(test_peerinfo_api_SOURCES) +DATA = $(pkgcfg_DATA) +ETAGS = etags +CTAGS = ctags +am__tty_colors = \ +red=; grn=; lgn=; blu=; std= +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +ARGZ_H = @ARGZ_H@ +AS = @AS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFAULT_INTERFACE = @DEFAULT_INTERFACE@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLDIR = @DLLDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +EXT_LIBS = @EXT_LIBS@ +EXT_LIB_PATH = @EXT_LIB_PATH@ +FGREP = @FGREP@ +GMSGFMT = @GMSGFMT@ +GMSGFMT_015 = @GMSGFMT_015@ +GNUNETDNS_GROUP = @GNUNETDNS_GROUP@ +GN_DAEMON_CONFIG_DIR = @GN_DAEMON_CONFIG_DIR@ +GN_DAEMON_HOME_DIR = @GN_DAEMON_HOME_DIR@ +GN_INTLINCL = @GN_INTLINCL@ +GN_LIBINTL = @GN_LIBINTL@ +GN_LIB_LDFLAGS = @GN_LIB_LDFLAGS@ +GN_PLUGIN_LDFLAGS = @GN_PLUGIN_LDFLAGS@ +GN_USER_HOME_DIR = @GN_USER_HOME_DIR@ +GREP = @GREP@ +HAVE_LIBUNISTRING = @HAVE_LIBUNISTRING@ +INCLTDL = @INCLTDL@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +INTLLIBS = @INTLLIBS@ +INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBADD_DL = @LIBADD_DL@ +LIBADD_DLD_LINK = @LIBADD_DLD_LINK@ +LIBADD_DLOPEN = @LIBADD_DLOPEN@ +LIBADD_SHL_LOAD = @LIBADD_SHL_LOAD@ +LIBCURL = @LIBCURL@ +LIBCURL_CPPFLAGS = @LIBCURL_CPPFLAGS@ +LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ +LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ +LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ +LIBICONV = @LIBICONV@ +LIBINTL = @LIBINTL@ +LIBLTDL = @LIBLTDL@ +LIBOBJS = @LIBOBJS@ +LIBPREFIX = @LIBPREFIX@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBUNISTRING = @LIBUNISTRING@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTDLDEPS = @LTDLDEPS@ +LTDLINCL = @LTDLINCL@ +LTDLOPEN = @LTDLOPEN@ +LTLIBICONV = @LTLIBICONV@ +LTLIBINTL = @LTLIBINTL@ +LTLIBOBJS = @LTLIBOBJS@ +LTLIBUNISTRING = @LTLIBUNISTRING@ +LT_CONFIG_H = @LT_CONFIG_H@ +LT_DLLOADERS = @LT_DLLOADERS@ +LT_DLPREOPEN = @LT_DLPREOPEN@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +MSGFMT = @MSGFMT@ +MSGFMT_015 = @MSGFMT_015@ +MSGMERGE = @MSGMERGE@ +MYSQL_CPPFLAGS = @MYSQL_CPPFLAGS@ +MYSQL_LDFLAGS = @MYSQL_LDFLAGS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJC = @OBJC@ +OBJCDEPMODE = @OBJCDEPMODE@ +OBJCFLAGS = @OBJCFLAGS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +POSTGRES_CPPFLAGS = @POSTGRES_CPPFLAGS@ +POSTGRES_LDFLAGS = @POSTGRES_LDFLAGS@ +POSUB = @POSUB@ +PYTHON = @PYTHON@ +PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@ +PYTHON_PLATFORM = @PYTHON_PLATFORM@ +PYTHON_PREFIX = @PYTHON_PREFIX@ +PYTHON_VERSION = @PYTHON_VERSION@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SQLITE_CPPFLAGS = @SQLITE_CPPFLAGS@ +SQLITE_LDFLAGS = @SQLITE_LDFLAGS@ +STRIP = @STRIP@ +SUDO_BINARY = @SUDO_BINARY@ +UNIXONLY = @UNIXONLY@ +USE_NLS = @USE_NLS@ +VERSION = @VERSION@ +XGETTEXT = @XGETTEXT@ +XGETTEXT_015 = @XGETTEXT_015@ +XMKMF = @XMKMF@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +_libcurl_config = @_libcurl_config@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +ac_ct_OBJC = @ac_ct_OBJC@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_target = @build_target@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +lt_ECHO = @lt_ECHO@ +ltdl_LIBOBJS = @ltdl_LIBOBJS@ +ltdl_LTLIBOBJS = @ltdl_LTLIBOBJS@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +pkgpyexecdir = @pkgpyexecdir@ +pkgpythondir = @pkgpythondir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +pyexecdir = @pyexecdir@ +pythondir = @pythondir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +subdirs = @subdirs@ +sys_symbol_underscore = @sys_symbol_underscore@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +INCLUDES = -I$(top_srcdir)/src/include +pkgcfgdir = $(pkgdatadir)/config.d/ +pkgcfg_DATA = \ + peerinfo.conf + +@MINGW_TRUE@WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols -lole32 -lshell32 -liconv -lstdc++ -lcomdlg32 -lgdi32 +@USE_COVERAGE_TRUE@AM_CFLAGS = --coverage -O0 +@USE_COVERAGE_TRUE@XLIB = -lgcov +lib_LTLIBRARIES = libgnunetpeerinfo.la +libgnunetpeerinfo_la_SOURCES = \ + peerinfo_api.c peerinfo.h \ + peerinfo_api_notify.c + +libgnunetpeerinfo_la_LIBADD = \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(XLIB) + +libgnunetpeerinfo_la_LDFLAGS = \ + $(GN_LIB_LDFLAGS) $(WINFLAGS) \ + -version-info 0:0:0 + +gnunet_service_peerinfo_SOURCES = \ + gnunet-service-peerinfo.c + +gnunet_service_peerinfo_LDADD = \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/statistics/libgnunetstatistics.la \ + $(top_builddir)/src/util/libgnunetutil.la + +@HAVE_BENCHMARKS_TRUE@PEERINFO_BENCHMARKS = \ +@HAVE_BENCHMARKS_TRUE@ perf_peerinfo_api + +@ENABLE_TEST_RUN_TRUE@TESTS = $(check_PROGRAMS) +test_peerinfo_api_SOURCES = \ + test_peerinfo_api.c + +test_peerinfo_api_LDADD = \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ + $(top_builddir)/src/util/libgnunetutil.la + +perf_peerinfo_api_SOURCES = \ + perf_peerinfo_api.c + +perf_peerinfo_api_LDADD = \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ + $(top_builddir)/src/util/libgnunetutil.la + +EXTRA_DIST = \ + test_peerinfo_api_data.conf + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/peerinfo/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/peerinfo/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +peerinfo.conf: $(top_builddir)/config.status $(srcdir)/peerinfo.conf.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \ + } + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libgnunetpeerinfo.la: $(libgnunetpeerinfo_la_OBJECTS) $(libgnunetpeerinfo_la_DEPENDENCIES) + $(AM_V_CCLD)$(libgnunetpeerinfo_la_LINK) -rpath $(libdir) $(libgnunetpeerinfo_la_OBJECTS) $(libgnunetpeerinfo_la_LIBADD) $(LIBS) +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p || test -f $$p1; \ + then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(bindir)" && rm -f $$files + +clean-binPROGRAMS: + @list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list + +clean-checkPROGRAMS: + @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list +gnunet-service-peerinfo$(EXEEXT): $(gnunet_service_peerinfo_OBJECTS) $(gnunet_service_peerinfo_DEPENDENCIES) + @rm -f gnunet-service-peerinfo$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(gnunet_service_peerinfo_OBJECTS) $(gnunet_service_peerinfo_LDADD) $(LIBS) +perf_peerinfo_api$(EXEEXT): $(perf_peerinfo_api_OBJECTS) $(perf_peerinfo_api_DEPENDENCIES) + @rm -f perf_peerinfo_api$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(perf_peerinfo_api_OBJECTS) $(perf_peerinfo_api_LDADD) $(LIBS) +test_peerinfo_api$(EXEEXT): $(test_peerinfo_api_OBJECTS) $(test_peerinfo_api_DEPENDENCIES) + @rm -f test_peerinfo_api$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(test_peerinfo_api_OBJECTS) $(test_peerinfo_api_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnunet-service-peerinfo.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/peerinfo_api.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/peerinfo_api_notify.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/perf_peerinfo_api.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_peerinfo_api.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-pkgcfgDATA: $(pkgcfg_DATA) + @$(NORMAL_INSTALL) + test -z "$(pkgcfgdir)" || $(MKDIR_P) "$(DESTDIR)$(pkgcfgdir)" + @list='$(pkgcfg_DATA)'; test -n "$(pkgcfgdir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pkgcfgdir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(pkgcfgdir)" || exit $$?; \ + done + +uninstall-pkgcfgDATA: + @$(NORMAL_UNINSTALL) + @list='$(pkgcfg_DATA)'; test -n "$(pkgcfgdir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + test -n "$$files" || exit 0; \ + echo " ( cd '$(DESTDIR)$(pkgcfgdir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(pkgcfgdir)" && rm -f $$files + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +check-TESTS: $(TESTS) + @failed=0; all=0; xfail=0; xpass=0; skip=0; \ + srcdir=$(srcdir); export srcdir; \ + list=' $(TESTS) '; \ + $(am__tty_colors); \ + if test -n "$$list"; then \ + for tst in $$list; do \ + if test -f ./$$tst; then dir=./; \ + elif test -f $$tst; then dir=; \ + else dir="$(srcdir)/"; fi; \ + if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xpass=`expr $$xpass + 1`; \ + failed=`expr $$failed + 1`; \ + col=$$red; res=XPASS; \ + ;; \ + *) \ + col=$$grn; res=PASS; \ + ;; \ + esac; \ + elif test $$? -ne 77; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xfail=`expr $$xfail + 1`; \ + col=$$lgn; res=XFAIL; \ + ;; \ + *) \ + failed=`expr $$failed + 1`; \ + col=$$red; res=FAIL; \ + ;; \ + esac; \ + else \ + skip=`expr $$skip + 1`; \ + col=$$blu; res=SKIP; \ + fi; \ + echo "$${col}$$res$${std}: $$tst"; \ + done; \ + if test "$$all" -eq 1; then \ + tests="test"; \ + All=""; \ + else \ + tests="tests"; \ + All="All "; \ + fi; \ + if test "$$failed" -eq 0; then \ + if test "$$xfail" -eq 0; then \ + banner="$$All$$all $$tests passed"; \ + else \ + if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ + banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ + fi; \ + else \ + if test "$$xpass" -eq 0; then \ + banner="$$failed of $$all $$tests failed"; \ + else \ + if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ + banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ + fi; \ + fi; \ + dashes="$$banner"; \ + skipped=""; \ + if test "$$skip" -ne 0; then \ + if test "$$skip" -eq 1; then \ + skipped="($$skip test was not run)"; \ + else \ + skipped="($$skip tests were not run)"; \ + fi; \ + test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$skipped"; \ + fi; \ + report=""; \ + if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ + report="Please report to $(PACKAGE_BUGREPORT)"; \ + test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$report"; \ + fi; \ + dashes=`echo "$$dashes" | sed s/./=/g`; \ + if test "$$failed" -eq 0; then \ + echo "$$grn$$dashes"; \ + else \ + echo "$$red$$dashes"; \ + fi; \ + echo "$$banner"; \ + test -z "$$skipped" || echo "$$skipped"; \ + test -z "$$report" || echo "$$report"; \ + echo "$$dashes$$std"; \ + test "$$failed" -eq 0; \ + else :; fi + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am + $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) + $(MAKE) $(AM_MAKEFLAGS) check-TESTS +check: check-am +all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(DATA) +install-binPROGRAMS: install-libLTLIBRARIES + +installdirs: + for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(pkgcfgdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-binPROGRAMS clean-checkPROGRAMS clean-generic \ + clean-libLTLIBRARIES clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: install-pkgcfgDATA + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-binPROGRAMS install-libLTLIBRARIES + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-binPROGRAMS uninstall-libLTLIBRARIES \ + uninstall-pkgcfgDATA + +.MAKE: check-am install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \ + clean-binPROGRAMS clean-checkPROGRAMS clean-generic \ + clean-libLTLIBRARIES clean-libtool ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-binPROGRAMS install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-libLTLIBRARIES install-man install-pdf \ + install-pdf-am install-pkgcfgDATA install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags uninstall uninstall-am \ + uninstall-binPROGRAMS uninstall-libLTLIBRARIES \ + uninstall-pkgcfgDATA + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c new file mode 100644 index 0000000..d6e52d4 --- /dev/null +++ b/src/peerinfo/gnunet-service-peerinfo.c @@ -0,0 +1,671 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2004, 2005, 2007, 2009, 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file peerinfo/gnunet-service-peerinfo.c + * @brief maintains list of known peers + * + * Code to maintain the list of currently known hosts (in memory + * structure of data/hosts/). + * + * @author Christian Grothoff + * + * TODO: + * - HostEntries are never 'free'd (add expiration, upper bound?) + */ + +#include "platform.h" +#include "gnunet_crypto_lib.h" +#include "gnunet_container_lib.h" +#include "gnunet_disk_lib.h" +#include "gnunet_hello_lib.h" +#include "gnunet_protocols.h" +#include "gnunet_service_lib.h" +#include "gnunet_statistics_service.h" +#include "peerinfo.h" + +/** + * How often do we scan the HOST_DIR for new entries? + */ +#define DATA_HOST_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) + +/** + * How often do we discard old entries in data/hosts/? + */ +#define DATA_HOST_CLEAN_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60) + +/** + * In-memory cache of known hosts. + */ +struct HostEntry +{ + + /** + * Identity of the peer. + */ + struct GNUNET_PeerIdentity identity; + + /** + * Hello for the peer (can be NULL) + */ + struct GNUNET_HELLO_Message *hello; + +}; + + +/** + * The in-memory list of known hosts, mapping of + * host IDs to 'struct HostEntry*' values. + */ +static struct GNUNET_CONTAINER_MultiHashMap *hostmap; + +/** + * Clients to immediately notify about all changes. + */ +static struct GNUNET_SERVER_NotificationContext *notify_list; + +/** + * Directory where the hellos are stored in (data/hosts) + */ +static char *networkIdDirectory; + +/** + * Handle for reporting statistics. + */ +static struct GNUNET_STATISTICS_Handle *stats; + + +/** + * Notify all clients in the notify list about the + * given host entry changing. + */ +static struct InfoMessage * +make_info_message (const struct HostEntry *he) +{ + struct InfoMessage *im; + size_t hs; + + hs = (he->hello == NULL) ? 0 : GNUNET_HELLO_size (he->hello); + im = GNUNET_malloc (sizeof (struct InfoMessage) + hs); + im->header.size = htons (hs + sizeof (struct InfoMessage)); + im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); + im->peer = he->identity; + if (he->hello != NULL) + memcpy (&im[1], he->hello, hs); + return im; +} + + +/** + * Address iterator that causes expired entries to be discarded. + * + * @param cls pointer to the current time + * @param address the address + * @param expiration expiration time for the address + * @return GNUNET_NO if expiration smaller than the current time + */ +static int +discard_expired (void *cls, const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) +{ + const struct GNUNET_TIME_Absolute *now = cls; + + if (now->abs_value > expiration.abs_value) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Removing expired address of transport `%s'\n"), + address->transport_name); + return GNUNET_NO; + } + return GNUNET_OK; +} + + +/** + * Get the filename under which we would store the GNUNET_HELLO_Message + * for the given host and protocol. + * @return filename of the form DIRECTORY/HOSTID + */ +static char * +get_host_filename (const struct GNUNET_PeerIdentity *id) +{ + struct GNUNET_CRYPTO_HashAsciiEncoded fil; + char *fn; + + GNUNET_CRYPTO_hash_to_enc (&id->hashPubKey, &fil); + GNUNET_asprintf (&fn, "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR, &fil); + return fn; +} + + +/** + * Broadcast information about the given entry to all + * clients that care. + * + * @param entry entry to broadcast about + */ +static void +notify_all (struct HostEntry *entry) +{ + struct InfoMessage *msg; + + msg = make_info_message (entry); + GNUNET_SERVER_notification_context_broadcast (notify_list, &msg->header, + GNUNET_NO); + GNUNET_free (msg); +} + + +/** + * Add a host to the list. + * + * @param identity the identity of the host + */ +static void +add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) +{ + struct HostEntry *entry; + char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; + const struct GNUNET_HELLO_Message *hello; + struct GNUNET_HELLO_Message *hello_clean; + int size; + struct GNUNET_TIME_Absolute now; + char *fn; + + entry = GNUNET_CONTAINER_multihashmap_get (hostmap, &identity->hashPubKey); + if (entry != NULL) + return; + GNUNET_STATISTICS_update (stats, gettext_noop ("# peers known"), 1, + GNUNET_NO); + entry = GNUNET_malloc (sizeof (struct HostEntry)); + entry->identity = *identity; + + fn = get_host_filename (identity); + if (GNUNET_DISK_file_test (fn) == GNUNET_YES) + { + size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); + hello = (const struct GNUNET_HELLO_Message *) buffer; + if ((size < sizeof (struct GNUNET_MessageHeader)) || + (size != ntohs ((((const struct GNUNET_MessageHeader *) hello)->size))) + || (size != GNUNET_HELLO_size (hello))) + { + GNUNET_break (0); + if (0 != UNLINK (fn)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); + } + else + { + now = GNUNET_TIME_absolute_get (); + hello_clean = + GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired, + &now); + entry->hello = hello_clean; + } + } + GNUNET_free (fn); + GNUNET_CONTAINER_multihashmap_put (hostmap, &identity->hashPubKey, entry, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); + notify_all (entry); +} + + +/** + * Remove a file that should not be there. LOG + * success or failure. + */ +static void +remove_garbage (const char *fullname) +{ + if (0 == UNLINK (fullname)) + GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, + _ + ("File `%s' in directory `%s' does not match naming convention. " + "Removed.\n"), fullname, networkIdDirectory); + else + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, + "unlink", fullname); +} + + +static int +hosts_directory_scan_callback (void *cls, const char *fullname) +{ + unsigned int *matched = cls; + struct GNUNET_PeerIdentity identity; + const char *filename; + + if (GNUNET_DISK_file_test (fullname) != GNUNET_YES) + return GNUNET_OK; /* ignore non-files */ + if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) + { + remove_garbage (fullname); + return GNUNET_OK; + } + filename = + &fullname[strlen (fullname) - + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1]; + if (filename[-1] != DIR_SEPARATOR) + { + remove_garbage (fullname); + return GNUNET_OK; + } + if (GNUNET_OK != + GNUNET_CRYPTO_hash_from_string (filename, &identity.hashPubKey)) + { + remove_garbage (fullname); + return GNUNET_OK; + } + (*matched)++; + add_host_to_known_hosts (&identity); + return GNUNET_OK; +} + + +/** + * Call this method periodically to scan data/hosts for new hosts. + */ +static void +cron_scan_directory_data_hosts (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + static unsigned int retries; + unsigned int count; + + if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) + return; + count = 0; + if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory)) + { + GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ, + GNUNET_SCHEDULER_PRIORITY_IDLE, + &cron_scan_directory_data_hosts, NULL); + return; + } + GNUNET_DISK_directory_scan (networkIdDirectory, + &hosts_directory_scan_callback, &count); + if ((0 == count) && (0 == (++retries & 31))) + GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, + _("Still no peers found in `%s'!\n"), networkIdDirectory); + GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ, + GNUNET_SCHEDULER_PRIORITY_IDLE, + &cron_scan_directory_data_hosts, + NULL); +} + + +/** + * Bind a host address (hello) to a hostId. + * + * @param peer the peer for which this is a hello + * @param hello the verified (!) hello message + */ +static void +bind_address (const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Message *hello) +{ + char *fn; + struct HostEntry *host; + struct GNUNET_HELLO_Message *mrg; + struct GNUNET_TIME_Absolute delta; + + add_host_to_known_hosts (peer); + host = GNUNET_CONTAINER_multihashmap_get (hostmap, &peer->hashPubKey); + GNUNET_assert (host != NULL); + if (host->hello == NULL) + { + host->hello = GNUNET_malloc (GNUNET_HELLO_size (hello)); + memcpy (host->hello, hello, GNUNET_HELLO_size (hello)); + } + else + { + mrg = GNUNET_HELLO_merge (host->hello, hello); + delta = GNUNET_HELLO_equals (mrg, host->hello, GNUNET_TIME_absolute_get ()); + if (delta.abs_value == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value) + { + GNUNET_free (mrg); + return; + } + GNUNET_free (host->hello); + host->hello = mrg; + } + fn = get_host_filename (peer); + if (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn)) + { + if (GNUNET_SYSERR == + GNUNET_DISK_fn_write (fn, host->hello, GNUNET_HELLO_size (host->hello), + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_GROUP_READ | + GNUNET_DISK_PERM_OTHER_READ)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); + + } + GNUNET_free (fn); + notify_all (host); +} + + + +/** + * Do transmit info about peer to given host. + * + * @param cls NULL to hit all hosts, otherwise specifies a particular target + * @param key hostID + * @param value information to transmit + * @return GNUNET_YES (continue to iterate) + */ +static int +add_to_tc (void *cls, const GNUNET_HashCode * key, void *value) +{ + struct GNUNET_SERVER_TransmitContext *tc = cls; + struct HostEntry *pos = value; + struct InfoMessage *im; + uint16_t hs; + char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; + + hs = 0; + im = (struct InfoMessage *) buf; + if (pos->hello != NULL) + { + hs = GNUNET_HELLO_size (pos->hello); + GNUNET_assert (hs < + GNUNET_SERVER_MAX_MESSAGE_SIZE - + sizeof (struct InfoMessage)); + memcpy (&im[1], pos->hello, hs); + } + im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); + im->header.size = htons (sizeof (struct InfoMessage) + hs); + im->reserved = htonl (0); + im->peer = pos->identity; + GNUNET_SERVER_transmit_context_append_message (tc, &im->header); + return GNUNET_YES; +} + + +/** + * @brief delete expired HELLO entries in data/hosts/ + */ +static int +discard_hosts_helper (void *cls, const char *fn) +{ + struct GNUNET_TIME_Absolute *now = cls; + char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; + const struct GNUNET_HELLO_Message *hello; + struct GNUNET_HELLO_Message *new_hello; + int size; + + size = GNUNET_DISK_fn_read (fn, buffer, sizeof (buffer)); + if (size < sizeof (struct GNUNET_MessageHeader)) + { + if (0 != UNLINK (fn)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | + GNUNET_ERROR_TYPE_BULK, "unlink", fn); + return GNUNET_OK; + } + hello = (const struct GNUNET_HELLO_Message *) buffer; + new_hello = + GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired, now); + if (new_hello != NULL) + { + GNUNET_DISK_fn_write (fn, new_hello, GNUNET_HELLO_size (new_hello), + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE | + GNUNET_DISK_PERM_GROUP_READ | + GNUNET_DISK_PERM_OTHER_READ); + GNUNET_free (new_hello); + } + else + { + if (0 != UNLINK (fn)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | + GNUNET_ERROR_TYPE_BULK, "unlink", fn); + } + return GNUNET_OK; +} + + +/** + * Call this method periodically to scan data/hosts for new hosts. + */ +static void +cron_clean_data_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_TIME_Absolute now; + + if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) + return; + now = GNUNET_TIME_absolute_get (); + GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now); + GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, &cron_clean_data_hosts, + NULL); +} + + +/** + * Handle HELLO-message. + * + * @param cls closure + * @param client identification of the client + * @param message the actual message + */ +static void +handle_hello (void *cls, struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + const struct GNUNET_HELLO_Message *hello; + struct GNUNET_PeerIdentity pid; + + hello = (const struct GNUNET_HELLO_Message *) message; + if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } +#if DEBUG_PEERINFO + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n", + "HELLO", GNUNET_i2s (&pid)); +#endif + bind_address (&pid, hello); + GNUNET_SERVER_receive_done (client, GNUNET_OK); +} + + +/** + * Handle GET-message. + * + * @param cls closure + * @param client identification of the client + * @param message the actual message + */ +static void +handle_get (void *cls, struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + const struct ListPeerMessage *lpm; + struct GNUNET_SERVER_TransmitContext *tc; + + lpm = (const struct ListPeerMessage *) message; + GNUNET_break (0 == ntohl (lpm->reserved)); +#if DEBUG_PEERINFO + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received for peer `%4s'\n", + "GET", GNUNET_i2s (&lpm->peer)); +#endif + tc = GNUNET_SERVER_transmit_context_create (client); + GNUNET_CONTAINER_multihashmap_get_multiple (hostmap, &lpm->peer.hashPubKey, + &add_to_tc, tc); + GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, + GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); + GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); +} + + +/** + * Handle GET-ALL-message. + * + * @param cls closure + * @param client identification of the client + * @param message the actual message + */ +static void +handle_get_all (void *cls, struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + struct GNUNET_SERVER_TransmitContext *tc; + +#if DEBUG_PEERINFO + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "GET_ALL"); +#endif + tc = GNUNET_SERVER_transmit_context_create (client); + GNUNET_CONTAINER_multihashmap_iterate (hostmap, &add_to_tc, tc); + GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, + GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); + GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); +} + + +static int +do_notify_entry (void *cls, const GNUNET_HashCode * key, void *value) +{ + struct GNUNET_SERVER_Client *client = cls; + struct HostEntry *he = value; + struct InfoMessage *msg; + + msg = make_info_message (he); + GNUNET_SERVER_notification_context_unicast (notify_list, client, &msg->header, + GNUNET_NO); + GNUNET_free (msg); + return GNUNET_YES; +} + + +/** + * Handle NOTIFY-message. + * + * @param cls closure + * @param client identification of the client + * @param message the actual message + */ +static void +handle_notify (void *cls, struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ +#if DEBUG_PEERINFO + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s' message received\n", "NOTIFY"); +#endif + GNUNET_SERVER_notification_context_add (notify_list, client); + GNUNET_CONTAINER_multihashmap_iterate (hostmap, &do_notify_entry, client); + GNUNET_SERVER_receive_done (client, GNUNET_OK); +} + + +static int +free_host_entry (void *cls, const GNUNET_HashCode * key, void *value) +{ + struct HostEntry *he = value; + + GNUNET_free_non_null (he->hello); + GNUNET_free (he); + return GNUNET_YES; +} + +/** + * Clean up our state. Called during shutdown. + * + * @param cls unused + * @param tc scheduler task context, unused + */ +static void +shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + GNUNET_SERVER_notification_context_destroy (notify_list); + notify_list = NULL; + GNUNET_CONTAINER_multihashmap_iterate (hostmap, &free_host_entry, NULL); + GNUNET_CONTAINER_multihashmap_destroy (hostmap); + if (stats != NULL) + { + GNUNET_STATISTICS_destroy (stats, GNUNET_NO); + stats = NULL; + } +} + + +/** + * Process statistics requests. + * + * @param cls closure + * @param server the initialized server + * @param cfg configuration to use + */ +static void +run (void *cls, struct GNUNET_SERVER_Handle *server, + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + static const struct GNUNET_SERVER_MessageHandler handlers[] = { + {&handle_hello, NULL, GNUNET_MESSAGE_TYPE_HELLO, 0}, + {&handle_get, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET, + sizeof (struct ListPeerMessage)}, + {&handle_get_all, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL, + sizeof (struct GNUNET_MessageHeader)}, + {&handle_notify, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY, + sizeof (struct GNUNET_MessageHeader)}, + {NULL, NULL, 0, 0} + }; + + hostmap = GNUNET_CONTAINER_multihashmap_create (1024); + stats = GNUNET_STATISTICS_create ("peerinfo", cfg); + notify_list = GNUNET_SERVER_notification_context_create (server, 0); + GNUNET_assert (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_filename (cfg, "peerinfo", + "HOSTS", + &networkIdDirectory)); + GNUNET_DISK_directory_create (networkIdDirectory); + GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, + &cron_scan_directory_data_hosts, NULL); + GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, + &cron_clean_data_hosts, NULL); + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, + NULL); + GNUNET_SERVER_add_handlers (server, handlers); +} + + +/** + * The main function for the statistics service. + * + * @param argc number of arguments from the command line + * @param argv command line arguments + * @return 0 ok, 1 on error + */ +int +main (int argc, char *const *argv) +{ + int ret; + + ret = + (GNUNET_OK == + GNUNET_SERVICE_run (argc, argv, "peerinfo", GNUNET_SERVICE_OPTION_NONE, + &run, NULL)) ? 0 : 1; + GNUNET_free_non_null (networkIdDirectory); + return ret; +} + + +/* end of gnunet-service-peerinfo.c */ diff --git a/src/peerinfo/peerinfo.conf.in b/src/peerinfo/peerinfo.conf.in new file mode 100644 index 0000000..a40cc4f --- /dev/null +++ b/src/peerinfo/peerinfo.conf.in @@ -0,0 +1,24 @@ +[peerinfo] +AUTOSTART = YES +@UNIXONLY@ PORT = 2090 +HOSTNAME = localhost +HOME = $SERVICEHOME +CONFIG = $DEFAULTCONFIG +BINARY = gnunet-service-peerinfo +ACCEPT_FROM = 127.0.0.1; +ACCEPT_FROM6 = ::1; +UNIXPATH = /tmp/gnunet-service-peerinfo.sock +UNIX_MATCH_UID = NO +UNIX_MATCH_GID = YES +# DISABLE_SOCKET_FORWARDING = NO +# USERNAME = +# MAXBUF = +# TIMEOUT = +# DISABLEV6 = +# BINDTO = +# REJECT_FROM = +# REJECT_FROM6 = +# PREFIX = +HOSTS = $SERVICEHOME/data/hosts/ + + diff --git a/src/peerinfo/peerinfo.h b/src/peerinfo/peerinfo.h new file mode 100644 index 0000000..bf56774 --- /dev/null +++ b/src/peerinfo/peerinfo.h @@ -0,0 +1,88 @@ +/* + This file is part of GNUnet. + (C) 2009, 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file peerinfo/peerinfo.h + * @brief common internal definitions for peerinfo service + * @author Christian Grothoff + */ +#include "gnunet_crypto_lib.h" +#include "gnunet_time_lib.h" +#include "gnunet_peerinfo_service.h" + +#define DEBUG_PEERINFO GNUNET_EXTRA_LOGGING + +GNUNET_NETWORK_STRUCT_BEGIN + +/** + * Message requesting a listing of all known peers, + * possibly restricted to the specified peer identity. + */ +struct ListPeerMessage +{ + + /** + * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET + */ + struct GNUNET_MessageHeader header; + + /** + * Always zero. + */ + uint32_t reserved GNUNET_PACKED; + + /** + * Restrict to peers with this identity (optional + * field, check header.size!). + */ + struct GNUNET_PeerIdentity peer; + +}; + + +/** + * Message used to inform the client about + * a particular peer; this message is optionally followed + * by a HELLO message for the respective peer (if available). + * Check the header.size field to see if a HELLO is + * present. + */ +struct InfoMessage +{ + + /** + * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_INFO + */ + struct GNUNET_MessageHeader header; + + /** + * Always zero. + */ + uint32_t reserved GNUNET_PACKED; + + /** + * About which peer are we talking here? + */ + struct GNUNET_PeerIdentity peer; + +}; +GNUNET_NETWORK_STRUCT_END + +/* end of peerinfo.h */ diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c new file mode 100644 index 0000000..4c5d795 --- /dev/null +++ b/src/peerinfo/peerinfo_api.c @@ -0,0 +1,661 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2004, 2005, 2007, 2009, 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file peerinfo/peerinfo_api.c + * @brief API to access peerinfo service + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_client_lib.h" +#include "gnunet_container_lib.h" +#include "gnunet_peerinfo_service.h" +#include "gnunet_protocols.h" +#include "gnunet_time_lib.h" +#include "peerinfo.h" + +#define LOG(kind,...) GNUNET_log_from (kind, "nse-api",__VA_ARGS__) + +/** + * Function to call after transmission has succeeded. + * + * @param cls closure + * @param success GNUNET_OK if transmission worked, GNUNET_SYSERR on error + */ +typedef void (*TransmissionContinuation) (void *cls, int success); + + +/** + * Entry in the transmission queue to PEERINFO service. + */ +struct TransmissionQueueEntry +{ + /** + * This is a linked list. + */ + struct TransmissionQueueEntry *next; + + /** + * This is a linked list. + */ + struct TransmissionQueueEntry *prev; + + /** + * Function to call after request has been transmitted, or NULL (in which + * case we must consider sending the next entry immediately). + */ + TransmissionContinuation cont; + + /** + * Closure for 'cont'. + */ + void *cont_cls; + + /** + * Timeout for the operation. + */ + struct GNUNET_TIME_Absolute timeout; + + /** + * Number of bytes of the request message (follows after this struct). + */ + size_t size; + +}; + + +/** + * Handle to the peerinfo service. + */ +struct GNUNET_PEERINFO_Handle +{ + /** + * Our configuration. + */ + const struct GNUNET_CONFIGURATION_Handle *cfg; + + /** + * Connection to the service. + */ + struct GNUNET_CLIENT_Connection *client; + + /** + * Head of transmission queue. + */ + struct TransmissionQueueEntry *tq_head; + + /** + * Tail of transmission queue. + */ + struct TransmissionQueueEntry *tq_tail; + + /** + * Handle for the current transmission request, or NULL if none is pending. + */ + struct GNUNET_CLIENT_TransmitHandle *th; + + /** + * ID for a reconnect task. + */ + GNUNET_SCHEDULER_TaskIdentifier r_task; + + /** + * Set to GNUNET_YES if we are currently receiving replies from the + * service. + */ + int in_receive; + +}; + + +/** + * Connect to the peerinfo service. + * + * @param cfg configuration to use + * @return NULL on error (configuration related, actual connection + * establishment may happen asynchronously). + */ +struct GNUNET_PEERINFO_Handle * +GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + struct GNUNET_PEERINFO_Handle *ret; + + ret = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_Handle)); + ret->client = GNUNET_CLIENT_connect ("peerinfo", cfg); + ret->cfg = cfg; + return ret; +} + + +/** + * Disconnect from the peerinfo service. Note that all iterators must + * have completed or have been cancelled by the time this function is + * called (otherwise, calling this function is a serious error). + * Furthermore, if 'GNUNET_PEERINFO_add_peer' operations are still + * pending, they will be cancelled silently on disconnect. + * + * @param h handle to disconnect + */ +void +GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h) +{ + struct TransmissionQueueEntry *tqe; + + while (NULL != (tqe = h->tq_head)) + { + GNUNET_CONTAINER_DLL_remove (h->tq_head, h->tq_tail, tqe); + if (tqe->cont != NULL) + tqe->cont (tqe->cont_cls, GNUNET_SYSERR); + GNUNET_free (tqe); + } + if (h->th != NULL) + { + GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); + h->th = NULL; + } + if (NULL != h->client) + { + GNUNET_CLIENT_disconnect (h->client, GNUNET_NO); + h->client = NULL; + } + if (GNUNET_SCHEDULER_NO_TASK != h->r_task) + { + GNUNET_SCHEDULER_cancel (h->r_task); + h->r_task = GNUNET_SCHEDULER_NO_TASK; + } + GNUNET_free (h); +} + + +/** + * Check if we have a request pending in the transmission queue and are + * able to transmit it right now. If so, schedule transmission. + * + * @param h handle to the service + */ +static void +trigger_transmit (struct GNUNET_PEERINFO_Handle *h); + + +/** + * Close the existing connection to PEERINFO and reconnect. + * + * @param h handle to the service + */ +static void +reconnect (struct GNUNET_PEERINFO_Handle *h); + +/** + * Task scheduled to re-try connecting to the peerinfo service. + * + * @param cls the 'struct GNUNET_PEERINFO_Handle' + * @param tc scheduler context + */ +static void +reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_PEERINFO_Handle *h = cls; + + h->r_task = GNUNET_SCHEDULER_NO_TASK; + reconnect (h); +} + + +/** + * Close the existing connection to PEERINFO and reconnect. + * + * @param h handle to the service + */ +static void +reconnect (struct GNUNET_PEERINFO_Handle *h) +{ + if (h->r_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (h->r_task); + h->r_task = GNUNET_SCHEDULER_NO_TASK; + } + if (NULL != h->th) + { + GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); + h->th = NULL; + } + if (NULL != h->client) + { + GNUNET_CLIENT_disconnect (h->client, GNUNET_SYSERR); + h->client = NULL; + } + h->client = GNUNET_CLIENT_connect ("peerinfo", h->cfg); + if (NULL == h->client) + { + h->r_task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task, + h); + return; + } + trigger_transmit (h); +} + + +/** + * Transmit the request at the head of the transmission queue + * and trigger continuation (if any). + * + * @param cls the 'struct GNUNET_PEERINFO_Handle' (with the queue) + * @param size size of the buffer (0 on error) + * @param buf where to copy the message + * @return number of bytes copied to buf + */ +static size_t +do_transmit (void *cls, size_t size, void *buf) +{ + struct GNUNET_PEERINFO_Handle *h = cls; + struct TransmissionQueueEntry *tqe = h->tq_head; + size_t ret; + + h->th = NULL; + if (tqe == NULL) + return 0; + if (buf == NULL) + { +#if DEBUG_PEERINFO + LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, + _("Failed to transmit message to `%s' service.\n"), "PEERINFO"); +#endif + GNUNET_CONTAINER_DLL_remove (h->tq_head, h->tq_tail, tqe); + reconnect (h); + if (tqe->cont != NULL) + tqe->cont (tqe->cont_cls, GNUNET_SYSERR); + GNUNET_free (tqe); + return 0; + } + ret = tqe->size; + GNUNET_assert (size >= ret); + memcpy (buf, &tqe[1], ret); +#if DEBUG_PEERINFO + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Transmitting request of size %u to `%s' service.\n", ret, "PEERINFO"); +#endif + GNUNET_CONTAINER_DLL_remove (h->tq_head, h->tq_tail, tqe); + if (tqe->cont != NULL) + tqe->cont (tqe->cont_cls, GNUNET_OK); + else + trigger_transmit (h); + GNUNET_free (tqe); + return ret; +} + + +/** + * Check if we have a request pending in the transmission queue and are + * able to transmit it right now. If so, schedule transmission. + * + * @param h handle to the service + */ +static void +trigger_transmit (struct GNUNET_PEERINFO_Handle *h) +{ + struct TransmissionQueueEntry *tqe; + + if (NULL == (tqe = h->tq_head)) + return; + if (h->th != NULL) + return; + if (h->in_receive == GNUNET_YES) + return; + if (NULL == h->client) + { + reconnect (h); + return; + } + h->th = + GNUNET_CLIENT_notify_transmit_ready (h->client, tqe->size, + GNUNET_TIME_absolute_get_remaining + (tqe->timeout), GNUNET_YES, + &do_transmit, h); +} + + +/** + * Add a host to the persistent list. This method operates in + * semi-reliable mode: if the transmission is not completed by + * the time 'GNUNET_PEERINFO_disconnect' is called, it will be + * aborted. Furthermore, if a second HELLO is added for the + * same peer before the first one was transmitted, PEERINFO may + * merge the two HELLOs prior to transmission to the service. + * + * @param h handle to the peerinfo service + * @param hello the verified (!) HELLO message + */ +void +GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h, + const struct GNUNET_HELLO_Message *hello) +{ + uint16_t hs = GNUNET_HELLO_size (hello); + struct TransmissionQueueEntry *tqe; + +#if DEBUG_PEERINFO + struct GNUNET_PeerIdentity peer; + + GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (hello, &peer)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Adding peer `%s' to PEERINFO database (%u bytes of `%s')\n", + GNUNET_i2s (&peer), hs, "HELLO"); +#endif + tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) + hs); + tqe->size = hs; + tqe->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; + memcpy (&tqe[1], hello, hs); + GNUNET_CONTAINER_DLL_insert_after (h->tq_head, h->tq_tail, h->tq_tail, tqe); + trigger_transmit (h); +} + + +/** + * Context for an iteration request. + */ +struct GNUNET_PEERINFO_IteratorContext +{ + /** + * Handle to the PEERINFO service. + */ + struct GNUNET_PEERINFO_Handle *h; + + /** + * Function to call with the results. + */ + GNUNET_PEERINFO_Processor callback; + + /** + * Closure for 'callback'. + */ + void *callback_cls; + + /** + * Our entry in the transmission queue. + */ + struct TransmissionQueueEntry *tqe; + + /** + * Task responsible for timeout. + */ + GNUNET_SCHEDULER_TaskIdentifier timeout_task; + + /** + * Timeout for the operation. + */ + struct GNUNET_TIME_Absolute timeout; + + /** + * Are we now receiving? + */ + int in_receive; +}; + + +/** + * Type of a function to call when we receive a message + * from the service. + * + * @param cls closure + * @param msg message received, NULL on timeout or fatal error + */ +static void +peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) +{ + struct GNUNET_PEERINFO_IteratorContext *ic = cls; + const struct InfoMessage *im; + const struct GNUNET_HELLO_Message *hello; + uint16_t ms; + + ic->h->in_receive = GNUNET_NO; + if (msg == NULL) + { + reconnect (ic->h); + if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) + GNUNET_SCHEDULER_cancel (ic->timeout_task); + if (ic->callback != NULL) + ic->callback (ic->callback_cls, NULL, NULL, + _("Failed to receive response from `PEERINFO' service.")); + GNUNET_free (ic); + return; + } + if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END) + { +#if DEBUG_PEERINFO + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received end of list of peers from `%s' service\n", "PEERINFO"); +#endif + trigger_transmit (ic->h); + if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) + GNUNET_SCHEDULER_cancel (ic->timeout_task); + if (ic->callback != NULL) + ic->callback (ic->callback_cls, NULL, NULL, NULL); + GNUNET_free (ic); + return; + } + ms = ntohs (msg->size); + if ((ms < sizeof (struct InfoMessage)) || + (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_PEERINFO_INFO)) + { + GNUNET_break (0); + reconnect (ic->h); + if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) + GNUNET_SCHEDULER_cancel (ic->timeout_task); + if (ic->callback != NULL) + ic->callback (ic->callback_cls, NULL, NULL, + _("Received invalid message from `PEERINFO' service.\n")); + GNUNET_free (ic); + return; + } + im = (const struct InfoMessage *) msg; + GNUNET_break (0 == ntohl (im->reserved)); + hello = NULL; + if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader)) + { + hello = (const struct GNUNET_HELLO_Message *) &im[1]; + if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello)) + { + GNUNET_break (0); + reconnect (ic->h); + if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) + GNUNET_SCHEDULER_cancel (ic->timeout_task); + if (ic->callback != NULL) + ic->callback (ic->callback_cls, NULL, NULL, + _("Received invalid message from `PEERINFO' service.\n")); + GNUNET_free (ic); + return; + } + } +#if DEBUG_PEERINFO + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received %u bytes of `%s' information about peer `%s' from `%s' service\n", + (hello == NULL) ? 0 : (unsigned int) GNUNET_HELLO_size (hello), "HELLO", + GNUNET_i2s (&im->peer), "PEERINFO"); +#endif + ic->h->in_receive = GNUNET_YES; + if (ic->callback != NULL) + ic->callback (ic->callback_cls, &im->peer, hello, NULL); + GNUNET_CLIENT_receive (ic->h->client, &peerinfo_handler, ic, + GNUNET_TIME_absolute_get_remaining (ic->timeout)); +} + + +/** + * We've transmitted the iteration request. Now get ready to process + * the results (or handle transmission error). + * + * @param cls the 'struct GNUNET_PEERINFO_IteratorContext' + * @param transmit_success GNUNET_OK if transmission worked + */ +static void +iterator_start_receive (void *cls, int transmit_success) +{ + struct GNUNET_PEERINFO_IteratorContext *ic = cls; + + if (GNUNET_OK != transmit_success) + { + if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (ic->timeout_task); + ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; + } + reconnect (ic->h); + if (ic->callback != NULL) + ic->callback (ic->callback_cls, NULL, NULL, + _ + ("Failed to transmit iteration request to `PEERINFO' service\n")); + GNUNET_free (ic); + return; + } +#if DEBUG_PEERINFO + LOG (GNUNET_ERROR_TYPE_DEBUG, "Waiting for response from `%s' service.\n", + "PEERINFO"); +#endif + ic->h->in_receive = GNUNET_YES; + ic->in_receive = GNUNET_YES; + ic->tqe = NULL; + GNUNET_CLIENT_receive (ic->h->client, &peerinfo_handler, ic, + GNUNET_TIME_absolute_get_remaining (ic->timeout)); +} + + +/** + * Peerinfo iteration request has timed out. + * + * @param cls the 'struct GNUNET_PEERINFO_IteratorContext*' + * @param tc scheduler context + */ +static void +signal_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_PEERINFO_IteratorContext *ic = cls; + + ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; + if (!ic->in_receive) + GNUNET_CONTAINER_DLL_remove (ic->h->tq_head, ic->h->tq_tail, ic->tqe); + else + reconnect (ic->h); + ic->callback (ic->callback_cls, NULL, NULL, + _ + ("Timeout transmitting iteration request to `PEERINFO' service.\n")); + ic->callback = NULL; + GNUNET_free_non_null (ic->tqe); + GNUNET_free (ic); +} + + +/** + * Call a method for each known matching host and change its trust + * value. The callback method will be invoked once for each matching + * host and then finally once with a NULL pointer. After that final + * invocation, the iterator context must no longer be used. + * + * Instead of calling this function with 'peer == NULL' it is often + * better to use 'GNUNET_PEERINFO_notify'. + * + * @param h handle to the peerinfo service + * @param peer restrict iteration to this peer only (can be NULL) + * @param timeout how long to wait until timing out + * @param callback the method to call for each peer + * @param callback_cls closure for callback + * @return iterator context + */ +struct GNUNET_PEERINFO_IteratorContext * +GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_TIME_Relative timeout, + GNUNET_PEERINFO_Processor callback, void *callback_cls) +{ + struct GNUNET_MessageHeader *lapm; + struct ListPeerMessage *lpm; + struct GNUNET_PEERINFO_IteratorContext *ic; + struct TransmissionQueueEntry *tqe; + + if (peer == NULL) + { +#if DEBUG_PEERINFO + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Requesting list of peers from PEERINFO service\n"); +#endif + tqe = + GNUNET_malloc (sizeof (struct TransmissionQueueEntry) + + sizeof (struct GNUNET_MessageHeader)); + tqe->size = sizeof (struct GNUNET_MessageHeader); + lapm = (struct GNUNET_MessageHeader *) &tqe[1]; + lapm->size = htons (sizeof (struct GNUNET_MessageHeader)); + lapm->type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL); + } + else + { +#if DEBUG_PEERINFO + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Requesting information on peer `%4s' from PEERINFO service\n", + GNUNET_i2s (peer)); +#endif + tqe = + GNUNET_malloc (sizeof (struct TransmissionQueueEntry) + + sizeof (struct ListPeerMessage)); + tqe->size = sizeof (struct ListPeerMessage); + lpm = (struct ListPeerMessage *) &tqe[1]; + lpm->header.size = htons (sizeof (struct ListPeerMessage)); + lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET); + memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity)); + } + ic = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext)); + ic->h = h; + ic->tqe = tqe; + ic->callback = callback; + ic->callback_cls = callback_cls; + ic->timeout = GNUNET_TIME_relative_to_absolute (timeout); + ic->timeout_task = + GNUNET_SCHEDULER_add_delayed (timeout, &signal_timeout, ic); + tqe->timeout = ic->timeout; + tqe->cont = &iterator_start_receive; + tqe->cont_cls = ic; + tqe->timeout = ic->timeout; + GNUNET_CONTAINER_DLL_insert_after (h->tq_head, h->tq_tail, h->tq_tail, tqe); + trigger_transmit (h); + return ic; +} + + +/** + * Cancel an iteration over peer information. + * + * @param ic context of the iterator to cancel + */ +void +GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic) +{ + if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel (ic->timeout_task); + ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; + } + ic->callback = NULL; + if (GNUNET_YES == ic->in_receive) + return; /* need to finish processing */ + GNUNET_CONTAINER_DLL_remove (ic->h->tq_head, ic->h->tq_tail, ic->tqe); + GNUNET_free (ic->tqe); + GNUNET_free (ic); +} + + +/* end of peerinfo_api.c */ diff --git a/src/peerinfo/peerinfo_api_notify.c b/src/peerinfo/peerinfo_api_notify.c new file mode 100644 index 0000000..a0588db --- /dev/null +++ b/src/peerinfo/peerinfo_api_notify.c @@ -0,0 +1,292 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2004, 2005, 2007, 2009, 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file peerinfo/peerinfo_api_notify.c + * @brief notify API to access peerinfo service + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_client_lib.h" +#include "gnunet_peerinfo_service.h" +#include "gnunet_protocols.h" +#include "gnunet_time_lib.h" +#include "peerinfo.h" + +#define LOG(kind,...) GNUNET_log_from (kind, "nse-api",__VA_ARGS__) + +/** + * Context for the info handler. + */ +struct GNUNET_PEERINFO_NotifyContext +{ + + /** + * Our connection to the PEERINFO service. + */ + struct GNUNET_CLIENT_Connection *client; + + /** + * Function to call with information. + */ + GNUNET_PEERINFO_Processor callback; + + /** + * Closure for callback. + */ + void *callback_cls; + + /** + * Handle to our initial request for message transmission to + * the peerinfo service. + */ + struct GNUNET_CLIENT_TransmitHandle *init; + + /** + * Configuration. + */ + const struct GNUNET_CONFIGURATION_Handle *cfg; + + /** + * Tasked used for delayed re-connection attempt. + */ + GNUNET_SCHEDULER_TaskIdentifier task; + +}; + + +/** + * Send a request to the peerinfo service to start being + * notified about all changes to peer information. + * + * @param nc our context + */ +static void +request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc); + + +/** + * Read notifications from the client handle and pass them + * to the callback. + * + * @param nc our context + */ +static void +receive_notifications (struct GNUNET_PEERINFO_NotifyContext *nc); + + +/** + * Task to re-try connecting to peerinfo. + * + * @param cls the 'struct GNUNET_PEERINFO_NotifyContext' + * @param tc scheduler context + */ +static void +reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GNUNET_PEERINFO_NotifyContext *nc = cls; + + nc->task = GNUNET_SCHEDULER_NO_TASK; + nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg); + if (NULL == nc->client) + { + /* ugh */ + nc->task = + GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect, nc); + return; + } + request_notifications (nc); +} + + +/** + * Receive a peerinfo information message, process it and + * go for more. + * + * @param cls closure + * @param msg message received, NULL on timeout or fatal error + */ +static void +process_notification (void *cls, const struct GNUNET_MessageHeader *msg) +{ + struct GNUNET_PEERINFO_NotifyContext *nc = cls; + const struct InfoMessage *im; + const struct GNUNET_HELLO_Message *hello; + uint16_t ms; + + if (msg == NULL) + { + GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); + reconnect (nc, NULL); + return; + } + ms = ntohs (msg->size); + if ((ms < sizeof (struct InfoMessage)) || + (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_PEERINFO_INFO)) + { + GNUNET_break (0); + GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); + nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg); + request_notifications (nc); + return; + } + im = (const struct InfoMessage *) msg; + hello = NULL; + if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader)) + { + hello = (const struct GNUNET_HELLO_Message *) &im[1]; + if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello)) + { + GNUNET_break (0); + GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); + nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg); + request_notifications (nc); + return; + } + } +#if DEBUG_PEERINFO + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received information about peer `%s' from peerinfo database\n", + GNUNET_i2s (&im->peer)); +#endif + nc->callback (nc->callback_cls, &im->peer, hello, NULL); + receive_notifications (nc); +} + + +/** + * Read notifications from the client handle and pass them + * to the callback. + * + * @param nc our context + */ +static void +receive_notifications (struct GNUNET_PEERINFO_NotifyContext *nc) +{ + GNUNET_CLIENT_receive (nc->client, &process_notification, nc, + GNUNET_TIME_UNIT_FOREVER_REL); +} + + +/** + * Transmit our init-notify request, start receiving. + * + * @param cls closure (our 'struct GNUNET_PEERINFO_NotifyContext') + * @param size number of bytes available in buf + * @param buf where the callee should write the message + * @return number of bytes written to buf + */ +static size_t +transmit_notify_request (void *cls, size_t size, void *buf) +{ + struct GNUNET_PEERINFO_NotifyContext *nc = cls; + struct GNUNET_MessageHeader hdr; + + nc->init = NULL; + if (buf == NULL) + { + GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); + nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg); + request_notifications (nc); + return 0; + } + GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); + hdr.size = htons (sizeof (struct GNUNET_MessageHeader)); + hdr.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY); + memcpy (buf, &hdr, sizeof (struct GNUNET_MessageHeader)); + receive_notifications (nc); + return sizeof (struct GNUNET_MessageHeader); +} + + +/** + * Send a request to the peerinfo service to start being + * notified about all changes to peer information. + * + * @param nc our context + */ +static void +request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc) +{ + GNUNET_assert (NULL == nc->init); + nc->init = + GNUNET_CLIENT_notify_transmit_ready (nc->client, + sizeof (struct GNUNET_MessageHeader), + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_YES, &transmit_notify_request, + nc); +} + + +/** + * Call a method whenever our known information about peers + * changes. Initially calls the given function for all known + * peers and then only signals changes. + * + * @param cfg configuration to use + * @param callback the method to call for each peer + * @param callback_cls closure for callback + * @return NULL on error + */ +struct GNUNET_PEERINFO_NotifyContext * +GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_PEERINFO_Processor callback, void *callback_cls) +{ + struct GNUNET_PEERINFO_NotifyContext *nc; + struct GNUNET_CLIENT_Connection *client; + + client = GNUNET_CLIENT_connect ("peerinfo", cfg); + if (client == NULL) + { + LOG (GNUNET_ERROR_TYPE_WARNING, _("Could not connect to `%s' service.\n"), + "peerinfo"); + return NULL; + } + nc = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_NotifyContext)); + nc->cfg = cfg; + nc->client = client; + nc->callback = callback; + nc->callback_cls = callback_cls; + request_notifications (nc); + return nc; +} + + +/** + * Stop notifying about changes. + * + * @param nc context to stop notifying + */ +void +GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc) +{ + if (NULL != nc->init) + { + GNUNET_CLIENT_notify_transmit_ready_cancel (nc->init); + nc->init = NULL; + } + if (NULL != nc->client) + GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); + if (GNUNET_SCHEDULER_NO_TASK != nc->task) + GNUNET_SCHEDULER_cancel (nc->task); + GNUNET_free (nc); +} + +/* end of peerinfo_api_notify.c */ diff --git a/src/peerinfo/perf_peerinfo_api.c b/src/peerinfo/perf_peerinfo_api.c new file mode 100755 index 0000000..3396930 --- /dev/null +++ b/src/peerinfo/perf_peerinfo_api.c @@ -0,0 +1,217 @@ +/* + This file is part of GNUnet. + (C) 2004, 2009, 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file peerinfo/test_peerinfo_hammer.c + * @brief testcase for peerinfo_api.c, hopefully hammer the peerinfo service + * @author Nathan Evans + */ + +#include "platform.h" +#include "gnunet_hello_lib.h" +#include "gnunet_getopt_lib.h" +#include "gnunet_os_lib.h" +#include "gnunet_peerinfo_service.h" +#include "gnunet_program_lib.h" +#include "gnunet_time_lib.h" +#include "peerinfo.h" +#include <gauger.h> + +#define START_SERVICE 1 + +#define NUM_REQUESTS 5000 + +static const struct GNUNET_CONFIGURATION_Handle *cfg; + +static struct GNUNET_PEERINFO_IteratorContext *ic[NUM_REQUESTS]; + +static struct GNUNET_PEERINFO_Handle *h; + +static unsigned int numpeers; + +static struct GNUNET_PeerIdentity pid; + + +static int +check_it (void *cls, const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) +{ +#if DEBUG + if (addrlen > 0) + { + FPRINTF (stderr, "name: %s, addr: %s\n", tname, (const char *) addr); + } +#endif + return GNUNET_OK; +} + + +static size_t +address_generator (void *cls, size_t max, void *buf) +{ + size_t *agc = cls; + size_t ret; + char *caddress; + struct GNUNET_HELLO_Address address; + + if (*agc == 0) + return 0; + + GNUNET_asprintf (&caddress, "Address%d", *agc); + address.peer = pid; + address.address_length = strlen (caddress) + 1; + address.address = caddress; + address.transport_name = "peerinfotest"; + ret = + GNUNET_HELLO_add_address (&address, + GNUNET_TIME_relative_to_absolute + (GNUNET_TIME_UNIT_HOURS), buf, max); + GNUNET_free (caddress); + *agc = 0; + return ret; +} + + +static void +add_peer (size_t i) +{ + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; + struct GNUNET_HELLO_Message *h2; + + memset (&pkey, i, sizeof (pkey)); + GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey); + h2 = GNUNET_HELLO_create (&pkey, &address_generator, &i); + GNUNET_PEERINFO_add_peer (h, h2); + GNUNET_free (h2); +} + + +static void +process (void *cls, const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Message *hello, const char *err_msg) +{ + if (peer == NULL) + { +#if DEBUG + FPRINTF (stderr, "Process received NULL response\n"); +#endif + } + else + { +#if DEBUG + FPRINTF (stderr, "Processed a peer\n"); +#endif + numpeers++; + if (0 && (hello != NULL)) + GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, NULL); + + } +} + + +static void +run (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) +{ + size_t i; + + cfg = c; + h = GNUNET_PEERINFO_connect (cfg); + GNUNET_assert (h != NULL); + for (i = 0; i < NUM_REQUESTS; i++) + { + add_peer (i); + ic[i] = + GNUNET_PEERINFO_iterate (h, NULL, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 30), &process, cls); + } +} + +static int +check () +{ + int ok = 0; + + char *const argv[] = { "perf-peerinfo-api", + "-c", + "test_peerinfo_api_data.conf", +#if DEBUG_PEERINFO + "-L", "DEBUG", +#else + "-L", "ERROR", +#endif + NULL + }; +#if START_SERVICE + struct GNUNET_OS_Process *proc; + + struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_OPTION_END + }; + proc = + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-peerinfo", + "gnunet-service-peerinfo", +#if DEBUG_PEERINFO + "-L", "DEBUG", +#else + "-L", "ERROR", +#endif + "-c", "test_peerinfo_api_data.conf", NULL); +#endif + GNUNET_assert (NULL != proc); + GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, + "perf-peerinfo-api", "nohelp", options, &run, &ok); + FPRINTF (stderr, "Received %u/%u calls before timeout\n", numpeers, + NUM_REQUESTS * NUM_REQUESTS / 2); + GAUGER ("PEERINFO", "Peerinfo lookups", numpeers / 30, "peers/s"); +#if START_SERVICE + if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); + ok = 1; + } + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close (proc); + proc = NULL; + +#endif + return ok; +} + + +int +main (int argc, char *argv[]) +{ + int ret = 0; + + GNUNET_log_setup ("perf_peerinfo_api", +#if DEBUG_PEERINFO + "DEBUG", +#else + "ERROR", +#endif + NULL); + ret = check (); + GNUNET_DISK_directory_remove ("/tmp/test-gnunet-peerinfo"); + return ret; +} + +/* end of perf_peerinfo_api.c */ diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c new file mode 100644 index 0000000..71da46b --- /dev/null +++ b/src/peerinfo/test_peerinfo_api.c @@ -0,0 +1,220 @@ +/* + This file is part of GNUnet. + (C) 2004, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file peerinfo/test_peerinfo_api.c + * @brief testcase for peerinfo_api.c + * @author Christian Grothoff + * + * TODO: + * - test merging of HELLOs (add same peer twice...) + */ + +#include "platform.h" +#include "gnunet_hello_lib.h" +#include "gnunet_getopt_lib.h" +#include "gnunet_os_lib.h" +#include "gnunet_peerinfo_service.h" +#include "gnunet_program_lib.h" +#include "gnunet_time_lib.h" +#include "peerinfo.h" + +static const struct GNUNET_CONFIGURATION_Handle *cfg; + +static struct GNUNET_PEERINFO_IteratorContext *ic; + +static struct GNUNET_PEERINFO_Handle *h; + +static unsigned int retries; + +static int +check_it (void *cls, const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) +{ + unsigned int *agc = cls; + + if (address != NULL) + { + GNUNET_assert (0 == strcmp ("peerinfotest", address->transport_name)); + GNUNET_assert (0 == + strncmp ("Address", address->address, + address->address_length)); + (*agc) -= (1 << (address->address_length - 1)); + } + return GNUNET_OK; +} + + +static size_t +address_generator (void *cls, size_t max, void *buf) +{ + size_t *agc = cls; + size_t ret; + struct GNUNET_HELLO_Address address; + + if (0 == *agc) + return 0; + memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); + address.address = "Address"; + address.transport_name = "peerinfotest"; + address.address_length = *agc; + ret = + GNUNET_HELLO_add_address (&address, + GNUNET_TIME_relative_to_absolute + (GNUNET_TIME_UNIT_HOURS), buf, max); + (*agc)--; + return ret; +} + + +static void +add_peer () +{ + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; + struct GNUNET_PeerIdentity pid; + struct GNUNET_HELLO_Message *h2; + size_t agc; + + agc = 2; + memset (&pkey, 32, sizeof (pkey)); + GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey); + h2 = GNUNET_HELLO_create (&pkey, &address_generator, &agc); + GNUNET_PEERINFO_add_peer (h, h2); + GNUNET_free (h2); + +} + + +static void +process (void *cls, const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Message *hello, const char *err_msg) +{ + int *ok = cls; + unsigned int agc; + + if (err_msg != NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Error in communication with PEERINFO service\n")); + } + + if (peer == NULL) + { + ic = NULL; + if ((3 == *ok) && (retries < 50)) + { + /* try again */ + retries++; + add_peer (); + ic = GNUNET_PEERINFO_iterate (h, NULL, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 15), &process, + cls); + return; + } + GNUNET_assert (peer == NULL); + GNUNET_assert (2 == *ok); + GNUNET_PEERINFO_disconnect (h); + h = NULL; + *ok = 0; + return; + } + if (hello != NULL) + { + GNUNET_assert (3 == *ok); + agc = 3; + GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, &agc); + GNUNET_assert (agc == 0); + *ok = 2; + } +} + + +static void +run (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) +{ + cfg = c; + h = GNUNET_PEERINFO_connect (cfg); + GNUNET_assert (h != NULL); + add_peer (); + ic = GNUNET_PEERINFO_iterate (h, NULL, + GNUNET_TIME_relative_multiply + (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls); +} + + +static int +check () +{ + int ok = 3; + struct GNUNET_OS_Process *proc; + + char *const argv[] = { "test-peerinfo-api", + "-c", + "test_peerinfo_api_data.conf", +#if DEBUG_PEERINFO + "-L", "DEBUG", +#endif + NULL + }; + struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_OPTION_END + }; + proc = + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-peerinfo", + "gnunet-service-peerinfo", +#if DEBUG_PEERINFO + "-L", "DEBUG", +#endif + "-c", "test_peerinfo_api_data.conf", NULL); + GNUNET_assert (NULL != proc); + GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, + "test-peerinfo-api", "nohelp", options, &run, &ok); + if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) + { + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); + ok = 1; + } + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close (proc); + proc = NULL; + return ok; +} + + +int +main (int argc, char *argv[]) +{ + int ret = 0; + + GNUNET_log_setup ("test_peerinfo_api", +#if DEBUG_PEERINFO + "DEBUG", +#else + "WARNING", +#endif + NULL); + ret = check (); + GNUNET_DISK_directory_remove ("/tmp/test-gnunet-peerinfo"); + return ret; +} + +/* end of test_peerinfo_api.c */ diff --git a/src/peerinfo/test_peerinfo_api_data.conf b/src/peerinfo/test_peerinfo_api_data.conf new file mode 100644 index 0000000..6caa1e4 --- /dev/null +++ b/src/peerinfo/test_peerinfo_api_data.conf @@ -0,0 +1,16 @@ +[PATHS] +SERVICEHOME = /tmp/test-gnunet-peerinfo/ + +[peerinfo] +PORT = 22354 +DEBUG = NO + +[dns] +AUTOSTART = NO + + + +[nse] +AUTOSTART = NO + + |