diff options
Diffstat (limited to 'src/include')
59 files changed, 4601 insertions, 2419 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am index 34a879f..67cee97 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am @@ -3,22 +3,23 @@ SUBDIRS = . gnunetincludedir = $(includedir)/gnunet nodist_gnunetinclude_HEADERS = \ - gnunet_directories.h \ - block_fs.h + gnunet_directories.h if MINGW WINPROC = winproc.h endif -gnunetinclude_HEADERS = \ +EXTRA_DIST = \ gauger.h \ - gettext.h \ - platform.h \ - plibc.h \ - $(WINPROC) \ + block_fs.h \ block_dns.h \ block_gns.h \ - block_fs.h \ + block_mesh.h \ + block_regex.h + +gnunetinclude_HEADERS = \ + platform.h plibc.h $(WINPROC) gettext.h \ + gns_protocol.h \ gnunet_applications.h \ gnunet_arm_service.h \ gnunet_ats_service.h \ @@ -42,6 +43,7 @@ gnunetinclude_HEADERS = \ gnunet_dht_service.h \ gnunet_disk_lib.h \ gnunet_dnsparser_lib.h \ + gnunet_dnsstub_lib.h \ gnunet_dns_service.h \ gnunet_dv_service.h \ gnunet_fragmentation_lib.h \ @@ -79,7 +81,6 @@ gnunetinclude_HEADERS = \ gnunet_strings_lib.h \ gnunet_testbed_service.h \ gnunet_testing_lib.h \ - gnunet_testing_lib-new.h \ gnunet_time_lib.h \ gnunet_transport_service.h \ gnunet_transport_plugin.h \ diff --git a/src/include/Makefile.in b/src/include/Makefile.in index ac6b874..8f2880a 100644 --- a/src/include/Makefile.in +++ b/src/include/Makefile.in @@ -1,9 +1,9 @@ -# Makefile.in generated by automake 1.11.1 from Makefile.am. +# Makefile.in generated by automake 1.11.6 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. +# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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. @@ -16,6 +16,23 @@ @SET_MAKE@ VPATH = @srcdir@ +am__make_dryrun = \ + { \ + am__dry=no; \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ + | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ + *) \ + for am__flg in $$MAKEFLAGS; do \ + case $$am__flg in \ + *=*|--*) ;; \ + *n*) am__dry=yes; break;; \ + esac; \ + done;; \ + esac; \ + test $$am__dry = yes; \ + } pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ @@ -41,14 +58,15 @@ DIST_COMMON = $(am__gnunetinclude_HEADERS_DIST) $(srcdir)/Makefile.am \ 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/gettext.m4 $(top_srcdir)/m4/glib-2.0.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/pkg.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) \ @@ -57,11 +75,11 @@ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/gnunet_config.h CONFIG_CLEAN_FILES = gnunet_directories.h CONFIG_CLEAN_VPATH_FILES = -AM_V_GEN = $(am__v_GEN_$(V)) -am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; -AM_V_at = $(am__v_at_$(V)) -am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ SOURCES = DIST_SOURCES = @@ -72,21 +90,27 @@ RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ install-pdf-recursive install-ps-recursive install-recursive \ installcheck-recursive installdirs-recursive pdf-recursive \ ps-recursive uninstall-recursive -am__gnunetinclude_HEADERS_DIST = gauger.h gettext.h platform.h plibc.h \ - winproc.h block_dns.h block_gns.h block_fs.h \ - gnunet_applications.h gnunet_arm_service.h \ - gnunet_ats_service.h gnunet_bandwidth_lib.h gnunet_bio_lib.h \ - gnunet_block_lib.h gnunet_block_plugin.h gnunet_client_lib.h \ +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__gnunetinclude_HEADERS_DIST = platform.h plibc.h winproc.h \ + gettext.h gns_protocol.h gnunet_applications.h \ + gnunet_arm_service.h gnunet_ats_service.h \ + gnunet_bandwidth_lib.h gnunet_bio_lib.h gnunet_block_lib.h \ + gnunet_block_plugin.h gnunet_client_lib.h \ gnunet_chat_service.h gnunet_common.h gnunet_constants.h \ gnunet_configuration_lib.h gnunet_container_lib.h \ gnunet_connection_lib.h gnunet_core_service.h \ gnunet_crypto_lib.h gnunet_datacache_lib.h \ gnunet_datacache_plugin.h gnunet_datastore_service.h \ gnunet_datastore_plugin.h gnunet_dht_service.h \ - gnunet_disk_lib.h gnunet_dnsparser_lib.h gnunet_dns_service.h \ - gnunet_dv_service.h gnunet_fragmentation_lib.h \ - gnunet_fs_service.h gnunet_getopt_lib.h gnunet_gns_service.h \ - gnunet_hello_lib.h gnunet_helper_lib.h gnunet_load_lib.h \ + gnunet_disk_lib.h gnunet_dnsparser_lib.h gnunet_dnsstub_lib.h \ + gnunet_dns_service.h gnunet_dv_service.h \ + gnunet_fragmentation_lib.h gnunet_fs_service.h \ + gnunet_getopt_lib.h gnunet_gns_service.h gnunet_hello_lib.h \ + gnunet_helper_lib.h gnunet_load_lib.h \ gnunet_lockmanager_service.h gnunet_mesh_service.h \ gnunet_mysql_lib.h gnunet_namestore_plugin.h \ gnunet_namestore_service.h gnunet_nat_lib.h \ @@ -99,10 +123,9 @@ am__gnunetinclude_HEADERS_DIST = gauger.h gettext.h platform.h plibc.h \ gnunet_service_lib.h gnunet_signal_lib.h gnunet_signatures.h \ gnunet_statistics_service.h gnunet_stream_lib.h \ gnunet_strings_lib.h gnunet_testbed_service.h \ - gnunet_testing_lib.h gnunet_testing_lib-new.h \ - gnunet_time_lib.h gnunet_transport_service.h \ - gnunet_transport_plugin.h gnunet_tun_lib.h gnunet_util_lib.h \ - gnunet_vpn_service.h + gnunet_testing_lib.h gnunet_time_lib.h \ + gnunet_transport_service.h gnunet_transport_plugin.h \ + gnunet_tun_lib.h gnunet_util_lib.h gnunet_vpn_service.h am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ @@ -124,6 +147,12 @@ am__nobase_list = $(am__nobase_strip_setup); \ am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } am__installdirs = "$(DESTDIR)$(gnunetincludedir)" \ "$(DESTDIR)$(gnunetincludedir)" HEADERS = $(gnunetinclude_HEADERS) $(nodist_gnunetinclude_HEADERS) @@ -196,6 +225,10 @@ EXEEXT = @EXEEXT@ EXT_LIBS = @EXT_LIBS@ EXT_LIB_PATH = @EXT_LIB_PATH@ FGREP = @FGREP@ +GLIB_CFLAGS = @GLIB_CFLAGS@ +GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ +GLIB_LIBS = @GLIB_LIBS@ +GLIB_MKENUMS = @GLIB_MKENUMS@ GMSGFMT = @GMSGFMT@ GMSGFMT_015 = @GMSGFMT_015@ GNUNETDNS_GROUP = @GNUNETDNS_GROUP@ @@ -206,6 +239,7 @@ GN_LIBINTL = @GN_LIBINTL@ GN_LIB_LDFLAGS = @GN_LIB_LDFLAGS@ GN_PLUGIN_LDFLAGS = @GN_PLUGIN_LDFLAGS@ GN_USER_HOME_DIR = @GN_USER_HOME_DIR@ +GOBJECT_QUERY = @GOBJECT_QUERY@ GREP = @GREP@ HAVE_LIBUNISTRING = @HAVE_LIBUNISTRING@ INCLTDL = @INCLTDL@ @@ -228,6 +262,8 @@ LIBCURL_CPPFLAGS = @LIBCURL_CPPFLAGS@ LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ +LIBGTOP_CFLAGS = @LIBGTOP_CFLAGS@ +LIBGTOP_LIBS = @LIBGTOP_LIBS@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBLTDL = @LIBLTDL@ @@ -249,6 +285,7 @@ LT_CONFIG_H = @LT_CONFIG_H@ LT_DLLOADERS = @LT_DLLOADERS@ LT_DLPREOPEN = @LT_DLPREOPEN@ MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ MONKEYPREFIX = @MONKEYPREFIX@ MSGFMT = @MSGFMT@ @@ -258,6 +295,7 @@ MYSQL_CPPFLAGS = @MYSQL_CPPFLAGS@ MYSQL_LDFLAGS = @MYSQL_LDFLAGS@ NM = @NM@ NMEDIT = @NMEDIT@ +NSS_DIR = @NSS_DIR@ OBJC = @OBJC@ OBJCDEPMODE = @OBJCDEPMODE@ OBJCFLAGS = @OBJCFLAGS@ @@ -273,6 +311,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ POSTGRES_CPPFLAGS = @POSTGRES_CPPFLAGS@ POSTGRES_LDFLAGS = @POSTGRES_LDFLAGS@ POSUB = @POSUB@ @@ -304,6 +343,7 @@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_CXX = @ac_ct_CXX@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ @@ -326,6 +366,7 @@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ +gitcommand = @gitcommand@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ @@ -339,7 +380,6 @@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ -lt_ECHO = @lt_ECHO@ ltdl_LIBOBJS = @ltdl_LIBOBJS@ ltdl_LTLIBOBJS = @ltdl_LTLIBOBJS@ mandir = @mandir@ @@ -357,6 +397,7 @@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ subdirs = @subdirs@ +svnversioncommand = @svnversioncommand@ sys_symbol_underscore = @sys_symbol_underscore@ sysconfdir = @sysconfdir@ target = @target@ @@ -370,19 +411,20 @@ top_srcdir = @top_srcdir@ SUBDIRS = . gnunetincludedir = $(includedir)/gnunet nodist_gnunetinclude_HEADERS = \ - gnunet_directories.h \ - block_fs.h + gnunet_directories.h @MINGW_TRUE@WINPROC = winproc.h -gnunetinclude_HEADERS = \ +EXTRA_DIST = \ gauger.h \ - gettext.h \ - platform.h \ - plibc.h \ - $(WINPROC) \ + block_fs.h \ block_dns.h \ block_gns.h \ - block_fs.h \ + block_mesh.h \ + block_regex.h + +gnunetinclude_HEADERS = \ + platform.h plibc.h $(WINPROC) gettext.h \ + gns_protocol.h \ gnunet_applications.h \ gnunet_arm_service.h \ gnunet_ats_service.h \ @@ -406,6 +448,7 @@ gnunetinclude_HEADERS = \ gnunet_dht_service.h \ gnunet_disk_lib.h \ gnunet_dnsparser_lib.h \ + gnunet_dnsstub_lib.h \ gnunet_dns_service.h \ gnunet_dv_service.h \ gnunet_fragmentation_lib.h \ @@ -443,7 +486,6 @@ gnunetinclude_HEADERS = \ gnunet_strings_lib.h \ gnunet_testbed_service.h \ gnunet_testing_lib.h \ - gnunet_testing_lib-new.h \ gnunet_time_lib.h \ gnunet_transport_service.h \ gnunet_transport_plugin.h \ @@ -494,8 +536,11 @@ clean-libtool: -rm -rf .libs _libs install-gnunetincludeHEADERS: $(gnunetinclude_HEADERS) @$(NORMAL_INSTALL) - test -z "$(gnunetincludedir)" || $(MKDIR_P) "$(DESTDIR)$(gnunetincludedir)" @list='$(gnunetinclude_HEADERS)'; test -n "$(gnunetincludedir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(gnunetincludedir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(gnunetincludedir)" || exit 1; \ + fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ @@ -509,13 +554,14 @@ uninstall-gnunetincludeHEADERS: @$(NORMAL_UNINSTALL) @list='$(gnunetinclude_HEADERS)'; test -n "$(gnunetincludedir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ - test -n "$$files" || exit 0; \ - echo " ( cd '$(DESTDIR)$(gnunetincludedir)' && rm -f" $$files ")"; \ - cd "$(DESTDIR)$(gnunetincludedir)" && rm -f $$files + dir='$(DESTDIR)$(gnunetincludedir)'; $(am__uninstall_files_from_dir) install-nodist_gnunetincludeHEADERS: $(nodist_gnunetinclude_HEADERS) @$(NORMAL_INSTALL) - test -z "$(gnunetincludedir)" || $(MKDIR_P) "$(DESTDIR)$(gnunetincludedir)" @list='$(nodist_gnunetinclude_HEADERS)'; test -n "$(gnunetincludedir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(gnunetincludedir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(gnunetincludedir)" || exit 1; \ + fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ @@ -529,9 +575,7 @@ uninstall-nodist_gnunetincludeHEADERS: @$(NORMAL_UNINSTALL) @list='$(nodist_gnunetinclude_HEADERS)'; test -n "$(gnunetincludedir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ - test -n "$$files" || exit 0; \ - echo " ( cd '$(DESTDIR)$(gnunetincludedir)' && rm -f" $$files ")"; \ - cd "$(DESTDIR)$(gnunetincludedir)" && rm -f $$files + dir='$(DESTDIR)$(gnunetincludedir)'; $(am__uninstall_files_from_dir) # This directory's subdirectories are mostly independent; you can cd # into them and run `make' without going through this Makefile. @@ -700,13 +744,10 @@ distdir: $(DISTFILES) done @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ if test "$$subdir" = .; then :; else \ - test -d "$(distdir)/$$subdir" \ - || $(MKDIR_P) "$(distdir)/$$subdir" \ - || exit 1; \ - fi; \ - done - @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ - if test "$$subdir" = .; then :; else \ + $(am__make_dryrun) \ + || test -d "$(distdir)/$$subdir" \ + || $(MKDIR_P) "$(distdir)/$$subdir" \ + || exit 1; \ dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ $(am__relativize); \ new_distdir=$$reldir; \ @@ -744,10 +785,15 @@ install-am: all-am installcheck: installcheck-recursive 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 + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi mostlyclean-generic: clean-generic: diff --git a/src/include/block_dns.h b/src/include/block_dns.h index e047779..0ca5a47 100644 --- a/src/include/block_dns.h +++ b/src/include/block_dns.h @@ -64,7 +64,7 @@ struct GNUNET_DNS_Record * The descriptor for the service * (a peer may provide more than one service) */ - GNUNET_HashCode service_descriptor; + struct GNUNET_HashCode service_descriptor; /** * When does this record expire? diff --git a/src/include/block_fs.h b/src/include/block_fs.h index aae741e..0b77adc 100644 --- a/src/include/block_fs.h +++ b/src/include/block_fs.h @@ -78,7 +78,7 @@ struct SBlock * used as the key for decryption; the xor of this identifier * and the hash of the "keyspace" is the datastore-query hash). */ - GNUNET_HashCode identifier; + struct GNUNET_HashCode identifier; /** * Public key of the namespace. @@ -153,7 +153,7 @@ struct OnDemandBlock * file that was indexed (used to uniquely * identify the plaintext file). */ - GNUNET_HashCode file_id; + struct GNUNET_HashCode file_id; /** * At which offset should we be able to find diff --git a/src/include/block_gns.h b/src/include/block_gns.h index ffdb294..7b4ceed 100644 --- a/src/include/block_gns.h +++ b/src/include/block_gns.h @@ -31,34 +31,6 @@ GNUNET_NETWORK_STRUCT_BEGIN /** - * @brief a simgle record inside a record block - */ -struct GNSRecordBlock -{ - /** - * the record type - */ - uint32_t type GNUNET_PACKED; - - /** - * expiration time of the record - */ - struct GNUNET_TIME_AbsoluteNBO expiration; - - /** - * length of the data - */ - uint32_t data_length GNUNET_PACKED; - - /* record flags */ - uint32_t flags GNUNET_PACKED; - - //Class of the record? - - /* followed by the record data */ -}; - -/** * @brief a record block for a given name of a single authority */ struct GNSNameRecordBlock @@ -79,7 +51,7 @@ struct GNSNameRecordBlock /* 0-terminated name here */ - /* variable-size GNSRecordBlocks follows here */ + /* variable-size serialized namestore record data */ }; diff --git a/src/include/block_mesh.h b/src/include/block_mesh.h new file mode 100644 index 0000000..9dfb859 --- /dev/null +++ b/src/include/block_mesh.h @@ -0,0 +1,64 @@ +/* + This file is part of GNUnet. + (C) 2012,2013 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 include/block_mesh.h + * @brief Mesh block formats. + * @author Bartlomiej Polot + */ +#ifndef BLOCK_MESH_H +#define BLOCK_MESH_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_util_lib.h" +#include "gnunet_mesh_service.h" +#include <stdint.h> + +/** + * @brief peer block (announce peer + type) + */ +struct PBlock +{ + /** + * Identity of the peer + */ + struct GNUNET_PeerIdentity id; + + /** + * Type of service offered + */ + GNUNET_MESH_ApplicationType type; +}; + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif
\ No newline at end of file diff --git a/src/include/block_regex.h b/src/include/block_regex.h new file mode 100644 index 0000000..282c626 --- /dev/null +++ b/src/include/block_regex.h @@ -0,0 +1,120 @@ +/* + This file is part of GNUnet. + (C) 2012,2013 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 include/block_regex.h + * @brief regex block formats + * @author Bartlomiej Polot + */ +#ifndef BLOCK_REGEX_H +#define BLOCK_REGEX_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 + /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_util_lib.h" +#include <stdint.h> + + +/** + * @brief A RegexBlock contains one or more of this struct in the payload. + */ +struct RegexEdge +{ + /** + * Destination of this edge. + */ + struct GNUNET_HashCode key; + + /** + * Length of the token towards the new state. + */ + unsigned int n_token; + + /* char token[n_token] */ +}; + +/** + * @brief Block to announce a regex state. + */ +struct RegexBlock +{ + /** + * The key of the state. + */ + struct GNUNET_HashCode key; + + /** + * Length of the proof regex string. + */ + unsigned int n_proof; + + /** + * Numer of edges parting from this state. + */ + unsigned int n_edges; + + /** + * Is this state an accepting state? + */ + int accepting; + + /* char proof[n_proof] */ + /* struct RegexEdge edges[n_edges] */ +}; + +/** + * @brief Block to announce a peer accepting a state. + */ +struct RegexAccept +{ + /** + * The key of the state. + */ + struct GNUNET_HashCode key; + + /** + * Length of the proof regex string. + * FIXME necessary??? + * already present in the leading MeshRegexBlock + */ + // unsigned int n_proof; + + /** + * The identity of the peer accepting the state + */ + struct GNUNET_PeerIdentity id; + +}; + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif
\ No newline at end of file diff --git a/src/include/gauger.h b/src/include/gauger.h index 9761cbe..10ada90 100644 --- a/src/include/gauger.h +++ b/src/include/gauger.h @@ -29,14 +29,14 @@ sprintf(__gauger_s,"%Lf", (long double) (value));\ __gauger_v[0] = "gauger";\ __gauger_v[1] = "-n";\ - __gauger_v[2] = counter;\ + __gauger_v[2] = (char*) (counter); \ __gauger_v[3] = "-d";\ __gauger_v[4] = __gauger_s;\ __gauger_v[5] = "-u";\ - __gauger_v[6] = unit;\ + __gauger_v[6] = (char*) (unit); \ __gauger_v[7] = "-c";\ - __gauger_v[8] = category;\ - __gauger_v[9] = (char *)NULL;\ + __gauger_v[8] = (char*) (category); \ + __gauger_v[9] = (char*) NULL;\ execvp("gauger",__gauger_v);\ _exit(1);\ }else{\ @@ -59,30 +59,51 @@ sprintf(__gauger_s,"%Lf", (long double) (value));\ __gauger_v[0] = "gauger";\ __gauger_v[1] = "-n";\ - __gauger_v[2] = counter;\ + __gauger_v[2] = (char*) (counter); \ __gauger_v[3] = "-d";\ __gauger_v[4] = __gauger_s;\ __gauger_v[5] = "-u";\ - __gauger_v[6] = unit;\ + __gauger_v[6] = (char*) (unit); \ __gauger_v[7] = "-i";\ __gauger_v[8] = id;\ __gauger_v[9] = "-c";\ - __gauger_v[10] = category;\ - __gauger_v[11] = (char *)NULL;\ + __gauger_v[10] = (char *) (category); \ + __gauger_v[11] = (char *) NULL;\ execvp("gauger",__gauger_v);\ _exit(1);\ }else{\ _exit(0);\ }\ }else{\ - waitpid(__gauger_p,NULL,0);\ + waitpid(__gauger_p, NULL, 0);\ }\ } -#else +#else /* WINDOWS */ + +#include <stdlib.h> +#include <stdio.h> +#include <windef.h> + +#define GAUGER(category, counter, value, unit)\ +{\ + char __gauger_commandline[MAX_PATH];\ + \ + snprintf (__gauger_commandline, MAX_PATH, "gauger.py -n \"%s\" -d \"%Lf\" -u \"%s\" -c \"%s\"",\ + (counter), (long double) (value), (unit), (category)); \ + __gauger_commandline[MAX_PATH - 1] = '\0';\ + system (__gauger_commandline);\ +} -#define GAUGER_ID(category, counter, value, unit, id) {} -#define GAUGER(category, counter, value, unit) {} +#define GAUGER_ID(category, counter, value, unit, id)\ +{\ + char __gauger_commandline[MAX_PATH];\ + \ + snprintf (__gauger_commandline, MAX_PATH, "gauger.py -n \"%s\" -d \"%Lf\" -u \"%s\" -i \"%s\" -c \"%s\"",\ + (counter), (long double) (value), (unit), (id), (category)); \ + __gauger_commandline[MAX_PATH - 1] = '\0';\ + system (__gauger_commandline);\ +} #endif // WINDOWS diff --git a/src/include/gns_protocol.h b/src/include/gns_protocol.h new file mode 100644 index 0000000..0d9758b --- /dev/null +++ b/src/include/gns_protocol.h @@ -0,0 +1,161 @@ +/* + This file is part of GNUnet + (C) 2012 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 2, 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 include/gns_protocol.h + * @brief Resource Record definitions + * @author Martin Schanzenbach + */ +#ifndef GNS_RECORDS_H +#define GNS_RECORDS_H + +GNUNET_NETWORK_STRUCT_BEGIN + +/** + * Payload of DNS SOA record (header). + */ +struct soa_data +{ + /** + * The version number of the original copy of the zone. (NBO) + */ + uint32_t serial GNUNET_PACKED; + + /** + * Time interval before the zone should be refreshed. (NBO) + */ + uint32_t refresh GNUNET_PACKED; + + /** + * Time interval that should elapse before a failed refresh should + * be retried. (NBO) + */ + uint32_t retry GNUNET_PACKED; + + /** + * Time value that specifies the upper limit on the time interval + * that can elapse before the zone is no longer authoritative. (NBO) + */ + uint32_t expire GNUNET_PACKED; + + /** + * The bit minimum TTL field that should be exported with any RR + * from this zone. (NBO) + */ + uint32_t minimum GNUNET_PACKED; +}; + + +/** + * Payload of DNS SRV record (header). + */ +struct srv_data +{ + + /** + * Preference for this entry (lower value is higher preference). Clients + * will contact hosts from the lowest-priority group first and fall back + * to higher priorities if the low-priority entries are unavailable. (NBO) + */ + uint16_t prio GNUNET_PACKED; + + /** + * Relative weight for records with the same priority. Clients will use + * the hosts of the same (lowest) priority with a probability proportional + * to the weight given. (NBO) + */ + uint16_t weight GNUNET_PACKED; + + /** + * TCP or UDP port of the service. (NBO) + */ + uint16_t port GNUNET_PACKED; + + /* followed by 'target' name */ +}; + + +/** + * Payload of DNSSEC TLSA record. + * http://datatracker.ietf.org/doc/draft-ietf-dane-protocol/ + */ +struct tlsa_data +{ + + /** + * Certificate usage + * 0: CA cert + * 1: Entity cert + * 2: Trust anchor + * 3: domain-issued cert + */ + uint8_t usage; + + /** + * Selector + * What part will be matched against the cert + * presented by server + * 0: Full cert (in binary) + * 1: Full cert (in DER) + */ + uint8_t selector; + + /** + * Matching type (of selected content) + * 0: exact match + * 1: SHA-256 hash + * 2: SHA-512 hash + */ + uint8_t matching_type; + + /** + * followed by certificate association data + * The "certificate association data" to be matched. + * These bytes are either raw data (that is, the full certificate or + * its SubjectPublicKeyInfo, depending on the selector) for matching + * type 0, or the hash of the raw data for matching types 1 and 2. + * The data refers to the certificate in the association, not to the + * TLS ASN.1 Certificate object. + * + * The data is represented as a string of hex chars + */ +}; + +/** + * Payload of GNS VPN record + */ +struct vpn_data +{ + /** + * The peer to contact + */ + struct GNUNET_HashCode peer; + + /** + * The protocol to use + */ + uint16_t proto; + + /* followed by the servicename */ +}; + +GNUNET_NETWORK_STRUCT_END + +#endif diff --git a/src/include/gnunet_applications.h b/src/include/gnunet_applications.h index 5feaeec..5710a88 100644 --- a/src/include/gnunet_applications.h +++ b/src/include/gnunet_applications.h @@ -50,6 +50,10 @@ extern "C" */ #define GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER 2 +/** + * Transfer of blocks for non-anonymmous file-sharing. + */ +#define GNUNET_APPLICATION_TYPE_FS_BLOCK_TRANSFER 3 /** * Internet IPv4 gateway (any TCP/UDP/ICMP). @@ -61,6 +65,17 @@ extern "C" */ #define GNUNET_APPLICATION_TYPE_IPV6_GATEWAY 17 +/** + * Internet exit regex prefix. Consisting of application ID, followed by version + * and padding. + */ +#define GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX "GNUNET-VPN-VER-0001-" + +/** + * Consensus. + */ +#define GNUNET_APPLICATION_TYPE_CONSENSUS 18 + #if 0 /* keep Emacsens' auto-indent happy */ { diff --git a/src/include/gnunet_arm_service.h b/src/include/gnunet_arm_service.h index 116bfc5..0aa916b 100644 --- a/src/include/gnunet_arm_service.h +++ b/src/include/gnunet_arm_service.h @@ -37,6 +37,7 @@ extern "C" #include "gnunet_configuration_lib.h" #include "gnunet_scheduler_lib.h" +#include "gnunet_os_lib.h" #include "gnunet_time_lib.h" /** @@ -169,12 +170,14 @@ GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h); * * @param h handle to ARM * @param service_name name of the service + * @param std_inheritance flags controlling std descriptors inheritance * @param timeout how long to wait before failing for good * @param cb callback to invoke when service is ready * @param cb_cls closure for callback */ void GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, const char *service_name, + enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_TIME_Relative timeout, GNUNET_ARM_Callback cb, void *cb_cls); diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index aa7a089..6578633 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h @@ -30,6 +30,20 @@ #include "gnunet_util_lib.h" #include "gnunet_hello_lib.h" +/** + * Number of network types supported by ATS + */ +#define GNUNET_ATS_NetworkTypeCount 5 + +/** + * ATS network types as array initializer + */ +#define GNUNET_ATS_NetworkType {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN} + +/** + * ATS network types as string array initializer + */ +#define GNUNET_ATS_NetworkTypeString {"UNSPECIFIED", "LOOPBACK", "LAN", "WAN", "WLAN"} enum GNUNET_ATS_Network_Type { @@ -41,6 +55,26 @@ enum GNUNET_ATS_Network_Type }; /** + * Default bandwidth assigned to a network : 64 KB/s + */ +#define GNUNET_ATS_DefaultBandwidth 65536 + +/** + * Maximum bandwidth assigned to a network : 4095 MB/s + */ +#define GNUNET_ATS_MaxBandwidth UINT32_MAX + +/** + * Number of property types supported by ATS + */ +#define GNUNET_ATS_PropertyCount 9 + +/** + * ATS properties types as string array initializer + */ +#define GNUNET_ATS_PropertyStrings {"Terminator", "Utilization up", "Utilization down", "Network type", "Delay", "Distance", "Cost WAN", "Cost LAN", "Cost WLAN"} + +/** * Enum defining all known property types for ATS Enum values are used * in the GNUNET_ATS_Information struct as * (key,value)-pairs. @@ -413,14 +447,10 @@ enum GNUNET_ATS_Property #define GNUNET_ATS_QualityProperties {GNUNET_ATS_QUALITY_NET_DELAY, GNUNET_ATS_QUALITY_NET_DISTANCE} /** - * Number of ATS quality properties + * ATS quality properties as string array initializer */ -#define GNUNET_ATS_NetworkTypeCount 5 +#define GNUNET_ATS_QualityPropertiesString {"Delay", "Distance"} -/** - * ATS quality properties as array initializer - */ -#define GNUNET_ATS_NetworkType {GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN} GNUNET_NETWORK_STRUCT_BEGIN @@ -464,6 +494,13 @@ GNUNET_NETWORK_STRUCT_END */ struct GNUNET_ATS_SchedulingHandle; +/** + * Handle for address suggestion requests + * + */ +struct GNUNET_ATS_SuggestHandle; + + /** * Opaque session handle, defined by plugins. Contents not known to ATS. @@ -471,6 +508,7 @@ struct GNUNET_ATS_SchedulingHandle; struct Session; + /** * Signature of a function called by ATS with the current bandwidth * and address preferences as determined by ATS. @@ -539,8 +577,9 @@ GNUNET_ATS_reset_backoff (struct GNUNET_ATS_SchedulingHandle *sh, * * @param sh handle * @param peer identity of the peer we need an address for + * @return suggestion handle */ -void +struct GNUNET_ATS_SuggestHandle * GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh, const struct GNUNET_PeerIdentity *peer); @@ -557,6 +596,15 @@ GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh, /** + * Convert a GNUNET_ATS_NetworkType to a string + * + * @param net the network type + * @return a string or NULL if invalid + */ +const char * +GNUNET_ATS_print_network_type (uint32_t net); + +/** * Returns where the address is located: LAN or WAN or ... * @param sh the GNUNET_ATS_SchedulingHandle handle * @param addr address @@ -568,6 +616,23 @@ GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle *sh, const struct sockaddr * addr, socklen_t addrlen); +/** + * We have a new address ATS should know. Addresses have to be added with this + * function before they can be: updated, set in use and destroyed + * + * @param sh handle + * @param address the address + * @param session session handle (if available) + * @param ats performance data for the address + * @param ats_count number of performance records in 'ats' + */ +int +GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, + const struct GNUNET_HELLO_Address *address, + struct Session *session, + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count); + /** * We have updated performance statistics for a given address. Note @@ -651,6 +716,11 @@ typedef void (*GNUNET_ATS_PeerInformationCallback) (void *cls, GNUNET_ATS_Information * ats, uint32_t ats_count); +/** + * Handle for an address listing operation + */ +struct GNUNET_ATS_AddressListHandle; + /** * Get handle to access performance API of the ATS subsystem. @@ -667,6 +737,35 @@ GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, /** + * Get information about addresses known to the ATS subsystem. + * + * @param handle the performance handle to use + * @param peer peer idm can be NULL for all peers + * @param all GNUNET_YES to get information about all addresses or GNUNET_NO to + * get only address currently used + * @param infocb callback to call with the addresses, + * will callback with address == NULL when done + * @param infocb_cls closure for infocb + * @return ats performance context + */ +struct GNUNET_ATS_AddressListHandle * +GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *handle, + const struct GNUNET_PeerIdentity *peer, + int all, + GNUNET_ATS_PeerInformationCallback infocb, + void *infocb_cls); + + +/** + * Cancel a pending address listing operation + * + * @param handle the GNUNET_ATS_AddressListHandle handle to cancel + */ +void +GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle); + + +/** * Client is done using the ATS performance subsystem, release resources. * * @param ph handle @@ -730,6 +829,21 @@ void GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc); +/** + * Number of preference types supported by ATS + */ +#define GNUNET_ATS_PreferenceCount 3 + +/** + * ATS preference types as array initializer + */ +#define GNUNET_ATS_PreferenceType {GNUNET_ATS_PREFERENCE_END, GNUNET_ATS_PREFERENCE_BANDWIDTH, GNUNET_ATS_PREFERENCE_LATENCY} + +/** + * ATS preference types as string array initializer + */ +#define GNUNET_ATS_PreferenceTypeString {"END", "BANDWIDTH", "LATENCY"} + /** * Enum defining all known preference categories. @@ -760,6 +874,14 @@ enum GNUNET_ATS_PreferenceKind GNUNET_ATS_PREFERENCE_LATENCY }; +/** + * Convert a GNUNET_ATS_PreferenceType to a string + * + * @param type the preference type + * @return a string or NULL if invalid + */ +const char * +GNUNET_ATS_print_preference_type (uint32_t type); /** * Change preferences for the given peer. Preference changes are forgotten if peers diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h index adc1775..002d5c1 100644 --- a/src/include/gnunet_block_lib.h +++ b/src/include/gnunet_block_lib.h @@ -98,7 +98,27 @@ enum GNUNET_BLOCK_Type /** * Block for storing record data */ - GNUNET_BLOCK_TYPE_GNS_NAMERECORD = 11 + GNUNET_BLOCK_TYPE_GNS_NAMERECORD = 11, + + /** + * Block for storing mesh peers + */ + GNUNET_BLOCK_TYPE_MESH_PEER = 20, + + /** + * Block for finding peers by type + */ + GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE = 21, + + /** + * Block to store a mesh regex state + */ + GNUNET_BLOCK_TYPE_REGEX = 22, + + /** + * Block to store a mesh regex accepting state + */ + GNUNET_BLOCK_TYPE_REGEX_ACCEPT = 23 }; @@ -128,21 +148,26 @@ enum GNUNET_BLOCK_EvaluationResult GNUNET_BLOCK_EVALUATION_RESULT_INVALID = 3, /** + * Block does not match xquery (valid result, not relevant for the request) + */ + GNUNET_BLOCK_EVALUATION_RESULT_IRRELEVANT = 4, + + /** * Query is valid, no reply given. */ - GNUNET_BLOCK_EVALUATION_REQUEST_VALID = 4, + GNUNET_BLOCK_EVALUATION_REQUEST_VALID = 10, /** * Query format does not match block type (invalid query). For * example, xquery not given or xquery_size not appropriate for * type. */ - GNUNET_BLOCK_EVALUATION_REQUEST_INVALID = 5, + GNUNET_BLOCK_EVALUATION_REQUEST_INVALID = 11, /** * Specified block type not supported by this plugin. */ - GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED = 6 + GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED = 20 }; @@ -160,8 +185,8 @@ struct GNUNET_BLOCK_Context; * @param hc where to store the result. */ void -GNUNET_BLOCK_mingle_hash (const GNUNET_HashCode * in, uint32_t mingle_number, - GNUNET_HashCode * hc); +GNUNET_BLOCK_mingle_hash (const struct GNUNET_HashCode * in, uint32_t mingle_number, + struct GNUNET_HashCode * hc); /** @@ -204,7 +229,7 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx); enum GNUNET_BLOCK_EvaluationResult GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, - const GNUNET_HashCode * query, + const struct GNUNET_HashCode * query, struct GNUNET_CONTAINER_BloomFilter **bf, int32_t bf_mutator, const void *xquery, size_t xquery_size, const void *reply_block, @@ -227,7 +252,7 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, int GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, const void *block, - size_t block_size, GNUNET_HashCode * key); + size_t block_size, struct GNUNET_HashCode * key); @@ -243,7 +268,7 @@ GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, */ struct GNUNET_CONTAINER_BloomFilter * GNUNET_BLOCK_construct_bloomfilter (int32_t bf_mutator, - const GNUNET_HashCode * seen_results, + const struct GNUNET_HashCode * seen_results, unsigned int seen_results_count); diff --git a/src/include/gnunet_block_plugin.h b/src/include/gnunet_block_plugin.h index 0ead4af..ac549fe 100644 --- a/src/include/gnunet_block_plugin.h +++ b/src/include/gnunet_block_plugin.h @@ -56,7 +56,7 @@ typedef enum GNUNET_BLOCK_Type type, const - GNUNET_HashCode + struct GNUNET_HashCode * query, struct GNUNET_CONTAINER_BloomFilter @@ -90,7 +90,7 @@ typedef int (*GNUNET_BLOCK_GetKeyFunction) (void *cls, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size, - GNUNET_HashCode * key); + struct GNUNET_HashCode * key); diff --git a/src/include/gnunet_chat_service.h b/src/include/gnunet_chat_service.h index 938b434..8e77f9b 100644 --- a/src/include/gnunet_chat_service.h +++ b/src/include/gnunet_chat_service.h @@ -111,7 +111,7 @@ typedef int (*GNUNET_CHAT_JoinCallback) (void *cls); */ typedef int (*GNUNET_CHAT_MessageCallback) (void *cls, struct GNUNET_CHAT_Room * room, - const GNUNET_HashCode * sender, + const struct GNUNET_HashCode * sender, const struct GNUNET_CONTAINER_MetaData * member_info, const char *message, @@ -156,7 +156,7 @@ typedef int (*GNUNET_CHAT_MessageConfirmation) (void *cls, uint32_t orig_seq_number, struct GNUNET_TIME_Absolute timestamp, - const GNUNET_HashCode * + const struct GNUNET_HashCode * receiver); /** @@ -195,7 +195,7 @@ GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CHAT_MemberListCallback memberCallback, void *member_cls, GNUNET_CHAT_MessageConfirmation confirmationCallback, - void *confirmation_cls, GNUNET_HashCode * me); + void *confirmation_cls, struct GNUNET_HashCode * me); /** * Send a message. diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 9f77658..4700694 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -46,10 +46,18 @@ #include <stdarg.h> #endif +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + /** * Version of the API (for entire gnunetutil.so library). */ -#define GNUNET_UTIL_VERSION 0x00090200 +#define GNUNET_UTIL_VERSION 0x00090500 /** * Named constants for return values. The following @@ -170,9 +178,13 @@ */ #define GNUNET_NORETURN __attribute__((noreturn)) +#if MINGW #if __GNUC__ > 3 /** - * gcc 4.x-ism to pack structures even on W32 (to be used before structs) + * gcc 4.x-ism to pack structures even on W32 (to be used before structs); + * Using this would cause structs to be unaligned on the stack on Sparc, + * so we *only* use this on W32 (see #670578 from Debian); fortunately, + * W32 doesn't run on sparc anyway. */ #define GNUNET_NETWORK_STRUCT_BEGIN \ _Pragma("pack(push)") \ @@ -180,19 +192,23 @@ /** * gcc 4.x-ism to pack structures even on W32 (to be used after structs) + * Using this would cause structs to be unaligned on the stack on Sparc, + * so we *only* use this on W32 (see #670578 from Debian); fortunately, + * W32 doesn't run on sparc anyway. */ #define GNUNET_NETWORK_STRUCT_END _Pragma("pack(pop)") + #else -#ifdef MINGW #error gcc 4.x or higher required on W32 systems #endif +#else /** - * Good luck, GNUNET_PACKED should suffice, but this won't work on W32 + * Define as empty, GNUNET_PACKED should suffice, but this won't work on W32 */ #define GNUNET_NETWORK_STRUCT_BEGIN /** - * Good luck, GNUNET_PACKED should suffice, but this won't work on W32 + * Define as empty, GNUNET_PACKED should suffice, but this won't work on W32; */ #define GNUNET_NETWORK_STRUCT_END #endif @@ -222,13 +238,21 @@ struct GNUNET_MessageHeader /** - * @brief 512-bit hashcode + * @brief A SHA-512 hashcode */ -typedef struct GNUNET_HashCode +struct GNUNET_HashCode { uint32_t bits[512 / 8 / sizeof (uint32_t)]; /* = 16 */ -} -GNUNET_HashCode; +}; + + +/** + * @brief A SHA-256 hashcode + */ +struct GNUNET_CRYPTO_ShortHashCode +{ + uint32_t bits[256 / 8 / sizeof (uint32_t)]; /* = 8 */ +}; /** @@ -237,7 +261,7 @@ GNUNET_HashCode; */ struct GNUNET_PeerIdentity { - GNUNET_HashCode hashPubKey; + struct GNUNET_HashCode hashPubKey; }; GNUNET_NETWORK_STRUCT_END @@ -285,15 +309,20 @@ typedef void (*GNUNET_Logger) (void *cls, enum GNUNET_ErrorType kind, /** - * Number of log calls to ignore. + * Get the number of log calls that are going to be skipped + * + * @return number of log calls to be ignored */ -extern unsigned int skip_log; +int +GNUNET_get_log_skip (); #if !defined(GNUNET_CULL_LOGGING) int GNUNET_get_log_call_status (int caller_level, const char *comp, const char *file, const char *function, int line); #endif + + /** * Main log function. * @@ -345,7 +374,7 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp, if ((GNUNET_EXTRA_LOGGING > 0) || ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) { \ if (GN_UNLIKELY(log_call_enabled == -1))\ log_call_enabled = GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), (comp), __FILE__, __FUNCTION__, log_line); \ - if (GN_UNLIKELY(skip_log > 0)) {skip_log--;}\ + if (GN_UNLIKELY(GNUNET_get_log_skip () > 0)) { GNUNET_log_skip (-1, GNUNET_NO); }\ else {\ if (GN_UNLIKELY(log_call_enabled))\ GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \ @@ -358,7 +387,7 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp, if ((GNUNET_EXTRA_LOGGING > 0) || ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) { \ if (GN_UNLIKELY(log_call_enabled == -1))\ log_call_enabled = GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), NULL, __FILE__, __FUNCTION__, log_line);\ - if (GN_UNLIKELY(skip_log > 0)) {skip_log--;}\ + if (GN_UNLIKELY(GNUNET_get_log_skip () > 0)) { GNUNET_log_skip (-1, GNUNET_NO); }\ else {\ if (GN_UNLIKELY(log_call_enabled))\ GNUNET_log_nocheck ((kind), __VA_ARGS__); \ @@ -372,6 +401,34 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp, /** + * Log error message about missing configuration option. + * + * @param kind log level + * @param section section with missing option + * @param option name of missing option + */ +void +GNUNET_log_config_missing (enum GNUNET_ErrorType kind, + const char *section, + const char *option); + + +/** + * Log error message about invalid configuration option value. + * + * @param kind log level + * @param section section with invalid option + * @param option name of invalid option + * @param required what is required that is invalid about the option + */ +void +GNUNET_log_config_invalid (enum GNUNET_ErrorType kind, + const char *section, + const char *option, + const char *required); + + +/** * Abort the process, generate a core dump if possible. */ void @@ -380,11 +437,11 @@ GNUNET_abort (void) GNUNET_NORETURN; /** * Ignore the next n calls to the log function. * - * @param n number of log calls to ignore + * @param n number of log calls to ignore (could be negative) * @param check_reset GNUNET_YES to assert that the log skip counter is currently zero */ void -GNUNET_log_skip (unsigned int n, int check_reset); +GNUNET_log_skip (int n, int check_reset); /** @@ -420,6 +477,31 @@ GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls); /** + * Convert a short hash value to a string (for printing debug messages). + * This is one of the very few calls in the entire API that is + * NOT reentrant! + * + * @param hc the short hash code + * @return string + */ +const char * +GNUNET_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc); + + +/** + * Convert a short hash value to a string (for printing debug messages). + * This prints all 104 characters of a hashcode! + * This is one of the very few calls in the entire API that is + * NOT reentrant! + * + * @param hc the short hash code + * @return string + */ +const char * +GNUNET_short_h2s_full (const struct GNUNET_CRYPTO_ShortHashCode * hc); + + +/** * Convert a hash value to a string (for printing debug messages). * This is one of the very few calls in the entire API that is * NOT reentrant! @@ -428,7 +510,7 @@ GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls); * @return string */ const char * -GNUNET_h2s (const GNUNET_HashCode * hc); +GNUNET_h2s (const struct GNUNET_HashCode * hc); /** @@ -441,7 +523,7 @@ GNUNET_h2s (const GNUNET_HashCode * hc); * @return string */ const char * -GNUNET_h2s_full (const GNUNET_HashCode * hc); +GNUNET_h2s_full (const struct GNUNET_HashCode * hc); /** @@ -855,4 +937,17 @@ GNUNET_copy_message (const struct GNUNET_MessageHeader *msg); #endif #endif + + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + + + #endif /*GNUNET_COMMON_H_ */ diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h index 0fcb4e0..0c87a53 100644 --- a/src/include/gnunet_configuration_lib.h +++ b/src/include/gnunet_configuration_lib.h @@ -113,6 +113,37 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, /** + * Serializes the given configuration. + * + * @param cfg configuration to serialize + * @param size will be set to the size of the serialized memory block + * @return the memory block where the serialized configuration is + * present. This memory should be freed by the caller + */ +char * +GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, + size_t *size); + + +/** + * De-serializes configuration + * + * @param cfg configuration to update + * @param mem the memory block of serialized configuration + * @param size the size of the memory block + * @param allow_inline set to GNUNET_YES if we recursively load configuration + * from inlined configurations; GNUNET_NO if not and raise warnings + * when we come across them + * @return GNUNET_OK on success, GNUNET_ERROR on error + */ +int +GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *mem, + const size_t size, + int allow_inline); + + +/** * Write configuration file. * * @param cfg configuration to write @@ -123,6 +154,7 @@ int GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename); + /** * Write only configuration entries that have been changed to configuration file * @param cfgDefault default configuration @@ -136,6 +168,21 @@ GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle const struct GNUNET_CONFIGURATION_Handle *cfgNew, const char *filename); + +/** + * Compute configuration with only entries that have been changed + * + * @param cfgDefault original configuration + * @param cfgNew new configuration + * @return configuration with only the differences, never NULL + */ +struct GNUNET_CONFIGURATION_Handle * +GNUNET_CONFIGURATION_get_diff (const struct GNUNET_CONFIGURATION_Handle + *cfgDefault, + const struct GNUNET_CONFIGURATION_Handle + *cfgNew); + + /** * Test if there are configuration options that were * changed since the last save. diff --git a/src/include/gnunet_constants.h b/src/include/gnunet_constants.h index 771b473..f104834 100644 --- a/src/include/gnunet_constants.h +++ b/src/include/gnunet_constants.h @@ -52,30 +52,11 @@ extern "C" #define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) /** - * After how long do we consider a connection to a peer dead - * if we got an explicit disconnect and were unable to reconnect? - */ -#define GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) - -/** * How long do we delay reading more from a peer after a quota violation? */ #define GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) /** - * How long do we wait after a FORK+EXEC before testing for the - * resulting process to be up (port open, waitpid, etc.)? - */ -#define GNUNET_CONSTANTS_EXEC_WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200) - -/** - * After how long do we retry a service connection that was - * unavailable? Used in cases where an exponential back-off - * seems inappropriate. - */ -#define GNUNET_CONSTANTS_SERVICE_RETRY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500) - -/** * After how long do we consider a service unresponsive * even if we assume that the service commonly does not * respond instantly (DNS, Database, etc.). @@ -116,19 +97,7 @@ extern "C" * Size of the 'struct EncryptedMessage' of the core (which * is the per-message overhead of the core). */ -#define GNUNET_CONSTANTS_CORE_SIZE_ENCRYPTED_MESSAGE (24 + sizeof (GNUNET_HashCode)) - -/** - * Size of the 'struct OutboundMessage' of the transport - * (which, in combination with the - * GNUNET_CONSTANTS_CORE_SIZE_ENCRYPTED_MESSAGE) defines - * the headers that must be pre-pendable to all GNUnet - * messages. Taking GNUNET_SERVER_MAX_MESSAGE_SIZE - * and subtracting these two constants defines the largest - * message core can handle. - */ -#define GNUNET_CONSTANTS_TRANSPORT_SIZE_OUTBOUND_MESSAGE (16 + sizeof (struct GNUNET_PeerIdentity)) - +#define GNUNET_CONSTANTS_CORE_SIZE_ENCRYPTED_MESSAGE (24 + sizeof (struct GNUNET_HashCode)) /** * What is the maximum size for encrypted messages? Note that this diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h index a78d8cc..0616006 100644 --- a/src/include/gnunet_container_lib.h +++ b/src/include/gnunet_container_lib.h @@ -62,7 +62,7 @@ struct GNUNET_CONTAINER_BloomFilter; * @return GNUNET_YES if next was updated * GNUNET_NO if there are no more entries */ -typedef int (*GNUNET_HashCodeIterator) (void *cls, GNUNET_HashCode * next); +typedef int (*GNUNET_HashCodeIterator) (void *cls, struct GNUNET_HashCode * next); /** @@ -121,7 +121,7 @@ GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct */ int GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter - *bf, const GNUNET_HashCode * e); + *bf, const struct GNUNET_HashCode * e); /** @@ -131,7 +131,7 @@ GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter */ void GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, - const GNUNET_HashCode * e); + const struct GNUNET_HashCode * e); /** @@ -141,7 +141,7 @@ GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, */ void GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, - const GNUNET_HashCode * e); + const struct GNUNET_HashCode * e); /** @@ -294,7 +294,7 @@ GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData * @param data_mime_type mime-type of data (not of the original file); * can be NULL (if mime-type is not known) * @param data actual meta-data found - * @param data_len number of bytes in data + * @param data_size number of bytes in data * @return GNUNET_OK on success, GNUNET_SYSERR if this entry already exists * data_mime_type and plugin_name are not considered for "exists" checks */ @@ -304,7 +304,7 @@ GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, const char *data_mime_type, const char *data, - size_t data_len); + size_t data_size); /** @@ -326,13 +326,13 @@ GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md, * @param type type of the item to remove * @param data specific value to remove, NULL to remove all * entries of the given type - * @param data_len number of bytes in data + * @param data_size number of bytes in data * @return GNUNET_OK on success, GNUNET_SYSERR if the item does not exist in md */ int GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md, enum EXTRACTOR_MetaType type, - const char *data, size_t data_len); + const char *data, size_t data_size); /** @@ -534,7 +534,7 @@ enum GNUNET_CONTAINER_MultiHashMapOption * GNUNET_NO if not. */ typedef int (*GNUNET_CONTAINER_HashMapIterator) (void *cls, - const GNUNET_HashCode * key, + const struct GNUNET_HashCode * key, void *value); @@ -542,10 +542,20 @@ typedef int (*GNUNET_CONTAINER_HashMapIterator) (void *cls, * Create a multi hash map. * * @param len initial size (map will grow as needed) + * @param do_not_copy_keys GNUNET_NO is always safe and should be used by default; + * GNUNET_YES means that on 'put', the 'key' does not have + * to be copied as the destination of the pointer is + * guaranteed to be life as long as the value is stored in + * the hashmap. This can significantly reduce memory + * consumption, but of course is also a recipie for + * heap corruption if the assumption is not true. Only + * use this if (1) memory use is important in this case and + * (2) you have triple-checked that the invariant holds * @return NULL on error */ struct GNUNET_CONTAINER_MultiHashMap * -GNUNET_CONTAINER_multihashmap_create (unsigned int len); +GNUNET_CONTAINER_multihashmap_create (unsigned int len, + int do_not_copy_keys); /** @@ -571,7 +581,7 @@ GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap */ void * GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap - *map, const GNUNET_HashCode * key); + *map, const struct GNUNET_HashCode * key); /** @@ -587,7 +597,7 @@ GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap */ int GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, - const GNUNET_HashCode * key, void *value); + const struct GNUNET_HashCode * key, void *value); /** * Remove all entries for the given key from the map. @@ -599,7 +609,7 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, */ int GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap - *map, const GNUNET_HashCode * key); + *map, const struct GNUNET_HashCode * key); /** @@ -614,7 +624,7 @@ GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap int GNUNET_CONTAINER_multihashmap_contains (const struct GNUNET_CONTAINER_MultiHashMap *map, - const GNUNET_HashCode * key); + const struct GNUNET_HashCode * key); /** @@ -630,7 +640,7 @@ GNUNET_CONTAINER_multihashmap_contains (const struct int GNUNET_CONTAINER_multihashmap_contains_value (const struct GNUNET_CONTAINER_MultiHashMap - *map, const GNUNET_HashCode * key, + *map, const struct GNUNET_HashCode * key, const void *value); @@ -648,7 +658,7 @@ GNUNET_CONTAINER_multihashmap_contains_value (const struct */ int GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, - const GNUNET_HashCode * key, void *value, + const struct GNUNET_HashCode * key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt); @@ -692,7 +702,7 @@ GNUNET_CONTAINER_multihashmap_iterate (const struct int GNUNET_CONTAINER_multihashmap_get_multiple (const struct GNUNET_CONTAINER_MultiHashMap *map, - const GNUNET_HashCode * key, + const struct GNUNET_HashCode * key, GNUNET_CONTAINER_HashMapIterator it, void *it_cls); @@ -822,6 +832,136 @@ GNUNET_CONTAINER_multihashmap_get_multiple (const struct (element)->prev = NULL; } while (0) +/* ************ Multi-DLL interface, allows DLL elements to be + in multiple lists at the same time *********************** */ + +/** + * Insert an element at the head of a MDLL. Assumes that head, tail and + * element are structs with prev and next fields. + * + * @param mdll suffix name for the next and prev pointers in the element + * @param head pointer to the head of the MDLL + * @param tail pointer to the tail of the MDLL + * @param element element to insert + */ +#define GNUNET_CONTAINER_MDLL_insert(mdll,head,tail,element) do { \ + GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \ + GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \ + (element)->next_##mdll = (head); \ + (element)->prev_##mdll = NULL; \ + if ((tail) == NULL) \ + (tail) = element; \ + else \ + (head)->prev_##mdll = element; \ + (head) = (element); } while (0) + + +/** + * Insert an element at the tail of a MDLL. Assumes that head, tail and + * element are structs with prev and next fields. + * + * @param mdll suffix name for the next and prev pointers in the element + * @param head pointer to the head of the MDLL + * @param tail pointer to the tail of the MDLL + * @param element element to insert + */ +#define GNUNET_CONTAINER_MDLL_insert_tail(mdll,head,tail,element) do { \ + GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \ + GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \ + (element)->prev_##mdll = (tail); \ + (element)->next_##mdll = NULL; \ + if ((head) == NULL) \ + (head) = element; \ + else \ + (tail)->next_##mdll = element; \ + (tail) = (element); } while (0) + + +/** + * Insert an element into a MDLL after the given other element. Insert + * at the head if the other element is NULL. + * + * @param mdll suffix name for the next and prev pointers in the element + * @param head pointer to the head of the MDLL + * @param tail pointer to the tail of the MDLL + * @param other prior element, NULL for insertion at head of MDLL + * @param element element to insert + */ +#define GNUNET_CONTAINER_MDLL_insert_after(mdll,head,tail,other,element) do { \ + GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \ + GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \ + (element)->prev_##mdll = (other); \ + if (NULL == other) \ + { \ + (element)->next_##mdll = (head); \ + (head) = (element); \ + } \ + else \ + { \ + (element)->next_##mdll = (other)->next_##mdll; \ + (other)->next_##mdll = (element); \ + } \ + if (NULL == (element)->next_##mdll) \ + (tail) = (element); \ + else \ + (element)->next->prev_##mdll = (element); } while (0) + + +/** + * Insert an element into a MDLL before the given other element. Insert + * at the tail if the other element is NULL. + * + * @param mdll suffix name for the next and prev pointers in the element + * @param head pointer to the head of the MDLL + * @param tail pointer to the tail of the MDLL + * @param other prior element, NULL for insertion at head of MDLL + * @param element element to insert + */ +#define GNUNET_CONTAINER_MDLL_insert_before(mdll,head,tail,other,element) do { \ + GNUNET_assert ( ( (element)->prev_##mdll == NULL) && ((head) != (element))); \ + GNUNET_assert ( ( (element)->next_##mdll == NULL) && ((tail) != (element))); \ + (element)->next_##mdll = (other); \ + if (NULL == other) \ + { \ + (element)->prev = (tail); \ + (tail) = (element); \ + } \ + else \ + { \ + (element)->prev_##mdll = (other)->prev_##mdll; \ + (other)->prev_##mdll = (element); \ + } \ + if (NULL == (element)->prev_##mdll) \ + (head) = (element); \ + else \ + (element)->prev_##mdll->next_##mdll = (element); } while (0) + + +/** + * Remove an element from a MDLL. Assumes + * that head, tail and element are structs + * with prev and next fields. + * + * @param mdll suffix name for the next and prev pointers in the element + * @param head pointer to the head of the MDLL + * @param tail pointer to the tail of the MDLL + * @param element element to remove + */ +#define GNUNET_CONTAINER_MDLL_remove(mdll,head,tail,element) do { \ + GNUNET_assert ( ( (element)->prev_##mdll != NULL) || ((head) == (element))); \ + GNUNET_assert ( ( (element)->next_##mdll != NULL) || ((tail) == (element))); \ + if ((element)->prev_##mdll == NULL) \ + (head) = (element)->next_##mdll; \ + else \ + (element)->prev_##mdll->next_##mdll = (element)->next_##mdll; \ + if ((element)->next_##mdll == NULL) \ + (tail) = (element)->prev_##mdll; \ + else \ + (element)->next_##mdll->prev_##mdll = (element)->prev_##mdll; \ + (element)->next_##mdll = NULL; \ + (element)->prev_##mdll = NULL; } while (0) + + /* ******************** Heap *************** */ @@ -942,24 +1082,6 @@ GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap, GNUNET_CONTAINER_HeapIterator iterator, void *iterator_cls); - -/** - * Return a *uniform* random element from the heap. Choose a random - * number between 0 and heap size and then walk directly to it. - * This cost can be between 0 and n, amortized cost of logN. - * - * @param heap heap to choose random element from - * @param max how many nodes from the heap to choose from - * - * @return data stored at the chosen random node, - * NULL if the heap is empty. - * - */ -void * -GNUNET_CONTAINER_heap_get_random (struct GNUNET_CONTAINER_Heap *heap, - uint32_t max); - - /** * Perform a random walk of the tree. The walk is biased * towards elements closer to the root of the tree (since diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h index cb48f41..4af8ef2 100644 --- a/src/include/gnunet_core_service.h +++ b/src/include/gnunet_core_service.h @@ -42,7 +42,7 @@ extern "C" /** * Version number of GNUnet-core API. */ -#define GNUNET_CORE_VERSION 0x00000000 +#define GNUNET_CORE_VERSION 0x00000001 /** @@ -131,7 +131,9 @@ struct GNUNET_CORE_MessageHandler * for good). Note that the private key of the peer is intentionally * not exposed here; if you need it, your process should try to read * the private key file directly (which should work if you are - * authorized...). + * authorized...). Implementations of this function must not call + * GNUNET_CORE_disconnect (other than by scheduling a new task to + * do this later). * * @param cls closure * @param server handle to the server, NULL if we failed @@ -148,14 +150,13 @@ typedef void (*GNUNET_CORE_StartupCallback) (void *cls, * (or fail) asynchronously. This function primarily causes the given * callback notification functions to be invoked whenever the * specified event happens. The maximum number of queued - * notifications (queue length) is per client but the queue is shared + * notifications (queue length) is per client; the queue is shared * across all types of notifications. So a slow client that registers * for 'outbound_notify' also risks missing 'inbound_notify' messages. * Certain events (such as connect/disconnect notifications) are not * subject to queue size limitations. * * @param cfg configuration to use - * @param queue_size size of the per-peer message queue * @param cls closure for the various callbacks that follow (including handlers in the handlers array) * @param init callback to call once we have successfully * connected to the core service @@ -190,7 +191,7 @@ typedef void (*GNUNET_CORE_StartupCallback) (void *cls, */ struct GNUNET_CORE_Handle * GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, - unsigned int queue_size, void *cls, + void *cls, GNUNET_CORE_StartupCallback init, GNUNET_CORE_ConnectEventHandler connects, GNUNET_CORE_DisconnectEventHandler disconnects, @@ -220,10 +221,13 @@ struct GNUNET_CORE_TransmitHandle; /** * Ask the core to call "notify" once it is ready to transmit the - * given number of bytes to the specified "target". Must only be + * given number of bytes to the specified "target". Must only be * called after a connection to the respective peer has been - * established (and the client has been informed about this). - * + * established (and the client has been informed about this). You may + * have one request of this type pending for each connected peer at + * any time. If a peer disconnects, the application MUST call + * "GNUNET_CORE_notify_transmit_ready_cancel" on the respective + * transmission request, if one such request is pending. * * @param handle connection to core service * @param cork is corking allowed for this transmission? @@ -232,18 +236,13 @@ struct GNUNET_CORE_TransmitHandle; * @param target who should receive the message, never NULL (can be this peer's identity for loopback) * @param notify_size how many bytes of buffer space does notify want? * @param notify function to call when buffer space is available; - * will be called with NULL on timeout or if the overall queue - * for this peer is larger than queue_size and this is currently - * the message with the lowest priority; will also be called - * with 'NULL' buf if the peer disconnects; since the disconnect - * signal will be emmitted even later, clients MUST cancel + * will be called with NULL on timeout; clients MUST cancel * all pending transmission requests DURING the disconnect - * handler (unless they ensure that 'notify' never calls - * 'GNUNET_CORE_notify_transmit_ready'). + * handler * @param notify_cls closure for notify * @return non-NULL if the notify callback was queued, - * NULL if we can not even queue the request (insufficient - * memory); if NULL is returned, "notify" will NOT be called. + * NULL if we can not even queue the request (request already pending); + * if NULL is returned, "notify" will NOT be called. */ struct GNUNET_CORE_TransmitHandle * GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, int cork, @@ -327,6 +326,26 @@ void GNUNET_CORE_is_peer_connected_cancel (struct GNUNET_CORE_ConnectTestHandle *cth); +/** + * Check if the given peer is currently connected. This function is for special + * cirumstances (GNUNET_TESTBED uses it), normal users of the CORE API are + * expected to track which peers are connected based on the connect/disconnect + * callbacks from GNUNET_CORE_connect. This function is NOT part of the + * 'versioned', 'official' API. The difference between this function and the + * function GNUNET_CORE_is_peer_connected() is that this one returns + * synchronously after looking in the CORE API cache. The function + * GNUNET_CORE_is_peer_connected() sends a message to the CORE service and hence + * its response is given asynchronously. + * + * @param h the core handle + * @param pid the identity of the peer to check if it has been connected to us + * @return GNUNET_YES if the peer is connected to us; GNUNET_NO if not + */ +int +GNUNET_CORE_is_peer_connected_sync (const struct GNUNET_CORE_Handle *h, + const struct GNUNET_PeerIdentity *pid); + + #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 777ddd9..6120b48 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -71,7 +71,6 @@ enum GNUNET_CRYPTO_Quality */ #define GNUNET_CRYPTO_AES_KEY_LENGTH (256/8) - /** * @brief Length of RSA encrypted data (2048 bit) * @@ -84,23 +83,39 @@ enum GNUNET_CRYPTO_Quality */ #define GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH 256 - /** * Length of an RSA KEY (n,e,len), 2048 bit (=256 octests) key n, 2 byte e */ #define GNUNET_CRYPTO_RSA_KEY_LENGTH 258 - /** * Length of a hash value */ -#define GNUNET_CRYPTO_HASH_LENGTH 512/8 +#define GNUNET_CRYPTO_HASH_LENGTH (512/8) + +/** + * Maximum length of an ECC signature. + * Note: round up to multiple of 8 minus 2 for alignment. + */ +#define GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH 190 + +/** + * Maximum length of the public key (q-point, Q = dP) when encoded. + */ +#define GNUNET_CRYPTO_ECC_MAX_PUBLIC_KEY_LENGTH 140 + /** * The private information of an RSA key pair. */ struct GNUNET_CRYPTO_RsaPrivateKey; +/** + * The private information of an ECC private key. + */ +struct GNUNET_CRYPTO_EccPrivateKey; + + GNUNET_NETWORK_STRUCT_BEGIN /** @@ -129,7 +144,7 @@ GNUNET_NETWORK_STRUCT_END /** - * @brief 0-terminated ASCII encoding of a GNUNET_HashCode. + * @brief 0-terminated ASCII encoding of a struct GNUNET_HashCode. */ struct GNUNET_CRYPTO_HashAsciiEncoded { @@ -137,17 +152,6 @@ struct GNUNET_CRYPTO_HashAsciiEncoded }; - - -/** - * @brief 256-bit hashcode - */ -struct GNUNET_CRYPTO_ShortHashCode -{ - uint32_t bits[256 / 8 / sizeof (uint32_t)]; /* = 8 */ -}; - - /** * @brief 0-terminated ASCII encoding of a 'struct GNUNET_ShortHashCode'. */ @@ -231,6 +235,85 @@ struct GNUNET_CRYPTO_RsaEncryptedData /** + * @brief header of what an ECC signature signs + * this must be followed by "size - 8" bytes of + * the actual signed data + */ +struct GNUNET_CRYPTO_EccSignaturePurpose +{ + /** + * How many bytes does this signature sign? + * (including this purpose header); in network + * byte order (!). + */ + uint32_t size GNUNET_PACKED; + + /** + * What does this signature vouch for? This + * must contain a GNUNET_SIGNATURE_PURPOSE_XXX + * constant (from gnunet_signatures.h). In + * network byte order! + */ + uint32_t purpose GNUNET_PACKED; + +}; + + +/** + * @brief an ECC signature + */ +struct GNUNET_CRYPTO_EccSignature +{ + /** + * Overall size of the signature data. + */ + uint16_t size; + + /** + * S-expression, padded with zeros. + */ + char sexpr[GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH]; +}; + + +/** + * Public ECC key (always for NIST P-521) encoded in a format suitable + * for network transmission as created using 'gcry_sexp_sprint'. + */ +struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded +{ + /** + * Size of the encoding, in network byte order. + */ + uint16_t size; + + /** + * Actual length of the q-point binary encoding. + */ + uint16_t len; + + /** + * 0-padded q-point in binary encoding (GCRYPT_MPI_FMT_USG). + */ + unsigned char key[GNUNET_CRYPTO_ECC_MAX_PUBLIC_KEY_LENGTH]; +}; + + +struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded +{ + /** + * Overall size of the private key. + */ + uint16_t size; + + /* followd by S-expression, opaque to applications */ + + /* FIXME: consider defining padding to make this a fixed-size struct */ + +}; + + +/** * @brief type for session keys */ struct GNUNET_CRYPTO_AesSessionKey @@ -251,7 +334,7 @@ GNUNET_NETWORK_STRUCT_END * @brief IV for sym cipher * * NOTE: must be smaller (!) in size than the - * GNUNET_HashCode. + * struct GNUNET_HashCode. */ struct GNUNET_CRYPTO_AesInitializationVector { @@ -448,7 +531,7 @@ GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector *iv, * safely cast to char*, a '\\0' termination is set). */ void -GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, +GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode * block, struct GNUNET_CRYPTO_HashAsciiEncoded *result); @@ -465,7 +548,7 @@ GNUNET_CRYPTO_short_hash_to_enc (const struct GNUNET_CRYPTO_ShortHashCode * bloc /** - * Convert ASCII encoding back to a 'GNUNET_HashCode' + * Convert ASCII encoding back to a 'struct GNUNET_HashCode' * * @param enc the encoding * @param enclen number of characters in 'enc' (without 0-terminator, which can be missing) @@ -474,7 +557,7 @@ GNUNET_CRYPTO_short_hash_to_enc (const struct GNUNET_CRYPTO_ShortHashCode * bloc */ int GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen, - GNUNET_HashCode * result); + struct GNUNET_HashCode * result); /** @@ -491,7 +574,7 @@ GNUNET_CRYPTO_short_hash_from_string2 (const char *enc, size_t enclen, /** - * Convert ASCII encoding back to GNUNET_HashCode + * Convert ASCII encoding back to struct GNUNET_HashCode * * @param enc the encoding * @param result where to store the hash code @@ -536,8 +619,8 @@ GNUNET_CRYPTO_short_hash_cmp (const struct GNUNET_CRYPTO_ShortHashCode * h1, * @return number between 0 and UINT32_MAX */ uint32_t -GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, - const GNUNET_HashCode * b); +GNUNET_CRYPTO_hash_distance_u32 (const struct GNUNET_HashCode * a, + const struct GNUNET_HashCode * b); /** @@ -548,7 +631,7 @@ GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, * @param ret pointer to where to write the hashcode */ void -GNUNET_CRYPTO_hash (const void *block, size_t size, GNUNET_HashCode * ret); +GNUNET_CRYPTO_hash (const void *block, size_t size, struct GNUNET_HashCode * ret); /** @@ -598,7 +681,7 @@ GNUNET_CRYPTO_short_hash_from_truncation (const struct GNUNET_HashCode *dh, void GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, - GNUNET_HashCode * hmac); + struct GNUNET_HashCode * hmac); /** @@ -609,7 +692,7 @@ GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, * @param res resulting hash, NULL on error */ typedef void (*GNUNET_CRYPTO_HashCompletedCallback) (void *cls, - const GNUNET_HashCode * + const struct GNUNET_HashCode * res); @@ -652,7 +735,7 @@ GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc); */ void GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, - GNUNET_HashCode * result); + struct GNUNET_HashCode * result); /** @@ -663,9 +746,9 @@ GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, * @param result set to b - a */ void -GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, - const GNUNET_HashCode * b, - GNUNET_HashCode * result); +GNUNET_CRYPTO_hash_difference (const struct GNUNET_HashCode * a, + const struct GNUNET_HashCode * b, + struct GNUNET_HashCode * result); /** @@ -676,9 +759,9 @@ GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, * @param result set to a + delta */ void -GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, - const GNUNET_HashCode * delta, - GNUNET_HashCode * result); +GNUNET_CRYPTO_hash_sum (const struct GNUNET_HashCode * a, + const struct GNUNET_HashCode * delta, + struct GNUNET_HashCode * result); /** @@ -689,8 +772,8 @@ GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, * @param result set to a ^ b */ void -GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b, - GNUNET_HashCode * result); +GNUNET_CRYPTO_hash_xor (const struct GNUNET_HashCode * a, const struct GNUNET_HashCode * b, + struct GNUNET_HashCode * result); /** @@ -701,7 +784,7 @@ GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b, * @param iv set to a valid initialization vector */ void -GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, +GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode * hc, struct GNUNET_CRYPTO_AesSessionKey *skey, struct GNUNET_CRYPTO_AesInitializationVector *iv); @@ -715,11 +798,11 @@ GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, * @return Bit \a bit from hashcode \a code, -1 for invalid index */ int -GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit); +GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode * code, unsigned int bit); /** * Determine how many low order bits match in two - * GNUNET_HashCodes. i.e. - 010011 and 011111 share + * struct GNUNET_HashCodes. i.e. - 010011 and 011111 share * the first two lowest order bits, and therefore the * return value is two (NOT XOR distance, nor how many * bits match absolutely!). @@ -730,8 +813,8 @@ GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit); * @return the number of bits that match */ unsigned int -GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first, - const GNUNET_HashCode * second); +GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode * first, + const struct GNUNET_HashCode * second); /** @@ -743,7 +826,7 @@ GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first, * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. */ int -GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, const GNUNET_HashCode * h2); +GNUNET_CRYPTO_hash_cmp (const struct GNUNET_HashCode * h1, const struct GNUNET_HashCode * h2); /** @@ -756,9 +839,9 @@ GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, const GNUNET_HashCode * h2); * @return -1 if h1 is closer, 1 if h2 is closer and 0 if h1==h2. */ int -GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, - const GNUNET_HashCode * h2, - const GNUNET_HashCode * target); +GNUNET_CRYPTO_hash_xorcmp (const struct GNUNET_HashCode * h1, + const struct GNUNET_HashCode * h2, + const struct GNUNET_HashCode * target); /** @@ -860,22 +943,13 @@ GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts, /** - * Create a new private key. Caller must free return value. - * - * @return fresh private key - */ -struct GNUNET_CRYPTO_RsaPrivateKey * -GNUNET_CRYPTO_rsa_key_create (void); - - -/** * Convert a public key to a string. * * @param pub key to convert * @return string representing 'pub' */ char * -GNUNET_CRYPTO_rsa_public_key_to_string (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub); +GNUNET_CRYPTO_rsa_public_key_to_string (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub); /** @@ -895,22 +969,24 @@ GNUNET_CRYPTO_rsa_public_key_from_string (const char *enc, /** * Encode the private key in a format suitable for * storing it into a file. - * @returns encoding of the private key. - * The first 4 bytes give the size of the array, as usual. + * @return encoding of the private key */ struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded * GNUNET_CRYPTO_rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey); + /** * Decode the private key from the data-format back * to the "normal", internal format. * * @param buf the buffer where the private key data is stored * @param len the length of the data in 'buffer' + * @return NULL on error */ struct GNUNET_CRYPTO_RsaPrivateKey * GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len); + /** * Create a new private key by reading it from a file. If the * files does not exist, create a new key and write it to the @@ -924,12 +1000,57 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len); * @param filename name of file to use for storage * @return new private key, NULL on error (for example, * permission denied) + * @deprecated use 'GNUNET_CRYPTO_rsa_key_create_start' instead */ struct GNUNET_CRYPTO_RsaPrivateKey * GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename); /** + * Handle to cancel private key generation. + */ +struct GNUNET_CRYPTO_RsaKeyGenerationContext; + + +/** + * Function called upon completion of 'GNUNET_CRYPTO_rsa_key_create_async'. + * + * @param cls closure + * @param pk NULL on error, otherwise the private key (which must be free'd by the callee) + * @param emsg NULL on success, otherwise an error message + */ +typedef void (*GNUNET_CRYPTO_RsaKeyCallback)(void *cls, + struct GNUNET_CRYPTO_RsaPrivateKey *pk, + const char *emsg); + + +/** + * Create a new private key by reading it from a file. If the files + * does not exist, create a new key and write it to the file. If the + * contents of the file are invalid the old file is deleted and a + * fresh key is created. + * + * @param filename name of file to use for storage + * @param cont function to call when done (or on errors) + * @param cont_cls closure for 'cont' + * @return handle to abort operation, NULL on fatal errors (cont will not be called if NULL is returned) + */ +struct GNUNET_CRYPTO_RsaKeyGenerationContext * +GNUNET_CRYPTO_rsa_key_create_start (const char *filename, + GNUNET_CRYPTO_RsaKeyCallback cont, + void *cont_cls); + + +/** + * Abort RSA key generation. + * + * @param gc key generation context to abort + */ +void +GNUNET_CRYPTO_rsa_key_create_stop (struct GNUNET_CRYPTO_RsaKeyGenerationContext *gc); + + +/** * Setup a hostkey file for a peer given the name of the * configuration file (!). This function is used so that * at a later point code can be certain that reading a @@ -938,7 +1059,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename); * @param cfg_name name of the configuration file to use */ void -GNUNET_CRYPTO_setup_hostkey (const char *cfg_name); +GNUNET_CRYPTO_rsa_setup_hostkey (const char *cfg_name); /** @@ -949,15 +1070,16 @@ GNUNET_CRYPTO_setup_hostkey (const char *cfg_name); * @return some private key purely dependent on input */ struct GNUNET_CRYPTO_RsaPrivateKey * -GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc); +GNUNET_CRYPTO_rsa_key_create_from_hash (const struct GNUNET_HashCode *hc); /** * Free memory occupied by the private key. - * @param hostkey pointer to the memory to free + * + * @param key pointer to the memory to free */ void -GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey); +GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *key); /** @@ -1040,6 +1162,202 @@ GNUNET_CRYPTO_rsa_verify (uint32_t purpose, /** + * Function called upon completion of 'GNUNET_CRYPTO_ecc_key_create_async'. + * + * @param cls closure + * @param pk NULL on error, otherwise the private key (which must be free'd by the callee) + * @param emsg NULL on success, otherwise an error message + */ +typedef void (*GNUNET_CRYPTO_EccKeyCallback)(void *cls, + struct GNUNET_CRYPTO_EccPrivateKey *pk, + const char *emsg); + + +/** + * Free memory occupied by ECC key + * + * @param privatekey pointer to the memory to free + */ +void +GNUNET_CRYPTO_ecc_key_free (struct GNUNET_CRYPTO_EccPrivateKey *privatekey); + + +/** + * Extract the public key for the given private key. + * + * @param priv the private key + * @param pub where to write the public key + */ +void +GNUNET_CRYPTO_ecc_key_get_public (const struct GNUNET_CRYPTO_EccPrivateKey *priv, + struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub); + +/** + * Convert a public key to a string. + * + * @param pub key to convert + * @return string representing 'pub' + */ +char * +GNUNET_CRYPTO_ecc_public_key_to_string (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub); + + +/** + * Convert a string representing a public key to a public key. + * + * @param enc encoded public key + * @param enclen number of bytes in enc (without 0-terminator) + * @param pub where to store the public key + * @return GNUNET_OK on success + */ +int +GNUNET_CRYPTO_ecc_public_key_from_string (const char *enc, + size_t enclen, + struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub); + + +/** + * Encode the private key in a format suitable for + * storing it into a file. + * + * @param key key to encode + * @return encoding of the private key. + * The first 4 bytes give the size of the array, as usual. + */ +struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded * +GNUNET_CRYPTO_ecc_encode_key (const struct GNUNET_CRYPTO_EccPrivateKey *key); + + +/** + * Decode the private key from the file-format back + * to the "normal", internal format. + * + * @param buf the buffer where the private key data is stored + * @param len the length of the data in 'buffer' + * @return NULL on error + */ +struct GNUNET_CRYPTO_EccPrivateKey * +GNUNET_CRYPTO_ecc_decode_key (const char *buf, + size_t len); + + +/** + * Create a new private key by reading it from a file. If the + * files does not exist, create a new key and write it to the + * file. Caller must free return value. Note that this function + * can not guarantee that another process might not be trying + * the same operation on the same file at the same time. + * If the contents of the file + * are invalid the old file is deleted and a fresh key is + * created. + * + * @return new private key, NULL on error (for example, + * permission denied) + */ +struct GNUNET_CRYPTO_EccPrivateKey * +GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename); + + +/** + * Handle to cancel private key generation and state for the + * key generation operation. + */ +struct GNUNET_CRYPTO_EccKeyGenerationContext; + +/** + * Create a new private key. Caller must free return value. Blocking version + * (blocks to gather entropy). + * + * @return fresh private key + */ +struct GNUNET_CRYPTO_EccPrivateKey * +GNUNET_CRYPTO_ecc_key_create (void); + + +/** + * Create a new private key by reading it from a file. If the files + * does not exist, create a new key and write it to the file. If the + * contents of the file are invalid the old file is deleted and a + * fresh key is created. + * + * @param filename name of file to use for storage + * @param cont function to call when done (or on errors) + * @param cont_cls closure for 'cont' + * @return handle to abort operation, NULL on fatal errors (cont will not be called if NULL is returned) + */ +struct GNUNET_CRYPTO_EccKeyGenerationContext * +GNUNET_CRYPTO_ecc_key_create_start (const char *filename, + GNUNET_CRYPTO_EccKeyCallback cont, + void *cont_cls); + + +/** + * Abort ECC key generation. + * + * @param gc key generation context to abort + */ +void +GNUNET_CRYPTO_ecc_key_create_stop (struct GNUNET_CRYPTO_EccKeyGenerationContext *gc); + +/** + * Setup a hostkey file for a peer given the name of the + * configuration file (!). This function is used so that + * at a later point code can be certain that reading a + * hostkey is fast (for example in time-dependent testcases). + * + * @param cfg_name name of the configuration file to use + */ +void +GNUNET_CRYPTO_ecc_setup_hostkey (const char *cfg_name); + + +/** + * Derive key material from a public and a private ECC key. + * + * @param key private key to use for the ECDH (x) + * @param pub public key to use for the ECDY (yG) + * @param key_material where to write the key material (xyG) + * @return GNUNET_SYSERR on error, GNUNET_OK on success + */ +int +GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EccPrivateKey *key, + const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *pub, + struct GNUNET_HashCode *key_material); + + +/** + * Sign a given block. + * + * @param key private key to use for the signing + * @param purpose what to sign (size, purpose) + * @param sig where to write the signature + * @return GNUNET_SYSERR on error, GNUNET_OK on success + */ +int +GNUNET_CRYPTO_ecc_sign (const struct GNUNET_CRYPTO_EccPrivateKey *key, + const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, + struct GNUNET_CRYPTO_EccSignature *sig); + + +/** + * Verify signature. + * + * @param purpose what is the purpose that the signature should have? + * @param validate block to validate (size, purpose, data) + * @param sig signature that is being validated + * @param publicKey public key of the signer + * @returns GNUNET_OK if ok, GNUNET_SYSERR if invalid + */ +int +GNUNET_CRYPTO_ecc_verify (uint32_t purpose, + const struct GNUNET_CRYPTO_EccSignaturePurpose + *validate, + const struct GNUNET_CRYPTO_EccSignature *sig, + const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded + *publicKey); + + +/** * This function should only be called in testcases * where strong entropy gathering is not desired * (for example, for hostkey generation). @@ -1048,6 +1366,17 @@ void GNUNET_CRYPTO_random_disable_entropy_gathering (void); +/** + * Check if we are using weak random number generation. + * + * @return GNUNET_YES if weak number generation is on + * (thus will return YES if 'GNUNET_CRYPTO_random_disable_entropy_gathering' + * was called previously). + */ +int +GNUNET_CRYPTO_random_is_weak (void); + + #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/include/gnunet_datacache_lib.h b/src/include/gnunet_datacache_lib.h index 84cb4d6..4f97ee5 100644 --- a/src/include/gnunet_datacache_lib.h +++ b/src/include/gnunet_datacache_lib.h @@ -74,18 +74,22 @@ GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h); * An iterator over a set of items stored in the datacache. * * @param cls closure - * @param exp when will the content expire? * @param key key for the content * @param size number of bytes in data * @param data content stored * @param type type of the content + * @param exp when will the content expire? + * @param path_info_len number of entries in 'path_info' + * @param path_info a path through the network * @return GNUNET_OK to continue iterating, GNUNET_SYSERR to abort */ typedef int (*GNUNET_DATACACHE_Iterator) (void *cls, - struct GNUNET_TIME_Absolute exp, - const GNUNET_HashCode * key, + const struct GNUNET_HashCode *key, size_t size, const char *data, - enum GNUNET_BLOCK_Type type); + enum GNUNET_BLOCK_Type type, + struct GNUNET_TIME_Absolute exp, + unsigned int path_info_len, + const struct GNUNET_PeerIdentity *path_info); /** @@ -97,13 +101,17 @@ typedef int (*GNUNET_DATACACHE_Iterator) (void *cls, * @param data data to store * @param type type of the value * @param discard_time when to discard the value in any case - * @return GNUNET_OK on success, GNUNET_SYSERR on error (full, etc.) + * @param path_info_len number of entries in 'path_info' + * @param path_info a path through the network + * @return GNUNET_OK on success, GNUNET_SYSERR on error, GNUNET_NO if duplicate */ int GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, - const GNUNET_HashCode * key, size_t size, + const struct GNUNET_HashCode * key, size_t size, const char *data, enum GNUNET_BLOCK_Type type, - struct GNUNET_TIME_Absolute discard_time); + struct GNUNET_TIME_Absolute discard_time, + unsigned int path_info_len, + const struct GNUNET_PeerIdentity *path_info); /** @@ -119,7 +127,7 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, */ unsigned int GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h, - const GNUNET_HashCode * key, enum GNUNET_BLOCK_Type type, + const struct GNUNET_HashCode * key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls); diff --git a/src/include/gnunet_datacache_plugin.h b/src/include/gnunet_datacache_plugin.h index fbfcdf1..2e07501 100644 --- a/src/include/gnunet_datacache_plugin.h +++ b/src/include/gnunet_datacache_plugin.h @@ -46,7 +46,7 @@ extern "C" * @param size number of bytes that were made available */ typedef void (*GNUNET_DATACACHE_DeleteNotifyCallback) (void *cls, - const GNUNET_HashCode * + const struct GNUNET_HashCode * key, size_t size); @@ -107,11 +107,15 @@ struct GNUNET_DATACACHE_PluginFunctions * @param data data to store * @param type type of the value * @param discard_time when to discard the value in any case - * @return 0 on error, number of bytes used otherwise + * @param path_info_len number of entries in 'path_info' + * @param path_info a path through the network + * @return 0 if duplicate, -1 on error, number of bytes used otherwise */ - size_t (*put) (void *cls, const GNUNET_HashCode * key, size_t size, - const char *data, enum GNUNET_BLOCK_Type type, - struct GNUNET_TIME_Absolute discard_time); + ssize_t (*put) (void *cls, const struct GNUNET_HashCode * key, size_t size, + const char *data, enum GNUNET_BLOCK_Type type, + struct GNUNET_TIME_Absolute discard_time, + unsigned int path_info_len, + const struct GNUNET_PeerIdentity *path_info); /** @@ -125,7 +129,7 @@ struct GNUNET_DATACACHE_PluginFunctions * @param iter_cls closure for iter * @return the number of results found */ - unsigned int (*get) (void *cls, const GNUNET_HashCode * key, + unsigned int (*get) (void *cls, const struct GNUNET_HashCode * key, enum GNUNET_BLOCK_Type type, GNUNET_DATACACHE_Iterator iter, void *iter_cls); diff --git a/src/include/gnunet_datastore_plugin.h b/src/include/gnunet_datastore_plugin.h index bbf0ce2..991abb7 100644 --- a/src/include/gnunet_datastore_plugin.h +++ b/src/include/gnunet_datastore_plugin.h @@ -92,7 +92,7 @@ struct GNUNET_DATASTORE_PluginEnvironment * @return GNUNET_OK to keep the item * GNUNET_NO to delete the item */ -typedef int (*PluginDatumProcessor) (void *cls, const GNUNET_HashCode * key, +typedef int (*PluginDatumProcessor) (void *cls, const struct GNUNET_HashCode * key, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, @@ -127,7 +127,7 @@ typedef unsigned long long (*PluginEstimateSize) (void *cls); * @return GNUNET_OK on success, * GNUNET_SYSERR on failure */ -typedef int (*PluginPut) (void *cls, const GNUNET_HashCode * key, uint32_t size, +typedef int (*PluginPut) (void *cls, const struct GNUNET_HashCode * key, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, @@ -142,7 +142,7 @@ typedef int (*PluginPut) (void *cls, const GNUNET_HashCode * key, uint32_t size, * @param count how many values are stored under this key in the datastore */ typedef void (*PluginKeyProcessor) (void *cls, - const GNUNET_HashCode *key, + const struct GNUNET_HashCode *key, unsigned int count); @@ -178,8 +178,8 @@ typedef void (*PluginGetKeys) (void *cls, * @param proc_cls closure for proc */ typedef void (*PluginGetKey) (void *cls, uint64_t offset, - const GNUNET_HashCode * key, - const GNUNET_HashCode * vhash, + const struct GNUNET_HashCode * key, + const struct GNUNET_HashCode * vhash, enum GNUNET_BLOCK_Type type, PluginDatumProcessor proc, void *proc_cls); @@ -208,9 +208,6 @@ typedef void (*PluginGetRandom) (void *cls, PluginDatumProcessor proc, * priority should be added to the existing priority, ignoring the * priority in value. * - * Note that it is possible for multiple values to match this put. - * In that case, all of the respective values are updated. - * * @param cls closure * @param uid unique identifier of the datum * @param delta by how much should the priority diff --git a/src/include/gnunet_datastore_service.h b/src/include/gnunet_datastore_service.h index 2950832..721963b 100644 --- a/src/include/gnunet_datastore_service.h +++ b/src/include/gnunet_datastore_service.h @@ -153,7 +153,7 @@ GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h, uint64_t amount, */ struct GNUNET_DATASTORE_QueueEntry * GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, uint32_t rid, - const GNUNET_HashCode * key, size_t size, + const struct GNUNET_HashCode * key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, @@ -245,7 +245,7 @@ GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, uint64_t uid, */ struct GNUNET_DATASTORE_QueueEntry * GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, - const GNUNET_HashCode * key, size_t size, + const struct GNUNET_HashCode * key, size_t size, const void *data, unsigned int queue_priority, unsigned int max_queue_size, struct GNUNET_TIME_Relative timeout, @@ -268,7 +268,7 @@ GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, * maybe 0 if no unique identifier is available */ typedef void (*GNUNET_DATASTORE_DatumProcessor) (void *cls, - const GNUNET_HashCode * key, + const struct GNUNET_HashCode * key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, @@ -300,7 +300,7 @@ typedef void (*GNUNET_DATASTORE_DatumProcessor) (void *cls, */ struct GNUNET_DATASTORE_QueueEntry * GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, uint64_t offset, - const GNUNET_HashCode * key, + const struct GNUNET_HashCode * key, enum GNUNET_BLOCK_Type type, unsigned int queue_priority, unsigned int max_queue_size, diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h index 6606acb..0de7551 100644 --- a/src/include/gnunet_dht_service.h +++ b/src/include/gnunet_dht_service.h @@ -163,10 +163,12 @@ typedef void (*GNUNET_DHT_PutContinuation)(void *cls, * (size too big) */ struct GNUNET_DHT_PutHandle * -GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const GNUNET_HashCode * key, +GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, + const struct GNUNET_HashCode * key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, - enum GNUNET_BLOCK_Type type, size_t size, const char *data, + enum GNUNET_BLOCK_Type type, + size_t size, const void *data, struct GNUNET_TIME_Absolute exp, struct GNUNET_TIME_Relative timeout, GNUNET_DHT_PutContinuation cont, @@ -205,7 +207,7 @@ GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph); */ typedef void (*GNUNET_DHT_GetIterator) (void *cls, struct GNUNET_TIME_Absolute exp, - const GNUNET_HashCode * key, + const struct GNUNET_HashCode * key, const struct GNUNET_PeerIdentity * get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity * @@ -234,14 +236,30 @@ typedef void (*GNUNET_DHT_GetIterator) (void *cls, */ struct GNUNET_DHT_GetHandle * GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, - enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key, + enum GNUNET_BLOCK_Type type, + const struct GNUNET_HashCode *key, uint32_t desired_replication_level, - enum GNUNET_DHT_RouteOption options, const void *xquery, - size_t xquery_size, GNUNET_DHT_GetIterator iter, - void *iter_cls); + enum GNUNET_DHT_RouteOption options, + const void *xquery, size_t xquery_size, + GNUNET_DHT_GetIterator iter, void *iter_cls); /** + * Tell the DHT not to return any of the following known results + * to this client. + * + * @param get_handle get operation for which results should be filtered + * @param num_results number of results to be blocked that are + * provided in this call (size of the 'results' array) + * @param results array of hash codes over the 'data' of the results + * to be blocked + */ +void +GNUNET_DHT_get_filter_known_results (struct GNUNET_DHT_GetHandle *get_handle, + unsigned int num_results, + const struct GNUNET_HashCode *results); + +/** * Stop async DHT-get. Frees associated resources. * * @param get_handle GET operation to stop. @@ -279,7 +297,7 @@ typedef void (*GNUNET_DHT_MonitorGetCB) (void *cls, uint32_t desired_replication_level, unsigned int path_length, const struct GNUNET_PeerIdentity *path, - const GNUNET_HashCode * key); + const struct GNUNET_HashCode * key); /** * Callback called on each GET reply going through the DHT. @@ -304,7 +322,7 @@ typedef void (*GNUNET_DHT_MonitorGetRespCB) (void *cls, * put_path, unsigned int put_path_length, struct GNUNET_TIME_Absolute exp, - const GNUNET_HashCode * key, + const struct GNUNET_HashCode * key, const void *data, size_t size); @@ -331,7 +349,7 @@ typedef void (*GNUNET_DHT_MonitorPutCB) (void *cls, unsigned int path_length, const struct GNUNET_PeerIdentity *path, struct GNUNET_TIME_Absolute exp, - const GNUNET_HashCode * key, + const struct GNUNET_HashCode * key, const void *data, size_t size); @@ -351,7 +369,7 @@ typedef void (*GNUNET_DHT_MonitorPutCB) (void *cls, struct GNUNET_DHT_MonitorHandle * GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle, enum GNUNET_BLOCK_Type type, - const GNUNET_HashCode *key, + const struct GNUNET_HashCode *key, GNUNET_DHT_MonitorGetCB get_cb, GNUNET_DHT_MonitorGetRespCB get_resp_cb, GNUNET_DHT_MonitorPutCB put_cb, diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h index d6ec0fe..dd42f9e 100644 --- a/src/include/gnunet_disk_lib.h +++ b/src/include/gnunet_disk_lib.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009 Christian Grothoff (and other contributing authors) + (C) 2001-2012 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 @@ -17,10 +17,10 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - /** * @file include/gnunet_disk_lib.h * @brief disk IO apis + * @author Christian Grothoff */ #ifndef GNUNET_DISK_LIB_H #define GNUNET_DISK_LIB_H @@ -36,10 +36,20 @@ */ struct GNUNET_DISK_PipeHandle; - +/** + * Type of a handle. + */ enum GNUNET_FILE_Type { - GNUNET_DISK_FILE, GNUNET_PIPE + /** + * Handle represents a file. + */ + GNUNET_DISK_HANLDE_TYPE_FILE, + + /** + * Handle represents a pipe. + */ + GNUNET_DISK_HANLDE_TYPE_PIPE }; /** @@ -75,8 +85,7 @@ struct GNUNET_DISK_FileHandle */ int fd; -#endif /* - */ +#endif }; @@ -103,39 +112,39 @@ extern "C" enum GNUNET_DISK_OpenFlags { - /** - * Open the file for reading - */ + /** + * Open the file for reading + */ GNUNET_DISK_OPEN_READ = 1, - /** - * Open the file for writing - */ + /** + * Open the file for writing + */ GNUNET_DISK_OPEN_WRITE = 2, - /** - * Open the file for both reading and writing - */ + /** + * Open the file for both reading and writing + */ GNUNET_DISK_OPEN_READWRITE = 3, - /** - * Fail if file already exists - */ + /** + * Fail if file already exists + */ GNUNET_DISK_OPEN_FAILIFEXISTS = 4, - /** - * Truncate file if it exists - */ + /** + * Truncate file if it exists + */ GNUNET_DISK_OPEN_TRUNCATE = 8, - /** - * Create file if it doesn't exist - */ + /** + * Create file if it doesn't exist + */ GNUNET_DISK_OPEN_CREATE = 16, - /** - * Append to the file - */ + /** + * Append to the file + */ GNUNET_DISK_OPEN_APPEND = 32 }; @@ -144,18 +153,19 @@ enum GNUNET_DISK_OpenFlags */ enum GNUNET_DISK_MapType { - /** - * Read-only memory map. - */ + /** + * Read-only memory map. + */ GNUNET_DISK_MAP_TYPE_READ = 1, - - /** - * Write-able memory map. - */ + + /** + * Write-able memory map. + */ GNUNET_DISK_MAP_TYPE_WRITE = 2, - /** - * Read-write memory map. - */ + + /** + * Read-write memory map. + */ GNUNET_DISK_MAP_TYPE_READWRITE = 3 }; @@ -165,77 +175,78 @@ enum GNUNET_DISK_MapType */ enum GNUNET_DISK_AccessPermissions { - /** - * Nobody is allowed to do anything to the file. - */ + /** + * Nobody is allowed to do anything to the file. + */ GNUNET_DISK_PERM_NONE = 0, - /** - * Owner can read. - */ + /** + * Owner can read. + */ GNUNET_DISK_PERM_USER_READ = 1, - /** - * Owner can write. - */ + /** + * Owner can write. + */ GNUNET_DISK_PERM_USER_WRITE = 2, - /** - * Owner can execute. - */ + /** + * Owner can execute. + */ GNUNET_DISK_PERM_USER_EXEC = 4, - /** - * Group can read. - */ + /** + * Group can read. + */ GNUNET_DISK_PERM_GROUP_READ = 8, - /** - * Group can write. - */ + /** + * Group can write. + */ GNUNET_DISK_PERM_GROUP_WRITE = 16, - /** - * Group can execute. - */ + /** + * Group can execute. + */ GNUNET_DISK_PERM_GROUP_EXEC = 32, - /** - * Everybody can read. - */ + /** + * Everybody can read. + */ GNUNET_DISK_PERM_OTHER_READ = 64, - /** - * Everybody can write. - */ + /** + * Everybody can write. + */ GNUNET_DISK_PERM_OTHER_WRITE = 128, - /** - * Everybody can execute. - */ + /** + * Everybody can execute. + */ GNUNET_DISK_PERM_OTHER_EXEC = 256 }; /** - * Constants for specifying how to seek. + * Constants for specifying how to seek. Do not change values or order, + * some of the code depends on the specific numeric values! */ enum GNUNET_DISK_Seek { - /** - * Seek an absolute position (from the start of the file). - */ - GNUNET_DISK_SEEK_SET, - - /** - * Seek a relative position (from the current offset). - */ - GNUNET_DISK_SEEK_CUR, - - /** - * Seek an absolute position from the end of the file. - */ - GNUNET_DISK_SEEK_END + /** + * Seek an absolute position (from the start of the file). + */ + GNUNET_DISK_SEEK_SET = 0, + + /** + * Seek a relative position (from the current offset). + */ + GNUNET_DISK_SEEK_CUR = 1, + + /** + * Seek an absolute position from the end of the file. + */ + GNUNET_DISK_SEEK_END = 2 }; @@ -244,14 +255,14 @@ enum GNUNET_DISK_Seek */ enum GNUNET_DISK_PipeEnd { - /** - * The reading-end of a pipe. - */ + /** + * The reading-end of a pipe. + */ GNUNET_DISK_PIPE_END_READ = 0, - /** - * The writing-end of a pipe. - */ + /** + * The writing-end of a pipe. + */ GNUNET_DISK_PIPE_END_WRITE = 1 }; @@ -290,6 +301,17 @@ GNUNET_DISK_file_test (const char *fil); /** + * Move a file out of the way (create a backup) by + * renaming it to "orig.NUM~" where NUM is the smallest + * number that is not used yet. + * + * @param fil name of the file to back up + */ +void +GNUNET_DISK_file_backup (const char *fil); + + +/** * Move the read/write pointer in a file * @param h handle of an open file * @param offset position to move to @@ -356,6 +378,19 @@ GNUNET_DISK_mktemp (const char *t); /** + * Create an (empty) temporary directory on disk. If the given name is not an + * absolute path, the current 'TMPDIR' will be prepended. In any case, 6 + * random characters will be appended to the name to create a unique name. + * + * @param t component to use for the name; + * does NOT contain "XXXXXX" or "/tmp/". + * @return NULL on error, otherwise name of freshly created directory + */ +char * +GNUNET_DISK_mkdtemp (const char *t); + + +/** * Open a file. Note that the access permissions will only be * used if a new file is created and if the underlying operating * system supports the given permissions. @@ -410,6 +445,7 @@ GNUNET_DISK_pipe (int blocking_read, int blocking_write, int inherit_read, int i struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2]); + /** * Closes an interprocess channel * @param p pipe @@ -418,6 +454,7 @@ GNUNET_DISK_pipe_from_fd (int blocking_read, int blocking_write, int fd[2]); int GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p); + /** * Closes one half of an interprocess channel * @@ -450,6 +487,17 @@ const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n); + +/** + * Get a handle from a native FD. + * + * @param fd native file descriptor + * @return file handle corresponding to the descriptor + */ +struct GNUNET_DISK_FileHandle * +GNUNET_DISK_get_handle_from_native (FILE *fd); + + /** * Read the contents of a binary file into a buffer. * @param h handle to an open file @@ -461,6 +509,7 @@ ssize_t GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, void *result, size_t len); + /** * Read the contents of a binary file into a buffer. * Guarantees not to block (returns GNUNET_SYSERR and sets errno to EAGAIN @@ -473,7 +522,8 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, void *result, */ ssize_t GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle * h, - void *result, size_t len); + void *result, size_t len); + /** * Read the contents of a binary file into a buffer. @@ -624,28 +674,30 @@ GNUNET_DISK_directory_create_for_file (const char *filename); /** - * Test if "fil" is a directory that can be accessed. - * Will not print an error message if the directory - * does not exist. Will log errors if GNUNET_SYSERR is - * returned. + * Test if "fil" is a directory and listable. Optionally, also check if the + * directory is readable. Will not print an error message if the directory does + * not exist. Will log errors if GNUNET_SYSERR is returned (i.e., a file exists + * with the same name). * * @param fil filename to test - * @return GNUNET_YES if yes, GNUNET_NO if does not exist, GNUNET_SYSERR - * on any error and if exists but not directory + * @param is_readable GNUNET_YES to additionally check if "fil" is readable; + * GNUNET_NO to disable this check + * @return GNUNET_YES if yes, GNUNET_NO if not; GNUNET_SYSERR if it + * does not exist or stat'ed */ int -GNUNET_DISK_directory_test (const char *fil); +GNUNET_DISK_directory_test (const char *fil, int is_readable); /** * Remove all files in a directory (rm -rf). Call with * caution. * - * @param fileName the file to remove + * @param filename the file to remove * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_DISK_directory_remove (const char *fileName); +GNUNET_DISK_directory_remove (const char *filename); /** diff --git a/src/include/gnunet_dnsparser_lib.h b/src/include/gnunet_dnsparser_lib.h index 28cc4c0..daeb420 100644 --- a/src/include/gnunet_dnsparser_lib.h +++ b/src/include/gnunet_dnsparser_lib.h @@ -31,6 +31,17 @@ #include "gnunet_common.h" /** + * Maximum length of a label in DNS. + */ +#define GNUNET_DNSPARSER_MAX_LABEL_LENGTH 63 + +/** + * Maximum length of a name in DNS. + */ +#define GNUNET_DNSPARSER_MAX_NAME_LENGTH 253 + + +/** * A few common DNS types. */ #define GNUNET_DNSPARSER_TYPE_A 1 @@ -41,6 +52,8 @@ #define GNUNET_DNSPARSER_TYPE_MX 15 #define GNUNET_DNSPARSER_TYPE_TXT 16 #define GNUNET_DNSPARSER_TYPE_AAAA 28 +#define GNUNET_DNSPARSER_TYPE_SRV 33 +#define GNUNET_DNSPARSER_TYPE_TLSA 52 /** * A few common DNS classes (ok, only one is common, but I list a @@ -78,6 +91,7 @@ */ struct GNUNET_DNSPARSER_Flags { +#if __BYTE_ORDER == __LITTLE_ENDIAN /** * Set to 1 if recursion is desired (client -> server) */ @@ -127,6 +141,61 @@ struct GNUNET_DNSPARSER_Flags * Set to 1 if recursion is available (server -> client) */ unsigned int recursion_available : 1 GNUNET_PACKED; +#elif __BYTE_ORDER == __BIG_ENDIAN + + /** + * query:0, response:1 + */ + unsigned int query_or_response : 1 GNUNET_PACKED; + + /** + * See GNUNET_DNSPARSER_OPCODE_ defines. + */ + unsigned int opcode : 4 GNUNET_PACKED; + + /** + * Set to 1 if this is an authoritative answer + */ + unsigned int authoritative_answer : 1 GNUNET_PACKED; + + /** + * Set to 1 if message is truncated + */ + unsigned int message_truncated : 1 GNUNET_PACKED; + + /** + * Set to 1 if recursion is desired (client -> server) + */ + unsigned int recursion_desired : 1 GNUNET_PACKED; + + + /** + * Set to 1 if recursion is available (server -> client) + */ + unsigned int recursion_available : 1 GNUNET_PACKED; + + /** + * Always zero. + */ + unsigned int zero : 1 GNUNET_PACKED; + + /** + * Response has been cryptographically verified, RFC 4035. + */ + unsigned int authenticated_data : 1 GNUNET_PACKED; + + /** + * See RFC 4035. + */ + unsigned int checking_disabled : 1 GNUNET_PACKED; + + /** + * See GNUNET_DNSPARSER_RETURN_CODE_ defines. + */ + unsigned int return_code : 4 GNUNET_PACKED; +#else + #error byteorder undefined +#endif } GNUNET_GCC_STRUCT_LAYOUT; @@ -139,6 +208,10 @@ struct GNUNET_DNSPARSER_Query /** * Name of the record that the query is for (0-terminated). + * In UTF-8 format. The library will convert from and to DNS-IDNA + * as necessary. Use 'GNUNET_DNSPARSER_check_label' to test if an + * individual label is well-formed. If a given name is not well-formed, + * creating the DNS packet will fail. */ char *name; @@ -168,11 +241,85 @@ struct GNUNET_DNSPARSER_MxRecord /** * Name of the mail server. + * In UTF-8 format. The library will convert from and to DNS-IDNA + * as necessary. Use 'GNUNET_DNSPARSER_check_label' to test if an + * individual label is well-formed. If a given name is not well-formed, + * creating the DNS packet will fail. */ char *mxhost; }; + +/** + * Information from SRV records (RFC 2782). The 'service', 'proto' + * and 'domain_name' fields together give the DNS-name which for SRV + * records is of the form "_$SERVICE._$PROTO.$DOMAIN_NAME". The DNS + * parser provides the full name in 'struct DNSPARSER_Record' and the + * individual components in the respective fields of this struct. + * When serializing, you CAN set the 'name' field of 'struct + * GNUNET_DNSPARSER_Record' to NULL, in which case the DNSPARSER code + * will populate 'name' from the 'service', 'proto' and 'domain_name' + * fields in this struct. + */ +struct GNUNET_DNSPARSER_SrvRecord +{ + + /** + * Service name without the underscore (!). Note that RFC 6335 clarifies the + * set of legal characters for service names. + * In UTF-8 format. The library will convert from and to DNS-IDNA + * as necessary. Use 'GNUNET_DNSPARSER_check_label' to test if an + * individual label is well-formed. If a given name is not well-formed, + * creating the DNS packet will fail. + */ + char *service; + + /** + * Transport protocol (typcially "tcp" or "udp", but others might be allowed). + * Without the underscore (!). + */ + char *proto; + + /** + * Domain name for which the record is valid + * In UTF-8 format. The library will convert from and to DNS-IDNA + * as necessary. Use 'GNUNET_DNSPARSER_check_label' to test if an + * individual label is well-formed. If a given name is not well-formed, + * creating the DNS packet will fail. + */ + char *domain_name; + + /** + * Hostname offering the service. + * In UTF-8 format. The library will convert from and to DNS-IDNA + * as necessary. Use 'GNUNET_DNSPARSER_check_label' to test if an + * individual label is well-formed. If a given name is not well-formed, + * creating the DNS packet will fail. + */ + char *target; + + /** + * Preference for this entry (lower value is higher preference). Clients + * will contact hosts from the lowest-priority group first and fall back + * to higher priorities if the low-priority entries are unavailable. + */ + uint16_t priority; + + /** + * Relative weight for records with the same priority. Clients will use + * the hosts of the same (lowest) priority with a probability proportional + * to the weight given. + */ + uint16_t weight; + + /** + * TCP or UDP port of the service. + */ + uint16_t port; + +}; + /** * Information from SOA records (RFC 1035). @@ -183,12 +330,20 @@ struct GNUNET_DNSPARSER_SoaRecord /** *The domainname of the name server that was the * original or primary source of data for this zone. + * In UTF-8 format. The library will convert from and to DNS-IDNA + * as necessary. Use 'GNUNET_DNSPARSER_check_label' to test if an + * individual label is well-formed. If a given name is not well-formed, + * creating the DNS packet will fail. */ char *mname; /** * A domainname which specifies the mailbox of the * person responsible for this zone. + * In UTF-8 format. The library will convert from and to DNS-IDNA + * as necessary. Use 'GNUNET_DNSPARSER_check_label' to test if an + * individual label is well-formed. If a given name is not well-formed, + * creating the DNS packet will fail. */ char *rname; @@ -249,14 +404,25 @@ struct GNUNET_DNSPARSER_Record /** * Name of the record that the query is for (0-terminated). + * In UTF-8 format. The library will convert from and to DNS-IDNA + * as necessary. Use 'GNUNET_DNSPARSER_check_label' to test if an + * individual label is well-formed. If a given name is not well-formed, + * creating the DNS packet will fail. */ char *name; + /** + * Payload of the record (which one of these is valid depends on the 'type'). + */ union { /** * For NS, CNAME and PTR records, this is the uncompressed 0-terminated hostname. + * In UTF-8 format. The library will convert from and to DNS-IDNA + * as necessary. Use 'GNUNET_DNSPARSER_check_label' to test if an + * individual label is well-formed. If a given name is not well-formed, + * creating the DNS packet will fail. */ char *hostname; @@ -271,6 +437,11 @@ struct GNUNET_DNSPARSER_Record struct GNUNET_DNSPARSER_MxRecord *mx; /** + * SRV data for SRV records. + */ + struct GNUNET_DNSPARSER_SrvRecord *srv; + + /** * Raw data for all other types. */ struct GNUNET_DNSPARSER_RawRecord raw; @@ -355,6 +526,31 @@ struct GNUNET_DNSPARSER_Packet /** + * Check if a label in UTF-8 format can be coded into valid IDNA. + * This can fail if the ASCII-conversion becomes longer than 63 characters. + * + * @param label label to check (UTF-8 string) + * @return GNUNET_OK if the label can be converted to IDNA, + * GNUNET_SYSERR if the label is not valid for DNS names + */ +int +GNUNET_DNSPARSER_check_label (const char *label); + + +/** + * Check if a hostname in UTF-8 format can be coded into valid IDNA. + * This can fail if a label becomes longer than 63 characters or if + * the entire name exceeds 253 characters. + * + * @param name name to check (UTF-8 string) + * @return GNUNET_OK if the label can be converted to IDNA, + * GNUNET_SYSERR if the label is not valid for DNS names + */ +int +GNUNET_DNSPARSER_check_name (const char *name); + + +/** * Parse a UDP payload of a DNS packet in to a nice struct for further * processing and manipulation. * diff --git a/src/include/gnunet_dnsstub_lib.h b/src/include/gnunet_dnsstub_lib.h new file mode 100644 index 0000000..0269fac --- /dev/null +++ b/src/include/gnunet_dnsstub_lib.h @@ -0,0 +1,124 @@ +/* + This file is part of GNUnet + (C) 2012 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 include/gnunet_dnsstub_lib.h + * @brief API for helper library to send DNS requests to DNS resolver + * @author Christian Grothoff + */ +#ifndef GNUNET_DNSSTUB_LIB_H +#define GNUNET_DNSSTUB_LIB_H + +#include "gnunet_common.h" +#include "gnunet_tun_lib.h" + +/** + * Opaque handle to the stub resolver. + */ +struct GNUNET_DNSSTUB_Context; + +/** + * Opaque handle to a socket doing UDP requests. + */ +struct GNUNET_DNSSTUB_RequestSocket; + + +/** + * Start a DNS stub resolver. + * + * @param dns_ip target IP address to use + * @return NULL on error + */ +struct GNUNET_DNSSTUB_Context * +GNUNET_DNSSTUB_start (const char *dns_ip); + + +/** + * Cleanup DNSSTUB resolver. + * + * @param ctx stub resolver to clean up + */ +void +GNUNET_DNSSTUB_stop (struct GNUNET_DNSSTUB_Context *ctx); + + +/** + * Function called with the result of a DNS resolution. + * + * @param cls closure + * @param rs socket that received the response + * @param dns dns response, never NULL + * @param dns_len number of bytes in 'dns' + */ +typedef void (*GNUNET_DNSSTUB_ResultCallback)(void *cls, + struct GNUNET_DNSSTUB_RequestSocket *rs, + const struct GNUNET_TUN_DnsHeader *dns, + size_t dns_len); + + +/** + * Perform DNS resolution using given address. + * + * @param ctx stub resolver to use + * @param sa the socket address + * @param sa_len the socket length + * @param request DNS request to transmit + * @param request_len number of bytes in msg + * @param rc function to call with result + * @param rc_cls closure for 'rc' + * @return socket used for the request, NULL on error + */ +struct GNUNET_DNSSTUB_RequestSocket * +GNUNET_DNSSTUB_resolve (struct GNUNET_DNSSTUB_Context *ctx, + const struct sockaddr *sa, + socklen_t sa_len, + const void *request, + size_t request_len, + GNUNET_DNSSTUB_ResultCallback rc, + void *rc_cls); + + +/** + * Perform DNS resolution using our default IP from init. + * + * @param ctx stub resolver to use + * @param request DNS request to transmit + * @param request_len number of bytes in msg + * @param rc function to call with result + * @param rc_cls closure for 'rc' + * @return socket used for the request, NULL on error + */ +struct GNUNET_DNSSTUB_RequestSocket * +GNUNET_DNSSTUB_resolve2 (struct GNUNET_DNSSTUB_Context *ctx, + const void *request, + size_t request_len, + GNUNET_DNSSTUB_ResultCallback rc, + void *rc_cls); + + +/** + * Cancel DNS resolution. + * + * @param rs resolution to cancel + */ +void +GNUNET_DNSSTUB_resolve_cancel (struct GNUNET_DNSSTUB_RequestSocket *rs); + +#endif diff --git a/src/include/gnunet_fragmentation_lib.h b/src/include/gnunet_fragmentation_lib.h index a953bd2..b022018 100644 --- a/src/include/gnunet_fragmentation_lib.h +++ b/src/include/gnunet_fragmentation_lib.h @@ -73,7 +73,9 @@ typedef void (*GNUNET_FRAGMENT_MessageProcessor) (void *cls, * @param stats statistics context * @param mtu the maximum message size for each fragment * @param tracker bandwidth tracker to use for flow control (can be NULL) - * @param delay expected delay between fragment transmission + * @param msg_delay initial delay to insert between fragment transmissions + * based on previous messages + * @param ack_delay expected delay between fragment transmission * and ACK based on previous messages * @param msg the message to fragment * @param proc function to call for each fragment to transmit @@ -84,7 +86,8 @@ struct GNUNET_FRAGMENT_Context * GNUNET_FRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, uint16_t mtu, struct GNUNET_BANDWIDTH_Tracker *tracker, - struct GNUNET_TIME_Relative delay, + struct GNUNET_TIME_Relative msg_delay, + struct GNUNET_TIME_Relative ack_delay, const struct GNUNET_MessageHeader *msg, GNUNET_FRAGMENT_MessageProcessor proc, void *proc_cls); @@ -122,11 +125,15 @@ GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc, * resources). * * @param fc fragmentation context - * @return average delay between transmission and ACK for the - * last message, FOREVER if the message was not fully transmitted + * @param msg_delay where to store average delay between individual message transmissions the + * last message (OUT only) + * @param ack_delay where to store average delay between transmission and ACK for the + * last message, set to FOREVER if the message was not fully transmitted (OUT only) */ -struct GNUNET_TIME_Relative -GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc); +void +GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc, + struct GNUNET_TIME_Relative *msg_delay, + struct GNUNET_TIME_Relative *ack_delay); /** diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index 1f1e60f..a806628 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h @@ -55,7 +55,7 @@ extern "C" * 9.0.0: CPS-style integrated API * 9.1.1: asynchronous directory scanning */ -#define GNUNET_FS_VERSION 0x00090102 +#define GNUNET_FS_VERSION 0x00090103 /* ******************** URI API *********************** */ @@ -68,6 +68,12 @@ extern "C" /** + * How often do we signal applications that a probe for a particular + * search result is running? (used to visualize probes). + */ +#define GNUNET_FS_PROBE_UPDATE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250) + +/** * A Universal Resource Identifier (URI), opaque. */ struct GNUNET_FS_Uri; @@ -91,7 +97,7 @@ typedef int (*GNUNET_FS_KeywordIterator) (void *cls, const char *keyword, * @param key wherer to store the unique key */ void -GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, GNUNET_HashCode * key); +GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, struct GNUNET_HashCode * key); /** * Convert a URI to a UTF-8 String. @@ -341,7 +347,7 @@ GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id, * @return an FS URI for the given namespace and identifier */ struct GNUNET_FS_Uri * -GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode * nsid, const char *id); +GNUNET_FS_uri_sks_create_from_nsid (struct GNUNET_HashCode * nsid, const char *id); /** @@ -354,7 +360,7 @@ GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode * nsid, const char *id); */ int GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, - GNUNET_HashCode * nsid); + struct GNUNET_HashCode * nsid); /** @@ -1018,21 +1024,32 @@ struct GNUNET_FS_ProgressInfo uint64_t data_len; /** + * How much time passed between us asking for this block and + * actually getting it? GNUNET_TIME_UNIT_FOREVER_REL if unknown. + */ + struct GNUNET_TIME_Relative block_download_duration; + + /** * Depth of the given block in the tree; * 0 would be the lowest level (DBLOCKS). */ unsigned int depth; /** - * How much trust did we offer for downloading this block? + * How much respect did we offer for downloading this block? (estimate, + * because we might have the same request pending for multiple clients, + * and of course because a transmission may have failed at a lower + * layer). */ - unsigned int trust_offered; + uint32_t respect_offered; /** - * How much time passed between us asking for this block and - * actually getting it? GNUNET_TIME_UNIT_FOREVER_REL if unknown. + * How often did we transmit the request? (estimate, + * because we might have the same request pending for multiple clients, + * and of course because a transmission may have failed at a lower + * layer). */ - struct GNUNET_TIME_Relative block_download_duration; + uint32_t num_transmissions; } progress; @@ -1258,6 +1275,11 @@ struct GNUNET_FS_ProgressInfo */ uint32_t applicability_rank; + /** + * How long has the current probe been active? + */ + struct GNUNET_TIME_Relative current_probe_time; + } update; /** @@ -1383,9 +1405,9 @@ struct GNUNET_FS_ProgressInfo /** * Hash-identifier for the namespace. */ - GNUNET_HashCode id; + struct GNUNET_HashCode id; - } namespace; + } ns; } specifics; @@ -1531,8 +1553,7 @@ struct GNUNET_FS_ProgressInfo * field in the GNUNET_FS_ProgressInfo struct. */ typedef void *(*GNUNET_FS_ProgressCallback) (void *cls, - const struct GNUNET_FS_ProgressInfo - * info); + const struct GNUNET_FS_ProgressInfo *info); /** @@ -1559,30 +1580,31 @@ enum GNUNET_FS_Flags GNUNET_FS_FLAGS_DO_PROBES = 2 }; + /** * Options specified in the VARARGs portion of GNUNET_FS_start. */ enum GNUNET_FS_OPTIONS { - /** - * Last option in the VARARG list. - */ + /** + * Last option in the VARARG list. + */ GNUNET_FS_OPTIONS_END = 0, - /** - * Select the desired amount of parallelism (this option should be - * followed by an "unsigned int" giving the desired maximum number - * of parallel downloads). - */ + /** + * Select the desired amount of parallelism (this option should be + * followed by an "unsigned int" giving the desired maximum number + * of parallel downloads). + */ GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1, - /** - * Maximum number of requests that should be pending at a given - * point in time (invidivual downloads may go above this, but - * if we are above this threshold, we should not activate any - * additional downloads. - */ + /** + * Maximum number of requests that should be pending at a given + * point in time (invidivual downloads may go above this, but + * if we are above this threshold, we should not activate any + * additional downloads. + */ GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2 }; @@ -1983,7 +2005,7 @@ enum GNUNET_FS_PublishOptions * * @param h handle to the file sharing subsystem * @param fi information about the file or directory structure to publish - * @param namespace namespace to publish the file in, NULL for no namespace + * @param ns namespace to publish the file in, NULL for no namespace * @param nid identifier to use for the publishd content in the namespace * (can be NULL, must be NULL if namespace is NULL) * @param nuid update-identifier that will be used for future updates @@ -1994,7 +2016,7 @@ enum GNUNET_FS_PublishOptions struct GNUNET_FS_PublishContext * GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, struct GNUNET_FS_FileInformation *fi, - struct GNUNET_FS_Namespace *namespace, const char *nid, + struct GNUNET_FS_Namespace *ns, const char *nid, const char *nuid, enum GNUNET_FS_PublishOptions options); @@ -2072,7 +2094,7 @@ struct GNUNET_FS_PublishSksContext; * Publish an SBlock on GNUnet. * * @param h handle to the file sharing subsystem - * @param namespace namespace to publish in + * @param ns namespace to publish in * @param identifier identifier to use * @param update update identifier to use * @param meta metadata to use @@ -2085,7 +2107,7 @@ struct GNUNET_FS_PublishSksContext; */ struct GNUNET_FS_PublishSksContext * GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, - struct GNUNET_FS_Namespace *namespace, + struct GNUNET_FS_Namespace *ns, const char *identifier, const char *update, const struct GNUNET_CONTAINER_MetaData *meta, const struct GNUNET_FS_Uri *uri, @@ -2112,7 +2134,7 @@ GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc); * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort */ typedef int (*GNUNET_FS_IndexedFileProcessor) (void *cls, const char *filename, - const GNUNET_HashCode * file_id); + const struct GNUNET_HashCode * file_id); /** @@ -2177,7 +2199,7 @@ struct GNUNET_FS_AdvertisementContext; * * @param h handle to the file sharing subsystem * @param ksk_uri keywords to use for advertisment - * @param namespace handle for the namespace that should be advertised + * @param ns handle for the namespace that should be advertised * @param meta meta-data for the namespace advertisement * @param bo block options * @param rootEntry name of the root of the namespace @@ -2188,7 +2210,7 @@ struct GNUNET_FS_AdvertisementContext; struct GNUNET_FS_AdvertisementContext * GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h, struct GNUNET_FS_Uri *ksk_uri, - struct GNUNET_FS_Namespace *namespace, + struct GNUNET_FS_Namespace *ns, const struct GNUNET_CONTAINER_MetaData *meta, const struct GNUNET_FS_BlockOptions *bo, const char *rootEntry, @@ -2211,7 +2233,7 @@ GNUNET_FS_namespace_advertise_cancel (struct GNUNET_FS_AdvertisementContext *ac) * * @param h handle to the file sharing subsystem * @param name name to use for the namespace - * @return handle to the namespace, NULL on error + * @return handle to the namespace, NULL on error (i.e. invalid filename) */ struct GNUNET_FS_Namespace * GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name); @@ -2232,14 +2254,14 @@ GNUNET_FS_namespace_dup (struct GNUNET_FS_Namespace *ns); * memory) or also to freeze the namespace to prevent further * insertions by anyone. * - * @param namespace handle to the namespace that should be deleted / freed + * @param ns handle to the namespace that should be deleted / freed * @param freeze prevents future insertions; creating a namespace * with the same name again will create a fresh namespace instead * * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace, int freeze); +GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *ns, int freeze); /** @@ -2252,7 +2274,7 @@ GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *namespace, int freeze); * @param id hash identifier for the namespace */ typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls, const char *name, - const GNUNET_HashCode * id); + const struct GNUNET_HashCode * id); /** @@ -2301,13 +2323,13 @@ typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls, const char *last_id, * cause the library to call "ip" with all children of the node. Note * that cycles within an SCC are possible (including self-loops). * - * @param namespace namespace to inspect for updateable content + * @param ns namespace to inspect for updateable content * @param next_id ID to look for; use NULL to look for SCC roots * @param ip function to call on each updateable identifier * @param ip_cls closure for ip */ void -GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *namespace, +GNUNET_FS_namespace_list_updateable (struct GNUNET_FS_Namespace *ns, const char *next_id, GNUNET_FS_IdentifierProcessor ip, void *ip_cls); diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h index 4b1873c..a22b3f3 100644 --- a/src/include/gnunet_getopt_lib.h +++ b/src/include/gnunet_getopt_lib.h @@ -232,6 +232,24 @@ GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, /** + * Set an option of type 'struct GNUNET_TIME_Relative' from the command line. + * A pointer to this function should be passed as part of the + * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options + * of this type. It should be followed by a pointer to a value of + * type 'struct GNUNET_TIME_Relative'. + * + * @param ctx command line processing context + * @param scls additional closure (will point to the 'struct GNUNET_TIME_Relative') + * @param option name of the option + * @param value actual value of the option as a string. + * @return GNUNET_OK if parsing the value worked + */ +int +GNUNET_GETOPT_set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, + void *scls, const char *option, const char *value); + + +/** * Set an option of type 'unsigned int' from the command line. * A pointer to this function should be passed as part of the * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options @@ -273,7 +291,7 @@ GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, * A pointer to this function should be passed as part of the * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options * of this type. It should be followed by a pointer to a value of - * type 'char *'. + * type 'char *', which will be allocated with the requested string. * * @param ctx command line processing context * @param scls additional closure (will point to the 'char *', @@ -315,7 +333,7 @@ GNUNET_GETOPT_increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext * @param scls additional closure (points to about text) * @param option name of the option * @param value not used (NULL) - * @return GNUNET_SYSERR (do not continue) + * @return GNUNET_NO (do not continue, not an error) */ int GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext @@ -329,7 +347,7 @@ GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext * @param scls additional closure (points to version string) * @param option name of the option * @param value not used (NULL) - * @return GNUNET_SYSERR (do not continue) + * @return GNUNET_NO (do not continue, not an error) */ int GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h index 4e040f7..8d2fde3 100644 --- a/src/include/gnunet_gns_service.h +++ b/src/include/gnunet_gns_service.h @@ -22,14 +22,7 @@ * @file include/gnunet_gns_service.h * @brief API to the GNS service * @author Martin Schanzenbach - * - * TODO: - * - decide what goes into storage API and what into GNS-service API - * - decide where to pass/expose/check keys / signatures - * - are GNS private keys per peer or per user? */ - - #ifndef GNUNET_GNS_SERVICE_H #define GNUNET_GNS_SERVICE_H @@ -47,18 +40,30 @@ extern "C" /** + * String we use to indicate the local master zone or a + * root entry in the current zone. + */ +#define GNUNET_GNS_MASTERZONE_STR "+" + +/** * Connection to the GNS service. */ struct GNUNET_GNS_Handle; /** - * Handle to control a get operation. + * Handle to control a lookup operation. + */ +struct GNUNET_GNS_LookupRequest; + +/** + * Handle to control a shorten operation. */ -struct GNUNET_GNS_LookupHandle; +struct GNUNET_GNS_ShortenRequest; /** - * Handle to control a shorten operation + * Handle to control a get authority operation */ +struct GNUNET_GNS_GetAuthRequest; /** * Record types @@ -67,21 +72,52 @@ struct GNUNET_GNS_LookupHandle; enum GNUNET_GNS_RecordType { /* Standard DNS */ - GNUNET_GNS_RECORD_TYPE_A = GNUNET_DNSPARSER_TYPE_A, - GNUNET_GNS_RECORD_TYPE_NS = GNUNET_DNSPARSER_TYPE_NS, - GNUNET_GNS_RECORD_TYPE_CNAME = GNUNET_DNSPARSER_TYPE_CNAME, - GNUNET_GNS_RECORD_TYPE_SOA = GNUNET_DNSPARSER_TYPE_SOA, - GNUNET_GNS_RECORD_TYPE_PTR = GNUNET_DNSPARSER_TYPE_PTR, - GNUNET_GNS_RECORD_MX = GNUNET_DNSPARSER_TYPE_MX, - GNUNET_GNS_RECORD_TXT = GNUNET_DNSPARSER_TYPE_TXT, - GNUNET_GNS_RECORD_AAAA = GNUNET_DNSPARSER_TYPE_AAAA, + /* struct in_addr */ + GNUNET_GNS_RECORD_A = GNUNET_DNSPARSER_TYPE_A, + + /* char */ + GNUNET_GNS_RECORD_NS = GNUNET_DNSPARSER_TYPE_NS, + + /* char */ + GNUNET_GNS_RECORD_CNAME = GNUNET_DNSPARSER_TYPE_CNAME, + + /* struct soa_data */ + GNUNET_GNS_RECORD_SOA = GNUNET_DNSPARSER_TYPE_SOA, + + /* struct srv_data */ + GNUNET_GNS_RECORD_SRV = GNUNET_DNSPARSER_TYPE_SRV, + + /* char */ + GNUNET_GNS_RECORD_PTR = GNUNET_DNSPARSER_TYPE_PTR, + + /* uint16_t, char */ + GNUNET_GNS_RECORD_MX = GNUNET_DNSPARSER_TYPE_MX, + + /* char */ + GNUNET_GNS_RECORD_TXT = GNUNET_DNSPARSER_TYPE_TXT, + + /* struct in6_addr */ + GNUNET_GNS_RECORD_AAAA = GNUNET_DNSPARSER_TYPE_AAAA, /* GNS specific */ + /* struct GNUNET_CRYPTO_ShortHashCode */ GNUNET_GNS_RECORD_PKEY = GNUNET_NAMESTORE_TYPE_PKEY, + + /* char */ GNUNET_GNS_RECORD_PSEU = GNUNET_NAMESTORE_TYPE_PSEU, - GNUNET_GNS_RECORD_ANY = GNUNET_NAMESTORE_TYPE_ANY + GNUNET_GNS_RECORD_ANY = GNUNET_NAMESTORE_TYPE_ANY, + + /* char */ + GNUNET_GNS_RECORD_LEHO = GNUNET_NAMESTORE_TYPE_LEHO, + + /* struct vpn_data */ + GNUNET_GNS_RECORD_VPN = GNUNET_NAMESTORE_TYPE_VPN, + + /* revocation */ + GNUNET_GNS_RECORD_REV = GNUNET_NAMESTORE_TYPE_REV }; + /** * Initialize the connection with the GNS service. * @@ -109,13 +145,12 @@ GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle); * lookup * * @param cls closure - * @param name "name" of the original lookup * @param rd_count number of records * @param rd the records in reply */ typedef void (*GNUNET_GNS_LookupResultProcessor) (void *cls, - uint32_t rd_count, - const struct GNUNET_NAMESTORE_RecordData *rd); + uint32_t rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd); @@ -126,17 +161,22 @@ typedef void (*GNUNET_GNS_LookupResultProcessor) (void *cls, * @param handle handle to the GNS service * @param name the name to look up * @param type the GNUNET_GNS_RecordType to look for + * @param only_cached GNUNET_NO to only check locally not DHT for performance + * @param shorten_key the private key of the shorten zone (can be NULL) * @param proc function to call on result * @param proc_cls closure for processor * * @return handle to the queued request */ -struct GNUNET_GNS_QueueEntry * +struct GNUNET_GNS_LookupRequest* GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, - const char * name, - enum GNUNET_GNS_RecordType type, - GNUNET_GNS_LookupResultProcessor proc, - void *proc_cls); + const char * name, + enum GNUNET_GNS_RecordType type, + int only_cached, + struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key, + GNUNET_GNS_LookupResultProcessor proc, + void *proc_cls); + /** * Perform an asynchronous lookup operation on the GNS @@ -146,18 +186,31 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, * @param name the name to look up * @param zone the zone to start the resolution in * @param type the GNUNET_GNS_RecordType to look for + * @param only_cached GNUNET_YES to only check locally not DHT for performance + * @param shorten_key the private key of the shorten zone (can be NULL) * @param proc function to call on result * @param proc_cls closure for processor * * @return handle to the queued request */ -struct GNUNET_GNS_QueueEntry * +struct GNUNET_GNS_LookupRequest* GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle, - const char * name, - struct GNUNET_CRYPTO_ShortHashCode *zone, - enum GNUNET_GNS_RecordType type, - GNUNET_GNS_LookupResultProcessor proc, - void *proc_cls); + const char * name, + struct GNUNET_CRYPTO_ShortHashCode *zone, + enum GNUNET_GNS_RecordType type, + int only_cached, + struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key, + GNUNET_GNS_LookupResultProcessor proc, + void *proc_cls); + + +/** + * Cancel pending lookup request + * + * @param lr the lookup request to cancel + */ +void +GNUNET_GNS_cancel_lookup_request (struct GNUNET_GNS_LookupRequest *lr); /* *************** Standard API: shorten ******************* */ @@ -167,10 +220,10 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle, * called only once * * @param cls closure - * @param short_name the shortened name or NULL if no result + * @param short_name the shortened name or NULL if no result / error */ typedef void (*GNUNET_GNS_ShortenResultProcessor) (void *cls, - const char* short_name); + const char* short_name); /** @@ -178,13 +231,17 @@ typedef void (*GNUNET_GNS_ShortenResultProcessor) (void *cls, * * @param handle handle to the GNS service * @param name the name to look up + * @param private_zone the public zone of the private zone + * @param shorten_zone the public zone of the shorten zone * @param proc function to call on result * @param proc_cls closure for processor * @return handle to the operation */ -struct GNUNET_GNS_QueueEntry * +struct GNUNET_GNS_ShortenRequest* GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle, const char * name, + struct GNUNET_CRYPTO_ShortHashCode *private_zone, + struct GNUNET_CRYPTO_ShortHashCode *shorten_zone, GNUNET_GNS_ShortenResultProcessor proc, void *proc_cls); @@ -194,17 +251,31 @@ GNUNET_GNS_shorten (struct GNUNET_GNS_Handle *handle, * * @param handle handle to the GNS service * @param name the name to look up + * @param private_zone the public zone of the private zone + * @param shorten_zone the public zone of the shorten zone * @param zone the zone to start the resolution in * @param proc function to call on result * @param proc_cls closure for processor * @return handle to the operation */ -struct GNUNET_GNS_QueueEntry * +struct GNUNET_GNS_ShortenRequest* GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle, - const char * name, - struct GNUNET_CRYPTO_ShortHashCode *zone, - GNUNET_GNS_ShortenResultProcessor proc, - void *proc_cls); + const char * name, + struct GNUNET_CRYPTO_ShortHashCode *private_zone, + struct GNUNET_CRYPTO_ShortHashCode *shorten_zone, + struct GNUNET_CRYPTO_ShortHashCode *zone, + GNUNET_GNS_ShortenResultProcessor proc, + void *proc_cls); + + +/** + * Cancel pending shorten request + * + * @param sr the lookup request to cancel + */ +void +GNUNET_GNS_cancel_shorten_request (struct GNUNET_GNS_ShortenRequest *sr); + /* *************** Standard API: get authority ******************* */ @@ -217,7 +288,7 @@ GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle, * @param auth_name the name of the auhtority or NULL */ typedef void (*GNUNET_GNS_GetAuthResultProcessor) (void *cls, - const char* short_name); + const char* short_name); /** @@ -229,11 +300,20 @@ typedef void (*GNUNET_GNS_GetAuthResultProcessor) (void *cls, * @param proc_cls closure for processor * @return handle to the operation */ -struct GNUNET_GNS_QueueEntry * +struct GNUNET_GNS_GetAuthRequest* GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle, - const char * name, - GNUNET_GNS_GetAuthResultProcessor proc, - void *proc_cls); + const char * name, + GNUNET_GNS_GetAuthResultProcessor proc, + void *proc_cls); + + +/** + * Cancel pending get auth request + * + * @param gar the lookup request to cancel + */ +void +GNUNET_GNS_cancel_get_auth_request (struct GNUNET_GNS_GetAuthRequest *gar); #if 0 /* keep Emacsens' auto-indent happy */ { diff --git a/src/include/gnunet_hello_lib.h b/src/include/gnunet_hello_lib.h index ffddb0b..7be30cf 100644 --- a/src/include/gnunet_hello_lib.h +++ b/src/include/gnunet_hello_lib.h @@ -40,6 +40,12 @@ extern "C" /** + * Prefix that every HELLO URI must start with. + */ +#define GNUNET_HELLO_URI_PREFIX "gnunet://hello/" + + +/** * An address for communicating with a peer. We frequently * need this tuple and the components cannot really be * separated. This is NOT the format that would be used @@ -331,6 +337,45 @@ GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello, struct GNUNET_MessageHeader * GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello); + +typedef struct GNUNET_TRANSPORT_PluginFunctions * +(*GNUNET_HELLO_TransportPluginsFind) (const char *name); + + +/** + * Compose a hello URI string from a hello message. + * + * @param hello Hello message + * @param plugins_find Function to find transport plugins by name + * @return Hello URI string + */ +char * +GNUNET_HELLO_compose_uri (const struct GNUNET_HELLO_Message *hello, + GNUNET_HELLO_TransportPluginsFind plugins_find); + +/** + * Parse a hello URI string to a hello message. + * + * @param uri URI string to parse + * @param pubkey Pointer to struct where public key is parsed + * @param hello Pointer to struct where hello message is parsed + * @param plugins_find Function to find transport plugins by name + * @return GNUNET_OK on success, GNUNET_SYSERR if the URI was invalid, GNUNET_NO on other errors + */ +int +GNUNET_HELLO_parse_uri (const char *uri, + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey, + struct GNUNET_HELLO_Message **hello, + GNUNET_HELLO_TransportPluginsFind plugins_find); + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + /* ifndef GNUNET_HELLO_LIB_H */ #endif /* end of gnunet_hello_lib.h */ diff --git a/src/include/gnunet_helper_lib.h b/src/include/gnunet_helper_lib.h index 9c1bc21..7f43f1a 100644 --- a/src/include/gnunet_helper_lib.h +++ b/src/include/gnunet_helper_lib.h @@ -24,6 +24,7 @@ * @author Philipp Toelke * @author Christian Grothoff */ + #ifndef GNUNET_HELPER_LIB_H #define GNUNET_HELPER_LIB_H @@ -37,24 +38,41 @@ struct GNUNET_HELPER_Handle; /** - * @brief Starts a helper and begins reading from it + * Callback that will be called when the helper process dies. This is not called + * when the helper process is stoped using GNUNET_HELPER_stop() + * + * @param cls the closure from GNUNET_HELPER_start() + */ +typedef void (*GNUNET_HELPER_ExceptionCallback) (void *cls); + + +/** + * Starts a helper and begins reading from it. The helper process is + * restarted when it dies except when it is stopped using GNUNET_HELPER_stop() + * or when the exp_cb callback is not NULL. * + * @param with_control_pipe does the helper support the use of a control pipe for signalling? * @param binary_name name of the binary to run * @param binary_argv NULL-terminated list of arguments to give when starting the binary (this * argument must not be modified by the client for * the lifetime of the helper handle) * @param cb function to call if we get messages from the helper - * @param cb_cls Closure for the callback + * @param exp_cb the exception callback to call. Set this to NULL if the helper + * process has to be restarted automatically when it dies/crashes + * @param cb_cls closure for the above callbacks * @return the new Handle, NULL on error */ struct GNUNET_HELPER_Handle * -GNUNET_HELPER_start (const char *binary_name, +GNUNET_HELPER_start (int with_control_pipe, + const char *binary_name, char *const binary_argv[], - GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls); + GNUNET_SERVER_MessageTokenizerCallback cb, + GNUNET_HELPER_ExceptionCallback exp_cb, + void *cb_cls); /** - * @brief Kills the helper, closes the pipe and frees the handle + * Kills the helper, closes the pipe and frees the handle * * @param h handle to helper to stop */ diff --git a/src/include/gnunet_lockmanager_service.h b/src/include/gnunet_lockmanager_service.h index 570cce5..23d84cd 100644 --- a/src/include/gnunet_lockmanager_service.h +++ b/src/include/gnunet_lockmanager_service.h @@ -92,7 +92,8 @@ enum GNUNET_LOCKMANAGER_Status * @param lock the lock for which this status is relevant * * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully - * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost + * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is + * lost. */ typedef void (*GNUNET_LOCKMANAGER_StatusCallback) (void *cls, @@ -142,8 +143,8 @@ GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle, /** * Function to cancel the locking request generated by - * GNUNET_LOCKMANAGER_acquire_lock. If the lock is acquired us then the lock is - * released. GNUNET_LOCKMANAGER_StatusCallback will not be called upon any + * GNUNET_LOCKMANAGER_acquire_lock. If the lock is acquired by us then the lock + * is released. GNUNET_LOCKMANAGER_StatusCallback will not be called upon any * status changes resulting due to this call. * * @param request the LockingRequest to cancel diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h index 7c2437e..4aa5947 100644 --- a/src/include/gnunet_mesh_service.h +++ b/src/include/gnunet_mesh_service.h @@ -107,6 +107,10 @@ struct GNUNET_MESH_MessageHandler /** * Method called whenever another peer has added us to a tunnel * the other peer initiated. + * Only called (once) upon reception of data with a message type which was + * subscribed to in GNUNET_MESH_connect. A call to GNUNET_MESH_tunnel_destroy + * causes te tunnel to be ignored and no further notifications are sent about + * the same tunnel. * * @param cls closure * @param tunnel new handle to the tunnel @@ -154,9 +158,6 @@ typedef uint32_t GNUNET_MESH_ApplicationType; * Connect to the mesh service. * * @param cfg configuration to use - * @param queue_size size of the data message queue, shared among all tunnels - * (each tunnel is guaranteed to accept at least one message, - * no matter what is the status of other tunnels) * @param cls closure for the various callbacks that follow * (including handlers in the handlers array) * @param new_tunnel function called when an *inbound* tunnel is created @@ -172,8 +173,7 @@ typedef uint32_t GNUNET_MESH_ApplicationType; * (in this case, init is never called) */ struct GNUNET_MESH_Handle * -GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, - unsigned int queue_size, void *cls, +GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel, GNUNET_MESH_TunnelEndHandler cleaner, const struct GNUNET_MESH_MessageHandler *handlers, @@ -223,6 +223,29 @@ typedef void (*GNUNET_MESH_PeerConnectHandler) (void *cls, GNUNET_ATS_Information * atsi); +/** + * Announce to ther peer the availability of services described by the regex, + * in order to be reachable to other peers via connect_by_string. + * + * Note that the first GNUNET_REGEX_INITIAL_BYTES characters are considered + * to be part of a prefix, (for instance 'gnunet://'). + * If you put a variable part in there (*, +. ()), all matching strings + * will be stored in the DHT. + * + * @param h Handle to mesh. + * @param regex String with the regular expression describing local services. + * @param compression_characters How many characters can be assigned to one + * edge of the graph. The bigger the variability + * of the data, the smaller this parameter should + * be (down to 1). + * For maximum compression, use strlen (regex) + * or 0 (special value). Use with care! + */ +void +GNUNET_MESH_announce_regex (struct GNUNET_MESH_Handle *h, + const char *regex, + unsigned int compression_characters); + /** * Create a new tunnel (we're initiator and will be allowed to add/remove peers @@ -251,6 +274,37 @@ GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel); /** + * Request that the tunnel data rate is limited to the speed of the slowest + * receiver. + * + * @param tunnel Tunnel affected. + */ +void +GNUNET_MESH_tunnel_speed_min (struct GNUNET_MESH_Tunnel *tunnel); + + +/** + * Request that the tunnel data rate is limited to the speed of the fastest + * receiver. This is the default behavior. + * + * @param tunnel Tunnel affected. + */ +void +GNUNET_MESH_tunnel_speed_max (struct GNUNET_MESH_Tunnel *tunnel); + + +/** + * Turn on/off the buffering status of the tunnel. + * + * @param tunnel Tunnel affected. + * @param buffer GNUNET_YES to turn buffering on (default), + * GNUNET_NO otherwise. + */ +void +GNUNET_MESH_tunnel_buffer (struct GNUNET_MESH_Tunnel *tunnel, int buffer); + + +/** * Request that a peer should be added to the tunnel. The connect handler * will be called when the peer connects * @@ -288,6 +342,45 @@ GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel, /** + * Request that the mesh should try to connect to a peer matching the + * description given in the service string. + * + * @param tunnel handle to existing tunnel + * @param description string describing the destination node requirements + */ +void +GNUNET_MESH_peer_request_connect_by_string (struct GNUNET_MESH_Tunnel *tunnel, + const char *description); + + +/** + * Request that the given peer isn't added to this tunnel in calls to + * connect_by_* calls, (due to misbehaviour, bad performance, ...). + * + * @param tunnel handle to existing tunnel. + * @param peer peer identity of the peer which should be blacklisted + * for the tunnel. + */ +void +GNUNET_MESH_peer_blacklist (struct GNUNET_MESH_Tunnel *tunnel, + const struct GNUNET_PeerIdentity *peer); + + +/** + * Request that the given peer isn't blacklisted anymore from this tunnel, + * and therefore can be added in future calls to connect_by_*. + * The peer must have been previously blacklisted for this tunnel. + * + * @param tunnel handle to existing tunnel. + * @param peer peer identity of the peer which shouldn't be blacklisted + * for the tunnel anymore. + */ +void +GNUNET_MESH_peer_unblacklist (struct GNUNET_MESH_Tunnel *tunnel, + const struct GNUNET_PeerIdentity *peer); + + +/** * Handle for a transmission request. */ struct GNUNET_MESH_TransmitHandle; @@ -296,10 +389,11 @@ struct GNUNET_MESH_TransmitHandle; /** * Ask the mesh to call "notify" once it is ready to transmit the * given number of bytes to the specified tunnel or target. + * Only one call can be active at any time, to issue another request, + * wait for the callback or cancel the current request. * * @param tunnel tunnel to use for transmission * @param cork is corking allowed for this transmission? - * @param priority how important is the message? * @param maxdelay how long can the message wait? * @param target destination for the message * NULL for multicast to all tunnel targets @@ -315,7 +409,6 @@ struct GNUNET_MESH_TransmitHandle; */ struct GNUNET_MESH_TransmitHandle * GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork, - uint32_t priority, struct GNUNET_TIME_Relative maxdelay, const struct GNUNET_PeerIdentity *target, size_t notify_size, @@ -334,13 +427,100 @@ GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle /** + * Method called to retrieve information about each tunnel the mesh peer + * is aware of. + * + * @param cls Closure. + * @param initiator Peer that started the tunnel (owner). + * @param tunnel_number Tunnel number. + * @param peers Array of peer identities that participate in the tunnel. + * @param npeers Number of peers in peers. + */ +typedef void (*GNUNET_MESH_TunnelsCB) (void *cls, + const struct GNUNET_PeerIdentity *owner, + unsigned int tunnel_number, + const struct GNUNET_PeerIdentity *peers, + unsigned int npeers); + + +/** + * Method called to retrieve information about a specific tunnel the mesh peer + * is aware of, including all transit nodes. + * + * @param cls Closure. + * @param peer Peer in the tunnel's tree. + * @param parent Parent of the current peer. All 0 when peer is root. + */ +typedef void (*GNUNET_MESH_TunnelCB) (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_PeerIdentity *parent); + + +/** + * Request information about the running mesh peer. + * The callback will be called for every tunnel known to the service, + * listing all active peers that blong to the tunnel. + * + * If called again on the same handle, it will overwrite the previous + * callback and cls. To retrieve the cls, monitor_cancel must be + * called first. + * + * WARNING: unstable API, likely to change in the future! + * + * @param h Handle to the mesh peer. + * @param callback Function to call with the requested data. + * @param callback_cls Closure for @c callback. + */ +void +GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h, + GNUNET_MESH_TunnelsCB callback, + void *callback_cls); + + +/** + * Request information about a specific tunnel of the running mesh peer. + * + * WARNING: unstable API, likely to change in the future! + * + * @param h Handle to the mesh peer. + * @param initiator ID of the owner of the tunnel. + * @param tunnel_number Tunnel number. + * @param callback Function to call with the requested data. + * @param callback_cls Closure for @c callback. + */ +void +GNUNET_MESH_show_tunnel (struct GNUNET_MESH_Handle *h, + struct GNUNET_PeerIdentity *initiator, + unsigned int tunnel_number, + GNUNET_MESH_TunnelCB callback, + void *callback_cls); + + +/** + * Cancel a monitor request. The monitor callback will not be called. + * + * WARNING: unstable API, likely to change in the future! + * + * @param h Mesh handle. + * + * @return Closure given to GNUNET_MESH_monitor, if any. + */ +void * +GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h); + + +/** * Transition API for tunnel ctx management + * + * FIXME deprecated */ void GNUNET_MESH_tunnel_set_data (struct GNUNET_MESH_Tunnel *tunnel, void *data); /** * Transition API for tunnel ctx management + * + * FIXME deprecated */ void * GNUNET_MESH_tunnel_get_data (struct GNUNET_MESH_Tunnel *tunnel); diff --git a/src/include/gnunet_namestore_plugin.h b/src/include/gnunet_namestore_plugin.h index b27867f..1168e0d 100644 --- a/src/include/gnunet_namestore_plugin.h +++ b/src/include/gnunet_namestore_plugin.h @@ -120,6 +120,7 @@ struct GNUNET_NAMESTORE_PluginFunctions * @param iter function to call with the result * @param iter_cls closure for iter * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error + * 'iter' will have been called unless the return value is 'GNUNET_SYSERR' */ int (*iterate_records) (void *cls, const struct GNUNET_CRYPTO_ShortHashCode *zone, @@ -138,6 +139,7 @@ struct GNUNET_NAMESTORE_PluginFunctions * @param iter function to call with the result * @param iter_cls closure for iter * @return GNUNET_OK on success, GNUNET_NO if there were no results, GNUNET_SYSERR on error + * 'iter' will have been called unless the return value is 'GNUNET_SYSERR' */ int (*zone_to_name) (void *cls, const struct GNUNET_CRYPTO_ShortHashCode *zone, diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index a484601..4267e20 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h @@ -25,8 +25,6 @@ * * Other functions we might want: * - enumerate all known zones - * - convenience function to gather record and the full affilliated stree - * in one shot */ #ifndef GNUNET_NAMESTORE_SERVICE_H @@ -64,6 +62,16 @@ extern "C" #define GNUNET_NAMESTORE_TYPE_LEHO 65538 /** + * Record type for VPN resolution + */ +#define GNUNET_NAMESTORE_TYPE_VPN 65539 + +/** + * Record type for zone revocation + */ +#define GNUNET_NAMESTORE_TYPE_REV 65540 + +/** * Entry in the queue. */ struct GNUNET_NAMESTORE_QueueEntry; @@ -100,10 +108,9 @@ GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); * resources). * * @param h handle to the namestore - * @param drop set to GNUNET_YES to delete all data in namestore (!) */ void -GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h, int drop); +GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h); /** @@ -149,8 +156,32 @@ enum GNUNET_NAMESTORE_RecordFlags * This record was added by the system * and is pending user confimation */ - GNUNET_NAMESTORE_RF_PENDING = 4 + GNUNET_NAMESTORE_RF_PENDING = 4, + + /** + * This expiration time of the record is a relative + * time (not an absolute time). + */ + GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION = 8, + + /** + * This record should not be used unless all (other) records with an absolute + * expiration time have expired. + */ + GNUNET_NAMESTORE_RF_SHADOW_RECORD = 16 + /** + * When comparing flags for record equality for removal, + * which flags should must match (in addition to the type, + * name, expiration value and data of the record)? All flags + * that are not listed here will be ignored for this purpose. + * (for example, we don't expect that users will remember to + * pass the '--private' option when removing a record from + * the namestore, hence we don't require this particular option + * to match upon removal). See also + * 'GNUNET_NAMESTORE_records_cmp'. + */ +#define GNUNET_NAMESTORE_RF_RCMP_FLAGS (GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION) }; @@ -162,13 +193,18 @@ struct GNUNET_NAMESTORE_RecordData /** * Binary value stored in the DNS record. + * FIXME: goofy API: sometimes 'data' is individually + * 'malloc'ed, sometimes it points into some existing + * data area (so sometimes this should be a 'void *', + * sometimes a 'const void *'). This is unclean. */ const void *data; /** - * Expiration time for the DNS record. + * Expiration time for the DNS record. Can be relative + * or absolute, depending on 'flags'. */ - struct GNUNET_TIME_Absolute expiration; + uint64_t expiration_time; /** * Number of bytes in 'data'. @@ -222,7 +258,7 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, * to validate signatures received from the network. * * @param public_key public key of the zone - * @param expire block expiration + * @param freshness time set for block expiration * @param name name that is being mapped (at most 255 characters long) * @param rd_count number of entries in 'rd' array * @param rd array of records with data to store @@ -242,6 +278,7 @@ GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinary * Store an item in the namestore. If the item is already present, * the expiration time is updated to the max of the existing time and * the new time. This API is used by the authority of a zone. + * FIXME: consider allowing to pass multiple records in one call! * * @param h handle to the namestore * @param pkey private key of the zone @@ -289,7 +326,7 @@ GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h, * * @param cls closure * @param zone_key public key of the zone - * @param expire when does the corresponding block in the DHT expire (until + * @param freshness when does the corresponding block in the DHT expire (until * when should we never do a DHT lookup for the same name again)?; * GNUNET_TIME_UNIT_ZERO_ABS if there are no records of any type in the namestore, * or the expiration time of the block in the namestore (even if there are zero @@ -311,7 +348,14 @@ typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls, /** * Get a result for a particular key from the namestore. The processor - * will only be called once. + * will only be called once. When using this functions, relative expiration + * times will be converted to absolute expiration times and a signature + * will be created if we are the authority. The record data and signature + * passed to 'proc' is thus always suitable for passing on to other peers + * (if we are the authority). If the record type is NOT set to 'ANY' and + * if we are NOT the authority, then non-matching records may be omitted + * from the result and no valid signature can be created; in this case, + * 'signature' will be NULL and the result cannot be given to other peers. * * @param h handle to the namestore * @param zone zone to look up a record from @@ -325,10 +369,10 @@ typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls, */ struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, - const struct GNUNET_CRYPTO_ShortHashCode *zone, - const char *name, - uint32_t record_type, - GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls); + const struct GNUNET_CRYPTO_ShortHashCode *zone, + const char *name, + uint32_t record_type, + GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls); /** @@ -354,9 +398,28 @@ GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, /** * Starts a new zone iteration (used to periodically PUT all of our - * records into our DHT). "proc" will be called once - * immediately, and then again after - * "GNUNET_NAMESTORE_zone_iterator_next" is invoked. + * records into our DHT). "proc" will be called once immediately, and + * then again after "GNUNET_NAMESTORE_zone_iterator_next" is invoked. + * + * By specifying a 'zone' of NULL and setting 'GNUNET_NAMESTORE_RF_AUTHORITY' + * in 'must_have_flags', we can iterate over all records for which we are + * the authority (the 'authority' flag will NOT be set in the returned + * records anyway). + * + * The 'GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION' + * bit in 'must_have_flags' has a special meaning: + * + * 0) If the bit is clear, all relative expriation times are converted to + * absolute expiration times. This is useful for performing DHT PUT + * operations (and zone transfers) of our zone. The generated signatures + * will be valid for other peers. + * 1) if it is set, it means that relative expiration times should be + * preserved when returned (this is useful for the zone editor user + * interface). No signatures will be created in this case, as + * signatures must not cover records with relative expiration times. + * + * Note that not all queries against this interface are equally performant + * as for some combinations no efficient index may exist. * * @param h handle to the namestore * @param zone zone to access, NULL for all zones @@ -388,7 +451,9 @@ GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it); /** - * Stops iteration and releases the namestore handle for further calls. + * Stops iteration and releases the namestore handle for further calls. Must + * be called on any iteration that has not yet completed prior to calling + * 'GNUNET_NAMESTORE_disconnect'. * * @param it the iterator */ @@ -398,7 +463,9 @@ GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it); /** * Cancel a namestore operation. The final callback from the - * operation must not have been done yet. + * operation must not have been done yet. Must be called on any + * namestore operation that has not yet completed prior to calling + * 'GNUNET_NAMESTORE_disconnect'. * * @param qe operation to cancel */ @@ -423,6 +490,7 @@ size_t GNUNET_NAMESTORE_records_get_size (unsigned int rd_count, const struct GNUNET_NAMESTORE_RecordData *rd); + /** * Serialize the given records to the given destination buffer. * @@ -431,7 +499,7 @@ GNUNET_NAMESTORE_records_get_size (unsigned int rd_count, * @param dest_size size of the destination array * @param dest where to write the result * - * @return the size of serialized records + * @return the size of serialized records, -1 if records do not fit */ ssize_t GNUNET_NAMESTORE_records_serialize (unsigned int rd_count, @@ -458,15 +526,6 @@ GNUNET_NAMESTORE_records_deserialize (size_t len, /** - * Checks if a name is wellformed - * - * @param name the name to check - * @return GNUNET_OK on success, GNUNET_SYSERR on error - */ -int -GNUNET_NAMESTORE_check_name (const char * name); - -/** * Convert the 'value' of a record to a string. * * @param type type of the record @@ -517,6 +576,16 @@ const char * GNUNET_NAMESTORE_number_to_typename (uint32_t type); +/** + * Test if a given record is expired. + * + * @return GNUNET_YES if the record is expired, + * GNUNET_NO if not + */ +int +GNUNET_NAMESTORE_is_expired (const struct GNUNET_NAMESTORE_RecordData *rd); + + #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/include/gnunet_nat_lib.h b/src/include/gnunet_nat_lib.h index 3a1e9a6..93b4418 100644 --- a/src/include/gnunet_nat_lib.h +++ b/src/include/gnunet_nat_lib.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2007, 2008, 2009, 2010, 2011 Christian Grothoff (and other contributing authors) + (C) 2007, 2008, 2009, 2010, 2011, 2012 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 @@ -254,6 +254,46 @@ void GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini); +/** + * Handle to auto-configuration in progress. + */ +struct GNUNET_NAT_AutoHandle; + + +/** + * Function called with the result from the autoconfiguration. + * + * @param cls closure + * @param diff minimal suggested changes to the original configuration + * to make it work (as best as we can) + */ +typedef void (*GNUNET_NAT_AutoResultCallback)(void *cls, + const struct GNUNET_CONFIGURATION_Handle *diff); + + +/** + * Start auto-configuration routine. The resolver service should + * be available when this function is called. + * + * @param cfg initial configuration + * @param cb function to call with autoconfiguration result + * @param cb_cls closure for cb + * @return handle to cancel operation + */ +struct GNUNET_NAT_AutoHandle * +GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_NAT_AutoResultCallback cb, + void *cb_cls); + + +/** + * Abort autoconfiguration. + * + * @param ah handle for operation to abort + */ +void +GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah); + #endif /* end of gnunet_nat_lib.h */ diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h index 085845a..1ff397e 100644 --- a/src/include/gnunet_network_lib.h +++ b/src/include/gnunet_network_lib.h @@ -67,11 +67,32 @@ struct GNUNET_NETWORK_FDSet }; - - +#include "platform.h" #include "gnunet_disk_lib.h" #include "gnunet_time_lib.h" +/** + * Test if the given protocol family is supported by this system. + * + * @param pf protocol family to test (PF_INET, PF_INET6, PF_UNIX) + * @return GNUNET_OK if the PF is supported + */ +int +GNUNET_NETWORK_test_pf (int pf); + + +/** + * Given a unixpath that is too long (larger than UNIX_PATH_MAX), + * shorten it to an acceptable length while keeping it unique + * and making sure it remains a valid filename (if possible). + * + * @param unixpath long path, will be freed (or same pointer returned + * with moved 0-termination). + * @return shortened unixpath, NULL on error + */ +char * +GNUNET_NETWORK_shorten_unixpath (char *unixpath); + /** * Accept a new connection on a socket. Configure it for non-blocking @@ -100,6 +121,18 @@ GNUNET_NETWORK_socket_box_native (SOCKTYPE fd); /** + * Set if a socket should use blocking or non-blocking IO. + * + * @param fd socket + * @param doBlock blocking mode + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, + int doBlock); + + +/** * Bind to a connected socket * * @param desc socket to bind @@ -185,7 +218,7 @@ GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle ssize_t GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length, - struct sockaddr *src_addr, socklen_t * addrlen); + struct sockaddr *src_addr, socklen_t *addrlen); /** diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h index 67b6cce..e4bbab8 100644 --- a/src/include/gnunet_os_lib.h +++ b/src/include/gnunet_os_lib.h @@ -54,6 +54,51 @@ extern "C" #include "gnunet_configuration_lib.h" #include "gnunet_scheduler_lib.h" + +/** + * Flags that determine which of the standard streams + * should be inherited by the child process. + */ +enum GNUNET_OS_InheritStdioFlags +{ + + /** + * No standard streams should be inherited. + */ + GNUNET_OS_INHERIT_STD_NONE = 0, + + /** + * When this flag is set, the child process will + * inherit stdin of the parent. + */ + GNUNET_OS_INHERIT_STD_IN = 1, + + /** + * When this flag is set, the child process will + * inherit stdout of the parent. + */ + GNUNET_OS_INHERIT_STD_OUT = 2, + + /** + * When this flag is set, the child process will + * inherit stderr of the parent. + */ + GNUNET_OS_INHERIT_STD_ERR = 4, + + /** + * When these flags are set, the child process will + * inherit stdout and stderr of the parent. + */ + GNUNET_OS_INHERIT_STD_OUT_AND_ERR = 6, + + /** + * Use this option to have all of the standard streams + * (stdin, stdout and stderror) be inherited. + */ + GNUNET_OS_INHERIT_STD_ALL = 7 +}; + + /** * Process information (OS-dependent) */ @@ -106,7 +151,12 @@ enum GNUNET_OS_InstallationPathKind * Return the prefix of the path with documentation files, including the * license (share/doc/gnunet/). */ - GNUNET_OS_IPK_DOCDIR + GNUNET_OS_IPK_DOCDIR, + + /** + * Return the directory where helper binaries are installed (lib/gnunet/libexec/) + */ + GNUNET_OS_IPK_LIBEXECDIR }; @@ -156,6 +206,18 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind); /** + * Given the name of a gnunet-helper, gnunet-service or gnunet-daemon + * binary, try to prefix it with the libexec/-directory to get the + * full path. + * + * @param progname name of the binary + * @return full path to the binary, if possible, otherwise copy of 'progname' + */ +char * +GNUNET_OS_get_libexec_binary_path (const char *progname); + + +/** * Callback function invoked for each interface found. * * @param cls closure @@ -257,6 +319,7 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, * Start a process. * * @param pipe_control should a pipe be used to send signals to the child? + * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags * @param pipe_stdin pipe to use to send input to child process (or NULL) * @param pipe_stdout pipe to use to get output from child process (or NULL) * @param filename name of the binary @@ -265,6 +328,7 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, */ struct GNUNET_OS_Process * GNUNET_OS_start_process_vap (int pipe_control, + enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, @@ -275,6 +339,7 @@ GNUNET_OS_start_process_vap (int pipe_control, * Start a process. * * @param pipe_control should a pipe be used to send signals to the child? + * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags * @param pipe_stdin pipe to use to send input to child process (or NULL) * @param pipe_stdout pipe to use to get output from child process (or NULL) * @param filename name of the binary @@ -283,6 +348,7 @@ GNUNET_OS_start_process_vap (int pipe_control, */ struct GNUNET_OS_Process * GNUNET_OS_start_process (int pipe_control, + enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, ...); @@ -292,6 +358,7 @@ GNUNET_OS_start_process (int pipe_control, * Start a process. * * @param pipe_control should a pipe be used to send signals to the child? + * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags * @param pipe_stdin pipe to use to send input to child process (or NULL) * @param pipe_stdout pipe to use to get output from child process (or NULL) * @param filename name of the binary @@ -300,6 +367,7 @@ GNUNET_OS_start_process (int pipe_control, */ struct GNUNET_OS_Process * GNUNET_OS_start_process_va (int pipe_control, + enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, va_list va); @@ -308,6 +376,7 @@ GNUNET_OS_start_process_va (int pipe_control, * Start a process. * * @param pipe_control should a pipe be used to send signals to the child? + * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags * @param lsocks array of listen sockets to dup systemd-style (or NULL); * must be NULL on platforms where dup is not supported * @param filename name of the binary @@ -317,6 +386,7 @@ GNUNET_OS_start_process_va (int pipe_control, */ struct GNUNET_OS_Process * GNUNET_OS_start_process_v (int pipe_control, + enum GNUNET_OS_InheritStdioFlags std_inheritance, const SOCKTYPE *lsocks, const char *filename, char *const argv[]); diff --git a/src/include/gnunet_peer_lib.h b/src/include/gnunet_peer_lib.h index 0121e84..6f5dee8 100644 --- a/src/include/gnunet_peer_lib.h +++ b/src/include/gnunet_peer_lib.h @@ -98,6 +98,24 @@ void GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid); +/** + * Convert an interned PID to a normal peer identity. + * + * @param id interned PID to convert + * @return pointer to peer identity, valid as long 'id' is valid + */ +const struct GNUNET_PeerIdentity * +GNUNET_PEER_resolve2 (GNUNET_PEER_Id id); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + /* ifndef GNUNET_PEER_LIB_H */ #endif /* end of gnunet_peer_lib.h */ diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index b655f08..2ccc3e5 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -483,6 +483,16 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP 139 +/** + * P2P request for content (one FS to another via a stream). + */ +#define GNUNET_MESSAGE_TYPE_FS_STREAM_QUERY 140 + +/** + * P2P answer for content (one FS to another via a stream). + */ +#define GNUNET_MESSAGE_TYPE_FS_STREAM_REPLY 141 + /******************************************************************************* * DHT message types @@ -558,6 +568,11 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT_OK 155 +/** + * Certain results are already known to the client, filter those. + */ +#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN 156 + /******************************************************************************* * HOSTLIST message types @@ -791,9 +806,14 @@ extern "C" #define GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY 266 /** - * We need flow control + * ACK for a data packet. + */ +#define GNUNET_MESSAGE_TYPE_MESH_ACK 267 + +/** + * Poll for an ACK. */ -#define GNUNET_MESSAGE_TYPE_MESH_SPEED_NOTIFY 270 +#define GNUNET_MESSAGE_TYPE_MESH_POLL 268 /** * Connect to the mesh service, specifying subscriptions @@ -826,9 +846,64 @@ extern "C" #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE 277 /** + * Ask the mesh service to add a peer described by a service string + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_ANNOUNCE_REGEX 278 + +/** + * Ask the mesh service to add a peer described by a service string + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_STRING 279 + +/** + * Ask the mesh service to add a peer to the blacklist of an existing tunnel + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_BLACKLIST 280 + +/** + * Ask the mesh service to remove a peer from the blacklist of a tunnel + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_UNBLACKLIST 281 + +/** + * Set tunnel speed to slowest peer + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MIN 282 + +/** + * Set tunnel speed to fastest peer + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MAX 283 + +/** + * Set tunnel buffering on. + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_BUFFER 284 + +/** + * Set tunnel buffering off. + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_NOBUFFER 285 + +/** + * Local ACK for data. + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK 286 + +/** + * Local information about all tunnels of service. + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS 287 + +/** + * Local information of service about a specific tunnel. + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL 288 + +/** * 640kb should be enough for everybody */ -#define GNUNET_MESSAGE_TYPE_MESH_RESERVE_END 288 +#define GNUNET_MESSAGE_TYPE_MESH_RESERVE_END 299 @@ -1034,6 +1109,23 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_ATS_RESET_BACKOFF 352 +/** + * Type of the 'struct AddressUpdateMessage' sent by client to ATS + * to add a new address + */ +#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD 353 + +/** + * Type of the 'struct AddressListRequestMessage' sent by client to ATS + * to request information about addresses + */ +#define GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST 354 + +/** + * Type of the 'struct AddressListResponseMessage' sent by ATS to client + * with information about addresses + */ +#define GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE 355 /******************************************************************************* * TRANSPORT message types @@ -1176,8 +1268,13 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON 384 +/** + * Message containing traffic metrics for transport service + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC 385 + /******************************************************************************* - * STREAM LIRBRARY MESSAGES + * STREAM messages types ******************************************************************************/ /** @@ -1276,15 +1373,87 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED 426 + /******************************************************************************* * NAMESTORE message types ******************************************************************************/ /** - * Request update and listing of a peer. + * Client to service: register. */ #define GNUNET_MESSAGE_TYPE_NAMESTORE_START 430 +/** + * Client to service: lookup name + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME 431 + +/** + * Service to client: result of name lookup + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE 432 + +/** + * Client to service: put records (for caching) + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT 433 + +/** + * Service to client: result of put operation. + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE 434 + +/** + * Client to service: create record as authority + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE 435 + +/** + * Service to client: result of record creation request + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE 436 + +/** + * Client to service: remove record(s) + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE 437 + +/** + * Service to client: result of removal request. + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE 438 + +/** + * Client to service: "reverse" lookup for zone name based on zone key + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME 439 + +/** + * Service to client: result of zone-to-name lookup. + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE 440 + +/** + * Client to service: please start iteration + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START 445 + +/** + * Service to client: current record in iteration (or end of list). + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE 446 + +/** + * Client to service: next record in iteration please. + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT 447 + +/** + * Client to service: stop iterating. + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP 448 + + /******************************************************************************* * LOCKMANAGER message types ******************************************************************************/ @@ -1292,21 +1461,238 @@ extern "C" /** * Message to acquire Lock */ -#define GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE 440 +#define GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE 450 /** * Message to release lock */ -#define GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE 441 +#define GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE 451 /** * SUCESS reply from lockmanager */ -#define GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS 442 +#define GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS 452 + +/******************************************************************************* + * TESTBED message types + ******************************************************************************/ + +/** + * Initial message from a client to a testing control service + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_INIT 460 + +/** + * Message to add host + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST 461 + +/** + * Message to signal that a add host succeeded + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS 462 + +/** + * Message to configure a service to be shared among peers + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_SHARE_SERVICE 463 /** - * Next available: 450 + * Message to link delegated controller to slave controller */ +#define GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS 464 + +/** + * Message to create a peer at a host + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER 465 + +/** + * Message to reconfigure a peer + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_RECONFIGURE_PEER 466 + +/** + * Message to start a peer at a host + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_START_PEER 467 + +/** + * Message to stop a peer at a host + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER 468 + +/** + * Message to destroy a peer + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_DESTROY_PEER 469 + +/** + * Configure underlay link message + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_CONFIGURE_UNDERLAY_LINK 470 + +/** + * Message to connect peers in a overlay + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_OVERLAY_CONNECT 471 + +/** + * Message for peer events + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT 472 + +/** + * Message for peer connect events + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT 473 + +/** + * Message for operation events + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT 474 + +/** + * Message to signal successful peer creation + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS 475 + +/** + * Message to signal a generic operation has been successful + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS 476 + +/** + * Message to get the configuration of a peer + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_CONFIGURATION 477 + +/** + * Message containing the peer configuration + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONFIGURATION 478 + +/** + * Message to request a controller to make one of its peer to connect to another + * peer using the contained HELLO + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_REMOTE_OVERLAY_CONNECT 479 + +/** + * Message to request configuration of a slave controller + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_GET_SLAVE_CONFIGURATION 480 + +/** + * Message which contains the configuration of slave controller + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION 481 + +/** + * Not really a message, but for careful checks on the testbed messages; Should + * always be the maximum and never be used to send messages with this type + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_MAX 482 + +/** + * The initialization message towards gnunet-testbed-helper + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT 495 + +/** + * The reply message from gnunet-testbed-helper + */ +#define GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY 496 + + +/** + * GNS. FIXME: document! + */ +#define GNUNET_MESSAGE_TYPE_GNS_LOOKUP 500 + +#define GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT 501 + +#define GNUNET_MESSAGE_TYPE_GNS_SHORTEN 502 + +#define GNUNET_MESSAGE_TYPE_GNS_SHORTEN_RESULT 503 + +#define GNUNET_MESSAGE_TYPE_GNS_GET_AUTH 504 + +#define GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT 505 + + +/******************************************************************************* + * CONSENSUS message types + ******************************************************************************/ + +/** + * Join a consensus session. Sent by client to service as first message. + */ +#define GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN 520 + +/** + * Insert an element. Sent by client to service. + */ +#define GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_INSERT 521 + +/** + * Begin accepting new elements from other participants. + * Sent by client to service. + */ +#define GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_BEGIN 522 + +/** + * Sent by service when a new element is added. + */ +#define GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_RECEIVED_ELEMENT 523 + +/** + * Sent by client to service in order to start the consensus conclusion. + */ +#define GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE 524 + +/** + * Sent by service to client in order to signal a completed consensus conclusion. + * Last message sent in a consensus session. + */ +#define GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_CONCLUDE_DONE 525 + + +/* message types 526-539 reserved for consensus client/service messages */ + + + +/** + * Sent by client to service, telling whether a received element should + * be accepted and propagated further or not. + */ +#define GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_ACK 540 + +/** + * Strata estimator. + */ +#define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_DELTA_ESTIMATE 541 + +/** + * IBF containing all elements of a peer. + */ +#define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_DIFFERENCE_DIGEST 542 + +/** + * Elements, and requests for further elements + */ +#define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_ELEMENTS 543 + +/* + * Initialization message for consensus p2p communication. + */ +#define GNUNET_MESSAGE_TYPE_CONSENSUS_P2P_HELLO 544 + + +/** + * Next available: 570 + */ + /******************************************************************************* * TODO: we need a way to register message types centrally (via some webpage). diff --git a/src/include/gnunet_pseudonym_lib.h b/src/include/gnunet_pseudonym_lib.h index 8fd938d..6ec51b6 100644 --- a/src/include/gnunet_pseudonym_lib.h +++ b/src/include/gnunet_pseudonym_lib.h @@ -51,7 +51,7 @@ extern "C" * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort */ typedef int (*GNUNET_PSEUDONYM_Iterator) (void *cls, - const GNUNET_HashCode * pseudonym, + const struct GNUNET_HashCode * pseudonym, const char *name, const char *unique_name, const struct GNUNET_CONTAINER_MetaData @@ -67,7 +67,7 @@ typedef int (*GNUNET_PSEUDONYM_Iterator) (void *cls, */ int GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg, - const GNUNET_HashCode * nsid, int delta); + const struct GNUNET_HashCode * nsid, int delta); /** * Add a pseudonym to the set of known pseudonyms. @@ -80,7 +80,7 @@ GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg, */ void GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg, - const GNUNET_HashCode * id, + const struct GNUNET_HashCode * id, const struct GNUNET_CONTAINER_MetaData *meta); @@ -127,7 +127,7 @@ GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator */ char * GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg, - const GNUNET_HashCode * nsid, const char *name, unsigned int *suffix); + const struct GNUNET_HashCode * nsid, const char *name, unsigned int *suffix); /** * Get namespace name, metadata and rank @@ -152,7 +152,7 @@ GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg, */ int GNUNET_PSEUDONYM_get_info (const struct GNUNET_CONFIGURATION_Handle *cfg, - const GNUNET_HashCode * nsid, struct GNUNET_CONTAINER_MetaData **ret_meta, + const struct GNUNET_HashCode * nsid, struct GNUNET_CONTAINER_MetaData **ret_meta, int32_t *ret_rank, char **ret_name, int *name_is_a_dup); @@ -166,7 +166,7 @@ GNUNET_PSEUDONYM_get_info (const struct GNUNET_CONFIGURATION_Handle *cfg, */ int GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *ns_uname, GNUNET_HashCode * nsid); + const char *ns_uname, struct GNUNET_HashCode * nsid); /** * Set the pseudonym metadata, rank and name. @@ -182,7 +182,7 @@ GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg, */ int GNUNET_PSEUDONYM_set_info (const struct GNUNET_CONFIGURATION_Handle *cfg, - const GNUNET_HashCode * nsid, const char *name, + const struct GNUNET_HashCode * nsid, const char *name, const struct GNUNET_CONTAINER_MetaData *md, int rank); diff --git a/src/include/gnunet_regex_lib.h b/src/include/gnunet_regex_lib.h index aec37c1..ebeb9e5 100644 --- a/src/include/gnunet_regex_lib.h +++ b/src/include/gnunet_regex_lib.h @@ -28,6 +28,8 @@ #define GNUNET_REGEX_LIB_H #include "gnunet_util_lib.h" +#include "gnunet_dht_service.h" +#include "gnunet_statistics_service.h" #ifdef __cplusplus extern "C" @@ -37,48 +39,69 @@ extern "C" #endif #endif + +/** + * Constant for how many bytes the initial string regex should have. + */ +#define GNUNET_REGEX_INITIAL_BYTES 24 + + +/** + * Maximum regex string length for use with GNUNET_REGEX_ipv4toregex + */ +#define GNUNET_REGEX_IPV4_REGEXLEN 32 + 6 + + +/** + * Maximum regex string length for use with GNUNET_REGEX_ipv6toregex + */ +#define GNUNET_REGEX_IPV6_REGEXLEN 128 + 6 + + /** * Automaton (NFA/DFA) representation. */ struct GNUNET_REGEX_Automaton; + /** * Edge representation. */ struct GNUNET_REGEX_Edge { /** - * Label of the edge. + * Label of the edge. FIXME: might want to not consume exactly multiples of 8 bits, need length? */ const char *label; /** * Destionation of the edge. */ - GNUNET_HashCode destination; + struct GNUNET_HashCode destination; }; -/** - * Construct an NFA by parsing the regex string of length 'len'. - * - * @param regex regular expression string. - * @param len length of the string. - * - * @return NFA, needs to be freed using GNUNET_REGEX_destroy_automaton. - */ -struct GNUNET_REGEX_Automaton * -GNUNET_REGEX_construct_nfa (const char *regex, const size_t len); /** * Construct DFA for the given 'regex' of length 'len'. * + * Path compression means, that for example a DFA o -> a -> b -> c -> o will be + * compressed to o -> abc -> o. Note that this parameter influences the + * non-determinism of states of the resulting NFA in the DHT (number of outgoing + * edges with the same label). For example for an application that stores IPv4 + * addresses as bitstrings it could make sense to limit the path compression to + * 4 or 8. + * * @param regex regular expression string. * @param len length of the regular expression. - * - * @return DFA, needs to be freed using GNUNET_REGEX_destroy_automaton. + * @param max_path_len limit the path compression length to the + * given value. If set to 1, no path compression is applied. Set to 0 for + * maximal possible path compression (generally not desireable). + * @return DFA, needs to be freed using GNUNET_REGEX_automaton_destroy. */ struct GNUNET_REGEX_Automaton * -GNUNET_REGEX_construct_dfa (const char *regex, const size_t len); +GNUNET_REGEX_construct_dfa (const char *regex, const size_t len, + unsigned int max_path_len); + /** * Free the memory allocated by constructing the GNUNET_REGEX_Automaton. @@ -89,15 +112,44 @@ GNUNET_REGEX_construct_dfa (const char *regex, const size_t len); void GNUNET_REGEX_automaton_destroy (struct GNUNET_REGEX_Automaton *a); + +/** + * Options for graph creation function + * GNUNET_REGEX_automaton_save_graph. + */ +enum GNUNET_REGEX_GraphSavingOptions +{ + /** + * Default. Do nothing special. + */ + GNUNET_REGEX_GRAPH_DEFAULT = 0, + + /** + * The generated graph will include extra information such as the NFA states + * that were used to generate the DFA state. + */ + GNUNET_REGEX_GRAPH_VERBOSE = 1, + + /** + * Enable graph coloring. Will color each SCC in a different color. + */ + GNUNET_REGEX_GRAPH_COLORING = 2 +}; + + /** * Save the given automaton as a GraphViz dot file. * * @param a the automaton to be saved. * @param filename where to save the file. + * @param options options for graph generation that include coloring or verbose + * mode */ void GNUNET_REGEX_automaton_save_graph (struct GNUNET_REGEX_Automaton *a, - const char *filename); + const char *filename, + enum GNUNET_REGEX_GraphSavingOptions options); + /** * Evaluates the given 'string' against the given compiled regex. @@ -111,9 +163,10 @@ int GNUNET_REGEX_eval (struct GNUNET_REGEX_Automaton *a, const char *string); + /** * Get the first key for the given 'input_string'. This hashes - * the first x bits of the 'input_strings'. + * the first x bits of the 'input_string'. * * @param input_string string. * @param string_len length of the 'input_string'. @@ -122,21 +175,23 @@ GNUNET_REGEX_eval (struct GNUNET_REGEX_Automaton *a, * @return number of bits of 'input_string' that have been consumed * to construct the key */ -unsigned int -GNUNET_REGEX_get_first_key (const char *input_string, unsigned int string_len, - GNUNET_HashCode * key); +size_t +GNUNET_REGEX_get_first_key (const char *input_string, size_t string_len, + struct GNUNET_HashCode * key); + /** * Check if the given 'proof' matches the given 'key'. * - * @param proof partial regex - * @param key hash + * @param proof partial regex of a state. + * @param key hash of a state. * - * @return GNUNET_OK if the proof is valid for the given key + * @return GNUNET_OK if the proof is valid for the given key. */ int GNUNET_REGEX_check_proof (const char *proof, - const GNUNET_HashCode *key); + const struct GNUNET_HashCode *key); + /** * Iterator callback function. @@ -149,12 +204,13 @@ GNUNET_REGEX_check_proof (const char *proof, * @param edges edges leaving current state. */ typedef void (*GNUNET_REGEX_KeyIterator)(void *cls, - const GNUNET_HashCode *key, + const struct GNUNET_HashCode *key, const char *proof, int accepting, unsigned int num_edges, const struct GNUNET_REGEX_Edge *edges); + /** * Iterate over all edges starting from start state of automaton 'a'. Calling * iterator for each edge. @@ -168,6 +224,133 @@ GNUNET_REGEX_iterate_all_edges (struct GNUNET_REGEX_Automaton *a, GNUNET_REGEX_KeyIterator iterator, void *iterator_cls); + +/** + * Create a regex in 'rxstr' from the given 'ip' and 'netmask'. + * + * @param ip IPv4 representation. + * @param netmask netmask for the ip. + * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV4_REGEXLEN + * bytes long. + */ +void +GNUNET_REGEX_ipv4toregex (const struct in_addr *ip, const char *netmask, + char *rxstr); + + +/** + * Create a regex in 'rxstr' from the given 'ipv6' and 'prefixlen'. + * + * @param ipv6 IPv6 representation. + * @param prefixlen length of the ipv6 prefix. + * @param rxstr generated regex, must be at least GNUNET_REGEX_IPV6_REGEXLEN + * bytes long. + */ +void +GNUNET_REGEX_ipv6toregex (const struct in6_addr *ipv6, + unsigned int prefixlen, char *rxstr); + + + +/** + * Handle to store cached data about a regex announce. + */ +struct GNUNET_REGEX_announce_handle; + +/** + * Handle to store data about a regex search. + */ +struct GNUNET_REGEX_search_handle; + +/** + * Announce a regular expression: put all states of the automaton in the DHT. + * Does not free resources, must call GNUNET_REGEX_announce_cancel for that. + * + * @param dht An existing and valid DHT service handle. + * @param id ID to announce as provider of regex. Own ID in most cases. + * @param regex Regular expression to announce. + * @param compression How many characters per edge can we squeeze? + * @param stats Optional statistics handle to report usage. Can be NULL. + * + * @return Handle to reuse o free cached resources. + * Must be freed by calling GNUNET_REGEX_announce_cancel. + */ +struct GNUNET_REGEX_announce_handle * +GNUNET_REGEX_announce (struct GNUNET_DHT_Handle *dht, + struct GNUNET_PeerIdentity *id, + const char *regex, + uint16_t compression, + struct GNUNET_STATISTICS_Handle *stats); + +/** + * Announce again a regular expression previously announced. + * Does use caching to speed up process. + * + * @param h Handle returned by a previous GNUNET_REGEX_announce call. + */ +void +GNUNET_REGEX_reannounce (struct GNUNET_REGEX_announce_handle *h); + + +/** + * Clear all cached data used by a regex announce. + * Does not close DHT connection. + * + * @param h Handle returned by a previous GNUNET_REGEX_announce call. + */ +void +GNUNET_REGEX_announce_cancel (struct GNUNET_REGEX_announce_handle *h); + + +/** + * Search callback function. + * + * @param cls Closure provided in GNUNET_REGEX_search. + * @param id Peer providing a regex that matches the string. + * @param get_path Path of the get request. + * @param get_path_length Lenght of get_path. + * @param put_path Path of the put request. + * @param put_path_length Length of the put_path. + */ +typedef void (*GNUNET_REGEX_Found)(void *cls, + const struct GNUNET_PeerIdentity *id, + const struct GNUNET_PeerIdentity *get_path, + unsigned int get_path_length, + const struct GNUNET_PeerIdentity *put_path, + unsigned int put_path_length); + + +/** + * Search for a peer offering a regex matching certain string in the DHT. + * The search runs until GNUNET_REGEX_search_cancel is called, even if results + * are returned. + * + * @param dht An existing and valid DHT service handle. + * @param string String to match against the regexes in the DHT. + * @param callback Callback for found peers. + * @param callback_cls Closure for @c callback. + * @param stats Optional statistics handle to report usage. Can be NULL. + * + * @return Handle to stop search and free resources. + * Must be freed by calling GNUNET_REGEX_search_cancel. + */ +struct GNUNET_REGEX_search_handle * +GNUNET_REGEX_search (struct GNUNET_DHT_Handle *dht, + const char *string, + GNUNET_REGEX_Found callback, + void *callback_cls, + struct GNUNET_STATISTICS_Handle *stats); + +/** + * Stop search and free all data used by a GNUNET_REGEX_search call. + * Does not close DHT connection. + * + * @param h Handle returned by a previous GNUNET_REGEX_search call. + */ +void +GNUNET_REGEX_search_cancel (struct GNUNET_REGEX_search_handle *h); + + #if 0 /* keep Emacsens' auto-indent happy */ { #endif @@ -177,4 +360,3 @@ GNUNET_REGEX_iterate_all_edges (struct GNUNET_REGEX_Automaton *a, /* end of gnunet_regex_lib.h */ #endif - diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h index 4727534..1e2a400 100644 --- a/src/include/gnunet_scheduler_lib.h +++ b/src/include/gnunet_scheduler_lib.h @@ -212,6 +212,8 @@ typedef int (*GNUNET_SCHEDULER_select) (void *cls, struct GNUNET_NETWORK_FDSet * wfds, struct GNUNET_NETWORK_FDSet * efds, struct GNUNET_TIME_Relative timeout); + + /** * Initialize and run scheduler. This function will return when all * tasks have completed. On systems with signals, receiving a SIGTERM diff --git a/src/include/gnunet_server_lib.h b/src/include/gnunet_server_lib.h index 73fe800..f59e970 100644 --- a/src/include/gnunet_server_lib.h +++ b/src/include/gnunet_server_lib.h @@ -155,6 +155,24 @@ GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, void *access_cls, /** + * Suspend accepting connections from the listen socket temporarily. + * + * @param server server to stop accepting connections. + */ +void +GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server); + + +/** + * Resume accepting connections from the listen socket. + * + * @param server server to stop accepting connections. + */ +void +GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server); + + +/** * Stop the listen socket and get ready to shutdown the server * once only 'monitor' clients are left. * @@ -519,10 +537,10 @@ GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext /** * The notification context is the key datastructure for a conveniance * API used for transmission of notifications to the client until the - * client disconnects (or the notification context is destroyed, in - * which case we disconnect these clients). Essentially, all - * (notification) messages are queued up until the client is able to - * read them. + * client disconnects or is disconnected (or the notification context + * is destroyed, in which case we disconnect these clients). + * Essentially, all (notification) messages are queued up until the + * client is able to read them. */ struct GNUNET_SERVER_NotificationContext; diff --git a/src/include/gnunet_stream_lib.h b/src/include/gnunet_stream_lib.h index e09c264..056695b 100644 --- a/src/include/gnunet_stream_lib.h +++ b/src/include/gnunet_stream_lib.h @@ -46,28 +46,23 @@ enum GNUNET_STREAM_Status /** * All previous read/write operations are successfully done */ - GNUNET_STREAM_OK = 0, + GNUNET_STREAM_OK, /** * A timeout occured while reading/writing the stream */ - GNUNET_STREAM_TIMEOUT = 1, + GNUNET_STREAM_TIMEOUT, /** * Other side has shutdown the socket for this type of operation * (reading/writing) */ - GNUNET_STREAM_SHUTDOWN = 2, + GNUNET_STREAM_SHUTDOWN, /** * A serious error occured while operating on this stream */ - GNUNET_STREAM_SYSERR = 3, - - /** - * An error resulted in an unusable stream - */ - GNUNET_STREAM_BROKEN + GNUNET_STREAM_SYSERR }; /** @@ -86,6 +81,13 @@ typedef void (*GNUNET_STREAM_OpenCallback) (void *cls, /** + * Callback for signalling stream listen success; See + * GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS + */ +typedef void (*GNUNET_STREAM_ListenSuccessCallback) (void); + + +/** * Options for the stream. */ enum GNUNET_STREAM_Option @@ -103,7 +105,32 @@ enum GNUNET_STREAM_Option * of '0' means to use the round-trip time (plus a tiny grace period); * this is also the default. */ - GNUNET_STREAM_OPTION_INITIAL_RETRANSMIT_TIMEOUT + GNUNET_STREAM_OPTION_INITIAL_RETRANSMIT_TIMEOUT, + + /** + * Option to set the write sequence number. Takes a uint32_t as parameter + * to set the value of the write sequence number + */ + GNUNET_STREAM_OPTION_TESTING_SET_WRITE_SEQUENCE_NUMBER, + + /** + * Listen socket timeout in milliseconds given as uint32_t + */ + GNUNET_STREAM_OPTION_LISTEN_TIMEOUT, + + /** + * Option to register a callback when stream listening is successfull. Takes + * parameter of the form GNUNET_STREAM_ListenSuccessCallback. The callback + * is only called if listening is successful + */ + GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS, + + /** + * Option to set the maximum payload size in bytes of a stream data + * packets. Takes an uint16_t as argument. Note that this should be less + * than 64000 and cannot be zero. Default is 64000 bytes. + */ + GNUNET_STREAM_OPTION_MAX_PAYLOAD_SIZE }; @@ -114,7 +141,8 @@ enum GNUNET_STREAM_Option * @param target the target peer to which the stream has to be opened * @param app_port the application port number which uniquely identifies this * stream - * @param open_cb this function will be called after stream has be established + * @param open_cb this function will be called after stream has be established; + * cannot be NULL * @param open_cb_cls the closure for open_cb * @param ... options to the stream, terminated by GNUNET_STREAM_OPTION_END * @return if successful it returns the stream socket; NULL if stream cannot be @@ -164,7 +192,10 @@ GNUNET_STREAM_shutdown (struct GNUNET_STREAM_Socket *socket, /** - * Cancels a pending shutdown + * Cancels a pending shutdown. Note that the shutdown messages may already + * be sent and the stream is shutdown already for the operation given to + * GNUNET_STREAM_shutdown(). This function only clears up any retranmissions of + * shutdown messages and frees the shutdown handle. * * @param handle the shutdown handle returned from GNUNET_STREAM_shutdown */ @@ -174,7 +205,7 @@ GNUNET_STREAM_shutdown_cancel (struct GNUNET_STREAM_ShutdownHandle *handle); /** * Closes the stream and frees the associated state. The stream should be - * shutdown before closing. + * shutdown for both reading and writing before closing. * * @param socket the stream socket */ @@ -184,11 +215,13 @@ GNUNET_STREAM_close (struct GNUNET_STREAM_Socket *socket); /** * Functions of this type are called upon new stream connection from other peers + * or upon binding error which happen when the app_port given in + * GNUNET_STREAM_listen() is already taken. * * @param cls the closure from GNUNET_STREAM_listen - * @param socket the socket representing the stream + * @param socket the socket representing the stream; NULL on binding error * @param initiator the identity of the peer who wants to establish a stream - * with us + * with us; NULL on binding error * @return GNUNET_OK to keep the socket open, GNUNET_SYSERR to close the * stream (the socket will be invalid after the call) */ @@ -207,17 +240,22 @@ struct GNUNET_STREAM_ListenSocket; * Listens for stream connections for a specific application ports * * @param cfg the configuration to use - * @param app_port the application port for which new streams will be accepted + * @param app_port the application port for which new streams will be + * accepted. If another stream is listening on the same port the + * listen_cb will be called to signal binding error and the returned + * ListenSocket will be invalidated. * @param listen_cb this function will be called when a peer tries to establish * a stream with us * @param listen_cb_cls closure for listen_cb + * @param ... options to the stream, terminated by GNUNET_STREAM_OPTION_END * @return listen socket, NULL for any error */ struct GNUNET_STREAM_ListenSocket * GNUNET_STREAM_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_MESH_ApplicationType app_port, GNUNET_STREAM_ListenCallback listen_cb, - void *listen_cb_cls); + void *listen_cb_cls, + ...); /** @@ -234,7 +272,14 @@ GNUNET_STREAM_listen_close (struct GNUNET_STREAM_ListenSocket *lsocket); * on a stream are executed * * @param cls the closure from GNUNET_STREAM_write - * @param status the status of the stream at the time this function is called + * @param status the status of the stream at the time this function is called; + * GNUNET_STREAM_OK if writing to stream was completed successfully; + * GNUNET_STREAM_TIMEOUT if the given data is not sent successfully + * (this doesn't mean that the data is never sent, the receiver may + * have read the data but its ACKs may have been lost); + * GNUNET_STREAM_SHUTDOWN if the stream is shutdown for writing in the + * mean time; GNUNET_STREAM_SYSERR if the stream is broken and cannot + * be processed. * @param size the number of bytes written */ typedef void (*GNUNET_STREAM_CompletionContinuation) (void *cls, @@ -246,17 +291,17 @@ typedef void (*GNUNET_STREAM_CompletionContinuation) (void *cls, /** * Handle to cancel IO write operations. */ -struct GNUNET_STREAM_IOWriteHandle; +struct GNUNET_STREAM_WriteHandle; /** * Handle to cancel IO read operations. */ -struct GNUNET_STREAM_IOReadHandle; +struct GNUNET_STREAM_ReadHandle; /** * Tries to write the given data to the stream. The maximum size of data that - * can be written as part of a write operation is (64 * (64000 - sizeof (struct + * can be written per a write operation is ~ 4MB (64 * (64000 - sizeof (struct * GNUNET_STREAM_DataMessage))). If size is greater than this it is not an API * violation, however only the said number of maximum bytes will be written. * @@ -268,11 +313,12 @@ struct GNUNET_STREAM_IOReadHandle; * stream * @param write_cont_cls the closure * - * @return handle to cancel the operation; if a previous write is pending or - * the stream has been shutdown for this operation then write_cont is - * immediately called and NULL is returned. + * @return handle to cancel the operation; if a previous write is pending NULL + * is returned. If the stream has been shutdown for this operation or + * is broken then write_cont is immediately called and NULL is + * returned. */ -struct GNUNET_STREAM_IOWriteHandle * +struct GNUNET_STREAM_WriteHandle * GNUNET_STREAM_write (struct GNUNET_STREAM_Socket *socket, const void *data, size_t size, @@ -299,18 +345,20 @@ typedef size_t (*GNUNET_STREAM_DataProcessor) (void *cls, /** - * Tries to read data from the stream. + * Tries to read data from the stream. Should not be called when another read + * handle is present; the existing read handle should be canceled with + * GNUNET_STREAM_read_cancel(). Only one read handle per socket is present at + * any time * * @param socket the socket representing a stream * @param timeout the timeout period * @param proc function to call with data (once only) * @param proc_cls the closure for proc - * - * @return handle to cancel the operation; if the stream has been shutdown for - * this type of opeartion then the DataProcessor is immediately - * called with GNUNET_STREAM_SHUTDOWN as status and NULL if returned + * @return handle to cancel the operation; NULL is returned if the stream has + * been shutdown for this type of opeartion (the DataProcessor is + * immediately called with GNUNET_STREAM_SHUTDOWN as status) */ -struct GNUNET_STREAM_IOReadHandle * +struct GNUNET_STREAM_ReadHandle * GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket, struct GNUNET_TIME_Relative timeout, GNUNET_STREAM_DataProcessor proc, @@ -332,19 +380,19 @@ GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket, * used before shutting down transmission from our side or before closing the * socket. * - * @param ioh handle to operation to cancel + * @param wh write operation handle to cancel */ void -GNUNET_STREAM_io_write_cancel (struct GNUNET_STREAM_IOWriteHandle *iowh); +GNUNET_STREAM_write_cancel (struct GNUNET_STREAM_WriteHandle *wh); /** * Cancel pending read operation. * - * @param ioh handle to operation to cancel + * @param rh read operation handle to cancel */ void -GNUNET_STREAM_io_read_cancel (struct GNUNET_STREAM_IOReadHandle *iorh); +GNUNET_STREAM_read_cancel (struct GNUNET_STREAM_ReadHandle *rh); #if 0 diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h index 54d2e30..64dbd1e 100644 --- a/src/include/gnunet_strings_lib.h +++ b/src/include/gnunet_strings_lib.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2012 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 @@ -76,6 +76,19 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time, /** + * Convert a given fancy human-readable time to our internal + * representation. + * + * @param fancy_time human readable string (i.e. %Y-%m-%d %H:%M:%S) + * @param atime set to the absolute time + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_STRINGS_fancy_time_to_absolute (const char *fancy_time, + struct GNUNET_TIME_Absolute *atime); + + +/** * Convert a given filesize into a fancy human-readable format. * * @param size number of bytes @@ -95,7 +108,9 @@ GNUNET_STRINGS_byte_size_fancy (unsigned long long size); */ char * GNUNET_STRINGS_conv (const char *input, size_t len, - const char *input_charset, const char *output_charset); + const char *input_charset, + const char *output_charset); + /** * Convert the len characters long character sequence @@ -108,7 +123,10 @@ GNUNET_STRINGS_conv (const char *input, size_t len, * @return the converted string (0-terminated) */ char * -GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset); +GNUNET_STRINGS_to_utf8 (const char *input, + size_t len, + const char *charset); + /** * Convert the len bytes-long UTF-8 string @@ -119,7 +137,10 @@ GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset); * string is returned. */ char * -GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset); +GNUNET_STRINGS_from_utf8 (const char *input, + size_t len, + const char *charset); + /** * Convert the utf-8 input string to lowercase @@ -129,7 +150,8 @@ GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset); * @param output output buffer */ void -GNUNET_STRINGS_utf8_tolower(const char* input, char** output); +GNUNET_STRINGS_utf8_tolower (const char* input, + char** output); /** @@ -140,7 +162,8 @@ GNUNET_STRINGS_utf8_tolower(const char* input, char** output); * @param output output buffer */ void -GNUNET_STRINGS_utf8_toupper(const char* input, char** output); +GNUNET_STRINGS_utf8_toupper (const char* input, + char** output); /** @@ -156,16 +179,14 @@ GNUNET_STRINGS_filename_expand (const char *fil); /** - * Fill a buffer of the given size with - * count 0-terminated strings (given as varargs). - * If "buffer" is NULL, only compute the amount of - * space required (sum of "strlen(arg)+1"). + * Fill a buffer of the given size with count 0-terminated strings + * (given as varargs). If "buffer" is NULL, only compute the amount + * of space required (sum of "strlen(arg)+1"). * - * Unlike using "snprintf" with "%s", this function - * will add 0-terminators after each string. The - * "GNUNET_string_buffer_tokenize" function can be - * used to parse the buffer back into individual - * strings. + * Unlike using "snprintf" with "%s", this function will add + * 0-terminators after each string. The + * "GNUNET_string_buffer_tokenize" function can be used to parse the + * buffer back into individual strings. * * @param buffer the buffer to fill with strings, can * be NULL in which case only the necessary @@ -177,15 +198,16 @@ GNUNET_STRINGS_filename_expand (const char *fil); * (or number of bytes that would have been written) */ size_t -GNUNET_STRINGS_buffer_fill (char *buffer, size_t size, unsigned int count, ...); +GNUNET_STRINGS_buffer_fill (char *buffer, + size_t size, + unsigned int count, + ...); /** - * Given a buffer of a given size, find "count" - * 0-terminated strings in the buffer and assign - * the count (varargs) of type "const char**" to the - * locations of the respective strings in the - * buffer. + * Given a buffer of a given size, find "count" 0-terminated strings + * in the buffer and assign the count (varargs) of type "const char**" + * to the locations of the respective strings in the buffer. * * @param buffer the buffer to parse * @param size size of the buffer @@ -201,24 +223,30 @@ GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size, /** - * "man ctime_r", except for GNUnet time; also, unlike ctime, the - * return value does not include the newline character. + * "asctime", except for GNUnet time. + * This is one of the very few calls in the entire API that is + * NOT reentrant! * * @param t the absolute time to convert * @return timestamp in human-readable form */ -char * +const char * GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t); /** * Give relative time in human-readable fancy format. + * This is one of the very few calls in the entire API that is + * NOT reentrant! * * @param delta time in milli seconds + * @param do_round are we allowed to round a bit? * @return string in human-readable form */ -char * -GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta); +const char * +GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta, + int do_round); + /** * "man basename" @@ -251,8 +279,10 @@ GNUNET_STRINGS_get_short_name (const char *filename); * @return pointer to the next byte in 'out' or NULL on error. */ char * -GNUNET_STRINGS_data_to_string (const unsigned char *data, size_t size, - char *out, size_t out_size); +GNUNET_STRINGS_data_to_string (const unsigned char *data, + size_t size, + char *out, + size_t out_size); /** @@ -266,25 +296,12 @@ GNUNET_STRINGS_data_to_string (const unsigned char *data, size_t size, * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding */ int -GNUNET_STRINGS_string_to_data (const char *enc, size_t enclen, - unsigned char *out, size_t out_size); +GNUNET_STRINGS_string_to_data (const char *enc, + size_t enclen, + unsigned char *out, + size_t out_size); -#if 0 /* keep Emacsens' auto-indent happy */ -{ -#endif -#ifdef __cplusplus -} -#endif - -enum GNUNET_STRINGS_FilenameCheck -{ - GNUNET_STRINGS_CHECK_EXISTS = 0x00000001, - GNUNET_STRINGS_CHECK_IS_DIRECTORY = 0x00000002, - GNUNET_STRINGS_CHECK_IS_LINK = 0x00000004, - GNUNET_STRINGS_CHECK_IS_ABSOLUTE = 0x00000008 -}; - /** * Parse a path that might be an URI. * @@ -302,8 +319,9 @@ enum GNUNET_STRINGS_FilenameCheck * (if they weren't NULL). */ int -GNUNET_STRINGS_parse_uri (const char *path, char **scheme_part, - const char **path_part); +GNUNET_STRINGS_parse_uri (const char *path, + char **scheme_part, + const char **path_part); /** @@ -328,7 +346,35 @@ GNUNET_STRINGS_path_is_absolute (const char *filename, /** - * Perform checks on 'filename; + * Flags for what we should check a file for. + */ +enum GNUNET_STRINGS_FilenameCheck +{ + /** + * Check that it exists. + */ + GNUNET_STRINGS_CHECK_EXISTS = 0x00000001, + + /** + * Check that it is a directory. + */ + GNUNET_STRINGS_CHECK_IS_DIRECTORY = 0x00000002, + + /** + * Check that it is a link. + */ + GNUNET_STRINGS_CHECK_IS_LINK = 0x00000004, + + /** + * Check that the path is an absolute path. + */ + GNUNET_STRINGS_CHECK_IS_ABSOLUTE = 0x00000008 +}; + + +/** + * Perform checks on 'filename'. FIXME: some duplication with + * "GNUNET_DISK_"-APIs. We should unify those. * * @param filename file to check * @param checks checks to perform @@ -390,6 +436,35 @@ GNUNET_STRINGS_to_address_ip (const char *addr, struct sockaddr_storage *r_buf); +/** + * Returns utf-8 encoded arguments. + * Does nothing (returns a copy of argc and argv) on any platform + * other than W32. + * Returned argv has u8argv[u8argc] == NULL. + * Returned argv is a single memory block, and can be freed with a single + * GNUNET_free () call. + * + * @param argc argc (as given by main()) + * @param argv argv (as given by main()) + * @param u8argc a location to store new argc in (though it's th same as argc) + * @param u8argv a location to store new argv in + * @return GNUNET_OK on success, GNUNET_SYSERR on failure + */ +int +GNUNET_STRINGS_get_utf8_args (int argc, + char *const *argv, + int *u8argc, + char *const **u8argv); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + /* ifndef GNUNET_UTIL_STRING_H */ #endif /* end of gnunet_util_string.h */ diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h index ab8db87..3c2d932 100644 --- a/src/include/gnunet_testbed_service.h +++ b/src/include/gnunet_testbed_service.h @@ -29,6 +29,7 @@ #define GNUNET_TESTBED_SERVICE_H #include "gnunet_util_lib.h" +#include "gnunet_testing_lib.h" #ifdef __cplusplus extern "C" @@ -49,7 +50,7 @@ struct GNUNET_TESTBED_Host; /** * Opaque handle to a peer controlled by the testbed framework. A peer runs * at a particular host. - */ + */ struct GNUNET_TESTBED_Peer; /** @@ -58,45 +59,62 @@ struct GNUNET_TESTBED_Peer; struct GNUNET_TESTBED_Operation; /** - * Handle to interact with a GNUnet testbed controller. Each controller has at - * least one master handle which is created when the controller is created; this - * master handle interacts with the controller via stdin/stdout of the controller - * process. Additionally, controllers can interact with each other (in a P2P - * fashion); those links are established via TCP/IP on the controller's service - * port. + * Handle to interact with a GNUnet testbed controller. Each + * controller has at least one master handle which is created when the + * controller is created; this master handle interacts with the + * controller process, destroying it destroys the controller (by + * closing stdin of the controller process). Additionally, + * controllers can interact with each other (in a P2P fashion); those + * links are established via TCP/IP on the controller's service port. */ struct GNUNET_TESTBED_Controller; + /** - * Handle to a large-scale testbed that is managed at a high level. + * Create a host to run peers and controllers on. + * + * @param hostname name of the host, use "NULL" for localhost + * @param username username to use for the login; may be NULL + * @param port port number to use for ssh; use 0 to let ssh decide + * @return handle to the host, NULL on error */ -struct GNUNET_TESTBED_Testbed; +struct GNUNET_TESTBED_Host * +GNUNET_TESTBED_host_create (const char *hostname, + const char *username, + uint16_t port); + /** - * Create a host to run peers and controllers on. - * + * Create a host to run peers and controllers on. This function is used + * if a peer learns about a host via IPC between controllers (and thus + * some higher-level controller has already determined the unique IDs). + * + * @param id global host ID assigned to the host; 0 is + * reserved to always mean 'localhost' * @param hostname name of the host, use "NULL" for localhost * @param username username to use for the login; may be NULL * @param port port number to use for ssh; use 0 to let ssh decide * @return handle to the host, NULL on error */ struct GNUNET_TESTBED_Host * -GNUNET_TESTBED_host_create (const char *hostname, - const char *username, - uint16_t port); +GNUNET_TESTBED_host_create_with_id (uint32_t id, + const char *hostname, + const char *username, + uint16_t port); /** * Load a set of hosts from a configuration file. * * @param filename file with the host specification - * @param hosts set to the hosts found in the file + * @param hosts set to the hosts found in the file; caller must free this if + * number of hosts returned is greater than 0 * @return number of hosts returned in 'hosts', 0 on error */ unsigned int GNUNET_TESTBED_hosts_load_from_file (const char *filename, - struct GNUNET_TESTBED_Host **hosts); + struct GNUNET_TESTBED_Host ***hosts); /** @@ -110,6 +128,68 @@ GNUNET_TESTBED_host_destroy (struct GNUNET_TESTBED_Host *host); /** + * The handle for whether a host is habitable or not + */ +struct GNUNET_TESTBED_HostHabitableCheckHandle; + + +/** + * Callbacks of this type are called by GNUNET_TESTBED_is_host_habitable to + * inform whether the given host is habitable or not. The Handle returned by + * GNUNET_TESTBED_is_host_habitable() is invalid after this callback is called + * + * @param cls the closure given to GNUNET_TESTBED_is_host_habitable() + * @param host the host whose status is being reported; will be NULL if the host + * given to GNUNET_TESTBED_is_host_habitable() is NULL + * @param status GNUNET_YES if it is habitable; GNUNET_NO if not + */ +typedef void (*GNUNET_TESTBED_HostHabitableCallback) (void *cls, + const struct + GNUNET_TESTBED_Host + *host, + int status); + + +/** + * Checks whether a host can be used to start testbed service + * + * @param host the host to check + * @param config the configuration handle to lookup the path of the testbed + * helper + * @param cb the callback to call to inform about habitability of the given host + * @param cb_cls the closure for the callback + * @return NULL upon any error or a handle which can be passed to + * GNUNET_TESTBED_is_host_habitable_cancel() + */ +struct GNUNET_TESTBED_HostHabitableCheckHandle * +GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host, + const struct GNUNET_CONFIGURATION_Handle + *config, + GNUNET_TESTBED_HostHabitableCallback cb, + void *cb_cls); + + +/** + * Function to cancel a request started using GNUNET_TESTBED_is_host_habitable() + * + * @param handle the habitability check handle + */ +void +GNUNET_TESTBED_is_host_habitable_cancel (struct + GNUNET_TESTBED_HostHabitableCheckHandle + *handle); + +/** + * Obtain the host's hostname. + * + * @param host handle to the host, NULL means 'localhost' + * @return hostname of the host + */ +const char * +GNUNET_TESTBED_host_get_hostname (const struct GNUNET_TESTBED_Host *host); + + +/** * Enumeration with (at most 64) possible event types that * can be monitored using the testbed framework. */ @@ -163,13 +243,6 @@ enum GNUNET_TESTBED_PeerInformationType GNUNET_TESTBED_PIT_GENERIC = 0, /** - * What host is the peer running on? Returns a 'const struct - * GNUNET_TESTBED_Host *'. Valid until - * 'GNUNET_TESTBED_operation_done' is called. - */ - GNUNET_TESTBED_PIT_HOST, - - /** * What configuration is the peer using? Returns a 'const struct * GNUNET_CONFIGURATION_Handle *'. Valid until * 'GNUNET_TESTNIG_operation_done' is called. However, the @@ -194,7 +267,7 @@ enum GNUNET_TESTBED_PeerInformationType */ struct GNUNET_TESTBED_EventInformation { - + /** * Type of the event. */ @@ -205,10 +278,10 @@ struct GNUNET_TESTBED_EventInformation */ union { - + /** * Details about peer start event. - */ + */ struct { /** @@ -221,12 +294,12 @@ struct GNUNET_TESTBED_EventInformation * Handle for the peer that was started. */ struct GNUNET_TESTBED_Peer *peer; - + } peer_start; /** * Details about peer stop event. - */ + */ struct { @@ -234,12 +307,12 @@ struct GNUNET_TESTBED_EventInformation * Handle for the peer that was started. */ struct GNUNET_TESTBED_Peer *peer; - + } peer_stop; /** * Details about connect event. - */ + */ struct { /** @@ -256,7 +329,7 @@ struct GNUNET_TESTBED_EventInformation /** * Details about disconnect event. - */ + */ struct { /** @@ -268,13 +341,13 @@ struct GNUNET_TESTBED_EventInformation * Handle for one of the disconnected peers. */ struct GNUNET_TESTBED_Peer *peer2; - + } peer_disconnect; /** * Details about an operation finished event. - */ - struct + */ + struct { /** @@ -290,57 +363,26 @@ struct GNUNET_TESTBED_EventInformation /** * Error message for the operation, NULL on success. - */ - const char *emsg; - - /** - * Peer information type; captures which of the types - * in the 'op_result' is actually in use. */ - enum GNUNET_TESTBED_PeerInformationType pit; + const char *emsg; /** - * Pointer to an operation-specific return value; NULL on error; - * can be NULL for certain operations. Valid until - * 'GNUNET_TESTBED_operation_done' is called. + * No result (NULL pointer) or generic result + * (whatever the GNUNET_TESTBED_ConnectAdapter returned). */ - union - { - /** - * No result (NULL pointer) or generic result - * (whatever the GNUNET_TESTBED_ConnectAdapter returned). - */ - void *generic; - - /** - * Identity of host running the peer. - */ - struct GNUNET_TESTBED_Host *host; - - /** - * Identity of the peer. - */ - const struct GNUNET_PeerIdentity *pid; - - /** - * Configuration of the peer. - */ - const struct GNUNET_CONFIGURATION_Handle *cfg; - - } op_result; - - } operation_finished; + void *generic; + } operation_finished; /** * Details about an testbed run completed event. - */ - struct + */ + struct { /** * Error message for the operation, NULL on success. - */ + */ const char *emsg; /** @@ -355,8 +397,8 @@ struct GNUNET_TESTBED_EventInformation * Size of the 'peers' array. */ unsigned int num_peers; - - } testbed_run_finished; + + } testbed_run_finished; } details; @@ -371,15 +413,80 @@ struct GNUNET_TESTBED_EventInformation * @param event information about the event */ typedef void (*GNUNET_TESTBED_ControllerCallback)(void *cls, - const struct GNUNET_TESTBED_EventInformation *event); + const struct GNUNET_TESTBED_EventInformation *event); + + +/** + * Opaque Handle for Controller process + */ +struct GNUNET_TESTBED_ControllerProc; + + +/** + * Callback to signal successfull startup of the controller process + * + * @param cls the closure from GNUNET_TESTBED_controller_start() + * @param cfg the configuration with which the controller has been started; + * NULL if status is not GNUNET_OK + * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, + * GNUNET_TESTBED_controller_stop() shouldn't be called in this case + */ +typedef void (*GNUNET_TESTBED_ControllerStatusCallback) (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + int status); /** - * Start a controller process using the given configuration at the + * Starts a controller process at the given host. + * + * @param trusted_ip the ip address of the controller which will be set as TRUSTED + * HOST(all connections form this ip are permitted by the testbed) when + * starting testbed controller at host. This can either be a single ip + * address or a network address in CIDR notation. + * @param host the host where the controller has to be started; NULL for + * localhost + * @param cfg template configuration to use for the remote controller; the + * remote controller will be started with a slightly modified + * configuration (port numbers, unix domain sockets and service home + * values are changed as per TESTING library on the remote host) + * @param cb function called when the controller is successfully started or + * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be + * called if cb is called with GNUNET_SYSERR as status. Will never be + * called in the same task as 'GNUNET_TESTBED_controller_start' + * (synchronous errors will be signalled by returning NULL). This + * parameter cannot be NULL. + * @param cls closure for above callbacks + * @return the controller process handle, NULL on errors + */ +struct GNUNET_TESTBED_ControllerProc * +GNUNET_TESTBED_controller_start (const char *trusted_ip, + struct GNUNET_TESTBED_Host *host, + const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_TESTBED_ControllerStatusCallback cb, + void *cls); + + +/** + * Stop the controller process (also will terminate all peers and controllers + * dependent on this controller). This function blocks until the testbed has + * been fully terminated (!). The controller status cb from + * GNUNET_TESTBED_controller_start() will not be called. + * + * @param cproc the controller process handle + */ +void +GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_ControllerProc *cproc); + + +/** + * Connect to a controller process using the given configuration at the * given host. * * @param cfg configuration to use - * @param host host to run the controller on, NULL for 'localhost' + * @param host host to run the controller on; This should be the same host if + * the controller was previously started with + * GNUNET_TESTBED_controller_start; NULL for localhost + * @param host host where this controller is being run; * @param event_mask bit mask with set of events to call 'cc' for; * or-ed values of "1LL" shifted by the * respective 'enum GNUNET_TESTBED_EventType' @@ -389,11 +496,11 @@ typedef void (*GNUNET_TESTBED_ControllerCallback)(void *cls, * @return handle to the controller */ struct GNUNET_TESTBED_Controller * -GNUNET_TESTBED_controller_start (const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TESTBED_Host *host, - uint64_t event_mask, - GNUNET_TESTBED_ControllerCallback cc, - void *cc_cls); +GNUNET_TESTBED_controller_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTBED_Host *host, + uint64_t event_mask, + GNUNET_TESTBED_ControllerCallback cc, + void *cc_cls); /** @@ -402,7 +509,7 @@ GNUNET_TESTBED_controller_start (const struct GNUNET_CONFIGURATION_Handle *cfg, * should not be run for each peer but instead be shared * across N peers on the specified host. This function * must be called before any peers are created at the host. - * + * * @param controller controller to configure * @param service_name name of the service to share * @param num_peers number of peers that should share one instance @@ -411,49 +518,190 @@ GNUNET_TESTBED_controller_start (const struct GNUNET_CONFIGURATION_Handle *cfg, */ void GNUNET_TESTBED_controller_configure_sharing (struct GNUNET_TESTBED_Controller *controller, - const char *service_name, - uint32_t num_peers); + const char *service_name, + uint32_t num_peers); /** * Stop the given controller (also will terminate all peers and - * controllers dependent on this controller). This function + * controllers dependent on this controller). This function * blocks until the testbed has been fully terminated (!). * * @param controller handle to controller to stop */ void -GNUNET_TESTBED_controller_stop (struct GNUNET_TESTBED_Controller *controller); - - -/** - * Create a link from a 'master' controller to a slave controller. - * Whenever the master controller is asked to start a peer at the - * given 'delegated_host', it will delegate the request to the - * specified slave controller. Note that the slave controller runs at - * the 'slave_host', which may or may not be the same host as the - * 'delegated_host' (for hierarchical delegations). The configuration - * of the slave controller is given and to be used to either create - * the slave controller or to connect to an existing slave controller - * process. 'is_subordinate' specifies if the given slave controller - * should be started and managed by the master controller, or if the - * slave already has a master and this is just a secondary master that - * is also allowed to use the existing slave. +GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *controller); + + +/** + * Opaque handle for host registration + */ +struct GNUNET_TESTBED_HostRegistrationHandle; + + +/** + * Callback which will be called to after a host registration succeeded or failed + * + * @param cls the closure + * @param emsg the error message; NULL if host registration is successful + */ +typedef void (* GNUNET_TESTBED_HostRegistrationCompletion) (void *cls, + const char *emsg); + + +/** + * Register a host with the controller. This makes the controller aware of the + * host. A host should be registered at the controller before starting a + * sub-controller on that host using GNUNET_TESTBED_controller_link(). + * + * @param controller the controller handle + * @param host the host to register + * @param cc the completion callback to call to inform the status of + * registration. After calling this callback the registration handle + * will be invalid. Cannot be NULL + * @param cc_cls the closure for the cc + * @return handle to the host registration which can be used to cancel the + * registration; NULL if another registration handle is present and + * is not cancelled + */ +struct GNUNET_TESTBED_HostRegistrationHandle * +GNUNET_TESTBED_register_host (struct GNUNET_TESTBED_Controller *controller, + struct GNUNET_TESTBED_Host *host, + GNUNET_TESTBED_HostRegistrationCompletion cc, + void *cc_cls); + + +/** + * Cancel the pending registration. Note that the registration message will + * already be queued to be sent to the service, cancellation has only the + * effect that the registration completion callback for the registration is + * never called and from our perspective the host is not registered until the + * completion callback is called. + * + * @param handle the registration handle to cancel + */ +void +GNUNET_TESTBED_cancel_registration (struct GNUNET_TESTBED_HostRegistrationHandle + *handle); + + +/** + * Callback to be called when an operation is completed + * + * @param cls the callback closure from functions generating an operation + * @param op the operation that has been finished + * @param emsg error message in case the operation has failed; will be NULL if + * operation has executed successfully. + */ +typedef void (*GNUNET_TESTBED_OperationCompletionCallback) (void *cls, + struct + GNUNET_TESTBED_Operation + *op, + const char *emsg); + + +/** + * Create a link from slave controller to delegated controller. Whenever the + * master controller is asked to start a peer at the delegated controller the + * request will be routed towards slave controller (if a route exists). The + * slave controller will then route it to the delegated controller. The + * configuration of the delegated controller is given and is used to either + * create the delegated controller or to connect to an existing controller. Note + * that while starting the delegated controller the configuration will be + * modified to accommodate available free ports. the 'is_subordinate' specifies + * if the given delegated controller should be started and managed by the slave + * controller, or if the delegated controller already has a master and the slave + * controller connects to it as a non master controller. The success or failure + * of this operation will be signalled through the + * GNUNET_TESTBED_ControllerCallback() with an event of type + * GNUNET_TESTBED_ET_OPERATION_FINISHED * + * @param op_cls the operation closure for the event which is generated to + * signal success or failure of this operation * @param master handle to the master controller who creates the association - * @param delegated_host requests to which host should be delegated - * @param slave_host which host is used to run the slave controller + * @param delegated_host requests to which host should be delegated; cannot be NULL + * @param slave_host which host is used to run the slave controller; use NULL to + * make the master controller connect to the delegated host * @param slave_cfg configuration to use for the slave controller - * @param is_subordinate GNUNET_YES if the slave should be started (and stopped) - * by the master controller; GNUNET_NO if we are just - * allowed to use the slave via TCP/IP + * @param is_subordinate GNUNET_YES if the controller at delegated_host should + * be started by the slave controller; GNUNET_NO if the slave + * controller has to connect to the already started delegated + * controller via TCP/IP + * @return the operation handle */ -void -GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master, - struct GNUNET_TESTBED_Host *delegated_host, - struct GNUNET_TESTBED_Host *slave_host, - const struct GNUNET_CONFIGURATION_Handle *slave_cfg, - int is_subordinate); +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_controller_link (void *op_cls, + struct GNUNET_TESTBED_Controller *master, + struct GNUNET_TESTBED_Host *delegated_host, + struct GNUNET_TESTBED_Host *slave_host, + const struct GNUNET_CONFIGURATION_Handle + *slave_cfg, + int is_subordinate); + + +/** + * Same as the GNUNET_TESTBED_controller_link, however expects configuration in + * serialized and compressed + * + * @param op_cls the operation closure for the event which is generated to + * signal success or failure of this operation + * @param master handle to the master controller who creates the association + * @param delegated_host requests to which host should be delegated; cannot be NULL + * @param slave_host which host is used to run the slave controller; use NULL to + * make the master controller connect to the delegated host + * @param sxcfg serialized and compressed configuration + * @param sxcfg_size the size sxcfg + * @param scfg_size the size of uncompressed serialized configuration + * @param is_subordinate GNUNET_YES if the controller at delegated_host should + * be started by the slave controller; GNUNET_NO if the slave + * controller has to connect to the already started delegated + * controller via TCP/IP + * @return the operation handle + */ +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_controller_link_2 (void *op_cls, + struct GNUNET_TESTBED_Controller *master, + struct GNUNET_TESTBED_Host *delegated_host, + struct GNUNET_TESTBED_Host *slave_host, + const char *sxcfg, + size_t sxcfg_size, + size_t scfg_size, + int is_subordinate); + + +/** + * Function to acquire the configuration of a running slave controller. The + * completion of the operation is signalled through the controller_cb from + * GNUNET_TESTBED_controller_connect(). If the operation is successful the + * handle to the configuration is available in the generic pointer of + * operation_finished field of struct GNUNET_TESTBED_EventInformation. + * + * @param op_cls the closure for the operation + * @param master the handle to master controller + * @param slave_host the host where the slave controller is running; the handle + * to the slave_host should remain valid until this operation is + * cancelled or marked as finished + * @return the operation handle; NULL if the slave_host is not registered at + * master + */ +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_get_slave_config (void *op_cls, + struct GNUNET_TESTBED_Controller *master, + struct GNUNET_TESTBED_Host *slave_host); + + +/** + * Functions of this signature are called when a peer has been successfully + * created + * + * @param cls the closure from GNUNET_TESTBED_peer_create() + * @param peer the handle for the created peer; NULL on any error during + * creation + * @param emsg NULL if peer is not NULL; else MAY contain the error description + */ +typedef void (*GNUNET_TESTBED_PeerCreateCallback) (void *cls, + struct GNUNET_TESTBED_Peer *peer, + const char *emsg); /** @@ -478,48 +726,131 @@ GNUNET_TESTBED_controller_link (struct GNUNET_TESTBED_Controller *master, * 'GNUNET_TESTBED_peer_get_information'. * * @param controller controller process to use - * @param host host to run the peer on - * @param cfg configuration to use for the peer - * @return handle to the peer (actual startup will happen asynchronously) + * @param host host to run the peer on; cannot be NULL + * @param cfg Template configuration to use for the peer. Should exist until + * operation is cancelled or GNUNET_TESTBED_operation_done() is called + * @param cb the callback to call when the peer has been created + * @param cls the closure to the above callback + * @return the operation handle */ -struct GNUNET_TESTBED_Peer * +struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_peer_create (struct GNUNET_TESTBED_Controller *controller, - struct GNUNET_TESTBED_Host *host, - const struct GNUNET_CONFIGURATION_Handle *cfg); + struct GNUNET_TESTBED_Host *host, + const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_TESTBED_PeerCreateCallback cb, + void *cls); + + +/** + * Functions of this signature are called when a peer has been successfully + * started or stopped. + * + * @param cls the closure from GNUNET_TESTBED_peer_start/stop() + * @param emsg NULL on success; otherwise an error description + */ +typedef void (*GNUNET_TESTBED_PeerChurnCallback) (void *cls, + const char *emsg); /** * Start the given peer. * + * @param op_cls the closure for this operation; will be set in + * event->details.operation_finished.op_cls when this operation fails. * @param peer peer to start + * @param pcc function to call upon completion + * @param pcc_cls closure for 'pcc' * @return handle to the operation */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer); +GNUNET_TESTBED_peer_start (void *op_cls, + struct GNUNET_TESTBED_Peer *peer, + GNUNET_TESTBED_PeerChurnCallback pcc, + void *pcc_cls); /** * Stop the given peer. The handle remains valid (use - * "GNUNET_TESTBED_peer_destroy" to fully clean up the + * "GNUNET_TESTBED_peer_destroy" to fully clean up the * state of the peer). * * @param peer peer to stop + * @param pcc function to call upon completion + * @param pcc_cls closure for 'pcc' * @return handle to the operation */ struct GNUNET_TESTBED_Operation * -GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer); +GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer, + GNUNET_TESTBED_PeerChurnCallback pcc, + void *pcc_cls); + + +/** + * Data returned from GNUNET_TESTBED_peer_get_information + */ +struct GNUNET_TESTBED_PeerInformation +{ + /** + * Peer information type; captures which of the types + * in the 'op_result' is actually in use. + */ + enum GNUNET_TESTBED_PeerInformationType pit; + + /** + * The result of the get information operation; Choose according to the pit + */ + union + { + /** + * The configuration of the peer + */ + struct GNUNET_CONFIGURATION_Handle *cfg; + + /** + * The identity of the peer + */ + struct GNUNET_PeerIdentity *id; + } result; +}; /** - * Request information about a peer. + * Callback to be called when the requested peer information is available + * + * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information() + * @param op the operation this callback corresponds to + * @param pinfo the result; will be NULL if the operation has failed + * @param emsg error message if the operation has failed; will be NULL if the + * operation is successfull + */ +typedef void (*GNUNET_TESTBED_PeerInfoCallback) (void *cb_cls, + struct GNUNET_TESTBED_Operation + *op, + const struct + GNUNET_TESTBED_PeerInformation + *pinfo, + const char *emsg); + + +/** + * Request information about a peer. The controller callback will not be called + * with event type GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this + * operation is available. Instead, the GNUNET_TESTBED_PeerInfoCallback() will + * be called. * * @param peer peer to request information about * @param pit desired information + * @param cb the convenience callback to be called when results for this + * operation are available + * @param cb_cls the closure for the above callback * @return handle to the operation */ struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, - enum GNUNET_TESTBED_PeerInformationType pit); + enum GNUNET_TESTBED_PeerInformationType + pit, + GNUNET_TESTBED_PeerInfoCallback cb, + void *cb_cls); /** @@ -534,7 +865,7 @@ GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, */ struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer, - const struct GNUNET_CONFIGURATION_Handle *cfg); + const struct GNUNET_CONFIGURATION_Handle *cfg); /** @@ -557,28 +888,28 @@ enum GNUNET_TESTBED_ConnectOption * No option (not valid as an argument). */ GNUNET_TESTBED_CO_NONE = 0, - + /** - * Allow or disallow a connection between the specified peers. + * Allow or disallow a connection between the specified peers. * Followed by GNUNET_NO (int) if a connection is disallowed * or GNUNET_YES if a connection is allowed. Note that the * default (all connections allowed or disallowed) is * specified in the configuration of the controller. */ GNUNET_TESTBED_CO_ALLOW = 1, - + /** * FIXME: add (and implement) options to limit connection to * particular transports, force simulation of particular latencies * or message loss rates, or set bandwidth limitations. */ - + }; /** * Manipulate the P2P underlay topology by configuring a link - * between two peers. + * between two peers. * * @param op_cls closure argument to give with the operation event * @param p1 first peer @@ -590,15 +921,15 @@ enum GNUNET_TESTBED_ConnectOption */ struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_underlay_configure_link_va (void *op_cls, - struct GNUNET_TESTBED_Peer *p1, - struct GNUNET_TESTBED_Peer *p2, - enum GNUNET_TESTBED_ConnectOption co, - va_list ap); + struct GNUNET_TESTBED_Peer *p1, + struct GNUNET_TESTBED_Peer *p2, + enum GNUNET_TESTBED_ConnectOption co, + va_list ap); /** * Manipulate the P2P underlay topology by configuring a link - * between two peers. + * between two peers. * * @param op_cls closure argument to give with the operation event * @param p1 first peer @@ -610,19 +941,21 @@ GNUNET_TESTBED_underlay_configure_link_va (void *op_cls, */ struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_underlay_configure_link (void *op_cls, - struct GNUNET_TESTBED_Peer *p1, - struct GNUNET_TESTBED_Peer *p2, - enum GNUNET_TESTBED_ConnectOption co, ...); + struct GNUNET_TESTBED_Peer *p1, + struct GNUNET_TESTBED_Peer *p2, + enum GNUNET_TESTBED_ConnectOption co, ...); /** - * Topologies supported for testbeds. + * Topologies and topology options supported for testbeds. Options should always + * end with GNUNET_TESTBED_TOPOLOGY_OPTION_END */ enum GNUNET_TESTBED_TopologyOption { /** - * A clique (everyone connected to everyone else). No options. + * A clique (everyone connected to everyone else). No options. If there are N + * peers this topology results in (N * (N -1)) connections. */ GNUNET_TESTBED_TOPOLOGY_CLIQUE, @@ -649,9 +982,8 @@ enum GNUNET_TESTBED_TopologyOption GNUNET_TESTBED_TOPOLOGY_2D_TORUS, /** - * Random graph. Followed by the link density, that is the - * percentage of links present in relation to a clique - * (float). + * Random graph. Followed by the number of random links to be established + * (unsigned int) */ GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, @@ -663,7 +995,7 @@ enum GNUNET_TESTBED_TopologyOption GNUNET_TESTBED_TOPOLOGY_INTERNAT, /** - * Scale free topology. FIXME: options? + * Scale free topology. No options. */ GNUNET_TESTBED_TOPOLOGY_SCALE_FREE, @@ -673,14 +1005,33 @@ enum GNUNET_TESTBED_TopologyOption GNUNET_TESTBED_TOPOLOGY_LINE, /** + * Read a topology from a given file. Followed by the name of the file (const char *). + */ + GNUNET_TESTBED_TOPOLOGY_FROM_FILE, + + /** * All peers are disconnected. No options. */ GNUNET_TESTBED_TOPOLOGY_NONE, /** - * Read a topology from a given file. Followed by the name of the file (const char *). + * The options should always end with this */ - GNUNET_TESTBED_TOPOLOGY_FROM_FILE + GNUNET_TESTBED_TOPOLOGY_OPTION_END, + + /* The following are not topologies but influence how the topology has to be + setup. These options should follow the topology specific options (if + required by the chosen topology). Note that these should be given before + GNUNET_TESTBED_TOPOLOGY_OPTION_END */ + + /** + * How many times should the failed overlay connect operations be retried + * before giving up. The default if this option is not specified is to retry + * 3 times. This option takes and unsigned integer as a parameter. Use this + * option with parameter 0 to disable retrying of failed overlay connect + * operations. + */ + GNUNET_TESTBED_TOPOLOGY_RETRY_CNT }; @@ -697,10 +1048,10 @@ enum GNUNET_TESTBED_TopologyOption */ struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers, - enum GNUNET_TESTBED_TopologyOption topo, - va_list ap); + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + enum GNUNET_TESTBED_TopologyOption topo, + va_list ap); /** @@ -716,10 +1067,10 @@ GNUNET_TESTBED_underlay_configure_topology_va (void *op_cls, */ struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_underlay_configure_topology (void *op_cls, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers, - enum GNUNET_TESTBED_TopologyOption topo, - ...); + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + enum GNUNET_TESTBED_TopologyOption topo, + ...); /** @@ -728,6 +1079,8 @@ GNUNET_TESTBED_underlay_configure_topology (void *op_cls, * and asks 'p2' to connect to 'p1'. * * @param op_cls closure argument to give with the operation event + * @param cb the callback to call when this operation has finished + * @param cb_cls the closure for the above callback * @param p1 first peer * @param p2 second peer * @return handle to the operation, NULL if connecting these two @@ -736,8 +1089,24 @@ GNUNET_TESTBED_underlay_configure_topology (void *op_cls, */ struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_overlay_connect (void *op_cls, - struct GNUNET_TESTBED_Peer *p1, - struct GNUNET_TESTBED_Peer *p2); + GNUNET_TESTBED_OperationCompletionCallback cb, + void *cb_cls, + struct GNUNET_TESTBED_Peer *p1, + struct GNUNET_TESTBED_Peer *p2); + + +/** + * Callbacks of this type are called when topology configuration is completed + * + * @param cls the operation closure given to + * GNUNET_TESTBED_overlay_configure_topology_va() and + * GNUNET_TESTBED_overlay_configure() calls + * @param nsuccess the number of successful overlay connects + * @param nfailures the number of overlay connects which failed + */ +typedef void (*GNUNET_TESTBED_TopologyCompletionCallback) (void *cls, + unsigned int nsuccess, + unsigned int nfailures); /** @@ -745,21 +1114,31 @@ GNUNET_TESTBED_overlay_connect (void *op_cls, * This function then connects the given peers in the P2P overlay * using the given topology. * - * @param op_cls closure argument to give with the operation event + * @param op_cls closure argument to give with the peer connect operation events + * generated through this function * @param num_peers number of peers in 'peers' * @param peers array of 'num_peers' with the peers to configure + * @param max_connections the maximums number of overlay connections that will + * be made to achieve the given topology + * @param comp_cb the completion callback to call when the topology generation + * is completed + * @param comp_cb_cls closure for the above completion callback * @param topo desired underlay topology to use * @param va topology-specific options - * @return handle to the operation, NULL if connecting these + * @return handle to the operation, NULL if connecting these * peers is fundamentally not possible at this time (peers - * not running or underlay disallows) + * not running or underlay disallows) or if num_peers is less than 2 */ struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer *peers, - enum GNUNET_TESTBED_TopologyOption topo, - va_list va); + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + unsigned int *max_connections, + GNUNET_TESTBED_TopologyCompletionCallback + comp_cb, + void *comp_cb_cls, + enum GNUNET_TESTBED_TopologyOption topo, + va_list va); /** @@ -767,28 +1146,38 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, * This function then connects the given peers in the P2P overlay * using the given topology. * - * @param op_cls closure argument to give with the operation event + * @param op_cls closure argument to give with the peer connect operation events + * generated through this function * @param num_peers number of peers in 'peers' * @param peers array of 'num_peers' with the peers to configure + * @param max_connections the maximums number of overlay connections that will + * be made to achieve the given topology + * @param comp_cb the completion callback to call when the topology generation + * is completed + * @param comp_cb_cls closure for the above completion callback * @param topo desired underlay topology to use * @param ... topology-specific options - * @return handle to the operation, NULL if connecting these + * @return handle to the operation, NULL if connecting these * peers is fundamentally not possible at this time (peers - * not running or underlay disallows) + * not running or underlay disallows) or if num_peers is less than 2 */ struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_overlay_configure_topology (void *op_cls, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer *peers, - enum GNUNET_TESTBED_TopologyOption topo, - ...); - + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + unsigned int *max_connections, + GNUNET_TESTBED_TopologyCompletionCallback + comp_cb, + void *comp_cb_cls, + enum GNUNET_TESTBED_TopologyOption topo, + ...); /** * Ask the testbed controller to write the current overlay topology to * a file. Naturally, the file will only contain a snapshot as the * topology may evolve all the time. + * FIXME: needs continuation!? * * @param controller overlay controller to inspect * @param filename name of the file the topology should @@ -796,30 +1185,51 @@ GNUNET_TESTBED_overlay_configure_topology (void *op_cls, */ void GNUNET_TESTBED_overlay_write_topology_to_file (struct GNUNET_TESTBED_Controller *controller, - const char *filename); + const char *filename); /** * Adapter function called to establish a connection to * a service. - * + * * @param cls closure - * @param cfg configuration of the peer to connect to + * @param cfg configuration of the peer to connect to; will be available until + * GNUNET_TESTBED_operation_done() is called on the operation returned + * from GNUNET_TESTBED_service_connect() * @return service handle to return in 'op_result', NULL on error */ typedef void * (*GNUNET_TESTBED_ConnectAdapter)(void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg); + const struct GNUNET_CONFIGURATION_Handle *cfg); /** * Adapter function called to destroy a connection to * a service. - * + * * @param cls closure * @param op_result service handle returned from the connect adapter */ typedef void (*GNUNET_TESTBED_DisconnectAdapter)(void *cls, - void *op_result); + void *op_result); + + +/** + * Callback to be called when a service connect operation is completed + * + * @param cls the callback closure from functions generating an operation + * @param op the operation that has been finished + * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter() + * @param emsg error message in case the operation has failed; will be NULL if + * operation has executed successfully. + */ +typedef void (*GNUNET_TESTBED_ServiceConnectCompletionCallback) (void *cls, + struct + GNUNET_TESTBED_Operation + *op, + void + *ca_result, + const char + *emsg ); /** @@ -828,14 +1238,16 @@ typedef void (*GNUNET_TESTBED_DisconnectAdapter)(void *cls, * maintain connections with other systems. The actual service * handle is then returned via the 'op_result' member in the event * callback. The 'ca' callback is used to create the connection - * when the time is right; the 'da' callback will be used to + * when the time is right; the 'da' callback will be used to * destroy the connection (upon 'GNUNET_TESTBED_operation_done'). * 'GNUNET_TESTBED_operation_cancel' can be used to abort this * operation until the event callback has been called. * - * @param op_cls closure to pass in operation event + * @param op_cls closure to pass in operation event // FIXME: didn't we say we'd no longer use the global callback for these? -CG * @param peer peer that runs the service * @param service_name name of the service to connect to + * @param cb the callback to call when this operation finishes + * @param cb_cls closure for the above callback * @param ca helper function to establish the connection * @param da helper function to close the connection * @param cada_cls closure for ca and da @@ -843,100 +1255,88 @@ typedef void (*GNUNET_TESTBED_DisconnectAdapter)(void *cls, */ struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_service_connect (void *op_cls, - struct GNUNET_TESTBED_Peer *peer, - const char *service_name, - GNUNET_TESTBED_ConnectAdapter ca, - GNUNET_TESTBED_DisconnectAdapter da, - void *cada_cls); - - -/** - * Cancel a pending operation. Releases all resources - * of the operation and will ensure that no event - * is generated for the operation. Does NOT guarantee - * that the operation will be fully undone (or that - * nothing ever happened). - * - * @param operation operation to cancel - */ -void -GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation); + struct GNUNET_TESTBED_Peer *peer, + const char *service_name, + GNUNET_TESTBED_ServiceConnectCompletionCallback cb, + void *cb_cls, + GNUNET_TESTBED_ConnectAdapter ca, + GNUNET_TESTBED_DisconnectAdapter da, + void *cada_cls); /** - * Signal that the information from an operation has been fully - * processed. This function MUST be called for each event - * of type 'operation_finished' to fully remove the operation - * from the operation queue. After calling this function, the - * 'op_result' becomes invalid (!). - * - * @param operation operation to signal completion for + * This function is used to signal that the event information (struct + * GNUNET_TESTBED_EventInformation) from an operation has been fully processed + * i.e. if the event callback is ever called for this operation. If the event + * callback for this operation has not yet been called, calling this function + * cancels the operation, frees its resources and ensures the no event is + * generated with respect to this operation. Note that however cancelling an + * operation does NOT guarantee that the operation will be fully undone (or that + * nothing ever happened). + * + * This function MUST be called for every operation to fully remove the + * operation from the operation queue. After calling this function, if + * operation is completed and its event information is of type + * GNUNET_TESTBED_ET_OPERATION_FINISHED, the 'op_result' becomes invalid (!). + + * If the operation is generated from GNUNET_TESTBED_service_connect() then + * calling this function on such as operation calls the disconnect adapter if + * the connect adapter was ever called. + * + * @param operation operation to signal completion or cancellation */ void GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation); /** - * Configure and run a testbed using the given - * master controller on 'num_hosts' starting - * 'num_peers' using the given peer configuration. + * Callback function to process statistic values from all peers. * - * @param controller master controller for the testbed - * (must not be destroyed until after the - * testbed is destroyed). - * @param num_hosts number of hosts in 'hosts', 0 to only - * use 'localhost' - * @param hosts list of hosts to use for the testbed - * @param num_peers number of peers to start - * @param peer_cfg peer configuration template to use - * @param underlay_topology underlay topology to create - * @param va topology-specific options - * @return handle to the testbed + * @param cls closure + * @param peer the peer the statistic belong to + * @param subsystem name of subsystem that created the statistic + * @param name the name of the datum + * @param value the current value + * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not + * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration */ -struct GNUNET_TESTBED_Testbed * -GNUNET_TESTBED_create_va (struct GNUNET_TESTBED_Controller *controller, - unsigned int num_hosts, - struct GNUNET_TESTBED_Host **hosts, - unsigned int num_peers, - const struct GNUNET_CONFIGURATION_Handle *peer_cfg, - enum GNUNET_TESTBED_TopologyOption underlay_topology, - va_list va); +typedef int (*GNUNET_TESTBED_StatisticsIterator) (void *cls, + const struct GNUNET_TESTBED_Peer *peer, + const char *subsystem, + const char *name, + uint64_t value, + int is_persistent); /** - * Configure and run a testbed using the given - * master controller on 'num_hosts' starting - * 'num_peers' using the given peer configuration. + * Convenience method that iterates over all (running) peers + * and retrieves all statistics from each peer. * - * @param controller master controller for the testbed - * (must not be destroyed until after the - * testbed is destroyed). - * @param num_hosts number of hosts in 'hosts', 0 to only - * use 'localhost' - * @param hosts list of hosts to use for the testbed - * @param num_peers number of peers to start - * @param peer_cfg peer configuration template to use - * @param underlay_topology underlay topology to create - * @param ... topology-specific options + * @param num_peers number of peers to iterate over + * @param peers array of peers to iterate over + * @param proc processing function for each statistic retrieved + * @param cont continuation to call once call is completed(?) + * @param cls closure to pass to proc and cont + * @return operation handle to cancel the operation */ -struct GNUNET_TESTBED_Testbed * -GNUNET_TESTBED_create (struct GNUNET_TESTBED_Controller *controller, - unsigned int num_hosts, - struct GNUNET_TESTBED_Host **hosts, - unsigned int num_peers, - const struct GNUNET_CONFIGURATION_Handle *peer_cfg, - enum GNUNET_TESTBED_TopologyOption underlay_topology, - ...); +struct GNUNET_TESTBED_Operation * +GNUNET_TESTBED_get_statistics (unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers, + GNUNET_TESTBED_StatisticsIterator proc, + GNUNET_TESTBED_OperationCompletionCallback cont, + void *cls); /** - * Destroy a testbed. Stops all running peers and then - * destroys all peers. Does NOT destroy the master controller. + * Signature of a main function for a testcase. * - * @param testbed testbed to destroy + * @param cls closure + * @param num_peers number of peers in 'peers' + * @param peers handle to peers run in the testbed */ -void -GNUNET_TESTBED_destroy (struct GNUNET_TESTBED_Testbed *testbed); +typedef void (*GNUNET_TESTBED_TestMaster)(void *cls, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers); /** @@ -953,40 +1353,32 @@ GNUNET_TESTBED_destroy (struct GNUNET_TESTBED_Testbed *testbed); * @param host_filename name of the file with the 'hosts', NULL * to run everything on 'localhost' * @param cfg configuration to use (for testbed, controller and peers) - * @param num_peers number of peers to start; FIXME: maybe put that ALSO into cfg? + * @param num_peers number of peers to start; FIXME: maybe put that ALSO into + * cfg?; should be greater than 0 * @param event_mask bit mask with set of events to call 'cc' for; * or-ed values of "1LL" shifted by the * respective 'enum GNUNET_TESTBED_EventType' * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...") - * @param cc controller callback to invoke on events + * @param cc controller callback to invoke on events; This callback is called + * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't + * set in the event_mask as this is the only way get access to the + * handle of each peer * @param cc_cls closure for cc - * @param master task to run once the testbed is ready - * @param master_cls closure for 'task'. + * @param test_master this callback will be called once the test is ready + * @param test_master_cls closure for 'test_master'. */ void GNUNET_TESTBED_run (const char *host_filename, - const struct GNUNET_CONFIGURATION_Handle *cfg, - unsigned int num_peers, - uint64_t event_mask, - GNUNET_TESTBED_ControllerCallback cc, - void *cc_cls, - GNUNET_SCHEDULER_Task master, - void *master_cls); + const struct GNUNET_CONFIGURATION_Handle *cfg, + unsigned int num_peers, + uint64_t event_mask, + GNUNET_TESTBED_ControllerCallback cc, + void *cc_cls, + GNUNET_TESTBED_TestMaster test_master, + void *test_master_cls); /** - * Signature of a main function for a testcase. - * - * @param cls closure - * @param num_peers number of peers in 'peers' - * @param peers handle to peers run in the testbed - */ -typedef void (*GNUNET_TESTBED_TestMaster)(void *cls, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers); - - -/** * Convenience method for running a "simple" test on the local system * with a single call from 'main'. Underlay and overlay topology are * configured using the "UNDERLAY" and "OVERLAY" options in the @@ -1005,16 +1397,29 @@ typedef void (*GNUNET_TESTBED_TestMaster)(void *cls, * @param testname name of the testcase (to configure logging, etc.) * @param cfg_filename configuration filename to use * (for testbed, controller and peers) - * @param num_peers number of peers to start - * @param test_master task to run once the test is ready - * @param test_master_cls closure for 'task'. + * @param num_peers number of peers to start; should be greter than 0 + * @param event_mask bit mask with set of events to call 'cc' for; + * or-ed values of "1LL" shifted by the + * respective 'enum GNUNET_TESTBED_EventType' + * (i.e. "(1LL << GNUNET_TESTBED_ET_CONNECT) || ...") + * @param cc controller callback to invoke on events; This callback is called + * for all peer start events even if GNUNET_TESTBED_ET_PEER_START isn't + * set in the event_mask as this is the only way get access to the + * handle of each peer + * @param cc_cls closure for cc + * @param test_master this callback will be called once the test is ready + * @param test_master_cls closure for 'test_master'. + * @return GNUNET_SYSERR on error, GNUNET_OK on success */ -void +int GNUNET_TESTBED_test_run (const char *testname, - const char *cfg_filename, - unsigned int num_peers, - GNUNET_TESTBED_TestMaster test_master, - void *test_master_cls); + const char *cfg_filename, + unsigned int num_peers, + uint64_t event_mask, + GNUNET_TESTBED_ControllerCallback cc, + void *cc_cls, + GNUNET_TESTBED_TestMaster test_master, + void *test_master_cls); #if 0 /* keep Emacsens' auto-indent happy */ diff --git a/src/include/gnunet_testing_lib-new.h b/src/include/gnunet_testing_lib-new.h deleted file mode 100644 index 9b5f4c2..0000000 --- a/src/include/gnunet_testing_lib-new.h +++ /dev/null @@ -1,299 +0,0 @@ -/* - This file is part of GNUnet - (C) 2008, 2009, 2012 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 include/gnunet_testing_lib-new.h - * @brief convenience API for writing testcases for GNUnet; - * can start/stop one or more peers on a system; - * testing is responsible for managing private keys, - * ports and paths; it is a low-level library that - * does not support higher-level functions such as - * P2P connection, topology management or distributed - * testbed maintenance (those are in gnunet_testbed_service.h) - * @author Christian Grothoff - */ - -#ifndef GNUNET_TESTING_LIB_NEW_H -#define GNUNET_TESTING_LIB_NEW_H - -#include "gnunet_util_lib.h" -#include "gnunet_statistics_service.h" - -#ifdef __cplusplus -extern "C" -{ -#if 0 /* keep Emacsens' auto-indent happy */ -} -#endif -#endif - - -/** - * Handle for a system on which GNUnet peers are executed; - * a system is used for reserving unique paths and ports. - */ -struct GNUNET_TESTING_System; - - -/** - * Handle for a GNUnet peer controlled by testing. - */ -struct GNUNET_TESTING_Peer; - - -/** - * Create a system handle. There must only be one system - * handle per operating system. - * - * @param tmppath prefix path to use for all service homes - * @param controller hostname of the controlling host, - * service configurations are modified to allow - * control connections from this host; can be NULL - * @return handle to this system, NULL on error - */ -struct GNUNET_TESTING_System * -GNUNET_TESTING_system_create (const char *tmppath, - const char *controller); - - - -/** - * Free system resources. - * - * @param system system to be freed - * @param remove_paths should the 'tmppath' and all subdirectories - * be removed (clean up on shutdown)? - */ -void -GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, - int remove_paths); - - -/** - * Testing includes a number of pre-created hostkeys for faster peer - * startup. This function loads such keys into memory from a file. - * - * @param system the testing system handle - * @param filename the path of the hostkeys file - * @return GNUNET_OK on success; GNUNET_SYSERR on error - */ -int -GNUNET_TESTING_hostkeys_load (struct GNUNET_TESTING_System *system, - const char *filename); - - -/** - * Function to remove the loaded hostkeys - * - * @param system the testing system handle - */ -void -GNUNET_TESTING_hostkeys_unload (struct GNUNET_TESTING_System *system); - - -/** - * Testing includes a number of pre-created hostkeys for - * faster peer startup. This function can be used to - * access the n-th key of those pre-created hostkeys; note - * that these keys are ONLY useful for testing and not - * secure as the private keys are part of the public - * GNUnet source code. - * - * This is primarily a helper function used internally - * by 'GNUNET_TESTING_peer_configure'. - * - * @param system the testing system handle - * @param key_number desired pre-created hostkey to obtain - * @param id set to the peer's identity (hash of the public - * key; if NULL, GNUNET_SYSERR is returned immediately - * @return GNUNET_SYSERR on error (not enough keys) - */ -int -GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, - uint32_t key_number, - struct GNUNET_PeerIdentity *id); - - -/** - * Reserve a TCP or UDP port for a peer. - * - * @param system system to use for reservation tracking - * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP - * @return 0 if no free port was available - */ -uint16_t -GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system, - int is_tcp); - - -/** - * Release reservation of a TCP or UDP port for a peer - * (used during GNUNET_TESTING_peer_destroy). - * - * @param system system to use for reservation tracking - * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP - * @param port reserved port to release - */ -void -GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, - int is_tcp, - uint16_t port); - - -/** - * Create a new configuration using the given configuration - * as a template; ports and paths will be modified to select - * available ports on the local system. If we run - * out of "*port" numbers, return SYSERR. - * - * This is primarily a helper function used internally - * by 'GNUNET_TESTING_peer_configure'. - * - * @param system system to use to coordinate resource usage - * @param cfg template configuration to update - * @return GNUNET_OK on success, GNUNET_SYSERR on error - the configuration will - * be incomplete and should not be used there upon - */ -int -GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, - struct GNUNET_CONFIGURATION_Handle *cfg); -// FIXME: add dual to 'release' ports again... - - -/** - * Configure a GNUnet peer. GNUnet must be installed on the local - * system and available in the PATH. - * - * @param system system to use to coordinate resource usage - * @param cfg configuration to use; will be UPDATED (to reflect needed - * changes in port numbers and paths) - * @param key_number number of the hostkey to use for the peer - * @param id identifier for the daemon, will be set, can be NULL - * @param emsg set to error message (set to NULL on success), can be NULL - * @return handle to the peer, NULL on error - */ -struct GNUNET_TESTING_Peer * -GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, - struct GNUNET_CONFIGURATION_Handle *cfg, - uint32_t key_number, - struct GNUNET_PeerIdentity *id, - char **emsg); - - -/** - * Start the peer. - * - * @param peer peer to start - * @return GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer already running) - */ -int -GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer); - - -/** - * Stop the peer. - * - * @param peer peer to stop - * @return GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer not running) - */ -int -GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer); - - -/** - * Destroy the peer. Releases resources locked during peer configuration. - * If the peer is still running, it will be stopped AND a warning will be - * printed (users of the API should stop the peer explicitly first). - * - * @param peer peer to destroy - */ -void -GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer); - - -/** - * Signature of the 'main' function for a (single-peer) testcase that - * is run using 'GNUNET_TESTING_peer_run'. - * - * @param cls closure - * @param cfg configuration of the peer that was started - */ -typedef void (*GNUNET_TESTING_TestMain)(void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg); - - -/** - * Start a single peer and run a test using the testing library. - * Starts a peer using the given configuration and then invokes the - * given callback. This function ALSO initializes the scheduler loop - * and should thus be called directly from "main". The testcase - * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'. - * - * @param tmppath path for storing temporary data for the test - * @param cfgfilename name of the configuration file to use; - * use NULL to only run with defaults - * @param tm main function of the testcase - * @param tm_cls closure for 'tm' - * @return 0 on success, 1 on error - */ -int -GNUNET_TESTING_peer_run (const char *tmppath, - const char *cfgfilename, - GNUNET_TESTING_TestMain tm, - void *tm_cls); - - - -/** - * Start a single service (no ARM, except of course if the given - * service name is 'arm') and run a test using the testing library. - * Starts a service using the given configuration and then invokes the - * given callback. This function ALSO initializes the scheduler loop - * and should thus be called directly from "main". The testcase - * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'. - * - * This function is useful if the testcase is for a single service - * and if that service doesn't itself depend on other services. - * - * @param tmppath path for storing temporary data for the test - * @param service_name name of the service to run - * @param cfgfilename name of the configuration file to use; - * use NULL to only run with defaults - * @param tm main function of the testcase - * @param tm_cls closure for 'tm' - * @return 0 on success, 1 on error - */ -int -GNUNET_TESTING_service_run (const char *tmppath, - const char *service_name, - const char *cfgfilename, - GNUNET_TESTING_TestMain tm, - void *tm_cls); - - - -#if 0 /* keep Emacsens' auto-indent happy */ -{ -#endif -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h index b170670..04a3e99 100644 --- a/src/include/gnunet_testing_lib.h +++ b/src/include/gnunet_testing_lib.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet - (C) 2008, 2009 Christian Grothoff (and other contributing authors) + (C) 2008, 2009, 2012 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 @@ -20,12 +20,13 @@ /** * @file include/gnunet_testing_lib.h - * @brief convenience API for writing testcases for GNUnet - * Many testcases need to start and stop gnunetd, - * and this library is supposed to make that easier - * for TESTCASES. Normal programs should always - * use functions from gnunet_{util,arm}_lib.h. This API is - * ONLY for writing testcases! + * @brief convenience API for writing testcases for GNUnet; + * can start/stop one or more peers on a system; + * testing is responsible for managing private keys, + * ports and paths; it is a low-level library that + * does not support higher-level functions such as + * P2P connection, topology management or distributed + * testbed maintenance (those are in gnunet_testbed_service.h) * @author Christian Grothoff */ @@ -43,1207 +44,319 @@ extern "C" #endif #endif -#define HOSTKEYFILESIZE 914 +#define GNUNET_TESTING_HOSTKEYFILESIZE 914 /** - * Handle for a GNUnet daemon (technically a set of - * daemons; the handle is really for the master ARM - * daemon) started by the testing library. + * Handle for a system on which GNUnet peers are executed; + * a system is used for reserving unique paths and ports. */ -struct GNUNET_TESTING_Daemon; - -/** - * Linked list of hostnames and ports to use for starting daemons. - */ -struct GNUNET_TESTING_Host -{ - /** - * Pointer to next item in the list. - */ - struct GNUNET_TESTING_Host *next; - - /** - * Hostname to connect to. - */ - char *hostname; - - /** - * Username to use when connecting (may be null). - */ - char *username; - - /** - * Port to use for SSH connection (used for ssh - * connection forwarding, 0 to let ssh decide) - */ - uint16_t port; -}; - -/** - * Prototype of a function that will be called whenever - * a daemon was started by the testing library. - * - * @param cls closure - * @param id identifier for the daemon, NULL on error - * @param d handle for the daemon - * @param emsg error message (NULL on success) - */ -typedef void (*GNUNET_TESTING_NotifyHostkeyCreated) (void *cls, - const struct - GNUNET_PeerIdentity * id, - struct - GNUNET_TESTING_Daemon * d, - const char *emsg); - -/** - * Prototype of a function that will be called whenever - * a daemon was started by the testing library. - * - * @param cls closure - * @param id identifier for the daemon, NULL on error - * @param cfg configuration used by this daemon - * @param d handle for the daemon - * @param emsg error message (NULL on success) - */ -typedef void (*GNUNET_TESTING_NotifyDaemonRunning) (void *cls, - const struct - GNUNET_PeerIdentity * id, - const struct - GNUNET_CONFIGURATION_Handle - * cfg, - struct GNUNET_TESTING_Daemon - * d, const char *emsg); - -/** - * Handle to an entire testbed of GNUnet peers. - */ -struct GNUNET_TESTING_Testbed; - -/** - * Phases of starting GNUnet on a system. - */ -enum GNUNET_TESTING_StartPhase -{ - /** - * Copy the configuration file to the target system. - */ - SP_COPYING, - - /** - * Configuration file has been copied, generate hostkey. - */ - SP_COPIED, - - /** - * Create the hostkey for the peer. - */ - SP_HOSTKEY_CREATE, - - /** - * Hostkey generated, wait for topology to be finished. - */ - SP_HOSTKEY_CREATED, - - /** - * Topology has been created, now start ARM. - */ - SP_TOPOLOGY_SETUP, - - /** - * ARM has been started, check that it has properly daemonized and - * then try to connect to the CORE service (which should be - * auto-started by ARM). - */ - SP_START_ARMING, - - /** - * We're waiting for CORE to start. - */ - SP_START_CORE, - - /** - * CORE is up, now make sure we get the HELLO for this peer. - */ - SP_GET_HELLO, - - /** - * Core has notified us that we've established a connection to the service. - * The main FSM halts here and waits to be moved to UPDATE or CLEANUP. - */ - SP_START_DONE, - - /** - * We've been asked to terminate the instance and are now waiting for - * the remote command to stop the gnunet-arm process and delete temporary - * files. - */ - SP_SHUTDOWN_START, - - /** - * We should shutdown a *single* service via gnunet-arm. Call the dead_cb - * upon notification from gnunet-arm that the service has been stopped. - */ - SP_SERVICE_SHUTDOWN_START, - - /** - * We should start a *single* service via gnunet-arm. Call the daemon cb - * upon notification from gnunet-arm that the service has been started. - */ - SP_SERVICE_START, - - /** - * We've received a configuration update and are currently waiting for - * the copy process for the update to complete. Once it is, we will - * return to "SP_START_DONE" (and rely on ARM to restart all affected - * services). - */ - SP_CONFIG_UPDATE -}; - -/** - * Prototype of a function that will be called when a - * particular operation was completed the testing library. - * - * @param cls closure - * @param emsg NULL on success - */ -typedef void (*GNUNET_TESTING_NotifyCompletion) (void *cls, const char *emsg); - -/** - * Prototype of a function that will be called with the - * number of connections created for a particular topology. - * - * @param cls closure - * @param num_connections the number of connections created - */ -typedef void (*GNUNET_TESTING_NotifyConnections) (void *cls, - unsigned int num_connections); - -/** - * Handle for a GNUnet daemon (technically a set of - * daemons; the handle is really for the master ARM - * daemon) started by the testing library. - */ -struct GNUNET_TESTING_Daemon -{ - /** - * Our configuration. - */ - struct GNUNET_CONFIGURATION_Handle *cfg; - - /** - * At what time to give up starting the peer - */ - struct GNUNET_TIME_Absolute max_timeout; - - /** - * Host to run GNUnet on. - */ - char *hostname; - - /** - * Port to use for ssh, NULL to let system choose default. - */ - char *ssh_port_str; - - /** - * Result of GNUNET_i2s of this peer, - * for printing - */ - char *shortname; - - /** - * Username we are using. - */ - char *username; - - /** - * Name of the configuration file - */ - char *cfgfile; - - /** - * Callback to inform initiator that the peer's - * hostkey has been created. - */ - GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback; - - /** - * Closure for hostkey creation callback. - */ - void *hostkey_cls; - - /** - * Function to call when the peer is running. - */ - GNUNET_TESTING_NotifyDaemonRunning cb; - - /** - * Closure for cb. - */ - void *cb_cls; - - /** - * Arguments from "daemon_stop" call. - */ - GNUNET_TESTING_NotifyCompletion dead_cb; - - /** - * Closure for 'dead_cb'. - */ - void *dead_cb_cls; - - /** - * Arguments from "daemon_stop" call. - */ - GNUNET_TESTING_NotifyCompletion update_cb; - - /** - * Closure for 'update_cb'. - */ - void *update_cb_cls; - - /** - * PID of the process we used to run gnunet-arm or SSH to start the peer. - */ - struct GNUNET_OS_Process *proc_arm_start; - - /** - * PID of the process we used to run gnunet-arm or SSH to stop the peer. - */ - struct GNUNET_OS_Process *proc_arm_stop; - - /** - * PID of the process we used to run gnunet-arm or SSH to manage services at the peer. - */ - struct GNUNET_OS_Process *proc_arm_srv_start; - - /** - * PID of the process we used to run gnunet-arm or SSH to manage services at the peer. - */ - struct GNUNET_OS_Process *proc_arm_srv_stop; - - /** - * PID of the process we used to run copy files - */ - struct GNUNET_OS_Process *proc_arm_copying; - - /** - * PID of the process we used to run gnunet-peerinfo. - */ - struct GNUNET_OS_Process *proc_arm_peerinfo; - - /** - * Handle to the server. - */ - struct GNUNET_CORE_Handle *server; - - /** - * Handle to the transport service of this peer - */ - struct GNUNET_TRANSPORT_Handle *th; - - /** - * Handle for getting HELLOs from transport - */ - struct GNUNET_TRANSPORT_GetHelloHandle *ghh; - - /** - * HELLO message for this peer - */ - struct GNUNET_HELLO_Message *hello; - - /** - * Handle to a pipe for reading the hostkey. - */ - struct GNUNET_DISK_PipeHandle *pipe_stdout; - - /** - * Currently, a single char * pointing to a service - * that has been churned off. - * - * FIXME: make this a linked list of services that have been churned off!!! - */ - char *churned_services; - - /** - * ID of the current task. - */ - GNUNET_SCHEDULER_TaskIdentifier task; - - /** - * Identity of this peer (once started). - */ - struct GNUNET_PeerIdentity id; - - /** - * Flag to indicate that we've already been asked - * to terminate (but could not because some action - * was still pending). - */ - int dead; - - /** - * GNUNET_YES if the hostkey has been created - * for this peer, GNUNET_NO otherwise. - */ - int have_hostkey; - - /** - * In which phase are we during the start of - * this process? - */ - enum GNUNET_TESTING_StartPhase phase; - - /** - * Current position in 'hostkeybuf' (for reading from gnunet-peerinfo) - */ - unsigned int hostkeybufpos; - - /** - * Set to GNUNET_YES once the peer is up. - */ - int running; - - /** - * Used to tell shutdown not to remove configuration for the peer - * (if it's going to be restarted later) - */ - int churn; - - /** - * Output from gnunet-peerinfo is read into this buffer. - */ - char hostkeybuf[105]; - -}; +struct GNUNET_TESTING_System; /** - * Handle to a group of GNUnet peers. + * Handle for a GNUnet peer controlled by testing. */ -struct GNUNET_TESTING_PeerGroup; +struct GNUNET_TESTING_Peer; /** - * Prototype of a function that will be called whenever - * two daemons are connected by the testing library. + * Create a system handle. There must only be one system handle per operating + * system. Uses a default range for allowed ports. Ports are still tested for + * availability. * - * @param cls closure - * @param first peer id for first daemon - * @param second peer id for the second daemon - * @param distance distance between the connected peers - * @param first_cfg config for the first daemon - * @param second_cfg config for the second daemon - * @param first_daemon handle for the first daemon - * @param second_daemon handle for the second daemon - * @param emsg error message (NULL on success) + * @param testdir only the directory name without any path. This is used for all + * service homes; the directory will be created in a temporary location + * depending on the underlying OS + * @param trusted_ip the ip address which will be set as TRUSTED HOST in all + * service configurations generated to allow control connections from + * this ip. This can either be a single ip address or a network address + * in CIDR notation. + * @param hostname the hostname of the system we are using for testing; NULL for + * localhost + * @return handle to this system, NULL on error */ -typedef void (*GNUNET_TESTING_NotifyConnection) (void *cls, - const struct - GNUNET_PeerIdentity * first, - const struct - GNUNET_PeerIdentity * second, - uint32_t distance, - const struct - GNUNET_CONFIGURATION_Handle * - first_cfg, - const struct - GNUNET_CONFIGURATION_Handle * - second_cfg, - struct GNUNET_TESTING_Daemon * - first_daemon, - struct GNUNET_TESTING_Daemon * - second_daemon, - const char *emsg); +struct GNUNET_TESTING_System * +GNUNET_TESTING_system_create (const char *testdir, + const char *trusted_ip, + const char *hostname); /** - * Prototype of a callback function indicating that two peers - * are currently connected. + * Create a system handle. There must only be one system + * handle per operating system. Use this function directly + * if multiple system objects are created for the same host + * (only really useful when testing --- or to make the port + * range configureable). * - * @param cls closure - * @param first peer id for first daemon - * @param second peer id for the second daemon - * @param distance distance between the connected peers - * @param emsg error message (NULL on success) + * @param testdir only the directory name without any path. This is used for + * all service homes; the directory will be created in a temporary + * location depending on the underlying OS + * @param trusted_ip the ip address which will be set as TRUSTED HOST in all + * service configurations generated to allow control connections from + * this ip. This can either be a single ip address or a network address + * in CIDR notation. + * @param hostname the hostname of the system we are using for testing; NULL for + * localhost + * @param lowport lowest port number this system is allowed to allocate (inclusive) + * @param highport highest port number this system is allowed to allocate (exclusive) + * @return handle to this system, NULL on error */ -typedef void (*GNUNET_TESTING_NotifyTopology) (void *cls, - const struct GNUNET_PeerIdentity - * first, - const struct GNUNET_PeerIdentity - * second, const char *emsg); - +struct GNUNET_TESTING_System * +GNUNET_TESTING_system_create_with_portrange (const char *testdir, + const char *trusted_ip, + const char *hostname, + uint16_t lowport, + uint16_t highport); -/** - * Starts a GNUnet daemon. GNUnet must be installed on the target - * system and available in the PATH. The machine must furthermore be - * reachable via "ssh" (unless the hostname is "NULL") without the - * need to enter a password. - * - * @param cfg configuration to use - * @param timeout how long to wait starting up peers - * @param pretend GNUNET_YES to set up files but not start peer GNUNET_NO - * to really start the peer (default) - * @param hostname name of the machine where to run GNUnet - * (use NULL for localhost). - * @param ssh_username ssh username to use when connecting to hostname - * @param sshport port to pass to ssh process when connecting to hostname - * @param hostkey pointer to a hostkey to be written to disk (instead of being generated) - * @param hostkey_callback function to call once the hostkey has been - * generated for this peer, but it hasn't yet been started - * (NULL to start immediately, otherwise waits on GNUNET_TESTING_daemon_continue_start) - * @param hostkey_cls closure for hostkey callback - * @param cb function to call once peer is up, or failed to start - * @param cb_cls closure for cb - * @return handle to the daemon (actual start will be completed asynchronously) - */ -struct GNUNET_TESTING_Daemon * -GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TIME_Relative timeout, int pretend, - const char *hostname, const char *ssh_username, - uint16_t sshport, const char *hostkey, - GNUNET_TESTING_NotifyHostkeyCreated - hostkey_callback, void *hostkey_cls, - GNUNET_TESTING_NotifyDaemonRunning cb, - void *cb_cls); /** - * Continues GNUnet daemon startup when user wanted to be notified - * once a hostkey was generated (for creating friends files, blacklists, - * etc.). + * Free system resources. * - * @param daemon the daemon to finish starting + * @param system system to be freed + * @param remove_paths should the 'testdir' and all subdirectories + * be removed (clean up on shutdown)? */ void -GNUNET_TESTING_daemon_continue_startup (struct GNUNET_TESTING_Daemon *daemon); +GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, + int remove_paths); /** - * Check whether the given daemon is running. + * Testing includes a number of pre-created hostkeys for + * faster peer startup. This function can be used to + * access the n-th key of those pre-created hostkeys; note + * that these keys are ONLY useful for testing and not + * secure as the private keys are part of the public + * GNUnet source code. * - * @param daemon the daemon to check - * @return GNUNET_YES if the daemon is up, GNUNET_NO if the - * daemon is down, GNUNET_SYSERR on error. - */ -int -GNUNET_TESTING_test_daemon_running (struct GNUNET_TESTING_Daemon *daemon); - - -/** - * Obtain the peer identity of the peer with the given configuration - * handle. This function reads the private key of the peer, obtains - * the public key and hashes it. - * - * @param cfg configuration of the peer - * @param pid where to store the peer identity - * @return GNUNET_OK on success, GNUNET_SYSERR on failure - */ -int -GNUNET_TESTING_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_PeerIdentity *pid); - - -/** - * Restart (stop and start) a GNUnet daemon. + * This is primarily a helper function used internally + * by 'GNUNET_TESTING_peer_configure'. * - * @param d the daemon that should be restarted - * @param cb function called once the daemon is (re)started - * @param cb_cls closure for cb + * @param system the testing system handle + * @param key_number desired pre-created hostkey to obtain + * @param id set to the peer's identity (hash of the public + * key; if NULL, GNUNET_SYSERR is returned immediately + * @return NULL on error (not enough keys) */ -void -GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, - GNUNET_TESTING_NotifyDaemonRunning cb, - void *cb_cls); +struct GNUNET_CRYPTO_RsaPrivateKey * +GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, + uint32_t key_number, + struct GNUNET_PeerIdentity *id); /** - * Start a peer that has previously been stopped using the daemon_stop - * call (and files weren't deleted and the allow restart flag) + * Reserve a TCP or UDP port for a peer. * - * @param daemon the daemon to start (has been previously stopped) - * @param timeout how long to wait for restart - * @param cb the callback for notification when the peer is running - * @param cb_cls closure for the callback + * @param system system to use for reservation tracking + * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP + * @return 0 if no free port was available */ -void -GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon, - struct GNUNET_TIME_Relative timeout, - GNUNET_TESTING_NotifyDaemonRunning cb, - void *cb_cls); +uint16_t +GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system, + int is_tcp); /** - * Starts a GNUnet daemon's service. + * Release reservation of a TCP or UDP port for a peer + * (used during GNUNET_TESTING_peer_destroy). * - * @param d the daemon for which the service should be started - * @param service the name of the service to start - * @param timeout how long to wait for process for startup - * @param cb function called once gnunet-arm returns - * @param cb_cls closure for cb + * @param system system to use for reservation tracking + * @param is_tcp GNUNET_YES for TCP ports, GNUNET_NO for UDP + * @param port reserved port to release */ void -GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d, - const char *service, - struct GNUNET_TIME_Relative timeout, - GNUNET_TESTING_NotifyDaemonRunning cb, - void *cb_cls); +GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, + int is_tcp, + uint16_t port); /** - * Starts a GNUnet daemon's service which has been previously turned off. + * Create a new configuration using the given configuration as a template; + * ports and paths will be modified to select available ports on the local + * system. The default configuration will be available in PATHS section under + * the option DEFAULTCONFIG after the call. SERVICE_HOME is also set in PATHS + * section to the temporary directory specific to this configuration. If we run + * out of "*port" numbers, return SYSERR. * - * @param d the daemon for which the service should be started - * @param service the name of the service to start - * @param timeout how long to wait for process for startup - * @param cb function called once gnunet-arm returns - * @param cb_cls closure for cb - */ -void -GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d, - char *service, - struct GNUNET_TIME_Relative - timeout, - GNUNET_TESTING_NotifyDaemonRunning - cb, void *cb_cls); - - -/** - * Get a certain testing daemon handle. + * This is primarily a helper function used internally + * by 'GNUNET_TESTING_peer_configure'. * - * @param pg handle to the set of running peers - * @param position the number of the peer to return + * @param system system to use to coordinate resource usage + * @param cfg template configuration to update + * @return GNUNET_OK on success, GNUNET_SYSERR on error - the configuration will + * be incomplete and should not be used there upon */ -struct GNUNET_TESTING_Daemon * -GNUNET_TESTING_daemon_get (struct GNUNET_TESTING_PeerGroup *pg, - unsigned int position); - - -/** - * Get a daemon by peer identity, so callers can - * retrieve the daemon without knowing it's offset. - * - * @param pg the peer group to retrieve the daemon from - * @param peer_id the peer identity of the daemon to retrieve - * - * @return the daemon on success, or NULL if no such peer identity is found - */ -struct GNUNET_TESTING_Daemon * -GNUNET_TESTING_daemon_get_by_id (struct GNUNET_TESTING_PeerGroup *pg, - const struct GNUNET_PeerIdentity *peer_id); - - -/** - * Stops a GNUnet daemon. - * - * @param d the daemon that should be stopped - * @param timeout how long to wait for process for shutdown to complete - * @param cb function called once the daemon was stopped - * @param cb_cls closure for cb - * @param delete_files GNUNET_YES to remove files, GNUNET_NO - * to leave them (i.e. for restarting at a later time, - * or logfile inspection once finished) - * @param allow_restart GNUNET_YES to restart peer later (using this API) - * GNUNET_NO to kill off and clean up for good - */ -void -GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, - struct GNUNET_TIME_Relative timeout, - GNUNET_TESTING_NotifyCompletion cb, void *cb_cls, - int delete_files, int allow_restart); - - - -/** - * Create a new configuration using the given configuration - * as a template; however, each PORT in the existing cfg - * must be renumbered by incrementing "*port". If we run - * out of "*port" numbers, return NULL. - * - * @param cfg template configuration - * @param off the current peer offset - * @param port port numbers to use, update to reflect - * port numbers that were used - * @param upnum number to make unix domain socket names unique - * @param hostname hostname of the controlling host, to allow control connections from - * @param fdnum number used to offset the unix domain socket for grouped processes - * (such as statistics or peerinfo, which can be shared among others) - * - * @return new configuration, NULL on error - */ -struct GNUNET_CONFIGURATION_Handle * -GNUNET_TESTING_create_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t off, - uint16_t * port, uint32_t * upnum, const char *hostname, - uint32_t * fdnum); - -/** - * Changes the configuration of a GNUnet daemon. - * - * @param d the daemon that should be modified - * @param cfg the new configuration for the daemon - * @param cb function called once the configuration was changed - * @param cb_cls closure for cb - */ -void -GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d, - struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_TESTING_NotifyCompletion cb, - void *cb_cls); - - -/** - * Stops a single service of a GNUnet daemon. Used like daemon_stop, - * only doesn't stop the entire peer in any case. If the service - * is not currently running, this call is likely to fail after - * timeout! - * - * @param d the daemon that should be stopped - * @param service the name of the service to stop - * @param timeout how long to wait for process for shutdown to complete - * @param cb function called once the service was stopped - * @param cb_cls closure for cb - */ -void -GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d, - const char *service, - struct GNUNET_TIME_Relative timeout, - GNUNET_TESTING_NotifyCompletion cb, - void *cb_cls); - - -/** - * Read a testing hosts file based on a configuration. - * Returns a DLL of hosts (caller must free!) on success - * or NULL on failure. - * - * @param cfg a configuration with a testing section - * - * @return DLL of hosts on success, NULL on failure - */ -struct GNUNET_TESTING_Host * -GNUNET_TESTING_hosts_load (const struct GNUNET_CONFIGURATION_Handle *cfg); - - -/** - * Start count gnunet instances with the same set of transports and - * applications. The port numbers (any option called "PORT") will be - * adjusted to ensure that no two peers running on the same system - * have the same port(s) in their respective configurations. - * - * @param cfg configuration template to use - * @param total number of daemons to start - * @param max_concurrent_connections for testing, how many peers can -* we connect to simultaneously - * @param max_concurrent_ssh when starting with ssh, how many ssh - * connections will we allow at once (based on remote hosts allowed!) - * @param timeout total time allowed for peers to start - * @param hostkey_callback function to call on each peers hostkey generation - * if NULL, peers will be started by this call, if non-null, - * GNUNET_TESTING_daemons_continue_startup must be called after - * successful hostkey generation - * @param hostkey_cls closure for hostkey callback - * @param cb function to call on each daemon that was started - * @param cb_cls closure for cb - * @param connect_callback function to call each time two hosts are connected - * @param connect_callback_cls closure for connect_callback - * @param hostnames linked list of host structs to use to start peers on - * (NULL to run on localhost only) - * - * @return NULL on error, otherwise handle to control peer group - */ -struct GNUNET_TESTING_PeerGroup * -GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, - unsigned int total, - unsigned int max_concurrent_connections, - unsigned int max_concurrent_ssh, - struct GNUNET_TIME_Relative timeout, - GNUNET_TESTING_NotifyHostkeyCreated - hostkey_callback, void *hostkey_cls, - GNUNET_TESTING_NotifyDaemonRunning cb, - void *cb_cls, - GNUNET_TESTING_NotifyConnection connect_callback, - void *connect_callback_cls, - const struct GNUNET_TESTING_Host *hostnames); - - -/** - * Function which continues a peer group starting up - * after successfully generating hostkeys for each peer. - * - * @param pg the peer group to continue starting - */ -void -GNUNET_TESTING_daemons_continue_startup (struct GNUNET_TESTING_PeerGroup *pg); - - -/** - * Handle for an active request to connect two peers. - */ -struct GNUNET_TESTING_ConnectContext; - - -/** - * Establish a connection between two GNUnet daemons. The daemons - * must both be running and not be stopped until either the - * 'cb' callback is called OR the connection request has been - * explicitly cancelled. - * - * @param d1 handle for the first daemon - * @param d2 handle for the second daemon - * @param timeout how long is the connection attempt - * allowed to take? - * @param max_connect_attempts how many times should we try to reconnect - * (within timeout) - * @param send_hello GNUNET_YES to send the HELLO, GNUNET_NO to assume - * the HELLO has already been exchanged - * @param cb function to call at the end - * @param cb_cls closure for cb - * @return handle to cancel the request, NULL on error - */ -struct GNUNET_TESTING_ConnectContext * -GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, - struct GNUNET_TESTING_Daemon *d2, - struct GNUNET_TIME_Relative timeout, - unsigned int max_connect_attempts, - int send_hello, - GNUNET_TESTING_NotifyConnection cb, - void *cb_cls); - - - -/** - * Cancel an attempt to connect two daemons. - * - * @param cc connect context - */ -void -GNUNET_TESTING_daemons_connect_cancel (struct GNUNET_TESTING_ConnectContext - *cc); - +int +GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, + struct GNUNET_CONFIGURATION_Handle *cfg); +// FIXME: add dual to 'release' ports again... /** - * Restart all peers in the given group. + * Configure a GNUnet peer. GNUnet must be installed on the local + * system and available in the PATH. * - * @param pg the handle to the peer group - * @param callback function to call on completion (or failure) - * @param callback_cls closure for the callback function + * @param system system to use to coordinate resource usage + * @param cfg configuration to use; will be UPDATED (to reflect needed + * changes in port numbers and paths) + * @param key_number number of the hostkey to use for the peer + * @param id identifier for the daemon, will be set, can be NULL + * @param emsg set to freshly allocated error message (set to NULL on success), + * can be NULL + * @return handle to the peer, NULL on error */ -void -GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg, - GNUNET_TESTING_NotifyCompletion callback, - void *callback_cls); +struct GNUNET_TESTING_Peer * +GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, + struct GNUNET_CONFIGURATION_Handle *cfg, + uint32_t key_number, + struct GNUNET_PeerIdentity *id, + char **emsg); /** - * Shutdown all peers started in the given group. + * Obtain the peer identity from a peer handle. * - * @param pg handle to the peer group - * @param timeout how long to wait for shutdown - * @param cb callback to notify upon success or failure - * @param cb_cls closure for cb + * @param peer peer handle for which we want the peer's identity + * @param id identifier for the daemon, will be set */ void -GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, - struct GNUNET_TIME_Relative timeout, - GNUNET_TESTING_NotifyCompletion cb, void *cb_cls); +GNUNET_TESTING_peer_get_identity (const struct GNUNET_TESTING_Peer *peer, + struct GNUNET_PeerIdentity *id); /** - * Count the number of running peers. - * - * @param pg handle for the peer group + * Start the peer. * - * @return the number of currently running peers in the peer group + * @param peer peer to start + * @return GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer already running) */ -unsigned int -GNUNET_TESTING_daemons_running (struct GNUNET_TESTING_PeerGroup *pg); - - -/** - * Simulate churn by stopping some peers (and possibly - * re-starting others if churn is called multiple times). This - * function can only be used to create leave-join churn (peers "never" - * leave for good). First "voff" random peers that are currently - * online will be taken offline; then "von" random peers that are then - * offline will be put back online. No notifications will be - * generated for any of these operations except for the callback upon - * completion. Note that the implementation is at liberty to keep - * the ARM service itself (but none of the other services or daemons) - * running even though the "peer" is being varied offline. - * - * @param pg handle for the peer group - * @param service the service to churn on/off, NULL for all - * @param voff number of peers that should go offline - * @param von number of peers that should come back online; - * must be zero on first call (since "testbed_start" - * always starts all of the peers) - * @param timeout how long to wait for operations to finish before - * giving up - * @param cb function to call at the end - * @param cb_cls closure for cb - */ -void -GNUNET_TESTING_daemons_churn (struct GNUNET_TESTING_PeerGroup *pg, - char *service, unsigned int voff, - unsigned int von, - struct GNUNET_TIME_Relative timeout, - GNUNET_TESTING_NotifyCompletion cb, void *cb_cls); - - -/** - * Start a given service for each of the peers in the peer group. - * - * @param pg handle for the peer group - * @param service the service to start - * @param timeout how long to wait for operations to finish before - * giving up - * @param cb function to call once finished - * @param cb_cls closure for cb - * - */ -void -GNUNET_TESTING_daemons_start_service (struct GNUNET_TESTING_PeerGroup *pg, - char *service, - struct GNUNET_TIME_Relative timeout, - GNUNET_TESTING_NotifyCompletion cb, - void *cb_cls); +int +GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer); /** - * Callback function to process statistic values. + * Stop the peer. * - * @param cls closure - * @param peer the peer the statistics belong to - * @param subsystem name of subsystem that created the statistic - * @param name the name of the datum - * @param value the current value - * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not - * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration + * @param peer peer to stop + * @return GNUNET_OK on success, GNUNET_SYSERR on error (i.e. peer not running) */ -typedef int (*GNUNET_TESTING_STATISTICS_Iterator) (void *cls, - const struct - GNUNET_PeerIdentity * peer, - const char *subsystem, - const char *name, - uint64_t value, - int is_persistent); +int +GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer); /** - * Iterate over all (running) peers in the peer group, retrieve - * all statistics from each. + * Destroy the peer. Releases resources locked during peer configuration. + * If the peer is still running, it will be stopped AND a warning will be + * printed (users of the API should stop the peer explicitly first). * - * @param pg the peergroup to iterate statistics of - * @param cont continuation to call once call is completed(?) - * @param proc processing function for each statistic retrieved - * @param cls closure to pass to proc + * @param peer peer to destroy */ void -GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg, - GNUNET_STATISTICS_Callback cont, - GNUNET_TESTING_STATISTICS_Iterator proc, - void *cls); +GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer); /** - * Topologies supported for testbeds. - */ -enum GNUNET_TESTING_Topology -{ - /** - * A clique (everyone connected to everyone else). - */ - GNUNET_TESTING_TOPOLOGY_CLIQUE, - - /** - * Small-world network (2d torus plus random links). - */ - GNUNET_TESTING_TOPOLOGY_SMALL_WORLD, - - /** - * Small-world network (ring plus random links). - */ - GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING, - - /** - * Ring topology. - */ - GNUNET_TESTING_TOPOLOGY_RING, - - /** - * 2-d torus. - */ - GNUNET_TESTING_TOPOLOGY_2D_TORUS, - - /** - * Random graph. - */ - GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI, - - /** - * Certain percentage of peers are unable to communicate directly - * replicating NAT conditions - */ - GNUNET_TESTING_TOPOLOGY_INTERNAT, - - /** - * Scale free topology. - */ - GNUNET_TESTING_TOPOLOGY_SCALE_FREE, - - /** - * Straight line topology. - */ - GNUNET_TESTING_TOPOLOGY_LINE, - - /** - * All peers are disconnected. - */ - GNUNET_TESTING_TOPOLOGY_NONE, - - /** - * Read a topology from a given file. - */ - GNUNET_TESTING_TOPOLOGY_FROM_FILE -}; - -/** - * Options for connecting a topology. - */ -enum GNUNET_TESTING_TopologyOption -{ - /** - * Try to connect all peers specified in the topology. - */ - GNUNET_TESTING_TOPOLOGY_OPTION_ALL, - - /** - * Choose a random subset of connections to create. - */ - GNUNET_TESTING_TOPOLOGY_OPTION_RANDOM, - - /** - * Create at least X connections for each peer. - */ - GNUNET_TESTING_TOPOLOGY_OPTION_MINIMUM, - - /** - * Using a depth first search, create one connection - * per peer. If any are missed (graph disconnected) - * start over at those peers until all have at least one - * connection. - */ - GNUNET_TESTING_TOPOLOGY_OPTION_DFS, - - /** - * Find the N closest peers to each allowed peer in the - * topology and make sure a connection to those peers - * exists in the connect topology. - */ - GNUNET_TESTING_TOPOLOGY_OPTION_ADD_CLOSEST, - - /** - * No options specified. - */ - GNUNET_TESTING_TOPOLOGY_OPTION_NONE -}; - - -/** - * Get a topology from a string input. + * Sends SIGTERM to the peer's main process * - * @param topology where to write the retrieved topology - * @param topology_string The string to attempt to - * get a configuration value from - * @return GNUNET_YES if topology string matched a - * known topology, GNUNET_NO if not + * @param peer the handle to the peer + * @return GNUNET_OK if successful; GNUNET_SYSERR if the main process is NULL + * or upon any error while sending SIGTERM */ int -GNUNET_TESTING_topology_get (enum GNUNET_TESTING_Topology *topology, - const char *topology_string); +GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer); /** - * Get connect topology option from string input. + * Waits for a peer to terminate. The peer's main process will also be destroyed. * - * @param topology_option where to write the retrieved topology - * @param topology_string The string to attempt to - * get a configuration value from - * @return GNUNET_YES if topology string matched a - * known topology, GNUNET_NO if not + * @param peer the handle to the peer + * @return GNUNET_OK if successful; GNUNET_SYSERR if the main process is NULL + * or upon any error while waiting */ int -GNUNET_TESTING_topology_option_get (enum GNUNET_TESTING_TopologyOption - *topology_option, - const char *topology_string); - - -/** - * Takes a peer group and creates a topology based on the - * one specified. Creates a topology means generates friend - * files for the peers so they can only connect to those allowed - * by the topology. This will only have an effect once peers - * are started if the FRIENDS_ONLY option is set in the base - * config. - * - * Also takes an optional restrict topology which - * disallows direct connections UNLESS they are specified in - * the restricted topology. - * - * A simple example; if the topology option is set to LINE - * peers can ONLY connect in a LINE. However, if the topology - * option is set to 2D-torus and the restrict option is set to - * line with restrict_transports equal to "tcp udp", then peers - * may connect in a 2D-torus, but will be restricted to tcp and - * udp connections only in a LINE. Generally it only makes - * sense to do this if restrict_topology is a subset of topology. - * - * For testing peer discovery, etc. it is generally better to - * leave restrict_topology as GNUNET_TESTING_TOPOLOGY_NONE and - * then use the connect_topology function to restrict the initial - * connection set. - * - * @param pg the peer group struct representing the running peers - * @param topology which topology to connect the peers in - * @param restrict_topology allow only direct connections in this topology, - * based on those listed in restrict_transports, set to - * GNUNET_TESTING_TOPOLOGY_NONE for no restrictions - * @param restrict_transports space delimited list of transports to blacklist - * to create restricted topology, NULL for none - * - * @return the maximum number of connections were all allowed peers - * connected to each other - */ -unsigned int -GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, - enum GNUNET_TESTING_Topology topology, - enum GNUNET_TESTING_Topology restrict_topology, - const char *restrict_transports); - - -/** - * Iterate over all (running) peers in the peer group, retrieve - * all connections that each currently has. - * - * @param pg the peer group we are concerned with - * @param cb callback for topology information - * @param cls closure for callback - */ -void -GNUNET_TESTING_get_topology (struct GNUNET_TESTING_PeerGroup *pg, - GNUNET_TESTING_NotifyTopology cb, void *cls); +GNUNET_TESTING_peer_wait (struct GNUNET_TESTING_Peer *peer); /** - * Stop the connection process temporarily. - * - * @param pg the peer group to stop connecting - */ -void -GNUNET_TESTING_stop_connections (struct GNUNET_TESTING_PeerGroup *pg); - - -/** - * Resume the connection process. - * - * @param pg the peer group to resume connecting + * Signature of the 'main' function for a (single-peer) testcase that + * is run using 'GNUNET_TESTING_peer_run'. + * + * @param cls closure + * @param cfg configuration of the peer that was started + * @param peer identity of the peer that was created */ -void -GNUNET_TESTING_resume_connections (struct GNUNET_TESTING_PeerGroup *pg); +typedef void (*GNUNET_TESTING_TestMain)(void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TESTING_Peer *peer); /** - * There are many ways to connect peers that are supported by this function. - * To connect peers in the same topology that was created via the - * GNUNET_TESTING_create_topology, the topology variable must be set to - * GNUNET_TESTING_TOPOLOGY_NONE. If the topology variable is specified, - * a new instance of that topology will be generated and attempted to be - * connected. This could result in some connections being impossible, - * because some topologies are non-deterministic. + * Start a single peer and run a test using the testing library. + * Starts a peer using the given configuration and then invokes the + * given callback. This function ALSO initializes the scheduler loop + * and should thus be called directly from "main". The testcase + * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'. * - * @param pg the peer group struct representing the running peers - * @param topology which topology to connect the peers in - * @param options options for connecting the topology - * @param option_modifier modifier for options that take a parameter - * @param connect_timeout how long to wait before giving up on connecting - * two peers - * @param connect_attempts how many times to attempt to connect two peers - * over the connect_timeout duration - * @param notify_callback notification to be called once all connections completed - * @param notify_cls closure for notification callback - * - * @return the number of connections that will be attempted, GNUNET_SYSERR on error + * @param testdir only the directory name without any path. This is used for + * all service homes; the directory will be created in a temporary + * location depending on the underlying OS + * @param cfgfilename name of the configuration file to use; + * use NULL to only run with defaults + * @param tm main function of the testcase + * @param tm_cls closure for 'tm' + * @return 0 on success, 1 on error */ int -GNUNET_TESTING_connect_topology (struct GNUNET_TESTING_PeerGroup *pg, - enum GNUNET_TESTING_Topology topology, - enum GNUNET_TESTING_TopologyOption options, - double option_modifier, - struct GNUNET_TIME_Relative connect_timeout, - unsigned int connect_attempts, - GNUNET_TESTING_NotifyCompletion - notify_callback, void *notify_cls); +GNUNET_TESTING_peer_run (const char *testdir, + const char *cfgfilename, + GNUNET_TESTING_TestMain tm, + void *tm_cls); /** - * Start or stop an individual peer from the given group. + * Start a single service (no ARM, except of course if the given + * service name is 'arm') and run a test using the testing library. + * Starts a service using the given configuration and then invokes the + * given callback. This function ALSO initializes the scheduler loop + * and should thus be called directly from "main". The testcase + * should self-terminate by invoking 'GNUNET_SCHEDULER_shutdown'. * - * @param pg handle to the peer group - * @param offset which peer to start or stop - * @param desired_status GNUNET_YES to have it running, GNUNET_NO to stop it - * @param timeout how long to wait for shutdown - * @param cb function to call at the end - * @param cb_cls closure for cb - */ -void -GNUNET_TESTING_daemons_vary (struct GNUNET_TESTING_PeerGroup *pg, - unsigned int offset, int desired_status, - struct GNUNET_TIME_Relative timeout, - GNUNET_TESTING_NotifyCompletion cb, void *cb_cls); - - -/** - * Start a peer group with a given number of peers. Notify - * on completion of peer startup and connection based on given - * topological constraints. Optionally notify on each - * established connection. + * This function is useful if the testcase is for a single service + * and if that service doesn't itself depend on other services. * - * @param cfg configuration template to use - * @param total number of daemons to start - * @param timeout total time allowed for peers to start - * @param connect_cb function to call each time two daemons are connected - * @param peergroup_cb function to call once all peers are up and connected - * @param peergroup_cls closure for peergroup callbacks - * @param hostnames linked list of host structs to use to start peers on - * (NULL to run on localhost only) - * - * @return NULL on error, otherwise handle to control peer group + * @param testdir only the directory name without any path. This is used for + * all service homes; the directory will be created in a temporary + * location depending on the underlying OS + * @param service_name name of the service to run + * @param cfgfilename name of the configuration file to use; + * use NULL to only run with defaults + * @param tm main function of the testcase + * @param tm_cls closure for 'tm' + * @return 0 on success, 1 on error */ -struct GNUNET_TESTING_PeerGroup * -GNUNET_TESTING_peergroup_start (const struct GNUNET_CONFIGURATION_Handle *cfg, - unsigned int total, - struct GNUNET_TIME_Relative timeout, - GNUNET_TESTING_NotifyConnection connect_cb, - GNUNET_TESTING_NotifyCompletion peergroup_cb, - void *peergroup_cls, - const struct GNUNET_TESTING_Host *hostnames); +int +GNUNET_TESTING_service_run (const char *testdir, + const char *service_name, + const char *cfgfilename, + GNUNET_TESTING_TestMain tm, + void *tm_cls); /** - * Print current topology to a graphviz readable file. + * Sometimes we use the binary name to determine which specific + * test to run. In those cases, the string after the last "_" + * in 'argv[0]' specifies a string that determines the configuration + * file or plugin to use. * - * @param pg a currently running peergroup to print to file - * @param output_filename the file to write the topology to - * @param notify_cb callback to call upon completion or failure - * @param notify_cb_cls closure for notify_cb + * This function returns the respective substring, taking care + * of issues such as binaries ending in '.exe' on W32. * + * @param argv0 the name of the binary + * @return string between the last '_' and the '.exe' (or the end of the string), + * NULL if argv0 has no '_' */ -void -GNUNET_TESTING_peergroup_topology_to_file (struct GNUNET_TESTING_PeerGroup *pg, - const char *output_filename, - GNUNET_TESTING_NotifyCompletion - notify_cb, void *notify_cb_cls); +char * +GNUNET_TESTING_get_testname_from_underscore (const char *argv0); #if 0 /* keep Emacsens' auto-indent happy */ diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h index 35d180c..d131e4e 100644 --- a/src/include/gnunet_time_lib.h +++ b/src/include/gnunet_time_lib.h @@ -150,6 +150,22 @@ GNUNET_NETWORK_STRUCT_END #define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever_ () + +/** + * Threshold after which exponential backoff should not increase (15 m). + */ +#define GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) + + +/** + * Perform our standard exponential back-off calculation, starting at 1mst + * and then going by a factor of 2 up unto a maximum of 1s. + * + * @param r current backoff time, initially zero + */ +#define GNUNET_TIME_STD_BACKOFF(r) GNUNET_TIME_relative_min (GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD, \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, (r)), 2)); + /** * Return relative time of 0ms. */ @@ -441,18 +457,6 @@ GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a); /** - * Convert a relative time to a string. - * NOT reentrant! - * - * @param time the time to print - * - * @return string form of the time (as milliseconds) - */ -const char * -GNUNET_TIME_relative_to_string (struct GNUNET_TIME_Relative time); - - -/** * Set the timestamp offset for this instance. * * @param offset the offset to skew the locale time by diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h index d1e03d7..d8c4ec4 100644 --- a/src/include/gnunet_transport_plugin.h +++ b/src/include/gnunet_transport_plugin.h @@ -44,6 +44,10 @@ * useful since sometimes (i.e. for inbound TCP connections) a * connection may not have an address that can be used for meaningful * distinction between sessions to the same peer. + * + * Each 'struct Session' MUST start with the 'struct GNUNET_PeerIdentity' + * of the peer the session is for (which will be used for some error + * checking by the ATS code). */ struct Session; @@ -151,10 +155,12 @@ typedef struct GNUNET_ATS_Information * @param addr one of the addresses of the host * the specific address format depends on the transport * @param addrlen length of the address + * @param dest_plugin plugin to use this address with */ typedef void (*GNUNET_TRANSPORT_AddressNotification) (void *cls, int add_remove, const void *addr, - size_t addrlen); + size_t addrlen, + const char *dest_plugin); /** @@ -185,8 +191,8 @@ typedef struct GNUNET_TIME_Relative (*GNUNET_TRANSPORT_TrafficReport) (void /** * Function that returns a HELLO message. */ -typedef const struct GNUNET_MessageHeader - *(*GNUNET_TRANSPORT_GetHelloCallback) (void); +typedef const struct GNUNET_MessageHeader * + (*GNUNET_TRANSPORT_GetHelloCallback) (void); /** @@ -277,11 +283,17 @@ struct GNUNET_TRANSPORT_PluginEnvironment * GNUNET_SYSERR if the target disconnected; * disconnect will ALSO be signalled using * the ReceiveCallback. + * @param size_payload bytes of payload from transport service in message + * @param size_on_wire bytes required on wire for transmission, + * 0 if result == GNUNET_SYSERR */ typedef void (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls, const struct GNUNET_PeerIdentity * - target, int result); + target, + int result, + size_t size_payload, + size_t size_on_wire); /** * The new send function with just the session and no address @@ -434,7 +446,7 @@ typedef const char *(*GNUNET_TRANSPORT_AddressToString) (void *cls, * * @param cls closure ('struct Plugin*') * @param addr string address - * @param addrlen length of the address + * @param addrlen length of the address including \0 termination * @param buf location to store the buffer * If the function returns GNUNET_SYSERR, its contents are undefined. * @param added length of created address diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index 5c939a0..5fb46a1 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h @@ -43,6 +43,13 @@ extern "C" */ #define GNUNET_TRANSPORT_VERSION 0x00000000 +enum TRAFFIC_METRIC_DIRECTION +{ + TM_SEND = 0, + TM_RECEIVE = 1, + TM_BOTH = 2 +}; + /** * Function called by the transport for each received message. @@ -99,6 +106,18 @@ typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls, /** + * Function to call with result of the try connect request. + * + * + * @param cls closure + * @param result GNUNET_OK if message was transmitted to transport service + * GNUNET_SYSERR if message was not transmitted to transport service + */ +typedef void (*GNUNET_TRANSPORT_TryConnectCallback) (void *cls, + const int result); + + +/** * Function to call with a textual representation of an address. * This function will be called several times with different possible * textual representations, and a last time with NULL to signal the end @@ -159,18 +178,40 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle); /** + * Opaque handle for a transmission-ready request. + */ +struct GNUNET_TRANSPORT_TryConnectHandle; + + +/** * Ask the transport service to establish a connection to * the given peer. * * @param handle connection to transport service * @param target who we should try to connect to + * @param cb callback to be called when request was transmitted to transport + * service + * @param cb_cls closure for the callback + * @return a GNUNET_TRANSPORT_TryConnectHandle handle or + * NULL on failure (cb will not be called) */ -void +struct GNUNET_TRANSPORT_TryConnectHandle * GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle, - const struct GNUNET_PeerIdentity *target); + const struct GNUNET_PeerIdentity *target, + GNUNET_TRANSPORT_TryConnectCallback cb, + void *cb_cls); /** + * Cancel the request to transport to try a connect + * Callback will not be called + * + * @param tch GNUNET_TRANSPORT_TryConnectHandle handle to cancel + */ +void +GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch); + +/** * Opaque handle for a transmission-ready request. */ struct GNUNET_TRANSPORT_TransmitHandle; @@ -236,7 +277,54 @@ struct GNUNET_TRANSPORT_GetHelloHandle; /** - * Obtain updates on changes to the HELLO message for this peer. + * Checks if a neighbour is connected + * + * @param handle connection to transport service + * @peer the peer to check + * @return GNUNET_YES or GNUNET_NO + * + */ +int +GNUNET_TRANSPORT_check_neighbour_connected (struct GNUNET_TRANSPORT_Handle *handle, + const struct GNUNET_PeerIdentity *peer); + + +/** + * Set transport metrics for a peer and a direction + * + * @param handle transport handle + * @param peer the peer to set the metric for + * @param direction can be: TM_SEND, TM_RECV, TM_BOTH + * @param ats the metric as ATS information + * @param ats_count the number of metrics + * + * Supported ATS values: + * GNUNET_ATS_QUALITY_NET_DELAY (value in ms) + * GNUNET_ATS_QUALITY_NET_DISTANCE (value in #hops) + * + * Example + * To enforce a delay of 10 ms for peer p1 in sending direction use: + * + * struct GNUNET_ATS_Information ats; + * ats.type = ntohl (GNUNET_ATS_QUALITY_NET_DELAY); + * ats.value = ntohl (10); + * GNUNET_TRANSPORT_set_traffic_metric (th, p1, TM_SEND, &ats, 1); + * + * Note: + * Delay restrictions in receiving direction will be enforced with + * 1 message delay. + */ +void +GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle, + const struct GNUNET_PeerIdentity *peer, + int direction, + const struct GNUNET_ATS_Information *ats, + size_t ats_count); + + +/** + * Obtain updates on changes to the HELLO message for this peer. The callback + * given in this function is never called synchronously. * * @param handle connection to transport service * @param rec function to call with the HELLO @@ -252,7 +340,7 @@ GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle, /** * Stop receiving updates about changes to our HELLO message. * - * @param ghh handle returned from 'GNUNET_TRANSPORT_get_hello') + * @param ghh handle to cancel */ void GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh); @@ -265,16 +353,29 @@ GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh); * * @param handle connection to transport service * @param hello the hello message - * @param cont continuation to call when HELLO has been sent + * @param cont continuation to call when HELLO has been sent, + * tc reason GNUNET_SCHEDULER_REASON_TIMEOUT for fail + * tc reasong GNUNET_SCHEDULER_REASON_READ_READY for success * @param cls closure for continuation + * @return a GNUNET_TRANSPORT_OfferHelloHandle handle or NULL on failure, + * in case of failure cont will not be called + * */ -void +struct GNUNET_TRANSPORT_OfferHelloHandle * GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, const struct GNUNET_MessageHeader *hello, GNUNET_SCHEDULER_Task cont, void *cls); /** + * Cancel the request to transport to offer the HELLO message + * + * @param ohh the GNUNET_TRANSPORT_OfferHelloHandle to cancel + */ +void +GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh); + +/** * Handle to cancel a pending address lookup. */ struct GNUNET_TRANSPORT_AddressToStringContext; @@ -315,7 +416,7 @@ GNUNET_TRANSPORT_address_to_string_cancel (struct /** * Return all the known addresses for a specific peer or all peers. - * Returns continously all address if one_shot is set to GNUNET_NO + * Returns continuously all address if one_shot is set to GNUNET_NO * * CHANGE: Returns the address(es) that we are currently using for this * peer. Upon completion, the 'AddressLookUpCallback' is called one more diff --git a/src/include/gnunet_vpn_service.h b/src/include/gnunet_vpn_service.h index ecf6cf5..77944c9 100644 --- a/src/include/gnunet_vpn_service.h +++ b/src/include/gnunet_vpn_service.h @@ -97,7 +97,7 @@ GNUNET_VPN_redirect_to_peer (struct GNUNET_VPN_Handle *vh, int result_af, uint8_t protocol, const struct GNUNET_PeerIdentity *peer, - const GNUNET_HashCode *serv, + const struct GNUNET_HashCode *serv, int nac, struct GNUNET_TIME_Absolute expiration_time, GNUNET_VPN_AllocationCallback cb, diff --git a/src/include/platform.h b/src/include/platform.h index 9a5d164..c44f67f 100644 --- a/src/include/platform.h +++ b/src/include/platform.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2012 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 @@ -20,14 +20,12 @@ /** * @file include/platform.h - * @brief plaform specifics - * + * @brief plaform specific includes and defines * @author Nils Durner - * + * @author Christian Grothoff * This file should never be included by installed - * header files (thos starting with "gnunet_"). + * header files (those starting with "gnunet_"). */ - #ifndef PLATFORM_H #define PLATFORM_H @@ -50,7 +48,7 @@ #include <sys/types.h> #endif -#define ALLOW_EXTRA_CHECKS GNUNET_NO +#define ALLOW_EXTRA_CHECKS GNUNET_YES /** * For strptime (glibc2 needs this). @@ -111,6 +109,9 @@ #ifdef WINDOWS #include <malloc.h> /* for alloca(), on other OSes it's in stdlib.h */ #endif +#ifdef HAVE_MALLOC_H +#include <malloc.h> /* for mallinfo on GNU */ +#endif #ifndef _MSC_VER #include <unistd.h> /* KLB_FIX */ #endif @@ -138,7 +139,7 @@ #ifdef SOMEBSD #include <net/if.h> #endif -#ifdef GNUNET_freeBSD +#ifdef FREEBSD #include <semaphore.h> #endif #ifdef DARWIN @@ -146,7 +147,7 @@ #include <semaphore.h> #include <net/if.h> #endif -#ifdef LINUX +#if defined(LINUX) || defined(GNU) #include <net/if.h> #endif #ifdef SOLARIS diff --git a/src/include/winproc.h b/src/include/winproc.h index 3670a74..6cbe562 100644 --- a/src/include/winproc.h +++ b/src/include/winproc.h @@ -227,6 +227,7 @@ extern "C" int GNInitWinEnv (); void GNShutdownWinEnv (); + BOOL SafeTerminateProcess (HANDLE hProcess, UINT uExitCode, DWORD dwTimeout); #ifdef __cplusplus } #endif |