diff options
author | Bertrand Marc <beberking@gmail.com> | 2012-05-02 21:43:37 +0200 |
---|---|---|
committer | Bertrand Marc <beberking@gmail.com> | 2012-05-02 21:43:37 +0200 |
commit | 2b81464a43485fcc8ce079fafdee7b7a171835f4 (patch) | |
tree | 394774c0f735199b57d51a2d3840356317853fe1 /src/include |
Imported Upstream version 0.9.2upstream/0.9.2
Diffstat (limited to 'src/include')
72 files changed, 26205 insertions, 0 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am new file mode 100644 index 0000000..afe4ecb --- /dev/null +++ b/src/include/Makefile.am @@ -0,0 +1,82 @@ +SUBDIRS = . + +gnunetincludedir = $(includedir)/gnunet + +nodist_gnunetinclude_HEADERS = \ + gnunet_directories.h \ + block_fs.h + +if MINGW + WINPROC = winproc.h +endif + +gnunetinclude_HEADERS = \ + gauger.h \ + gettext.h \ + platform.h \ + plibc.h \ + $(WINPROC) \ + 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 \ + 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_mesh_service.h \ + gnunet_namestore_plugin.h \ + gnunet_namestore_service.h \ + gnunet_nat_lib.h \ + gnunet_network_lib.h \ + gnunet_nse_service.h \ + gnunet_os_lib.h \ + gnunet_peer_lib.h \ + gnunet_peerinfo_service.h \ + gnunet_plugin_lib.h \ + gnunet_program_lib.h \ + gnunet_protocols.h \ + gnunet_pseudonym_lib.h \ + gnunet_resolver_service.h \ + gnunet_scheduler_lib.h \ + gnunet_server_lib.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_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 diff --git a/src/include/Makefile.in b/src/include/Makefile.in new file mode 100644 index 0000000..ce91bd7 --- /dev/null +++ b/src/include/Makefile.in @@ -0,0 +1,840 @@ +# Makefile.in generated by automake 1.11.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = src/include +DIST_COMMON = $(am__gnunetinclude_HEADERS_DIST) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in $(srcdir)/gnunet_directories.h.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/absolute-header.m4 \ + $(top_srcdir)/m4/align.m4 $(top_srcdir)/m4/argz.m4 \ + $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/iconv.m4 \ + $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ + $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libcurl.m4 \ + $(top_srcdir)/m4/libgcrypt.m4 $(top_srcdir)/m4/libtool.m4 \ + $(top_srcdir)/m4/libunistring.m4 $(top_srcdir)/m4/ltdl.m4 \ + $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ + $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ + $(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/po.m4 \ + $(top_srcdir)/m4/progtest.m4 $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/gnunet_config.h +CONFIG_CLEAN_FILES = 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_0 = @echo " GEN " $@; +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +SOURCES = +DIST_SOURCES = +RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ + html-recursive info-recursive install-data-recursive \ + install-dvi-recursive install-exec-recursive \ + install-html-recursive install-info-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 \ + 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_mesh_service.h gnunet_namestore_plugin.h \ + gnunet_namestore_service.h gnunet_nat_lib.h \ + gnunet_network_lib.h gnunet_nse_service.h gnunet_os_lib.h \ + gnunet_peer_lib.h gnunet_peerinfo_service.h \ + gnunet_plugin_lib.h gnunet_program_lib.h gnunet_protocols.h \ + gnunet_pseudonym_lib.h gnunet_resolver_service.h \ + gnunet_scheduler_lib.h gnunet_server_lib.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_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/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(gnunetincludedir)" \ + "$(DESTDIR)$(gnunetincludedir)" +HEADERS = $(gnunetinclude_HEADERS) $(nodist_gnunetinclude_HEADERS) +RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \ + $(RECURSIVE_CLEAN_TARGETS:-recursive=) tags TAGS ctags CTAGS \ + distdir +ETAGS = etags +CTAGS = ctags +DIST_SUBDIRS = $(SUBDIRS) +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +am__relativize = \ + dir0=`pwd`; \ + sed_first='s,^\([^/]*\)/.*$$,\1,'; \ + sed_rest='s,^[^/]*/*,,'; \ + sed_last='s,^.*/\([^/]*\)$$,\1,'; \ + sed_butlast='s,/*[^/]*$$,,'; \ + while test -n "$$dir1"; do \ + first=`echo "$$dir1" | sed -e "$$sed_first"`; \ + if test "$$first" != "."; then \ + if test "$$first" = ".."; then \ + dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ + dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ + else \ + first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ + if test "$$first2" = "$$first"; then \ + dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ + else \ + dir2="../$$dir2"; \ + fi; \ + dir0="$$dir0"/"$$first"; \ + fi; \ + fi; \ + dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ + done; \ + reldir="$$dir2" +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +ARGZ_H = @ARGZ_H@ +AS = @AS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFAULT_INTERFACE = @DEFAULT_INTERFACE@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLDIR = @DLLDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +EXT_LIBS = @EXT_LIBS@ +EXT_LIB_PATH = @EXT_LIB_PATH@ +FGREP = @FGREP@ +GMSGFMT = @GMSGFMT@ +GMSGFMT_015 = @GMSGFMT_015@ +GNUNETDNS_GROUP = @GNUNETDNS_GROUP@ +GN_DAEMON_CONFIG_DIR = @GN_DAEMON_CONFIG_DIR@ +GN_DAEMON_HOME_DIR = @GN_DAEMON_HOME_DIR@ +GN_INTLINCL = @GN_INTLINCL@ +GN_LIBINTL = @GN_LIBINTL@ +GN_LIB_LDFLAGS = @GN_LIB_LDFLAGS@ +GN_PLUGIN_LDFLAGS = @GN_PLUGIN_LDFLAGS@ +GN_USER_HOME_DIR = @GN_USER_HOME_DIR@ +GREP = @GREP@ +HAVE_LIBUNISTRING = @HAVE_LIBUNISTRING@ +INCLTDL = @INCLTDL@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +INTLLIBS = @INTLLIBS@ +INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBADD_DL = @LIBADD_DL@ +LIBADD_DLD_LINK = @LIBADD_DLD_LINK@ +LIBADD_DLOPEN = @LIBADD_DLOPEN@ +LIBADD_SHL_LOAD = @LIBADD_SHL_LOAD@ +LIBCURL = @LIBCURL@ +LIBCURL_CPPFLAGS = @LIBCURL_CPPFLAGS@ +LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ +LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ +LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ +LIBICONV = @LIBICONV@ +LIBINTL = @LIBINTL@ +LIBLTDL = @LIBLTDL@ +LIBOBJS = @LIBOBJS@ +LIBPREFIX = @LIBPREFIX@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIBUNISTRING = @LIBUNISTRING@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTDLDEPS = @LTDLDEPS@ +LTDLINCL = @LTDLINCL@ +LTDLOPEN = @LTDLOPEN@ +LTLIBICONV = @LTLIBICONV@ +LTLIBINTL = @LTLIBINTL@ +LTLIBOBJS = @LTLIBOBJS@ +LTLIBUNISTRING = @LTLIBUNISTRING@ +LT_CONFIG_H = @LT_CONFIG_H@ +LT_DLLOADERS = @LT_DLLOADERS@ +LT_DLPREOPEN = @LT_DLPREOPEN@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +MSGFMT = @MSGFMT@ +MSGFMT_015 = @MSGFMT_015@ +MSGMERGE = @MSGMERGE@ +MYSQL_CPPFLAGS = @MYSQL_CPPFLAGS@ +MYSQL_LDFLAGS = @MYSQL_LDFLAGS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJC = @OBJC@ +OBJCDEPMODE = @OBJCDEPMODE@ +OBJCFLAGS = @OBJCFLAGS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +POSTGRES_CPPFLAGS = @POSTGRES_CPPFLAGS@ +POSTGRES_LDFLAGS = @POSTGRES_LDFLAGS@ +POSUB = @POSUB@ +PYTHON = @PYTHON@ +PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@ +PYTHON_PLATFORM = @PYTHON_PLATFORM@ +PYTHON_PREFIX = @PYTHON_PREFIX@ +PYTHON_VERSION = @PYTHON_VERSION@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SQLITE_CPPFLAGS = @SQLITE_CPPFLAGS@ +SQLITE_LDFLAGS = @SQLITE_LDFLAGS@ +STRIP = @STRIP@ +SUDO_BINARY = @SUDO_BINARY@ +UNIXONLY = @UNIXONLY@ +USE_NLS = @USE_NLS@ +VERSION = @VERSION@ +XGETTEXT = @XGETTEXT@ +XGETTEXT_015 = @XGETTEXT_015@ +XMKMF = @XMKMF@ +X_CFLAGS = @X_CFLAGS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBS = @X_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +_libcurl_config = @_libcurl_config@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +ac_ct_OBJC = @ac_ct_OBJC@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_target = @build_target@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +lt_ECHO = @lt_ECHO@ +ltdl_LIBOBJS = @ltdl_LIBOBJS@ +ltdl_LTLIBOBJS = @ltdl_LTLIBOBJS@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +pkgpyexecdir = @pkgpyexecdir@ +pkgpythondir = @pkgpythondir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +pyexecdir = @pyexecdir@ +pythondir = @pythondir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +subdirs = @subdirs@ +sys_symbol_underscore = @sys_symbol_underscore@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +SUBDIRS = . +gnunetincludedir = $(includedir)/gnunet +nodist_gnunetinclude_HEADERS = \ + gnunet_directories.h \ + block_fs.h + +@MINGW_TRUE@WINPROC = winproc.h +gnunetinclude_HEADERS = \ + gauger.h \ + gettext.h \ + platform.h \ + plibc.h \ + $(WINPROC) \ + 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 \ + 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_mesh_service.h \ + gnunet_namestore_plugin.h \ + gnunet_namestore_service.h \ + gnunet_nat_lib.h \ + gnunet_network_lib.h \ + gnunet_nse_service.h \ + gnunet_os_lib.h \ + gnunet_peer_lib.h \ + gnunet_peerinfo_service.h \ + gnunet_plugin_lib.h \ + gnunet_program_lib.h \ + gnunet_protocols.h \ + gnunet_pseudonym_lib.h \ + gnunet_resolver_service.h \ + gnunet_scheduler_lib.h \ + gnunet_server_lib.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_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 + +all: all-recursive + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/include/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/include/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): +gnunet_directories.h: $(top_builddir)/config.status $(srcdir)/gnunet_directories.h.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ + +mostlyclean-libtool: + -rm -f *.lo + +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=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(gnunetincludedir)'"; \ + $(INSTALL_HEADER) $$files "$(DESTDIR)$(gnunetincludedir)" || exit $$?; \ + done + +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 +install-nodist_gnunetincludeHEADERS: $(nodist_gnunetinclude_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(gnunetincludedir)" || $(MKDIR_P) "$(DESTDIR)$(gnunetincludedir)" + @list='$(nodist_gnunetinclude_HEADERS)'; test -n "$(gnunetincludedir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(gnunetincludedir)'"; \ + $(INSTALL_HEADER) $$files "$(DESTDIR)$(gnunetincludedir)" || exit $$?; \ + done + +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 + +# This directory's subdirectories are mostly independent; you can cd +# into them and run `make' without going through this Makefile. +# To change the values of `make' variables: instead of editing Makefiles, +# (1) if the variable is set in `config.status', edit `config.status' +# (which will cause the Makefiles to be regenerated when you run `make'); +# (2) otherwise, pass the desired values on the `make' command line. +$(RECURSIVE_TARGETS): + @fail= failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ + dot_seen=no; \ + target=`echo $@ | sed s/-recursive//`; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + dot_seen=yes; \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done; \ + if test "$$dot_seen" = "no"; then \ + $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ + fi; test -z "$$fail" + +$(RECURSIVE_CLEAN_TARGETS): + @fail= failcom='exit 1'; \ + for f in x $$MAKEFLAGS; do \ + case $$f in \ + *=* | --[!k]*);; \ + *k*) failcom='fail=yes';; \ + esac; \ + done; \ + dot_seen=no; \ + case "$@" in \ + distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ + *) list='$(SUBDIRS)' ;; \ + esac; \ + rev=''; for subdir in $$list; do \ + if test "$$subdir" = "."; then :; else \ + rev="$$subdir $$rev"; \ + fi; \ + done; \ + rev="$$rev ."; \ + target=`echo $@ | sed s/-recursive//`; \ + for subdir in $$rev; do \ + echo "Making $$target in $$subdir"; \ + if test "$$subdir" = "."; then \ + local_target="$$target-am"; \ + else \ + local_target="$$target"; \ + fi; \ + ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ + || eval $$failcom; \ + done && test -z "$$fail" +tags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \ + done +ctags-recursive: + list='$(SUBDIRS)'; for subdir in $$list; do \ + test "$$subdir" = . || ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + set x; \ + here=`pwd`; \ + if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ + include_option=--etags-include; \ + empty_fix=.; \ + else \ + include_option=--include; \ + empty_fix=; \ + fi; \ + list='$(SUBDIRS)'; for subdir in $$list; do \ + if test "$$subdir" = .; then :; else \ + test ! -f $$subdir/TAGS || \ + set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ + fi; \ + done; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: CTAGS +CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done + @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 \ + dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ + $(am__relativize); \ + new_distdir=$$reldir; \ + dir1=$$subdir; dir2="$(top_distdir)"; \ + $(am__relativize); \ + new_top_distdir=$$reldir; \ + echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ + echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ + ($(am__cd) $$subdir && \ + $(MAKE) $(AM_MAKEFLAGS) \ + top_distdir="$$new_top_distdir" \ + distdir="$$new_distdir" \ + am__remove_distdir=: \ + am__skip_length_check=: \ + am__skip_mode_fix=: \ + distdir) \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-recursive +all-am: Makefile $(HEADERS) +installdirs: installdirs-recursive +installdirs-am: + for dir in "$(DESTDIR)$(gnunetincludedir)" "$(DESTDIR)$(gnunetincludedir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-recursive +install-exec: install-exec-recursive +install-data: install-data-recursive +uninstall: uninstall-recursive + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-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 +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-recursive + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-recursive + -rm -f Makefile +distclean-am: clean-am distclean-generic distclean-tags + +dvi: dvi-recursive + +dvi-am: + +html: html-recursive + +html-am: + +info: info-recursive + +info-am: + +install-data-am: install-gnunetincludeHEADERS \ + install-nodist_gnunetincludeHEADERS + +install-dvi: install-dvi-recursive + +install-dvi-am: + +install-exec-am: + +install-html: install-html-recursive + +install-html-am: + +install-info: install-info-recursive + +install-info-am: + +install-man: + +install-pdf: install-pdf-recursive + +install-pdf-am: + +install-ps: install-ps-recursive + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-recursive + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-recursive + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-recursive + +pdf-am: + +ps: ps-recursive + +ps-am: + +uninstall-am: uninstall-gnunetincludeHEADERS \ + uninstall-nodist_gnunetincludeHEADERS + +.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) ctags-recursive \ + install-am install-strip tags-recursive + +.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \ + all all-am check check-am clean clean-generic clean-libtool \ + ctags ctags-recursive distclean distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-gnunetincludeHEADERS install-html \ + install-html-am install-info install-info-am install-man \ + install-nodist_gnunetincludeHEADERS install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs installdirs-am maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags tags-recursive \ + uninstall uninstall-am uninstall-gnunetincludeHEADERS \ + uninstall-nodist_gnunetincludeHEADERS + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/include/block_dns.h b/src/include/block_dns.h new file mode 100644 index 0000000..4c2f1a3 --- /dev/null +++ b/src/include/block_dns.h @@ -0,0 +1,87 @@ +/* + This file is part of GNUnet. + (C) 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file include/block_dns.h + * @author Philipp Toelke + */ +#ifndef _GNVPN_BLOCKDNS_H_ +#define _GNVPN_BLOCKDNS_H_ + +#include "gnunet_common.h" +#include "gnunet_crypto_lib.h" + +/** + * Bitmask describing what IP-protocols are supported by the service + */ +enum GNUNET_DNS_ServiceTypes +{ + GNUNET_DNS_SERVICE_TYPE_UDP = 1, + GNUNET_DNS_SERVICE_TYPE_TCP = 2 +}; + +GNUNET_NETWORK_STRUCT_BEGIN + +/** + * This is the structure describing an dns-record such as www.gnunet. + */ +struct GNUNET_DNS_Record +{ + /** + * Signature of the peer affirming that he is offering the service. + */ + struct GNUNET_CRYPTO_RsaSignature signature; + + /** + * Beginning of signed portion of the record, signs everything until + * the end of the struct. + */ + struct GNUNET_CRYPTO_RsaSignaturePurpose purpose; + + /** + * The peer providing this service + */ + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer; + + /** + * The descriptor for the service + * (a peer may provide more than one service) + */ + GNUNET_HashCode service_descriptor GNUNET_PACKED; + + /** + * When does this record expire? + */ + struct GNUNET_TIME_AbsoluteNBO expiration_time; + + /** + * Four TCP and UDP-Ports that are used by this service, big endian format + */ + uint64_t ports GNUNET_PACKED; + + /** + * What connection-types (UDP, TCP, ...) are supported by the service. + * Contains an 'enum GNUNET_DNS_ServiceTypes' in big endian format. + */ + uint32_t service_type GNUNET_PACKED; +}; +GNUNET_NETWORK_STRUCT_END + +#endif diff --git a/src/include/block_fs.h b/src/include/block_fs.h new file mode 100644 index 0000000..aae741e --- /dev/null +++ b/src/include/block_fs.h @@ -0,0 +1,167 @@ +/* + This file is part of GNUnet. + (C) 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file include/block_fs.h + * @brief fs block formats (shared between fs and block) + * @author Christian Grothoff + */ +#ifndef BLOCK_FS_H +#define BLOCK_FS_H + +#include "gnunet_util_lib.h" + +/** + * @brief keyword block (advertising data under a keyword) + */ +struct KBlock +{ + + /** + * GNUNET_RSA_Signature using RSA-key generated from search keyword. + */ + struct GNUNET_CRYPTO_RsaSignature signature; + + /** + * What is being signed and why? + */ + struct GNUNET_CRYPTO_RsaSignaturePurpose purpose; + + /** + * Key generated (!) from the H(keyword) as the seed! + */ + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace; + + /* 0-terminated URI here */ + + /* variable-size Meta-Data follows here */ + +}; + + +/** + * @brief namespace content block (advertising data under an identifier in a namespace) + */ +struct SBlock +{ + + /** + * GNUNET_RSA_Signature using RSA-key of the namespace + */ + struct GNUNET_CRYPTO_RsaSignature signature; + + /** + * What is being signed and why? + */ + struct GNUNET_CRYPTO_RsaSignaturePurpose purpose; + + /** + * Hash of the hash of the human-readable identifier used for + * this entry (the hash of the human-readable identifier is + * 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; + + /** + * Public key of the namespace. + */ + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace; + + /* 0-terminated update-identifier here */ + + /* 0-terminated URI here (except for NBlocks) */ + + /* variable-size Meta-Data follows here */ + +}; + + +/** + * @brief namespace advertisement block (advertising root of a namespace) + */ +struct NBlock +{ + + /** + * GNUNET_RSA_Signature using RSA-key generated from search keyword. + */ + struct GNUNET_CRYPTO_RsaSignature ksk_signature; + + /** + * What is being signed and why? + */ + struct GNUNET_CRYPTO_RsaSignaturePurpose ksk_purpose; + + /** + * Key generated (!) from the H(keyword) as the seed! + */ + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace; + + /** + * GNUNET_RSA_Signature using RSA-key of the namespace + */ + struct GNUNET_CRYPTO_RsaSignature ns_signature; + + /** + * What is being signed and why? + */ + struct GNUNET_CRYPTO_RsaSignaturePurpose ns_purpose; + + /** + * Public key of the namespace. + */ + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace; + + /* from here on, data is encrypted with H(keyword) */ + + /* 0-terminated root identifier here */ + + /* variable-size Meta-Data follows here */ + +}; + + +GNUNET_NETWORK_STRUCT_BEGIN + +/** + * @brief index block (indexing a DBlock that + * can be obtained directly from reading + * the plaintext file) + */ +struct OnDemandBlock +{ + /** + * Hash code of the entire content of the + * file that was indexed (used to uniquely + * identify the plaintext file). + */ + GNUNET_HashCode file_id; + + /** + * At which offset should we be able to find + * this on-demand encoded block? (in NBO) + */ + uint64_t offset GNUNET_PACKED; + +}; +GNUNET_NETWORK_STRUCT_END + +#endif diff --git a/src/include/block_gns.h b/src/include/block_gns.h new file mode 100644 index 0000000..4514acf --- /dev/null +++ b/src/include/block_gns.h @@ -0,0 +1,93 @@ +/* + 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/block_gns.h + * @brief fs block formats (shared between fs and block) + * @author Martin Schanzenbach + */ +#ifndef BLOCK_GNS_H +#define BLOCK_GNS_H + +#include "gnunet_util_lib.h" + +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 +{ + + /** + * GNUNET_RSA_Signature using RSA-key generated from the records. + */ + struct GNUNET_CRYPTO_RsaSignature signature; + + /** + * What is being signed and why? + */ + struct GNUNET_CRYPTO_RsaSignaturePurpose purpose; + + /** + * The public key of the authority + */ + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; + + /* number of records that follow */ + uint32_t rd_count GNUNET_PACKED; + + /* 0-terminated name here */ + + /* variable-size GNSRecordBlocks follows here */ + + +}; + +GNUNET_NETWORK_STRUCT_END +#endif diff --git a/src/include/gauger.h b/src/include/gauger.h new file mode 100644 index 0000000..9761cbe --- /dev/null +++ b/src/include/gauger.h @@ -0,0 +1,89 @@ +/** --------------------------------------------------------------------------- + * This software is in the public domain, furnished "as is", without technical + * support, and with no warranty, express or implied, as to its usefulness for + * any purpose. + * + * gauger.h + * Interface for C programs to log remotely to a gauger server + * + * Author: Bartlomiej Polot + * -------------------------------------------------------------------------*/ +#ifndef __GAUGER_H__ +#define __GAUGER_H__ + +#ifndef WINDOWS + +#include <unistd.h> +#include <stdio.h> +#include <sys/wait.h> + +#define GAUGER(category, counter, value, unit)\ +{\ + char* __gauger_v[10];\ + char __gauger_s[32];\ + pid_t __gauger_p;\ + if(!(__gauger_p=fork())){\ + close (1); \ + close (2); \ + if(!fork()){\ + sprintf(__gauger_s,"%Lf", (long double) (value));\ + __gauger_v[0] = "gauger";\ + __gauger_v[1] = "-n";\ + __gauger_v[2] = counter;\ + __gauger_v[3] = "-d";\ + __gauger_v[4] = __gauger_s;\ + __gauger_v[5] = "-u";\ + __gauger_v[6] = unit;\ + __gauger_v[7] = "-c";\ + __gauger_v[8] = category;\ + __gauger_v[9] = (char *)NULL;\ + execvp("gauger",__gauger_v);\ + _exit(1);\ + }else{\ + _exit(0);\ + }\ + }else{\ + waitpid(__gauger_p,NULL,0);\ + }\ +} + +#define GAUGER_ID(category, counter, value, unit, id)\ +{\ + char* __gauger_v[12];\ + char __gauger_s[32];\ + pid_t __gauger_p;\ + if(!(__gauger_p=fork())){\ + close (1); \ + close (2); \ + if(!fork()){\ + sprintf(__gauger_s,"%Lf", (long double) (value));\ + __gauger_v[0] = "gauger";\ + __gauger_v[1] = "-n";\ + __gauger_v[2] = counter;\ + __gauger_v[3] = "-d";\ + __gauger_v[4] = __gauger_s;\ + __gauger_v[5] = "-u";\ + __gauger_v[6] = unit;\ + __gauger_v[7] = "-i";\ + __gauger_v[8] = id;\ + __gauger_v[9] = "-c";\ + __gauger_v[10] = category;\ + __gauger_v[11] = (char *)NULL;\ + execvp("gauger",__gauger_v);\ + _exit(1);\ + }else{\ + _exit(0);\ + }\ + }else{\ + waitpid(__gauger_p,NULL,0);\ + }\ +} + +#else + +#define GAUGER_ID(category, counter, value, unit, id) {} +#define GAUGER(category, counter, value, unit) {} + +#endif // WINDOWS + +#endif diff --git a/src/include/gettext.h b/src/include/gettext.h new file mode 100644 index 0000000..0295ac2 --- /dev/null +++ b/src/include/gettext.h @@ -0,0 +1,71 @@ +/* Convenience header for conditional use of GNU <libintl.h>. + Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + USA. */ + +#ifndef _LIBGETTEXT_H +#define _LIBGETTEXT_H 1 + +/* NLS can be disabled through the configure --disable-nls option. */ +#if ENABLE_NLS + +/* Get declarations of GNU message catalog functions. */ +#include <libintl.h> + +#else + +/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which + chokes if dcgettext is defined as a macro. So include it now, to make + later inclusions of <locale.h> a NOP. We don't include <libintl.h> + as well because people using "gettext.h" will not include <libintl.h>, + and also including <libintl.h> would fail on SunOS 4, whereas <locale.h> + is GNUNET_OK. */ +#if defined(__sun) +#include <locale.h> +#endif + +/* Disabled NLS. + The casts to 'const char *' serve the purpose of producing warnings + for invalid uses of the value returned from these functions. + On pre-ANSI systems without 'const', the config.h file is supposed to + contain "#define const". */ +#define gettext(Msgid) ((const char *) (Msgid)) +#define dgettext(Domainname, Msgid) ((const char *) (Msgid)) +#define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid)) +#define ngettext(Msgid1, Msgid2, N) \ + ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) +#define dngettext(Domainname, Msgid1, Msgid2, N) \ + ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) +#define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ + ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) +/* slight modification here to avoid warnings: generate GNUNET_NO code, + not even the cast... */ +#define textdomain(Domainname) +#define bindtextdomain(Domainname, Dirname) +#define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset)) + +#endif + +/* A pseudo function call that serves as a marker for the automated + extraction of messages, but does not call gettext(). The run-time + translation is done at a different place in the code. + The argument, String, should be a literal string. Concatenated strings + and other string expressions won't work. + The macro's expansion is not parenthesized, so that it is suitable as + initializer for static 'char[]' or 'const char[]' variables. */ +#define gettext_noop(String) String + +#endif /* _LIBGETTEXT_H */ diff --git a/src/include/gnunet_applications.h b/src/include/gnunet_applications.h new file mode 100644 index 0000000..5feaeec --- /dev/null +++ b/src/include/gnunet_applications.h @@ -0,0 +1,74 @@ +/* + This file is part of GNUnet. + (C) 2011 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/gnunet_applications.h + * @brief constants for network applications operating on top of the MESH service + * @author Christian Grothoff + */ + +#ifndef GNUNET_APPLICATIONS_H +#define GNUNET_APPLICATIONS_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +/** + * End of list marker. + */ +#define GNUNET_APPLICATION_TYPE_END 0 + +/** + * Test. + */ +#define GNUNET_APPLICATION_TYPE_TEST 1 + +/** + * Internet DNS resolution (external DNS gateway). + */ +#define GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER 2 + + +/** + * Internet IPv4 gateway (any TCP/UDP/ICMP). + */ +#define GNUNET_APPLICATION_TYPE_IPV4_GATEWAY 16 + +/** + * Internet IPv6 gateway (any TCP/UDP/ICMP). + */ +#define GNUNET_APPLICATION_TYPE_IPV6_GATEWAY 17 + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_APPLICATIONS_H */ +#endif +/* end of gnunet_applications.h */ diff --git a/src/include/gnunet_arm_service.h b/src/include/gnunet_arm_service.h new file mode 100644 index 0000000..af1c8cd --- /dev/null +++ b/src/include/gnunet_arm_service.h @@ -0,0 +1,194 @@ +/* + This file is part of GNUnet + (C) 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +/** + * @file include/gnunet_arm_service.h + * @brief API to access gnunet-arm + * @author Christian Grothoff + */ + +#ifndef GNUNET_ARM_SERVICE_H +#define GNUNET_ARM_SERVICE_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_configuration_lib.h" +#include "gnunet_scheduler_lib.h" +#include "gnunet_time_lib.h" + +/** + * Version of the arm API. + */ +#define GNUNET_ARM_VERSION 0x00000001 + + +/** + * Values characterizing GNUnet process states. + */ +enum GNUNET_ARM_ProcessStatus +{ + /** + * Service name is unknown to ARM. + */ + GNUNET_ARM_PROCESS_UNKNOWN = -1, + + /** + * Service is now down (due to client request). + */ + GNUNET_ARM_PROCESS_DOWN = 0, + + /** + * Service is already running. + */ + GNUNET_ARM_PROCESS_ALREADY_RUNNING = 1, + + /** + * Service is currently being started (due to client request). + */ + GNUNET_ARM_PROCESS_STARTING = 2, + + /** + * Service is already being stopped by some other client. + */ + GNUNET_ARM_PROCESS_ALREADY_STOPPING = 3, + + /** + * Service is already down (no action taken) + */ + GNUNET_ARM_PROCESS_ALREADY_DOWN = 4, + + /** + * ARM is currently being shut down (no more process starts) + */ + GNUNET_ARM_PROCESS_SHUTDOWN = 5, + + /** + * Error in communication with ARM + */ + GNUNET_ARM_PROCESS_COMMUNICATION_ERROR = 6, + + /** + * Timeout in communication with ARM + */ + GNUNET_ARM_PROCESS_COMMUNICATION_TIMEOUT = 7, + + /** + * Failure to perform operation + */ + GNUNET_ARM_PROCESS_FAILURE = 8 +}; + + +/** + * Callback function invoked when operation is complete. + * + * @param cls closure + * @param result outcome of the operation + */ +typedef void (*GNUNET_ARM_Callback) (void *cls, + enum GNUNET_ARM_ProcessStatus result); + + +/** + * Handle for interacting with ARM. + */ +struct GNUNET_ARM_Handle; + + +/** + * Setup a context for communicating with ARM. Note that this + * can be done even if the ARM service is not yet running. + * + * @param cfg configuration to use (needed to contact ARM; + * the ARM service may internally use a different + * configuration to determine how to start the service). + * @param service service that *this* process is implementing/providing, can be NULL + * @return context to use for further ARM operations, NULL on error + */ +struct GNUNET_ARM_Handle * +GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *service); + + +/** + * Disconnect from the ARM service. + * + * @param h the handle that was being used + */ +void +GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h); + + +/** + * Start a service. Note that this function merely asks ARM to start + * the service and that ARM merely confirms that it forked the + * respective process. The specified callback may thus return before + * the service has started to listen on the server socket and it may + * also be that the service has crashed in the meantime. Clients + * should repeatedly try to connect to the service at the respective + * port (with some delays in between) before assuming that the service + * actually failed to start. Note that if an error is returned to the + * callback, clients obviously should not bother with trying to + * contact the service. + * + * @param h handle to ARM + * @param service_name name of the service + * @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, + struct GNUNET_TIME_Relative timeout, + GNUNET_ARM_Callback cb, void *cb_cls); + + +/** + * Stop a service. Note that the callback is invoked as soon + * as ARM confirms that it will ask the service to terminate. + * The actual termination may still take some time. + * + * @param h handle to ARM + * @param service_name name of the service + * @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_stop_service (struct GNUNET_ARM_Handle *h, const char *service_name, + struct GNUNET_TIME_Relative timeout, + GNUNET_ARM_Callback cb, void *cb_cls); + + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h new file mode 100644 index 0000000..858ae1d --- /dev/null +++ b/src/include/gnunet_ats_service.h @@ -0,0 +1,767 @@ +/* + This file is part of GNUnet. + (C) 2010,2011 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_ats_service.h + * @brief automatic transport selection and outbound bandwidth determination + * @author Christian Grothoff + * @author Matthias Wachs + */ +#ifndef GNUNET_ATS_SERVICE_H +#define GNUNET_ATS_SERVICE_H + +#include "gnunet_constants.h" +#include "gnunet_util_lib.h" +#include "gnunet_hello_lib.h" + + +enum GNUNET_ATS_Network_Type +{ + GNUNET_ATS_NET_UNSPECIFIED = 0, + GNUNET_ATS_NET_LOOPBACK = 1, + GNUNET_ATS_NET_LAN = 2, + GNUNET_ATS_NET_WAN = 3, + GNUNET_ATS_NET_WLAN = 4, +}; + +/** + * Enum defining all known property types for ATS Enum values are used + * in the GNUNET_ATS_Information struct as + * (key,value)-pairs. + * + * Cost are always stored in uint32_t, so all units used to define costs + * have to be normalized to fit in uint32_t [0 .. 4.294.967.295] + */ +enum GNUNET_ATS_Property +{ + + /** + * End of the array. + * @deprecated + */ + GNUNET_ATS_ARRAY_TERMINATOR = 0, + + /** + * Actual traffic on this connection from the other peer to this peer. + * + * Unit: [bytes/second] + */ + GNUNET_ATS_UTILIZATION_UP, + + /** + * Actual traffic on this connection from this peer to the other peer. + * + * Unit: [bytes/second] + */ + GNUNET_ATS_UTILIZATION_DOWN, + + /** + * Is this address located in WAN, LAN or a loopback address + * Value is element of GNUNET_ATS_Network_Type + */ + GNUNET_ATS_NETWORK_TYPE, + + /** + * Delay + * Time between when the time packet is sent and the packet arrives + * + * Unit: [ms] + * + * Examples: + * + * LAN : 1 + * WLAN : 2 + * Dialup: 500 + */ + GNUNET_ATS_QUALITY_NET_DELAY, + + /** + * Distance on network layer (required for distance-vector routing). + * + * Unit: [DV-hops] + */ + GNUNET_ATS_QUALITY_NET_DISTANCE, + + /** + * Network overhead on WAN (Wide-Area Network) + * + * How many bytes are sent on the WAN when 1 kilobyte (1024 bytes) + * of application data is transmitted? + * A factor used with connect cost, bandwidth cost and energy cost + * to describe the overhead produced by the transport protocol + * + * Unit: [bytes/kb] + * + * Interpretation: less is better + * + * Examples: + * + * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb] + * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb] + * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb] + * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb] + */ + GNUNET_ATS_COST_WAN, + + /** + * Network overhead on LAN (Local-Area Network) + * + * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes) + * of application data is transmitted? + * A factor used with connect cost, bandwidth cost and energy cost + * to describe the overhead produced by the transport protocol + * + * Unit: [bytes/kb] + * + * Interpretation: less is better + * + * Examples: + * + * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb] + * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb] + * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb] + * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb] + */ + GNUNET_ATS_COST_LAN, + + /** + * Network overhead on WLAN (Wireless Local Area Network) + * + * How many bytes are sent on the LAN when 1 kilobyte (1024 bytes) + * of application data is transmitted? + * A factor used with connect cost, bandwidth cost and energy cost + * to describe the overhead produced by the transport protocol + * + * Unit: [bytes/kb] + * + * Interpretation: less is better + * + * Examples: + * + * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb] + * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb] + * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb] + * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb] + */ + GNUNET_ATS_COST_WLAN + /* Cost related values */ + /* =================== */ + /** + * Volume based cost in financial units to transmit data + * + * Note: This value is not bound to a specific currency or unit and only + * used locally. + * "cent" just refers the smallest amount of money in the respective + * currency. + * + * Unit: [cent/MB] + * + * Interpretation: less is better + * + * Examples: + * LAN: 0 [cent/MB] + * 2G : 10 [cent/MB] + */ + // GNUNET_ATS_COST_FINANCIAL_PER_VOLUME = 1, + /** + * Time based cost in financial units to transmit data + * + * Note: This value is not bound to a specific currency or unit and only + * used locally. + * "cent" just refers the smallest amount of money in the respective + * currency. + * + * Unit: [cent/h] + * + * Interpretation: less is better + * + * Examples: + * LAN : 0 [cent/h] + * Dialup: 10 [cent/h] + */ + // GNUNET_ATS_COST_FINANCIAL_PER_TIME = 2, + /** + * Computational costs + * + * Effort of preparing data to be sent with this transport + * Includes encoding, encryption and conversion of data + * Partial values can be summed up: c_sum = c_enc + c_enc + c_conv + * Resulting values depend on local system properties, e.g. CPU + * + * Unit: [ms/GB] + * + * Interpretation: less is better + * + * Examples: + * + * HTTPS with AES CBC-256: 7,382 + * HTTPS with AES CBC-128: 5,279 + * HTTPS with RC4-1024: 2,652 + */ + // GNUNET_ATS_COST_COMPUTATIONAL = 3, + /** + * Energy consumption + * + * Energy consumption using this transport when sending with a certain + * power at a certain bitrate. This is only an approximation based on: + * Energy consumption E = P / D + * + * with: + * Power P in Watt (J/s) + * Datarate D in MBit/s + * + * Conversion between power P and dBm used by WLAN in radiotap's dBm TX power: + * + * Lp(dbm) = 10 log10 (P/ 1mW) + * + * => P = 1 mW * 10^(Lp(dbm)/10) + * + * Unit: [mJ/MB] + * + * Interpretation: less is better + * + * Examples: + * + * LAN: 0 + * WLAN: 89 (600 mW @ 802.11g /w 54 MBit/s) + * Bluetooth: 267 (100 mW @ BT2.0 EDR /w 3 MBit/s) + */ + // GNUNET_ATS_COST_ENERGY_CONSUMPTION = 4, + /** + * Connect cost + * How many bytes are transmitted to initiate a new connection using + * this transport? + * + * Unit: [bytes] + * + * Interpretation: less is better + * + * Examples: + * + * UDP (No connection) : + * 0 bytes + * TCP (TCP 3-Way handshake): + * 220 bytes Ethernet, 172 bytes TCP/IP, 122 bytes TCP + * HTTP (TCP + Header) : + * 477 bytes Ethernet, 429 bytes TCP/IP, 374 bytes TCP, 278 bytes HTTP + * HTTPS HTTP+TLS Handshake: + * 2129 bytes Ethernet, 1975 bytes TCP/IP, 1755 bytes TCP, 1403 bytes HTTPS + * + * */ + // GNUNET_ATS_COST_CONNECT = 5, + /** + * Bandwidth cost + * + * How many bandwidth is available to consume? + * Used to calculate which impact sending data with this transport has + * + * Unit: [kB/s] + * + * Interpretation: more is better + * + * Examples: + * LAN: 12,800 (100 MBit/s) + * WLAN: 6,912 (54 MBit/s) + * Dial-up: 8 (64 Kbit/s) + * + */ + // GNUNET_ATS_COST_BANDWITH_AVAILABLE = 6, + /** + * Network overhead + * + * How many bytes are sent over the wire when 1 kilobyte (1024 bytes) + * of application data is transmitted? + * A factor used with connect cost, bandwidth cost and energy cost + * to describe the overhead produced by the transport protocol + * + * Unit: [bytes/kb] + * + * Interpretation: less is better + * + * Examples: + * + * TCP/IPv4 over Ethernet: 1024 + 38 + 20 + 20 = 1102 [bytes/kb] + * TCP/IPv6 over Ethernet: 1024 + 38 + 20 + 40 = 1122 [bytes/kb] + * UDP/IPv4 over Ethernet: 1024 + 38 + 20 + 8 = 1090 [bytes/kb] + * UDP/IPv6 over Ethernet: 1024 + 38 + 40 + 8 = 1110 [bytes/kb] + */ + // GNUNET_ATS_COST_NETWORK_OVERHEAD = 7, + /* Quality related values */ + /* ====================== */ + /* Physical layer quality properties */ + /** + * Signal strength on physical layer + * + * Unit: [dBm] + */ + // GNUNET_ATS_QUALITY_PHY_SIGNAL_STRENGTH = 1025, + /** + * Collision rate on physical layer + * + * Unit: [B/s] + */ + // GNUNET_ATS_QUALITY_PHY_COLLISION_RATE = 1026, + /** + * Error rate on physical layer + * + * Unit: [B/s] + */ + // GNUNET_ATS_QUALITY_PHY_ERROR_RATE = 1027, + /** + * Jitter + * Time variations of the delay + * 1st derivative of a delay function + * + * Unit: [ms] + */ + // GNUNET_ATS_QUALITY_NET_JITTER = 1029, + /** + * Error rate on network layer + * + * Unit: [B/s] + * + * Examples: + * + * LAN : 0 + * WLAN : 400 + * Bluetooth : 100 + * Note: This numbers are just assumptions as an example, not + * measured or somehow determined + */ + // GNUNET_ATS_QUALITY_NET_ERRORRATE = 1030, + /** + * Drop rate on network layer + * Bytes actively dismissed by a network component during transmission + * Reasons for dropped data can be full queues, congestion, quota violations... + * + * Unit: [B/s] + * + * Examples: + * + * LAN : 0 + * WLAN : 400 + * Bluetooth : 100 + * Note: This numbers are just assumptions as an example, not + * measured or somehow determined + */ + // GNUNET_ATS_QUALITY_NET_DROPRATE = 1031, + /** + * Loss rate on network layer + * Bytes lost during transmission + * Reasons can be collisions, ... + * + * Unit: [B/s] + * + * Examples: + * + * LAN : 0 + * WLAN : 40 + * Bluetooth : 10 + * Note: This numbers are just assumptions as an example, not measured + * or somehow determined + */ + // GNUNET_ATS_QUALITY_NET_LOSSRATE = 1032, + /** + * Throughput on network layer + * + * Unit: [kB/s] + * + * Examples: + * + * LAN : 3400 + * WLAN : 1200 + * Dialup: 4 + * + */ + // GNUNET_ATS_QUALITY_NET_THROUGHPUT = 1033, + /* Availability related values */ + /* =========================== */ + /** + * Is a peer reachable? + */ + // GNUNET_ATS_AVAILABILITY_REACHABLE = 2048, + /** + * Is there a connection established to a peer using this transport + */ + // GNUNET_ATS_AVAILABILITY_CONNECTED = 2049 +}; + +/** + * Number of ATS quality properties + */ +#define GNUNET_ATS_QualityPropertiesCount 2 + +/** + * ATS quality properties as array initializer + */ +#define GNUNET_ATS_QualityProperties {GNUNET_ATS_QUALITY_NET_DELAY, GNUNET_ATS_QUALITY_NET_DISTANCE} + +/** + * Number of ATS quality properties + */ +#define GNUNET_ATS_NetworkTypeCount 5 + +/** + * 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 + +/** + * struct used to communicate the transport's properties like cost and + * quality of service as well as high-level constraints on resource + * consumption. + * + * +---+ + * +-----------+ Constraints | | Plugin properties +---------+ + * | Highlevel |------------> |ATS| <------------------|Transport| + * | Component | ATS struct | | ATS struct | Plugin | + * +-----------+ | | +---------+ + * +---+ + * + * This structure will be used by transport plugins to communicate + * costs to ATS or by higher level components to tell ATS their + * constraints. Always a pair of (GNUNET_ATS_Property, + * uint32_t value). Value is always uint32_t, so all units used to + * define costs have to be normalized to fit uint32_t. + */ +struct GNUNET_ATS_Information +{ + /** + * ATS property type, in network byte order. + */ + uint32_t type GNUNET_PACKED; + + /** + * ATS property value, in network byte order. + */ + uint32_t value GNUNET_PACKED; +}; +GNUNET_NETWORK_STRUCT_END + + +/* ******************************** Scheduling API ***************************** */ + +/** + * Handle to the ATS subsystem for bandwidth/transport scheduling information. + */ +struct GNUNET_ATS_SchedulingHandle; + + +/** + * Opaque session handle, defined by plugins. Contents not known to ATS. + */ +struct Session; + + +/** + * Signature of a function called by ATS with the current bandwidth + * and address preferences as determined by ATS. + * + * @param cls closure + * @param address suggested address (including peer identity of the peer) + * @param session session to use + * @param bandwidth_out assigned outbound bandwidth for the connection + * @param bandwidth_in assigned inbound bandwidth for the connection + * @param ats performance data for the address (as far as known) + * @param ats_count number of performance records in 'ats' + */ +typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls, + const struct + GNUNET_HELLO_Address * + address, + struct Session * session, + struct + GNUNET_BANDWIDTH_Value32NBO + bandwidth_out, + struct + GNUNET_BANDWIDTH_Value32NBO + bandwidth_in, + const struct + GNUNET_ATS_Information * + ats, uint32_t ats_count); + + +/** + * Initialize the ATS subsystem. + * + * @param cfg configuration to use + * @param suggest_cb notification to call whenever the suggestation changed + * @param suggest_cb_cls closure for 'suggest_cb' + * @return ats context + */ +struct GNUNET_ATS_SchedulingHandle * +GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_ATS_AddressSuggestionCallback suggest_cb, + void *suggest_cb_cls); + + +/** + * Client is done with ATS scheduling, release resources. + * + * @param sh handle to release + */ +void +GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh); + + +/** + * We would like to establish a new connection with a peer. ATS + * should suggest a good address to begin with. + * + * @param sh handle + * @param peer identity of the peer we need an address for + */ +void +GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh, + const struct GNUNET_PeerIdentity *peer); + + +/** + * We want to cancel ATS suggesting addresses for a peer. + * + * @param sh handle + * @param peer identity of the peer + */ +void +GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh, + const struct GNUNET_PeerIdentity *peer); + + +/** + * Returns where the address is located: LAN or WAN or ... + * @param sh the GNUNET_ATS_SchedulingHandle handle + * @param addr address + * @param addrlen address length + * @return location as GNUNET_ATS_Information + */ +const struct GNUNET_ATS_Information +GNUNET_ATS_address_get_type (struct GNUNET_ATS_SchedulingHandle *sh, + const struct sockaddr * addr, + socklen_t addrlen); + + +/** + * We have updated performance statistics for a given address. Note + * that this function can be called for addresses that are currently + * in use as well as addresses that are valid but not actively in use. + * Furthermore, the peer may not even be connected to us right now (in + * which case the call may be ignored or the information may be stored + * for later use). Update bandwidth assignments. + * + * @param sh handle + * @param address updated address + * @param session session handle (if available) + * @param ats performance data for the address + * @param ats_count number of performance records in 'ats' + */ +void +GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, + const struct GNUNET_HELLO_Address *address, + struct Session *session, + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count); + + +/** + * An address is now in use or not used any more. + * + * @param sh handle + * @param address the address + * @param session session handle + * @param in_use GNUNET_YES if this address is now used, GNUNET_NO + * if address is not used any more + */ +void +GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, + const struct GNUNET_HELLO_Address *address, + struct Session *session, int in_use); + +/** + * A session got destroyed, stop including it as a valid address. + * + * @param sh handle + * @param address the address + * @param session session handle that is no longer valid (if available) + */ +void +GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, + const struct GNUNET_HELLO_Address *address, + struct Session *session); + + +/* ******************************** Performance API ***************************** */ + +/** + * ATS Handle to obtain and/or modify performance information. + */ +struct GNUNET_ATS_PerformanceHandle; + + +/** + * Signature of a function that is called with QoS information about a peer. + * + * @param cls closure + * @param address the address + * @param bandwidth_out assigned outbound bandwidth for the connection + * @param bandwidth_in assigned inbound bandwidth for the connection + * @param ats performance data for the address (as far as known) + * @param ats_count number of performance records in 'ats' + */ +typedef void (*GNUNET_ATS_PeerInformationCallback) (void *cls, + const struct + GNUNET_HELLO_Address * + address, + struct + GNUNET_BANDWIDTH_Value32NBO + bandwidth_out, + struct + GNUNET_BANDWIDTH_Value32NBO + bandwidth_in, + const struct + GNUNET_ATS_Information * + ats, uint32_t ats_count); + + +/** + * Get handle to access performance API of the ATS subsystem. + * + * @param cfg configuration to use + * @param infocb function to call on performance changes, can be NULL + * @param infocb_cls closure for infocb + * @return ats performance context + */ +struct GNUNET_ATS_PerformanceHandle * +GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_ATS_PeerInformationCallback infocb, + void *infocb_cls); + + +/** + * Client is done using the ATS performance subsystem, release resources. + * + * @param ph handle + */ +void +GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph); + + +/** + * Function called with reservation result. + * + * @param cls closure + * @param peer identifies the peer + * @param amount set to the amount that was actually reserved or unreserved; + * either the full requested amount or zero (no partial reservations) + * @param res_delay if the reservation could not be satisfied (amount was 0), how + * long should the client wait until re-trying? + */ +typedef void (*GNUNET_ATS_ReservationCallback) (void *cls, + const struct GNUNET_PeerIdentity + * peer, int32_t amount, + struct GNUNET_TIME_Relative + res_delay); + + + +/** + * Context that can be used to cancel a peer information request. + */ +struct GNUNET_ATS_ReservationContext; + + +/** + * Reserve inbound bandwidth from the given peer. ATS will look at + * the current amount of traffic we receive from the peer and ensure + * that the peer could add 'amount' of data to its stream. + * + * @param ph performance handle + * @param peer identifies the peer + * @param amount reserve N bytes for receiving, negative + * amounts can be used to undo a (recent) reservation; + * @param rcb function to call with the resulting reservation information + * @param rcb_cls closure for info + * @return NULL on error + * @deprecated will be replaced soon + */ +struct GNUNET_ATS_ReservationContext * +GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, + const struct GNUNET_PeerIdentity *peer, + int32_t amount, + GNUNET_ATS_ReservationCallback rcb, + void *rcb_cls); + + +/** + * Cancel request for reserving bandwidth. + * + * @param rc context returned by the original GNUNET_ATS_reserve_bandwidth call + */ +void +GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc); + + + +/** + * Enum defining all known preference categories. + */ +enum GNUNET_ATS_PreferenceKind +{ + + /** + * End of preference list. + */ + GNUNET_ATS_PREFERENCE_END = 0, + + /** + * Change the peer's bandwidth value (value per byte of bandwidth in + * the goal function) to the given amount. The argument is followed + * by a double value giving the desired value (can be negative). + * Preference changes are forgotten if peers disconnect. + */ + GNUNET_ATS_PREFERENCE_BANDWIDTH, + + /** + * Change the peer's latency value to the given amount. The + * argument is followed by a double value giving the desired value + * (can be negative). The absolute score in the goal function is + * the inverse of the latency in ms (minimum: 1 ms) multiplied by + * the latency preferences. + */ + GNUNET_ATS_PREFERENCE_LATENCY +}; + + +/** + * Change preferences for the given peer. Preference changes are forgotten if peers + * disconnect. + * + * @param ph performance handle + * @param peer identifies the peer + * @param ... 0-terminated specification of the desired changes + */ +void +GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, + const struct GNUNET_PeerIdentity *peer, ...); + + + +#endif +/* end of file gnunet-service-transport_ats.h */ diff --git a/src/include/gnunet_bandwidth_lib.h b/src/include/gnunet_bandwidth_lib.h new file mode 100644 index 0000000..fabe47b --- /dev/null +++ b/src/include/gnunet_bandwidth_lib.h @@ -0,0 +1,227 @@ +/* + This file is part of GNUnet. + (C) 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_bandwidth_lib.h + * @brief functions related to bandwidth (unit) + * @author Christian Grothoff + */ + +#ifndef GNUNET_BANDWIDTH_LIB_H +#define GNUNET_BANDWIDTH_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" +#include "gnunet_time_lib.h" + +GNUNET_NETWORK_STRUCT_BEGIN + +/** + * 32-bit bandwidth used for network exchange by GNUnet, in bytes per second. + */ +struct GNUNET_BANDWIDTH_Value32NBO +{ + /** + * The actual value (bytes per second). + */ + uint32_t value__ GNUNET_PACKED; +}; +GNUNET_NETWORK_STRUCT_END + +/** + * Struct to track available bandwidth. Combines a time stamp with a + * number of bytes transmitted, a quota and a maximum amount that + * carries over. Not opaque so that it can be inlined into data + * structures (reducing malloc-ing); however, values should not be + * accessed directly by clients (hence the '__'). + */ +struct GNUNET_BANDWIDTH_Tracker +{ + /** + * Number of bytes consumed since we last updated the tracker. + */ + int64_t consumption_since_last_update__; + + /** + * Time when we last updated the tracker. + */ + struct GNUNET_TIME_Absolute last_update__; + + /** + * Bandwidth limit to enforce in bytes per s. + */ + uint32_t available_bytes_per_s__; + + /** + * Maximum number of seconds over which bandwidth may "accumulate". + * Note that additionally, we also always allow at least + * GNUNET_SERVER_MAX_MESSAGE_SIZE to accumulate. + */ + uint32_t max_carry_s__; +}; + + +/** + * Create a new bandwidth value. + * + * @param bytes_per_second value to create + * @return the new bandwidth value + */ +struct GNUNET_BANDWIDTH_Value32NBO +GNUNET_BANDWIDTH_value_init (uint32_t bytes_per_second); + + +/** + * Maximum possible bandwidth value. + */ +#define GNUNET_BANDWIDTH_VALUE_MAX GNUNET_BANDWIDTH_value_init(UINT32_MAX) + + +/** + * At the given bandwidth, calculate how much traffic will be + * available until the given deadline. + * + * @param bps bandwidth + * @param deadline when is the deadline + * @return number of bytes available at bps until deadline + */ +uint64_t +GNUNET_BANDWIDTH_value_get_available_until (struct GNUNET_BANDWIDTH_Value32NBO + bps, + struct GNUNET_TIME_Relative + deadline); + + +/** + * At the given bandwidth, calculate how long it would take for + * 'size' bytes to be transmitted. + * + * @param bps bandwidth + * @param size number of bytes we want to have available + * @return how long it would take + */ +struct GNUNET_TIME_Relative +GNUNET_BANDWIDTH_value_get_delay_for (struct GNUNET_BANDWIDTH_Value32NBO bps, + uint64_t size); + + + +/** + * Compute the MIN of two bandwidth values. + * + * @param b1 first value + * @param b2 second value + * @return the min of b1 and b2 + */ +struct GNUNET_BANDWIDTH_Value32NBO +GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1, + struct GNUNET_BANDWIDTH_Value32NBO b2); + + +/** + * Initialize bandwidth tracker. Note that in addition to the + * 'max_carry_s' limit, we also always allow at least + * GNUNET_SERVER_MAX_MESSAGE_SIZE to accumulate. So if the + * bytes-per-second limit is so small that within 'max_carry_s' not + * even GNUNET_SERVER_MAX_MESSAGE_SIZE is allowed to accumulate, it is + * ignored and replaced by GNUNET_SERVER_MAX_MESSAGE_SIZE (which is in + * bytes). + * + * @param av tracker to initialize + * @param bytes_per_second_limit initial limit to assume + * @param max_carry_s maximum number of seconds unused bandwidth + * may accumulate before it expires + */ +void +GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av, + struct GNUNET_BANDWIDTH_Value32NBO + bytes_per_second_limit, uint32_t max_carry_s); + + +/** + * Notify the tracker that a certain number of bytes of bandwidth have + * been consumed. Note that it is legal to consume bytes even if not + * enough bandwidth is available (in that case, + * GNUNET_BANDWIDTH_tracker_get_delay may return non-zero delay values + * even for a size of zero for a while). + * + * @param av tracker to update + * @param size number of bytes consumed + * @return GNUNET_YES if this consumption is above the limit + */ +int +GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av, + ssize_t size); + + +/** + * Compute how long we should wait until consuming 'size' + * bytes of bandwidth in order to stay within the given + * quota. + * + * @param av tracker to query + * @param size number of bytes we would like to consume + * @return time to wait for consumption to be OK + */ +struct GNUNET_TIME_Relative +GNUNET_BANDWIDTH_tracker_get_delay (struct GNUNET_BANDWIDTH_Tracker *av, + size_t size); + + +/** + * Compute how many bytes are available for consumption right now. + * quota. + * + * @param av tracker to query + * @return number of bytes available for consumption right now + */ +int64_t +GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker *av); + + +/** + * Update quota of bandwidth tracker. + * + * @param av tracker to initialize + * @param bytes_per_second_limit new limit to assume + */ +void +GNUNET_BANDWIDTH_tracker_update_quota (struct GNUNET_BANDWIDTH_Tracker *av, + struct GNUNET_BANDWIDTH_Value32NBO + bytes_per_second_limit); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_BANDWIDTH_LIB_H */ +#endif +/* end of gnunet_bandwidth_lib.h */ diff --git a/src/include/gnunet_bio_lib.h b/src/include/gnunet_bio_lib.h new file mode 100644 index 0000000..47d8d5e --- /dev/null +++ b/src/include/gnunet_bio_lib.h @@ -0,0 +1,303 @@ +/* + This file is part of GNUnet. + (C) 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_bio_lib.h + * @brief buffered IO API + * @author Christian Grothoff + */ + +#ifndef GNUNET_BIO_LIB_H +#define GNUNET_BIO_LIB_H + +#include "gnunet_container_lib.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +/** + * Handle for buffered reading. + */ +struct GNUNET_BIO_ReadHandle; + + +/** + * Open a file for reading. + * + * @param fn file name to be opened + * @return IO handle on success, NULL on error + */ +struct GNUNET_BIO_ReadHandle * +GNUNET_BIO_read_open (const char *fn); + + +/** + * Close an open file. Reports if any errors reading + * from the file were encountered. + * + * @param h file handle + * @param emsg set to the error message + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg); + + +/** + * Read the contents of a binary file into a buffer. + * + * @param h handle to an open file + * @param what describes what is being read (for error message creation) + * @param result the buffer to write the result to + * @param len the number of bytes to read + * @return GNUNET_OK on success, GNUNET_SYSERR on failure + */ +int +GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what, + void *result, size_t len); + + +/** + * Read the contents of a binary file into a buffer. + * + * @param h handle to an open file + * @param file name of the source file + * @param line line number in the source file + * @param result the buffer to write the result to + * @param len the number of bytes to read + * @return GNUNET_OK on success, GNUNET_SYSERR on failure + */ +int +GNUNET_BIO_read_fn (struct GNUNET_BIO_ReadHandle *h, const char *file, int line, + void *result, size_t len); + +/** + * Read 0-terminated string from a file. + * + * @param h handle to an open file + * @param what describes what is being read (for error message creation) + * @param result the buffer to store a pointer to the (allocated) string to + * (note that *result could be set to NULL as well) + * @param maxLen maximum allowed length for the string + * @return GNUNET_OK on success, GNUNET_SYSERR on failure + */ +int +GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what, + char **result, size_t maxLen); + + +/** + * Read metadata container from a file. + * + * @param h handle to an open file + * @param what describes what is being read (for error message creation) + * @param result the buffer to store a pointer to the (allocated) metadata + * @return GNUNET_OK on success, GNUNET_SYSERR on failure + */ +int +GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, const char *what, + struct GNUNET_CONTAINER_MetaData **result); + + +/** + * Read a float. + * + * @param h hande to open file + * @param f address of float to read + */ +#define GNUNET_BIO_read_float(h, f) (GNUNET_BIO_read_fn (h, __FILE__, __LINE__, f, sizeof(float))) + + + +/** + * Read a double. + * + * @param h hande to open file + * @param f address of double to read + */ +#define GNUNET_BIO_read_double(h, f) (GNUNET_BIO_read_fn (h, __FILE__, __LINE__, f, sizeof(double))) + + +/** + * Read an (u)int32_t. + * + * @param h hande to open file + * @param file name of the source file + * @param line line number in the code + * @param i address of 32-bit integer to read + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, const char *file, + int line, int32_t * i); + + +/** + * Read an (u)int32_t. + * + * @param h hande to open file + * @param i address of 32-bit integer to read + */ +#define GNUNET_BIO_read_int32(h, i) GNUNET_BIO_read_int32__ (h, __FILE__, __LINE__, (int32_t*) i) + + +/** + * Read an (u)int64_t. + * + * @param h hande to open file + * @param file name of the source file + * @param line line number in the code + * @param i address of 64-bit integer to read + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, const char *file, + int line, int64_t * i); + + +/** + * Read an (u)int64_t. + * + * @param h hande to open file + * @param i address of 64-bit integer to read + */ +#define GNUNET_BIO_read_int64(h, i) GNUNET_BIO_read_int64__ (h, __FILE__, __LINE__, (int64_t*) i) + + +/** + * Handle for buffered writing. + */ +struct GNUNET_BIO_WriteHandle; + +/** + * Open a file for writing. + * + * @param fn file name to be opened + * @return IO handle on success, NULL on error + */ +struct GNUNET_BIO_WriteHandle * +GNUNET_BIO_write_open (const char *fn); + + +/** + * Close an open file for writing. + * + * @param h file handle + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h); + + +/** + * Write a buffer to a file. + * + * @param h handle to open file + * @param buffer the data to write + * @param n number of bytes to write + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const void *buffer, + size_t n); + + +/** + * Write a string to a file. + * + * @param h handle to open file + * @param s string to write (can be NULL) + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s); + + + + +/** + * Write metadata container to a file. + * + * @param h handle to open file + * @param m metadata to write + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, + const struct GNUNET_CONTAINER_MetaData *m); + + + +/** + * Write a float. + * + * @param h hande to open file + * @param f float to write (must be a variable) + */ +#define GNUNET_BIO_write_float(h, f) GNUNET_BIO_write (h, &f, sizeof(float)) + + + +/** + * Write a double. + * + * @param h hande to open file + * @param f double to write (must be a variable) + */ +#define GNUNET_BIO_write_double(h, f) GNUNET_BIO_write (h, &f, sizeof(double)) + + +/** + * Write an (u)int32_t. + * + * @param h hande to open file + * @param i 32-bit integer to write + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i); + + +/** + * Write an (u)int64_t. + * + * @param h hande to open file + * @param i 64-bit integer to write + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_BIO_LIB_H */ +#endif +/* end of gnunet_bio_lib.h */ diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h new file mode 100644 index 0000000..adc1775 --- /dev/null +++ b/src/include/gnunet_block_lib.h @@ -0,0 +1,260 @@ +/* + This file is part of GNUnet. + (C) 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file include/gnunet_block_lib.h + * @brief library for data block manipulation + * @author Christian Grothoff + */ +#ifndef GNUNET_BLOCK_LIB_H +#define GNUNET_BLOCK_LIB_H + +#include "gnunet_util_lib.h" +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * Blocks in the datastore and the datacache must have a unique type. + */ +enum GNUNET_BLOCK_Type +{ + /** + * Any type of block, used as a wildcard when searching. Should + * never be attached to a specific block. + */ + GNUNET_BLOCK_TYPE_ANY = 0, + + /** + * Data block (leaf) in the CHK tree. + */ + GNUNET_BLOCK_TYPE_FS_DBLOCK = 1, + + /** + * Inner block in the CHK tree. + */ + GNUNET_BLOCK_TYPE_FS_IBLOCK = 2, + + /** + * Type of a block representing a keyword search result. Note that + * the values for KBLOCK, SBLOCK and NBLOCK must be consecutive. + */ + GNUNET_BLOCK_TYPE_FS_KBLOCK = 3, + + /** + * Type of a block that is used to advertise content in a namespace. + */ + GNUNET_BLOCK_TYPE_FS_SBLOCK = 4, + + /** + * Type of a block that is used to advertise a namespace. + */ + GNUNET_BLOCK_TYPE_FS_NBLOCK = 5, + + /** + * Type of a block representing a block to be encoded on demand from disk. + * Should never appear on the network directly. + */ + GNUNET_BLOCK_TYPE_FS_ONDEMAND = 6, + + /** + * Type of a block that contains a HELLO for a peer (for + * DHT find-peer operations). + */ + GNUNET_BLOCK_TYPE_DHT_HELLO = 7, + + /** + * Block for testing. + */ + GNUNET_BLOCK_TYPE_TEST = 8, + + /** + * Block for storing .gnunet-domains + */ + GNUNET_BLOCK_TYPE_DNS = 10, + + /** + * Block for storing record data + */ + GNUNET_BLOCK_TYPE_GNS_NAMERECORD = 11 +}; + + +/** + * Possible ways for how a block may relate to a query. + */ +enum GNUNET_BLOCK_EvaluationResult +{ + /** + * Valid result, and there may be more. + */ + GNUNET_BLOCK_EVALUATION_OK_MORE = 0, + + /** + * Last possible valid result. + */ + GNUNET_BLOCK_EVALUATION_OK_LAST = 1, + + /** + * Valid result, but suppressed because it is a duplicate. + */ + GNUNET_BLOCK_EVALUATION_OK_DUPLICATE = 2, + + /** + * Block does not match query (invalid result) + */ + GNUNET_BLOCK_EVALUATION_RESULT_INVALID = 3, + + /** + * Query is valid, no reply given. + */ + GNUNET_BLOCK_EVALUATION_REQUEST_VALID = 4, + + /** + * 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, + + /** + * Specified block type not supported by this plugin. + */ + GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED = 6 +}; + + +/** + * Handle to an initialized block library. + */ +struct GNUNET_BLOCK_Context; + + +/** + * Mingle hash with the mingle_number to produce different bits. + * + * @param in original hash code + * @param mingle_number number for hash permutation + * @param hc where to store the result. + */ +void +GNUNET_BLOCK_mingle_hash (const GNUNET_HashCode * in, uint32_t mingle_number, + GNUNET_HashCode * hc); + + +/** + * Create a block context. Loads the block plugins. + * + * @param cfg configuration to use + * @return NULL on error + */ +struct GNUNET_BLOCK_Context * +GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Destroy the block context. + * + * @param ctx context to destroy + */ +void +GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx); + + +/** + * Function called to validate a reply or a request. For + * request evaluation, simply pass "NULL" for the reply_block. + * Note that it is assumed that the reply has already been + * matched to the key (and signatures checked) as it would + * be done with the "get_key" function. + * + * @param ctx block contxt + * @param type block type + * @param query original query (hash) + * @param bf pointer to bloom filter associated with query; possibly updated (!) + * @param bf_mutator mutation value for bf + * @param xquery extrended query data (can be NULL, depending on type) + * @param xquery_size number of bytes in xquery + * @param reply_block response to validate + * @param reply_block_size number of bytes in reply block + * @return characterization of result + */ +enum GNUNET_BLOCK_EvaluationResult +GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, + enum GNUNET_BLOCK_Type type, + const GNUNET_HashCode * query, + struct GNUNET_CONTAINER_BloomFilter **bf, + int32_t bf_mutator, const void *xquery, + size_t xquery_size, const void *reply_block, + size_t reply_block_size); + + +/** + * Function called to obtain the key for a block. + * + * @param ctx block context + * @param type block type + * @param block block to get the key for + * @param block_size number of bytes in block + * @param key set to the key (query) for the given block + * @return GNUNET_YES on success, + * GNUNET_NO if the block is malformed + * GNUNET_SYSERR if type not supported + * (or if extracting a key from a block of this type does not work) + */ +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); + + + +/** + * Construct a bloom filter that would filter out the given + * results. + * + * @param bf_mutator mutation value to use + * @param seen_results results already seen + * @param seen_results_count number of entries in 'seen_results' + * @return NULL if seen_results_count is 0, otherwise a BF + * that would match the given results. + */ +struct GNUNET_CONTAINER_BloomFilter * +GNUNET_BLOCK_construct_bloomfilter (int32_t bf_mutator, + const GNUNET_HashCode * seen_results, + unsigned int seen_results_count); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + +/* ifndef GNUNET_BLOCK_LIB_H */ +#endif +/* end of gnunet_block_lib.h */ diff --git a/src/include/gnunet_block_plugin.h b/src/include/gnunet_block_plugin.h new file mode 100644 index 0000000..0ead4af --- /dev/null +++ b/src/include/gnunet_block_plugin.h @@ -0,0 +1,128 @@ +/* + This file is part of GNUnet + (C) 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file include/gnunet_block_plugin.h + * @brief API for block plugins. Each block plugin must conform to + * the API specified by this header. + * @author Christian Grothoff + */ +#ifndef PLUGIN_BLOCK_H +#define PLUGIN_BLOCK_H + +#include "gnunet_util_lib.h" +#include "gnunet_container_lib.h" +#include "gnunet_block_lib.h" + + +/** + * Function called to validate a reply or a request. For + * request evaluation, simply pass "NULL" for the reply_block. + * Note that it is assumed that the reply has already been + * matched to the key (and signatures checked) as it would + * be done with the "get_key" function. + * + * @param cls closure + * @param type block type + * @param query original query (hash) + * @param bf pointer to bloom filter associated with query; possibly updated (!) + * @param bf_mutator mutation value for bf + * @param xquery extrended query data (can be NULL, depending on type) + * @param xquery_size number of bytes in xquery + * @param reply_block response to validate + * @param reply_block_size number of bytes in reply block + * @return characterization of result + */ +typedef enum + GNUNET_BLOCK_EvaluationResult (*GNUNET_BLOCK_EvaluationFunction) (void *cls, + enum + GNUNET_BLOCK_Type + type, + const + GNUNET_HashCode + * query, + struct + GNUNET_CONTAINER_BloomFilter + ** bf, + int32_t + bf_mutator, + const void + *xquery, + size_t + xquery_size, + const void + *reply_block, + size_t + reply_block_size); + + +/** + * Function called to obtain the key for a block. + * + * @param cls closure + * @param type block type + * @param block block to get the key for + * @param block_size number of bytes in block + * @param key set to the key (query) for the given block + * @return GNUNET_YES on success, + * GNUNET_NO if the block is malformed + * GNUNET_SYSERR if type not supported + * (or if extracting a key from a block of this type does not work) + */ +typedef int (*GNUNET_BLOCK_GetKeyFunction) (void *cls, + enum GNUNET_BLOCK_Type type, + const void *block, + size_t block_size, + GNUNET_HashCode * key); + + + +/** + * Each plugin is required to return a pointer to a struct of this + * type as the return value from its entry point. + */ +struct GNUNET_BLOCK_PluginFunctions +{ + + /** + * Closure for all of the callbacks. + */ + void *cls; + + /** + * 0-terminated array of block types supported by this plugin. + */ + const enum GNUNET_BLOCK_Type *types; + + /** + * Main function of a block plugin. Allows us to check if a + * block matches a query. + */ + GNUNET_BLOCK_EvaluationFunction evaluate; + + /** + * Obtain the key for a given block (if possible). + */ + GNUNET_BLOCK_GetKeyFunction get_key; + +}; + + +#endif diff --git a/src/include/gnunet_chat_service.h b/src/include/gnunet_chat_service.h new file mode 100644 index 0000000..938b434 --- /dev/null +++ b/src/include/gnunet_chat_service.h @@ -0,0 +1,253 @@ +/* + This file is part of GNUnet. + (C) 2009, 2011 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_chat_service.h + * @brief API for chatting via GNUnet + * @author Christian Grothoff + * @author Nathan Evans + * @author Vitaly Minko + */ + +#ifndef GNUNET_CHAT_SERVICE_H +#define GNUNET_CHAT_SERVICE_H + +#include "gnunet_util_lib.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +#define GNUNET_CHAT_VERSION 0x00000003 +#define MAX_MESSAGE_LENGTH (32 * 1024) + +/** + * Options for messaging. Compatible options can be OR'ed together. + */ +enum GNUNET_CHAT_MsgOptions +{ + /** + * No special options. + */ + GNUNET_CHAT_MSG_OPTION_NONE = 0, + + /** + * Encrypt the message so that only the receiver can decrypt it. + */ + GNUNET_CHAT_MSG_PRIVATE = 1, + + /** + * Hide the identity of the sender. + */ + GNUNET_CHAT_MSG_ANONYMOUS = 2, + + /** + * Sign the content, authenticating the sender (using the provided private + * key, which may represent a pseudonym). + */ + GNUNET_CHAT_MSG_AUTHENTICATED = 4, + + /** + * Require signed acknowledgment before completing delivery (and of course, + * only acknowledge if delivery is guaranteed). + */ + GNUNET_CHAT_MSG_ACKNOWLEDGED = 8, + + /** + * Authenticate for the receiver, but ensure that receiver cannot prove + * authenticity to third parties later. (not yet implemented) + */ + GNUNET_CHAT_MSG_OFF_THE_RECORD = 16, + +}; + +/** + * Handle for a (joined) chat room. + */ +struct GNUNET_CHAT_Room; + +/** + * Callback used for notification that we have joined the room. + * + * @param cls closure + * @return GNUNET_OK + */ +typedef int (*GNUNET_CHAT_JoinCallback) (void *cls); + +/** + * Callback used for notification about incoming messages. + * + * @param cls closure + * @param room in which room was the message received? + * @param sender what is the ID of the sender? (maybe NULL) + * @param member_info information about the joining member + * @param message the message text + * @param timestamp when was the message sent? + * @param options options for the message + * @return GNUNET_OK to accept the message now, GNUNET_NO to + * accept (but user is away), GNUNET_SYSERR to signal denied delivery + */ +typedef int (*GNUNET_CHAT_MessageCallback) (void *cls, + struct GNUNET_CHAT_Room * room, + const GNUNET_HashCode * sender, + const struct + GNUNET_CONTAINER_MetaData * + member_info, const char *message, + struct GNUNET_TIME_Absolute + timestamp, + enum GNUNET_CHAT_MsgOptions + options); + +/** + * Callback used for notification that another room member has joined or left. + * + * @param cls closure + * @param member_info will be non-null if the member is joining, NULL if he is + * leaving + * @param member_id hash of public key of the user (for unique identification) + * @param options what types of messages is this member willing to receive? + * @return GNUNET_OK + */ +typedef int (*GNUNET_CHAT_MemberListCallback) (void *cls, + const struct + GNUNET_CONTAINER_MetaData * + member_info, + const struct + GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded + * member_id, + enum GNUNET_CHAT_MsgOptions + options); + +/** + * Callback used for message delivery confirmations. + * + * @param cls closure + * @param room in which room was the message received? + * @param orig_seq_number sequence number of the original message + * @param timestamp when was the message received? + * @param receiver who is confirming the receipt? + * @return GNUNET_OK to continue, GNUNET_SYSERR to refuse processing further + * confirmations from anyone for this message + */ +typedef int (*GNUNET_CHAT_MessageConfirmation) (void *cls, + struct GNUNET_CHAT_Room * room, + uint32_t orig_seq_number, + struct GNUNET_TIME_Absolute + timestamp, + const GNUNET_HashCode * + receiver); + +/** + * Join a chat room. + * + * @param cfg configuration + * @param nick_name nickname of the user joining (used to + * determine which public key to use); + * the nickname should probably also + * be used in the member_info (as "EXTRACTOR_TITLE") + * @param member_info information about the joining member + * @param room_name name of the room + * @param msg_options message options of the joining user + * @param joinCallback which function to call when we've joined the room + * @param join_cls argument to callback + * @param messageCallback which function to call if a message has + * been received? + * @param message_cls argument to callback + * @param memberCallback which function to call for join/leave notifications + * @param member_cls argument to callback + * @param confirmationCallback which function to call for confirmations + * (maybe NULL) + * @param confirmation_cls argument to callback + * @param me member ID (pseudonym) + * @return NULL on error + */ +struct GNUNET_CHAT_Room * +GNUNET_CHAT_join_room (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *nick_name, + struct GNUNET_CONTAINER_MetaData *member_info, + const char *room_name, + enum GNUNET_CHAT_MsgOptions msg_options, + GNUNET_CHAT_JoinCallback joinCallback, void *join_cls, + GNUNET_CHAT_MessageCallback messageCallback, + void *message_cls, + GNUNET_CHAT_MemberListCallback memberCallback, + void *member_cls, + GNUNET_CHAT_MessageConfirmation confirmationCallback, + void *confirmation_cls, GNUNET_HashCode * me); + +/** + * Send a message. + * + * @param room handle for the chat room + * @param message message to be sent + * @param options options for the message + * @param receiver use NULL to send to everyone in the room + * @param sequence_number where to write the sequence id of the message + */ +void +GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room, const char *message, + enum GNUNET_CHAT_MsgOptions options, + const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded + *receiver, uint32_t * sequence_number); + + +/** + * Leave a chat room. + */ +void +GNUNET_CHAT_leave_room (struct GNUNET_CHAT_Room *chat_room); + + +#if 0 +/* these are not yet implemented / supported */ +/** + * Callback function to iterate over rooms. + * + * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration + */ +typedef int (*GNUNET_CHAT_RoomIterator) (const char *room, const char *topic, + void *cls); + +/** + * List all of the (publically visible) chat rooms. + * @return number of rooms on success, GNUNET_SYSERR if iterator aborted + */ +int +GNUNET_CHAT_list_rooms (struct GNUNET_GE_Context *ectx, + struct GNUNET_GC_Configuration *cfg, + GNUNET_CHAT_RoomIterator it, void *cls); +#endif + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif + +/* end of gnunet_chat_service.h */ diff --git a/src/include/gnunet_client_lib.h b/src/include/gnunet_client_lib.h new file mode 100644 index 0000000..60fa938 --- /dev/null +++ b/src/include/gnunet_client_lib.h @@ -0,0 +1,222 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_client_lib.h + * @brief functions related to accessing services + * @author Christian Grothoff + */ + +#ifndef GNUNET_CLIENT_LIB_H +#define GNUNET_CLIENT_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" +#include "gnunet_configuration_lib.h" +#include "gnunet_connection_lib.h" +#include "gnunet_scheduler_lib.h" +#include "gnunet_time_lib.h" + +/** + * Opaque handle for a connection to a service. + */ +struct GNUNET_CLIENT_Connection; + +/** + * Get a connection with a service. + * + * @param service_name name of the service + * @param cfg configuration to use + * @return NULL on error (service unknown to configuration) + */ +struct GNUNET_CLIENT_Connection * +GNUNET_CLIENT_connect (const char *service_name, + const struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Destroy connection with the service. This will automatically + * cancel any pending "receive" request (however, the handler will + * *NOT* be called, not even with a NULL message). Any pending + * transmission request will also be cancelled UNLESS the callback for + * the transmission request has already been called, in which case the + * transmission 'finish_pending_write' argument determines whether or + * not the write is guaranteed to complete before the socket is fully + * destroyed (unless, of course, there is an error with the server in + * which case the message may still be lost). + * + * @param sock handle to the service connection + * @param finish_pending_write should a transmission already passed to the + * handle be completed? + */ +void +GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock, + int finish_pending_write); + + +/** + * Type of a function to call when we receive a message + * from the service. + * + * @param cls closure + * @param msg message received, NULL on timeout or fatal error + */ +typedef void (*GNUNET_CLIENT_MessageHandler) (void *cls, + const struct GNUNET_MessageHeader + * msg); + + +/** + * Type of a function to call when we have finished shutting + * down a service, or failed. + * + * @param cls closure + * @param reason what is the result of the shutdown + * GNUNET_NO on shutdown (not running) + * GNUNET_YES on running + * GNUNET_SYSERR on failure to transmit message + */ +typedef void (*GNUNET_CLIENT_ShutdownTask) (void *cls, int reason); + + +/** + * Read from the service. + * + * @param sock the service + * @param handler function to call with the message + * @param handler_cls closure for handler + * @param timeout how long to wait until timing out + */ +void +GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock, + GNUNET_CLIENT_MessageHandler handler, void *handler_cls, + struct GNUNET_TIME_Relative timeout); + + +/** + * Transmit handle for client connections. + */ +struct GNUNET_CLIENT_TransmitHandle; + + +/** + * Ask the client to call us once the specified number of bytes + * are free in the transmission buffer. May call the notify + * method immediately if enough space is available. + * + * @param sock connection to the service + * @param size number of bytes to send + * @param timeout after how long should we give up (and call + * notify with buf NULL and size 0)? + * @param auto_retry if the connection to the service dies, should we + * automatically re-connect and retry (within the timeout period) + * or should we immediately fail in this case? Pass GNUNET_YES + * if the caller does not care about temporary connection errors, + * for example because the protocol is stateless + * @param notify function to call + * @param notify_cls closure for notify + * @return NULL if someone else is already waiting to be notified + * non-NULL if the notify callback was queued (can be used to cancel + * using GNUNET_CONNECTION_notify_transmit_ready_cancel) + */ +struct GNUNET_CLIENT_TransmitHandle * +GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock, + size_t size, + struct GNUNET_TIME_Relative timeout, + int auto_retry, + GNUNET_CONNECTION_TransmitReadyNotify + notify, void *notify_cls); + + +/** + * Cancel a request for notification. + * + * @param th handle from the original request. + */ +void +GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle + *th); + + +/** + * Convenience API that combines sending a request + * to the service and waiting for a response. + * If either operation times out, the callback + * will be called with a "NULL" response (in which + * case the connection should probably be destroyed). + * + * @param sock connection to use + * @param hdr message to transmit + * @param timeout when to give up (for both transmission + * and for waiting for a response) + * @param auto_retry if the connection to the service dies, should we + * automatically re-connect and retry (within the timeout period) + * or should we immediately fail in this case? Pass GNUNET_YES + * if the caller does not care about temporary connection errors, + * for example because the protocol is stateless + * @param rn function to call with the response + * @param rn_cls closure for rn + * @return GNUNET_OK on success, GNUNET_SYSERR if a request + * is already pending + */ +int +GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection *sock, + const struct GNUNET_MessageHeader *hdr, + struct GNUNET_TIME_Relative timeout, + int auto_retry, + GNUNET_CLIENT_MessageHandler rn, + void *rn_cls); + + +/** + * Wait until the service is running. + * + * @param service name of the service to wait for + * @param cfg configuration to use + * @param timeout how long to wait at most in ms + * @param task task to run if service is running + * (reason will be "PREREQ_DONE" (service running) + * or "TIMEOUT" (service not known to be running)) + * @param task_cls closure for task + */ +void +GNUNET_CLIENT_service_test (const char *service, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TIME_Relative timeout, + GNUNET_SCHEDULER_Task task, void *task_cls); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_CLIENT_LIB_H */ +#endif +/* end of gnunet_client_lib.h */ diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h new file mode 100644 index 0000000..a1ef4ee --- /dev/null +++ b/src/include/gnunet_common.h @@ -0,0 +1,840 @@ +/* + This file is part of GNUnet. + (C) 2006, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_common.h + * @brief commonly used definitions; globals in this file + * are exempt from the rule that the module name ("common") + * must be part of the symbol name. + * + * @author Christian Grothoff + * @author Nils Durner + */ +#ifndef GNUNET_COMMON_H +#define GNUNET_COMMON_H + +#if HAVE_SYS_SOCKET_H +#include <sys/socket.h> +#endif +#if HAVE_NETINET_IN_H +#include <netinet/in.h> +#endif +#ifdef MINGW +#include "winproc.h" +#endif +#ifdef HAVE_STDINT_H +#include <stdint.h> +#endif +#ifdef HAVE_STDARG_H +#include <stdarg.h> +#endif + +/** + * Version of the API (for entire gnunetutil.so library). + */ +#define GNUNET_UTIL_VERSION 0x00090200 + +/** + * Named constants for return values. The following + * invariants hold: "GNUNET_NO == 0" (to allow "if (GNUNET_NO)") + * "GNUNET_OK != GNUNET_SYSERR", "GNUNET_OK != GNUNET_NO", "GNUNET_NO != GNUNET_SYSERR" + * and finally "GNUNET_YES != GNUNET_NO". + */ +#define GNUNET_OK 1 +#define GNUNET_SYSERR -1 +#define GNUNET_YES 1 +#define GNUNET_NO 0 + +#define GNUNET_MIN(a,b) (((a) < (b)) ? (a) : (b)) + +#define GNUNET_MAX(a,b) (((a) > (b)) ? (a) : (b)) + +/* some systems use one underscore only, and mingw uses no underscore... */ +#ifndef __BYTE_ORDER +#ifdef _BYTE_ORDER +#define __BYTE_ORDER _BYTE_ORDER +#else +#ifdef BYTE_ORDER +#define __BYTE_ORDER BYTE_ORDER +#endif +#endif +#endif +#ifndef __BIG_ENDIAN +#ifdef _BIG_ENDIAN +#define __BIG_ENDIAN _BIG_ENDIAN +#else +#ifdef BIG_ENDIAN +#define __BIG_ENDIAN BIG_ENDIAN +#endif +#endif +#endif +#ifndef __LITTLE_ENDIAN +#ifdef _LITTLE_ENDIAN +#define __LITTLE_ENDIAN _LITTLE_ENDIAN +#else +#ifdef LITTLE_ENDIAN +#define __LITTLE_ENDIAN LITTLE_ENDIAN +#endif +#endif +#endif + +/** + * Endian operations + */ + +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define GNUNET_htobe16(x) __bswap_16 (x) +# define GNUNET_htole16(x) (x) +# define GNUNET_be16toh(x) __bswap_16 (x) +# define GNUNET_le16toh(x) (x) + +# define GNUNET_htobe32(x) __bswap_32 (x) +# define GNUNET_htole32(x) (x) +# define GNUNET_be32toh(x) __bswap_32 (x) +# define GNUNET_le32toh(x) (x) + +# define GNUNET_htobe64(x) __bswap_64 (x) +# define GNUNET_htole64(x) (x) +# define GNUNET_be64toh(x) __bswap_64 (x) +# define GNUNET_le64toh(x) (x) +#endif +# if __BYTE_ORDER == __BIG_ENDIAN +# define GNUNET_htobe16(x) (x) +# define GNUNET_htole16(x) __bswap_16 (x) +# define GNUNET_be16toh(x) (x) +# define GNUNET_le16toh(x) __bswap_16 (x) + +# define GNUNET_htobe32(x) (x) +# define GNUNET_htole32(x) __bswap_32 (x) +# define GNUNET_be32toh(x) (x) +# define GNUNET_le32toh(x) __bswap_32 (x) + +# define GNUNET_htobe64(x) (x) +# define GNUNET_htole64(x) __bswap_64 (x) +# define GNUNET_be64toh(x) (x) +# define GNUNET_le64toh(x) __bswap_64 (x) +#endif + + + + +/** + * gcc-ism to get packed structs. + */ +#define GNUNET_PACKED __attribute__((packed)) + +/** + * gcc-ism to document unused arguments + */ +#define GNUNET_UNUSED __attribute__((unused)) + +/** + * gcc-ism to document functions that don't return + */ +#define GNUNET_NORETURN __attribute__((noreturn)) + +#if __GNUC__ > 3 +/** + * gcc 4.x-ism to pack structures even on W32 (to be used before structs) + */ +#define GNUNET_NETWORK_STRUCT_BEGIN \ + _Pragma("pack(push)") \ + _Pragma("pack(1)") + +/** + * gcc 4.x-ism to pack structures even on W32 (to be used after structs) + */ +#define GNUNET_NETWORK_STRUCT_END _Pragma("pack(pop)") +#else +#ifdef MINGW +#error gcc 4.x or higher required on W32 systems +#endif +/** + * Good luck, 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 GNUNET_NETWORK_STRUCT_END +#endif + +/* ************************ super-general types *********************** */ + +GNUNET_NETWORK_STRUCT_BEGIN + +/** + * Header for all communications. + */ +struct GNUNET_MessageHeader +{ + + /** + * The length of the struct (in bytes, including the length field itself), + * in big-endian format. + */ + uint16_t size GNUNET_PACKED; + + /** + * The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format. + */ + uint16_t type GNUNET_PACKED; + +}; +GNUNET_NETWORK_STRUCT_END + +/** + * @brief 512-bit hashcode + */ +typedef struct +{ + uint32_t bits[512 / 8 / sizeof (uint32_t)]; /* = 16 */ +} +GNUNET_HashCode; + + +GNUNET_NETWORK_STRUCT_BEGIN + +/** + * The identity of the host (basically the SHA-512 hashcode of + * it's public key). + */ +struct GNUNET_PeerIdentity +{ + GNUNET_HashCode hashPubKey GNUNET_PACKED; +}; +GNUNET_NETWORK_STRUCT_END + +/** + * Function called with a filename. + * + * @param cls closure + * @param filename complete filename (absolute path) + * @return GNUNET_OK to continue to iterate, + * GNUNET_SYSERR to abort iteration with error! + */ +typedef int (*GNUNET_FileNameCallback) (void *cls, const char *filename); + + +/* ****************************** logging ***************************** */ + +/** + * Types of errors. + */ +enum GNUNET_ErrorType +{ + GNUNET_ERROR_TYPE_UNSPECIFIED = -1, + GNUNET_ERROR_TYPE_NONE = 0, + GNUNET_ERROR_TYPE_ERROR = 1, + GNUNET_ERROR_TYPE_WARNING = 2, + GNUNET_ERROR_TYPE_INFO = 4, + GNUNET_ERROR_TYPE_DEBUG = 8, + GNUNET_ERROR_TYPE_INVALID = 16, + GNUNET_ERROR_TYPE_BULK = 32 +}; + + +/** + * User-defined handler for log messages. + * + * @param cls closure + * @param kind severeity + * @param component what component is issuing the message? + * @param date when was the message logged? + * @param message what is the message + */ +typedef void (*GNUNET_Logger) (void *cls, enum GNUNET_ErrorType kind, + const char *component, const char *date, + const char *message); + + +/** + * Number of log calls to ignore. + */ +extern unsigned int skip_log; + +#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. + * + * @param kind how serious is the error? + * @param message what is the message (format string) + * @param ... arguments for format string + */ +void +GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...); + +/* from glib */ +#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) +#define _GNUNET_BOOLEAN_EXPR(expr) \ + __extension__ ({ \ + int _gnunet_boolean_var_; \ + if (expr) \ + _gnunet_boolean_var_ = 1; \ + else \ + _gnunet_boolean_var_ = 0; \ + _gnunet_boolean_var_; \ +}) +#define GN_LIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR(expr), 1)) +#define GN_UNLIKELY(expr) (__builtin_expect (_GNUNET_BOOLEAN_EXPR(expr), 0)) +#else +#define GN_LIKELY(expr) (expr) +#define GN_UNLIKELY(expr) (expr) +#endif + +#if !defined(GNUNET_LOG_CALL_STATUS) +#define GNUNET_LOG_CALL_STATUS -1 +#endif + +/** + * Log function that specifies an alternative component. + * This function should be used by plugins. + * + * @param kind how serious is the error? + * @param comp component responsible for generating the message + * @param message what is the message (format string) + * @param ... arguments for format string + */ +void +GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp, + const char *message, ...); + +#if !defined(GNUNET_CULL_LOGGING) +#define GNUNET_log_from(kind,comp,...) do { int log_line = __LINE__;\ + static int log_call_enabled = GNUNET_LOG_CALL_STATUS;\ + 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--;}\ + else {\ + if (GN_UNLIKELY(log_call_enabled))\ + GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__); \ + }\ + }\ +} while (0) + +#define GNUNET_log(kind,...) do { int log_line = __LINE__;\ + static int log_call_enabled = GNUNET_LOG_CALL_STATUS;\ + 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--;}\ + else {\ + if (GN_UNLIKELY(log_call_enabled))\ + GNUNET_log_nocheck ((kind), __VA_ARGS__); \ + }\ + }\ +} while (0) +#else +#define GNUNET_log(...) +#define GNUNET_log_from(...) +#endif + + +/** + * Abort the process, generate a core dump if possible. + */ +void +GNUNET_abort (void) GNUNET_NORETURN; + +/** + * Ignore the next n calls to the log function. + * + * @param n number of log calls to ignore + * @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); + + +/** + * Setup logging. + * + * @param comp default component to use + * @param loglevel what types of messages should be logged + * @param logfile change logging to logfile (use NULL to keep stderr) + * @return GNUNET_OK on success, GNUNET_SYSERR if logfile could not be opened + */ +int +GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile); + + +/** + * Add a custom logger. + * + * @param logger log function + * @param logger_cls closure for logger + */ +void +GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls); + + +/** + * Remove a custom logger. + * + * @param logger log function + * @param logger_cls closure for logger + */ +void +GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls); + + +/** + * 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! + * + * @param hc the hash code + * @return string + */ +const char * +GNUNET_h2s (const GNUNET_HashCode * hc); + + +/** + * Convert a 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 hash code + * @return string + */ +const char * +GNUNET_h2s_full (const GNUNET_HashCode * hc); + + +/** + * Convert a peer identity to a string (for printing debug messages). + * This is one of the very few calls in the entire API that is + * NOT reentrant! + * + * @param pid the peer identity + * @return string form of the pid; will be overwritten by next + * call to GNUNET_i2s. + */ +const char * +GNUNET_i2s (const struct GNUNET_PeerIdentity *pid); + +/** + * Convert a peer identity to a string (for printing debug messages). + * This is one of the very few calls in the entire API that is + * NOT reentrant! + * + * @param pid the peer identity + * @return string form of the pid; will be overwritten by next + * call to GNUNET_i2s. + */ +const char * +GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid); + +/** + * Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string + * (for printing debug messages). This is one of the very few calls + * in the entire API that is NOT reentrant! + * + * @param addr the address + * @param addrlen the length of the address + * @return nicely formatted string for the address + * will be overwritten by next call to GNUNET_a2s. + */ +const char * +GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen); + +/** + * Convert error type to string. + * + * @param kind type to convert + * @return string corresponding to the type + */ +const char * +GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); + + +/** + * Use this for fatal errors that cannot be handled + */ +#define GNUNET_assert(cond) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d.\n"), __FILE__, __LINE__); GNUNET_abort(); } } while(0) + +/** + * Use this for fatal errors that cannot be handled + */ +#define GNUNET_assert_at(cond, f, l) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d.\n"), f, l); GNUNET_abort(); } } while(0) + +/** + * Use this for internal assertion violations that are + * not fatal (can be handled) but should not occur. + */ +#define GNUNET_break(cond) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Assertion failed at %s:%d.\n"), __FILE__, __LINE__); } } while(0) + +/** + * Use this for assertion violations caused by other + * peers (i.e. protocol violations). We do not want to + * confuse end-users (say, some other peer runs an + * older, broken or incompatible GNUnet version), but + * we still want to see these problems during + * development and testing. "OP == other peer". + */ +#define GNUNET_break_op(cond) do { if (! (cond)) { GNUNET_log(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, _("External protocol violation detected at %s:%d.\n"), __FILE__, __LINE__); } } while(0) + +/** + * Log an error message at log-level 'level' that indicates + * a failure of the command 'cmd' with the message given + * by strerror(errno). + */ +#define GNUNET_log_strerror(level, cmd) do { GNUNET_log(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, STRERROR(errno)); } while(0) + +/** + * Log an error message at log-level 'level' that indicates + * a failure of the command 'cmd' with the message given + * by strerror(errno). + */ +#define GNUNET_log_from_strerror(level, component, cmd) do { GNUNET_log_from (level, component, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, STRERROR(errno)); } while(0) + +/** + * Log an error message at log-level 'level' that indicates + * a failure of the command 'cmd' with the message given + * by strerror(errno). + */ +#define GNUNET_log_strerror_file(level, cmd, filename) do { GNUNET_log(level, _("`%s' failed on file `%s' at %s:%d with error: %s\n"), cmd, filename,__FILE__, __LINE__, STRERROR(errno)); } while(0) + +/** + * Log an error message at log-level 'level' that indicates + * a failure of the command 'cmd' with the message given + * by strerror(errno). + */ +#define GNUNET_log_from_strerror_file(level, component, cmd, filename) do { GNUNET_log_from (level, component, _("`%s' failed on file `%s' at %s:%d with error: %s\n"), cmd, filename,__FILE__, __LINE__, STRERROR(errno)); } while(0) + +/* ************************* endianess conversion ****************** */ + +/** + * Convert unsigned 64-bit integer to host-byte-order. + * @param n the value in network byte order + * @return the same value in host byte order + */ +uint64_t +GNUNET_ntohll (uint64_t n); + +/** + * Convert unsigned 64-bit integer to network-byte-order. + * @param n the value in host byte order + * @return the same value in network byte order + */ +uint64_t +GNUNET_htonll (uint64_t n); + +/** + * Convert double to network-byte-order. + * @param d the value in network byte order + * @return the same value in host byte order + */ +double +GNUNET_hton_double (double d); + +/** + * Convert double to host-byte-order + * @param d the value in network byte order + * @return the same value in host byte order + */ +double +GNUNET_ntoh_double (double d); + +/* ************************* allocation functions ****************** */ + +/** + * Maximum allocation with GNUNET_malloc macro. + */ +#define GNUNET_MAX_MALLOC_CHECKED (1024 * 1024 * 40) + +/** + * Wrapper around malloc. Allocates size bytes of memory. + * The memory will be zero'ed out. + * + * @param size the number of bytes to allocate, must be + * smaller than 40 MB. + * @return pointer to size bytes of memory, never NULL (!) + */ +#define GNUNET_malloc(size) GNUNET_xmalloc_(size, __FILE__, __LINE__) + +/** + * Allocate and initialize a block of memory. + * + * @param buf data to initalize the block with + * @param size the number of bytes in buf (and size of the allocation) + * @return pointer to size bytes of memory, never NULL (!) + */ +#define GNUNET_memdup(buf,size) GNUNET_xmemdup_(buf, size, __FILE__, __LINE__) + +/** + * Wrapper around malloc. Allocates size bytes of memory. + * The memory will be zero'ed out. + * + * @param size the number of bytes to allocate + * @return pointer to size bytes of memory, NULL if we do not have enough memory + */ +#define GNUNET_malloc_large(size) GNUNET_xmalloc_unchecked_(size, __FILE__, __LINE__) + +/** + * Wrapper around realloc. Rellocates size bytes of memory. + * + * @param ptr the pointer to reallocate + * @param size the number of bytes to reallocate + * @return pointer to size bytes of memory + */ +#define GNUNET_realloc(ptr, size) GNUNET_xrealloc_(ptr, size, __FILE__, __LINE__) + +/** + * Wrapper around free. Frees the memory referred to by ptr. + * Note that is is generally better to free memory that was + * allocated with GNUNET_array_grow using GNUNET_array_grow(mem, size, 0) instead of GNUNET_free. + * + * @param ptr location where to free the memory. ptr must have + * been returned by GNUNET_strdup, GNUNET_strndup, GNUNET_malloc or GNUNET_array_grow earlier. + */ +#define GNUNET_free(ptr) GNUNET_xfree_(ptr, __FILE__, __LINE__) + +/** + * Free the memory pointed to by ptr if ptr is not NULL. + * Equivalent to if (ptr!=null)GNUNET_free(ptr). + * + * @param ptr the location in memory to free + */ +#define GNUNET_free_non_null(ptr) do { void * __x__ = ptr; if (__x__ != NULL) { GNUNET_free(__x__); } } while(0) + +/** + * Wrapper around GNUNET_strdup. Makes a copy of the zero-terminated string + * pointed to by a. + * + * @param a pointer to a zero-terminated string + * @return a copy of the string including zero-termination + */ +#define GNUNET_strdup(a) GNUNET_xstrdup_(a,__FILE__,__LINE__) + +/** + * Wrapper around GNUNET_strndup. Makes a partial copy of the string + * pointed to by a. + * + * @param a pointer to a string + * @param length of the string to duplicate + * @return a partial copy of the string including zero-termination + */ +#define GNUNET_strndup(a,length) GNUNET_xstrndup_(a,length,__FILE__,__LINE__) + +/** + * Grow a well-typed (!) array. This is a convenience + * method to grow a vector <tt>arr</tt> of size <tt>size</tt> + * to the new (target) size <tt>tsize</tt>. + * <p> + * + * Example (simple, well-typed stack): + * + * <pre> + * static struct foo * myVector = NULL; + * static int myVecLen = 0; + * + * static void push(struct foo * elem) { + * GNUNET_array_grow(myVector, myVecLen, myVecLen+1); + * memcpy(&myVector[myVecLen-1], elem, sizeof(struct foo)); + * } + * + * static void pop(struct foo * elem) { + * if (myVecLen == 0) die(); + * memcpy(elem, myVector[myVecLen-1], sizeof(struct foo)); + * GNUNET_array_grow(myVector, myVecLen, myVecLen-1); + * } + * </pre> + * + * @param arr base-pointer of the vector, may be NULL if size is 0; + * will be updated to reflect the new address. The TYPE of + * arr is important since size is the number of elements and + * not the size in bytes + * @param size the number of elements in the existing vector (number + * of elements to copy over) + * @param tsize the target size for the resulting vector, use 0 to + * free the vector (then, arr will be NULL afterwards). + */ +#define GNUNET_array_grow(arr,size,tsize) GNUNET_xgrow_((void**)&arr, sizeof(arr[0]), &size, tsize, __FILE__, __LINE__) + +/** + * Append an element to a list (growing the + * list by one). + */ +#define GNUNET_array_append(arr,size,element) do { GNUNET_array_grow(arr,size,size+1); arr[size-1] = element; } while(0) + +/** + * Like snprintf, just aborts if the buffer is of insufficient size. + * + * @param buf pointer to buffer that is written to + * @param size number of bytes in buf + * @param format format strings + * @param ... data for format string + * @return number of bytes written to buf or negative value on error + */ +int +GNUNET_snprintf (char *buf, size_t size, const char *format, ...); + + +/** + * Like asprintf, just portable. + * + * @param buf set to a buffer of sufficient size (allocated, caller must free) + * @param format format string (see printf, fprintf, etc.) + * @param ... data for format string + * @return number of bytes in "*buf" excluding 0-termination + */ +int +GNUNET_asprintf (char **buf, const char *format, ...); + + +/* ************** internal implementations, use macros above! ************** */ + +/** + * Allocate memory. Checks the return value, aborts if no more + * memory is available. Don't use GNUNET_xmalloc_ directly. Use the + * GNUNET_malloc macro. + * The memory will be zero'ed out. + * + * @param size number of bytes to allocate + * @param filename where is this call being made (for debugging) + * @param linenumber line where this call is being made (for debugging) + * @return allocated memory, never NULL + */ +void * +GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber); + + +/** + * Allocate and initialize memory. Checks the return value, aborts if no more + * memory is available. Don't use GNUNET_xmemdup_ directly. Use the + * GNUNET_memdup macro. + * + * @param buf buffer to initialize from (must contain size bytes) + * @param size number of bytes to allocate + * @param filename where is this call being made (for debugging) + * @param linenumber line where this call is being made (for debugging) + * @return allocated memory, never NULL + */ +void * +GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, + int linenumber); + + +/** + * Allocate memory. This function does not check if the allocation + * request is within reasonable bounds, allowing allocations larger + * than 40 MB. If you don't expect the possibility of very large + * allocations, use GNUNET_malloc instead. The memory will be zero'ed + * out. + * + * @param size number of bytes to allocate + * @param filename where is this call being made (for debugging) + * @param linenumber line where this call is being made (for debugging) + * @return pointer to size bytes of memory, NULL if we do not have enough memory + */ +void * +GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber); + +/** + * Reallocate memory. Checks the return value, aborts if no more + * memory is available. + */ +void * +GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber); + +/** + * Free memory. Merely a wrapper for the case that we + * want to keep track of allocations. Don't use GNUNET_xfree_ + * directly. Use the GNUNET_free macro. + * + * @param ptr pointer to memory to free + * @param filename where is this call being made (for debugging) + * @param linenumber line where this call is being made (for debugging) + */ +void +GNUNET_xfree_ (void *ptr, const char *filename, int linenumber); + + +/** + * Dup a string. Don't call GNUNET_xstrdup_ directly. Use the GNUNET_strdup macro. + * @param str string to duplicate + * @param filename where is this call being made (for debugging) + * @param linenumber line where this call is being made (for debugging) + * @return the duplicated string + */ +char * +GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber); + +/** + * Dup partially a string. Don't call GNUNET_xstrndup_ directly. Use the GNUNET_strndup macro. + * + * @param str string to duplicate + * @param len length of the string to duplicate + * @param filename where is this call being made (for debugging) + * @param linenumber line where this call is being made (for debugging) + * @return the duplicated string + */ +char * +GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, + int linenumber); + +/** + * Grow an array, the new elements are zeroed out. + * Grows old by (*oldCount-newCount)*elementSize + * bytes and sets *oldCount to newCount. + * + * Don't call GNUNET_xgrow_ directly. Use the GNUNET_array_grow macro. + * + * @param old address of the pointer to the array + * *old may be NULL + * @param elementSize the size of the elements of the array + * @param oldCount address of the number of elements in the *old array + * @param newCount number of elements in the new array, may be 0 (then *old will be NULL afterwards) + * @param filename where is this call being made (for debugging) + * @param linenumber line where this call is being made (for debugging) + */ +void +GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount, + unsigned int newCount, const char *filename, int linenumber); + + +/** + * Create a copy of the given message. + * + * @param msg message to copy + * @return duplicate of the message + */ +struct GNUNET_MessageHeader * +GNUNET_copy_message (const struct GNUNET_MessageHeader *msg); + + +#if __STDC_VERSION__ < 199901L +#if __GNUC__ >= 2 +#define __func__ __FUNCTION__ +#else +#define __func__ "<unknown>" +#endif +#endif + +#endif /*GNUNET_COMMON_H_ */ diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h new file mode 100644 index 0000000..f8f302a --- /dev/null +++ b/src/include/gnunet_configuration_lib.h @@ -0,0 +1,442 @@ +/* + This file is part of GNUnet. + (C) 2006, 2008, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_configuration_lib.h + * @brief configuration API + * + * @author Christian Grothoff + */ + +#ifndef GNUNET_CONFIGURATION_LIB_H +#define GNUNET_CONFIGURATION_LIB_H + + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" +#include "gnunet_time_lib.h" + +/** + * A configuration object. + */ +struct GNUNET_CONFIGURATION_Handle; + +/** + * Create a new configuration object. + * @return fresh configuration object + */ +struct GNUNET_CONFIGURATION_Handle * +GNUNET_CONFIGURATION_create (void); + + +/** + * Duplicate an existing configuration object. + * + * @param cfg configuration to duplicate + * @return duplicate configuration + */ +struct GNUNET_CONFIGURATION_Handle * +GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Destroy configuration object. + * + * @param cfg configuration to destroy + */ +void +GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Load configuration. This function will first parse the + * defaults and then parse the specific configuration file + * to overwrite the defaults. + * + * @param cfg configuration to update + * @param filename name of the configuration file, NULL to load defaults + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *filename); + + +/** + * Parse a configuration file, add all of the options in the + * file to the configuration environment. + * + * @param cfg configuration to update + * @param filename name of the configuration file + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *filename); + + +/** + * Write configuration file. + * + * @param cfg configuration to write + * @param filename where to write the configuration + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +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 + * @param cfgNew new configuration + * @param filename where to write the configuration diff between default and new + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle + *cfgDefault, + const struct GNUNET_CONFIGURATION_Handle + *cfgNew, const char *filename); + +/** + * Test if there are configuration options that were + * changed since the last save. + * + * @param cfg configuration to inspect + * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed) + */ +int +GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Function to iterate over options. + * + * @param cls closure + * @param section name of the section + * @param option name of the option + * @param value value of the option + */ +typedef void (*GNUNET_CONFIGURATION_Iterator) (void *cls, const char *section, + const char *option, + const char *value); + + +/** + * Function to iterate over section. + * + * @param cls closure + * @param section name of the section + */ +typedef void (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls, + const char *section); + + +/** + * Iterate over all options in the configuration. + * + * @param cfg configuration to inspect + * @param iter function to call on each option + * @param iter_cls closure for iter + */ +void +GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_CONFIGURATION_Iterator iter, + void *iter_cls); + + +/** + * Iterate over all sections in the configuration. + * + * @param cfg configuration to inspect + * @param iter function to call on each section + * @param iter_cls closure for iter + */ +void +GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle + *cfg, + GNUNET_CONFIGURATION_Section_Iterator + iter, void *iter_cls); + + +/** + * Remove the given section and all options in it. + * + * @param cfg configuration to inspect + * @param section name of the section to remove + */ +void +GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section); + +/** + * Get a configuration value that should be a number. + * + * @param cfg configuration to inspect + * @param section section of interest + * @param option option of interest + * @param number where to store the numeric value of the option + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, + unsigned long long *number); + + +/** + * Get a configuration value that should be a relative time. + * + * @param cfg configuration to inspect + * @param section section of interest + * @param option option of interest + * @param time set to the time value stored in the configuration + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, + struct GNUNET_TIME_Relative *time); + + + +/** + * Get a configuration value that should be a size in bytes. + * + * @param cfg configuration to inspect + * @param section section of interest + * @param option option of interest + * @param size set to the size in bytes as stored in the configuration + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, + unsigned long long *size); + + +/** + * Test if we have a value for a particular option + * + * @param cfg configuration to inspect + * @param section section of interest + * @param option option of interest + * @return GNUNET_YES if so, GNUNET_NO if not. + */ +int +GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option); + + +/** + * Get a configuration value that should be a string. + * + * @param cfg configuration to inspect + * @param section section of interest + * @param option option of interest + * @param value will be set to a freshly allocated configuration + * value, or NULL if option is not specified + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, char **value); + + +/** + * Get a configuration value that should be the name of a file + * or directory. + * + * @param cfg configuration to inspect + * @param section section of interest + * @param option option of interest + * @param value will be set to a freshly allocated configuration + * value, or NULL if option is not specified + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_CONFIGURATION_get_value_filename (const struct + GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + const char *option, char **value); + +/** + * Iterate over the set of filenames stored in a configuration value. + * + * @param cfg configuration to inspect + * @param section section of interest + * @param option option of interest + * @param cb function to call on each filename + * @param cb_cls closure for cb + * @return number of filenames iterated over, -1 on error + */ +int +GNUNET_CONFIGURATION_iterate_value_filenames (const struct + GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + const char *option, + GNUNET_FileNameCallback cb, + void *cb_cls); + +/** + * Iterate over values of a section in the configuration. + * + * @param cfg configuration to inspect + * @param section the section + * @param iter function to call on each option + * @param iter_cls closure for iter + */ +void +GNUNET_CONFIGURATION_iterate_section_values (const struct + GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + GNUNET_CONFIGURATION_Iterator iter, + void *iter_cls); + +/** + * Get a configuration value that should be in a set of + * predefined strings + * + * @param cfg configuration to inspect + * @param section section of interest + * @param option option of interest + * @param choices NULL-terminated list of legal values + * @param value will be set to an entry in the legal list, + * or NULL if option is not specified and no default given + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, const char **choices, + const char **value); + +/** + * Get a configuration value that should be in a set of + * "YES" or "NO". + * + * @param cfg configuration to inspect + * @param section section of interest + * @param option option of interest + * @return GNUNET_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR + */ +int +GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option); + + +/** + * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" + * where either in the "PATHS" section or the environtment + * "FOO" is set to "DIRECTORY". + * + * @param cfg configuration to use for path expansion + * @param orig string to $-expand (will be freed!) + * @return $-expanded string + */ +char * +GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle + *cfg, char *orig); + + +/** + * Set a configuration value that should be a number. + * + * @param cfg configuration to update + * @param section section of interest + * @param option option of interest + * @param number value to set + */ +void +GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option, + unsigned long long number); + + +/** + * Set a configuration value that should be a string. + * + * @param cfg configuration to update + * @param section section of interest + * @param option option of interest + * @param value value to set + */ +void +GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option, + const char *value); + + +/** + * Remove a filename from a configuration value that + * represents a list of filenames + * + * @param cfg configuration to update + * @param section section of interest + * @param option option of interest + * @param value filename to remove + * @return GNUNET_OK on success, + * GNUNET_SYSERR if the filename is not in the list + */ +int +GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, + const char *value); + +/** + * Append a filename to a configuration value that + * represents a list of filenames + * + * @param cfg configuration to update + * @param section section of interest + * @param option option of interest + * @param value filename to append + * @return GNUNET_OK on success, + * GNUNET_SYSERR if the filename already in the list + */ +int +GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, + const char *value); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/gnunet_connection_lib.h b/src/include/gnunet_connection_lib.h new file mode 100644 index 0000000..3e48d32 --- /dev/null +++ b/src/include/gnunet_connection_lib.h @@ -0,0 +1,373 @@ +/* + This file is part of GNUnet. + (C) 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_connection_lib.h + * @brief basic, low-level TCP networking interface + * @author Christian Grothoff + */ +#ifndef GNUNET_CONNECTION_LIB_H +#define GNUNET_CONNECTION_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_network_lib.h" +#include "gnunet_scheduler_lib.h" +#include "gnunet_time_lib.h" + +/** + * Timeout we use on TCP connect before trying another + * result from the DNS resolver. Actual value used + * is this value divided by the number of address families. + * Default is 5s. + */ +#define GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) + +/** + * @brief handle for a network connection + */ +struct GNUNET_CONNECTION_Handle; + + +/** + * Credentials for UNIX domain sockets. + */ +struct GNUNET_CONNECTION_Credentials +{ + /** + * UID of the other end of the connection. + */ + uid_t uid; + + /** + * GID of the other end of the connection. + */ + gid_t gid; +}; + + +/** + * Function to call for access control checks. + * + * @param cls closure + * @param ucred credentials, if available, otherwise NULL + * @param addr address + * @param addrlen length of address + * @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR + * for unknown address family (will be denied). + */ +typedef int (*GNUNET_CONNECTION_AccessCheck) (void *cls, + const struct + GNUNET_CONNECTION_Credentials * + ucred, + const struct sockaddr * addr, + socklen_t addrlen); + + +/** + * Callback function for data received from the network. Note that + * both "available" and "err" would be 0 if the read simply timed out. + * + * @param cls closure + * @param buf pointer to received data + * @param available number of bytes availabe in "buf", + * possibly 0 (on errors) + * @param addr address of the sender + * @param addrlen size of addr + * @param errCode value of errno (on errors receiving) + */ +typedef void (*GNUNET_CONNECTION_Receiver) (void *cls, const void *buf, + size_t available, + const struct sockaddr * addr, + socklen_t addrlen, int errCode); + +/** + * Set the persist option on this connection handle. Indicates + * that the underlying socket or fd should never really be closed. + * Used for indicating process death. + * + * @param sock the connection to set persistent + */ +void +GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *sock); + +/** + * Disable the "CORK" feature for communication with the given socket, + * forcing the OS to immediately flush the buffer on transmission + * instead of potentially buffering multiple messages. Essentially + * reduces the OS send buffers to zero. + * Used to make sure that the last messages sent through the connection + * reach the other side before the process is terminated. + * + * @param sock the connection to make flushing and blocking + * @return GNUNET_OK on success + */ +int +GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *sock); + + +/** + * Create a socket handle by boxing an existing OS socket. The OS + * socket should henceforth be no longer used directly. + * GNUNET_socket_destroy will close it. + * + * @param osSocket existing socket to box + * @return the boxed socket handle + */ +struct GNUNET_CONNECTION_Handle * +GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket); + + +/** + * Create a socket handle by accepting on a listen socket. This + * function may block if the listen socket has no connection ready. + * + * @param access function to use to check if access is allowed + * @param access_cls closure for access + * @param lsock listen socket + * @return the socket handle, NULL on error (for example, access refused) + */ +struct GNUNET_CONNECTION_Handle * +GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, + void *access_cls, + struct GNUNET_NETWORK_Handle *lsock); + + +/** + * Create a socket handle by (asynchronously) connecting to a host. + * This function returns immediately, even if the connection has not + * yet been established. This function only creates TCP connections. + * + * @param cfg configuration to use + * @param hostname name of the host to connect to + * @param port port to connect to + * @return the socket handle + */ +struct GNUNET_CONNECTION_Handle * +GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *hostname, + uint16_t port); + + +/** + * Create a socket handle by connecting to a UNIX domain service. + * This function returns immediately, even if the connection has not + * yet been established. This function only creates UNIX connections. + * + * @param cfg configuration to use + * @param unixpath path to connect to) + * @return the socket handle, NULL on systems without UNIX support + */ +struct GNUNET_CONNECTION_Handle * +GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct + GNUNET_CONFIGURATION_Handle + *cfg, const char *unixpath); + + + + +/** + * Create a socket handle by (asynchronously) connecting to a host. + * This function returns immediately, even if the connection has not + * yet been established. This function only creates TCP connections. + * + * @param af_family address family to use + * @param serv_addr server address + * @param addrlen length of server address + * @return the socket handle + */ +struct GNUNET_CONNECTION_Handle * +GNUNET_CONNECTION_create_from_sockaddr (int af_family, + const struct sockaddr *serv_addr, + socklen_t addrlen); + +/** + * Check if socket is valid (no fatal errors have happened so far). + * Note that a socket that is still trying to connect is considered + * valid. + * + * @param sock socket to check + * @return GNUNET_YES if valid, GNUNET_NO otherwise + */ +int +GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock); + + +/** + * Obtain the network address of the other party. + * + * @param sock the client to get the address for + * @param addr where to store the address + * @param addrlen where to store the length of the address + * @return GNUNET_OK on success + */ +int +GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *sock, + void **addr, size_t * addrlen); + + +/** + * Close the socket and free associated resources. Pending + * transmissions may be completed or dropped depending on the + * arguments. If a receive call is pending and should + * NOT be completed, 'GNUNET_CONNECTION_receive_cancel' + * should be called explicitly first. + * + * @param sock socket to destroy + * @param finish_pending_write should pending writes be completed or aborted? + * (this applies to transmissions where the data has already been + * read from the application; all other transmissions should be + * aborted using 'GNUNET_CONNECTION_notify_transmit_ready_cancel'). + */ +void +GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock, + int finish_pending_write); + + +/** + * Receive data from the given socket. Note that this function will + * call "receiver" asynchronously using the scheduler. It will + * "immediately" return. Note that there MUST only be one active + * receive call per socket at any given point in time (so do not + * call receive again until the receiver callback has been invoked). + * + * @param sock socket handle + * @param max maximum number of bytes to read + * @param timeout maximum amount of time to wait + * @param receiver function to call with received data + * @param receiver_cls closure for receiver + */ +void +GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, size_t max, + struct GNUNET_TIME_Relative timeout, + GNUNET_CONNECTION_Receiver receiver, + void *receiver_cls); + + +/** + * Cancel receive job on the given socket. Note that the + * receiver callback must not have been called yet in order + * for the cancellation to be valid. + * + * @param sock socket handle + * @return closure of the original receiver callback closure + */ +void * +GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock); + + +/** + * Function called to notify a client about the socket + * begin ready to queue more data. "buf" will be + * NULL and "size" zero if the socket was closed for + * writing in the meantime. + * + * @param cls closure + * @param size number of bytes available in buf + * @param buf where the callee should write the message + * @return number of bytes written to buf + */ +typedef size_t (*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls, size_t size, + void *buf); + + +/** + * Opaque handle that can be used to cancel + * a transmit-ready notification. + */ +struct GNUNET_CONNECTION_TransmitHandle; + +/** + * Ask the socket to call us once the specified number of bytes + * are free in the transmission buffer. May call the notify + * method immediately if enough space is available. Note that + * this function will abort if "size" is greater than + * GNUNET_SERVER_MAX_MESSAGE_SIZE. + * + * Note that "notify" will be called either when enough + * buffer space is available OR when the socket is destroyed. + * The size parameter given to notify is guaranteed to be + * larger or equal to size if the buffer is ready, or zero + * if the socket was destroyed (or at least closed for + * writing). Finally, any time before 'notify' is called, a + * client may call "notify_transmit_ready_cancel" to cancel + * the transmission request. + * + * Only one transmission request can be scheduled at the same + * time. Notify will be run with the same scheduler priority + * as that of the caller. + * + * @param sock socket + * @param size number of bytes to send + * @param timeout after how long should we give up (and call + * notify with buf NULL and size 0)? + * @param notify function to call when buffer space is available + * @param notify_cls closure for notify + * @return non-NULL if the notify callback was queued, + * NULL if we are already going to notify someone else (busy) + */ +struct GNUNET_CONNECTION_TransmitHandle * +GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *sock, + size_t size, + struct GNUNET_TIME_Relative timeout, + GNUNET_CONNECTION_TransmitReadyNotify + notify, void *notify_cls); + + +/** + * Cancel the specified transmission-ready + * notification. + * + * @param th handle for notification to cancel + */ +void +GNUNET_CONNECTION_notify_transmit_ready_cancel (struct + GNUNET_CONNECTION_TransmitHandle + *th); + + +/** + * Configure this connection to ignore shutdown signals. + * + * @param sock socket handle + * @param do_ignore GNUNET_YES to ignore, GNUNET_NO to restore default + */ +void +GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock, + int do_ignore); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + +/* ifndef GNUNET_CONNECTION_LIB_H */ +#endif +/* end of gnunet_connection_lib.h */ diff --git a/src/include/gnunet_constants.h b/src/include/gnunet_constants.h new file mode 100644 index 0000000..771b473 --- /dev/null +++ b/src/include/gnunet_constants.h @@ -0,0 +1,161 @@ +/* + This file is part of GNUnet. + (C) 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_constants.h + * @brief "global" constants for performance tuning + * @author Christian Grothoff + */ + +#ifndef GNUNET_CONSTANTS_H +#define GNUNET_CONSTANTS_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_bandwidth_lib.h" + +/** + * Bandwidth (in/out) to assume initially (before either peer has + * communicated any particular preference). Should be rather low; set + * so that at least one maximum-size message can be send roughly once + * per minute. + */ +#define GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT GNUNET_BANDWIDTH_value_init (1024) + +/** + * After how long do we consider a connection to a peer dead + * if we don't receive messages from the peer? + */ +#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.). + */ +#define GNUNET_CONSTANTS_SERVICE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10) + +/** + * How long do we delay messages to get larger packet sizes (CORKing)? + */ +#define GNUNET_CONSTANTS_MAX_CORK_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) + +/** + * Until which load do we consider the peer overly idle + * (which means that we would like to use more resources).<p> + * + * Note that we use 70 to leave some room for applications + * to consume resources "idly" (i.e. up to 85%) and then + * still have some room for "paid for" resource consumption. + */ +#define GNUNET_CONSTANTS_IDLE_LOAD_THRESHOLD 70 + +/** + * For how long do we allow unused bandwidth + * from the past to carry over into the future? (in seconds) + */ +#define GNUNET_CONSTANTS_MAX_BANDWIDTH_CARRY_S 5 + + +/** + * After how long do we expire an address in a HELLO that we just + * validated? This value is also used for our own addresses when we + * create a HELLO. + */ +#define GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12) + + +/** + * 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)) + + +/** + * What is the maximum size for encrypted messages? Note that this + * number imposes a clear limit on the maximum size of any message. + * Set to a value close to 64k but not so close that transports will + * have trouble with their headers. + * + * Could theoretically be 64k minus (GNUNET_CONSTANTS_CORE_SIZE_ENCRYPTED_MESSAGE + + * GNUNET_CONSTANTS_TRANSPORT_SIZE_OUTBOUND_MESSAGE), but we're going + * to be more conservative for now. + */ +#define GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE (63 * 1024) + + +/** + * K-value that must be used for the bloom filters in 'GET' + * queries. + */ +#define GNUNET_CONSTANTS_BLOOMFILTER_K 16 + + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h new file mode 100644 index 0000000..75443b6 --- /dev/null +++ b/src/include/gnunet_container_lib.h @@ -0,0 +1,1240 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_container_lib.h + * @brief container classes for GNUnet + * + * @author Christian Grothoff + * @author Nils Durner + */ + +#ifndef GNUNET_CONTAINER_LIB_H +#define GNUNET_CONTAINER_LIB_H + +/* add error and config prototypes */ +#include "gnunet_crypto_lib.h" +#include <extractor.h> + +#ifndef EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME +/* hack for LE < 0.6.3 */ +#define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME 180 +#endif + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/* ******************* bloomfilter ***************** */ + +/** + * @brief bloomfilter representation (opaque) + */ +struct GNUNET_CONTAINER_BloomFilter; + +/** + * Iterator over HashCodes. + * + * @param cls closure + * @param next set to the next hash code + * @return GNUNET_YES if next was updated + * GNUNET_NO if there are no more entries + */ +typedef int (*GNUNET_HashCodeIterator) (void *cls, GNUNET_HashCode * next); + + +/** + * Load a bloom-filter from a file. + * + * @param filename the name of the file (or the prefix) + * @param size the size of the bloom-filter (number of + * bytes of storage space to use) + * @param k the number of GNUNET_CRYPTO_hash-functions to apply per + * element (number of bits set per element in the set) + * @return the bloomfilter + */ +struct GNUNET_CONTAINER_BloomFilter * +GNUNET_CONTAINER_bloomfilter_load (const char *filename, size_t size, + unsigned int k); + + +/** + * Create a bloom filter from raw bits. + * + * @param data the raw bits in memory (maybe NULL, + * in which case all bits should be considered + * to be zero). + * @param size the size of the bloom-filter (number of + * bytes of storage space to use); also size of data + * -- unless data is NULL. Must be a power of 2. + * @param k the number of GNUNET_CRYPTO_hash-functions to apply per + * element (number of bits set per element in the set) + * @return the bloomfilter + */ +struct GNUNET_CONTAINER_BloomFilter * +GNUNET_CONTAINER_bloomfilter_init (const char *data, size_t size, + unsigned int k); + + +/** + * Copy the raw data of this bloomfilter into + * the given data array. + * + * @param data where to write the data + * @param size the size of the given data array + * @return GNUNET_SYSERR if the data array of the wrong size + */ +int +GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct + GNUNET_CONTAINER_BloomFilter *bf, + char *data, size_t size); + + +/** + * Test if an element is in the filter. + * @param e the element + * @param bf the filter + * @return GNUNET_YES if the element is in the filter, GNUNET_NO if not + */ +int +GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter + *bf, const GNUNET_HashCode * e); + + +/** + * Add an element to the filter + * @param bf the filter + * @param e the element + */ +void +GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf, + const GNUNET_HashCode * e); + + +/** + * Remove an element from the filter. + * @param bf the filter + * @param e the element to remove + */ +void +GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf, + const GNUNET_HashCode * e); + + +/** + * Create a copy of a bloomfilter. + * + * @param bf the filter + * @return copy of bf + */ +struct GNUNET_CONTAINER_BloomFilter * +GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter + *bf); + + + +/** + * Free the space associcated with a filter + * in memory, flush to drive if needed (do not + * free the space on the drive) + * @param bf the filter + */ +void +GNUNET_CONTAINER_bloomfilter_free (struct GNUNET_CONTAINER_BloomFilter *bf); + + +/** + * Get size of the bloom filter. + * + * @param bf the filter + * @return number of bytes used for the data of the bloom filter + */ +size_t +GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter + *bf); + + +/** + * Reset a bloom filter to empty. + * @param bf the filter + */ +void +GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter *bf); + +/** + * Or the entries of the given raw data array with the + * data of the given bloom filter. Assumes that + * the size of the data array and the current filter + * match. + * + * @param bf the filter + * @param data data to OR-in + * @param size size of data + * @return GNUNET_OK on success + */ +int +GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, + const char *data, size_t size); + +/** + * Or the entries of the given raw data array with the + * data of the given bloom filter. Assumes that + * the size of the data array and the current filter + * match. + * + * @param bf the filter + * @param to_or the bloomfilter to or-in + * @param size number of bytes in data + */ +int +GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf, + const struct GNUNET_CONTAINER_BloomFilter + *to_or, size_t size); + +/** + * Resize a bloom filter. Note that this operation + * is pretty costly. Essentially, the bloom filter + * needs to be completely re-build. + * + * @param bf the filter + * @param iterator an iterator over all elements stored in the BF + * @param iterator_cls closure for iterator + * @param size the new size for the filter + * @param k the new number of GNUNET_CRYPTO_hash-function to apply per element + */ +void +GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, + GNUNET_HashCodeIterator iterator, + void *iterator_cls, size_t size, + unsigned int k); + +/* ****************** metadata ******************* */ + +/** + * Meta data to associate with a file, directory or namespace. + */ +struct GNUNET_CONTAINER_MetaData; + +/** + * Create a fresh MetaData token. + * + * @return empty meta-data container + */ +struct GNUNET_CONTAINER_MetaData * +GNUNET_CONTAINER_meta_data_create (void); + +/** + * Duplicate a MetaData token. + * + * @param md what to duplicate + * @return duplicate meta-data container + */ +struct GNUNET_CONTAINER_MetaData * +GNUNET_CONTAINER_meta_data_duplicate (const struct GNUNET_CONTAINER_MetaData + *md); + +/** + * Free meta data. + * + * @param md what to free + */ +void +GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md); + +/** + * Test if two MDs are equal. We consider them equal if + * the meta types, formats and content match (we do not + * include the mime types and plugins names in this + * consideration). + * + * @param md1 first value to check + * @param md2 other value to check + * @return GNUNET_YES if they are equal + */ +int +GNUNET_CONTAINER_meta_data_test_equal (const struct GNUNET_CONTAINER_MetaData + *md1, + const struct GNUNET_CONTAINER_MetaData + *md2); + + +/** + * Extend metadata. + * + * @param md metadata to extend + * @param plugin_name name of the plugin that produced this value; + * special values can be used (i.e. '<zlib>' for zlib being + * used in the main libextractor library and yielding + * meta data). + * @param type libextractor-type describing the meta data + * @param format basic format information about data + * @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 + * @return GNUNET_OK on success, GNUNET_SYSERR if this entry already exists + * data_mime_type and plugin_name are not considered for "exists" checks + */ +int +GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md, + const char *plugin_name, + enum EXTRACTOR_MetaType type, + enum EXTRACTOR_MetaFormat format, + const char *data_mime_type, const char *data, + size_t data_len); + + +/** + * Extend metadata. Merges the meta data from the second argument + * into the first, discarding duplicate key-value pairs. + * + * @param md metadata to extend + * @param in metadata to merge + */ +void +GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md, + const struct GNUNET_CONTAINER_MetaData *in); + + +/** + * Remove an item. + * + * @param md metadata to manipulate + * @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 + * @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); + + +/** + * Remove all items in the container. + * + * @param md metadata to manipulate + */ +void +GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md); + + +/** + * Add the current time as the publication date + * to the meta-data. + * + * @param md metadata to modify + */ +void +GNUNET_CONTAINER_meta_data_add_publication_date (struct + GNUNET_CONTAINER_MetaData *md); + + +/** + * Iterate over MD entries. + * + * @param md metadata to inspect + * @param iter function to call on each entry + * @param iter_cls closure for iterator + * @return number of entries + */ +int +GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData *md, + EXTRACTOR_MetaDataProcessor iter, + void *iter_cls); + +/** + * Get the first MD entry of the given type. Caller + * is responsible for freeing the return value. + * Also, only meta data items that are strings (0-terminated) + * are returned by this function. + * + * @param md metadata to inspect + * @param type type to look for + * @return NULL if no entry was found + */ +char * +GNUNET_CONTAINER_meta_data_get_by_type (const struct GNUNET_CONTAINER_MetaData + *md, enum EXTRACTOR_MetaType type); + + +/** + * Get the first matching MD entry of the given types. Caller is + * responsible for freeing the return value. Also, only meta data + * items that are strings (0-terminated) are returned by this + * function. + * + * @param md metadata to inspect + * @param ... -1-terminated list of types + * @return NULL if we do not have any such entry, + * otherwise client is responsible for freeing the value! + */ +char * +GNUNET_CONTAINER_meta_data_get_first_by_types (const struct + GNUNET_CONTAINER_MetaData *md, + ...); + +/** + * Get a thumbnail from the meta-data (if present). Only matches meta + * data with mime type "image" and binary format. + * + * @param md metadata to inspect + * @param thumb will be set to the thumbnail data. Must be + * freed by the caller! + * @return number of bytes in thumbnail, 0 if not available + */ +size_t +GNUNET_CONTAINER_meta_data_get_thumbnail (const struct GNUNET_CONTAINER_MetaData + *md, unsigned char **thumb); + + + +/** + * Options for metadata serialization. + */ +enum GNUNET_CONTAINER_MetaDataSerializationOptions +{ + /** + * Serialize all of the data. + */ + GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL = 0, + + /** + * If not enough space is available, it is acceptable + * to only serialize some of the metadata. + */ + GNUNET_CONTAINER_META_DATA_SERIALIZE_PART = 1, + + /** + * Speed is of the essence, do not allow compression. + */ + GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS = 2 +}; + + +/** + * Serialize meta-data to target. + * + * @param md metadata to serialize + * @param target where to write the serialized metadata; + * *target can be NULL, in which case memory is allocated + * @param max maximum number of bytes available + * @param opt is it ok to just write SOME of the + * meta-data to match the size constraint, + * possibly discarding some data? + * @return number of bytes written on success, + * -1 on error (typically: not enough + * space) + */ +ssize_t +GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData + *md, char **target, size_t max, + enum + GNUNET_CONTAINER_MetaDataSerializationOptions + opt); + + +/** + * Get the size of the full meta-data in serialized form. + * + * @param md metadata to inspect + * @return number of bytes needed for serialization, -1 on error + */ +ssize_t +GNUNET_CONTAINER_meta_data_get_serialized_size (const struct + GNUNET_CONTAINER_MetaData *md); + + +/** + * Deserialize meta-data. Initializes md. + * + * @param input serialized meta-data. + * @param size number of bytes available + * @return MD on success, NULL on error (i.e. + * bad format) + */ +struct GNUNET_CONTAINER_MetaData * +GNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size); + + +/* ******************************* HashMap **************************** */ + +/** + * Opaque handle for a HashMap. + */ +struct GNUNET_CONTAINER_MultiHashMap; + +/** + * Options for storing values in the HashMap. + */ +enum GNUNET_CONTAINER_MultiHashMapOption +{ + + /** + * If a value with the given key exists, replace it. Note that the + * old value would NOT be freed by replace (the application has to + * make sure that this happens if required). + */ + GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE, + + /** + * Allow multiple values with the same key. + */ + GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, + + /** + * There must only be one value per key; storing a value should fail + * if a value under the same key already exists. + */ + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, + + /** + * There must only be one value per key, but don't bother checking + * if a value already exists (faster than UNIQUE_ONLY; implemented + * just like MULTIPLE but this option documents better what is + * intended if UNIQUE is what is desired). + */ + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST +}; + + +/** + * Iterator over hash map entries. + * + * @param cls closure + * @param key current key code + * @param value value in the hash map + * @return GNUNET_YES if we should continue to + * iterate, + * GNUNET_NO if not. + */ +typedef int (*GNUNET_CONTAINER_HashMapIterator) (void *cls, + const GNUNET_HashCode * key, + void *value); + + +/** + * Create a multi hash map. + * + * @param len initial size (map will grow as needed) + * @return NULL on error + */ +struct GNUNET_CONTAINER_MultiHashMap * +GNUNET_CONTAINER_multihashmap_create (unsigned int len); + + +/** + * Destroy a hash map. Will not free any values + * stored in the hash map! + * + * @param map the map + */ +void +GNUNET_CONTAINER_multihashmap_destroy (struct GNUNET_CONTAINER_MultiHashMap + *map); + + +/** + * Given a key find a value in the map matching the key. + * + * @param map the map + * @param key what to look for + * @return NULL if no value was found; note that + * this is indistinguishable from values that just + * happen to be NULL; use "contains" to test for + * key-value pairs with value NULL + */ +void * +GNUNET_CONTAINER_multihashmap_get (const struct GNUNET_CONTAINER_MultiHashMap + *map, const GNUNET_HashCode * key); + + +/** + * Remove the given key-value pair from the map. Note that if the + * key-value pair is in the map multiple times, only one of the pairs + * will be removed. + * + * @param map the map + * @param key key of the key-value pair + * @param value value of the key-value pair + * @return GNUNET_YES on success, GNUNET_NO if the key-value pair + * is not in the map + */ +int +GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap *map, + const GNUNET_HashCode * key, void *value); + +/** + * Remove all entries for the given key from the map. + * Note that the values would not be "freed". + * + * @param map the map + * @param key identifies values to be removed + * @return number of values removed + */ +int +GNUNET_CONTAINER_multihashmap_remove_all (struct GNUNET_CONTAINER_MultiHashMap + *map, const GNUNET_HashCode * key); + + +/** + * Check if the map contains any value under the given + * key (including values that are NULL). + * + * @param map the map + * @param key the key to test if a value exists for it + * @return GNUNET_YES if such a value exists, + * GNUNET_NO if not + */ +int +GNUNET_CONTAINER_multihashmap_contains (const struct + GNUNET_CONTAINER_MultiHashMap *map, + const GNUNET_HashCode * key); + + +/** + * Check if the map contains the given value under the given + * key. + * + * @param map the map + * @param key the key to test if a value exists for it + * @param value value to test for + * @return GNUNET_YES if such a value exists, + * GNUNET_NO if not + */ +int +GNUNET_CONTAINER_multihashmap_contains_value (const struct + GNUNET_CONTAINER_MultiHashMap + *map, const GNUNET_HashCode * key, + const void *value); + + +/** + * Store a key-value pair in the map. + * + * @param map the map + * @param key key to use + * @param value value to use + * @param opt options for put + * @return GNUNET_OK on success, + * GNUNET_NO if a value was replaced (with REPLACE) + * GNUNET_SYSERR if UNIQUE_ONLY was the option and the + * value already exists + */ +int +GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map, + const GNUNET_HashCode * key, void *value, + enum GNUNET_CONTAINER_MultiHashMapOption + opt); + +/** + * Get the number of key-value pairs in the map. + * + * @param map the map + * @return the number of key value pairs + */ +unsigned int +GNUNET_CONTAINER_multihashmap_size (const struct GNUNET_CONTAINER_MultiHashMap + *map); + + +/** + * Iterate over all entries in the map. + * + * @param map the map + * @param it function to call on each entry + * @param it_cls extra argument to it + * @return the number of key value pairs processed, + * GNUNET_SYSERR if it aborted iteration + */ +int +GNUNET_CONTAINER_multihashmap_iterate (const struct + GNUNET_CONTAINER_MultiHashMap *map, + GNUNET_CONTAINER_HashMapIterator it, + void *it_cls); + + +/** + * Iterate over all entries in the map that match a particular key. + * + * @param map the map + * @param key key that the entries must correspond to + * @param it function to call on each entry + * @param it_cls extra argument to it + * @return the number of key value pairs processed, + * GNUNET_SYSERR if it aborted iteration + */ +int +GNUNET_CONTAINER_multihashmap_get_multiple (const struct + GNUNET_CONTAINER_MultiHashMap *map, + const GNUNET_HashCode * key, + GNUNET_CONTAINER_HashMapIterator it, + void *it_cls); + + +/* ******************** doubly-linked list *************** */ +/* To avoid mistakes: head->prev == tail->next == NULL */ + +/** + * Insert an element at the head of a DLL. Assumes that head, tail and + * element are structs with prev and next fields. + * + * @param head pointer to the head of the DLL + * @param tail pointer to the tail of the DLL + * @param element element to insert + */ +#define GNUNET_CONTAINER_DLL_insert(head,tail,element) do { \ + GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \ + GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \ + (element)->next = (head); \ + (element)->prev = NULL; \ + if ((tail) == NULL) \ + (tail) = element; \ + else \ + (head)->prev = element; \ + (head) = (element); } while (0) + + +/** + * Insert an element at the tail of a DLL. Assumes that head, tail and + * element are structs with prev and next fields. + * + * @param head pointer to the head of the DLL + * @param tail pointer to the tail of the DLL + * @param element element to insert + */ +#define GNUNET_CONTAINER_DLL_insert_tail(head,tail,element) do { \ + GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \ + GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \ + (element)->prev = (tail); \ + (element)->next = NULL; \ + if ((head) == NULL) \ + (head) = element; \ + else \ + (tail)->next = element; \ + (tail) = (element); } while (0) + + +/** + * Insert an element into a DLL after the given other element. Insert + * at the head if the other element is NULL. + * + * @param head pointer to the head of the DLL + * @param tail pointer to the tail of the DLL + * @param other prior element, NULL for insertion at head of DLL + * @param element element to insert + */ +#define GNUNET_CONTAINER_DLL_insert_after(head,tail,other,element) do { \ + GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \ + GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \ + (element)->prev = (other); \ + if (NULL == other) \ + { \ + (element)->next = (head); \ + (head) = (element); \ + } \ + else \ + { \ + (element)->next = (other)->next; \ + (other)->next = (element); \ + } \ + if (NULL == (element)->next) \ + (tail) = (element); \ + else \ + (element)->next->prev = (element); } while (0) + + +/** + * Insert an element into a DLL before the given other element. Insert + * at the tail if the other element is NULL. + * + * @param head pointer to the head of the DLL + * @param tail pointer to the tail of the DLL + * @param other prior element, NULL for insertion at head of DLL + * @param element element to insert + */ +#define GNUNET_CONTAINER_DLL_insert_before(head,tail,other,element) do { \ + GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \ + GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \ + (element)->next = (other); \ + if (NULL == other) \ + { \ + (element)->prev = (tail); \ + (tail) = (element); \ + } \ + else \ + { \ + (element)->prev = (other)->prev; \ + (other)->prev = (element); \ + } \ + if (NULL == (element)->prev) \ + (head) = (element); \ + else \ + (element)->prev->next = (element); } while (0) + + +/** + * Remove an element from a DLL. Assumes + * that head, tail and element are structs + * with prev and next fields. + * + * @param head pointer to the head of the DLL + * @param tail pointer to the tail of the DLL + * @param element element to remove + */ +#define GNUNET_CONTAINER_DLL_remove(head,tail,element) do { \ + GNUNET_assert ( ( (element)->prev != NULL) || ((head) == (element))); \ + GNUNET_assert ( ( (element)->next != NULL) || ((tail) == (element))); \ + if ((element)->prev == NULL) \ + (head) = (element)->next; \ + else \ + (element)->prev->next = (element)->next; \ + if ((element)->next == NULL) \ + (tail) = (element)->prev; \ + else \ + (element)->next->prev = (element)->prev; \ + (element)->next = NULL; \ + (element)->prev = NULL; } while (0) + + + +/* ******************** Heap *************** */ + + +/** + * Cost by which elements in a heap can be ordered. + */ +typedef uint64_t GNUNET_CONTAINER_HeapCostType; + + +/* + * Heap type, either max or min. Hopefully makes the + * implementation more useful. + */ +enum GNUNET_CONTAINER_HeapOrder +{ + /** + * Heap with the maximum cost at the root. + */ + GNUNET_CONTAINER_HEAP_ORDER_MAX, + + /** + * Heap with the minimum cost at the root. + */ + GNUNET_CONTAINER_HEAP_ORDER_MIN +}; + + +/** + * Handle to a Heap. + */ +struct GNUNET_CONTAINER_Heap; + + + +/** + * Handle to a node in a heap. + */ +struct GNUNET_CONTAINER_HeapNode; + + +/** + * Create a new heap. + * + * @param order how should the heap be sorted? + * @return handle to the heap + */ +struct GNUNET_CONTAINER_Heap * +GNUNET_CONTAINER_heap_create (enum GNUNET_CONTAINER_HeapOrder order); + + +/** + * Destroys the heap. Only call on a heap that + * is already empty. + * + * @param heap heap to destroy + */ +void +GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap); + + +/** + * Get element stored at root of heap. + * + * @param heap heap to inspect + * @return NULL if heap is empty + */ +void * +GNUNET_CONTAINER_heap_peek (const struct GNUNET_CONTAINER_Heap *heap); + + +/** + * Get the current size of the heap + * + * @param heap the heap to get the size of + * @return number of elements stored + */ +unsigned int +GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap); + + +/** + * Get the current cost of the node + * + * @param node the node to get the cost of + * @return cost of the node + */ +GNUNET_CONTAINER_HeapCostType +GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode + *node); + +/** + * Iterator for heap + * + * @param cls closure + * @param node internal node of the heap + * @param element value stored at the node + * @param cost cost associated with the node + * @return GNUNET_YES if we should continue to iterate, + * GNUNET_NO if not. + */ +typedef int (*GNUNET_CONTAINER_HeapIterator) (void *cls, + struct GNUNET_CONTAINER_HeapNode * + node, void *element, + GNUNET_CONTAINER_HeapCostType + cost); + + +/** + * Iterate over all entries in the heap. + * + * @param heap the heap + * @param iterator function to call on each entry + * @param iterator_cls closure for iterator + */ +void +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 + * each walk starts at the root and ends at a random leaf). + * The heap internally tracks the current position of the + * walk. + * + * @param heap heap to walk + * @return data stored at the next random node in the walk; + * NULL if the tree is empty. + */ +void * +GNUNET_CONTAINER_heap_walk_get_next (struct GNUNET_CONTAINER_Heap *heap); + + +/** + * Inserts a new element into the heap. + * + * @param heap heap to modify + * @param element element to insert + * @param cost cost for the element + * @return node for the new element + */ +struct GNUNET_CONTAINER_HeapNode * +GNUNET_CONTAINER_heap_insert (struct GNUNET_CONTAINER_Heap *heap, void *element, + GNUNET_CONTAINER_HeapCostType cost); + + +/** + * Remove root of the heap. + * + * @param heap heap to modify + * @return element data stored at the root node + */ +void * +GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap); + + +/** + * Removes a node from the heap. + * + * @param node node to remove + * @return element data stored at the node, NULL if heap is empty + */ +void * +GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node); + + +/** + * Updates the cost of any node in the tree + * + * @param heap heap to modify + * @param node node for which the cost is to be changed + * @param new_cost new cost for the node + */ +void +GNUNET_CONTAINER_heap_update_cost (struct GNUNET_CONTAINER_Heap *heap, + struct GNUNET_CONTAINER_HeapNode *node, + GNUNET_CONTAINER_HeapCostType new_cost); + + +/* ******************** Singly linked list *************** */ + +/** + * Possible ways for how data stored in the linked list + * might be allocated. + */ +enum GNUNET_CONTAINER_SListDisposition +{ + /** + * Single-linked list must copy the buffer. + */ + GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT = 0, + + /** + * Data is static, no need to copy or free. + */ + GNUNET_CONTAINER_SLIST_DISPOSITION_STATIC = 2, + + /** + * Data is dynamic, do not copy but free when done. + */ + GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC = 4 +}; + + + +/** + * Handle to a singly linked list + */ +struct GNUNET_CONTAINER_SList; + +/** + * Handle to a singly linked list iterator + */ +struct GNUNET_CONTAINER_SList_Iterator +{ + /** + * Linked list that we are iterating over. + */ + struct GNUNET_CONTAINER_SList *list; + + /** + * Last element accessed. + */ + struct GNUNET_CONTAINER_SList_Elem *last; + + /** + * Current list element. + */ + struct GNUNET_CONTAINER_SList_Elem *elem; +}; + + + +/** + * Add a new element to the list + * @param l list + * @param disp memory disposition + * @param buf payload buffer + * @param len length of the buffer + */ +void +GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l, + enum GNUNET_CONTAINER_SListDisposition disp, + const void *buf, size_t len); + + +/** + * Add a new element to the end of the list + * @param l list + * @param disp memory disposition + * @param buf payload buffer + * @param len length of the buffer + */ +void +GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l, + enum GNUNET_CONTAINER_SListDisposition disp, + const void *buf, size_t len); + + +/** + * Append a singly linked list to another + * @param dst list to append to + * @param src source + */ +void +GNUNET_CONTAINER_slist_append (struct GNUNET_CONTAINER_SList *dst, + struct GNUNET_CONTAINER_SList *src); + + +/** + * Create a new singly linked list + * @return the new list + */ +struct GNUNET_CONTAINER_SList * +GNUNET_CONTAINER_slist_create (void); + + +/** + * Destroy a singly linked list + * @param l the list to be destroyed + */ +void +GNUNET_CONTAINER_slist_destroy (struct GNUNET_CONTAINER_SList *l); + + +/** + * Return the beginning of a list + * + * @param l list + * @return iterator pointing to the beginning (by value! Either allocate the + * structure on the stack, or use GNUNET_malloc() yourself! All other + * functions do take pointer to this struct though) + */ +struct GNUNET_CONTAINER_SList_Iterator +GNUNET_CONTAINER_slist_begin (struct GNUNET_CONTAINER_SList *l); + + +/** + * Clear a list + * + * @param l list + */ +void +GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l); + + +/** + * Check if a list contains a certain element + * @param l list + * @param buf payload buffer to find + * @param len length of the payload (number of bytes in buf) + */ +int +GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l, + const void *buf, size_t len); + + +/** + * Count the elements of a list + * @param l list + * @return number of elements in the list + */ +int +GNUNET_CONTAINER_slist_count (const struct GNUNET_CONTAINER_SList *l); + + +/** + * Remove an element from the list + * @param i iterator that points to the element to be removed + */ +void +GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i); + + +/** + * Insert an element into a list at a specific position + * @param before where to insert the new element + * @param disp memory disposition + * @param buf payload buffer + * @param len length of the payload + */ +void +GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before, + enum GNUNET_CONTAINER_SListDisposition disp, + const void *buf, size_t len); + + +/** + * Advance an iterator to the next element + * @param i iterator + * @return GNUNET_YES on success, GNUNET_NO if the end has been reached + */ +int +GNUNET_CONTAINER_slist_next (struct GNUNET_CONTAINER_SList_Iterator *i); + + +/** + * Check if an iterator points beyond the end of a list + * @param i iterator + * @return GNUNET_YES if the end has been reached, GNUNET_NO if the iterator + * points to a valid element + */ +int +GNUNET_CONTAINER_slist_end (struct GNUNET_CONTAINER_SList_Iterator *i); + + +/** + * Retrieve the element at a specific position in a list + * + * @param i iterator + * @param len set to the payload length + * @return payload + */ +void * +GNUNET_CONTAINER_slist_get (const struct GNUNET_CONTAINER_SList_Iterator *i, + size_t * len); + + +/** + * Release an iterator + * @param i iterator + */ +void +GNUNET_CONTAINER_slist_iter_destroy (struct GNUNET_CONTAINER_SList_Iterator *i); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + +/* ifndef GNUNET_CONTAINER_LIB_H */ +#endif +/* end of gnunet_container_lib.h */ diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h new file mode 100644 index 0000000..1f6c0f3 --- /dev/null +++ b/src/include/gnunet_core_service.h @@ -0,0 +1,328 @@ +/* + This file is part of GNUnet. + (C) 2009, 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file include/gnunet_core_service.h + * @brief core service; this is the main API for encrypted P2P + * communications + * @author Christian Grothoff + */ + +#ifndef GNUNET_CORE_SERVICE_H +#define GNUNET_CORE_SERVICE_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_util_lib.h" +#include "gnunet_transport_service.h" + +/** + * Version number of GNUnet-core API. + */ +#define GNUNET_CORE_VERSION 0x00000000 + + +/** + * Opaque handle to the service. + */ +struct GNUNET_CORE_Handle; + + +/** + * Method called whenever a given peer connects. + * + * @param cls closure + * @param peer peer identity this notification is about + * @param atsi performance data for the connection + * @param atsi_count number of records in 'atsi' + */ +typedef void (*GNUNET_CORE_ConnectEventHandler) (void *cls, + const struct + GNUNET_PeerIdentity * peer, + const struct + GNUNET_ATS_Information * atsi, + unsigned int atsi_count); + + +/** + * Method called whenever a peer disconnects. + * + * @param cls closure + * @param peer peer identity this notification is about + */ +typedef void (*GNUNET_CORE_DisconnectEventHandler) (void *cls, + const struct + GNUNET_PeerIdentity * peer); + + +/** + * Functions with this signature are called whenever a message is + * received or transmitted. + * + * @param cls closure (set from GNUNET_CORE_connect) + * @param peer the other peer involved (sender or receiver, NULL + * for loopback messages where we are both sender and receiver) + * @param message the actual message + * @param atsi performance data for the connection + * @param atsi_count number of records in 'atsi' + * @return GNUNET_OK to keep the connection open, + * GNUNET_SYSERR to close it (signal serious error) + */ +typedef int (*GNUNET_CORE_MessageCallback) (void *cls, + const struct GNUNET_PeerIdentity * + other, + const struct GNUNET_MessageHeader * + message, + const struct GNUNET_ATS_Information + * atsi, unsigned int atsi_count); + + +/** + * Message handler. Each struct specifies how to handle on particular + * type of message received. + */ +struct GNUNET_CORE_MessageHandler +{ + /** + * Function to call for messages of "type". + */ + GNUNET_CORE_MessageCallback callback; + + /** + * Type of the message this handler covers. + */ + uint16_t type; + + /** + * Expected size of messages of this type. Use 0 for variable-size. + * If non-zero, messages of the given type will be discarded if they + * do not have the right size. + */ + uint16_t expected_size; + +}; + + +/** + * Function called after GNUNET_CORE_connect has succeeded (or failed + * 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...). + * + * @param cls closure + * @param server handle to the server, NULL if we failed + * @param my_identity ID of this peer, NULL if we failed + */ +typedef void (*GNUNET_CORE_StartupCallback) (void *cls, + struct GNUNET_CORE_Handle * server, + const struct GNUNET_PeerIdentity * + my_identity); + + +/** + * Connect to the core service. Note that the connection may complete + * (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 + * 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 on timeout or once we have successfully + * connected to the core service; note that timeout is only meaningful if init is not NULL + * @param connects function to call on peer connect, can be NULL + * @param disconnects function to call on peer disconnect / timeout, can be NULL + * @param inbound_notify function to call for all inbound messages, can be NULL + * note that the core is allowed to drop notifications about inbound + * messages if the client does not process them fast enough (for this + * notification type, a bounded queue is used) + * @param inbound_hdr_only set to GNUNET_YES if inbound_notify will only read the + * GNUNET_MessageHeader and hence we do not need to give it the full message; + * can be used to improve efficiency, ignored if inbound_notify is NULL + * note that the core is allowed to drop notifications about inbound + * messages if the client does not process them fast enough (for this + * notification type, a bounded queue is used) + * @param outbound_notify function to call for all outbound messages, can be NULL; + * note that the core is allowed to drop notifications about outbound + * messages if the client does not process them fast enough (for this + * notification type, a bounded queue is used) + * @param outbound_hdr_only set to GNUNET_YES if outbound_notify will only read the + * GNUNET_MessageHeader and hence we do not need to give it the full message + * can be used to improve efficiency, ignored if outbound_notify is NULL + * note that the core is allowed to drop notifications about outbound + * messages if the client does not process them fast enough (for this + * notification type, a bounded queue is used) + * @param handlers callbacks for messages we care about, NULL-terminated + * note that the core is allowed to drop notifications about inbound + * messages if the client does not process them fast enough (for this + * notification type, a bounded queue is used) + * @return handle to the core service (only useful for disconnect until 'init' is called), + * NULL on error (in this case, init is never called) + */ +struct GNUNET_CORE_Handle * +GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + unsigned int queue_size, void *cls, + GNUNET_CORE_StartupCallback init, + GNUNET_CORE_ConnectEventHandler connects, + GNUNET_CORE_DisconnectEventHandler disconnects, + GNUNET_CORE_MessageCallback inbound_notify, + int inbound_hdr_only, + GNUNET_CORE_MessageCallback outbound_notify, + int outbound_hdr_only, + const struct GNUNET_CORE_MessageHandler *handlers); + + +/** + * Disconnect from the core service. This function can only + * be called *after* all pending 'GNUNET_CORE_notify_transmit_ready' + * requests have been explicitly cancelled. + * + * @param handle connection to core to disconnect + */ +void +GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle); + + +/** + * Handle for a transmission request. + */ +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 + * called after a connection to the respective peer has been + * established (and the client has been informed about this). + * + * + * @param handle connection to core service + * @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 who should receive the message, + * use NULL for this peer (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 + * all pending transmission requests DURING the disconnect + * handler (unless they ensure that 'notify' never calls + * 'GNUNET_CORE_notify_transmit_ready'). + * @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. + */ +struct GNUNET_CORE_TransmitHandle * +GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, int cork, + uint32_t priority, + struct GNUNET_TIME_Relative maxdelay, + const struct GNUNET_PeerIdentity *target, + size_t notify_size, + GNUNET_CONNECTION_TransmitReadyNotify notify, + void *notify_cls); + + +/** + * Cancel the specified transmission-ready notification. + * + * @param th handle that was returned by "notify_transmit_ready". + */ +void +GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle + *th); + + + + + +/** + * Iterate over all connected peers. Calls peer_cb with each + * connected peer, and then once with NULL to indicate that all peers + * have been handled. Normal users of the CORE API are not expected + * to use this function. It is different in that it truly lists + * all connections, not just those relevant to the application. This + * function is used by special applications for diagnostics. This + * function is NOT part of the 'versioned', 'official' API. + * + * FIXME: we should probably make it possible to 'cancel' the + * operation... + * + * @param cfg configuration handle + * @param peer_cb function to call with the peer information + * @param cb_cls closure for peer_cb + * @return GNUNET_OK on success, GNUNET_SYSERR on errors + */ +int +GNUNET_CORE_iterate_peers (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_CORE_ConnectEventHandler peer_cb, + void *cb_cls); + + +/** + * Check if the given peer is currently connected and return information + * about the session if so. This function is for special cirumstances + * (GNUNET_TESTING 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. + * + * FIXME: we should probably make it possible to 'cancel' the + * operation... + * + * @param cfg configuration to use + * @param peer the specific peer to check for + * @param peer_cb function to call with the peer information + * @param cb_cls closure for peer_cb + * @return GNUNET_OK if iterating, GNUNET_SYSERR on error + */ +int +GNUNET_CORE_is_peer_connected (const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_PeerIdentity *peer, + GNUNET_CORE_ConnectEventHandler peer_cb, + void *cb_cls); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_CORE_SERVICE_H */ +#endif +/* end of gnunet_core_service.h */ diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h new file mode 100644 index 0000000..6e37266 --- /dev/null +++ b/src/include/gnunet_crypto_lib.h @@ -0,0 +1,882 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 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/gnunet_crypto_lib.h + * @brief cryptographic primitives for GNUnet + * + * @author Christian Grothoff + * @author Krista Bennett + * @author Gerd Knorr <kraxel@bytesex.org> + * @author Ioana Patrascu + * @author Tzvetan Horozov + */ + +#ifndef GNUNET_CRYPTO_LIB_H +#define GNUNET_CRYPTO_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" +#include "gnunet_scheduler_lib.h" + +/** + * Desired quality level for cryptographic operations. + */ +enum GNUNET_CRYPTO_Quality +{ + /** + * No good quality of the operation is needed (i.e., + * random numbers can be pseudo-random). + */ + GNUNET_CRYPTO_QUALITY_WEAK, + + /** + * High-quality operations are desired. + */ + GNUNET_CRYPTO_QUALITY_STRONG, + + /** + * Randomness for IVs etc. is required. + */ + GNUNET_CRYPTO_QUALITY_NONCE +}; + + +/** + * @brief length of the sessionkey in bytes (256 BIT sessionkey) + */ +#define GNUNET_CRYPTO_AES_KEY_LENGTH (256/8) + + +/** + * @brief Length of RSA encrypted data (2048 bit) + * + * We currently do not handle encryption of data + * that can not be done in a single call to the + * RSA methods (read: large chunks of data). + * We should never need that, as we can use + * the GNUNET_CRYPTO_hash for larger pieces of data for signing, + * and for encryption, we only need to encode sessionkeys! + */ +#define GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH 256 + + +/** + * Length of an RSA KEY (d,e,len), 2048 bit (=256 octests) key d, 2 byte e + */ +#define GNUNET_CRYPTO_RSA_KEY_LENGTH 258 + + +/** + * Length of a hash value + */ +#define GNUNET_CRYPTO_HASH_LENGTH 512/8 + +/** + * The private information of an RSA key pair. + */ +struct GNUNET_CRYPTO_RsaPrivateKey; + + +/** + * @brief 0-terminated ASCII encoding of a GNUNET_HashCode. + */ +struct GNUNET_CRYPTO_HashAsciiEncoded +{ + unsigned char encoding[104]; +}; + + + +/** + * @brief an RSA signature + */ +struct GNUNET_CRYPTO_RsaSignature +{ + unsigned char sig[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH]; +}; + + +GNUNET_NETWORK_STRUCT_BEGIN + +/** + * @brief header of what an RSA signature signs + * this must be followed by "size - 8" bytes of + * the actual signed data + */ +struct GNUNET_CRYPTO_RsaSignaturePurpose +{ + /** + * 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 A public key. + */ +struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded +{ + /** + * In big-endian, must be GNUNET_CRYPTO_RSA_KEY_LENGTH+4 + */ + uint16_t len GNUNET_PACKED; + + /** + * Size of n in key; in big-endian! + */ + uint16_t sizen GNUNET_PACKED; + + /** + * The key itself, contains n followed by e. + */ + unsigned char key[GNUNET_CRYPTO_RSA_KEY_LENGTH]; + + /** + * Padding (must be 0) + */ + uint16_t padding GNUNET_PACKED; +}; + + +/** + * RSA Encrypted data. + */ +struct GNUNET_CRYPTO_RsaEncryptedData +{ + unsigned char encoding[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH]; +}; + + +/** + * @brief type for session keys + */ +struct GNUNET_CRYPTO_AesSessionKey +{ + /** + * Actual key. + */ + unsigned char key[GNUNET_CRYPTO_AES_KEY_LENGTH]; + + /** + * checksum! + */ + uint32_t crc32 GNUNET_PACKED; +}; +GNUNET_NETWORK_STRUCT_END + +/** + * @brief IV for sym cipher + * + * NOTE: must be smaller (!) in size than the + * GNUNET_HashCode. + */ +struct GNUNET_CRYPTO_AesInitializationVector +{ + unsigned char iv[GNUNET_CRYPTO_AES_KEY_LENGTH / 2]; +}; + + +/** + * @brief type for (message) authentication keys + */ +struct GNUNET_CRYPTO_AuthKey +{ + unsigned char key[GNUNET_CRYPTO_HASH_LENGTH]; +}; + + +/* **************** Functions and Macros ************* */ + +/** + * Seed a weak random generator. Only GNUNET_CRYPTO_QUALITY_WEAK-mode generator + * can be seeded. + * + * @param seed the seed to use + */ +void +GNUNET_CRYPTO_seed_weak_random (int32_t seed); + + +/** + * Perform an incremental step in a CRC16 (for TCP/IP) calculation. + * + * @param sum current sum, initially 0 + * @param buf buffer to calculate CRC over (must be 16-bit aligned) + * @param len number of bytes in hdr, must be multiple of 2 + * @return updated crc sum (must be subjected to GNUNET_CRYPTO_crc16_finish to get actual crc16) + */ +uint32_t +GNUNET_CRYPTO_crc16_step (uint32_t sum, const void *buf, size_t len); + + +/** + * Convert results from GNUNET_CRYPTO_crc16_step to final crc16. + * + * @param sum cummulative sum + * @return crc16 value + */ +uint16_t +GNUNET_CRYPTO_crc16_finish (uint32_t sum); + + +/** + * Calculate the checksum of a buffer in one step. + * + * @param buf buffer to calculate CRC over (must be 16-bit aligned) + * @param len number of bytes in hdr, must be multiple of 2 + * @return crc16 value + */ +uint16_t +GNUNET_CRYPTO_crc16_n (const void *buf, size_t len); + + +/** + * Compute the CRC32 checksum for the first len + * bytes of the buffer. + * + * @param buf the data over which we're taking the CRC + * @param len the length of the buffer in bytes + * @return the resulting CRC32 checksum + */ +int32_t +GNUNET_CRYPTO_crc32_n (const void *buf, size_t len); + + +/** + * Produce a random value. + * + * @param mode desired quality of the random number + * @param i the upper limit (exclusive) for the random number + * @return a random value in the interval [0,i) (exclusive). + */ +uint32_t +GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i); + + +/** + * Random on unsigned 64-bit values. + * + * @param mode desired quality of the random number + * @param max value returned will be in range [0,max) (exclusive) + * @return random 64-bit number + */ +uint64_t +GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max); + + +/** + * Get an array with a random permutation of the + * numbers 0...n-1. + * @param mode GNUNET_CRYPTO_QUALITY_STRONG if the strong (but expensive) PRNG should be used, GNUNET_CRYPTO_QUALITY_WEAK otherwise + * @param n the size of the array + * @return the permutation array (allocated from heap) + */ +unsigned int * +GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n); + + +/** + * Create a new Session key. + * + * @param key key to initialize + */ +void +GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey *key); + +/** + * Check that a new session key is well-formed. + * + * @param key key to check + * @return GNUNET_OK if the key is valid + */ +int +GNUNET_CRYPTO_aes_check_session_key (const struct GNUNET_CRYPTO_AesSessionKey + *key); + + +/** + * Encrypt a block with the public key of another + * host that uses the same cyper. + * + * @param block the block to encrypt + * @param len the size of the block + * @param sessionkey the key used to encrypt + * @param iv the initialization vector to use, use INITVALUE + * for streams. + * @return the size of the encrypted block, -1 for errors + */ +ssize_t +GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len, + const struct GNUNET_CRYPTO_AesSessionKey *sessionkey, + const struct GNUNET_CRYPTO_AesInitializationVector + *iv, void *result); + + +/** + * Decrypt a given block with the sessionkey. + * + * @param block the data to decrypt, encoded as returned by encrypt + * @param size how big is the block? + * @param sessionkey the key used to decrypt + * @param iv the initialization vector to use + * @param result address to store the result at + * @return -1 on failure, size of decrypted block on success + */ +ssize_t +GNUNET_CRYPTO_aes_decrypt (const void *block, size_t size, + const struct GNUNET_CRYPTO_AesSessionKey *sessionkey, + const struct GNUNET_CRYPTO_AesInitializationVector + *iv, void *result); + + +/** + * @brief Derive an IV + * @param iv initialization vector + * @param skey session key + * @param salt salt for the derivation + * @param salt_len size of the salt + * @param ... pairs of void * & size_t for context chunks, terminated by NULL + */ +void +GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, + const struct GNUNET_CRYPTO_AesSessionKey *skey, + const void *salt, size_t salt_len, ...); + + +/** + * @brief Derive an IV + * @param iv initialization vector + * @param skey session key + * @param salt salt for the derivation + * @param salt_len size of the salt + * @param argp pairs of void * & size_t for context chunks, terminated by NULL + */ +void +GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector *iv, + const struct GNUNET_CRYPTO_AesSessionKey *skey, + const void *salt, size_t salt_len, va_list argp); + + +/** + * Convert hash to ASCII encoding. + * @param block the hash code + * @param result where to store the encoding (struct GNUNET_CRYPTO_HashAsciiEncoded can be + * safely cast to char*, a '\\0' termination is set). + */ +void +GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, + struct GNUNET_CRYPTO_HashAsciiEncoded *result); + + +/** + * Convert ASCII encoding back to GNUNET_CRYPTO_hash + * + * @param enc the encoding + * @param enclen number of characters in 'enc' (without 0-terminator, which can be missing) + * @param result where to store the GNUNET_CRYPTO_hash code + * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding + */ +int +GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen, + GNUNET_HashCode * result); + + +/** + * Convert ASCII encoding back to GNUNET_CRYPTO_hash + * @param enc the encoding + * @param result where to store the GNUNET_CRYPTO_hash code + * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding + */ +#define GNUNET_CRYPTO_hash_from_string(enc, result) \ + GNUNET_CRYPTO_hash_from_string2 (enc, strlen(enc), result) + + +/** + * Compute the distance between 2 hashcodes. + * The computation must be fast, not involve + * a.a or a.e (they're used elsewhere), and + * be somewhat consistent. And of course, the + * result should be a positive number. + * + * @param a some hash code + * @param b some hash code + * @return number between 0 and UINT32_MAX + */ +uint32_t +GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, + const GNUNET_HashCode * b); + + +/** + * Compute hash of a given block. + * + * @param block the data to hash + * @param size size of the block + * @param ret pointer to where to write the hashcode + */ +void +GNUNET_CRYPTO_hash (const void *block, size_t size, GNUNET_HashCode * ret); + + +/** + * Calculate HMAC of a message (RFC 2104) + * + * @param key secret key + * @param plaintext input plaintext + * @param plaintext_len length of plaintext + * @param hmac where to store the hmac + */ +void +GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, + const void *plaintext, size_t plaintext_len, + GNUNET_HashCode * hmac); + + +/** + * Function called once the hash computation over the + * specified file has completed. + * + * @param cls closure + * @param res resulting hash, NULL on error + */ +typedef void (*GNUNET_CRYPTO_HashCompletedCallback) (void *cls, + const GNUNET_HashCode * + res); + + +/** + * Handle to file hashing operation. + */ +struct GNUNET_CRYPTO_FileHashContext; + +/** + * Compute the hash of an entire file. + * + * @param priority scheduling priority to use + * @param filename name of file to hash + * @param blocksize number of bytes to process in one task + * @param callback function to call upon completion + * @param callback_cls closure for callback + * @return NULL on (immediate) errror + */ +struct GNUNET_CRYPTO_FileHashContext * +GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority, + const char *filename, size_t blocksize, + GNUNET_CRYPTO_HashCompletedCallback callback, + void *callback_cls); + + +/** + * Cancel a file hashing operation. + * + * @param fhc operation to cancel (callback must not yet have been invoked) + */ +void +GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc); + + +/** + * Create a random hash code. + * + * @param mode desired quality level + * @param result hash code that is randomized + */ +void +GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, + GNUNET_HashCode * result); + + +/** + * compute result(delta) = b - a + * + * @param a some hash code + * @param b some hash code + * @param result set to b - a + */ +void +GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, + const GNUNET_HashCode * b, + GNUNET_HashCode * result); + + +/** + * compute result(b) = a + delta + * + * @param a some hash code + * @param delta some hash code + * @param result set to a + delta + */ +void +GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, + const GNUNET_HashCode * delta, + GNUNET_HashCode * result); + + +/** + * compute result = a ^ b + * + * @param a some hash code + * @param b some hash code + * @param result set to a ^ b + */ +void +GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b, + GNUNET_HashCode * result); + + +/** + * Convert a hashcode into a key. + * + * @param hc hash code that serves to generate the key + * @param skey set to a valid session key + * @param iv set to a valid initialization vector + */ +void +GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, + struct GNUNET_CRYPTO_AesSessionKey *skey, + struct GNUNET_CRYPTO_AesInitializationVector + *iv); + + +/** + * Obtain a bit from a hashcode. + * + * @param code the GNUNET_CRYPTO_hash to index bit-wise + * @param bit index into the hashcode, [0...159] + * @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); + +/** + * Determine how many low order bits match in two + * 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!). + * + * @param first the first hashcode + * @param second the hashcode to compare first to + * + * @return the number of bits that match + */ +unsigned int +GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first, + const GNUNET_HashCode * second); + + +/** + * Compare function for HashCodes, producing a total ordering + * of all hashcodes. + * + * @param h1 some hash code + * @param h2 some hash code + * @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); + + +/** + * Find out which of the two GNUNET_CRYPTO_hash codes is closer to target + * in the XOR metric (Kademlia). + * + * @param h1 some hash code + * @param h2 some hash code + * @param target some hash code + * @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); + + +/** + * @brief Derive an authentication key + * @param key authentication key + * @param rkey root key + * @param salt salt + * @param salt_len size of the salt + * @param argp pair of void * & size_t for context chunks, terminated by NULL + */ +void +GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key, + const struct GNUNET_CRYPTO_AesSessionKey *rkey, + const void *salt, size_t salt_len, + va_list argp); + + +/** + * @brief Derive an authentication key + * @param key authentication key + * @param rkey root key + * @param salt salt + * @param salt_len size of the salt + * @param ... pair of void * & size_t for context chunks, terminated by NULL + */ +void +GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key, + const struct GNUNET_CRYPTO_AesSessionKey *rkey, + const void *salt, size_t salt_len, ...); + +/** + * @brief Derive key + * @param result buffer for the derived key, allocated by caller + * @param out_len desired length of the derived key + * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_... + * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_... + * @param xts salt + * @param xts_len length of xts + * @param skm source key material + * @param skm_len length of skm + * @return GNUNET_YES on success + */ +int +GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, int prf_algo, + const void *xts, size_t xts_len, const void *skm, + size_t skm_len, ...); + + +/** + * @brief Derive key + * @param result buffer for the derived key, allocated by caller + * @param out_len desired length of the derived key + * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_... + * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_... + * @param xts salt + * @param xts_len length of xts + * @param skm source key material + * @param skm_len length of skm + * @param argp va_list of void * & size_t pairs for context chunks + * @return GNUNET_YES on success + */ +int +GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo, + const void *xts, size_t xts_len, const void *skm, + size_t skm_len, va_list argp); + + +/** + * @brief Derive key + * @param result buffer for the derived key, allocated by caller + * @param out_len desired length of the derived key + * @param xts salt + * @param xts_len length of xts + * @param skm source key material + * @param skm_len length of skm + * @param argp va_list of void * & size_t pairs for context chunks + * @return GNUNET_YES on success + */ +int +GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts, + size_t xts_len, const void *skm, size_t skm_len, + va_list argp); + + +/** + * @brief Derive key + * @param result buffer for the derived key, allocated by caller + * @param out_len desired length of the derived key + * @param xts salt + * @param xts_len length of xts + * @param skm source key material + * @param skm_len length of skm + * @param ... void * & size_t pairs for context chunks + * @return GNUNET_YES on success + */ +int +GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts, + size_t xts_len, const void *skm, size_t skm_len, ...); + + +/** + * Create a new private key. Caller must free return value. + * + * @return fresh private key + */ +struct GNUNET_CRYPTO_RsaPrivateKey * +GNUNET_CRYPTO_rsa_key_create (void); + +/** + * 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' + */ +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 + * 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. + * + * @param filename name of file to use for storage + * @return new private key, NULL on error (for example, + * permission denied) + */ +struct GNUNET_CRYPTO_RsaPrivateKey * +GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename); + + +/** + * Deterministically (!) create a private key using only the + * given HashCode as input to the PRNG. + * + * @param hc "random" input to PRNG + * @return some private key purely dependent on input + */ +struct GNUNET_CRYPTO_RsaPrivateKey * +GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc); + + +/** + * Free memory occupied by the private key. + * @param hostkey pointer to the memory to free + */ +void +GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey); + + +/** + * Extract the public key of the host. + * + * @param priv the private key + * @param pub where to write the public key + */ +void +GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey + *priv, + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded + *pub); + + +/** + * Encrypt a block with the public key of another host that uses the + * same cyper. + * + * @param block the block to encrypt + * @param size the size of block + * @param publicKey the encoded public key used to encrypt + * @param target where to store the encrypted block + * @return GNUNET_SYSERR on error, GNUNET_OK if ok + */ +int +GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size, + const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded + *publicKey, + struct GNUNET_CRYPTO_RsaEncryptedData *target); + + +/** + * Decrypt a given block with the hostkey. + * + * @param key the key to use + * @param block the data to decrypt, encoded as returned by encrypt, not consumed + * @param result pointer to a location where the result can be stored + * @param max how many bytes of a result are expected? Must be exact. + * @return the size of the decrypted block (that is, size) or -1 on error + */ +ssize_t +GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *key, + const struct GNUNET_CRYPTO_RsaEncryptedData *block, + void *result, size_t max); + + +/** + * 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_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key, + const struct GNUNET_CRYPTO_RsaSignaturePurpose *purpose, + struct GNUNET_CRYPTO_RsaSignature *sig); + + +/** + * Verify signature. Note that the caller MUST have already + * checked that "validate->size" bytes are actually available. + * + * @param purpose what is the purpose that validate should have? + * @param validate block to validate (size, purpose, data) + * @param sig signature that is being validated + * @param publicKey public key of the signer + * @return GNUNET_OK if ok, GNUNET_SYSERR if invalid + */ +int +GNUNET_CRYPTO_rsa_verify (uint32_t purpose, + const struct GNUNET_CRYPTO_RsaSignaturePurpose + *validate, + const struct GNUNET_CRYPTO_RsaSignature *sig, + const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded + *publicKey); + + + +/** + * This function should only be called in testcases + * where strong entropy gathering is not desired + * (for example, for hostkey generation). + */ +void +GNUNET_CRYPTO_random_disable_entropy_gathering (void); + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + +/* ifndef GNUNET_CRYPTO_LIB_H */ +#endif +/* end of gnunet_crypto_lib.h */ diff --git a/src/include/gnunet_datacache_lib.h b/src/include/gnunet_datacache_lib.h new file mode 100644 index 0000000..84cb4d6 --- /dev/null +++ b/src/include/gnunet_datacache_lib.h @@ -0,0 +1,134 @@ +/* + This file is part of GNUnet + (C) 2006, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_datacache_lib.h + * @brief datacache is a simple, transient hash table + * of bounded size with content expiration. + * In contrast to the sqstore there is + * no prioritization, deletion or iteration. + * All of the data is discarded when the peer shuts down! + * @author Christian Grothoff + */ + +#ifndef GNUNET_DATACACHE_LIB_H +#define GNUNET_DATACACHE_LIB_H + +#include "gnunet_util_lib.h" +#include "gnunet_block_lib.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * Handle to the cache. + */ +struct GNUNET_DATACACHE_Handle; + + +/** + * Create a data cache. + * + * @param cfg configuration to use + * @param section section in the configuration that contains our options + * @return handle to use to access the service + */ +struct GNUNET_DATACACHE_Handle * +GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section); + + +/** + * Destroy a data cache (and free associated resources). + * + * @param h handle to the datastore + */ +void +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 + * @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, + size_t size, const char *data, + enum GNUNET_BLOCK_Type type); + + +/** + * Store an item in the datacache. + * + * @param h handle to the datacache + * @param key key to store data under + * @param size number of bytes in data + * @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.) + */ +int +GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h, + const GNUNET_HashCode * key, size_t size, + const char *data, enum GNUNET_BLOCK_Type type, + struct GNUNET_TIME_Absolute discard_time); + + +/** + * Iterate over the results for a particular key + * in the datacache. + * + * @param h handle to the datacache + * @param key what to look up + * @param type entries of which type are relevant? + * @param iter maybe NULL (to just count) + * @param iter_cls closure for iter + * @return the number of results found + */ +unsigned int +GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h, + const GNUNET_HashCode * key, enum GNUNET_BLOCK_Type type, + GNUNET_DATACACHE_Iterator iter, void *iter_cls); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* end of gnunet_datacache_lib.h */ +#endif diff --git a/src/include/gnunet_datacache_plugin.h b/src/include/gnunet_datacache_plugin.h new file mode 100644 index 0000000..fbfcdf1 --- /dev/null +++ b/src/include/gnunet_datacache_plugin.h @@ -0,0 +1,154 @@ +/* + This file is part of GNUnet + (C) 2006, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_datacache_plugin.h + * @brief API for database backends for the datacache + * @author Christian Grothoff + */ +#ifndef PLUGIN_DATACACHE_H +#define PLUGIN_DATACACHE_H + +#include "gnunet_datacache_lib.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * Function called by plugins to notify the datacache + * about content deletions. + * + * @param cls closure + * @param key key of the content that was deleted + * @param size number of bytes that were made available + */ +typedef void (*GNUNET_DATACACHE_DeleteNotifyCallback) (void *cls, + const GNUNET_HashCode * + key, size_t size); + + +/** + * The datastore service will pass a pointer to a struct + * of this type as the first and only argument to the + * entry point of each datastore plugin. + */ +struct GNUNET_DATACACHE_PluginEnvironment +{ + + + /** + * Configuration to use. + */ + const struct GNUNET_CONFIGURATION_Handle *cfg; + + /** + * Configuration section to use. + */ + const char *section; + + /** + * Closure to use for callbacks. + */ + void *cls; + + /** + * Function to call whenever the plugin needs to + * discard content that it was asked to store. + */ + GNUNET_DATACACHE_DeleteNotifyCallback delete_notify; + + /** + * How much space are we allowed to use? + */ + unsigned long long quota; + +}; + + +/** + * @brief struct returned by the initialization function of the plugin + */ +struct GNUNET_DATACACHE_PluginFunctions +{ + + /** + * Closure to pass to all plugin functions. + */ + void *cls; + + /** + * Store an item in the datastore. + * + * @param cls closure (internal context for the plugin) + * @param size number of bytes in data + * @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 + */ + 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); + + + /** + * Iterate over the results for a particular key + * in the datastore. + * + * @param cls closure (internal context for the plugin) + * @param key + * @param type entries of which type are relevant? + * @param iter maybe NULL (to just count) + * @param iter_cls closure for iter + * @return the number of results found + */ + unsigned int (*get) (void *cls, const GNUNET_HashCode * key, + enum GNUNET_BLOCK_Type type, + GNUNET_DATACACHE_Iterator iter, void *iter_cls); + + + /** + * Delete the entry with the lowest expiration value + * from the datacache right now. + * + * @param cls closure (internal context for the plugin) + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ + int (*del) (void *cls); + + +}; + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* end of gnunet_datacache_plugin.h */ +#endif diff --git a/src/include/gnunet_datastore_plugin.h b/src/include/gnunet_datastore_plugin.h new file mode 100644 index 0000000..bbf0ce2 --- /dev/null +++ b/src/include/gnunet_datastore_plugin.h @@ -0,0 +1,333 @@ +/* + This file is part of GNUnet + (C) 2009, 2011 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/gnunet_datastore_plugin.h + * @brief API for the database backend plugins. + * @author Christian Grothoff + */ +#ifndef PLUGIN_DATASTORE_H +#define PLUGIN_DATASTORE_H + +#include "gnunet_block_lib.h" +#include "gnunet_configuration_lib.h" +#include "gnunet_datastore_service.h" +#include "gnunet_statistics_service.h" +#include "gnunet_scheduler_lib.h" + + +/** + * How many bytes of overhead will we assume per entry + * in any DB (for reservations)? + */ +#define GNUNET_DATASTORE_ENTRY_OVERHEAD 256 + + +/** + * Function invoked to notify service of disk utilization + * changes. + * + * @param cls closure + * @param delta change in disk utilization, + * 0 for "reset to empty" + */ +typedef void (*DiskUtilizationChange) (void *cls, int delta); + + +/** + * The datastore service will pass a pointer to a struct + * of this type as the first and only argument to the + * entry point of each datastore plugin. + */ +struct GNUNET_DATASTORE_PluginEnvironment +{ + /** + * Configuration to use. + */ + const struct GNUNET_CONFIGURATION_Handle *cfg; + + /** + * Function to call on disk utilization change. + */ + DiskUtilizationChange duc; + + /** + * Closure. + */ + void *cls; + +}; + + +/** + * An processor over a set of items stored in the datastore. + * + * @param cls closure + * @param key key for the content + * @param size number of bytes in data + * @param data content stored + * @param type type of the content + * @param priority priority of the content + * @param anonymity anonymity-level for the content + * @param expiration expiration time for the content + * @param uid unique identifier for the datum + * + * @return GNUNET_OK to keep the item + * GNUNET_NO to delete the item + */ +typedef int (*PluginDatumProcessor) (void *cls, const GNUNET_HashCode * key, + uint32_t size, const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, uint32_t anonymity, + struct GNUNET_TIME_Absolute expiration, + uint64_t uid); + +/** + * Get an estimate of how much space the database is + * currently using. + * + * @param cls closure + * @return number of bytes used on disk + */ +typedef unsigned long long (*PluginEstimateSize) (void *cls); + + +/** + * Store an item in the datastore. If the item is already present, + * the priorities and replication levels are summed up and the higher + * expiration time and lower anonymity level is used. + * + * @param cls closure + * @param key key for the item + * @param size number of bytes in data + * @param data content stored + * @param type type of the content + * @param priority priority of the content + * @param anonymity anonymity-level for the content + * @param replication replication-level for the content + * @param expiration expiration time for the content + * @param msg set to an error message (on failure) + * @return GNUNET_OK on success, + * GNUNET_SYSERR on failure + */ +typedef int (*PluginPut) (void *cls, const GNUNET_HashCode * key, uint32_t size, + const void *data, enum GNUNET_BLOCK_Type type, + uint32_t priority, uint32_t anonymity, + uint32_t replication, + struct GNUNET_TIME_Absolute expiration, char **msg); + + +/** + * An processor over a set of keys stored in the datastore. + * + * @param cls closure + * @param key key in the data store + * @param count how many values are stored under this key in the datastore + */ +typedef void (*PluginKeyProcessor) (void *cls, + const GNUNET_HashCode *key, + unsigned int count); + + +/** + * Get all of the keys in the datastore. + * + * @param cls closure + * @param proc function to call on each key + * @param proc_cls closure for proc + */ +typedef void (*PluginGetKeys) (void *cls, + PluginKeyProcessor proc, void *proc_cls); + + +/** + * Get one of the results for a particular key in the datastore. + * + * @param cls closure + * @param offset offset of the result (modulo num-results); + * specific ordering does not matter for the offset + * @param key key to match, never NULL + * @param vhash hash of the value, maybe NULL (to + * match all values that have the right key). + * Note that for DBlocks there is no difference + * betwen key and vhash, but for other blocks + * there may be! + * @param type entries of which type are relevant? + * Use 0 for any type. + * @param min find the smallest key that is larger than the given min, + * NULL for no minimum (return smallest key) + * @param proc function to call on the matching value; + * proc should be called with NULL if there is no result + * @param proc_cls closure for proc + */ +typedef void (*PluginGetKey) (void *cls, uint64_t offset, + const GNUNET_HashCode * key, + const GNUNET_HashCode * vhash, + enum GNUNET_BLOCK_Type type, + PluginDatumProcessor proc, void *proc_cls); + + +/** + * Get a random item (additional constraints may apply depending on + * the specific implementation). Calls 'proc' with all values ZERO or + * NULL if no item applies, otherwise 'proc' is called once and only + * once with an item. + * + * @param cls closure + * @param proc function to call the value (once only). + * @param proc_cls closure for proc + */ +typedef void (*PluginGetRandom) (void *cls, PluginDatumProcessor proc, + void *proc_cls); + + + + +/** + * Update the priority for a particular key in the datastore. If + * the expiration time in value is different than the time found in + * the datastore, the higher value should be kept. For the + * anonymity level, the lower value is to be used. The specified + * 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 + * change? If priority + delta < 0 the + * priority should be set to 0 (never go + * negative). + * @param expire new expiration time should be the + * MAX of any existing expiration time and + * this value + * @param msg set to an error message (on error) + * @return GNUNET_OK on success + */ +typedef int (*PluginUpdate) (void *cls, uint64_t uid, int delta, + struct GNUNET_TIME_Absolute expire, char **msg); + + +/** + * Select a single item from the datastore at the specified offset + * (among those applicable). + * + * @param cls closure + * @param offset offset of the result (modulo num-results); + * specific ordering does not matter for the offset + * @param type entries of which type should be considered? + * Must not be zero (ANY). + * @param proc function to call on the matching value + * @param proc_cls closure for proc + */ +typedef void (*PluginGetType) (void *cls, uint64_t offset, + enum GNUNET_BLOCK_Type type, + PluginDatumProcessor proc, void *proc_cls); + + +/** + * Drop database. + * + * @param cls closure + */ +typedef void (*PluginDrop) (void *cls); + + + +/** + * Each plugin is required to return a pointer to a struct of this + * type as the return value from its entry point. + */ +struct GNUNET_DATASTORE_PluginFunctions +{ + + /** + * Closure to use for all of the following callbacks + * (except "next_request"). + */ + void *cls; + + /** + * Calculate the current on-disk size of the SQ store. Estimates + * are fine, if that's the only thing available. + */ + PluginEstimateSize estimate_size; + + /** + * Function to store an item in the datastore. + */ + PluginPut put; + + /** + * Update the priority for a particular key in the datastore. If + * the expiration time in value is different than the time found in + * the datastore, the higher value should be kept. For the + * anonymity level, the lower value is to be used. The specified + * priority should be added to the existing priority, ignoring the + * priority in value. + */ + PluginUpdate update; + + /** + * Get a particular datum matching a given hash from the datastore. + */ + PluginGetKey get_key; + + /** + * Get datum (of the specified type) with anonymity level zero. + * This function is allowed to ignore the 'offset' argument + * and instead return a random result (with zero anonymity of + * the correct type) if implementing an offset is expensive. + */ + PluginGetType get_zero_anonymity; + + /** + * Function to get a random item with high replication score from + * the database, lowering the item's replication score. Returns a + * single random item from those with the highest replication + * counters. The item's replication counter is decremented by one + * IF it was positive before. + */ + PluginGetRandom get_replication; + + /** + * Function to get a random expired item or, if none are expired, + * either the oldest entry or one with a low priority (depending + * on what was efficiently implementable). + */ + PluginGetRandom get_expiration; + + /** + * Delete the database. The next operation is + * guaranteed to be unloading of the module. + */ + PluginDrop drop; + + /** + * Iterate over all keys in the database. + */ + PluginGetKeys get_keys; + +}; + + +#endif diff --git a/src/include/gnunet_datastore_service.h b/src/include/gnunet_datastore_service.h new file mode 100644 index 0000000..b4af0e6 --- /dev/null +++ b/src/include/gnunet_datastore_service.h @@ -0,0 +1,393 @@ +/* + This file is part of GNUnet + (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 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/gnunet_datastore_service.h + * @brief API that can be used manage the + * datastore for files stored on a GNUnet node; + * note that the datastore is NOT responsible for + * on-demand encoding, that is achieved using + * a special kind of entry. + * @author Christian Grothoff + */ + +#ifndef GNUNET_DATASTORE_SERVICE_H +#define GNUNET_DATASTORE_SERVICE_H + +#include "gnunet_util_lib.h" +#include "gnunet_block_lib.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +/** + * Entry in the queue. + */ +struct GNUNET_DATASTORE_QueueEntry; + +/** + * Handle to the datastore service. + */ +struct GNUNET_DATASTORE_Handle; + +/** + * Maximum size of a value that can be stored in the datastore. + */ +#define GNUNET_DATASTORE_MAX_VALUE_SIZE 65536 + +/** + * Connect to the datastore service. + * + * @param cfg configuration to use + * @return handle to use to access the service + */ +struct GNUNET_DATASTORE_Handle * +GNUNET_DATASTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Disconnect from the datastore service (and free + * associated resources). + * + * @param h handle to the datastore + * @param drop set to GNUNET_YES to delete all data in datastore (!) + */ +void +GNUNET_DATASTORE_disconnect (struct GNUNET_DATASTORE_Handle *h, int drop); + + +/** + * Continuation called to notify client about result of the + * operation. + * + * @param cls closure + * @param success GNUNET_SYSERR on failure (including timeout/queue drop) + * GNUNET_NO if content was already there + * GNUNET_YES (or other positive value) on success + * @param min_expiration minimum expiration time required for 0-priority content to be stored + * by the datacache at this time, zero for unknown, forever if we have no + * space for 0-priority content + * @param msg NULL on success, otherwise an error message + */ +typedef void (*GNUNET_DATASTORE_ContinuationWithStatus) (void *cls, + int32_t success, + struct GNUNET_TIME_Absolute min_expiration, + const char *msg); + + +/** + * Reserve space in the datastore. This function should be used + * to avoid "out of space" failures during a longer sequence of "put" + * operations (for example, when a file is being inserted). + * + * @param h handle to the datastore + * @param amount how much space (in bytes) should be reserved (for content only) + * @param entries how many entries will be created (to calculate per-entry overhead) + * @param queue_priority ranking of this request in the priority queue + * @param max_queue_size at what queue size should this request be dropped + * (if other requests of higher priority are in the queue) + * @param timeout how long to wait at most for a response (or before dying in queue) + * @param cont continuation to call when done; "success" will be set to + * a positive reservation value if space could be reserved. + * @param cont_cls closure for cont + * @return NULL if the entry was not queued, otherwise a handle that can be used to + * cancel; note that even if NULL is returned, the callback will be invoked + * (or rather, will already have been invoked) + */ +struct GNUNET_DATASTORE_QueueEntry * +GNUNET_DATASTORE_reserve (struct GNUNET_DATASTORE_Handle *h, uint64_t amount, + uint32_t entries, unsigned int queue_priority, + unsigned int max_queue_size, + struct GNUNET_TIME_Relative timeout, + GNUNET_DATASTORE_ContinuationWithStatus cont, + void *cont_cls); + + +/** + * Store an item in the datastore. If the item is already present, + * the priorities and replication values are summed up and the higher + * expiration time and lower anonymity level is used. + * + * @param h handle to the datastore + * @param rid reservation ID to use (from "reserve"); use 0 if no + * prior reservation was made + * @param key key for the value + * @param size number of bytes in data + * @param data content stored + * @param type type of the content + * @param priority priority of the content + * @param anonymity anonymity-level for the content + * @param replication how often should the content be replicated to other peers? + * @param expiration expiration time for the content + * @param queue_priority ranking of this request in the priority queue + * @param max_queue_size at what queue size should this request be dropped + * (if other requests of higher priority are in the queue) + * @param timeout timeout for the operation + * @param cont continuation to call when done + * @param cont_cls closure for cont + * @return NULL if the entry was not queued, otherwise a handle that can be used to + * cancel; note that even if NULL is returned, the callback will be invoked + * (or rather, will already have been invoked) + */ +struct GNUNET_DATASTORE_QueueEntry * +GNUNET_DATASTORE_put (struct GNUNET_DATASTORE_Handle *h, uint32_t rid, + const GNUNET_HashCode * key, size_t size, + const void *data, enum GNUNET_BLOCK_Type type, + uint32_t priority, uint32_t anonymity, + uint32_t replication, + struct GNUNET_TIME_Absolute expiration, + unsigned int queue_priority, unsigned int max_queue_size, + struct GNUNET_TIME_Relative timeout, + GNUNET_DATASTORE_ContinuationWithStatus cont, + void *cont_cls); + + +/** + * Signal that all of the data for which a reservation was made has + * been stored and that whatever excess space might have been reserved + * can now be released. + * + * @param h handle to the datastore + * @param rid reservation ID (value of "success" in original continuation + * from the "reserve" function). + * @param queue_priority ranking of this request in the priority queue + * @param max_queue_size at what queue size should this request be dropped + * (if other requests of higher priority are in the queue) + * @param queue_priority ranking of this request in the priority queue + * @param max_queue_size at what queue size should this request be dropped + * (if other requests of higher priority are in the queue) + * @param timeout how long to wait at most for a response + * @param cont continuation to call when done + * @param cont_cls closure for cont + * @return NULL if the entry was not queued, otherwise a handle that can be used to + * cancel; note that even if NULL is returned, the callback will be invoked + * (or rather, will already have been invoked) + */ +struct GNUNET_DATASTORE_QueueEntry * +GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h, + uint32_t rid, unsigned int queue_priority, + unsigned int max_queue_size, + struct GNUNET_TIME_Relative timeout, + GNUNET_DATASTORE_ContinuationWithStatus cont, + void *cont_cls); + + +/** + * Update a value in the datastore. + * + * @param h handle to the datastore + * @param uid identifier for the value + * @param priority how much to increase the priority of the value + * @param expiration new expiration value should be MAX of existing and this argument + * @param queue_priority ranking of this request in the priority queue + * @param max_queue_size at what queue size should this request be dropped + * (if other requests of higher priority are in the queue) + * @param timeout how long to wait at most for a response + * @param cont continuation to call when done + * @param cont_cls closure for cont + * @return NULL if the entry was not queued, otherwise a handle that can be used to + * cancel; note that even if NULL is returned, the callback will be invoked + * (or rather, will already have been invoked) + */ +struct GNUNET_DATASTORE_QueueEntry * +GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h, uint64_t uid, + uint32_t priority, + struct GNUNET_TIME_Absolute expiration, + unsigned int queue_priority, + unsigned int max_queue_size, + struct GNUNET_TIME_Relative timeout, + GNUNET_DATASTORE_ContinuationWithStatus cont, + void *cont_cls); + + +/** + * Explicitly remove some content from the database. + * The "cont"inuation will be called with status + * "GNUNET_OK" if content was removed, "GNUNET_NO" + * if no matching entry was found and "GNUNET_SYSERR" + * on all other types of errors. + * + * @param h handle to the datastore + * @param key key for the value + * @param size number of bytes in data + * @param data content stored + * @param queue_priority ranking of this request in the priority queue + * @param max_queue_size at what queue size should this request be dropped + * (if other requests of higher priority are in the queue) + * @param timeout how long to wait at most for a response + * @param cont continuation to call when done + * @param cont_cls closure for cont + * @return NULL if the entry was not queued, otherwise a handle that can be used to + * cancel; note that even if NULL is returned, the callback will be invoked + * (or rather, will already have been invoked) + */ +struct GNUNET_DATASTORE_QueueEntry * +GNUNET_DATASTORE_remove (struct GNUNET_DATASTORE_Handle *h, + const GNUNET_HashCode * key, size_t size, + const void *data, unsigned int queue_priority, + unsigned int max_queue_size, + struct GNUNET_TIME_Relative timeout, + GNUNET_DATASTORE_ContinuationWithStatus cont, + void *cont_cls); + + +/** + * Process a datum that was stored in the datastore. + * + * @param cls closure + * @param key key for the content + * @param size number of bytes in data + * @param data content stored + * @param type type of the content + * @param priority priority of the content + * @param anonymity anonymity-level for the content + * @param expiration expiration time for the content + * @param uid unique identifier for the datum; + * maybe 0 if no unique identifier is available + */ +typedef void (*GNUNET_DATASTORE_DatumProcessor) (void *cls, + const GNUNET_HashCode * key, + size_t size, const void *data, + enum GNUNET_BLOCK_Type type, + uint32_t priority, + uint32_t anonymity, + struct GNUNET_TIME_Absolute + expiration, uint64_t uid); + + +/** + * Get a result for a particular key from the datastore. The processor + * will only be called once. + * + * @param h handle to the datastore + * @param offset offset of the result (modulo num-results); set to + * a random 64-bit value initially; then increment by + * one each time; detect that all results have been found by uid + * being again the first uid ever returned. + * @param key maybe NULL (to match all entries) + * @param type desired type, 0 for any + * @param queue_priority ranking of this request in the priority queue + * @param max_queue_size at what queue size should this request be dropped + * (if other requests of higher priority are in the queue) + * @param timeout how long to wait at most for a response + * @param proc function to call on each matching value; + * will be called once with a NULL value at the end + * @param proc_cls closure for proc + * @return NULL if the entry was not queued, otherwise a handle that can be used to + * cancel + */ +struct GNUNET_DATASTORE_QueueEntry * +GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, uint64_t offset, + const GNUNET_HashCode * key, + enum GNUNET_BLOCK_Type type, + unsigned int queue_priority, + unsigned int max_queue_size, + struct GNUNET_TIME_Relative timeout, + GNUNET_DATASTORE_DatumProcessor proc, void *proc_cls); + + +/** + * Get a single zero-anonymity value from the datastore. + * Note that some implementations can ignore the 'offset' and + * instead return a random zero-anonymity value. In that case, + * detecting the wrap-around based on a repeating UID is at best + * probabilistic. + * + * @param h handle to the datastore + * @param offset offset of the result (modulo num-results); set to + * a random 64-bit value initially; then increment by + * one each time; detect that all results have been found by uid + * being again the first uid ever returned. + * @param queue_priority ranking of this request in the priority queue + * @param max_queue_size at what queue size should this request be dropped + * (if other requests of higher priority are in the queue) + * @param timeout how long to wait at most for a response + * @param type allowed type for the operation (never zero) + * @param proc function to call on a random value; it + * will be called once with a value (if available) + * or with NULL if none value exists. + * @param proc_cls closure for proc + * @return NULL if the entry was not queued, otherwise a handle that can be used to + * cancel + */ +struct GNUNET_DATASTORE_QueueEntry * +GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h, + uint64_t offset, + unsigned int queue_priority, + unsigned int max_queue_size, + struct GNUNET_TIME_Relative timeout, + enum GNUNET_BLOCK_Type type, + GNUNET_DATASTORE_DatumProcessor proc, + void *proc_cls); + + +/** + * Get a random value from the datastore for content replication. + * Returns a single, random value among those with the highest + * replication score, lowering positive replication scores by one for + * the chosen value (if only content with a replication score exists, + * a random value is returned and replication scores are not changed). + * + * @param h handle to the datastore + * @param queue_priority ranking of this request in the priority queue + * @param max_queue_size at what queue size should this request be dropped + * (if other requests of higher priority are in the queue) + * @param timeout how long to wait at most for a response + * @param proc function to call on a random value; it + * will be called once with a value (if available) + * and always once with a value of NULL. + * @param proc_cls closure for proc + * @return NULL if the entry was not queued, otherwise a handle that can be used to + * cancel + */ +struct GNUNET_DATASTORE_QueueEntry * +GNUNET_DATASTORE_get_for_replication (struct GNUNET_DATASTORE_Handle *h, + unsigned int queue_priority, + unsigned int max_queue_size, + struct GNUNET_TIME_Relative timeout, + GNUNET_DATASTORE_DatumProcessor proc, + void *proc_cls); + + + +/** + * Cancel a datastore operation. The final callback from the + * operation must not have been done yet. + * + * @param qe operation to cancel + */ +void +GNUNET_DATASTORE_cancel (struct GNUNET_DATASTORE_QueueEntry *qe); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* end of gnunet_datastore_service.h */ +#endif diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h new file mode 100644 index 0000000..e533ef2 --- /dev/null +++ b/src/include/gnunet_dht_service.h @@ -0,0 +1,290 @@ +/* + This file is part of GNUnet + (C) 2004, 2005, 2006, 2008, 2009, 2011 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_dht_service.h + * @brief API to the DHT service + * @author Christian Grothoff + */ + +#ifndef GNUNET_DHT_SERVICE_H +#define GNUNET_DHT_SERVICE_H + +#include "gnunet_util_lib.h" +#include "gnunet_block_lib.h" +#include "gnunet_hello_lib.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * Default republication frequency for stored data in the DHT. + */ +#define GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60) + + + +/** + * Connection to the DHT service. + */ +struct GNUNET_DHT_Handle; + +/** + * Handle to control a get operation. + */ +struct GNUNET_DHT_GetHandle; + +/** + * Handle to control a find peer operation. + */ +struct GNUNET_DHT_FindPeerHandle; + + +/** + * Options for routing. + */ +enum GNUNET_DHT_RouteOption +{ + /** + * Default. Do nothing special. + */ + GNUNET_DHT_RO_NONE = 0, + + /** + * Each peer along the way should look at 'enc' (otherwise + * only the k-peers closest to the key should look at it). + */ + GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE = 1, + + /** + * We should keep track of the route that the message + * took in the P2P network. + */ + GNUNET_DHT_RO_RECORD_ROUTE = 2, + + /** + * This is a 'FIND-PEER' request, so approximate results are fine. + */ + GNUNET_DHT_RO_FIND_PEER = 4, + + /** + * Possible message option for query key randomization. + */ + GNUNET_DHT_RO_BART = 8 +}; + + +/** + * Initialize the connection with the DHT service. + * + * @param cfg configuration to use + * @param ht_len size of the internal hash table to use for + * processing multiple GET/FIND requests in parallel + * @return NULL on error + */ +struct GNUNET_DHT_Handle * +GNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + unsigned int ht_len); + + +/** + * Shutdown connection with the DHT service. + * + * @param handle connection to shut down + */ +void +GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle); + + +/* *************** Standard API: get and put ******************* */ + +/** + * Perform a PUT operation storing data in the DHT. + * + * @param handle handle to DHT service + * @param key the key to store under + * @param desired_replication_level estimate of how many + * nearest peers this request should reach + * @param options routing options for this message + * @param type type of the value + * @param size number of bytes in data; must be less than 64k + * @param data the data to store + * @param exp desired expiration time for the value + * @param timeout how long to wait for transmission of this request + * @param cont continuation to call when done (transmitting request to service) + * @param cont_cls closure for cont + */ +void +GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const GNUNET_HashCode * key, + uint32_t desired_replication_level, + enum GNUNET_DHT_RouteOption options, + enum GNUNET_BLOCK_Type type, size_t size, const char *data, + struct GNUNET_TIME_Absolute exp, + struct GNUNET_TIME_Relative timeout, GNUNET_SCHEDULER_Task cont, + void *cont_cls); + + +/** + * Iterator called on each result obtained for a DHT + * operation that expects a reply + * + * @param cls closure + * @param exp when will this value expire + * @param key key of the result + * @param get_path peers on reply path (or NULL if not recorded) + * @param get_path_length number of entries in get_path + * @param put_path peers on the PUT path (or NULL if not recorded) + * @param put_path_length number of entries in get_path + * @param type type of the result + * @param size number of bytes in data + * @param data pointer to the result data + */ +typedef void (*GNUNET_DHT_GetIterator) (void *cls, + struct GNUNET_TIME_Absolute exp, + const GNUNET_HashCode * key, + const struct GNUNET_PeerIdentity * + get_path, unsigned int get_path_length, + const struct GNUNET_PeerIdentity * + put_path, unsigned int put_path_length, + enum GNUNET_BLOCK_Type type, + size_t size, const void *data); + + + +/** + * Perform an asynchronous GET operation on the DHT identified. See + * also "GNUNET_BLOCK_evaluate". + * + * @param handle handle to the DHT service + * @param timeout how long to wait for transmission of this request to the service + * @param type expected type of the response object + * @param key the key to look up + * @param desired_replication_level estimate of how many + nearest peers this request should reach + * @param options routing options for this message + * @param xquery extended query data (can be NULL, depending on type) + * @param xquery_size number of bytes in xquery + * @param iter function to call on each result + * @param iter_cls closure for iter + * + * @return handle to stop the async get + */ +struct GNUNET_DHT_GetHandle * +GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, + struct GNUNET_TIME_Relative timeout, + enum GNUNET_BLOCK_Type type, const 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); + + +/** + * Stop async DHT-get. Frees associated resources. + * + * @param get_handle GET operation to stop. + * + * On return get_handle will no longer be valid, caller + * must not use again!!! + */ +void +GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle); + + +/* *************** Extended API: monitor ******************* */ + +struct GNUNET_DHT_MonitorHandle; + +/** + * Callback called on each request going through the DHT. + * + * @param cls Closure. + * @param mtype Type of the DHT message monitored. + * @param exp When will this value expire. + * @param key Key of the result/request. + * @param get_path Peers on reply path (or NULL if not recorded). + * @param get_path_length number of entries in get_path. + * @param put_path peers on the PUT path (or NULL if not recorded). + * @param put_path_length number of entries in get_path. + * @param desired_replication_level Desired replication level. + * @param type Type of the result/request. + * @param data Pointer to the result data. + * @param size Number of bytes in data. + */ +typedef void (*GNUNET_DHT_MonitorCB) (void *cls, + uint16_t mtype, + struct GNUNET_TIME_Absolute exp, + const GNUNET_HashCode * key, + const struct GNUNET_PeerIdentity * + get_path, unsigned int get_path_length, + const struct GNUNET_PeerIdentity * + put_path, unsigned int put_path_length, + uint32_t desired_replication_level, + enum GNUNET_DHT_RouteOption options, + enum GNUNET_BLOCK_Type type, + const void *data, + size_t size); + +/** + * Start monitoring the local DHT service. + * + * @param handle Handle to the DHT service. + * @param type Type of blocks that are of interest. + * @param key Key of data of interest, NULL for all. + * @param cb Callback to process all monitored data. + * @param cb_cls Closure for cb. + * + * @return Handle to stop monitoring. + */ +struct GNUNET_DHT_MonitorHandle * +GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle, + enum GNUNET_BLOCK_Type type, + const GNUNET_HashCode *key, + GNUNET_DHT_MonitorCB cb, + void *cb_cls); + + +/** + * Stop monitoring. + * + * @param handle The handle to the monitor request returned by monitor_start. + * + * On return handle will no longer be valid, caller must not use again!!! + */ +void +GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + +#endif +/* gnunet_dht_service.h */ diff --git a/src/include/gnunet_directories.h.in b/src/include/gnunet_directories.h.in new file mode 100644 index 0000000..3f6898a --- /dev/null +++ b/src/include/gnunet_directories.h.in @@ -0,0 +1,33 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006 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/gnunet_directories.h + * @brief directories and files in GNUnet (default locations) + * + * @author Christian Grothoff + */ + +#ifndef GNUNET_DIRECTORIES +#define GNUNET_DIRECTORIES + +#define GNUNET_DEFAULT_USER_CONFIG_FILE "@GN_USER_HOME_DIR@/gnunet.conf" + +#endif diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h new file mode 100644 index 0000000..18f5535 --- /dev/null +++ b/src/include/gnunet_disk_lib.h @@ -0,0 +1,768 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_disk_lib.h + * @brief disk IO apis + */ +#ifndef GNUNET_DISK_LIB_H +#define GNUNET_DISK_LIB_H + +#if WINDOWS +#define OFF_T uint64_t +#else +#define OFF_T off_t +#endif + +/** + * Handle used to manage a pipe. + */ +struct GNUNET_DISK_PipeHandle; + + +enum GNUNET_FILE_Type +{ + GNUNET_DISK_FILE, GNUNET_PIPE +}; + +/** + * Handle used to access files (and pipes). + */ +struct GNUNET_DISK_FileHandle +{ + +#if WINDOWS + /** + * File handle under W32. + */ + HANDLE h; + + /** + * Type + */ + enum GNUNET_FILE_Type type; + + /** + * Structure for overlapped reading (for pipes) + */ + OVERLAPPED *oOverlapRead; + + /** + * Structure for overlapped writing (for pipes) + */ + OVERLAPPED *oOverlapWrite; +#else + + /** + * File handle on other OSes. + */ + int fd; + +#endif /* + */ +}; + + +/* we need size_t, and since it can be both unsigned int + or unsigned long long, this IS platform dependent; + but "stdlib.h" should be portable 'enough' to be + unconditionally available... */ +#include <stdlib.h> +#include "gnunet_configuration_lib.h" +#include "gnunet_scheduler_lib.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * Specifies how a file should be opened. + */ +enum GNUNET_DISK_OpenFlags +{ + + /** + * Open the file for reading + */ + GNUNET_DISK_OPEN_READ = 1, + + /** + * Open the file for writing + */ + GNUNET_DISK_OPEN_WRITE = 2, + + /** + * Open the file for both reading and writing + */ + GNUNET_DISK_OPEN_READWRITE = 3, + + /** + * Fail if file already exists + */ + GNUNET_DISK_OPEN_FAILIFEXISTS = 4, + + /** + * Truncate file if it exists + */ + GNUNET_DISK_OPEN_TRUNCATE = 8, + + /** + * Create file if it doesn't exist + */ + GNUNET_DISK_OPEN_CREATE = 16, + + /** + * Append to the file + */ + GNUNET_DISK_OPEN_APPEND = 32 +}; + +/** + * Specifies what type of memory map is desired. + */ +enum GNUNET_DISK_MapType +{ + /** + * Read-only memory map. + */ + GNUNET_DISK_MAP_TYPE_READ = 1, + + /** + * Write-able memory map. + */ + GNUNET_DISK_MAP_TYPE_WRITE = 2, + /** + * Read-write memory map. + */ + GNUNET_DISK_MAP_TYPE_READWRITE = 3 +}; + + +/** + * File access permissions, UNIX-style. + */ +enum GNUNET_DISK_AccessPermissions +{ + /** + * Nobody is allowed to do anything to the file. + */ + GNUNET_DISK_PERM_NONE = 0, + + /** + * Owner can read. + */ + GNUNET_DISK_PERM_USER_READ = 1, + + /** + * Owner can write. + */ + GNUNET_DISK_PERM_USER_WRITE = 2, + + /** + * Owner can execute. + */ + GNUNET_DISK_PERM_USER_EXEC = 4, + + /** + * Group can read. + */ + GNUNET_DISK_PERM_GROUP_READ = 8, + + /** + * Group can write. + */ + GNUNET_DISK_PERM_GROUP_WRITE = 16, + + /** + * Group can execute. + */ + GNUNET_DISK_PERM_GROUP_EXEC = 32, + + /** + * Everybody can read. + */ + GNUNET_DISK_PERM_OTHER_READ = 64, + + /** + * Everybody can write. + */ + GNUNET_DISK_PERM_OTHER_WRITE = 128, + + /** + * Everybody can execute. + */ + GNUNET_DISK_PERM_OTHER_EXEC = 256 +}; + + +/** + * Constants for specifying how to seek. + */ +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 +}; + + +/** + * Enumeration identifying the two ends of a pipe. + */ +enum GNUNET_DISK_PipeEnd +{ + /** + * The reading-end of a pipe. + */ + GNUNET_DISK_PIPE_END_READ = 0, + + /** + * The writing-end of a pipe. + */ + GNUNET_DISK_PIPE_END_WRITE = 1 +}; + + +/** + * Get the number of blocks that are left on the partition that + * contains the given file (for normal users). + * + * @param part a file on the partition to check + * @return -1 on errors, otherwise the number of free blocks + */ +long +GNUNET_DISK_get_blocks_available (const char *part); + + +/** + * Checks whether a handle is invalid + * + * @param h handle to check + * @return GNUNET_YES if invalid, GNUNET_NO if valid + */ +int +GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h); + + +/** + * Check that fil corresponds to a filename + * (of a file that exists and that is not a directory). + * + * @param fil filename to check + * @return GNUNET_YES if yes, GNUNET_NO if not a file, GNUNET_SYSERR if something + * else (will print an error message in that case, too). + */ +int +GNUNET_DISK_file_test (const char *fil); + + +/** + * Move the read/write pointer in a file + * @param h handle of an open file + * @param offset position to move to + * @param whence specification to which position the offset parameter relates to + * @return the new position on success, GNUNET_SYSERR otherwise + */ +OFF_T +GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, OFF_T offset, + enum GNUNET_DISK_Seek whence); + + +/** + * Get the size of the file (or directory) + * of the given file (in bytes). + * + * @param filename name of the file or directory + * @param size set to the size of the file (or, + * in the case of directories, the sum + * of all sizes of files in the directory) + * @param includeSymLinks should symbolic links be + * included? + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_DISK_file_size (const char *filename, uint64_t * size, + int includeSymLinks); + + +/** + * Obtain some unique identifiers for the given file + * that can be used to identify it in the local system. + * This function is used between GNUnet processes to + * quickly check if two files with the same absolute path + * are actually identical. The two processes represent + * the same peer but may communicate over the network + * (and the file may be on an NFS volume). This function + * may not be supported on all operating systems. + * + * @param filename name of the file + * @param dev set to the device ID + * @param ino set to the inode ID + * @return GNUNET_OK on success + */ +int +GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t * dev, + uint64_t * ino); + + +/** + * Create an (empty) temporary file 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 + * filename. + * + * @param t component to use for the name; + * does NOT contain "XXXXXX" or "/tmp/". + * @return NULL on error, otherwise name of fresh + * file on disk in directory for temporary files + */ +char * +GNUNET_DISK_mktemp (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. + * + * @param fn file name to be opened + * @param flags opening flags, a combination of GNUNET_DISK_OPEN_xxx bit flags + * @param perm permissions for the newly created file, use + * GNUNET_DISK_PERM_NONE if a file could not be created by this + * call (because of flags) + * @return IO handle on success, NULL on error + */ +struct GNUNET_DISK_FileHandle * +GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, + enum GNUNET_DISK_AccessPermissions perm); + + +/** + * Get the size of an open file. + * + * @param fh open file handle + * @param size where to write size of the file + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, + OFF_T *size); + + +/** + * Creates an interprocess channel + * + * @param blocking_read creates an asynchronous pipe for reading if set to GNUNET_NO + * @param blocking_write creates an asynchronous pipe for writing if set to GNUNET_NO + * @param inherit_read 1 to make read handle inheritable, 0 otherwise (NT only) + * @param inherit_write 1 to make write handle inheritable, 0 otherwise (NT only) + * @return handle to the new pipe, NULL on error + */ +struct GNUNET_DISK_PipeHandle * +GNUNET_DISK_pipe (int blocking_read, int blocking_write, int inherit_read, int inherit_write); + + +/** + * Creates a pipe object from a couple of file descriptors. + * Useful for wrapping existing pipe FDs. + * + * @param blocking_read creates an asynchronous pipe for reading if set to GNUNET_NO + * @param blocking_write creates an asynchronous pipe for writing if set to GNUNET_NO + * @param fd an array of two fd values. One of them may be -1 for read-only or write-only pipes + * + * @return handle to the new pipe, NULL on error + */ +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 + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p); + +/** + * Closes one half of an interprocess channel + * + * @param p pipe to close end of + * @param end which end of the pipe to close + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, + enum GNUNET_DISK_PipeEnd end); + +/** + * Close an open file. + * + * @param h file handle + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h); + + +/** + * Get the handle to a particular pipe end + * + * @param p pipe + * @param n end to access + * @return handle for the respective end + */ +const struct GNUNET_DISK_FileHandle * +GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, + enum GNUNET_DISK_PipeEnd n); + +/** + * Read the contents of a binary file into a buffer. + * @param h handle to an open file + * @param result the buffer to write the result to + * @param len the maximum number of bytes to read + * @return the number of bytes read on success, GNUNET_SYSERR on failure + */ +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 + * when no data can be read). + * + * @param h handle to an open file + * @param result the buffer to write the result to + * @param len the maximum number of bytes to read + * @return the number of bytes read on success, GNUNET_SYSERR on failure + */ +ssize_t +GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle * h, + void *result, size_t len); + +/** + * Read the contents of a binary file into a buffer. + * + * @param fn file name + * @param result the buffer to write the result to + * @param len the maximum number of bytes to read + * @return number of bytes read, GNUNET_SYSERR on failure + */ +ssize_t +GNUNET_DISK_fn_read (const char *fn, void *result, size_t len); + + +/** + * Write a buffer to a file. + * + * @param h handle to open file + * @param buffer the data to write + * @param n number of bytes to write + * @return number of bytes written on success, GNUNET_SYSERR on error + */ +ssize_t +GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, + const void *buffer, size_t n); + + +/** + * Write a buffer to a file, blocking, if necessary. + * @param h handle to open file + * @param buffer the data to write + * @param n number of bytes to write + * @return number of bytes written on success, GNUNET_SYSERR on error + */ +ssize_t +GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h, + const void *buffer, size_t n); + +/** + * Write a buffer to a file. If the file is longer than + * the given buffer size, it will be truncated. + * + * @param fn file name + * @param buffer the data to write + * @param n number of bytes to write + * @param mode file permissions + * @return number of bytes written on success, GNUNET_SYSERR on error + */ +ssize_t +GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n, + enum GNUNET_DISK_AccessPermissions mode); + + +/** + * Copy a file. + * + * @param src file to copy + * @param dst destination file name + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_DISK_file_copy (const char *src, const char *dst); + + +/** + * Scan a directory for files. + * + * @param dirName the name of the directory + * @param callback the method to call for each file + * @param callback_cls closure for callback + * @return the number of files found, -1 on error + */ +int +GNUNET_DISK_directory_scan (const char *dirName, + GNUNET_FileNameCallback callback, + void *callback_cls); + + +/** + * Opaque handle used for iterating over a directory. + */ +struct GNUNET_DISK_DirectoryIterator; + + +/** + * Function called to iterate over a directory. + * + * @param cls closure + * @param di argument to pass to "GNUNET_DISK_directory_iterator_next" to + * get called on the next entry (or finish cleanly); + * NULL on error (will be the last call in that case) + * @param filename complete filename (absolute path) + * @param dirname directory name (absolute path) + */ +typedef void (*GNUNET_DISK_DirectoryIteratorCallback) (void *cls, + struct + GNUNET_DISK_DirectoryIterator + * di, + const char *filename, + const char *dirname); + + +/** + * This function must be called during the DiskIteratorCallback + * (exactly once) to schedule the task to process the next + * filename in the directory (if there is one). + * + * @param iter opaque handle for the iterator + * @param can set to GNUNET_YES to terminate the iteration early + * @return GNUNET_YES if iteration will continue, + * GNUNET_NO if this was the last entry (and iteration is complete), + * GNUNET_SYSERR if "can" was YES + */ +int +GNUNET_DISK_directory_iterator_next (struct GNUNET_DISK_DirectoryIterator *iter, + int can); + + +/** + * Scan a directory for files using the scheduler to run a task for + * each entry. The name of the directory must be expanded first (!). + * If a scheduler does not need to be used, GNUNET_DISK_directory_scan + * may provide a simpler API. + * + * @param prio priority to use + * @param dirName the name of the directory + * @param callback the method to call for each file + * @param callback_cls closure for callback + * @return GNUNET_YES if directory is not empty and 'callback' + * will be called later, GNUNET_NO otherwise, GNUNET_SYSERR on error. + */ +int +GNUNET_DISK_directory_iterator_start (enum GNUNET_SCHEDULER_Priority prio, + const char *dirName, + GNUNET_DISK_DirectoryIteratorCallback + callback, void *callback_cls); + + +/** + * Create the directory structure for storing + * a file. + * + * @param filename name of a file in the directory + * @returns GNUNET_OK on success, GNUNET_SYSERR on failure, + * GNUNET_NO if directory exists but is not writeable + */ +int +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. + * + * @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 + */ +int +GNUNET_DISK_directory_test (const char *fil); + + +/** + * Remove all files in a directory (rm -rf). Call with + * caution. + * + * @param fileName the file to remove + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_DISK_directory_remove (const char *fileName); + + +/** + * Implementation of "mkdir -p" + * + * @param dir the directory to create + * @returns GNUNET_SYSERR on failure, GNUNET_OK otherwise + */ +int +GNUNET_DISK_directory_create (const char *dir); + + +/** + * Lock a part of a file. + * + * @param fh file handle + * @param lockStart absolute position from where to lock + * @param lockEnd absolute position until where to lock + * @param excl GNUNET_YES for an exclusive lock + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, OFF_T lockStart, + OFF_T lockEnd, int excl); + + +/** + * Unlock a part of a file + * @param fh file handle + * @param unlockStart absolute position from where to unlock + * @param unlockEnd absolute position until where to unlock + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, OFF_T unlockStart, + OFF_T unlockEnd); + + +/** + * @brief Removes special characters as ':' from a filename. + * @param fn the filename to canonicalize + */ +void +GNUNET_DISK_filename_canonicalize (char *fn); + + +/** + * @brief Change owner of a file + * @param filename file to change + * @param user new owner of the file + * @return GNUNET_OK on success, GNUNET_SYSERR on failure + */ +int +GNUNET_DISK_file_change_owner (const char *filename, const char *user); + + +/** + * Construct full path to a file inside of the private + * directory used by GNUnet. Also creates the corresponding + * directory. If the resulting name is supposed to be + * a directory, end the last argument in '/' (or pass + * DIR_SEPARATOR_STR as the last argument before NULL). + * + * @param cfg configuration to use + * @param serviceName name of the service asking + * @param ... is NULL-terminated list of + * path components to append to the + * private directory name. + * @return the constructed filename + */ +char * +GNUNET_DISK_get_home_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *serviceName, ...); + + +/** + * Opaque handle for a memory-mapping operation. + */ +struct GNUNET_DISK_MapHandle; + +/** + * Map a file into memory + * @param h open file handle + * @param m handle to the new mapping (will be set) + * @param access access specification, GNUNET_DISK_MAP_TYPE_xxx + * @param len size of the mapping + * @return pointer to the mapped memory region, NULL on failure + */ +void * +GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, + struct GNUNET_DISK_MapHandle **m, + enum GNUNET_DISK_MapType access, size_t len); + +/** + * Unmap a file + * + * @param h mapping handle + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h); + +/** + * Write file changes to disk + * @param h handle to an open file + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + +/* ifndef GNUNET_DISK_LIB_H */ +#endif +/* end of gnunet_disk_lib.h */ diff --git a/src/include/gnunet_dns_service.h b/src/include/gnunet_dns_service.h new file mode 100644 index 0000000..a822b06 --- /dev/null +++ b/src/include/gnunet_dns_service.h @@ -0,0 +1,186 @@ +/* + 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/gnunet_dns_service.h + * @brief API to access the DNS service. + * @author Christian Grothoff + */ +#ifndef GNUNET_DNS_SERVICE_NEW_H +#define GNUNET_DNS_SERVICE_NEW_H + +#include "gnunet_common.h" +#include "gnunet_util_lib.h" + + +/** + * Opaque DNS handle + */ +struct GNUNET_DNS_Handle; + +/** + * Handle to identify an individual DNS request. + */ +struct GNUNET_DNS_RequestHandle; + +/** + * Flags that specify when to call the client's handler. + */ +enum GNUNET_DNS_Flags +{ + + /** + * Useless option: never call the client. + */ + GNUNET_DNS_FLAG_NEVER = 0, + + /** + * Set this flag to see all requests first prior to resolution + * (for monitoring). Clients that set this flag must then + * call "GNUNET_DNS_request_forward" when they process a request + * for the first time. Caling "GNUNET_DNS_request_answer" is + * not allowed for MONITOR peers. + */ + GNUNET_DNS_FLAG_REQUEST_MONITOR = 1, + + /** + * This client should be called on requests that have not + * yet been resolved as this client provides a resolution + * service. Note that this does not guarantee that the + * client will see all requests as another client might be + * called first and that client might have already done the + * resolution, in which case other pre-resolution clients + * won't see the request anymore. + */ + GNUNET_DNS_FLAG_PRE_RESOLUTION = 2, + + /** + * This client wants to be called on the results of a DNS resolution + * (either resolved by PRE-RESOLUTION clients or the global DNS). + * The client then has a chance to modify the answer (or cause it to + * be dropped). There is no guarantee that other POST-RESOLUTION + * client's won't modify (or drop) the answer afterwards. + */ + GNUNET_DNS_FLAG_POST_RESOLUTION = 4, + + /** + * Set this flag to see all requests just before they are + * returned to the network. Clients that set this flag must then + * call "GNUNET_DNS_request_forward" when they process a request + * for the last time. Caling "GNUNET_DNS_request_answer" is + * not allowed for MONITOR peers. + */ + GNUNET_DNS_FLAG_RESPONSE_MONITOR = 8 + +}; + + + +/** + * Signature of a function that is called whenever the DNS service + * encounters a DNS request and needs to do something with it. The + * function has then the chance to generate or modify the response by + * calling one of the three "GNUNET_DNS_request_*" continuations. + * + * When a request is intercepted, this function is called first to + * give the client a chance to do the complete address resolution; + * "rdata" will be NULL for this first call for a DNS request, unless + * some other client has already filled in a response. + * + * If multiple clients exist, all of them are called before the global + * DNS. The global DNS is only called if all of the clients' + * functions call GNUNET_DNS_request_forward. Functions that call + * GNUNET_DNS_request_forward will be called again before a final + * response is returned to the application. If any of the clients' + * functions call GNUNET_DNS_request_drop, the response is dropped. + * + * @param cls closure + * @param rh request handle to user for reply + * @param request_length number of bytes in request + * @param request udp payload of the DNS request + */ +typedef void (*GNUNET_DNS_RequestHandler)(void *cls, + struct GNUNET_DNS_RequestHandle *rh, + size_t request_length, + const char *request); + + +/** + * If a GNUNET_DNS_RequestHandler calls this function, the client + * has no desire to interfer with the request and it should + * continue to be processed normally. + * + * @param rh request that should now be forwarded + */ +void +GNUNET_DNS_request_forward (struct GNUNET_DNS_RequestHandle *rh); + + +/** + * If a GNUNET_DNS_RequestHandler calls this function, the request is + * to be dropped and no response should be generated. + * + * @param rh request that should now be dropped + */ +void +GNUNET_DNS_request_drop (struct GNUNET_DNS_RequestHandle *rh); + + +/** + * If a GNUNET_DNS_RequestHandler calls this function, the request is + * supposed to be answered with the data provided to this call (with + * the modifications the function might have made). The reply given + * must always be a valid DNS reply and not a mutated DNS request. + * + * @param rh request that should now be answered + * @param reply_length size of reply (uint16_t to force sane size) + * @param reply reply data + */ +void +GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh, + uint16_t reply_length, + const char *reply); + + +/** + * Connect to the service-dns + * + * @param cfg configuration to use + * @param flags when to call rh + * @param rh function to call with DNS requests + * @param rh_cls closure to pass to rh + * @return DNS handle + */ +struct GNUNET_DNS_Handle * +GNUNET_DNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + enum GNUNET_DNS_Flags flags, + GNUNET_DNS_RequestHandler rh, + void *rh_cls); + + +/** + * Disconnect from the DNS service. + * + * @param dh DNS handle + */ +void +GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *dh); + +#endif diff --git a/src/include/gnunet_dnsparser_lib.h b/src/include/gnunet_dnsparser_lib.h new file mode 100644 index 0000000..0c310ba --- /dev/null +++ b/src/include/gnunet_dnsparser_lib.h @@ -0,0 +1,397 @@ +/* + This file is part of GNUnet + (C) 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 + 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/gnunet_dnsparser_lib.h + * @brief API for helper library to parse DNS packets. + * @author Philipp Toelke + * @author Christian Grothoff + */ +#ifndef GNUNET_DNSPARSER_LIB_H +#define GNUNET_DNSPARSER_LIB_H + +#include "platform.h" +#include "gnunet_common.h" + +/** + * A few common DNS types. + */ +#define GNUNET_DNSPARSER_TYPE_A 1 +#define GNUNET_DNSPARSER_TYPE_NS 2 +#define GNUNET_DNSPARSER_TYPE_CNAME 5 +#define GNUNET_DNSPARSER_TYPE_SOA 6 +#define GNUNET_DNSPARSER_TYPE_PTR 12 +#define GNUNET_DNSPARSER_TYPE_MX 15 +#define GNUNET_DNSPARSER_TYPE_TXT 16 +#define GNUNET_DNSPARSER_TYPE_AAAA 28 + +/** + * A few common DNS classes (ok, only one is common, but I list a + * couple more to make it clear what we're talking about here). + */ +#define GNUNET_DNSPARSER_CLASS_INTERNET 1 +#define GNUNET_DNSPARSER_CLASS_CHAOS 3 +#define GNUNET_DNSPARSER_CLASS_HESIOD 4 + +#define GNUNET_DNSPARSER_OPCODE_QUERY 0 +#define GNUNET_DNSPARSER_OPCODE_INVERSE_QUERY 1 +#define GNUNET_DNSPARSER_OPCODE_STATUS 2 + +/** + * RFC 1035 codes. + */ +#define GNUNET_DNSPARSER_RETURN_CODE_NO_ERROR 0 +#define GNUNET_DNSPARSER_RETURN_CODE_FORMAT_ERROR 1 +#define GNUNET_DNSPARSER_RETURN_CODE_SERVER_FAILURE 2 +#define GNUNET_DNSPARSER_RETURN_CODE_NAME_ERROR 3 +#define GNUNET_DNSPARSER_RETURN_CODE_NOT_IMPLEMENTED 4 +#define GNUNET_DNSPARSER_RETURN_CODE_REFUSED 5 + +/** + * RFC 2136 codes + */ +#define GNUNET_DNSPARSER_RETURN_CODE_YXDOMAIN 6 +#define GNUNET_DNSPARSER_RETURN_CODE_YXRRSET 7 +#define GNUNET_DNSPARSER_RETURN_CODE_NXRRSET 8 +#define GNUNET_DNSPARSER_RETURN_CODE_NOT_AUTH 9 +#define GNUNET_DNSPARSER_RETURN_CODE_NOT_ZONE 10 + +/** + * DNS flags (largely RFC 1035 / RFC 2136). + */ +struct GNUNET_DNSPARSER_Flags +{ + /** + * Set to 1 if recursion is desired (client -> server) + */ + unsigned int recursion_desired : 1 GNUNET_PACKED; + + /** + * Set to 1 if message is truncated + */ + unsigned int message_truncated : 1 GNUNET_PACKED; + + /** + * Set to 1 if this is an authoritative answer + */ + unsigned int authoritative_answer : 1 GNUNET_PACKED; + + /** + * See GNUNET_DNSPARSER_OPCODE_ defines. + */ + unsigned int opcode : 4 GNUNET_PACKED; + + /** + * query:0, response:1 + */ + unsigned int query_or_response : 1 GNUNET_PACKED; + + /** + * See GNUNET_DNSPARSER_RETURN_CODE_ defines. + */ + unsigned int return_code : 4 GNUNET_PACKED; + + /** + * See RFC 4035. + */ + unsigned int checking_disabled : 1 GNUNET_PACKED; + + /** + * Response has been cryptographically verified, RFC 4035. + */ + unsigned int authenticated_data : 1 GNUNET_PACKED; + + /** + * Always zero. + */ + unsigned int zero : 1 GNUNET_PACKED; + + /** + * Set to 1 if recursion is available (server -> client) + */ + unsigned int recursion_available : 1 GNUNET_PACKED; + +}; + + +/** + * A DNS query. + */ +struct GNUNET_DNSPARSER_Query +{ + + /** + * Name of the record that the query is for (0-terminated). + */ + char *name; + + /** + * See GNUNET_DNSPARSER_TYPE_*. + */ + uint16_t type; + + /** + * See GNUNET_DNSPARSER_CLASS_*. + */ + uint16_t class; + +}; + + +/** + * Information from MX records (RFC 1035). + */ +struct GNUNET_DNSPARSER_MxRecord +{ + + /** + * Preference for this entry (lower value is higher preference). + */ + uint16_t preference; + + /** + * Name of the mail server. + */ + char *mxhost; + +}; + + +/** + * Information from SOA records (RFC 1035). + */ +struct GNUNET_DNSPARSER_SoaRecord +{ + + /** + *The domainname of the name server that was the + * original or primary source of data for this zone. + */ + char *mname; + + /** + * A domainname which specifies the mailbox of the + * person responsible for this zone. + */ + char *rname; + + /** + * The version number of the original copy of the zone. + */ + uint32_t serial; + + /** + * Time interval before the zone should be refreshed. + */ + uint32_t refresh; + + /** + * Time interval that should elapse before a failed refresh should + * be retried. + */ + uint32_t retry; + + /** + * Time value that specifies the upper limit on the time interval + * that can elapse before the zone is no longer authoritative. + */ + uint32_t expire; + + /** + * The bit minimum TTL field that should be exported with any RR + * from this zone. + */ + uint32_t minimum_ttl; + +}; + + +/** + * Binary record information (unparsed). + */ +struct GNUNET_DNSPARSER_RawRecord +{ + + /** + * Binary record data. + */ + void *data; + + /** + * Number of bytes in data. + */ + size_t data_len; +}; + + +/** + * A DNS response record. + */ +struct GNUNET_DNSPARSER_Record +{ + + /** + * Name of the record that the query is for (0-terminated). + */ + char *name; + + union + { + + /** + * For NS, CNAME and PTR records, this is the uncompressed 0-terminated hostname. + */ + char *hostname; + + /** + * SOA data for SOA records. + */ + struct GNUNET_DNSPARSER_SoaRecord *soa; + + /** + * MX data for MX records. + */ + struct GNUNET_DNSPARSER_MxRecord *mx; + + /** + * Raw data for all other types. + */ + struct GNUNET_DNSPARSER_RawRecord raw; + + } data; + + + /** + * When does the record expire? + */ + struct GNUNET_TIME_Absolute expiration_time; + + /** + * See GNUNET_DNSPARSER_TYPE_*. + */ + uint16_t type; + + /** + * See GNUNET_DNSPARSER_CLASS_*. + */ + uint16_t class; + +}; + + +/** + * Easy-to-process, parsed version of a DNS packet. + */ +struct GNUNET_DNSPARSER_Packet +{ + /** + * Array of all queries in the packet, must contain "num_queries" entries. + */ + struct GNUNET_DNSPARSER_Query *queries; + + /** + * Array of all answers in the packet, must contain "num_answers" entries. + */ + struct GNUNET_DNSPARSER_Record *answers; + + /** + * Array of all authority records in the packet, must contain "num_authority_records" entries. + */ + struct GNUNET_DNSPARSER_Record *authority_records; + + /** + * Array of all additional answers in the packet, must contain "num_additional_records" entries. + */ + struct GNUNET_DNSPARSER_Record *additional_records; + + /** + * Number of queries in the packet. + */ + unsigned int num_queries; + + /** + * Number of answers in the packet, should be 0 for queries. + */ + unsigned int num_answers; + + /** + * Number of authoritative answers in the packet, should be 0 for queries. + */ + unsigned int num_authority_records; + + /** + * Number of additional records in the packet, should be 0 for queries. + */ + unsigned int num_additional_records; + + /** + * Bitfield of DNS flags. + */ + struct GNUNET_DNSPARSER_Flags flags; + + /** + * DNS ID (to match replies to requests). + */ + uint16_t id; + +}; + + +/** + * Parse a UDP payload of a DNS packet in to a nice struct for further + * processing and manipulation. + * + * @param udp_payload wire-format of the DNS packet + * @param udp_payload_length number of bytes in udp_payload + * @return NULL on error, otherwise the parsed packet + */ +struct GNUNET_DNSPARSER_Packet * +GNUNET_DNSPARSER_parse (const char *udp_payload, + size_t udp_payload_length); + + +/** + * Free memory taken by a packet. + * + * @param p packet to free + */ +void +GNUNET_DNSPARSER_free_packet (struct GNUNET_DNSPARSER_Packet *p); + + +/** + * Given a DNS packet, generate the corresponding UDP payload. + * + * @param p packet to pack + * @param max maximum allowed size for the resulting UDP payload + * @param buf set to a buffer with the packed message + * @param buf_length set to the length of buf + * @return GNUNET_SYSERR if 'p' is invalid + * GNUNET_NO if 'p' was truncated (but there is still a result in 'buf') + * GNUNET_OK if 'p' was packed completely into '*buf' + */ +int +GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p, + uint16_t max, + char **buf, + size_t *buf_length); + + +#endif diff --git a/src/include/gnunet_dv_service.h b/src/include/gnunet_dv_service.h new file mode 100644 index 0000000..3454ebc --- /dev/null +++ b/src/include/gnunet_dv_service.h @@ -0,0 +1,88 @@ +/* + This file is part of GNUnet + (C) 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +/** + * @file include/gnunet_dv_service.h + * @brief API to deal with dv service + * + * @author Christian Grothoff + * @author Nathan Evans + */ + +#ifndef GNUNET_DV_SERVICE_H +#define GNUNET_DV_SERVICE_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" +#include "gnunet_configuration_lib.h" +#include "gnunet_scheduler_lib.h" +#include "gnunet_transport_plugin.h" + +/** + * Version of the dv API. + */ +#define GNUNET_DV_VERSION 0x00000000 + +/** + * Opaque handle for the dv service. + */ +struct GNUNET_DV_Handle; + +/** + * Send a message from the plugin to the DV service indicating that + * a message should be sent via DV to some peer. + * + * @param dv_handle the handle to the DV api + * @param target the final target of the message + * @param msgbuf the msg(s) to send + * @param msgbuf_size the size of msgbuf + * @param priority priority to pass on to core when sending the message + * @param timeout how long can this message be delayed (pass through to core) + * @param addr the address of this peer (internally known to DV) + * @param addrlen the length of the peer address + * @param cont continuation to call once the message has been sent (or failed) + * @param cont_cls closure for continuation + * + */ +int +GNUNET_DV_send (struct GNUNET_DV_Handle *dv_handle, + const struct GNUNET_PeerIdentity *target, const char *msgbuf, + size_t msgbuf_size, unsigned int priority, + struct GNUNET_TIME_Relative timeout, const void *addr, + size_t addrlen, GNUNET_TRANSPORT_TransmitContinuation cont, + void *cont_cls); + + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/gnunet_fragmentation_lib.h b/src/include/gnunet_fragmentation_lib.h new file mode 100644 index 0000000..a953bd2 --- /dev/null +++ b/src/include/gnunet_fragmentation_lib.h @@ -0,0 +1,203 @@ +/* + This file is part of GNUnet + (C) 2009, 2011 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_fragmentation_lib.h + * @brief library to help fragment messages + * @author Christian Grothoff + * + * TODO: consider additional flow-control for sending from + * fragmentation based on continuations. + */ + +#ifndef GNUNET_FRAGMENTATION_LIB_H +#define GNUNET_FRAGMENTATION_LIB_H + +#include "gnunet_util_lib.h" +#include "gnunet_bandwidth_lib.h" +#include "gnunet_statistics_service.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * Fragmentation context. + */ +struct GNUNET_FRAGMENT_Context; + + +/** + * Function that is called with messages created by the fragmentation + * module. In the case of the 'proc' callback of the + * GNUNET_FRAGMENT_context_create function, this function must + * eventually call 'GNUNET_FRAGMENT_context_transmission_done'. + * + * @param cls closure + * @param msg the message that was created + */ +typedef void (*GNUNET_FRAGMENT_MessageProcessor) (void *cls, + const struct + GNUNET_MessageHeader * msg); + + +/** + * Create a fragmentation context for the given message. + * Fragments the message into fragments of size "mtu" or + * less. Calls 'proc' on each un-acknowledged fragment, + * using both the expected 'delay' between messages and + * acknowledgements and the given 'tracker' to guide the + * frequency of calls to 'proc'. + * + * @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 + * and ACK based on previous messages + * @param msg the message to fragment + * @param proc function to call for each fragment to transmit + * @param proc_cls closure for proc + * @return the fragmentation context + */ +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, + const struct GNUNET_MessageHeader *msg, + GNUNET_FRAGMENT_MessageProcessor proc, + void *proc_cls); + + +/** + * Continuation to call from the 'proc' function after the fragment + * has been transmitted (and hence the next fragment can now be + * given to proc). + * + * @param fc fragmentation context + */ +void +GNUNET_FRAGMENT_context_transmission_done (struct GNUNET_FRAGMENT_Context *fc); + + +/** + * Process an acknowledgement message we got from the other + * side (to control re-transmits). + * + * @param fc fragmentation context + * @param msg acknowledgement message we received + * @return GNUNET_OK if this ack completes the work of the 'fc' + * (all fragments have been received); + * GNUNET_NO if more messages are pending + * GNUNET_SYSERR if this ack is not valid for this fc + */ +int +GNUNET_FRAGMENT_process_ack (struct GNUNET_FRAGMENT_Context *fc, + const struct GNUNET_MessageHeader *msg); + + +/** + * Destroy the given fragmentation context (stop calling 'proc', free + * resources). + * + * @param fc fragmentation context + * @return average delay between transmission and ACK for the + * last message, FOREVER if the message was not fully transmitted + */ +struct GNUNET_TIME_Relative +GNUNET_FRAGMENT_context_destroy (struct GNUNET_FRAGMENT_Context *fc); + + +/** + * Defragmentation context (one per connection). + */ +struct GNUNET_DEFRAGMENT_Context; + + +/** + * Function that is called with acknowledgement messages created by + * the fragmentation module. Acknowledgements are cummulative, + * so it is OK to only transmit the 'latest' ack message for the same + * message ID. + * + * @param cls closure + * @param id unique message ID (modulo collisions) + * @param msg the message that was created + */ +typedef void (*GNUNET_DEFRAGMENT_AckProcessor) (void *cls, uint32_t id, + const struct + GNUNET_MessageHeader * msg); + + +/** + * Create a defragmentation context. + * + * @param stats statistics context + * @param mtu the maximum message size for each fragment + * @param num_msgs how many fragmented messages + * to we defragment at most at the same time? + * @param cls closure for proc and ackp + * @param proc function to call with defragmented messages + * @param ackp function to call with acknowledgements (to send + * back to the other side) + * @return the defragmentation context + */ +struct GNUNET_DEFRAGMENT_Context * +GNUNET_DEFRAGMENT_context_create (struct GNUNET_STATISTICS_Handle *stats, + uint16_t mtu, unsigned int num_msgs, + void *cls, + GNUNET_FRAGMENT_MessageProcessor proc, + GNUNET_DEFRAGMENT_AckProcessor ackp); + + +/** + * Destroy the given defragmentation context. + * + * @param dc defragmentation context + */ +void +GNUNET_DEFRAGMENT_context_destroy (struct GNUNET_DEFRAGMENT_Context *dc); + + +/** + * We have received a fragment. Process it. + * + * @param dc the context + * @param msg the message that was received + * @return GNUNET_OK on success, GNUNET_NO if this was a duplicate, GNUNET_SYSERR on error + */ +int +GNUNET_DEFRAGMENT_process_fragment (struct GNUNET_DEFRAGMENT_Context *dc, + const struct GNUNET_MessageHeader *msg); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* end of gnunet_fragmentation_lib.h */ +#endif diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h new file mode 100644 index 0000000..3eb5892 --- /dev/null +++ b/src/include/gnunet_fs_service.h @@ -0,0 +1,2843 @@ +/* + This file is part of GNUnet + (C) 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file include/gnunet_fs_service.h + * @brief API for file-sharing via GNUnet + * @author Christian Grothoff + */ +#ifndef GNUNET_FS_LIB_H +#define GNUNET_FS_LIB_H + +#include "gnunet_util_lib.h" +#include "gnunet_scheduler_lib.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +/** + * Version number of the implementation. + * History: + * + * 1.x.x: initial version with triple GNUNET_hash and merkle tree + * 2.x.x: root node with mime-type, filename and version number + * 2.1.x: combined GNUNET_EC_ContentHashKey/3HASH encoding with 25:1 super-nodes + * 2.2.x: with directories + * 3.0.x: with namespaces + * 3.1.x: with namespace meta-data + * 3.2.x: with collections + * 4.0.x: with expiration, variable meta-data, kblocks + * 4.1.x: with new error and configuration handling + * 5.0.x: with location URIs + * 6.0.0: with support for OR in KSKs + * 6.1.x: with simplified namespace support + * 9.0.0: CPS-style integrated API + * 9.1.1: asynchronous directory scanning + */ +#define GNUNET_FS_VERSION 0x00090102 + + +/* ******************** URI API *********************** */ + +#define GNUNET_FS_URI_PREFIX "gnunet://fs/" +#define GNUNET_FS_URI_KSK_INFIX "ksk/" +#define GNUNET_FS_URI_SKS_INFIX "sks/" +#define GNUNET_FS_URI_CHK_INFIX "chk/" +#define GNUNET_FS_URI_LOC_INFIX "loc/" + + +/** + * A Universal Resource Identifier (URI), opaque. + */ +struct GNUNET_FS_Uri; + +/** + * Iterator over keywords + * + * @param cls closure + * @param keyword the keyword + * @param is_mandatory is the keyword mandatory (in a search) + * @return GNUNET_OK to continue to iterate, GNUNET_SYSERR to abort + */ +typedef int (*GNUNET_FS_KeywordIterator) (void *cls, const char *keyword, + int is_mandatory); + +/** + * Get a unique key from a URI. This is for putting URIs + * into HashMaps. The key may change between FS implementations. + * + * @param uri uri to convert to a unique key + * @param key wherer to store the unique key + */ +void +GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, GNUNET_HashCode * key); + +/** + * Convert a URI to a UTF-8 String. + * + * @param uri uri to convert to a string + * @return the UTF-8 string + */ +char * +GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri); + +/** + * Convert keyword URI to a human readable format + * (i.e. the search query that was used in the first place) + * + * @param uri ksk uri to convert to a string + * @return string with the keywords + */ +char * +GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri); + + +/** + * Add the given keyword to the set of keywords represented by the URI. + * Does nothing if the keyword is already present. + * + * @param uri ksk uri to modify + * @param keyword keyword to add + * @param is_mandatory is this keyword mandatory? + */ +void +GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, const char *keyword, + int is_mandatory); + + +/** + * Remove the given keyword from the set of keywords represented by the URI. + * Does nothing if the keyword is not present. + * + * @param uri ksk uri to modify + * @param keyword keyword to add + */ +void +GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri, + const char *keyword); + + +/** + * Convert a UTF-8 String to a URI. + * + * @param uri string to parse + * @param emsg where to store the parser error message (if any) + * @return NULL on error + */ +struct GNUNET_FS_Uri * +GNUNET_FS_uri_parse (const char *uri, char **emsg); + +/** + * Free URI. + * + * @param uri uri to free + */ +void +GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri); + + +/** + * How many keywords are ANDed in this keyword URI? + * + * @param uri ksk uri to get the number of keywords from + * @return 0 if this is not a keyword URI + */ +unsigned int +GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri); + + +/** + * Iterate over all keywords in this keyword URI. + * + * @param uri ksk uri to get the keywords from + * @param iterator function to call on each keyword + * @param iterator_cls closure for iterator + * @return -1 if this is not a keyword URI, otherwise number of + * keywords iterated over until iterator aborted + */ +int +GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, + GNUNET_FS_KeywordIterator iterator, + void *iterator_cls); + + +/** + * Obtain the identity of the peer offering the data + * + * @param uri the location URI to inspect + * @param peer where to store the identify of the peer (presumably) offering the content + * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK + */ +int +GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri, + struct GNUNET_PeerIdentity *peer); + + +/** + * Obtain the URI of the content itself. + * + * @param uri location URI to get the content URI from + * @return NULL if argument is not a location URI + */ +struct GNUNET_FS_Uri * +GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri); + + +/** + * Obtain the expiration of the LOC URI. + * + * @param uri location URI to get the expiration from + * @return expiration time of the URI + */ +struct GNUNET_TIME_Absolute +GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri); + + +/** + * Construct a location URI (this peer will be used for the location). + * + * @param baseUri content offered by the sender + * @param cfg configuration information (used to find our hostkey) + * @param expiration_time how long will the content be offered? + * @return the location URI, NULL on error + */ +struct GNUNET_FS_Uri * +GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_TIME_Absolute expiration_time); + + +/** + * Merge the sets of keywords from two KSK URIs. + * + * @param u1 first uri + * @param u2 second uri + * @return merged URI, NULL on error + */ +struct GNUNET_FS_Uri * +GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, + const struct GNUNET_FS_Uri *u2); + + +/** + * Duplicate URI. + * + * @param uri the URI to duplicate + * @return copy of the URI + */ +struct GNUNET_FS_Uri * +GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri); + + +/** + * Create an FS URI from a single user-supplied string of keywords. + * The string is broken up at spaces into individual keywords. + * Keywords that start with "+" are mandatory. Double-quotes can + * be used to prevent breaking up strings at spaces (and also + * to specify non-mandatory keywords starting with "+"). + * + * Keywords must contain a balanced number of double quotes and + * double quotes can not be used in the actual keywords (for + * example, the string '""foo bar""' will be turned into two + * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'. + * + * @param keywords the keyword string + * @param emsg where to store an error message + * @return an FS URI for the given keywords, NULL + * if keywords is not legal (i.e. empty). + */ +struct GNUNET_FS_Uri * +GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg); + + +/** + * Create an FS URI from a user-supplied command line of keywords. + * Arguments should start with "+" to indicate mandatory + * keywords. + * + * @param argc number of keywords + * @param argv keywords (double quotes are not required for + * keywords containing spaces; however, double + * quotes are required for keywords starting with + * "+"); there is no mechanism for having double + * quotes in the actual keywords (if the user + * did specifically specify double quotes, the + * caller should convert each double quote + * into two single quotes). + * @return an FS URI for the given keywords, NULL + * if keywords is not legal (i.e. empty). + */ +struct GNUNET_FS_Uri * +GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv); + + +/** + * Test if two URIs are equal. + * + * @param u1 one of the URIs + * @param u2 the other URI + * @return GNUNET_YES if the URIs are equal + */ +int +GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, + const struct GNUNET_FS_Uri *u2); + + +/** + * Is this a namespace URI? + * + * @param uri the uri to check + * @return GNUNET_YES if this is an SKS uri + */ +int +GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri); + + +/** + * Handle to one of our namespaces. + */ +struct GNUNET_FS_Namespace; + + +/** + * Create an SKS URI from a namespace and an identifier. + * + * @param ns namespace + * @param id identifier + * @param emsg where to store an error message + * @return an FS URI for the given namespace and identifier + */ +struct GNUNET_FS_Uri * +GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id, + char **emsg); + + +/** + * Create an SKS URI from a namespace ID and an identifier. + * + * @param nsid namespace ID + * @param id identifier + * @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); + + +/** + * Get the ID of a namespace from the given + * namespace URI. + * + * @param uri the uri to get the namespace ID from + * @param nsid where to store the ID of the namespace + * @return GNUNET_OK on success + */ +int +GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, + GNUNET_HashCode * nsid); + + +/** + * Get the content identifier of an SKS URI. + * + * @param uri the sks uri + * @return NULL on error (not a valid SKS URI) + */ +char * +GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri); + + +/** + * Convert namespace URI to a human readable format + * (using the namespace description, if available). + * + * @param cfg configuration to use + * @param uri SKS uri to convert + * @return NULL on error (not an SKS URI) + */ +char * +GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_FS_Uri *uri); + + +/** + * Is this a keyword URI? + * + * @param uri the uri + * @return GNUNET_YES if this is a KSK uri + */ +int +GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri); + + +/** + * Is this a file (or directory) URI? + * + * @param uri the uri to check + * @return GNUNET_YES if this is a CHK uri + */ +int +GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri); + + +/** + * What is the size of the file that this URI + * refers to? + * + * @param uri the CHK (or LOC) URI to inspect + * @return size of the file as specified in the CHK URI + */ +uint64_t +GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri); + + +/** + * Is this a location URI? + * + * @param uri the uri to check + * @return GNUNET_YES if this is a LOC uri + */ +int +GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri); + + +/** + * Construct a keyword-URI from meta-data (take all entries + * in the meta-data and construct one large keyword URI + * that lists all keywords that can be found in the meta-data). + * + * @param md metadata to use + * @return NULL on error, otherwise a KSK URI + */ +struct GNUNET_FS_Uri * +GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData + *md); + + +/* ******************** command-line option parsing API *********************** */ + +/** + * Command-line option parser function that allows the user + * to specify one or more '-k' options with keywords. Each + * specified keyword will be added to the URI. A pointer to + * the URI must be passed as the "scls" argument. + * + * @param ctx command line processor context + * @param scls must be of type "struct GNUNET_FS_Uri **" + * @param option name of the option (typically 'k') + * @param value command line argument given + * @return GNUNET_OK on success + */ +int +GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext + *ctx, void *scls, const char *option, + const char *value); + + +/** + * Command-line option parser function that allows the user to specify + * one or more '-m' options with metadata. Each specified entry of + * the form "type=value" will be added to the metadata. A pointer to + * the metadata must be passed as the "scls" argument. + * + * @param ctx command line processor context + * @param scls must be of type "struct GNUNET_CONTAINER_MetaData **" + * @param option name of the option (typically 'k') + * @param value command line argument given + * @return GNUNET_OK on success + */ +int +GNUNET_FS_getopt_set_metadata (struct GNUNET_GETOPT_CommandLineProcessorContext + *ctx, void *scls, const char *option, + const char *value); + + + +/* ************************* sharing API ***************** */ + + +/** + * Possible status codes used in the callback for the + * various file-sharing operations. On each file (or search), + * the callback is guaranteed to be called once with "START" + * and once with STOPPED; calls with PROGRESS, ERROR or COMPLETED + * are optional and depend on the circumstances; parent operations + * will be STARTED before child-operations and STOPPED after + * their respective child-operations. START and STOP signals + * are typically generated either due to explicit client requests + * or because of suspend/resume operations. + */ +enum GNUNET_FS_Status +{ + /** + * Notification that we have started to publish a file structure. + */ + GNUNET_FS_STATUS_PUBLISH_START = 0, + + /** + * Notification that we have resumed sharing a file structure. + */ + GNUNET_FS_STATUS_PUBLISH_RESUME = 1, + + /** + * Notification that we have suspended sharing a file structure. + */ + GNUNET_FS_STATUS_PUBLISH_SUSPEND = 2, + + /** + * Notification that we are making progress sharing a file structure. + */ + GNUNET_FS_STATUS_PUBLISH_PROGRESS = 3, + + /** + * Notification that an error was encountered sharing a file structure. + * The application will continue to receive resume/suspend events for + * this structure until "GNUNET_FS_publish_stop" is called. + */ + GNUNET_FS_STATUS_PUBLISH_ERROR = 4, + + /** + * Notification that we completed sharing a file structure. + * The application will continue to receive resume/suspend events for + * this structure until "GNUNET_FS_publish_stop" is called. + */ + GNUNET_FS_STATUS_PUBLISH_COMPLETED = 5, + + /** + * Notification that we have stopped + * the process of uploading a file structure; no + * futher events will be generated for this action. + */ + GNUNET_FS_STATUS_PUBLISH_STOPPED = 6, + + /** + * Notification that we have started this download. + */ + GNUNET_FS_STATUS_DOWNLOAD_START = 7, + + /** + * Notification that this download is being resumed. + */ + GNUNET_FS_STATUS_DOWNLOAD_RESUME = 8, + + /** + * Notification that this download was suspended. + */ + GNUNET_FS_STATUS_DOWNLOAD_SUSPEND = 9, + + /** + * Notification about progress with this download. + */ + GNUNET_FS_STATUS_DOWNLOAD_PROGRESS = 10, + + /** + * Notification that this download encountered an error. + */ + GNUNET_FS_STATUS_DOWNLOAD_ERROR = 11, + + /** + * Notification that this download completed. Note that for + * directories, completion does not imply completion of all files in + * the directory. + */ + GNUNET_FS_STATUS_DOWNLOAD_COMPLETED = 12, + + /** + * Notification that this download was stopped + * (final event with respect to this action). + */ + GNUNET_FS_STATUS_DOWNLOAD_STOPPED = 13, + + /** + * Notification that this download is now actively being + * pursued (as opposed to waiting in the queue). + */ + GNUNET_FS_STATUS_DOWNLOAD_ACTIVE = 14, + + /** + * Notification that this download is no longer actively + * being pursued (back in the queue). + */ + GNUNET_FS_STATUS_DOWNLOAD_INACTIVE = 15, + + /** + * Notification that this download is no longer part of a + * recursive download or search but now a 'stand-alone' + * download (and may thus need to be moved in the GUI + * into a different category). + */ + GNUNET_FS_STATUS_DOWNLOAD_LOST_PARENT = 16, + + /** + * First event generated when a client requests + * a search to begin or when a namespace result + * automatically triggers the search for updates. + */ + GNUNET_FS_STATUS_SEARCH_START = 17, + + /** + * Last event when a search is being resumed; + * note that "GNUNET_FS_SEARCH_START" will not + * be generated in this case. + */ + GNUNET_FS_STATUS_SEARCH_RESUME = 18, + + /** + * Event generated for each search result + * when the respective search is resumed. + */ + GNUNET_FS_STATUS_SEARCH_RESUME_RESULT = 19, + + /** + * Last event when a search is being suspended; + * note that "GNUNET_FS_SEARCH_STOPPED" will not + * be generated in this case. + */ + GNUNET_FS_STATUS_SEARCH_SUSPEND = 20, + + /** + * This search has yielded a result. + */ + GNUNET_FS_STATUS_SEARCH_RESULT = 21, + + /** + * We have discovered a new namespace. + */ + GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE = 22, + + /** + * We have additional data about the quality + * or availability of a search result. + */ + GNUNET_FS_STATUS_SEARCH_UPDATE = 23, + + /** + * Signals a problem with this search. + */ + GNUNET_FS_STATUS_SEARCH_ERROR = 24, + + /** + * Signals that this search was paused. + */ + GNUNET_FS_STATUS_SEARCH_PAUSED = 25, + + /** + * Signals that this search was continued (unpaused). + */ + GNUNET_FS_STATUS_SEARCH_CONTINUED = 26, + + /** + * Event generated for each search result + * when the respective search is stopped. + */ + GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED = 27, + + /** + * Event generated for each search result + * when the respective search is suspended. + */ + GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND = 28, + + /** + * Last message from a search; this signals + * that there will be no further events associated + * with this search. + */ + GNUNET_FS_STATUS_SEARCH_STOPPED = 29, + + /** + * Notification that we started to unindex a file. + */ + GNUNET_FS_STATUS_UNINDEX_START = 30, + + /** + * Notification that we resumed unindexing of a file. + */ + GNUNET_FS_STATUS_UNINDEX_RESUME = 31, + + /** + * Notification that we suspended unindexing a file. + */ + GNUNET_FS_STATUS_UNINDEX_SUSPEND = 32, + + /** + * Notification that we made progress unindexing a file. + */ + GNUNET_FS_STATUS_UNINDEX_PROGRESS = 33, + + /** + * Notification that we encountered an error unindexing + * a file. + */ + GNUNET_FS_STATUS_UNINDEX_ERROR = 34, + + /** + * Notification that the unindexing of this file + * was completed. + */ + GNUNET_FS_STATUS_UNINDEX_COMPLETED = 35, + + /** + * Notification that the unindexing of this file + * was stopped (final event for this action). + */ + GNUNET_FS_STATUS_UNINDEX_STOPPED = 36 +}; + + +/** + * Handle for controlling an upload. + */ +struct GNUNET_FS_PublishContext; + + +/** + * Handle for controlling an unindexing operation. + */ +struct GNUNET_FS_UnindexContext; + + +/** + * Handle for controlling a search. + */ +struct GNUNET_FS_SearchContext; + + +/** + * Result from a search. Opaque handle to refer to the search + * (typically used when starting a download associated with the search + * result). + */ +struct GNUNET_FS_SearchResult; + + +/** + * Context for controlling a download. + */ +struct GNUNET_FS_DownloadContext; + + +/** + * Handle for detail information about a file that is being publishd. + * Specifies metadata, keywords, how to get the contents of the file + * (i.e. data-buffer in memory, filename on disk) and other options. + */ +struct GNUNET_FS_FileInformation; + + +/** + * Argument given to the progress callback with + * information about what is going on. + */ +struct GNUNET_FS_ProgressInfo +{ + + /** + * Values that depend on the event type. + */ + union + { + + /** + * Values for all "GNUNET_FS_STATUS_PUBLISH_*" events. + */ + struct + { + + /** + * Context for controlling the upload. + */ + struct GNUNET_FS_PublishContext *pc; + + /** + * Information about the file that is being publishd. + */ + const struct GNUNET_FS_FileInformation *fi; + + /** + * Client context pointer (set the last time by the client for + * this operation; initially NULL on START/RESUME events). + */ + void *cctx; + + /** + * Client context pointer for the parent operation + * (if this is a file in a directory or a subdirectory). + */ + void *pctx; + + /** + * Name of the file being published; can be NULL. + */ + const char *filename; + + /** + * How large is the file overall? For directories, + * this is only the size of the directory itself, + * not of the other files contained within the + * directory. + */ + uint64_t size; + + /** + * At what time do we expect to finish the upload? + * (will be a value in the past for completed + * uploads). + */ + struct GNUNET_TIME_Relative eta; + + /** + * How long has this upload been actively running + * (excludes times where the upload was suspended). + */ + struct GNUNET_TIME_Relative duration; + + /** + * How many bytes have we completed? + */ + uint64_t completed; + + /** + * What anonymity level is used for this upload? + */ + uint32_t anonymity; + + /** + * Additional values for specific events. + */ + union + { + + /** + * These values are only valid for + * GNUNET_FS_STATUS_PUBLISH_PROGRESS events. + */ + struct + { + + /** + * Data block we just published. + */ + const void *data; + + /** + * At what offset in the file is "data"? + */ + uint64_t offset; + + /** + * Length of the data block. + */ + uint64_t data_len; + + /** + * Depth of the given block in the tree; + * 0 would be the lowest level (DBLOCKs). + */ + unsigned int depth; + + } progress; + + /** + * These values are only valid for + * GNUNET_FS_STATUS_PUBLISH_RESUME events. + */ + struct + { + + /** + * Error message, NULL if no error was encountered so far. + */ + const char *message; + + /** + * URI of the file (if the download had been completed) + */ + const struct GNUNET_FS_Uri *chk_uri; + + } resume; + + /** + * These values are only valid for + * GNUNET_FS_STATUS_PUBLISH_COMPLETED events. + */ + struct + { + + /** + * URI of the file. + */ + const struct GNUNET_FS_Uri *chk_uri; + + } completed; + + /** + * These values are only valid for + * GNUNET_FS_STATUS_PUBLISH_ERROR events. + */ + struct + { + + /** + * Error message, never NULL. + */ + const char *message; + + } error; + + } specifics; + + } publish; + + + /** + * Values for all "GNUNET_FS_STATUS_DOWNLOAD_*" events. + */ + struct + { + + /** + * Context for controlling the download. + */ + struct GNUNET_FS_DownloadContext *dc; + + /** + * Client context pointer (set the last time + * by the client for this operation; initially + * NULL on START/RESUME events). + */ + void *cctx; + + /** + * Client context pointer for the parent operation + * (if this is a file in a directory or a subdirectory). + */ + void *pctx; + + /** + * Client context pointer for the associated search operation + * (specifically, context pointer for the specific search + * result, not the overall search); only set if this + * download was started from a search result. + */ + void *sctx; + + /** + * URI used for this download. + */ + const struct GNUNET_FS_Uri *uri; + + /** + * Name of the file that we are downloading. + */ + const char *filename; + + /** + * How large is the download overall? This + * is NOT necessarily the size from the + * URI since we may be doing a partial download. + */ + uint64_t size; + + /** + * At what time do we expect to finish the download? + * (will be a value in the past for completed + * uploads). + */ + struct GNUNET_TIME_Relative eta; + + /** + * How long has this download been active? + */ + struct GNUNET_TIME_Relative duration; + + /** + * How many bytes have we completed? + */ + uint64_t completed; + + /** + * What anonymity level is used for this download? + */ + uint32_t anonymity; + + /** + * Is the download currently active. + */ + int is_active; + + /** + * Additional values for specific events. + */ + union + { + + /** + * These values are only valid for + * GNUNET_FS_STATUS_DOWNLOAD_PROGRESS events. + */ + struct + { + + /** + * Data block we just obtained, can be NULL (even if + * data_len > 0) if we found the entire block 'intact' on + * disk. In this case, it is also possible for 'data_len' + * to be larger than an individual (32k) block. + */ + const void *data; + + /** + * At what offset in the file is "data"? + */ + uint64_t offset; + + /** + * Length of the data block. + */ + uint64_t data_len; + + /** + * 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? + */ + unsigned int trust_offered; + + /** + * 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; + + } progress; + + /** + * These values are only valid for + * GNUNET_FS_STATUS_DOWNLOAD_START events. + */ + struct + { + + /** + * Known metadata for the download. + */ + const struct GNUNET_CONTAINER_MetaData *meta; + + } start; + + /** + * These values are only valid for + * GNUNET_FS_STATUS_DOWNLOAD_RESUME events. + */ + struct + { + + /** + * Known metadata for the download. + */ + const struct GNUNET_CONTAINER_MetaData *meta; + + /** + * Error message, NULL if we have not encountered any error yet. + */ + const char *message; + + } resume; + + /** + * These values are only valid for + * GNUNET_FS_STATUS_DOWNLOAD_ERROR events. + */ + struct + { + + /** + * Error message. + */ + const char *message; + + } error; + + } specifics; + + } download; + + /** + * Values for all "GNUNET_FS_STATUS_SEARCH_*" events. + */ + struct + { + + /** + * Context for controlling the search, NULL for + * searches that were not explicitly triggered + * by the client (i.e., searches for updates in + * namespaces). + */ + struct GNUNET_FS_SearchContext *sc; + + /** + * Client context pointer (set the last time by the client for + * this operation; initially NULL on START/RESUME events). Note + * that this value can only be set on START/RESUME; returning + * non-NULL on RESULT/RESUME_RESULT will actually update the + * private context for "UPDATE" events. + */ + void *cctx; + + /** + * Client parent-context pointer; NULL for top-level searches, + * refers to the client context of the associated search result + * for automatically triggered searches for updates in + * namespaces. In this case, 'presult' refers to that search + * result. + */ + void *pctx; + + /** + * What query is used for this search + * (list of keywords or SKS identifier). + */ + const struct GNUNET_FS_Uri *query; + + /** + * How long has this search been actively running + * (excludes times where the search was paused or + * suspended). + */ + struct GNUNET_TIME_Relative duration; + + /** + * What anonymity level is used for this search? + */ + uint32_t anonymity; + + /** + * Additional values for specific events. + */ + union + { + + /** + * These values are only valid for + * GNUNET_FS_STATUS_SEARCH_RESULT events. + */ + struct + { + + /** + * Metadata for the search result. + */ + const struct GNUNET_CONTAINER_MetaData *meta; + + /** + * URI for the search result. + */ + const struct GNUNET_FS_Uri *uri; + + /** + * Handle to the result (for starting downloads). + */ + struct GNUNET_FS_SearchResult *result; + + /** + * Applicability rank (the larger, the better the result + * fits the search criteria). + */ + uint32_t applicability_rank; + + } result; + + /** + * These values are only valid for + * GNUNET_FS_STATUS_SEARCH_RESUME_RESULT events. + */ + struct + { + + /** + * Metadata for the search result. + */ + const struct GNUNET_CONTAINER_MetaData *meta; + + /** + * URI for the search result. + */ + const struct GNUNET_FS_Uri *uri; + + /** + * Handle to the result (for starting downloads). + */ + struct GNUNET_FS_SearchResult *result; + + /** + * Current availability rank (negative: + * unavailable, positive: available) + */ + int32_t availability_rank; + + /** + * On how many total queries is the given + * availability_rank based? + */ + uint32_t availability_certainty; + + /** + * Updated applicability rank (the larger, + * the better the result fits the search + * criteria). + */ + uint32_t applicability_rank; + + } resume_result; + + /** + * These values are only valid for + * GNUNET_FS_STATUS_SEARCH_UPDATE events. + */ + struct + { + + /** + * Private context set for for this result + * during the "RESULT" event. + */ + void *cctx; + + /** + * Metadata for the search result. + */ + const struct GNUNET_CONTAINER_MetaData *meta; + + /** + * URI for the search result. + */ + const struct GNUNET_FS_Uri *uri; + + /** + * Current availability rank (negative: + * unavailable, positive: available) + */ + int32_t availability_rank; + + /** + * On how many total queries is the given + * availability_rank based? + */ + uint32_t availability_certainty; + + /** + * Updated applicability rank (the larger, + * the better the result fits the search + * criteria). + */ + uint32_t applicability_rank; + + } update; + + /** + * These values are only valid for + * GNUNET_FS_STATUS_SEARCH_RESULT_SUSPEND events. + * These events are automatically triggered for + * each search result before the + * GNUNET_FS_STATUS_SEARCH_SUSPEND event. This + * happens primarily to give the client a chance + * to clean up the "cctx" (if needed). + */ + struct + { + + /** + * Private context set for for this result + * during the "RESULT" event. + */ + void *cctx; + + /** + * Metadata for the search result. + */ + const struct GNUNET_CONTAINER_MetaData *meta; + + /** + * URI for the search result. + */ + const struct GNUNET_FS_Uri *uri; + + } result_suspend; + + /** + * These values are only valid for + * GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED events. + * These events are automatically triggered for + * each search result before the + * GNUNET_FS_STATUS_SEARCH_STOPPED event. This + * happens primarily to give the client a chance + * to clean up the "cctx" (if needed). + */ + struct + { + + /** + * Private context set for for this result + * during the "RESULT" event. + */ + void *cctx; + + /** + * Metadata for the search result. + */ + const struct GNUNET_CONTAINER_MetaData *meta; + + /** + * URI for the search result. + */ + const struct GNUNET_FS_Uri *uri; + + } result_stopped; + + /** + * These values are only valid for + * GNUNET_FS_STATUS_SEARCH_RESUME events. + */ + struct + { + + /** + * Error message, NULL if we have not encountered any error yet. + */ + const char *message; + + /** + * Is this search currently paused? + */ + int is_paused; + + } resume; + + /** + * These values are only valid for + * GNUNET_FS_STATUS_SEARCH_ERROR events. + */ + struct + { + + /** + * Error message. + */ + const char *message; + + } error; + + /** + * Values for all "GNUNET_FS_STATUS_SEARCH_RESULT_NAMESPACE" events. + */ + struct + { + + /** + * Handle to the namespace (NULL if it is not a local + * namespace). + */ + struct GNUNET_FS_Namespace *ns; + + /** + * Short, human-readable name of the namespace. + */ + const char *name; + + /** + * Root identifier for the namespace, can be NULL. + */ + const char *root; + + /** + * Metadata for the namespace. + */ + const struct GNUNET_CONTAINER_MetaData *meta; + + /** + * Hash-identifier for the namespace. + */ + GNUNET_HashCode id; + + } namespace; + + } specifics; + + } search; + + /** + * Values for all "GNUNET_FS_STATUS_UNINDEX_*" events. + */ + struct + { + + /** + * Context for controlling the unindexing. + */ + struct GNUNET_FS_UnindexContext *uc; + + /** + * Client context pointer (set the last time + * by the client for this operation; initially + * NULL on START/RESUME events). + */ + void *cctx; + + /** + * Name of the file that is being unindexed. + */ + const char *filename; + + /** + * How large is the file overall? + */ + uint64_t size; + + /** + * At what time do we expect to finish unindexing? + * (will be a value in the past for completed + * unindexing opeations). + */ + struct GNUNET_TIME_Relative eta; + + /** + * How long has this upload been actively running + * (excludes times where the upload was suspended). + */ + struct GNUNET_TIME_Relative duration; + + /** + * How many bytes have we completed? + */ + uint64_t completed; + + /** + * Additional values for specific events. + */ + union + { + + /** + * These values are only valid for + * GNUNET_FS_STATUS_UNINDEX_PROGRESS events. + */ + struct + { + + /** + * Data block we just unindexed. + */ + const void *data; + + /** + * At what offset in the file is "data"? + */ + uint64_t offset; + + /** + * Length of the data block. + */ + uint64_t data_len; + + /** + * Depth of the given block in the tree; + * 0 would be the lowest level (DBLOCKS). + */ + unsigned int depth; + + } progress; + + /** + * These values are only valid for + * GNUNET_FS_STATUS_UNINDEX_RESUME events. + */ + struct + { + + /** + * Error message, NULL if we have not encountered any error yet. + */ + const char *message; + + } resume; + + /** + * These values are only valid for + * GNUNET_FS_STATUS_UNINDEX_ERROR events. + */ + struct + { + + /** + * Error message. + */ + const char *message; + + } error; + + } specifics; + + } unindex; + + } value; + + /** + * Specific status code (determines the event type). + */ + enum GNUNET_FS_Status status; + +}; + + +/** + * Notification of FS to a client about the progress of an + * operation. Callbacks of this type will be used for uploads, + * downloads and searches. Some of the arguments depend a bit + * in their meaning on the context in which the callback is used. + * + * @param cls closure + * @param info details about the event, specifying the event type + * and various bits about the event + * @return client-context (for the next progress call + * for this operation; should be set to NULL for + * SUSPEND and STOPPED events). The value returned + * will be passed to future callbacks in the respective + * field in the GNUNET_FS_ProgressInfo struct. + */ +typedef void *(*GNUNET_FS_ProgressCallback) (void *cls, + const struct GNUNET_FS_ProgressInfo + * info); + + +/** + * General (global) option flags for file-sharing. + */ +enum GNUNET_FS_Flags +{ + /** + * No special flags set. + */ + GNUNET_FS_FLAGS_NONE = 0, + + /** + * Is persistence of operations desired? + * (will create SUSPEND/RESUME events). + */ + GNUNET_FS_FLAGS_PERSISTENCE = 1, + + /** + * Should we automatically trigger probes for search results + * to determine availability? + * (will create GNUNET_FS_STATUS_SEARCH_UPDATE events). + */ + 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. + */ + 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). + */ + 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. + */ + GNUNET_FS_OPTIONS_REQUEST_PARALLELISM = 2 +}; + + +/** + * Settings for publishing a block (which may of course also + * apply to an entire directory or file). + */ +struct GNUNET_FS_BlockOptions +{ + + /** + * At what time should the block expire? Data blocks (DBLOCKS and + * IBLOCKS) may still be used even if they are expired (however, + * they'd be removed quickly from the datastore if we are short on + * space), all other types of blocks will no longer be returned + * after they expire. + */ + struct GNUNET_TIME_Absolute expiration_time; + + /** + * At which anonymity level should the block be shared? + * (0: no anonymity, 1: normal GAP, >1: with cover traffic). + */ + uint32_t anonymity_level; + + /** + * How important is it for us to store the block? If we run + * out of space, the highest-priority, non-expired blocks will + * be kept. + */ + uint32_t content_priority; + + /** + * How often should we try to migrate the block to other peers? + * Only used if "CONTENT_PUSHING" is set to YES, in which case we + * first push each block to other peers according to their + * replication levels. Once each block has been pushed that many + * times to other peers, blocks are chosen for migration at random. + * Naturally, there is no guarantee that the other peers will keep + * these blocks for any period of time (since they won't have any + * priority or might be too busy to even store the block in the + * first place). + */ + uint32_t replication_level; + +}; + + +/** + * Return the current year (i.e. '2011'). + */ +unsigned int +GNUNET_FS_get_current_year (void); + + +/** + * Convert a year to an expiration time of January 1st of that year. + * + * @param year a year (after 1970, please ;-)). + * @return absolute time for January 1st of that year. + */ +struct GNUNET_TIME_Absolute +GNUNET_FS_year_to_time (unsigned int year); + + +/** + * Convert an expiration time to the respective year (rounds) + * + * @param at absolute time + * @return year a year (after 1970), 0 on error + */ +unsigned int +GNUNET_FS_time_to_year (struct GNUNET_TIME_Absolute at); + + +/** + * Handle to the file-sharing service. + */ +struct GNUNET_FS_Handle; + + +/** + * Setup a connection to the file-sharing service. + * + * @param cfg configuration to use + * @param client_name unique identifier for this client + * @param upcb function to call to notify about FS actions + * @param upcb_cls closure for upcb + * @param flags specific attributes for fs-operations + * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END + * @return NULL on error + */ +struct GNUNET_FS_Handle * +GNUNET_FS_start (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *client_name, GNUNET_FS_ProgressCallback upcb, + void *upcb_cls, enum GNUNET_FS_Flags flags, ...); + + +/** + * Close our connection with the file-sharing service. + * The callback given to GNUNET_FS_start will no longer be + * called after this function returns. + * + * @param h handle that was returned from GNUNET_FS_start + */ +void +GNUNET_FS_stop (struct GNUNET_FS_Handle *h); + + +/** + * Function called on entries in a GNUNET_FS_FileInformation publish-structure. + * + * @param cls closure + * @param fi the entry in the publish-structure + * @param length length of the file or directory + * @param meta metadata for the file or directory (can be modified) + * @param uri pointer to the keywords that will be used for this entry (can be modified) + * @param bo block options (can be modified) + * @param do_index should we index (can be modified) + * @param client_info pointer to client context set upon creation (can be modified) + * @return GNUNET_OK to continue, GNUNET_NO to remove + * this entry from the directory, GNUNET_SYSERR + * to abort the iteration + */ +typedef int (*GNUNET_FS_FileInformationProcessor) (void *cls, + struct + GNUNET_FS_FileInformation * + fi, uint64_t length, + struct + GNUNET_CONTAINER_MetaData * + meta, + struct GNUNET_FS_Uri ** uri, + struct GNUNET_FS_BlockOptions + * bo, int *do_index, + void **client_info); + + +/** + * Obtain the name under which this file information + * structure is stored on disk. Only works for top-level + * file information structures. + * + * @param s structure to get the filename for + * @return NULL on error, otherwise filename that + * can be passed to "GNUNET_FS_file_information_recover" + * to read this fi-struct from disk. + */ +const char * +GNUNET_FS_file_information_get_id (struct GNUNET_FS_FileInformation *s); + + +/** + * Obtain the filename from the file information structure. + * + * @param s structure to get the filename for + * @return "filename" field of the structure (can be NULL) + */ +const char * +GNUNET_FS_file_information_get_filename (struct GNUNET_FS_FileInformation *s); + + +/** + * Set the filename in the file information structure. + * If filename was already set, frees it before setting the new one. + * Makes a copy of the argument. + * + * @param s structure to get the filename for + * @param filename filename to set + */ +void +GNUNET_FS_file_information_set_filename (struct GNUNET_FS_FileInformation *s, + const char *filename); + + +/** + * Create an entry for a file in a publish-structure. + * + * @param h handle to the file sharing subsystem + * @param client_info initial client-info value for this entry + * @param filename name of the file or directory to publish + * @param keywords under which keywords should this file be available + * directly; can be NULL + * @param meta metadata for the file + * @param do_index GNUNET_YES for index, GNUNET_NO for insertion, + * GNUNET_SYSERR for simulation + * @param bo block options + * @return publish structure entry for the file + */ +struct GNUNET_FS_FileInformation * +GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h, + void *client_info, + const char *filename, + const struct GNUNET_FS_Uri + *keywords, + const struct + GNUNET_CONTAINER_MetaData *meta, + int do_index, + const struct GNUNET_FS_BlockOptions + *bo); + + +/** + * Create an entry for a file in a publish-structure. + * + * @param h handle to the file sharing subsystem + * @param client_info initial client-info value for this entry + * @param length length of the file + * @param data data for the file (should not be used afterwards by + * the caller; callee will "free") + * @param keywords under which keywords should this file be available + * directly; can be NULL + * @param meta metadata for the file + * @param do_index GNUNET_YES for index, GNUNET_NO for insertion, + * GNUNET_SYSERR for simulation + * @param bo block options + * @return publish structure entry for the file + */ +struct GNUNET_FS_FileInformation * +GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h, + void *client_info, uint64_t length, + void *data, + const struct GNUNET_FS_Uri + *keywords, + const struct + GNUNET_CONTAINER_MetaData *meta, + int do_index, + const struct GNUNET_FS_BlockOptions + *bo); + + +/** + * Function that provides data. + * + * @param cls closure + * @param offset offset to read from; it is possible + * that the caller might need to go backwards + * a bit at times + * @param max maximum number of bytes that should be + * copied to buf; readers are not allowed + * to provide less data unless there is an error; + * a value of "0" will be used at the end to allow + * the reader to clean up its internal state + * @param buf where the reader should write the data + * @param emsg location for the reader to store an error message + * @return number of bytes written, usually "max", 0 on error + */ +typedef size_t (*GNUNET_FS_DataReader) (void *cls, uint64_t offset, size_t max, + void *buf, char **emsg); + + +/** + * Create an entry for a file in a publish-structure. + * + * @param h handle to the file sharing subsystem + * @param client_info initial client-info value for this entry + * @param length length of the file + * @param reader function that can be used to obtain the data for the file + * @param reader_cls closure for "reader" + * @param keywords under which keywords should this file be available + * directly; can be NULL + * @param meta metadata for the file + * @param do_index GNUNET_YES for index, GNUNET_NO for insertion, + * GNUNET_SYSERR for simulation + * @param bo block options + * @return publish structure entry for the file + */ +struct GNUNET_FS_FileInformation * +GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h, + void *client_info, + uint64_t length, + GNUNET_FS_DataReader reader, + void *reader_cls, + const struct GNUNET_FS_Uri + *keywords, + const struct + GNUNET_CONTAINER_MetaData *meta, + int do_index, + const struct + GNUNET_FS_BlockOptions *bo); + + +/** + * Create an entry for an empty directory in a publish-structure. + * This function should be used by applications for which the + * use of "GNUNET_FS_file_information_create_from_directory" + * is not appropriate. + * + * @param h handle to the file sharing subsystem + * @param client_info initial client-info value for this entry + * @param keywords under which keywords should this directory be available + * directly; can be NULL + * @param meta metadata for the directory + * @param bo block options + * @param filename name of the directory; can be NULL + * @return publish structure entry for the directory , NULL on error + */ +struct GNUNET_FS_FileInformation * +GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h, + void *client_info, + const struct GNUNET_FS_Uri + *keywords, + const struct + GNUNET_CONTAINER_MetaData + *meta, + const struct + GNUNET_FS_BlockOptions *bo, + const char *filename); + + +/** + * Test if a given entry represents a directory. + * + * @param ent check if this FI represents a directory + * @return GNUNET_YES if so, GNUNET_NO if not + */ +int +GNUNET_FS_file_information_is_directory (const struct GNUNET_FS_FileInformation + *ent); + + +/** + * Add an entry to a directory in a publish-structure. Clients + * should never modify publish structures that were passed to + * "GNUNET_FS_publish_start" already. + * + * @param dir the directory + * @param ent the entry to add; the entry must not have been + * added to any other directory at this point and + * must not include "dir" in its structure + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_FS_file_information_add (struct GNUNET_FS_FileInformation *dir, + struct GNUNET_FS_FileInformation *ent); + + +/** + * Inspect a file or directory in a publish-structure. Clients + * should never modify publish structures that were passed to + * "GNUNET_FS_publish_start" already. When called on a directory, + * this function will FIRST call "proc" with information about + * the directory itself and then for each of the files in the + * directory (but not for files in subdirectories). When called + * on a file, "proc" will be called exactly once (with information + * about the specific file). + * + * @param dir the directory + * @param proc function to call on each entry + * @param proc_cls closure for proc + */ +void +GNUNET_FS_file_information_inspect (struct GNUNET_FS_FileInformation *dir, + GNUNET_FS_FileInformationProcessor proc, + void *proc_cls); + + +/** + * Destroy publish-structure. Clients should never destroy publish + * structures that were passed to "GNUNET_FS_publish_start" already. + * + * @param fi structure to destroy + * @param cleaner function to call on each entry in the structure + * (useful to clean up client_info); can be NULL; return + * values are ignored + * @param cleaner_cls closure for cleaner + */ +void +GNUNET_FS_file_information_destroy (struct GNUNET_FS_FileInformation *fi, + GNUNET_FS_FileInformationProcessor cleaner, + void *cleaner_cls); + + +/** + * Options for publishing. Compatible options + * can be OR'ed together. + */ +enum GNUNET_FS_PublishOptions +{ + /** + * No options (use defaults for everything). + */ + GNUNET_FS_PUBLISH_OPTION_NONE = 0, + + /** + * Simulate publishing. With this option, no data will be stored + * in the datastore. Useful for computing URIs from files. + */ + GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY = 1 +}; + +/** + * Publish a file or directory. + * + * @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 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 + * (can be NULL, must be NULL if namespace or nid is NULL) + * @param options options for the publication + * @return context that can be used to control the publish operation + */ +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, + const char *nuid, + enum GNUNET_FS_PublishOptions options); + + +/** + * Stop a publication. Will abort incomplete publications (but + * not remove blocks that have already been published) or + * simply clean up the state for completed publications. + * Must NOT be called from within the event callback! + * + * @param pc context for the publication to stop + */ +void +GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc); + + +/** + * Signature of a function called as the continuation of a KBlock or + * SBlock publication. + * + * @param cls closure + * @param uri URI under which the block is now available, NULL on error + * @param emsg error message, NULL on success + */ +typedef void (*GNUNET_FS_PublishContinuation) (void *cls, + const struct GNUNET_FS_Uri * uri, + const char *emsg); + + +/** + * Handle to cancel publish KSK operation. + */ +struct GNUNET_FS_PublishKskContext; + + +/** + * Publish a KBlock on GNUnet. + * + * @param h handle to the file sharing subsystem + * @param ksk_uri keywords to use + * @param meta metadata to use + * @param uri URI to refer to in the KBlock + * @param bo block options + * @param options publication options + * @param cont continuation + * @param cont_cls closure for cont + * @return NULL on error ('cont' will still be called) + */ +struct GNUNET_FS_PublishKskContext * +GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, + const struct GNUNET_FS_Uri *ksk_uri, + const struct GNUNET_CONTAINER_MetaData *meta, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_FS_BlockOptions *bo, + enum GNUNET_FS_PublishOptions options, + GNUNET_FS_PublishContinuation cont, void *cont_cls); + + +/** + * Abort the KSK publishing operation. + * + * @param pkc context of the operation to abort. + */ +void +GNUNET_FS_publish_ksk_cancel (struct GNUNET_FS_PublishKskContext *pkc); + + +/** + * Handle to cancel publish SKS operation. + */ +struct GNUNET_FS_PublishSksContext; + + +/** + * Publish an SBlock on GNUnet. + * + * @param h handle to the file sharing subsystem + * @param namespace namespace to publish in + * @param identifier identifier to use + * @param update update identifier to use + * @param meta metadata to use + * @param uri URI to refer to in the SBlock + * @param bo block options + * @param options publication options + * @param cont continuation + * @param cont_cls closure for cont + * @return NULL on error ('cont' will still be called) + */ +struct GNUNET_FS_PublishSksContext * +GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h, + struct GNUNET_FS_Namespace *namespace, + const char *identifier, const char *update, + const struct GNUNET_CONTAINER_MetaData *meta, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_FS_BlockOptions *bo, + enum GNUNET_FS_PublishOptions options, + GNUNET_FS_PublishContinuation cont, void *cont_cls); + + +/** + * Abort the SKS publishing operation. + * + * @param psc context of the operation to abort. + */ +void +GNUNET_FS_publish_sks_cancel (struct GNUNET_FS_PublishSksContext *psc); + + +/** + * Type of a function called by "GNUNET_FS_get_indexed_files". + * + * @param cls closure + * @param filename the name of the file, NULL for end of list + * @param file_id hash of the contents of the indexed file + * @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); + + +/** + * Handle to cancel 'GNUNET_FS_get_indexed_files'. + */ +struct GNUNET_FS_GetIndexedContext; + + +/** + * Iterate over all indexed files. + * + * @param h handle to the file sharing subsystem + * @param iterator function to call on each indexed file + * @param iterator_cls closure for iterator + * @return NULL on error ('iter' is not called) + */ +struct GNUNET_FS_GetIndexedContext * +GNUNET_FS_get_indexed_files (struct GNUNET_FS_Handle *h, + GNUNET_FS_IndexedFileProcessor iterator, + void *iterator_cls); + + +/** + * Cancel iteration over all indexed files. + * + * @param gic operation to cancel + */ +void +GNUNET_FS_get_indexed_files_cancel (struct GNUNET_FS_GetIndexedContext *gic); + + +/** + * Unindex a file. + * + * @param h handle to the file sharing subsystem + * @param filename file to unindex + * @param cctx initial value for the client context + * @return NULL on error, otherwise handle + */ +struct GNUNET_FS_UnindexContext * +GNUNET_FS_unindex_start (struct GNUNET_FS_Handle *h, const char *filename, + void *cctx); + + +/** + * Clean up after completion of an unindex operation. + * + * @param uc handle + */ +void +GNUNET_FS_unindex_stop (struct GNUNET_FS_UnindexContext *uc); + + +/** + * Context for advertising a namespace. + */ +struct GNUNET_FS_AdvertisementContext; + + +/** + * Publish an advertismement for a namespace. + * + * @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 meta meta-data for the namespace advertisement + * @param bo block options + * @param rootEntry name of the root of the namespace + * @param cont continuation + * @param cont_cls closure for cont + * @return NULL on error ('cont' will still be called) + */ +struct GNUNET_FS_AdvertisementContext * +GNUNET_FS_namespace_advertise (struct GNUNET_FS_Handle *h, + struct GNUNET_FS_Uri *ksk_uri, + struct GNUNET_FS_Namespace *namespace, + const struct GNUNET_CONTAINER_MetaData *meta, + const struct GNUNET_FS_BlockOptions *bo, + const char *rootEntry, + GNUNET_FS_PublishContinuation cont, + void *cont_cls); + + +/** + * Abort the namespace advertisement operation. + * + * @param ac context of the operation to abort. + */ +void +GNUNET_FS_namespace_advertise_cancel (struct GNUNET_FS_AdvertisementContext *ac); + + +/** + * Create a namespace with the given name; if one already + * exists, return a handle to the existing namespace. + * + * @param h handle to the file sharing subsystem + * @param name name to use for the namespace + * @return handle to the namespace, NULL on error + */ +struct GNUNET_FS_Namespace * +GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name); + + +/** + * Duplicate a namespace handle. + * + * @param ns namespace handle + * @return duplicated handle to the namespace + */ +struct GNUNET_FS_Namespace * +GNUNET_FS_namespace_dup (struct GNUNET_FS_Namespace *ns); + + +/** + * Delete a namespace handle. Can be used for a clean shutdown (free + * 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 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); + + +/** + * Callback with information about local (!) namespaces. + * Contains the names of the local namespace and the global + * ID. + * + * @param cls closure + * @param name human-readable identifier of the namespace + * @param id hash identifier for the namespace + */ +typedef void (*GNUNET_FS_NamespaceInfoProcessor) (void *cls, const char *name, + const GNUNET_HashCode * id); + + +/** + * Build a list of all available local (!) namespaces The returned + * names are only the nicknames since we only iterate over the local + * namespaces. + * + * @param h handle to the file sharing subsystem + * @param cb function to call on each known namespace + * @param cb_cls closure for cb + */ +void +GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h, + GNUNET_FS_NamespaceInfoProcessor cb, void *cb_cls); + + +/** + * Function called on updateable identifiers. + * + * @param cls closure + * @param last_id last identifier + * @param last_uri uri used for the content published under the last_id + * @param last_meta metadata associated with last_uri + * @param next_id identifier that should be used for updates + */ +typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls, const char *last_id, + const struct GNUNET_FS_Uri * + last_uri, + const struct + GNUNET_CONTAINER_MetaData * + last_meta, const char *next_id); + + +/** + * List all of the identifiers in the namespace for which we could + * produce an update. Namespace updates form a graph where each node + * has a name. Each node can have any number of URI/meta-data entries + * which can each be linked to other nodes. Cycles are possible. + * + * Calling this function with "next_id" NULL will cause the library to + * call "ip" with a root for each strongly connected component of the + * graph (a root being a node from which all other nodes in the Scc + * are reachable). + * + * Calling this function with "next_id" being the name of a node will + * 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 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, + const char *next_id, + GNUNET_FS_IdentifierProcessor ip, + void *ip_cls); + + +/** + * Options for searching. Compatible options + * can be OR'ed together. + */ +enum GNUNET_FS_SearchOptions +{ + /** + * No options (use defaults for everything). + */ + GNUNET_FS_SEARCH_OPTION_NONE = 0, + + /** + * Only search the local host, do not search remote systems (no P2P) + */ + GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY = 1 +}; + + +/** + * Start search for content. + * + * @param h handle to the file sharing subsystem + * @param uri specifies the search parameters; can be + * a KSK URI or an SKS URI. + * @param anonymity desired level of anonymity + * @param options options for the search + * @param cctx initial value for the client context + * @return context that can be used to control the search + */ +struct GNUNET_FS_SearchContext * +GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, + const struct GNUNET_FS_Uri *uri, uint32_t anonymity, + enum GNUNET_FS_SearchOptions options, void *cctx); + + +/** + * Pause search. + * + * @param sc context for the search that should be paused + */ +void +GNUNET_FS_search_pause (struct GNUNET_FS_SearchContext *sc); + + +/** + * Continue paused search. + * + * @param sc context for the search that should be resumed + */ +void +GNUNET_FS_search_continue (struct GNUNET_FS_SearchContext *sc); + + +/** + * Stop search for content. + * + * @param sc context for the search that should be stopped + */ +void +GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc); + + + + +/** + * Options for downloading. Compatible options + * can be OR'ed together. + */ +enum GNUNET_FS_DownloadOptions +{ + /** + * No options (use defaults for everything). + */ + GNUNET_FS_DOWNLOAD_OPTION_NONE = 0, + + /** + * Only download from the local host, do not access remote systems (no P2P) + */ + GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY = 1, + + /** + * Do a recursive download (that is, automatically trigger the + * download of files in directories). + */ + GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE = 2, + + /** + * Do not append temporary data to + * the target file (for the IBlocks). + */ + GNUNET_FS_DOWNLOAD_NO_TEMPORARIES = 4, + + /** + * Internal option used to flag this download as a 'probe' for a + * search result. Impacts the priority with which the download is + * run and causes signalling callbacks to be done differently. + * Also, probe downloads are not serialized on suspension. Normal + * clients should not use this! + */ + GNUNET_FS_DOWNLOAD_IS_PROBE = (1 << 31) +}; + + + +/** + * Download parts of a file. Note that this will store + * the blocks at the respective offset in the given file. Also, the + * download is still using the blocking of the underlying FS + * encoding. As a result, the download may *write* outside of the + * given boundaries (if offset and length do not match the 32k FS + * block boundaries). <p> + * + * The given range can be used to focus a download towards a + * particular portion of the file (optimization), not to strictly + * limit the download to exactly those bytes. + * + * @param h handle to the file sharing subsystem + * @param uri the URI of the file (determines what to download); CHK or LOC URI + * @param meta known metadata for the file (can be NULL) + * @param filename where to store the file, maybe NULL (then no file is + * created on disk and data must be grabbed from the callbacks) + * @param tempname where to store temporary file data, not used if filename is non-NULL; + * can be NULL (in which case we will pick a name if needed); the temporary file + * may already exist, in which case we will try to use the data that is there and + * if it is not what is desired, will overwrite it + * @param offset at what offset should we start the download (typically 0) + * @param length how many bytes should be downloaded starting at offset + * @param anonymity anonymity level to use for the download + * @param options various download options + * @param cctx initial value for the client context for this download + * @param parent parent download to associate this download with (use NULL + * for top-level downloads; useful for manually-triggered recursive downloads) + * @return context that can be used to control this download + */ +struct GNUNET_FS_DownloadContext * +GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *meta, + const char *filename, const char *tempname, + uint64_t offset, uint64_t length, uint32_t anonymity, + enum GNUNET_FS_DownloadOptions options, void *cctx, + struct GNUNET_FS_DownloadContext *parent); + + +/** + * Download parts of a file based on a search result. The download + * will be associated with the search result (and the association + * will be preserved when serializing/deserializing the state). + * If the search is stopped, the download will not be aborted but + * be 'promoted' to a stand-alone download. + * + * As with the other download function, this will store + * the blocks at the respective offset in the given file. Also, the + * download is still using the blocking of the underlying FS + * encoding. As a result, the download may *write* outside of the + * given boundaries (if offset and length do not match the 32k FS + * block boundaries). <p> + * + * The given range can be used to focus a download towards a + * particular portion of the file (optimization), not to strictly + * limit the download to exactly those bytes. + * + * @param h handle to the file sharing subsystem + * @param sr the search result to use for the download (determines uri and + * meta data and associations) + * @param filename where to store the file, maybe NULL (then no file is + * created on disk and data must be grabbed from the callbacks) + * @param tempname where to store temporary file data, not used if filename is non-NULL; + * can be NULL (in which case we will pick a name if needed); the temporary file + * may already exist, in which case we will try to use the data that is there and + * if it is not what is desired, will overwrite it + * @param offset at what offset should we start the download (typically 0) + * @param length how many bytes should be downloaded starting at offset + * @param anonymity anonymity level to use for the download + * @param options various download options + * @param cctx initial value for the client context for this download + * @return context that can be used to control this download + */ +struct GNUNET_FS_DownloadContext * +GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h, + struct GNUNET_FS_SearchResult *sr, + const char *filename, + const char *tempname, uint64_t offset, + uint64_t length, uint32_t anonymity, + enum GNUNET_FS_DownloadOptions options, + void *cctx); + + +/** + * Stop a download (aborts if download is incomplete). + * + * @param dc handle for the download + * @param do_delete delete files of incomplete downloads + */ +void +GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc, int do_delete); + + + +/* ******************** Directory API *********************** */ + + +#define GNUNET_FS_DIRECTORY_MIME "application/gnunet-directory" +#define GNUNET_FS_DIRECTORY_MAGIC "\211GND\r\n\032\n" +#define GNUNET_FS_DIRECTORY_EXT ".gnd" + +/** + * Does the meta-data claim that this is a directory? + * Checks if the mime-type is that of a GNUnet directory. + * + * @return GNUNET_YES if it is, GNUNET_NO if it is not, GNUNET_SYSERR if + * we have no mime-type information (treat as 'GNUNET_NO') + */ +int +GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData + *md); + + +/** + * Set the MIMETYPE information for the given + * metadata to "application/gnunet-directory". + * + * @param md metadata to add mimetype to + */ +void +GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md); + + +/** + * Suggest a filename based on given metadata. + * + * @param md given meta data + * @return NULL if meta data is useless for suggesting a filename + */ +char * +GNUNET_FS_meta_data_suggest_filename (const struct GNUNET_CONTAINER_MetaData + *md); + + +/** + * Function used to process entries in a directory. + * + * @param cls closure + * @param filename name of the file in the directory + * @param uri URI of the file + * @param metadata metadata for the file; metadata for + * the directory if everything else is NULL/zero + * @param length length of the available data for the file + * (of type size_t since data must certainly fit + * into memory; if files are larger than size_t + * permits, then they will certainly not be + * embedded with the directory itself). + * @param data data available for the file (length bytes) + */ +typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls, + const char *filename, + const struct GNUNET_FS_Uri * + uri, + const struct + GNUNET_CONTAINER_MetaData * + meta, size_t length, + const void *data); + + +/** + * Iterate over all entries in a directory. Note that directories + * are structured such that it is possible to iterate over the + * individual blocks as well as over the entire directory. Thus + * a client can call this function on the buffer in the + * GNUNET_FS_ProgressCallback. Also, directories can optionally + * include the contents of (small) files embedded in the directory + * itself; for those files, the processor may be given the + * contents of the file directly by this function. + * + * @param size number of bytes in data + * @param data pointer to the beginning of the directory + * @param offset offset of data in the directory + * @param dep function to call on each entry + * @param dep_cls closure for dep + * @return GNUNET_OK if this could be a block in a directory, + * GNUNET_NO if this could be part of a directory (but not 100% OK) + * GNUNET_SYSERR if 'data' does not represent a directory + */ +int +GNUNET_FS_directory_list_contents (size_t size, const void *data, + uint64_t offset, + GNUNET_FS_DirectoryEntryProcessor dep, + void *dep_cls); + + +/** + * Opaque handle to a directory builder. + */ +struct GNUNET_FS_DirectoryBuilder; + +/** + * Create a directory builder. + * + * @param mdir metadata for the directory + */ +struct GNUNET_FS_DirectoryBuilder * +GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData + *mdir); + + +/** + * Add an entry to a directory. + * + * @param bld directory to extend + * @param uri uri of the entry (must not be a KSK) + * @param md metadata of the entry + * @param data raw data of the entry, can be NULL, otherwise + * data must point to exactly the number of bytes specified + * by the uri + */ +void +GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, + const struct GNUNET_FS_Uri *uri, + const struct GNUNET_CONTAINER_MetaData *md, + const void *data); + + +/** + * Finish building the directory. Frees the + * builder context and returns the directory + * in-memory. + * + * @param bld directory to finish + * @param rsize set to the number of bytes needed + * @param rdata set to the encoded directory + * @return GNUNET_OK on success + */ +int +GNUNET_FS_directory_builder_finish (struct GNUNET_FS_DirectoryBuilder *bld, + size_t * rsize, void **rdata); + + +/* ******************** DirScanner API *********************** */ + +/** + * Progress reasons of the directory scanner. + */ +enum GNUNET_FS_DirScannerProgressUpdateReason +{ + + /** + * We've started processing a file or directory. + */ + GNUNET_FS_DIRSCANNER_FILE_START = 0, + + /** + * We're having trouble accessing a file (soft-error); it will + * be ignored. + */ + GNUNET_FS_DIRSCANNER_FILE_IGNORED, + + /** + * We've found all files (in the pre-pass). + */ + GNUNET_FS_DIRSCANNER_ALL_COUNTED, + + /** + * We've finished extracting meta data from a file. + */ + GNUNET_FS_DIRSCANNER_EXTRACT_FINISHED, + + /** + * Last call to the progress function: we have finished scanning + * the directory. + */ + GNUNET_FS_DIRSCANNER_FINISHED, + + /** + * There was an internal error. Application should abort the scan. + */ + GNUNET_FS_DIRSCANNER_INTERNAL_ERROR + +}; + + +/** + * Function called over time as the directory scanner makes + * progress on the job at hand. + * + * @param cls closure + * @param filename which file we are making progress on + * @param is_directory GNUNET_YES if this is a directory, + * GNUNET_NO if this is a file + * GNUNET_SYSERR if it is neither (or unknown) + * @param reason kind of progress we are making + */ +typedef void (*GNUNET_FS_DirScannerProgressCallback) (void *cls, + const char *filename, + int is_directory, + enum GNUNET_FS_DirScannerProgressUpdateReason reason); + + +/** + * A node of a directory tree (produced by dirscanner) + */ +struct GNUNET_FS_ShareTreeItem +{ + /** + * This is a doubly-linked list + */ + struct GNUNET_FS_ShareTreeItem *prev; + + /** + * This is a doubly-linked list + */ + struct GNUNET_FS_ShareTreeItem *next; + + /** + * This is a doubly-linked tree + * NULL for top-level entries. + */ + struct GNUNET_FS_ShareTreeItem *parent; + + /** + * This is a doubly-linked tree + * NULL for files and empty directories + */ + struct GNUNET_FS_ShareTreeItem *children_head; + + /** + * This is a doubly-linked tree + * NULL for files and empty directories + */ + struct GNUNET_FS_ShareTreeItem *children_tail; + + /** + * Metadata for this file or directory + */ + struct GNUNET_CONTAINER_MetaData *meta; + + /** + * Keywords for this file or directory (derived from metadata). + */ + struct GNUNET_FS_Uri *ksk_uri; + + /** + * Name of the file/directory + */ + char *filename; + + /** + * Base name of the file/directory. + */ + char *short_filename; + + /** + * GNUNET_YES if this is a directory + */ + int is_directory; + +}; + + +/** + * Opaqe handle to an asynchronous directory scanning activity. + */ +struct GNUNET_FS_DirScanner; + + +/** + * Start a directory scanner. + * + * @param filename name of the directory to scan + * @param disable_extractor GNUNET_YES to not to run libextractor on files (only build a tree) + * @param ex if not NULL, must be a list of extra plugins for extractor + * @param cb the callback to call when there are scanning progress messages + * @param cb_cls closure for 'cb' + * @return directory scanner object to be used for controlling the scanner + */ +struct GNUNET_FS_DirScanner * +GNUNET_FS_directory_scan_start (const char *filename, + int disable_extractor, + const char *ex, + GNUNET_FS_DirScannerProgressCallback cb, + void *cb_cls); + + +/** + * Abort the scan. Must not be called from within the progress_callback + * function. + * + * @param ds directory scanner structure + */ +void +GNUNET_FS_directory_scan_abort (struct GNUNET_FS_DirScanner *ds); + + +/** + * Obtain the result of the scan after the scan has signalled + * completion. Must not be called prior to completion. The 'ds' is + * freed as part of this call. + * + * @param ds directory scanner structure + * @return the results of the scan (a directory tree) + */ +struct GNUNET_FS_ShareTreeItem * +GNUNET_FS_directory_scan_get_result (struct GNUNET_FS_DirScanner *ds); + + +/** + * Process a share item tree, moving frequent keywords up and + * copying frequent metadata up. + * + * @param toplevel toplevel directory in the tree, returned by the scanner + */ +void +GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel); + + +/** + * Release memory of a share item tree. + * + * @param toplevel toplevel of the tree to be freed + */ +void +GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h new file mode 100644 index 0000000..4b1873c --- /dev/null +++ b/src/include/gnunet_getopt_lib.h @@ -0,0 +1,349 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2011 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/gnunet_getopt_lib.h + * @brief command line parsing and --help formatting + * + * @author Christian Grothoff + */ + +#ifndef GNUNET_GETOPT_LIB_H +#define GNUNET_GETOPT_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_configuration_lib.h" + +/** + * @brief General context for command line processors. + */ +struct GNUNET_GETOPT_CommandLineProcessorContext +{ + + /** + * Name of the application + */ + const char *binaryName; + + /** + * Name of application with option summary + */ + const char *binaryOptions; + + /** + * Array with all command line options. + */ + const struct GNUNET_GETOPT_CommandLineOption *allOptions; + + /** + * Original command line + */ + char *const *argv; + + /** + * Total number of argv's. + */ + unsigned int argc; + + /** + * Current argument. + */ + unsigned int currentArgument; + +}; + +/** + * @brief Process a command line option + * + * @param ctx context for all options + * @param scls specific closure (for this processor) + * @param option long name of the option (i.e. "config" for --config) + * @param value argument, NULL if none was given + * @return GNUNET_OK to continue processing other options, GNUNET_SYSERR to abort + */ +typedef int (*GNUNET_GETOPT_CommandLineOptionProcessor) (struct + GNUNET_GETOPT_CommandLineProcessorContext + * ctx, void *scls, + const char *option, + const char *value); + +/** + * @brief Definition of a command line option. + */ +struct GNUNET_GETOPT_CommandLineOption +{ + + /** + * Short name of the option (use '\\0' for none). + */ + const char shortName; + + /** + * Long name of the option (may not be NULL) + */ + const char *name; + + /** + * Name of the argument for the user in help text + */ + const char *argumentHelp; + + /** + * Help text for the option (description) + */ + const char *description; + + /** + * Is an argument required? 0: GNUNET_NO (includes optional), 1: GNUNET_YES. + */ + int require_argument; + + /** + * Handler for the option. + */ + GNUNET_GETOPT_CommandLineOptionProcessor processor; + + /** + * Specific closure to pass to the processor. + */ + void *scls; + +}; + +/** + * Macro defining the option to print the command line + * help text (-h option). + * + * @param about string with brief description of the application + */ +#define GNUNET_GETOPT_OPTION_HELP(about) \ + { 'h', "help", (const char *) NULL, gettext_noop("print this help"), 0, &GNUNET_GETOPT_format_help_, (void *) about } + + +/** + * Macro defining the option to print the version of + * the application (-v option) + * + * @param version string with the version number + */ +#define GNUNET_GETOPT_OPTION_VERSION(version) \ + { 'v', "version", (const char *) NULL, gettext_noop("print the version number"), 0, &GNUNET_GETOPT_print_version_, (void *) version } + + +/** + * Allow user to specify log file name (-l option) + * + * @param logfn set to the name of the logfile + */ +#define GNUNET_GETOPT_OPTION_LOGFILE(logfn) \ + { 'l', "logfile", "LOGFILE", gettext_noop("configure logging to write logs to LOGFILE"), 1, &GNUNET_GETOPT_set_string, (void *) logfn } + + +/** + * Allow user to specify log level (-L option) + * + * @param loglev set to the log level + */ +#define GNUNET_GETOPT_OPTION_LOGLEVEL(loglev) \ + { 'L', "log", "LOGLEVEL", gettext_noop("configure logging to use LOGLEVEL"), 1, &GNUNET_GETOPT_set_string, (void *) loglev } + + +/** + * Get number of verbose (-V) flags + * + * @param level where to store the verbosity level (should be an 'int') + */ +#define GNUNET_GETOPT_OPTION_VERBOSE(level) \ + { 'V', "verbose", (const char *) NULL, gettext_noop("be verbose"), 0, &GNUNET_GETOPT_increment_value, (void *) level } + + +/** + * Get configuration file name (-c option) + * + * @param fn set to the configuration file name + */ +#define GNUNET_GETOPT_OPTION_CFG_FILE(fn) \ + { 'c', "config", "FILENAME", gettext_noop("use configuration file FILENAME"), 1, &GNUNET_GETOPT_set_string, (void *) fn } + + +/** + * Marker for the end of the list of options. + */ +#define GNUNET_GETOPT_OPTION_END \ + { '\0', NULL, NULL, NULL, 0, NULL, NULL } + + +/** + * Parse the command line. + * + * @param binaryOptions Name of application with option summary + * @param allOptions defined options and handlers + * @param argc number of arguments + * @param argv actual arguments + * @return index into argv with first non-option + * argument, or GNUNET_SYSERR on error + */ +int +GNUNET_GETOPT_run (const char *binaryOptions, + const struct GNUNET_GETOPT_CommandLineOption *allOptions, + unsigned int argc, char *const *argv); + + +/** + * Set an option of type 'unsigned long long' 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 'unsigned long long'. + * + * @param ctx command line processing context + * @param scls additional closure (will point to the 'unsigned long long') + * @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_ulong (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 + * of this type. It should be followed by a pointer to a value of + * type 'unsigned int'. + * + * @param ctx command line processing context + * @param scls additional closure (will point to the 'unsigned int') + * @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_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, + void *scls, const char *option, const char *value); + + +/** + * Set an option of type 'int' from the command line to 1 if the + * given option is present. + * 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 'int'. + * + * @param ctx command line processing context + * @param scls additional closure (will point to the 'int') + * @param option name of the option + * @param value not used (NULL) + * @return GNUNET_OK + */ +int +GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, + void *scls, const char *option, const char *value); + + +/** + * Set an option of type 'char *' 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 'char *'. + * + * @param ctx command line processing context + * @param scls additional closure (will point to the 'char *', + * which will be allocated) + * @param option name of the option + * @param value actual value of the option (a string) + * @return GNUNET_OK + */ +int +GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, + void *scls, const char *option, const char *value); + +/** + * Set an option of type 'unsigned int' from the command line. Each + * time the option flag is given, the value is incremented by one. + * 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 'int'. + * + * @param ctx command line processing context + * @param scls additional closure (will point to the 'int') + * @param option name of the option + * @param value not used (NULL) + * @return GNUNET_OK + */ +int +GNUNET_GETOPT_increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext + *ctx, void *scls, const char *option, + const char *value); + + +/* *************** internal prototypes - use macros above! ************* */ + +/** + * Print out details on command line options (implements --help). + * + * @param ctx command line processing context + * @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) + */ +int +GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext + *ctx, void *scls, const char *option, + const char *value); + +/** + * Print out program version (implements --version). + * + * @param ctx command line processing context + * @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) + */ +int +GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext + *ctx, void *scls, const char *option, + const char *value); + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + +/* ifndef GNUNET_GETOPT_LIB_H */ +#endif +/* end of gnunet_getopt_lib.h */ diff --git a/src/include/gnunet_gns_service.h b/src/include/gnunet_gns_service.h new file mode 100644 index 0000000..2422178 --- /dev/null +++ b/src/include/gnunet_gns_service.h @@ -0,0 +1,163 @@ +/* + 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_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 + +#include "gnunet_util_lib.h" +#include "gnunet_namestore_service.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * Connection to the GNS service. + */ +struct GNUNET_GNS_Handle; + +/** + * Handle to control a get operation. + */ +struct GNUNET_GNS_LookupHandle; + +/** + * Record types + * Based on GNUNET_DNSPARSER_TYPEs (standard DNS) + */ +enum GNUNET_GNS_RecordType +{ + /* Standard DNS */ + GNUNET_GNS_RECORD_TYPE_A = 1, + GNUNET_GNS_RECORD_TYPE_NS = 2, + GNUNET_GNS_RECORD_TYPE_CNAME = 5, + GNUNET_GNS_RECORD_TYPE_SOA = 6, + GNUNET_GNS_RECORD_TYPE_PTR = 12, + GNUNET_GNS_RECORD_MX = 15, + GNUNET_GNS_RECORD_TXT = 16, + GNUNET_GNS_RECORD_AAAA = 28, + + /* GNS specific */ + GNUNET_GNS_RECORD_PKEY = 256 +}; + +/** + * Initialize the connection with the GNS service. + * FIXME: Do we need the ht_len? + * + * @param cfg configuration to use + * @param ht_len size of the internal hash table to use for parallel lookups + * @return NULL on error + */ +struct GNUNET_GNS_Handle * +GNUNET_GNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + unsigned int ht_len); + + +/** + * Shutdown connection with the GNS service. + * + * @param handle connection to shut down + */ +void +GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle); + + +/* *************** Standard API: lookup ******************* */ + +/** + * Iterator called on each result obtained for a GNS + * lookup + * + * @param cls closure + * @param name "name" of the original lookup + * @param record the records in reply + * @param num_records the number of records in reply + */ +typedef void (*GNUNET_GNS_LookupIterator) (void *cls, + const char * name, + const struct GNUNET_NAMESTORE_RecordData *record, + unsigned int num_records); + + + +/** + * Perform an asynchronous lookup operation on the GNS. + * + * @param handle handle to the GNS service + * @param timeout how long to wait for transmission of this request to the service + * // FIXME: what happens afterwards? + * @param handle handle to the GNS service + * @param timeout timeout of request + * @param name the name to look up + * @param type the GNUNET_GNS_RecordType to look for + * @param iter function to call on each result + * @param iter_cls closure for iter + * + * @return handle to stop the async lookup + */ +struct GNUNET_GNS_LookupHandle * +GNUNET_GNS_lookup_start (struct GNUNET_GNS_Handle *handle, + struct GNUNET_TIME_Relative timeout, + const char * name, + enum GNUNET_GNS_RecordType type, + GNUNET_GNS_LookupIterator iter, + void *iter_cls); + + +/** + * Stop async GNS lookup. Frees associated resources. + * + * @param lookup_handle lookup operation to stop. + * + * On return lookup_handle will no longer be valid, caller + * must not use again!!! + */ +void +GNUNET_GNS_lookup_stop (struct GNUNET_GNS_LookupHandle *lookup_handle); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + +#endif +/* gnunet_gns_service.h */ diff --git a/src/include/gnunet_hello_lib.h b/src/include/gnunet_hello_lib.h new file mode 100644 index 0000000..ffddb0b --- /dev/null +++ b/src/include/gnunet_hello_lib.h @@ -0,0 +1,336 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2010, 2011 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_hello_lib.h + * @brief helper library for handling HELLOs + * @author Christian Grothoff + */ + +#ifndef GNUNET_HELLO_LIB_H +#define GNUNET_HELLO_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" +#include "gnunet_crypto_lib.h" + + +/** + * 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 + * on the wire. + */ +struct GNUNET_HELLO_Address +{ + + /** + * For which peer is this an address? + */ + struct GNUNET_PeerIdentity peer; + + /** + * Name of the transport plugin enabling the communication using + * this address. + */ + const char *transport_name; + + /** + * Binary representation of the address (plugin-specific). + */ + const void *address; + + /** + * Number of bytes in 'address'. + */ + size_t address_length; + +}; + + +/** + * Allocate an address struct. + * + * @param peer the peer + * @param transport_name plugin name + * @param address binary address + * @param address_length number of bytes in 'address' + * @return the address struct + */ +struct GNUNET_HELLO_Address * +GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, + const char *transport_name, const void *address, + size_t address_length); + + +/** + * Copy an address struct. + * + * @param address address to copy + * @return a copy of the address struct + */ +struct GNUNET_HELLO_Address * +GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address); + + +/** + * Compare two addresses. Does NOT compare the peer identity, + * that is assumed already to match! + * + * @param a1 first address + * @param a2 second address + * @return 0 if the addresses are equal, -1 if a1<a2, 1 if a1>a2. + */ +int +GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1, + const struct GNUNET_HELLO_Address *a2); + + +/** + * Get the size of an address struct. + * + * @param address address + * @return the size + */ +size_t +GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address); + +/** + * Free an address. + * + * @param addr address to free + */ +#define GNUNET_HELLO_address_free(addr) GNUNET_free(addr) + + +/** + * A HELLO message is used to exchange information about + * transports with other peers. This struct is guaranteed + * to start with a "GNUNET_MessageHeader", everything else + * should be internal to the HELLO library. + */ +struct GNUNET_HELLO_Message; + + +/** + * Copy the given address information into + * the given buffer using the format of HELLOs. + * + * @param address address to add + * @param expiration expiration for the address + * @param target where to copy the address + * @param max maximum number of bytes to copy to target + * @return number of bytes copied, 0 if + * the target buffer was not big enough. + */ +size_t +GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration, char *target, + size_t max); + + +/** + * Callback function used to fill a buffer of max bytes with a list of + * addresses in the format used by HELLOs. Should use + * "GNUNET_HELLO_add_address" as a helper function. + * + * @param cls closure + * @param max maximum number of bytes that can be written to buf + * @param buf where to write the address information + * @return number of bytes written, 0 to signal the + * end of the iteration. + */ +typedef size_t (*GNUNET_HELLO_GenerateAddressListCallback) (void *cls, + size_t max, + void *buf); + + +/** + * Construct a HELLO message given the public key, + * expiration time and an iterator that spews the + * transport addresses. + * + * @return the hello message + */ +struct GNUNET_HELLO_Message * +GNUNET_HELLO_create (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded + *publicKey, + GNUNET_HELLO_GenerateAddressListCallback addrgen, + void *addrgen_cls); + + +/** + * Return the size of the given HELLO message. + * @param hello to inspect + * @return the size, 0 if HELLO is invalid + */ +uint16_t +GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello); + + +/** + * Construct a HELLO message by merging the + * addresses in two existing HELLOs (which + * must be for the same peer). + * + * @param h1 first HELLO message + * @param h2 the second HELLO message + * @return the combined hello message + */ +struct GNUNET_HELLO_Message * +GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1, + const struct GNUNET_HELLO_Message *h2); + + +/** + * Test if two HELLO messages contain the same addresses. + * If they only differ in expiration time, the lowest + * expiration time larger than 'now' where they differ + * is returned. + * + * @param h1 first HELLO message + * @param h2 the second HELLO message + * @param now time to use for deciding which addresses have + * expired and should not be considered at all + * @return absolute time forever if the two HELLOs are + * totally identical; smallest timestamp >= now if + * they only differ in timestamps; + * zero if the some addresses with expirations >= now + * do not match at all + */ +struct GNUNET_TIME_Absolute +GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1, + const struct GNUNET_HELLO_Message *h2, + struct GNUNET_TIME_Absolute now); + + +/** + * Iterator callback to go over all addresses. + * + * @param cls closure + * @param address the address + * @param expiration expiration time + * @return GNUNET_OK to keep the address, + * GNUNET_NO to delete it from the HELLO + * GNUNET_SYSERR to stop iterating (but keep current address) + */ +typedef int (*GNUNET_HELLO_AddressIterator) (void *cls, + const struct GNUNET_HELLO_Address * + address, + struct GNUNET_TIME_Absolute + expiration); + + +/** + * When does the last address in the given HELLO expire? + * + * @param msg HELLO to inspect + * @return time the last address expires, 0 if there are no addresses in the HELLO + */ +struct GNUNET_TIME_Absolute +GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg); + + +/** + * Iterate over all of the addresses in the HELLO. + * + * @param msg HELLO to iterate over; client does not need to + * have verified that msg is well-formed (beyond starting + * with a GNUNET_MessageHeader of the right type). + * @param return_modified if a modified copy should be returned, + * otherwise NULL will be returned + * @param it iterator to call on each address + * @param it_cls closure for it + * @return the modified HELLO or NULL + */ +struct GNUNET_HELLO_Message * +GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg, + int return_modified, + GNUNET_HELLO_AddressIterator it, void *it_cls); + + +/** + * Iterate over addresses in "new_hello" that + * are NOT already present in "old_hello". + * + * @param new_hello a HELLO message + * @param old_hello a HELLO message + * @param expiration_limit ignore addresses in old_hello + * that expired before the given time stamp + * @param it iterator to call on each address + * @param it_cls closure for it + */ +void +GNUNET_HELLO_iterate_new_addresses (const struct GNUNET_HELLO_Message + *new_hello, + const struct GNUNET_HELLO_Message + *old_hello, + struct GNUNET_TIME_Absolute + expiration_limit, + GNUNET_HELLO_AddressIterator it, + void *it_cls); + + +/** + * Get the public key from a HELLO message. + * + * @param hello the hello message + * @param publicKey where to copy the public key information, can be NULL + * @return GNUNET_SYSERR if the HELLO was malformed + */ +int +GNUNET_HELLO_get_key (const struct GNUNET_HELLO_Message *hello, + struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded + *publicKey); + + +/** + * Get the peer identity from a HELLO message. + * + * @param hello the hello message + * @param peer where to store the peer's identity + * @return GNUNET_SYSERR if the HELLO was malformed + */ +int +GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello, + struct GNUNET_PeerIdentity *peer); + + +/** + * Get the header from a HELLO message, used so other code + * can correctly send HELLO messages. + * + * @param hello the hello message + * + * @return header or NULL if the HELLO was malformed + */ +struct GNUNET_MessageHeader * +GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello); + +/* 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 new file mode 100644 index 0000000..7115748 --- /dev/null +++ b/src/include/gnunet_helper_lib.h @@ -0,0 +1,96 @@ +/* + This file is part of GNUnet. + (C) 2011, 2012 Christian Grothoff + + 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_helper_lib.h + * @brief API for dealing with (SUID) helper processes that communicate via GNUNET_MessageHeaders on stdin/stdout + * @author Philipp Toelke + * @author Christian Grothoff + */ +#ifndef GNUNET_HELPER_LIB_H +#define GNUNET_HELPER_LIB_H + +#include "gnunet_scheduler_lib.h" +#include "gnunet_server_lib.h" + +/** + * The handle to a helper process. + */ +struct GNUNET_HELPER_Handle; + + +/** + * @brief Starts a helper and begins reading from it + * + * @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 + * @return the new Handle, NULL on error + */ +struct GNUNET_HELPER_Handle * +GNUNET_HELPER_start (const char *binary_name, + char *const binary_argv[], + GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls); + + +/** + * @brief Kills the helper, closes the pipe and frees the handle + * + * @param h handle to helper to stop + */ +void +GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h); + + +/** + * Continuation function. + * + * @param cls closure + * @param result GNUNET_OK on success, + * GNUNET_NO if helper process died + * GNUNET_SYSERR during GNUNET_HELPER_stop + */ +typedef void (*GNUNET_HELPER_Continuation)(void *cls, + int result); + + +/** + * Send an message to the helper. + * + * @param h helper to send message to + * @param msg message to send + * @param can_drop can the message be dropped if there is already one in the queue? + * @param cont continuation to run once the message is out + * @param cont_cls closure for 'cont' + * @return GNUNET_YES if the message will be sent + * GNUNET_NO if the message was dropped + */ +int +GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h, + const struct GNUNET_MessageHeader *msg, + int can_drop, + GNUNET_HELPER_Continuation cont, + void *cont_cls); + + +#endif /* end of include guard: GNUNET_HELPER_LIB_H */ diff --git a/src/include/gnunet_load_lib.h b/src/include/gnunet_load_lib.h new file mode 100644 index 0000000..6dfe80c --- /dev/null +++ b/src/include/gnunet_load_lib.h @@ -0,0 +1,119 @@ +/* + This file is part of GNUnet. + (C) 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_load_lib.h + * @brief functions related to load calculations + * @author Christian Grothoff + */ + +#ifndef GNUNET_LOAD_LIB_H +#define GNUNET_LOAD_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" +#include "gnunet_time_lib.h" + +/** + * Opaque load handle. + */ +struct GNUNET_LOAD_Value; + +/** + * Create a new load value. + * + * @param autodecline speed at which this value should automatically + * decline in the absence of external events; at the given + * frequency, 0-load values will be added to the load + * @return the new load value + */ +struct GNUNET_LOAD_Value * +GNUNET_LOAD_value_init (struct GNUNET_TIME_Relative autodecline); + + +/** + * Change the value by which the load automatically declines. + * + * @param load load to update + * @param autodecline frequency of load decline + */ +void +GNUNET_LOAD_value_set_decline (struct GNUNET_LOAD_Value *load, + struct GNUNET_TIME_Relative autodecline); + + +/** + * Free a load value. + * + * @param lv value to free + */ +#define GNUNET_LOAD_value_free(lv) GNUNET_free (lv) + + +/** + * Get the current load. + * + * @param load load handle + * @return zero for below-average load, otherwise + * number of std. devs we are above average; + * 100 if the latest updates were so large + * that we could not do proper calculations + */ +double +GNUNET_LOAD_get_load (struct GNUNET_LOAD_Value *load); + + +/** + * Get the average value given to update so far. + * + * @param load load handle + * @return zero if update was never called + */ +double +GNUNET_LOAD_get_average (struct GNUNET_LOAD_Value *load); + + +/** + * Update the current load. + * + * @param load to update + * @param data latest measurement value (for example, delay) + */ +void +GNUNET_LOAD_update (struct GNUNET_LOAD_Value *load, uint64_t data); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_LOAD_LIB_H */ +#endif +/* end of gnunet_load_lib.h */ diff --git a/src/include/gnunet_mesh_service.h b/src/include/gnunet_mesh_service.h new file mode 100644 index 0000000..7c2437e --- /dev/null +++ b/src/include/gnunet_mesh_service.h @@ -0,0 +1,358 @@ +/* + This file is part of GNUnet. + (C) 2009, 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file include/gnunet_mesh_service.h + * @brief mesh service; establish tunnels to distant peers + * @author Christian Grothoff + */ + +#ifndef GNUNET_MESH_SERVICE_H +#define GNUNET_MESH_SERVICE_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_util_lib.h" +#include "gnunet_transport_service.h" + +/** + * Version number of GNUnet-mesh API. + */ +#define GNUNET_MESH_VERSION 0x00000000 + + +/** + * Opaque handle to the service. + */ +struct GNUNET_MESH_Handle; + +/** + * Opaque handle to a tunnel. + */ +struct GNUNET_MESH_Tunnel; + +/** + * Functions with this signature are called whenever a message is + * received. + * + * @param cls closure (set from GNUNET_MESH_connect) + * @param tunnel connection to the other end + * @param tunnel_ctx place to store local state associated with the tunnel + * @param sender who sent the message + * @param message the actual message + * @param atsi performance data for the connection + * @return GNUNET_OK to keep the connection open, + * GNUNET_SYSERR to close it (signal serious error) + */ +typedef int (*GNUNET_MESH_MessageCallback) (void *cls, + struct GNUNET_MESH_Tunnel * tunnel, + void **tunnel_ctx, + const struct GNUNET_PeerIdentity * + sender, + const struct GNUNET_MessageHeader * + message, + const struct GNUNET_ATS_Information + * atsi); + + +/** + * Message handler. Each struct specifies how to handle on particular + * type of message received. + */ +struct GNUNET_MESH_MessageHandler +{ + /** + * Function to call for messages of "type". + */ + GNUNET_MESH_MessageCallback callback; + + /** + * Type of the message this handler covers. + */ + uint16_t type; + + /** + * Expected size of messages of this type. Use 0 for variable-size. + * If non-zero, messages of the given type will be discarded if they + * do not have the right size. + */ + uint16_t expected_size; + +}; + + +/** + * Method called whenever another peer has added us to a tunnel + * the other peer initiated. + * + * @param cls closure + * @param tunnel new handle to the tunnel + * @param initiator peer that started the tunnel + * @param atsi performance information for the tunnel + * @return initial tunnel context for the tunnel + * (can be NULL -- that's not an error) + */ +typedef void *(GNUNET_MESH_InboundTunnelNotificationHandler) (void *cls, + struct + GNUNET_MESH_Tunnel + * tunnel, + const struct + GNUNET_PeerIdentity + * initiator, + const struct + GNUNET_ATS_Information + * atsi); + + +/** + * Function called whenever an inbound tunnel is destroyed. Should clean up + * any associated state. This function is NOT called if the client has + * explicitly asked for the tunnel to be destroyed using + * GNUNET_MESH_tunnel_destroy. It must NOT call GNUNET_MESH_tunnel_destroy on + * the tunnel. + * + * @param cls closure (set from GNUNET_MESH_connect) + * @param tunnel connection to the other end (henceforth invalid) + * @param tunnel_ctx place where local state associated + * with the tunnel is stored + */ +typedef void (GNUNET_MESH_TunnelEndHandler) (void *cls, + const struct GNUNET_MESH_Tunnel * + tunnel, void *tunnel_ctx); + + +/** + * Type for an application. Values defined in gnunet_applications.h + */ +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 + * @param cleaner function called when an *inbound* tunnel is destroyed by the + * remote peer, it is *not* called if GNUNET_MESH_tunnel_destroy + * is called on the tunnel + * @param handlers callbacks for messages we care about, NULL-terminated + * note that the mesh is allowed to drop notifications about + * inbound messages if the client does not process them fast + * enough (for this notification type, a bounded queue is used) + * @param stypes list of the applications that this client claims to provide + * @return handle to the mesh service NULL on error + * (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_InboundTunnelNotificationHandler new_tunnel, + GNUNET_MESH_TunnelEndHandler cleaner, + const struct GNUNET_MESH_MessageHandler *handlers, + const GNUNET_MESH_ApplicationType *stypes); + + +/** + * Disconnect from the mesh service. All tunnels will be destroyed. All tunnel + * disconnect callbacks will be called on any still connected peers, notifying + * about their disconnection. The registered inbound tunnel cleaner will be + * called should any inbound tunnels still exist. + * + * @param handle connection to mesh to disconnect + */ +void +GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle); + + +/** + * Method called whenever a peer has disconnected from the tunnel. + * Implementations of this callback must NOT call + * GNUNET_MESH_tunnel_destroy immediately, but instead schedule those + * to run in some other task later. However, calling + * "GNUNET_MESH_notify_transmit_ready_cancel" is allowed. + * + * @param cls closure + * @param peer peer identity the tunnel stopped working with + */ +typedef void (*GNUNET_MESH_PeerDisconnectHandler) (void *cls, + const struct + GNUNET_PeerIdentity * peer); + + +/** + * Method called whenever a peer has connected to the tunnel. + * + * @param cls closure + * @param peer peer identity the tunnel was created to, NULL on timeout + * @param atsi performance data for the connection + * + * TODO: change to return int to let client allow the new peer or not? + */ +typedef void (*GNUNET_MESH_PeerConnectHandler) (void *cls, + const struct GNUNET_PeerIdentity + * peer, + const struct + GNUNET_ATS_Information * atsi); + + + +/** + * Create a new tunnel (we're initiator and will be allowed to add/remove peers + * and to broadcast). + * + * @param h mesh handle + * @param tunnel_ctx client's tunnel context to associate with the tunnel + * @param connect_handler function to call when peers are actually connected + * @param disconnect_handler function to call when peers are disconnected + * @param handler_cls closure for connect/disconnect handlers + */ +struct GNUNET_MESH_Tunnel * +GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx, + GNUNET_MESH_PeerConnectHandler connect_handler, + GNUNET_MESH_PeerDisconnectHandler disconnect_handler, + void *handler_cls); + +/** + * Destroy an existing tunnel. The existing callback for the tunnel will NOT + * be called. + * + * @param tunnel tunnel handle + */ +void +GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel); + + +/** + * Request that a peer should be added to the tunnel. The connect handler + * will be called when the peer connects + * + * @param tunnel handle to existing tunnel + * @param peer peer to add + */ +void +GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel, + const struct GNUNET_PeerIdentity *peer); + + +/** + * Request that a peer should be removed from the tunnel. The existing + * disconnect handler will be called ONCE if we were connected. + * + * @param tunnel handle to existing tunnel + * @param peer peer to remove + */ +void +GNUNET_MESH_peer_request_connect_del (struct GNUNET_MESH_Tunnel *tunnel, + const struct GNUNET_PeerIdentity *peer); + + +/** + * Request that the mesh should try to connect to a peer supporting the given + * message type. + * + * @param tunnel handle to existing tunnel + * @param app_type application type that must be supported by the peer + * (MESH should discover peer in proximity handling this type) + */ +void +GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel, + GNUNET_MESH_ApplicationType app_type); + + +/** + * Handle for a transmission request. + */ +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. + * + * @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 + * @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 + * @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. + */ +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, + GNUNET_CONNECTION_TransmitReadyNotify notify, + void *notify_cls); + + +/** + * Cancel the specified transmission-ready notification. + * + * @param th handle that was returned by "notify_transmit_ready". + */ +void +GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle + *th); + + +/** + * Transition API for tunnel ctx management + */ +void +GNUNET_MESH_tunnel_set_data (struct GNUNET_MESH_Tunnel *tunnel, void *data); + +/** + * Transition API for tunnel ctx management + */ +void * +GNUNET_MESH_tunnel_get_data (struct GNUNET_MESH_Tunnel *tunnel); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_MESH_SERVICE_H */ +#endif +/* end of gnunet_mesh_service.h */ diff --git a/src/include/gnunet_namestore_plugin.h b/src/include/gnunet_namestore_plugin.h new file mode 100644 index 0000000..5468513 --- /dev/null +++ b/src/include/gnunet_namestore_plugin.h @@ -0,0 +1,152 @@ +/* + 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/gnunet_namestore_plugin.h + * @brief plugin API for the namestore database backend + * @author Christian Grothoff + */ +#ifndef GNUNET_NAMESTORE_PLUGIN_H +#define GNUNET_NAMESTORE_PLUGIN_H + +#include "gnunet_common.h" +#include "gnunet_util_lib.h" +#include "gnunet_namestore_service.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * Function called by for each matching record. + * + * @param cls closure + * @param zone_key public key of the zone + * @param expire when does the corresponding block in the DHT expire (until + * when should we never do a DHT lookup for the same name again)? + * @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 + * @param signature signature of the record block, NULL if signature is unavailable (i.e. + * because the user queried for a particular record type only) + */ +typedef void (*GNUNET_NAMESTORE_RecordIterator) (void *cls, + const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, + struct GNUNET_TIME_Absolute expire, + const char *name, + unsigned int rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd, + const struct GNUNET_CRYPTO_RsaSignature *signature); + + +/** + * @brief struct returned by the initialization function of the plugin + */ +struct GNUNET_NAMESTORE_PluginFunctions +{ + + /** + * Closure to pass to all plugin functions. + */ + void *cls; + + /** + * Store a record in the datastore. Removes any existing record in the + * same zone with the same name. + * + * @param cls closure (internal context for the plugin) + * @param zone_key public key of the zone + * @param expire when does the corresponding block in the DHT expire (until + * when should we never do a DHT lookup for the same name again)? + * @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 + * @param signature signature of the record block, NULL if signature is unavailable (i.e. + * because the user queried for a particular record type only) + * @return GNUNET_OK on success + */ + int (*put_records) (void *cls, + const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, + struct GNUNET_TIME_Absolute expire, + const char *name, + unsigned int rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd, + const struct GNUNET_CRYPTO_RsaSignature *signature); + + + /** + * Removes any existing record in the given zone with the same name. + * + * @param cls closure (internal context for the plugin) + * @param zone hash of the public key of the zone + * @param name name to remove (at most 255 characters long) + * @return GNUNET_OK on success + */ + int (*remove_records) (void *cls, + const GNUNET_HashCode *zone, + const char *name); + + + /** + * Iterate over the results for a particular key and zone in the + * datastore. Will return at most one result to the iterator. + * + * @param cls closure (internal context for the plugin) + * @param zone hash of public key of the zone, NULL to iterate over all zones + * @param name_hash hash of name, NULL to iterate over all records of the zone + * @param offset offset in the list of all matching records + * @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 + */ + int (*iterate_records) (void *cls, + const GNUNET_HashCode *zone, + const GNUNET_HashCode *name_hash, + uint64_t offset, + GNUNET_NAMESTORE_RecordIterator iter, void *iter_cls); + + + /** + * Delete an entire zone (all records). Not used in normal operation. + * + * @param cls closure (internal context for the plugin) + * @param zone zone to delete + */ + void (*delete_zone) (void *cls, + const GNUNET_HashCode *zone); + + +}; + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* end of gnunet_namestore_plugin.h */ +#endif diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h new file mode 100644 index 0000000..8ab2ce8 --- /dev/null +++ b/src/include/gnunet_namestore_service.h @@ -0,0 +1,368 @@ +/* + 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/gnunet_namestore_service.h + * @brief API that can be used to store naming information on a GNUnet node; + * @author Christian Grothoff + * + * 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 +#define GNUNET_NAMESTORE_SERVICE_H + +#include "gnunet_util_lib.h" +#include "gnunet_block_lib.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +/** + * Entry in the queue. + */ +struct GNUNET_NAMESTORE_QueueEntry; + +/** + * Handle to the namestore service. + */ +struct GNUNET_NAMESTORE_Handle; + +/** + * Handle to the namestore zone iterator. + */ +struct GNUNET_NAMESTORE_ZoneIterator; + +/** + * Maximum size of a value that can be stored in the namestore. + */ +#define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024) + +/** + * Connect to the namestore service. + * + * @param cfg configuration to use + * @return handle to use to access the service + */ +struct GNUNET_NAMESTORE_Handle * +GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Disconnect from the namestore service (and free associated + * 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); + + +/** + * Continuation called to notify client about result of the + * operation. + * + * @param cls closure + * @param success GNUNET_SYSERR on failure (including timeout/queue drop/failure to validate) + * GNUNET_NO if content was already there + * GNUNET_YES (or other positive value) on success + * @param emsg NULL on success, otherwise an error message + */ +typedef void (*GNUNET_NAMESTORE_ContinuationWithStatus) (void *cls, + int32_t success, + const char *emsg); + + +/** + * Flags that can be set for a record. + */ +enum GNUNET_NAMESTORE_RecordFlags +{ + + /** + * No special options. + */ + GNUNET_NAMESTORE_RF_NONE = 0, + + /** + * This peer is the authority for this record; it must thus + * not be deleted (other records can be deleted if we run + * out of space). + */ + GNUNET_NAMESTORE_RF_AUTHORITY = 1, + + /** + * This is a private record of this peer and it should + * thus not be handed out to other peers. + */ + GNUNET_NAMESTORE_RF_PRIVATE = 2 + +}; + + +/** + * A GNS record. + */ +struct GNUNET_NAMESTORE_RecordData +{ + + /** + * Binary value stored in the DNS record. + */ + const void *data; + + /** + * Expiration time for the DNS record. + */ + struct GNUNET_TIME_Absolute expiration; + + /** + * Number of bytes in 'data'. + */ + size_t data_size; + + /** + * Type of the GNS/DNS record. + */ + uint32_t record_type; + + /** + * Flags for the record. + */ + enum GNUNET_NAMESTORE_RecordFlags flags; +}; + + +/** + * 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 when we cache signatures from other + * authorities. + * + * @param h handle to the namestore + * @param zone_key public key of the zone + * @param name name that is being mapped (at most 255 characters long) + * @param expire when does the corresponding block in the DHT expire (until + * when should we never do a DHT lookup for the same name again)? + * @param rd_count number of entries in 'rd' array + * @param rd array of records with data to store + * @param signature signature for all the records in the zone under the given name + * @param cont continuation to call when done + * @param cont_cls closure for cont + * @return handle to abort the request + */ +struct GNUNET_NAMESTORE_QueueEntry * +GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, + const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, + const char *name, + struct GNUNET_TIME_Absolute expire, + unsigned int rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd, + const struct GNUNET_CRYPTO_RsaSignature *signature, + GNUNET_NAMESTORE_ContinuationWithStatus cont, + void *cont_cls); + + +/** + * Check if a signature is valid. This API is used by the GNS Block + * to validate signatures received from the network. + * + * @param public_key public key of the zone + * @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 + * @param signature signature for all the records in the zone under the given name + * @return GNUNET_OK if the signature is valid + */ +int +GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, + const char *name, + unsigned int rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd, + const struct GNUNET_CRYPTO_RsaSignature *signature); + + +/** + * 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. + * + * @param h handle to the namestore + * @param pkey private key of the zone + * @param name name that is being mapped (at most 255 characters long) + * @param rd record data to store + * @param cont continuation to call when done + * @param cont_cls closure for cont + * @return handle to abort the request + */ +struct GNUNET_NAMESTORE_QueueEntry * +GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h, + const struct GNUNET_CRYPTO_RsaPrivateKey *pkey, + const char *name, + const struct GNUNET_NAMESTORE_RecordData *rd, + GNUNET_NAMESTORE_ContinuationWithStatus cont, + void *cont_cls); + + +/** + * Explicitly remove some content from the database. The + * "cont"inuation will be called with status "GNUNET_OK" if content + * was removed, "GNUNET_NO" if no matching entry was found and + * "GNUNET_SYSERR" on all other types of errors. + * This API is used by the authority of a zone. + * + * @param h handle to the namestore + * @param pkey private key of the zone + * @param name name that is being mapped (at most 255 characters long) + * @param rd record data + * @param cont continuation to call when done + * @param cont_cls closure for cont + * @return handle to abort the request + */ +struct GNUNET_NAMESTORE_QueueEntry * +GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h, + const struct GNUNET_CRYPTO_RsaPrivateKey *pkey, + const char *name, + const struct GNUNET_NAMESTORE_RecordData *rd, + GNUNET_NAMESTORE_ContinuationWithStatus cont, + void *cont_cls); + + +/** + * Process a record that was stored in the namestore. + * + * @param cls closure + * @param zone_key public key of the zone + * @param expire 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 + * records matching the desired record type) + * @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 + * @param signature signature of the record block, NULL if signature is unavailable (i.e. + * because the user queried for a particular record type only) + */ +typedef void (*GNUNET_NAMESTORE_RecordProcessor) (void *cls, + const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, + struct GNUNET_TIME_Absolute expire, + const char *name, + unsigned int rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd, + const struct GNUNET_CRYPTO_RsaSignature *signature); + + +/** + * Get a result for a particular key from the namestore. The processor + * will only be called once. + * + * @param h handle to the namestore + * @param zone zone to look up a record from + * @param name name to look up + * @param record_type desired record type, 0 for all + * @param proc function to call on the matching records, or with + * NULL (rd_count == 0) if there are no matching records + * @param proc_cls closure for proc + * @return a handle that can be used to + * cancel + */ +struct GNUNET_NAMESTORE_QueueEntry * +GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, + const GNUNET_HashCode *zone, + const char *name, + uint32_t record_type, + GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls); + + +/** + * Starts a new zone iteration (used to periodically PUT all of our + * records into our DHT). This MUST lock the GNUNET_NAMESTORE_Handle + * for any other calls than GNUNET_NAMESTORE_zone_iterator_next and + * GNUNET_NAMESTORE_zone_iteration_stop. "proc" will be called once + * immediately, and then again after + * "GNUNET_NAMESTORE_zone_iterator_next" is invoked. + * + * @param h handle to the namestore + * @param zone zone to access, NULL for all zones + * @param must_have_flags flags that must be set for the record to be returned + * @param must_not_have_flags flags that must NOT be set for the record to be returned + * @param proc function to call on each name from the zone; it + * will be called repeatedly with a value (if available) + * and always once at the end with a name of NULL. + * @param proc_cls closure for proc + * @return an iterator handle to use for iteration + */ +struct GNUNET_NAMESTORE_ZoneIterator * +GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, + const GNUNET_HashCode *zone, + enum GNUNET_NAMESTORE_RecordFlags must_have_flags, + enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags, + GNUNET_NAMESTORE_RecordProcessor proc, + void *proc_cls); + + +/** + * Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start + * for the next record. + * + * @param it the iterator + */ +void +GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it); + + +/** + * Stops iteration and releases the namestore handle for further calls. + * + * @param it the iterator + */ +void +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. + * + * @param qe operation to cancel + */ +void +GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* end of gnunet_namestore_service.h */ +#endif diff --git a/src/include/gnunet_nat_lib.h b/src/include/gnunet_nat_lib.h new file mode 100644 index 0000000..6c1db80 --- /dev/null +++ b/src/include/gnunet_nat_lib.h @@ -0,0 +1,256 @@ +/* + This file is part of GNUnet. + (C) 2007, 2008, 2009, 2010, 2011 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_nat_lib.h + * @brief Library handling UPnP and NAT-PMP port forwarding and + * external IP address retrieval + * + * @author Milan Bouchet-Valat + */ + +#ifndef GNUNET_NAT_LIB_H +#define GNUNET_NAT_LIB_H + +#include "gnunet_util_lib.h" + +/** + * Signature of the callback passed to GNUNET_NAT_register for + * a function to call whenever our set of 'valid' addresses changes. + * + * @param cls closure + * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean + * the previous (now invalid) one + * @param addr either the previous or the new public IP address + * @param addrlen actual lenght of the address + */ +typedef void (*GNUNET_NAT_AddressCallback) (void *cls, int add_remove, + const struct sockaddr * addr, + socklen_t addrlen); + + +/** + * Signature of the callback passed to GNUNET_NAT_register + * for a function to call whenever someone asks us to do connection + * reversal. + * + * @param cls closure + * @param addr public IP address of the other peer + * @param addrlen actual lenght of the address + */ +typedef void (*GNUNET_NAT_ReversalCallback) (void *cls, + const struct sockaddr * addr, + socklen_t addrlen); + + +/** + * Handle for active NAT registrations. + */ +struct GNUNET_NAT_Handle; + + +/** + * Attempt to enable port redirection and detect public IP address contacting + * UPnP or NAT-PMP routers on the local network. Use addr to specify to which + * of the local host's addresses should the external port be mapped. The port + * is taken from the corresponding sockaddr_in[6] field. The NAT module + * should call the given callback for any 'plausible' external address. + * + * @param cfg configuration to use + * @param is_tcp GNUNET_YES for TCP, GNUNET_NO for UDP + * @param adv_port advertised port (port we are either bound to or that our OS + * locally performs redirection from to our bound port). + * @param num_addrs number of addresses in 'addrs' + * @param addrs list of local addresses packets should be redirected to + * @param addrlens actual lengths of the addresses + * @param address_callback function to call everytime the public IP address changes + * @param reversal_callback function to call if someone wants connection reversal from us, + * NULL if connection reversal is not supported + * @param callback_cls closure for callback + * @return NULL on error, otherwise handle that can be used to unregister + */ +struct GNUNET_NAT_Handle * +GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, int is_tcp, + uint16_t adv_port, unsigned int num_addrs, + const struct sockaddr **addrs, const socklen_t * addrlens, + GNUNET_NAT_AddressCallback address_callback, + GNUNET_NAT_ReversalCallback reversal_callback, + void *callback_cls); + + +/** + * Test if the given address is (currently) a plausible IP address for this peer. + * + * @param h the handle returned by register + * @param addr IP address to test (IPv4 or IPv6) + * @param addrlen number of bytes in addr + * @return GNUNET_YES if the address is plausible, + * GNUNET_NO if the address is not plausible, + * GNUNET_SYSERR if the address is malformed + */ +int +GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h, const void *addr, + socklen_t addrlen); + + +/** + * We learned about a peer (possibly behind NAT) so run the + * gnunet-nat-client to send dummy ICMP responses to cause + * that peer to connect to us (connection reversal). + * + * @param h handle (used for configuration) + * @param sa the address of the peer (IPv4-only) + */ +void +GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h, + const struct sockaddr_in *sa); + + + +/** + * Stop port redirection and public IP address detection for the given handle. + * This frees the handle, after having sent the needed commands to close open ports. + * + * @param h the handle to stop + */ +void +GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h); + + +/** + * Handle to a NAT test. + */ +struct GNUNET_NAT_Test; + +/** + * Function called to report success or failure for + * NAT configuration test. + * + * @param cls closure + * @param success GNUNET_OK on success, GNUNET_NO on failure, + * GNUNET_SYSERR if the test could not be + * properly started (internal failure) + */ +typedef void (*GNUNET_NAT_TestCallback) (void *cls, int success); + +/** + * Start testing if NAT traversal works using the + * given configuration (IPv4-only). + * + * @param cfg configuration for the NAT traversal + * @param is_tcp GNUNET_YES to test TCP, GNUNET_NO to test UDP + * @param bnd_port port to bind to, 0 for connection reversal + * @param adv_port externally advertised port to use + * @param report function to call with the result of the test + * @param report_cls closure for report + * @return handle to cancel NAT test + */ +struct GNUNET_NAT_Test * +GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, + int is_tcp, uint16_t bnd_port, uint16_t adv_port, + GNUNET_NAT_TestCallback report, void *report_cls); + + +/** + * Stop an active NAT test. + * + * @param tst test to stop. + */ +void +GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst); + + +/** + * Signature of a callback that is given an IP address. + * + * @param cls closure + * @param addr the address, NULL on errors + */ +typedef void (*GNUNET_NAT_IPCallback) (void *cls, const struct in_addr * addr); + + + +/** + * Opaque handle to cancel "GNUNET_NAT_mini_get_external_ipv4" operation. + */ +struct GNUNET_NAT_ExternalHandle; + + +/** + * Try to get the external IPv4 address of this peer. + * + * @param timeout when to fail + * @param cb function to call with result + * @param cb_cls closure for 'cb' + * @return handle for cancellation (can only be used until 'cb' is called), NULL on error + */ +struct GNUNET_NAT_ExternalHandle * +GNUNET_NAT_mini_get_external_ipv4 (struct GNUNET_TIME_Relative timeout, + GNUNET_NAT_IPCallback cb, void *cb_cls); + + +/** + * Cancel operation. + * + * @param eh operation to cancel + */ +void +GNUNET_NAT_mini_get_external_ipv4_cancel (struct GNUNET_NAT_ExternalHandle *eh); + + +/** + * Handle to a mapping created with upnpc. + */ +struct GNUNET_NAT_MiniHandle; + + +/** + * Start mapping the given port using (mini)upnpc. This function + * should typically not be used directly (it is used within the + * general-purpose 'GNUNET_NAT_register' code). However, it can be + * used if specifically UPnP-based NAT traversal is to be used or + * tested. + * + * @param port port to map + * @param is_tcp GNUNET_YES to map TCP, GNUNET_NO for UDP + * @param ac function to call with mapping result + * @param ac_cls closure for 'ac' + * @return NULL on error + */ +struct GNUNET_NAT_MiniHandle * +GNUNET_NAT_mini_map_start (uint16_t port, int is_tcp, + GNUNET_NAT_AddressCallback ac, void *ac_cls); + + +/** + * Remove a mapping created with (mini)upnpc. Calling + * this function will give 'upnpc' 1s to remove tha mapping, + * so while this function is non-blocking, a task will be + * left with the scheduler for up to 1s past this call. + * + * @param mini the handle + */ +void +GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini); + + +#endif + +/* end of gnunet_nat_lib.h */ diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h new file mode 100644 index 0000000..a14d5f0 --- /dev/null +++ b/src/include/gnunet_network_lib.h @@ -0,0 +1,464 @@ +/* + This file is part of GNUnet. + (C) 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_network_lib.h + * @brief basic low-level networking interface + * @author Nils Durner + */ + +#ifndef GNUNET_NETWORK_LIB_H +#define GNUNET_NETWORK_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * @brief handle to a socket + */ +struct GNUNET_NETWORK_Handle; + + +/** + * @brief collection of IO descriptors + */ +struct GNUNET_NETWORK_FDSet +{ + + /** + * Maximum number of any socket socket descriptor in the set (plus one) + */ + int nsds; + + /** + * Bitset with the descriptors. + */ + fd_set sds; + +#ifdef WINDOWS + /** + * Linked list of handles + */ + struct GNUNET_CONTAINER_SList *handles; +#endif + +}; + + + +#include "gnunet_disk_lib.h" +#include "gnunet_time_lib.h" + + +/** + * Accept a new connection on a socket. Configure it for non-blocking + * IO and mark it as non-inheritable to child processes (set the + * close-on-exec flag). + * + * @param desc bound socket + * @param address address of the connecting peer, may be NULL + * @param address_len length of address + * @return client socket + */ +struct GNUNET_NETWORK_Handle * +GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, + struct sockaddr *address, + socklen_t * address_len); + + +/** + * Box a native socket (and check that it is a socket). + * + * @param fd socket to box + * @return NULL on error (including not supported on target platform) + */ +struct GNUNET_NETWORK_Handle * +GNUNET_NETWORK_socket_box_native (SOCKTYPE fd); + + +/** + * Bind to a connected socket + * + * @param desc socket to bind + * @param address address to be bound + * @param address_len length of address + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, + const struct sockaddr *address, + socklen_t address_len); + +/** + * Close a socket. + * + * @param desc socket to close + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc); + + +/** + * Connect a socket + * + * @param desc socket to connect + * @param address peer address + * @param address_len of address + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, + const struct sockaddr *address, + socklen_t address_len); + + +/** + * Get socket options + * + * @param desc socket to inspect + * @param level protocol level of the option + * @param optname identifier of the option + * @param optval options + * @param optlen length of optval + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, + int level, int optname, void *optval, + socklen_t * optlen); + + +/** + * Listen on a socket + * + * @param desc socket to start listening on + * @param backlog length of the listen queue + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, + int backlog); + + +/** + * How much data is available to be read on this descriptor? + * @param desc socket + */ +ssize_t +GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle + *desc); + + +/** + * Read data from a connected socket (always non-blocking). + * @param desc socket + * @param buffer buffer + * @param length length of buffer + * @param src_addr either the source to recv from, or all zeroes + * to be filled in by recvfrom + * @param addrlen length of the addr + */ +ssize_t +GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle *desc, + void *buffer, size_t length, + struct sockaddr *src_addr, socklen_t * addrlen); + + +/** + * Read data from a connected socket (always non-blocking). + * + * @param desc socket + * @param buffer buffer + * @param length length of buffer + * @return number of bytes read + */ +ssize_t +GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle *desc, + void *buffer, size_t length); + + +/** + * Check if sockets meet certain conditions + * @param rfds set of sockets to be checked for readability + * @param wfds set of sockets to be checked for writability + * @param efds set of sockets to be checked for exceptions + * @param timeout relative value when to return + * @return number of selected sockets, GNUNET_SYSERR on error + */ +int +GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, + struct GNUNET_NETWORK_FDSet *wfds, + struct GNUNET_NETWORK_FDSet *efds, + struct GNUNET_TIME_Relative timeout); + + +/** + * Send data (always non-blocking). + * + * @param desc socket + * @param buffer data to send + * @param length size of the buffer + * @return number of bytes sent, GNUNET_SYSERR on error + */ +ssize_t +GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle *desc, + const void *buffer, size_t length); + + +/** + * Send data to a particular destination (always non-blocking). + * This function only works for UDP sockets. + * + * @param desc socket + * @param message data to send + * @param length size of the data + * @param dest_addr destination address + * @param dest_len length of address + * @return number of bytes sent, GNUNET_SYSERR on error + */ +ssize_t +GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle *desc, + const void *message, size_t length, + const struct sockaddr *dest_addr, + socklen_t dest_len); + + +/** + * Set socket option + * + * @param fd socket + * @param level protocol level of the option + * @param option_name option identifier + * @param option_value value to set + * @param option_len size of option_value + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, int level, + int option_name, const void *option_value, + socklen_t option_len); + + +/** + * Shut down socket operations + * + * @param desc socket + * @param how type of shutdown + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, int how); + + +/** + * Disable the "CORK" feature for communication with the given socket, + * forcing the OS to immediately flush the buffer on transmission + * instead of potentially buffering multiple messages. Essentially + * reduces the OS send buffers to zero. + * + * @param desc socket + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_NETWORK_socket_disable_corking (struct GNUNET_NETWORK_Handle *desc); + + +/** + * Create a new socket. Configure it for non-blocking IO and + * mark it as non-inheritable to child processes (set the + * close-on-exec flag). + * + * @param domain domain of the socket + * @param type socket type + * @param protocol network protocol + * @return new socket, NULL on error + */ +struct GNUNET_NETWORK_Handle * +GNUNET_NETWORK_socket_create (int domain, int type, int protocol); + + +/** + * Reset FD set (clears all file descriptors). + * + * @param fds fd set to clear + */ +void +GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds); + + +/** + * Add a socket to the FD set + * @param fds fd set + * @param desc socket to add + */ +void +GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds, + const struct GNUNET_NETWORK_Handle *desc); + + +#if WINDOWS +/** + * Add a W32 file handle to the fd set + * @param fds fd set + * @param h the file handle to add + */ +void +GNUNET_NETWORK_fdset_handle_set_native_w32_handle (struct GNUNET_NETWORK_FDSet + *fds, HANDLE h); +#endif + + +/** + * Check whether a socket is part of the fd set + * @param fds fd set + * @param desc socket + * @return GNUNET_YES if the socket is in the set + */ +int +GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds, + const struct GNUNET_NETWORK_Handle *desc); + + +/** + * Add one fd set to another + * @param dst the fd set to add to + * @param src the fd set to add from + */ +void +GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, + const struct GNUNET_NETWORK_FDSet *src); + + +/** + * Copy one fd set to another + * @param to destination + * @param from source + */ +void +GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to, + const struct GNUNET_NETWORK_FDSet *from); + + +/** + * Return file descriptor for this network handle + * + * @param desc wrapper to process + * @return POSIX file descriptor + */ +int +GNUNET_NETWORK_get_fd (struct GNUNET_NETWORK_Handle *desc); + + +/** + * Copy a native fd set + * @param to destination + * @param from native source set + * @param nfds the biggest socket number in from + 1 + */ +void +GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, + const fd_set * from, int nfds); + + +/** + * Set a native fd in a set + * + * @param to destination + * @param nfd native FD to set + */ +void +GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to, int nfd); + + +/** + * Test native fd in a set + * + * @param to set to test, NULL for empty set + * @param nfd native FD to test, -1 for none + * @return GNUNET_YES if to contains nfd + */ +int +GNUNET_NETWORK_fdset_test_native (const struct GNUNET_NETWORK_FDSet *to, + int nfd); + + +/** + * Add a file handle to the fd set + * @param fds fd set + * @param h the file handle to add + */ +void +GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, + const struct GNUNET_DISK_FileHandle *h); + + +/** + * Check if a file handle is part of an fd set + * @param fds fd set + * @param h file handle + * @return GNUNET_YES if the file handle is part of the set + */ +int +GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, + const struct GNUNET_DISK_FileHandle *h); + + +/** + * Checks if two fd sets overlap + * @param fds1 first fd set + * @param fds2 second fd set + * @return GNUNET_YES if they do overlap, GNUNET_NO otherwise + */ +int +GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, + const struct GNUNET_NETWORK_FDSet *fds2); + + +/** + * Creates an fd set + * @return a new fd set + */ +struct GNUNET_NETWORK_FDSet * +GNUNET_NETWORK_fdset_create (void); + + +/** + * Releases the associated memory of an fd set + * @param fds fd set + */ +void +GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif /* GNUNET_NETWORK_LIB_H */ diff --git a/src/include/gnunet_nse_service.h b/src/include/gnunet_nse_service.h new file mode 100644 index 0000000..a0c6016 --- /dev/null +++ b/src/include/gnunet_nse_service.h @@ -0,0 +1,109 @@ +/* + This file is part of GNUnet + (C) 2011 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. + */ + +#ifndef GNUNET_NSE_SERVICE_H_ +#define GNUNET_NSE_SERVICE_H_ + +/** + * @file include/gnunet_nse_service.h + * @brief API to retrieve the current network size estimate, + * also to register for notifications whenever a new + * network size estimate is calculated. + * + * @author Nathan Evans + */ + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" +#include "gnunet_configuration_lib.h" +#include "gnunet_scheduler_lib.h" + +/** + * Version of the network size estimation API. + */ +#define GNUNET_NSE_VERSION 0x00000000 + +/** + * Handle for the network size estimation service. + */ +struct GNUNET_NSE_Handle; + +/** + * Callback to call when network size estimate is updated. + * + * @param cls closure + * @param timestamp time when the estimate was received from the server (or created by the server) + * @param logestimate the log(Base 2) value of the current network size estimate + * @param std_dev standard deviation for the estimate + * + */ +typedef void (*GNUNET_NSE_Callback) (void *cls, + struct GNUNET_TIME_Absolute timestamp, + double logestimate, double std_dev); + + +/** + * Convert the logarithmic estimated returned to the 'GNUNET_NSE_Callback' + * into an absolute estimate in terms of the number of peers in the network. + * + * @param loge logarithmic estimate + * @return absolute number of peers in the network (estimated) + */ +#define GNUNET_NSE_log_estimate_to_n(loge) pow(2.0, (loge)) + +/** + * Connect to the network size estimation service. + * + * @param cfg the configuration to use + * @param func funtion to call with network size estimate + * @param func_cls closure to pass for network size estimate callback + * + * @return handle to use + */ +struct GNUNET_NSE_Handle * +GNUNET_NSE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_NSE_Callback func, void *func_cls); + + +/** + * Disconnect from network size estimation service + * + * @param h handle to destroy + * + */ +void +GNUNET_NSE_disconnect (struct GNUNET_NSE_Handle *h); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif /* GNUNET_NSE_SERVICE_H_ */ diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h new file mode 100644 index 0000000..e9e484f --- /dev/null +++ b/src/include/gnunet_os_lib.h @@ -0,0 +1,434 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2011 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/gnunet_os_lib.h + * @brief low level process routines + * @author Christian Grothoff + * @author Krista Bennett + * @author Gerd Knorr <kraxel@bytesex.org> + * @author Ioana Patrascu + * @author Tzvetan Horozov + * @author Milan + * + * This code manages child processes. We can communicate with child + * processes using signals. Because signals are not supported on W32 + * and Java (at least not nicely), we can alternatively use a pipe + * to send signals to the child processes (if the child process is + * a full-blown GNUnet process that supports reading signals from + * a pipe, of course). Naturally, this also only works for 'normal' + * termination via signals, and not as a replacement for SIGKILL. + * Thus using pipes to communicate signals should only be enabled if + * the child is a Java process OR if we are on Windoze. + */ + +#ifndef GNUNET_OS_LIB_H +#define GNUNET_OS_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" +#include "gnunet_configuration_lib.h" +#include "gnunet_scheduler_lib.h" + +/** + * Process information (OS-dependent) + */ +struct GNUNET_OS_Process; + + +/** + * Possible installation paths to request + */ +enum GNUNET_OS_InstallationPathKind +{ + /** + * Return the "PREFIX" directory given to configure. + */ + GNUNET_OS_IPK_PREFIX, + + /** + * Return the directory where the program binaries are installed. (bin/) + */ + GNUNET_OS_IPK_BINDIR, + + /** + * Return the directory where libraries are installed. (lib/gnunet/) + */ + GNUNET_OS_IPK_LIBDIR, + + /** + * Return the directory where data is installed (share/gnunet/) + */ + GNUNET_OS_IPK_DATADIR, + + /** + * Return the directory where translations are installed (share/locale/) + */ + GNUNET_OS_IPK_LOCALEDIR, + + /** + * Return the installation directory of this application, not + * the one of the overall GNUnet installation (in case they + * are different). + */ + GNUNET_OS_IPK_SELF_PREFIX, + + /** + * Return the prefix of the path with application icons (share/icons/). + */ + GNUNET_OS_IPK_ICONDIR, + + /** + * Return the prefix of the path with documentation files, including the + * license (share/doc/gnunet/). + */ + GNUNET_OS_IPK_DOCDIR +}; + + +/** + * Process status types + */ +enum GNUNET_OS_ProcessStatusType +{ + /** + * The process is not known to the OS (or at + * least not one of our children). + */ + GNUNET_OS_PROCESS_UNKNOWN, + + /** + * The process is still running. + */ + GNUNET_OS_PROCESS_RUNNING, + + /** + * The process is paused (but could be resumed). + */ + GNUNET_OS_PROCESS_STOPPED, + + /** + * The process exited with a return code. + */ + GNUNET_OS_PROCESS_EXITED, + + /** + * The process was killed by a signal. + */ + GNUNET_OS_PROCESS_SIGNALED +}; + + +/** + * Get the path to a specific GNUnet installation directory or, with + * GNUNET_OS_IPK_SELF_PREFIX, the current running apps installation + * directory. + * + * @param dirkind what kind of directory is desired? + * @return a pointer to the dir path (to be freed by the caller) + */ +char * +GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind); + + +/** + * Callback function invoked for each interface found. + * + * @param cls closure + * @param name name of the interface (can be NULL for unknown) + * @param isDefault is this presumably the default interface + * @param addr address of this interface (can be NULL for unknown or unassigned) + * @param broadcast_addr the broadcast address (can be NULL for unknown or unassigned) + * @param netmask the network mask (can be NULL for unknown or unassigned)) + * @param addrlen length of the address + * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort + */ +typedef int (*GNUNET_OS_NetworkInterfaceProcessor) (void *cls, const char *name, + int isDefault, + const struct sockaddr * + addr, + const struct sockaddr * + broadcast_addr, + const struct sockaddr * + netmask, socklen_t addrlen); + + +/** + * @brief Enumerate all network interfaces + * @param proc the callback function + * @param proc_cls closure for proc + */ +void +GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor proc, + void *proc_cls); + +/** + * @brief Get maximum string length returned by gethostname() + */ +#if HAVE_SYSCONF && defined(_SC_HOST_NAME_MAX) +#define GNUNET_OS_get_hostname_max_length() ({ int __sc_tmp = sysconf(_SC_HOST_NAME_MAX); __sc_tmp <= 0 ? 255 : __sc_tmp; }) +#elif defined(HOST_NAME_MAX) +#define GNUNET_OS_get_hostname_max_length() HOST_NAME_MAX +#else +#define GNUNET_OS_get_hostname_max_length() 255 +#endif + + +/** + * Get process structure for current process + * + * The pointer it returns points to static memory location and must not be + * deallocated/closed + * + * @return pointer to the process sturcutre for this process + */ +struct GNUNET_OS_Process * +GNUNET_OS_process_current (void); + + +/** + * Sends a signal to the process + * + * @param proc pointer to process structure + * @param sig signal + * @return 0 on success, -1 on error + */ +int +GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig); + + +/** + * Cleans up process structure contents (OS-dependent) and deallocates it + * + * @param proc pointer to process structure + */ +void +GNUNET_OS_process_close (struct GNUNET_OS_Process *proc); + + +/** + * Get the pid of the process in question + * + * @param proc the process to get the pid of + * + * @return the current process id + */ +pid_t +GNUNET_OS_process_get_pid (struct GNUNET_OS_Process *proc); + + +/** + * Set process priority + * + * @param proc pointer to process structure + * @param prio priority value + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, + enum GNUNET_SCHEDULER_Priority prio); + + +/** + * Start a process. + * + * @param pipe_control should a pipe be used to send signals to the child? + * @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 + * @param argv NULL-terminated array of arguments to the process + * @return pointer to process structure of the new process, NULL on error + */ +struct GNUNET_OS_Process * +GNUNET_OS_start_process_vap (int pipe_control, + struct GNUNET_DISK_PipeHandle *pipe_stdin, + struct GNUNET_DISK_PipeHandle *pipe_stdout, + const char *filename, + char *const argv[]); + + +/** + * Start a process. + * + * @param pipe_control should a pipe be used to send signals to the child? + * @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 + * @param ... NULL-terminated list of arguments to the process + * @return pointer to process structure of the new process, NULL on error + */ +struct GNUNET_OS_Process * +GNUNET_OS_start_process (int pipe_control, + struct GNUNET_DISK_PipeHandle *pipe_stdin, + struct GNUNET_DISK_PipeHandle *pipe_stdout, + const char *filename, ...); + + +/** + * Start a process. + * + * @param pipe_control should a pipe be used to send signals to the child? + * @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 + * @param va NULL-terminated list of arguments to the process + * @return pointer to process structure of the new process, NULL on error + */ +struct GNUNET_OS_Process * +GNUNET_OS_start_process_va (int pipe_control, + struct GNUNET_DISK_PipeHandle *pipe_stdin, + struct GNUNET_DISK_PipeHandle *pipe_stdout, + const char *filename, va_list va); + +/** + * Start a process. + * + * @param pipe_control should a pipe be used to send signals to the child? + * @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 + * @param argv NULL-terminated list of arguments to the process, + * including the process name as the first argument + * @return pointer to process structure of the new process, NULL on error + */ +struct GNUNET_OS_Process * +GNUNET_OS_start_process_v (int pipe_control, + const SOCKTYPE *lsocks, + const char *filename, + char *const argv[]); + + +/** + * Handle to a command action. + */ +struct GNUNET_OS_CommandHandle; + + +/** + * Type of a function to process a line of output. + * + * @param cls closure + * @param line line of output from a command, NULL for the end + */ +typedef void (*GNUNET_OS_LineProcessor) (void *cls, const char *line); + + +/** + * Stop/kill a command. + * + * @param cmd handle to the process + */ +void +GNUNET_OS_command_stop (struct GNUNET_OS_CommandHandle *cmd); + + +/** + * Run the given command line and call the given function + * for each line of the output. + * + * @param proc function to call for each line of the output + * @param proc_cls closure for proc + * @param timeout when to time out + * @param binary command to run + * @param ... arguments to command + * @return NULL on error + */ +struct GNUNET_OS_CommandHandle * +GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls, + struct GNUNET_TIME_Relative timeout, const char *binary, + ...); + + +/** + * Retrieve the status of a process. Nonblocking version. + * + * @param proc pointer to process structure + * @param type status type + * @param code return code/signal number + * @return GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise + */ +int +GNUNET_OS_process_status (struct GNUNET_OS_Process *proc, + enum GNUNET_OS_ProcessStatusType *type, + unsigned long *code); + + +/** + * Wait for a process to terminate. The return code is discarded. + * You must not use 'GNUNET_OS_process_status' on the same process + * after calling this function! This function is blocking and should + * thus only be used if the child process is known to have terminated + * or to terminate very soon. + * + * @param proc pointer to process structure of the process to wait for + * @return GNUNET_OK on success, GNUNET_SYSERR otherwise + */ +int +GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc); + + +/** + * Connects this process to its parent via pipe; + * essentially, the parent control handler will read signal numbers + * from the 'GNUNET_OS_CONTROL_PIPE' (as given in an environment + * variable) and raise those signals. + * + * @param cls closure (unused) + * @param tc scheduler context (unused) + */ +void +GNUNET_OS_install_parent_control_handler (void *cls, + const struct + GNUNET_SCHEDULER_TaskContext *tc); + + +/** + * Check whether an executable exists and possibly + * if the suid bit is set on the file. + * Attempts to find the file using the current + * PATH environment variable as a search path. + * + * @param binary the name of the file to check + * @return GNUNET_YES if the file is SUID, + * GNUNET_NO if not SUID (but binary exists) + * GNUNET_SYSERR on error (no such binary or not executable) + */ +int +GNUNET_OS_check_helper_binary (const char *binary); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + +/* ifndef GNUNET_OS_LIB_H */ +#endif +/* end of gnunet_os_lib.h */ diff --git a/src/include/gnunet_peer_lib.h b/src/include/gnunet_peer_lib.h new file mode 100644 index 0000000..0121e84 --- /dev/null +++ b/src/include/gnunet_peer_lib.h @@ -0,0 +1,103 @@ +/* + This file is part of GNUnet. + (C) 2006, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_peer_lib.h + * @brief helper library for interning of peer identifiers + * @author Christian Grothoff + */ + +#ifndef GNUNET_PEER_LIB_H +#define GNUNET_PEER_LIB_H + +#include "gnunet_util_lib.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +/** + * A GNUNET_PEER_Id is simply a shorter + * version of a "struct GNUNET_PeerIdentifier" + * that can be used inside of a GNUnet peer + * to save memory when the same identifier + * needs to be used over and over again. + */ +typedef unsigned int GNUNET_PEER_Id; + + +/** + * Search for a peer identity. The reference counter is not changed. + * + * @param pid identity to find + * @return the interned identity or 0. + */ +GNUNET_PEER_Id +GNUNET_PEER_search (const struct GNUNET_PeerIdentity *pid); + + +/** + * Intern an peer identity. If the identity is already known, its + * reference counter will be increased by one. + * + * @param pid identity to intern + * @return the interned identity. + */ +GNUNET_PEER_Id +GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid); + + +/** + * Change the reference counter of an interned PID. + * + * @param id identity to change the RC of + * @param delta how much to change the RC + */ +void +GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta); + + +/** + * Decrement multiple RCs of peer identities by one. + * + * @param ids array of PIDs to decrement the RCs of + * @param count size of the ids array + */ +void +GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id *ids, unsigned int count); + + +/** + * Convert an interned PID to a normal peer identity. + * + * @param id interned PID to convert + * @param pid where to write the normal peer identity + */ +void +GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid); + + +/* ifndef GNUNET_PEER_LIB_H */ +#endif +/* end of gnunet_peer_lib.h */ diff --git a/src/include/gnunet_peerinfo_service.h b/src/include/gnunet_peerinfo_service.h new file mode 100644 index 0000000..12264fb --- /dev/null +++ b/src/include/gnunet_peerinfo_service.h @@ -0,0 +1,190 @@ +/* + This file is part of GNUnet + (C) 2009, 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file include/gnunet_peerinfo_service.h + * @brief Code to maintain the list of currently known hosts + * (in memory structure of data/hosts). + * @author Christian Grothoff + */ + +#ifndef GNUNET_PEERINFO_SERVICE_H +#define GNUNET_PEERINFO_SERVICE_H + +#include "gnunet_common.h" +#include "gnunet_configuration_lib.h" +#include "gnunet_crypto_lib.h" +#include "gnunet_hello_lib.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * Handle to the peerinfo service. + */ +struct GNUNET_PEERINFO_Handle; + + +/** + * Connect to the peerinfo service. + * + * @param cfg configuration to use + * @return NULL on error (configuration related, actual connection + * etablishment may happen asynchronously). + */ +struct GNUNET_PEERINFO_Handle * +GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); + + + +/** + * Disconnect from the peerinfo service. Note that all iterators must + * have completed or have been cancelled by the time this function is + * called (otherwise, calling this function is a serious error). + * Furthermore, if 'GNUNET_PEERINFO_add_peer' operations are still + * pending, they will be cancelled silently on disconnect. + * + * @param h handle to disconnect + */ +void +GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h); + + +/** + * Add a host to the persistent list. This method operates in + * semi-reliable mode: if the transmission is not completed by + * the time 'GNUNET_PEERINFO_disconnect' is called, it will be + * aborted. Furthermore, if a second HELLO is added for the + * same peer before the first one was transmitted, PEERINFO may + * merge the two HELLOs prior to transmission to the service. + * + * @param h handle to the peerinfo service + * @param hello the verified (!) HELLO message + */ +void +GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h, + const struct GNUNET_HELLO_Message *hello); + + +/** + * Type of an iterator over the hosts. Note that each + * host will be called with each available protocol. + * + * @param cls closure + * @param peer id of the peer, NULL for last call + * @param hello hello message for the peer (can be NULL) + * @param error message + */ +typedef void (*GNUNET_PEERINFO_Processor) (void *cls, + const struct GNUNET_PeerIdentity * + peer, + const struct GNUNET_HELLO_Message * + hello, const char *err_msg); + + +/** + * Handle for cancellation of iteration over peers. + */ +struct GNUNET_PEERINFO_IteratorContext; + + +/** + * Call a method for each known matching host to get its HELLO. + * The callback method will be invoked once for each matching + * host and then finally once with a NULL pointer. After that final + * invocation, the iterator context must no longer be used. + * + * Instead of calling this function with 'peer == NULL' + * it is often better to use 'GNUNET_PEERINFO_notify'. + * + * @param h handle to the peerinfo service + * @param peer restrict iteration to this peer only (can be NULL) + * @param timeout how long to wait until timing out + * @param callback the method to call for each peer + * @param callback_cls closure for callback + * @return NULL on error (in this case, 'callback' is never called!), + * otherwise an iterator context + */ +struct GNUNET_PEERINFO_IteratorContext * +GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_TIME_Relative timeout, + GNUNET_PEERINFO_Processor callback, + void *callback_cls); + + + +/** + * Cancel an iteration over peer information. + * + * @param ic context of the iterator to cancel + */ +void +GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic); + + + +/** + * Handle for notifications about changes to the set of known peers. + */ +struct GNUNET_PEERINFO_NotifyContext; + + +/** + * Call a method whenever our known information about peers + * changes. Initially calls the given function for all known + * peers and then only signals changes. Note that it is + * possible (i.e. on disconnects) that the callback is called + * twice with the same peer information. + * + * @param cfg configuration to use + * @param callback the method to call for each peer + * @param callback_cls closure for callback + * @return NULL on error + */ +struct GNUNET_PEERINFO_NotifyContext * +GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_PEERINFO_Processor callback, void *callback_cls); + + +/** + * Stop notifying about changes. + * + * @param nc context to stop notifying + */ +void +GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + +/* end of gnunet_peerinfo_service.h */ +#endif diff --git a/src/include/gnunet_plugin_lib.h b/src/include/gnunet_plugin_lib.h new file mode 100644 index 0000000..387ca38 --- /dev/null +++ b/src/include/gnunet_plugin_lib.h @@ -0,0 +1,137 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006 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/gnunet_plugin_lib.h + * @brief plugin loading and unloading + * @author Christian Grothoff + */ + +#ifndef GNUNET_PLUGIN_LIB_H +#define GNUNET_PLUGIN_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" +#include "gnunet_configuration_lib.h" + + +/** + * Signature of any function exported by a plugin. + * + * @param arg argument to the function (context) + * @return some pointer, NULL if the plugin was + * shutdown or if there was an error, otherwise + * the plugin's API on success + */ +typedef void *(*GNUNET_PLUGIN_Callback) (void *arg); + + +/** + * Test if a plugin exists. + * + * Note that the library must export a symbol called + * "library_name_init" for the test to succeed. + * + * @param library_name name of the plugin to test if it is installed + * @return GNUNET_YES if the plugin exists, GNUNET_NO if not + */ +int +GNUNET_PLUGIN_test (const char *library_name); + + +/** + * Setup plugin (runs the "init" callback and returns whatever "init" + * returned). If "init" returns NULL, the plugin is unloaded. + * + * Note that the library must export symbols called + * "library_name_init" and "library_name_done". These will be called + * when the library is loaded and unloaded respectively. + * + * @param library_name name of the plugin to load + * @param arg argument to the plugin initialization function + * @return whatever the initialization function returned, NULL on error + */ +void * +GNUNET_PLUGIN_load (const char *library_name, void *arg); + + +/** + * Signature of a function called by 'GNUNET_PLUGIN_load_all'. + * + * @param cls closure + * @param library_name full name of the library (to be used with + * 'GNUNET_PLUGIN_unload') + * @param lib_ret return value from the initialization function + * of the library (same as what 'GNUNET_PLUGIN_load' would + * have returned for the given library name) + */ +typedef void (*GNUNET_PLUGIN_LoaderCallback) (void *cls, + const char *library_name, + void *lib_ret); + + +/** + * Load all compatible plugins with the given base name. + * + * Note that the library must export symbols called + * "basename_ANYTHING_init" and "basename_ANYTHING__done". These will + * be called when the library is loaded and unloaded respectively. + * + * @param basename basename of the plugins to load + * @param arg argument to the plugin initialization function + * @param cb function to call for each plugin found + * @param cb_cls closure for 'cb' + */ +void +GNUNET_PLUGIN_load_all (const char *basename, void *arg, + GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls); + + +/** + * Unload plugin (runs the "done" callback and returns whatever "done" + * returned). The plugin is then unloaded. + * + * @param library_name name of the plugin to unload + * @param arg argument to the plugin shutdown function + * @return whatever the shutdown function returned, typically NULL + * or a "char *" representing the error message + */ +void * +GNUNET_PLUGIN_unload (const char *library_name, void *arg); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + +/* ifndef GNUNET_PLUGIN_LIB_H */ +#endif +/* end of gnunet_plugin_lib.h */ diff --git a/src/include/gnunet_program_lib.h b/src/include/gnunet_program_lib.h new file mode 100644 index 0000000..48d5280 --- /dev/null +++ b/src/include/gnunet_program_lib.h @@ -0,0 +1,86 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_program_lib.h + * @brief functions related to starting programs + * @author Christian Grothoff + */ + +#ifndef GNUNET_PROGRAM_LIB_H +#define GNUNET_PROGRAM_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_configuration_lib.h" +#include "gnunet_getopt_lib.h" +#include "gnunet_scheduler_lib.h" + +/** + * Main function that will be run. + * + * @param cls closure + * @param args remaining command-line arguments + * @param cfgfile name of the configuration file used (for saving, can be NULL!) + * @param cfg configuration + */ +typedef void (*GNUNET_PROGRAM_Main) (void *cls, char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle * + cfg); + + +/** + * Run a standard GNUnet command startup sequence (initialize loggers + * and configuration, parse options). + * + * @param argc number of command line arguments + * @param argv command line arguments + * @param binaryName our expected name + * @param binaryHelp helptext for "-h" option (about the app) + * @param options command line options + * @param task main function to run + * @param task_cls closure for task + * @return GNUNET_SYSERR on error, GNUNET_OK on success + */ +int +GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, + const char *binaryHelp, + const struct GNUNET_GETOPT_CommandLineOption *options, + GNUNET_PROGRAM_Main task, void *task_cls); + + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_PROGRAM_LIB_H */ +#endif +/* end of gnunet_program_lib.h */ diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h new file mode 100644 index 0000000..dd7c7fe --- /dev/null +++ b/src/include/gnunet_protocols.h @@ -0,0 +1,1289 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_protocols.h + * @brief constants for network protocols + * @author Christian Grothoff + */ + +#ifndef GNUNET_PROTOCOLS_H +#define GNUNET_PROTOCOLS_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +/******************************************************************************* + * UTIL message types + ******************************************************************************/ + +/** + * Test if service is online. + */ +#define GNUNET_MESSAGE_TYPE_TEST 1 + +/** + * Dummy messages for testing / benchmarking. + */ +#define GNUNET_MESSAGE_TYPE_DUMMY 2 + +/******************************************************************************* + * RESOLVER message types + ******************************************************************************/ + +/** + * Request DNS resolution. + */ +#define GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST 4 + +/** + * Response to a DNS resolution request. + */ +#define GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE 5 + +/******************************************************************************* + * ARM message types + ******************************************************************************/ + +/** + * Request to ARM to start a service. + */ +#define GNUNET_MESSAGE_TYPE_ARM_START 8 + +/** + * Request to ARM to stop a service. + */ +#define GNUNET_MESSAGE_TYPE_ARM_STOP 9 + +/** + * Request ARM service itself to shutdown. + */ +#define GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN 10 + +/** + * Response from ARM. + */ +#define GNUNET_MESSAGE_TYPE_ARM_RESULT 11 + + +/******************************************************************************* + * HELLO message types + ******************************************************************************/ + +/** + * HELLO message used for communicating peer addresses. + * Managed by libgnunethello. + */ +#define GNUNET_MESSAGE_TYPE_HELLO 16 + +/******************************************************************************* + * FRAGMENTATION message types + ******************************************************************************/ + +/** + * FRAGMENT of a larger message. + * Managed by libgnunetfragment. + */ +#define GNUNET_MESSAGE_TYPE_FRAGMENT 18 + +/** + * Acknowledgement of a FRAGMENT of a larger message. + * Managed by libgnunetfragment. + */ +#define GNUNET_MESSAGE_TYPE_FRAGMENT_ACK 19 + +/******************************************************************************* + * Transport-WLAN message types + ******************************************************************************/ + +/** + * Type of messages between the gnunet-wlan-helper and the daemon + * + */ +#define GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA 40 + +/** + * Control messages between the gnunet-wlan-helper and the daemon + */ + +#define GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL 41 + +/** + * Type of messages for advertisement over wlan + */ +#define GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT 42 + +/** + * Type of messages for data over the wlan + */ +#define GNUNET_MESSAGE_TYPE_WLAN_DATA 43 + + +/******************************************************************************* + * Transport-DV message types + ******************************************************************************/ + +/** + * DV service to DV Plugin message, when a message is + * unwrapped by the DV service and handed to the plugin + * for processing + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE 44 + +/** + * DV Plugin to DV service message, indicating a message + * should be sent out. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND 45 + +/** + * DV service to DV api message, containing a confirmation + * or failure of a DV_SEND message. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT 46 + +/** + * P2P DV message encapsulating some real message + */ +#define GNUNET_MESSAGE_TYPE_DV_DATA 47 + +/** + * P2P DV message gossipping peer information + */ +#define GNUNET_MESSAGE_TYPE_DV_GOSSIP 48 + +/** + * DV Plugin to DV service message, indicating + * startup. + */ +#define GNUNET_MESSAGE_TYPE_DV_START 49 + +/** + * P2P DV message notifying connected peers of a disconnect + */ +#define GNUNET_MESSAGE_TYPE_DV_DISCONNECT 50 + +/******************************************************************************* + * Transport-UDP message types + ******************************************************************************/ + +/** + * Normal UDP message type. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE 56 + +/** + * UDP ACK. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK 57 + +/******************************************************************************* + * Transport-TCP message types + ******************************************************************************/ + +/** + * TCP NAT probe message, send from NAT'd peer to + * other peer to establish bi-directional communication + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE 60 + +/** + * Welcome message between TCP transports. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME 61 + +/** + * Message to force transport to update bandwidth assignment (LEGACY) + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_ATS 62 + +/******************************************************************************* + * NAT message types + ******************************************************************************/ + +/** + * Message to ask NAT server to perform traversal test + */ +#define GNUNET_MESSAGE_TYPE_NAT_TEST 63 + +/******************************************************************************* + * CORE message types + ******************************************************************************/ + +/** + * Initial setup message from core client to core. + */ +#define GNUNET_MESSAGE_TYPE_CORE_INIT 64 + +/** + * Response from core to core client to INIT message. + */ +#define GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY 65 + +/** + * Notify clients about new peer-to-peer connections (before + * key exchange and authentication). + */ +#define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_PRE_CONNECT 66 + +/** + * Notify clients about new peer-to-peer connections (triggered + * after key exchange). + */ +#define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT 67 + +/** + * Notify clients about peer disconnecting. + */ +#define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT 68 + +/** + * Notify clients about peer status change. + */ +#define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_STATUS_CHANGE 69 + +/** + * Notify clients about incoming P2P messages. + */ +#define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND 70 + +/** + * Notify clients about outgoing P2P transmissions. + */ +#define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND 71 + +/** + * Request from client to transmit message. + */ +#define GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST 74 + +/** + * Confirmation from core that message can now be sent + */ +#define GNUNET_MESSAGE_TYPE_CORE_SEND_READY 75 + +/** + * Client with message to transmit (after SEND_READY confirmation + * was received). + */ +#define GNUNET_MESSAGE_TYPE_CORE_SEND 76 + + +/** + * Request for peer iteration from CORE service. + */ +#define GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS 78 + +/** + * Last reply from core to request for peer iteration from CORE service. + */ +#define GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END 79 + +/** + * Check whether a given peer is currently connected to CORE. + */ +#define GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED 80 + +/** + * Session key exchange between peers. + */ +#define GNUNET_MESSAGE_TYPE_CORE_SET_KEY 81 + +/** + * Encapsulation for an encrypted message between peers. + */ +#define GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE 82 + +/** + * Check that other peer is alive (challenge). + */ +#define GNUNET_MESSAGE_TYPE_CORE_PING 83 + +/** + * Confirmation that other peer is alive. + */ +#define GNUNET_MESSAGE_TYPE_CORE_PONG 84 + +/** + * Request by the other peer to terminate the connection. + */ +#define GNUNET_MESSAGE_TYPE_CORE_HANGUP 85 + +/** + * gzip-compressed type map of the sender + */ +#define GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP 86 + +/** + * uncompressed type map of the sender + */ +#define GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP 87 + +/******************************************************************************* + * DATASTORE message types + ******************************************************************************/ + +/** + * Message sent by datastore client on join. + */ +#define GNUNET_MESSAGE_TYPE_DATASTORE_RESERVE 92 + +/** + * Message sent by datastore client on join. + */ +#define GNUNET_MESSAGE_TYPE_DATASTORE_RELEASE_RESERVE 93 + +/** + * Message sent by datastore to client informing about status + * processing a request + * (in response to RESERVE, RELEASE_RESERVE, PUT, UPDATE and REMOVE requests). + */ +#define GNUNET_MESSAGE_TYPE_DATASTORE_STATUS 94 + +/** + * Message sent by datastore client to store data. + */ +#define GNUNET_MESSAGE_TYPE_DATASTORE_PUT 95 + +/** + * Message sent by datastore client to update data. + */ +#define GNUNET_MESSAGE_TYPE_DATASTORE_UPDATE 96 + +/** + * Message sent by datastore client to get data. + */ +#define GNUNET_MESSAGE_TYPE_DATASTORE_GET 97 + +/** + * Message sent by datastore client to get random data. + */ +#define GNUNET_MESSAGE_TYPE_DATASTORE_GET_REPLICATION 98 + +/** + * Message sent by datastore client to get random data. + */ +#define GNUNET_MESSAGE_TYPE_DATASTORE_GET_ZERO_ANONYMITY 99 + +/** + * Message sent by datastore to client providing requested data + * (in response to GET or GET_RANDOM request). + */ +#define GNUNET_MESSAGE_TYPE_DATASTORE_DATA 100 + +/** + * Message sent by datastore to client signaling end of matching data. + * This message will also be sent for "GET_RANDOM", even though + * "GET_RANDOM" returns at most one data item. + */ +#define GNUNET_MESSAGE_TYPE_DATASTORE_DATA_END 101 + +/** + * Message sent by datastore client to remove data. + */ +#define GNUNET_MESSAGE_TYPE_DATASTORE_REMOVE 102 + +/** + * Message sent by datastore client to drop the database. + */ +#define GNUNET_MESSAGE_TYPE_DATASTORE_DROP 103 + + +/******************************************************************************* + * FS message types + ******************************************************************************/ + +/** + * Message sent by fs client to start indexing. + */ +#define GNUNET_MESSAGE_TYPE_FS_INDEX_START 128 + +/** + * Affirmative response to a request for start indexing. + */ +#define GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK 129 + +/** + * Response to a request for start indexing that + * refuses. + */ +#define GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED 130 + +/** + * Request from client for list of indexed files. + */ +#define GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_GET 131 + +/** + * Reply to client with an indexed file name. + */ +#define GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY 132 + +/** + * Reply to client indicating end of list. + */ +#define GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END 133 + +/** + * Request from client to unindex a file. + */ +#define GNUNET_MESSAGE_TYPE_FS_UNINDEX 134 + +/** + * Reply to client indicating unindex receipt. + */ +#define GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK 135 + +/** + * Client asks FS service to start a (keyword) search. + */ +#define GNUNET_MESSAGE_TYPE_FS_START_SEARCH 136 + +/** + * P2P request for content (one FS to another). + */ +#define GNUNET_MESSAGE_TYPE_FS_GET 137 + +/** + * P2P response with content or active migration of content. Also + * used between the service and clients (in response to START_SEARCH). + */ +#define GNUNET_MESSAGE_TYPE_FS_PUT 138 + +/** + * Peer asks us to stop migrating content towards it for a while. + */ +#define GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP 139 + + +/******************************************************************************* + * DHT message types + ******************************************************************************/ + +/** + * Client wants to store item in DHT. + */ +#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT 142 + +/** + * Client wants to lookup item in DHT. + */ +#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET 143 + +/** + * Client wants to stop search in DHT. + */ +#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP 144 + +/** + * Service returns result to client. + */ +#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT 145 + +/** + * Peer is storing data in DHT. + */ +#define GNUNET_MESSAGE_TYPE_DHT_P2P_PUT 146 + +/** + * Peer tries to find data in DHT. + */ +#define GNUNET_MESSAGE_TYPE_DHT_P2P_GET 147 + +/** + * Data is returned to peer from DHT. + */ +#define GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT 148 + +/** + * Request / receive information about transiting GETs + */ +#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET 149 + +/** + * Request / receive information about transiting GET responses + */ +#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP 150 + +/** + * Request / receive information about transiting PUTs + */ +#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT 151 + +/** + * Request / receive information about transiting PUT responses (TODO) + */ +#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT_RESP 152 + + +/******************************************************************************* + * HOSTLIST message types + ******************************************************************************/ + +/** + * Hostlist advertisement message + */ +#define GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT 160 + + +/******************************************************************************* + * STATISTICS message types + ******************************************************************************/ + +/** + * Set a statistical value. + */ +#define GNUNET_MESSAGE_TYPE_STATISTICS_SET 168 + +/** + * Get a statistical value(s). + */ +#define GNUNET_MESSAGE_TYPE_STATISTICS_GET 169 + +/** + * Response to a STATISTICS_GET message (with value). + */ +#define GNUNET_MESSAGE_TYPE_STATISTICS_VALUE 170 + +/** + * Response to a STATISTICS_GET message (end of value stream). + */ +#define GNUNET_MESSAGE_TYPE_STATISTICS_END 171 + +/** + * Watch changes to a statistical value. Message format is the same + * as for GET, except that the subsystem and entry name must be given. + */ +#define GNUNET_MESSAGE_TYPE_STATISTICS_WATCH 172 + +/** + * Changes to a watched value. + */ +#define GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE 173 + + +/******************************************************************************* + * VPN message types + ******************************************************************************/ + +/** + * Type of messages between the gnunet-vpn-helper and the daemon + */ +#define GNUNET_MESSAGE_TYPE_VPN_HELPER 185 + +/** + * Type of messages containing an ICMP packet for a service. + */ +#define GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE 190 + +/** + * Type of messages containing an ICMP packet for the Internet. + */ +#define GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET 191 + +/** + * Type of messages containing an ICMP packet for the VPN + */ +#define GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN 192 + +/** + * Type of messages containing an DNS request for a DNS exit service. + */ +#define GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET 193 + +/** + * Type of messages containing an DNS reply from a DNS exit service. + */ +#define GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET 194 + +/** + * Type of messages containing an TCP packet for a service. + */ +#define GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START 195 + +/** + * Type of messages containing an TCP packet for the Internet. + */ +#define GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START 196 + +/** + * Type of messages containing an TCP packet of an established connection. + */ +#define GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT 197 + +/** + * Type of messages containing an TCP packet of an established connection. + */ +#define GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN 198 + +/** + * Type of messages containing an UDP packet for a service. + */ +#define GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE 199 + +/** + * Type of messages containing an UDP packet for the Internet. + */ +#define GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET 200 + +/** + * Type of messages containing an UDP packet from a remote host + */ +#define GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY 201 + + +/** + * Client asks VPN service to setup an IP to redirect traffic + * via an exit node to some global IP address. + */ +#define GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP 202 + +/** + * Client asks VPN service to setup an IP to redirect traffic + * to some peer offering a service. + */ +#define GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE 203 + +/** + * VPN service responds to client with an IP to use for the + * requested redirection. + */ +#define GNUNET_MESSAGE_TYPE_VPN_CLIENT_USE_IP 204 + + +/******************************************************************************* + * VPN-DNS message types + ******************************************************************************/ + + +/** + * Initial message from client to DNS service for registration. + */ +#define GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT 211 + +/** + * Type of messages between the gnunet-helper-dns and the service + */ +#define GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST 212 + +/** + * Type of messages between the gnunet-helper-dns and the service + */ +#define GNUNET_MESSAGE_TYPE_DNS_CLIENT_RESPONSE 213 + +/** + * Type of messages between the gnunet-helper-dns and the service + */ +#define GNUNET_MESSAGE_TYPE_DNS_HELPER 214 + + +/******************************************************************************* + * MESH message types + ******************************************************************************/ + +/** + * Type of message used to transport messages throug a MESH-tunnel (LEGACY) + */ +#define GNUNET_MESSAGE_TYPE_MESH 215 + +/** + * Type of message used to send another peer which messages we want to receive + * through a mesh-tunnel (LEGACY) + */ +#define GNUNET_MESSAGE_TYPE_MESH_HELLO 216 + +/** + * Request the creation of a path + */ +#define GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE 256 + +/** + * Request the modification of an existing path + */ +#define GNUNET_MESSAGE_TYPE_MESH_PATH_CHANGE 257 + +/** + * Notify that a connection of a path is no longer valid + */ +#define GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN 258 + +/** + * At some point, the route will spontaneously change + */ +#define GNUNET_MESSAGE_TYPE_MESH_PATH_CHANGED 259 + +/** + * Transport data in the mesh (origin->end) unicast + */ +#define GNUNET_MESSAGE_TYPE_MESH_UNICAST 260 + +/** + * Transport data to all peers in a tunnel + */ +#define GNUNET_MESSAGE_TYPE_MESH_MULTICAST 261 + +/** + * Transport data back in the mesh (end->origin) + */ +#define GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN 262 + +/** + * Send origin an ACK that the path is complete + */ +#define GNUNET_MESSAGE_TYPE_MESH_PATH_ACK 263 + +/** + * Avoid path timeouts + */ +#define GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE 264 + +/** + * Request the destuction of a path + */ +#define GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY 265 + +/** + * Request the destruction of a whole tunnel + */ +#define GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY 266 + +/** + * We need flow control + */ +#define GNUNET_MESSAGE_TYPE_MESH_SPEED_NOTIFY 270 + +/** + * Connect to the mesh service, specifying subscriptions + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT 272 + +/** + * Ask the mesh service to create a new tunnel + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE 273 + +/** + * Ask the mesh service to destroy a tunnel + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY 274 + +/** + * Ask the mesh service to add a peer to an existing tunnel + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD 275 + +/** + * Ask the mesh service to remove a peer from a tunnel + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL 276 + +/** + * Ask the mesh service to add a peer offering a service to an existing tunnel + */ +#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE 277 + +/** + * 640kb should be enough for everybody + */ +#define GNUNET_MESSAGE_TYPE_MESH_RESERVE_END 288 + + + +/******************************************************************************* + * CHAT message types START + ******************************************************************************/ + +/** + * Message sent from client to join a chat room. + */ +#define GNUNET_MESSAGE_TYPE_CHAT_JOIN_REQUEST 300 + +/** + * Message sent to client to indicate joining of another room member. + */ +#define GNUNET_MESSAGE_TYPE_CHAT_JOIN_NOTIFICATION 301 + +/** + * Message sent to client to indicate leaving of another room member. + */ +#define GNUNET_MESSAGE_TYPE_CHAT_LEAVE_NOTIFICATION 302 + +/** + * Notification sent by service to client indicating that we've received a chat + * message. + */ +#define GNUNET_MESSAGE_TYPE_CHAT_MESSAGE_NOTIFICATION 303 + +/** + * Request sent by client to transmit a chat message to another room members. + */ +#define GNUNET_MESSAGE_TYPE_CHAT_TRANSMIT_REQUEST 304 + +/** + * Receipt sent from a message receiver to the service to confirm delivery of + * a chat message. + */ +#define GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_RECEIPT 305 + +/** + * Notification sent from the service to the original sender + * to acknowledge delivery of a chat message. + */ +#define GNUNET_MESSAGE_TYPE_CHAT_CONFIRMATION_NOTIFICATION 306 + +/** + * P2P message sent to indicate joining of another room member. + */ +#define GNUNET_MESSAGE_TYPE_CHAT_P2P_JOIN_NOTIFICATION 307 + +/** + * P2P message sent to indicate leaving of another room member. + */ +#define GNUNET_MESSAGE_TYPE_CHAT_P2P_LEAVE_NOTIFICATION 308 + +/** + * P2P message sent to a newly connected peer to request its known clients in + * order to synchronize room members. + */ +#define GNUNET_MESSAGE_TYPE_CHAT_P2P_SYNC_REQUEST 309 + +/** + * Notification sent from one peer to another to indicate that we have received + * a chat message. + */ +#define GNUNET_MESSAGE_TYPE_CHAT_P2P_MESSAGE_NOTIFICATION 310 + +/** + * P2P receipt confirming delivery of a chat message. + */ +#define GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT 311 + + +/******************************************************************************* + * NSE (network size estimation) message types + ******************************************************************************/ + +/** + * client->service message indicating start + */ +#define GNUNET_MESSAGE_TYPE_NSE_START 321 + +/** + * P2P message sent from nearest peer + */ +#define GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD 322 + +/** + * service->client message indicating + */ +#define GNUNET_MESSAGE_TYPE_NSE_ESTIMATE 323 + + +/******************************************************************************* + * PEERINFO message types + ******************************************************************************/ + +/** + * Request update and listing of a peer. + */ +#define GNUNET_MESSAGE_TYPE_PEERINFO_GET 330 + +/** + * Request update and listing of all peers. + */ +#define GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL 331 + +/** + * Information about one of the peers. + */ +#define GNUNET_MESSAGE_TYPE_PEERINFO_INFO 332 + +/** + * End of information about other peers. + */ +#define GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END 333 + +/** + * Start notifying this client about all changes to + * the known peers until it disconnects. + */ +#define GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY 334 + +/******************************************************************************* + * ATS message types + ******************************************************************************/ + +/** + * Type of the 'struct ClientStartMessage' sent by clients to ATS to + * identify the type of the client. + */ +#define GNUNET_MESSAGE_TYPE_ATS_START 340 + +/** + * Type of the 'struct RequestAddressMessage' sent by clients to ATS + * to request an address to help connect. + */ +#define GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS 341 + +/** + * Type of the 'struct RequestAddressMessage' sent by clients to ATS + * to request an address to help connect. + */ +#define GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL 342 + +/** + * Type of the 'struct AddressUpdateMessage' sent by clients to ATS + * to inform ATS about performance changes. + */ +#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE 343 + +/** + * Type of the 'struct AddressDestroyedMessage' sent by clients to ATS + * to inform ATS about an address being unavailable. + */ +#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED 344 + +/** + * Type of the 'struct AddressSuggestionMessage' sent by ATS to clients + * to suggest switching to a different address. + */ +#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION 345 + +/** + * Type of the 'struct PeerInformationMessage' sent by ATS to clients + * to inform about QoS for a particular connection. + */ +#define GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION 346 + +/** + * Type of the 'struct ReservationRequestMessage' sent by clients to ATS + * to ask for inbound bandwidth reservations. + */ +#define GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST 347 + +/** + * Type of the 'struct ReservationResultMessage' sent by ATS to clients + * in response to a reservation request. + */ +#define GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT 348 + +/** + * Type of the 'struct ChangePreferenceMessage' sent by clients to ATS + * to ask for allocation preference changes. + */ +#define GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE 349 + +/** + * Type of the 'struct SessionReleaseMessage' sent by ATS to client + * to confirm that a session ID was destroyed. + */ +#define GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE 350 + +/** + * Type of the 'struct AddressUseMessage' sent by ATS to client + * to confirm that an address is used or not used anymore + */ +#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE 351 + + + + +/******************************************************************************* + * TRANSPORT message types + ******************************************************************************/ + +/** + * Message from the core saying that the transport + * server should start giving it messages. This + * should automatically trigger the transmission of + * a HELLO message. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_START 360 + +/** + * Message from TRANSPORT notifying about a + * client that connected to us. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT 361 + +/** + * Message from TRANSPORT notifying about a + * client that disconnected from us. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT 362 + +/** + * Request to TRANSPORT to transmit a message. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_SEND 363 + +/** + * Confirmation from TRANSPORT that message for transmission has been + * queued (and that the next message to this peer can now be passed to + * the service). Note that this confirmation does NOT imply that the + * message was fully transmitted. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK 364 + +/** + * Message from TRANSPORT notifying about a + * message that was received. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_RECV 365 + +/** + * Message telling transport to limit its receive rate. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA 366 + +/** + * Request to look addresses of peers in server. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING 367 + +/** + * Response to the address lookup request. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY 368 + +/** + * Register a client that wants to do blacklisting. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT 369 + +/** + * Query to a blacklisting client (is this peer blacklisted)? + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY 370 + +/** + * Reply from blacklisting client (answer to blacklist query). + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY 371 + +/** + * Transport PING message + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_PING 372 + +/** + * Transport PONG message + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_PONG 373 + +/** + * Message for transport service from a client asking that a + * connection be initiated with another peer. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT 374 + +/** + * Transport CONNECT message exchanged between transport services to + * indicate that a session should be marked as 'connected'. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT 375 + +/** + * Transport CONNECT_ACK message exchanged between transport services to + * indicate that a CONNECT message was accepted + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK 376 + +/** + * Transport CONNECT_ACK message exchanged between transport services to + * indicate that a CONNECT message was accepted + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK 377 + +/** + * Transport DISCONNECT message exchanged between transport services to + * indicate that a connection should be dropped. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT 378 + +/** + * Request to monitor addresses used by a peer or all peers. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE 380 + +/** + * Message send by a peer to notify the other to keep the session alive + * and measure latency in a regular interval + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE 381 + +/** + * Response to a GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE message to + * measure latency in a regular interval + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE 382 + + +/** + * Request to iterate over all known addresses. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE 383 + +/** + * Message send by a peer to notify the other to keep the session alive. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON 384 + +/******************************************************************************* + * STREAM LIRBRARY MESSAGES + ******************************************************************************/ + +/** + * Message containing data exchanged between stream end-points over mesh. + */ +#define GNUNET_MESSAGE_TYPE_STREAM_DATA 400 + +/** + * ACK message + */ +#define GNUNET_MESSAGE_TYPE_STREAM_ACK 401 + +/** + * Handshake hello message + */ +#define GNUNET_MESSAGE_TYPE_STREAM_HELLO 402 + +/** + * Handshake hello acknowledgement message + */ +#define GNUNET_MESSAGE_TYPE_STREAM_HELLO_ACK 403 + +/** + * Reset message + */ +#define GNUNET_MESSAGE_TYPE_STREAM_RESET 404 + +/** + * Transmit close message (data transmission no longer possible after this + * message) + */ +#define GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE 405 + +/** + * Transmit close acknowledgement message + */ +#define GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE_ACK 406 + +/** + * Receive close message (data is no loger read by the receiver after this + * message) + */ +#define GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE 407 + +/** + * Receive close acknowledgement message + */ +#define GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE_ACK 408 + +/** + * Stream close message (data is no longer sent or read after this message) + */ +#define GNUNET_MESSAGE_TYPE_STREAM_CLOSE 409 + +/** + * Close acknowledgement message + */ +#define GNUNET_MESSAGE_TYPE_STREAM_CLOSE_ACK 410 + +/******************************************************************************* + * FS-PUBLISH-HELPER IPC Messages + ******************************************************************************/ + +/** + * Progress information from the helper: found a file + */ +#define GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE 420 + +/** + * Progress information from the helper: found a directory + */ +#define GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY 421 + +/** + * Error signal from the helper. + */ +#define GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR 422 + +/** + * Signal that helper skipped a file. + */ +#define GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE 423 + +/** + * Signal that helper is done scanning the directory tree. + */ +#define GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE 424 + +/** + * Extracted meta data from the helper. + */ +#define GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA 425 + +/** + * Signal that helper is done. + */ +#define GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED 426 + +/******************************************************************************* + * NAMESTORE message types + ******************************************************************************/ + +/** + * Request update and listing of a peer. + */ +#define GNUNET_MESSAGE_TYPE_NAMESTORE_START 430 + +/** + * Next available: 440 + */ + +/******************************************************************************* + * TODO: we need a way to register message types centrally (via some webpage). + * For now: unofficial extensions should start at 48k, internal extensions + * define here should leave some room (4-10 additional messages to the previous + * extension). + ******************************************************************************/ + +/** + * Type used to match 'all' message types. + */ +#define GNUNET_MESSAGE_TYPE_ALL 65535 + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_PROTOCOLS_H */ +#endif +/* end of gnunet_protocols.h */ diff --git a/src/include/gnunet_pseudonym_lib.h b/src/include/gnunet_pseudonym_lib.h new file mode 100644 index 0000000..bde98ef --- /dev/null +++ b/src/include/gnunet_pseudonym_lib.h @@ -0,0 +1,140 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_pseudonym_lib.h + * @brief functions related to pseudonyms + * @author Christian Grothoff + */ + +#ifndef GNUNET_PSEUDONYM_LIB_H +#define GNUNET_PSEUDONYM_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" +#include "gnunet_configuration_lib.h" +#include "gnunet_container_lib.h" + +/** + * Iterator over all known pseudonyms. + * + * @param cls closure + * @param pseudonym hash code of public key of pseudonym + * @param md meta data known about the pseudonym + * @param rating the local rating of the pseudonym + * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort + */ +typedef int (*GNUNET_PSEUDONYM_Iterator) (void *cls, + const GNUNET_HashCode * pseudonym, + const struct GNUNET_CONTAINER_MetaData + * md, int rating); + +/** + * Change the ranking of a pseudonym. + * + * @param cfg overall configuration + * @param nsid id of the pseudonym + * @param delta by how much should the rating be changed? + * @return new rating of the namespace + */ +int +GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg, + const GNUNET_HashCode * nsid, int delta); + +/** + * Add a pseudonym to the set of known pseudonyms. + * For all pseudonym advertisements that we discover + * FS should automatically call this function. + * + * @param cfg overall configuration + * @param id the pseudonym identifier + * @param meta metadata for the pseudonym + */ +void +GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg, + const GNUNET_HashCode * id, + const struct GNUNET_CONTAINER_MetaData *meta); + + +/** + * List all known pseudonyms. + * + * @param cfg overall configuration + * @param iterator function to call for each pseudonym + * @param closure closure for iterator + * @return number of pseudonyms found + */ +int +GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_PSEUDONYM_Iterator iterator, void *closure); + +/** + * Register callback to be invoked whenever we discover + * a new pseudonym. + */ +int +GNUNET_PSEUDONYM_discovery_callback_register (const struct + GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_PSEUDONYM_Iterator + iterator, void *closure); + +/** + * Unregister namespace discovery callback. + */ +int +GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator + iterator, void *closure); + +/** + * Return the unique, human readable name for the given pseudonym. + * + * @return NULL on failure (should never happen) + */ +char * +GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg, + const GNUNET_HashCode * pseudo); + +/** + * Get the pseudonym ID belonging to the given human readable name. + * + * @return GNUNET_OK on success + */ +int +GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *hname, GNUNET_HashCode * psid); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_PSEUDONYM_LIB_H */ +#endif +/* end of gnunet_pseudonym_lib.h */ diff --git a/src/include/gnunet_resolver_service.h b/src/include/gnunet_resolver_service.h new file mode 100644 index 0000000..498400d --- /dev/null +++ b/src/include/gnunet_resolver_service.h @@ -0,0 +1,169 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_resolver_service.h + * @brief functions related to doing DNS lookups + * @author Christian Grothoff + */ + +#ifndef GNUNET_RESOLVER_SERVICE_H +#define GNUNET_RESOLVER_SERVICE_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_configuration_lib.h" +#include "gnunet_scheduler_lib.h" +#include "gnunet_time_lib.h" + + +/** + * Function called by the resolver for each address obtained from DNS. + * + * @param cls closure + * @param addr one of the addresses of the host, NULL for the last address + * @param addrlen length of the address + */ +typedef void (*GNUNET_RESOLVER_AddressCallback) (void *cls, + const struct sockaddr * addr, + socklen_t addrlen); + + +/** + * Handle to a request given to the resolver. Can be used to cancel + * the request prior to the timeout or successful execution. + */ +struct GNUNET_RESOLVER_RequestHandle; + +/** + * Create the connection to the resolver service. + * + * @param cfg configuration to use + */ +void +GNUNET_RESOLVER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Destroy the connection to the resolver service. + */ +void +GNUNET_RESOLVER_disconnect (void); + + +/** + * Convert a string to one or more IP addresses. + * + * @param hostname the hostname to resolve + * @param af AF_INET or AF_INET6; use AF_UNSPEC for "any" + * @param callback function to call with addresses + * @param callback_cls closure for callback + * @param timeout how long to try resolving + * @return handle that can be used to cancel the request, NULL on error + */ +struct GNUNET_RESOLVER_RequestHandle * +GNUNET_RESOLVER_ip_get (const char *hostname, int af, + struct GNUNET_TIME_Relative timeout, + GNUNET_RESOLVER_AddressCallback callback, + void *callback_cls); + + +/** + * Resolve our hostname to an IP address. + * + * @param af AF_INET or AF_INET6; use AF_UNSPEC for "any" + * @param callback function to call with addresses + * @param cls closure for callback + * @param timeout how long to try resolving + * @return handle that can be used to cancel the request, NULL on error + */ +struct GNUNET_RESOLVER_RequestHandle * +GNUNET_RESOLVER_hostname_resolve (int af, + struct GNUNET_TIME_Relative timeout, + GNUNET_RESOLVER_AddressCallback callback, + void *cls); + + +/** + * Function called by the resolver for each hostname obtained from DNS. + * + * @param cls closure + * @param hostname one of the names for the host, NULL + * on the last call to the callback + */ +typedef void (*GNUNET_RESOLVER_HostnameCallback) (void *cls, + const char *hostname); + +/** + * Get local fully qualified domain name + * + * @return local hostname, caller must free + */ +char * +GNUNET_RESOLVER_local_fqdn_get (void); + + +/** + * Perform a reverse DNS lookup. + * + * @param sa host address + * @param salen length of host address + * @param do_resolve use GNUNET_NO to return numeric hostname + * @param timeout how long to try resolving + * @param callback function to call with hostnames + * @param cls closure for callback + * @return handle that can be used to cancel the request, NULL on error + */ +struct GNUNET_RESOLVER_RequestHandle * +GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, socklen_t salen, + int do_resolve, + struct GNUNET_TIME_Relative timeout, + GNUNET_RESOLVER_HostnameCallback callback, + void *cls); + + +/** + * Cancel a request that is still pending with the resolver. + * Note that a client MUST NOT cancel a request that has + * been completed (i.e, the callback has been called to + * signal timeout or the final result). + * + * @param rh handle of request to cancel + */ +void +GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_RESOLVER_SERVICE_H */ +#endif +/* end of gnunet_resolver_service.h */ diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h new file mode 100644 index 0000000..e16ccc5 --- /dev/null +++ b/src/include/gnunet_scheduler_lib.h @@ -0,0 +1,555 @@ +/* + This file is part of GNUnet + (C) 2009, 2011 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/gnunet_scheduler_lib.h + * @brief API to schedule computations using continuation passing style + * @author Christian Grothoff + */ + +#ifndef GNUNET_SCHEDULER_LIB_H +#define GNUNET_SCHEDULER_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +/** + * Opaque reference to a task. + */ +typedef unsigned long long GNUNET_SCHEDULER_TaskIdentifier; + + +/** + * Constant used to indicate that the scheduled + * task has no others as prerequisites. + */ +#define GNUNET_SCHEDULER_NO_TASK ((GNUNET_SCHEDULER_TaskIdentifier) 0) + +/** + * Reasons why the schedule may have triggered + * the task now. + */ +enum GNUNET_SCHEDULER_Reason +{ + /** + * This is the very first task run during startup. + */ + GNUNET_SCHEDULER_REASON_STARTUP = 0, + + /** + * We are shutting down and are running all shutdown-related tasks + * (regardless of timeout, etc.). + */ + GNUNET_SCHEDULER_REASON_SHUTDOWN = 1, + + /** + * The specified timeout has expired. + * (also set if the delay given was 0). + */ + GNUNET_SCHEDULER_REASON_TIMEOUT = 2, + + /** + * The reading socket is ready. + */ + GNUNET_SCHEDULER_REASON_READ_READY = 4, + + /** + * The writing socket is ready. + */ + GNUNET_SCHEDULER_REASON_WRITE_READY = 8, + + /** + * The prerequisite task is done. + */ + GNUNET_SCHEDULER_REASON_PREREQ_DONE = 16 +}; + + +/** + * Valid task priorities. Use these, do not + * pass random integers! + */ +enum GNUNET_SCHEDULER_Priority +{ + /** + * Run with the same priority as the current job. + */ + GNUNET_SCHEDULER_PRIORITY_KEEP = 0, + + /** + * Run when otherwise idle. + */ + GNUNET_SCHEDULER_PRIORITY_IDLE = 1, + + /** + * Run as background job (higher than idle, + * lower than default). + */ + GNUNET_SCHEDULER_PRIORITY_BACKGROUND = 2, + + /** + * Run with the default priority (normal + * P2P operations). Any task that is scheduled + * without an explicit priority being specified + * will run with this priority. + */ + GNUNET_SCHEDULER_PRIORITY_DEFAULT = 3, + + /** + * Run with high priority (important requests). + * Higher than DEFAULT. + */ + GNUNET_SCHEDULER_PRIORITY_HIGH = 4, + + /** + * Run with priority for interactive tasks. + * Higher than "HIGH". + */ + GNUNET_SCHEDULER_PRIORITY_UI = 5, + + /** + * Run with priority for urgent tasks. Use + * for things like aborts and shutdowns that + * need to preempt "UI"-level tasks. + * Higher than "UI". + */ + GNUNET_SCHEDULER_PRIORITY_URGENT = 6, + + /** + * This is an internal priority level that is only used for tasks + * that are being triggered due to shutdown (they have automatically + * highest priority). User code must not use this priority level + * directly. Tasks run with this priority level that internally + * schedule other tasks will see their original priority level + * be inherited (unless otherwise specified). + */ + GNUNET_SCHEDULER_PRIORITY_SHUTDOWN = 7, + + /** + * Number of priorities (must be the last priority). + * This priority must not be used by clients. + */ + GNUNET_SCHEDULER_PRIORITY_COUNT = 8 +}; + +#include "gnunet_time_lib.h" +#include "gnunet_network_lib.h" + + +/** + * Context information passed to each scheduler task. + */ +struct GNUNET_SCHEDULER_TaskContext +{ + /** + * Reason why the task is run now + */ + enum GNUNET_SCHEDULER_Reason reason; + + /** + * Set of file descriptors ready for reading; + * note that additional bits may be set + * that were not in the original request + */ + const struct GNUNET_NETWORK_FDSet *read_ready; + + /** + * Set of file descriptors ready for writing; + * note that additional bits may be set + * that were not in the original request. + */ + const struct GNUNET_NETWORK_FDSet *write_ready; + +}; + + +/** + * Signature of the main function of a task. + * + * @param cls closure + * @param tc context information (why was this task triggered now) + */ +typedef void (*GNUNET_SCHEDULER_Task) (void *cls, + const struct GNUNET_SCHEDULER_TaskContext + * tc); + + +/** + * Signature of the select function used by the scheduler. + * GNUNET_NETWORK_socket_select matches it. + * + * @param cls closure + * @param rfds set of sockets to be checked for readability + * @param wfds set of sockets to be checked for writability + * @param efds set of sockets to be checked for exceptions + * @param timeout relative value when to return + * @return number of selected sockets, GNUNET_SYSERR on error + */ +typedef int (*GNUNET_SCHEDULER_select) (void *cls, + struct GNUNET_NETWORK_FDSet * rfds, + 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 + * (and other similar signals) will cause "GNUNET_SCHEDULER_shutdown" + * to be run after the active task is complete. As a result, SIGTERM + * causes all active tasks to be scheduled with reason + * "GNUNET_SCHEDULER_REASON_SHUTDOWN". (However, tasks added + * afterwards will execute normally!). Note that any particular + * signal will only shut down one scheduler; applications should + * always only create a single scheduler. + * + * @param task task to run first (and immediately) + * @param task_cls closure of task + */ +void +GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls); + + +/** + * Request the shutdown of a scheduler. Marks all currently + * pending tasks as ready because of shutdown. This will + * cause all tasks to run (as soon as possible, respecting + * priorities and prerequisite tasks). Note that tasks + * scheduled AFTER this call may still be delayed arbitrarily. + */ +void +GNUNET_SCHEDULER_shutdown (); + + +/** + * Get information about the current load of this scheduler. Use this + * function to determine if an elective task should be added or simply + * dropped (if the decision should be made based on the number of + * tasks ready to run). + * + * * @param p priority-level to query, use KEEP to query the level + * of the current task, use COUNT to get the sum over + * all priority levels + * @return number of tasks pending right now + */ +unsigned int +GNUNET_SCHEDULER_get_load (enum GNUNET_SCHEDULER_Priority p); + + +/** + * Obtain the reason code for why the current task was + * started. Will return the same value as + * the GNUNET_SCHEDULER_TaskContext's reason field. + * + * * @return reason(s) why the current task is run + */ +enum GNUNET_SCHEDULER_Reason +GNUNET_SCHEDULER_get_reason (void); + + +/** + * Cancel the task with the specified identifier. + * The task must not yet have run. + * + * * @param task id of the task to cancel + * @return the closure of the callback of the cancelled task + */ +void * +GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task); + + +/** + * Continue the current execution with the given function. This is + * similar to the other "add" functions except that there is no delay + * and the reason code can be specified. + * + * * @param task main function of the task + * @param task_cls closure of task + * @param reason reason for task invocation + */ +void +GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, + enum GNUNET_SCHEDULER_Reason reason); + + +/** + * Continue the current execution with the given function. This is + * similar to the other "add" functions except that there is no delay + * and the reason code can be specified. + * + * @param task main function of the task + * @param task_cls closure for 'main' + * @param reason reason for task invocation + * @param priority priority to use for the task + */ +void +GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_Task task, void *task_cls, + enum GNUNET_SCHEDULER_Reason reason, + enum GNUNET_SCHEDULER_Priority priority); + + +/** + * Schedule a new task to be run after the specified prerequisite task + * has completed. It will be run with DEFAULT priority. + * + * * @param prerequisite_task run this task after the task with the given + * task identifier completes (and any of our other + * conditions, such as delay, read or write-readiness + * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency + * on completion of other tasks (this will cause the task to run as + * soon as possible). + * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, + GNUNET_SCHEDULER_Task task, void *task_cls); + + +/** + * Schedule a new task to be run with a specified priority. + * + * * @param prio how important is the new task? + * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio, + GNUNET_SCHEDULER_Task task, void *task_cls); + + +/** + * Schedule a new task to be run as soon as possible. The task + * will be run with the DEFAULT priority. + * + * * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls); + + +/** + * Schedule a new task to be run as soon as possible with the + * (transitive) ignore-shutdown flag either explicitly set or + * explicitly enabled. This task (and all tasks created from it, + * other than by another call to this function) will either count or + * not count for the 'lifeness' of the process. This API is only + * useful in a few special cases. + * + * @param lifeness GNUNET_YES if the task counts for lifeness, GNUNET_NO if not. + * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness, + GNUNET_SCHEDULER_Task task, + void *task_cls); + + +/** + * Schedule a new task to be run with a specified delay. The task + * will be scheduled for execution once the delay has expired. It + * will be run with the DEFAULT priority. + * + * * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" + * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, + GNUNET_SCHEDULER_Task task, void *task_cls); + + +/** + * Schedule a new task to be run with a specified delay. The task + * will be scheduled for execution once the delay has expired. + * + * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" + * @param priority priority to use for the task + * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay, + enum GNUNET_SCHEDULER_Priority priority, + GNUNET_SCHEDULER_Task task, void *task_cls); + + +/** + * Schedule a new task to be run with a specified delay or when the + * specified file descriptor is ready for reading. The delay can be + * used as a timeout on the socket being ready. The task will be + * scheduled for execution once either the delay has expired or the + * socket operation is ready. It will be run with the DEFAULT priority. + * + * * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" + * @param rfd read file-descriptor + * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay, + struct GNUNET_NETWORK_Handle *rfd, + GNUNET_SCHEDULER_Task task, void *task_cls); + + +/** + * Schedule a new task to be run with a specified delay or when the + * specified file descriptor is ready for writing. The delay can be + * used as a timeout on the socket being ready. The task will be + * scheduled for execution once either the delay has expired or the + * socket operation is ready. It will be run with the DEFAULT priority. + * + * * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" + * @param wfd write file-descriptor + * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay, + struct GNUNET_NETWORK_Handle *wfd, + GNUNET_SCHEDULER_Task task, void *task_cls); + + +/** + * Schedule a new task to be run with a specified delay or when the + * specified file descriptor is ready for reading. The delay can be + * used as a timeout on the socket being ready. The task will be + * scheduled for execution once either the delay has expired or the + * socket operation is ready. It will be run with the DEFAULT priority. + * + * * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" + * @param rfd read file-descriptor + * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay, + const struct GNUNET_DISK_FileHandle *rfd, + GNUNET_SCHEDULER_Task task, void *task_cls); + + +/** + * Schedule a new task to be run with a specified delay or when the + * specified file descriptor is ready for writing. The delay can be + * used as a timeout on the socket being ready. The task will be + * scheduled for execution once either the delay has expired or the + * socket operation is ready. It will be run with the DEFAULT priority. + * + * * @param delay when should this operation time out? Use + * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" + * @param wfd write file-descriptor + * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay, + const struct GNUNET_DISK_FileHandle *wfd, + GNUNET_SCHEDULER_Task task, void *task_cls); + + +/** + * Schedule a new task to be run with a specified delay or when any of + * the specified file descriptor sets is ready. The delay can be used + * as a timeout on the socket(s) being ready. The task will be + * scheduled for execution once either the delay has expired or any of + * the socket operations is ready. This is the most general + * function of the "add" family. Note that the "prerequisite_task" + * must be satisfied in addition to any of the other conditions. In + * other words, the task will be started when + * <code> + * (prerequisite-run) + * && (delay-ready + * || any-rs-ready + * || any-ws-ready + * || shutdown-active) + * </code> + * + * * @param prio how important is this task? + * @param prerequisite_task run this task after the task with the given + * task identifier completes (and any of our other + * conditions, such as delay, read or write-readiness + * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency + * on completion of other tasks. + * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever", + * which means that the task will only be run after we receive SIGTERM + * @param rs set of file descriptors we want to read (can be NULL) + * @param ws set of file descriptors we want to write (can be NULL) + * @param task main function of the task + * @param task_cls closure of task + * @return unique task identifier for the job + * only valid until "task" is started! + */ +GNUNET_SCHEDULER_TaskIdentifier +GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, + GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, + struct GNUNET_TIME_Relative delay, + const struct GNUNET_NETWORK_FDSet *rs, + const struct GNUNET_NETWORK_FDSet *ws, + GNUNET_SCHEDULER_Task task, void *task_cls); + +/** + * Sets the select function to use in the scheduler (scheduler_select). + * + * @param new_select new select function to use (NULL to reset to default) + * @param new_select_cls closure for 'new_select' + */ +void +GNUNET_SCHEDULER_set_select (GNUNET_SCHEDULER_select new_select, + void *new_select_cls); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/gnunet_server_lib.h b/src/include/gnunet_server_lib.h new file mode 100644 index 0000000..7fb8ae7 --- /dev/null +++ b/src/include/gnunet_server_lib.h @@ -0,0 +1,715 @@ +/* + This file is part of GNUnet. + (C) 2009, 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_server_lib.h + * @brief library for building GNUnet network servers + * + * @author Christian Grothoff + */ + +#ifndef GNUNET_SERVER_LIB_H +#define GNUNET_SERVER_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" +#include "gnunet_connection_lib.h" + + +/** + * Largest supported message. + */ +#define GNUNET_SERVER_MAX_MESSAGE_SIZE 65536 + +/** + * Smallest supported message. + */ +#define GNUNET_SERVER_MIN_BUFFER_SIZE sizeof (struct GNUNET_MessageHeader) + +/** + * @brief handle for a server + */ +struct GNUNET_SERVER_Handle; + + +/** + * @brief opaque handle for a client of the server + */ +struct GNUNET_SERVER_Client; + + +/** + * Functions with this signature are called whenever a message is + * received. + * + * @param cls closure + * @param client identification of the client + * @param message the actual message + */ +typedef void (*GNUNET_SERVER_MessageCallback) (void *cls, + struct GNUNET_SERVER_Client * + client, + const struct GNUNET_MessageHeader + * message); + + + +/** + * Message handler. Each struct specifies how to handle on particular + * type of message received. + */ +struct GNUNET_SERVER_MessageHandler +{ + /** + * Function to call for messages of "type". + */ + GNUNET_SERVER_MessageCallback callback; + + /** + * Closure argument for "callback". + */ + void *callback_cls; + + /** + * Type of the message this handler covers. + */ + uint16_t type; + + /** + * Expected size of messages of this type. Use 0 for + * variable-size. If non-zero, messages of the given + * type will be discarded (and the connection closed) + * if they do not have the right size. + */ + uint16_t expected_size; + +}; + + +/** + * Create a new server. + * + * @param access function for access control + * @param access_cls closure for access + * @param lsocks NULL-terminated array of listen sockets + * @param idle_timeout after how long should we timeout idle connections? + * @param require_found if YES, connections sending messages of unknown type + * will be closed + * @return handle for the new server, NULL on error + * (typically, "port" already in use) + */ +struct GNUNET_SERVER_Handle * +GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access, + void *access_cls, + struct GNUNET_NETWORK_Handle **lsocks, + struct GNUNET_TIME_Relative idle_timeout, + int require_found); + +/** + * Create a new server. + * + * @param access function for access control + * @param access_cls closure for access + * @param serverAddr address toes listen on (including port), NULL terminated array + * @param socklen lengths of respective serverAddr + * @param idle_timeout after how long should we timeout idle connections? + * @param require_found if YES, connections sending messages of unknown type + * will be closed + * @return handle for the new server, NULL on error + * (typically, "port" already in use) + */ +struct GNUNET_SERVER_Handle * +GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, void *access_cls, + struct sockaddr *const *serverAddr, + const socklen_t * socklen, + struct GNUNET_TIME_Relative idle_timeout, + int require_found); + + +/** + * Free resources held by this server. + * + * @param s server to destroy + */ +void +GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s); + + +/** + * Add additional handlers to an existing server. + * + * @param server the server to add handlers to + * @param handlers array of message handlers for + * incoming messages; the last entry must + * have "NULL" for the "callback"; multiple + * entries for the same type are allowed, + * they will be called in order of occurence. + * These handlers can be removed later; + * the handlers array must exist until removed + * (or server is destroyed). + */ +void +GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server, + const struct GNUNET_SERVER_MessageHandler + *handlers); + + +/** + * Notify us when the server has enough space to transmit + * a message of the given size to the given client. + * + * @param client client to transmit message to + * @param size requested amount of buffer space + * @param timeout after how long should we give up (and call + * notify with buf NULL and size 0)? + * @param callback function to call when space is available + * @param callback_cls closure for callback + * @return non-NULL if the notify callback was queued; can be used + * to cancel the request using + * GNUNET_CONNECTION_notify_transmit_ready_cancel. + * NULL if we are already going to notify someone else (busy) + */ +struct GNUNET_CONNECTION_TransmitHandle * +GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, + size_t size, + struct GNUNET_TIME_Relative timeout, + GNUNET_CONNECTION_TransmitReadyNotify + callback, void *callback_cls); + + +/** + * Set the persistent flag on this client, used to setup client connection + * to only be killed when the service it's connected to is actually dead. + * + * @param client the client to set the persistent flag on + */ +void +GNUNET_SERVER_client_persist_ (struct GNUNET_SERVER_Client *client); + +/** + * Resume receiving from this client, we are done processing the + * current request. This function must be called from within each + * GNUNET_SERVER_MessageCallback (or its respective continuations). + * + * @param client client we were processing a message of + * @param success GNUNET_OK to keep the connection open and + * continue to receive + * GNUNET_NO to close the connection (normal behavior) + * GNUNET_SYSERR to close the connection (signal + * serious error) + */ +void +GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client, int success); + + +/** + * Change the timeout for a particular client. Decreasing the timeout + * may not go into effect immediately (only after the previous timeout + * times out or activity happens on the socket). + * + * @param client the client to update + * @param timeout new timeout for activities on the socket + */ +void +GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client, + struct GNUNET_TIME_Relative timeout); + + +/** + * Set if a client should finish a pending write when disconnecting. + */ +void +GNUNET_SERVER_client_set_finish_pending_write (struct GNUNET_SERVER_Client *client, + int finish); + + +/** + * Disable the warning the server issues if a message is not acknowledged + * in a timely fashion. Use this call if a client is intentionally delayed + * for a while. Only applies to the current message. + * + * @param client client for which to disable the warning + */ +void +GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client + *client); + + +/** + * Inject a message into the server, pretend it came + * from the specified client. Delivery of the message + * will happen instantly (if a handler is installed; + * otherwise the call does nothing). + * + * @param server the server receiving the message + * @param sender the "pretended" sender of the message + * can be NULL! + * @param message message to transmit + * @return GNUNET_OK if the message was OK and the + * connection can stay open + * GNUNET_SYSERR if the connection to the + * client should be shut down + */ +int +GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server, + struct GNUNET_SERVER_Client *sender, + const struct GNUNET_MessageHeader *message); + + +/** + * Add a TCP socket-based connection to the set of handles managed by + * this server. Use this function for outgoing (P2P) connections that + * we initiated (and where this server should process incoming + * messages). + * + * @param server the server to use + * @param connection the connection to manage (client must + * stop using this connection from now on) + * @return the client handle (client should call + * "client_drop" on the return value eventually) + */ +struct GNUNET_SERVER_Client * +GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, + struct GNUNET_CONNECTION_Handle *connection); + + +/** + * Notify the server that the given client handle should + * be kept (keeps the connection up if possible, increments + * the internal reference counter). + * + * @param client the client to keep + */ +void +GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client); + + +/** + * Notify the server that the given client handle is no + * longer required. Decrements the reference counter. If + * that counter reaches zero an inactive connection maybe + * closed. + * + * @param client the client to drop + */ +void +GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client); + + +/** + * Obtain the network address of the other party. + * + * @param client the client to get the address for + * @param addr where to store the address + * @param addrlen where to store the length of the address + * @return GNUNET_OK on success + */ +int +GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client, + void **addr, size_t * addrlen); + + +/** + * Functions with this signature are called whenever a client + * is disconnected on the network level. + * + * @param cls closure + * @param client identification of the client; NULL + * for the last call when the server is destroyed + */ +typedef void (*GNUNET_SERVER_DisconnectCallback) (void *cls, + struct GNUNET_SERVER_Client * + client); + + +/** + * Ask the server to notify us whenever a client disconnects. + * This function is called whenever the actual network connection + * is closed; the reference count may be zero or larger than zero + * at this point. If the server is destroyed before this + * notification is explicitly cancelled, the 'callback' will + * once be called with a 'client' argument of NULL to indicate + * that the server itself is now gone (and that the callback + * won't be called anymore and also can no longer be cancelled). + * + * @param server the server manageing the clients + * @param callback function to call on disconnect + * @param callback_cls closure for callback + */ +void +GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server, + GNUNET_SERVER_DisconnectCallback callback, + void *callback_cls); + + +/** + * Ask the server to stop notifying us whenever a client disconnects. + * + * @param server the server manageing the clients + * @param callback function to call on disconnect + * @param callback_cls closure for callback + */ +void +GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server, + GNUNET_SERVER_DisconnectCallback + callback, void *callback_cls); + + +/** + * Ask the server to disconnect from the given client. + * This is the same as returning GNUNET_SYSERR from a message + * handler, except that it allows dropping of a client even + * when not handling a message from that client. + * + * @param client the client to disconnect from + */ +void +GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client); + + +/** + * Configure this server's connections to continue handling client + * requests as usual even after we get a shutdown signal. The change + * only applies to clients that connect to the server from the outside + * using TCP after this call. Clients managed previously or those + * added using GNUNET_SERVER_connect_socket and + * GNUNET_SERVER_connect_callback are not affected by this option. + * + * @param h server handle + * @param do_ignore GNUNET_YES to ignore, GNUNET_NO to restore default + */ +void +GNUNET_SERVER_ignore_shutdown (struct GNUNET_SERVER_Handle *h, int do_ignore); + + + +/** + * Disable the "CORK" feature for communication with the given client, + * forcing the OS to immediately flush the buffer on transmission + * instead of potentially buffering multiple messages. + * + * @param client handle to the client + * @return GNUNET_OK on success + */ +int +GNUNET_SERVER_client_disable_corking (struct GNUNET_SERVER_Client *client); + + +/** + * The tansmit context is the key datastructure for a conveniance API + * used for transmission of complex results to the client followed + * ONLY by signaling receive_done with success or error + */ +struct GNUNET_SERVER_TransmitContext; + + +/** + * Create a new transmission context for the + * given client. + * + * @param client client to create the context for. + * @return NULL on error + */ +struct GNUNET_SERVER_TransmitContext * +GNUNET_SERVER_transmit_context_create (struct GNUNET_SERVER_Client *client); + + +/** + * Append a message to the transmission context. + * All messages in the context will be sent by + * the transmit_context_run method. + * + * @param tc context to use + * @param data what to append to the result message + * @param length length of data + * @param type type of the message + */ +void +GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext + *tc, const void *data, + size_t length, uint16_t type); + + +/** + * Append a message to the transmission context. + * All messages in the context will be sent by + * the transmit_context_run method. + * + * @param tc context to use + * @param msg message to append + */ +void +GNUNET_SERVER_transmit_context_append_message (struct + GNUNET_SERVER_TransmitContext + *tc, + const struct GNUNET_MessageHeader + *msg); + + +/** + * Execute a transmission context. If there is an error in the + * transmission, the receive_done method will be called with an error + * code (GNUNET_SYSERR), otherwise with GNUNET_OK. + * + * @param tc transmission context to use + * @param timeout when to time out and abort the transmission + */ +void +GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc, + struct GNUNET_TIME_Relative timeout); + + +/** + * Destroy a transmission context. This function must not be called + * after 'GNUNET_SERVER_transmit_context_run'. + * + * @param tc transmission context to destroy + * @param success code to give to 'GNUNET_SERVER_receive_done' for + * the client: GNUNET_OK to keep the connection open and + * continue to receive + * GNUNET_NO to close the connection (normal behavior) + * GNUNET_SYSERR to close the connection (signal + * serious error) + */ +void +GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext + *tc, int success); + + +/** + * 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. + */ +struct GNUNET_SERVER_NotificationContext; + + +/** + * Create a new notification context. + * + * @param server server for which this function creates the context + * @param queue_length maximum number of messages to keep in + * the notification queue; optional messages are dropped + * if the queue gets longer than this number of messages + * @return handle to the notification context + */ +struct GNUNET_SERVER_NotificationContext * +GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle *server, + unsigned int queue_length); + + +/** + * Destroy the context, force disconnect for all clients. + * + * @param nc context to destroy. + */ +void +GNUNET_SERVER_notification_context_destroy (struct + GNUNET_SERVER_NotificationContext + *nc); + + +/** + * Add a client to the notification context. + * + * @param nc context to modify + * @param client client to add + */ +void +GNUNET_SERVER_notification_context_add (struct GNUNET_SERVER_NotificationContext + *nc, + struct GNUNET_SERVER_Client *client); + + +/** + * Send a message to a particular client; must have + * already been added to the notification context. + * + * @param nc context to modify + * @param client client to transmit to + * @param msg message to send + * @param can_drop can this message be dropped due to queue length limitations + */ +void +GNUNET_SERVER_notification_context_unicast (struct + GNUNET_SERVER_NotificationContext + *nc, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader + *msg, int can_drop); + + +/** + * Send a message to all clients of this context. + * + * @param nc context to modify + * @param msg message to send + * @param can_drop can this message be dropped due to queue length limitations + */ +void +GNUNET_SERVER_notification_context_broadcast (struct + GNUNET_SERVER_NotificationContext + *nc, + const struct GNUNET_MessageHeader + *msg, int can_drop); + + + +/** + * Handle to a message stream tokenizer. + */ +struct GNUNET_SERVER_MessageStreamTokenizer; + +/** + * Functions with this signature are called whenever a + * complete message is received by the tokenizer. + * + * @param cls closure + * @param client identification of the client + * @param message the actual message + */ +typedef void (*GNUNET_SERVER_MessageTokenizerCallback) (void *cls, void *client, + const struct + GNUNET_MessageHeader * + message); + + +/** + * Create a message stream tokenizer. + * + * @param cb function to call on completed messages + * @param cb_cls closure for cb + * @return handle to tokenizer + */ +struct GNUNET_SERVER_MessageStreamTokenizer * +GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, + void *cb_cls); + + +/** + * Add incoming data to the receive buffer and call the + * callback for all complete messages. + * + * @param mst tokenizer to use + * @param client_identity ID of client for which this is a buffer, + * can be NULL (will be passed back to 'cb') + * @param buf input data to add + * @param size number of bytes in buf + * @param purge should any excess bytes in the buffer be discarded + * (i.e. for packet-based services like UDP) + * @param one_shot only call callback once, keep rest of message in buffer + * @return GNUNET_OK if we are done processing (need more data) + * GNUNET_NO if one_shot was set and we have another message ready + * GNUNET_SYSERR if the data stream is corrupt + */ +int +GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, + void *client_identity, const char *buf, size_t size, + int purge, int one_shot); + + +/** + * Destroys a tokenizer. + * + * @param mst tokenizer to destroy + */ +void +GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst); + + +/** + * Signature of a function to create a custom tokenizer. + * + * @param cls closure from 'GNUNET_SERVER_set_callbacks' + * @param client handle to client the tokenzier will be used for + * @return handle to custom tokenizer ('mst') + */ +typedef void* (*GNUNET_SERVER_MstCreateCallback) (void *cls, + struct GNUNET_SERVER_Client *client); + +/** + * Signature of a function to destroy a custom tokenizer. + * + * @param cls closure from 'GNUNET_SERVER_set_callbacks' + * @param mst custom tokenizer handle + */ +typedef void (*GNUNET_SERVER_MstDestroyCallback) (void *cls, void *mst); + +/** + * Signature of a function to destroy a custom tokenizer. + * + * @param cls closure from 'GNUNET_SERVER_set_callbacks' + * @param mst custom tokenizer handle + * @param client_identity ID of client for which this is a buffer, + * can be NULL (will be passed back to 'cb') + * @param buf input data to add + * @param size number of bytes in buf + * @param purge should any excess bytes in the buffer be discarded + * (i.e. for packet-based services like UDP) + * @param one_shot only call callback once, keep rest of message in buffer + * @return GNUNET_OK if we are done processing (need more data) + * GNUNET_NO if one_shot was set and we have another message ready + * GNUNET_SYSERR if the data stream is corrupt + */ +typedef int (*GNUNET_SERVER_MstReceiveCallback) (void *cls, void *mst, + struct GNUNET_SERVER_Client *client, + const char *buf, size_t size, + int purge, int one_shot); + + +/** + * Change functions used by the server to tokenize the message stream. + * (very rarely used). + * + * @param server server to modify + * @param create new tokenizer initialization function + * @param destroy new tokenizer destruction function + * @param receive new tokenizer receive function + * @param cls closure for 'create', 'receive', 'destroy' + */ +void +GNUNET_SERVER_set_callbacks (struct GNUNET_SERVER_Handle *server, + GNUNET_SERVER_MstCreateCallback create, + GNUNET_SERVER_MstDestroyCallback destroy, + GNUNET_SERVER_MstReceiveCallback receive, + void *cls); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + + +/* ifndef GNUNET_SERVER_LIB_H */ +#endif +/* end of gnunet_server_lib.h */ diff --git a/src/include/gnunet_service_lib.h b/src/include/gnunet_service_lib.h new file mode 100644 index 0000000..1641e0f --- /dev/null +++ b/src/include/gnunet_service_lib.h @@ -0,0 +1,164 @@ +/* + This file is part of GNUnet. + (C) 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_service_lib.h + * @brief functions related to starting services + * @author Christian Grothoff + */ + +#ifndef GNUNET_SERVICE_LIB_H +#define GNUNET_SERVICE_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_configuration_lib.h" +#include "gnunet_server_lib.h" + + +/** + * Get the list of addresses that a server for the given service + * should bind to. + * + * @param serviceName name of the service + * @param cfg configuration (which specifies the addresses) + * @param addrs set (call by reference) to an array of pointers to the + * addresses the server should bind to and listen on; the + * array will be NULL-terminated (on success) + * @param addr_lens set (call by reference) to an array of the lengths + * of the respective 'struct sockaddr' struct in the 'addrs' + * array (on success) + * @return number of addresses found on success, + * GNUNET_SYSERR if the configuration + * did not specify reasonable finding information or + * if it specified a hostname that could not be resolved; + * GNUNET_NO if the number of addresses configured is + * zero (in this case, '*addrs' and '*addr_lens' will be + * set to NULL). + */ +int +GNUNET_SERVICE_get_server_addresses (const char *serviceName, + const struct GNUNET_CONFIGURATION_Handle + *cfg, struct sockaddr ***addrs, + socklen_t ** addr_lens); + + +/** + * Function called by the service's run + * method to run service-specific setup code. + * + * @param cls closure + * @param server the initialized server + * @param cfg configuration to use + */ +typedef void (*GNUNET_SERVICE_Main) (void *cls, + struct GNUNET_SERVER_Handle * server, + const struct GNUNET_CONFIGURATION_Handle * + cfg); + + +/** + * Options for the service (bitmask). + */ +enum GNUNET_SERVICE_Options +{ + /** + * Use defaults. + */ + GNUNET_SERVICE_OPTION_NONE = 0, + + /** + * Do not trigger server shutdown on signals, allow for the user + * to terminate the server explicitly when needed. + */ + GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN = 1 +}; + + +/** + * Run a standard GNUnet service startup sequence (initialize loggers + * and configuration, parse options). + * + * @param argc number of command line arguments + * @param argv command line arguments + * @param serviceName our service name + * @param opt service options + * @param task main task of the service + * @param task_cls closure for task + * @return GNUNET_SYSERR on error, GNUNET_OK + * if we shutdown nicely + */ +int +GNUNET_SERVICE_run (int argc, char *const *argv, const char *serviceName, + enum GNUNET_SERVICE_Options opt, GNUNET_SERVICE_Main task, + void *task_cls); + + +struct GNUNET_SERVICE_Context; + +/** + * Run a service startup sequence within an existing + * initialized system. + * + * @param serviceName our service name + * @param cfg configuration to use + * @return NULL on error, service handle + */ +struct GNUNET_SERVICE_Context * +GNUNET_SERVICE_start (const char *serviceName, + const struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Obtain the server used by a service. Note that the server must NOT + * be destroyed by the caller. + * + * @param ctx the service context returned from the start function + * @return handle to the server for this service, NULL if there is none + */ +struct GNUNET_SERVER_Handle * +GNUNET_SERVICE_get_server (struct GNUNET_SERVICE_Context *ctx); + + +/** + * Stop a service that was started with "GNUNET_SERVICE_start". + * + * @param sctx the service context returned from the start function + */ +void +GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_SERVICE_LIB_H */ +#endif +/* end of gnunet_service_lib.h */ diff --git a/src/include/gnunet_signal_lib.h b/src/include/gnunet_signal_lib.h new file mode 100644 index 0000000..1597c76 --- /dev/null +++ b/src/include/gnunet_signal_lib.h @@ -0,0 +1,84 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_signal_lib.h + * @brief functions related to signals + * @author Christian Grothoff + */ + +#ifndef GNUNET_SIGNAL_LIB_H +#define GNUNET_SIGNAL_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +/** + * Context created when a signal handler is installed; + * can be used to restore it to the previous state later. + */ +struct GNUNET_SIGNAL_Context; + +/** + * A signal handler. Since different OSes have different signatures + * for their handlers, the API only gives the most restrictive + * signature -- no arguments, no return value. Note that this will + * work even if the OS expects a function with arguments. However, + * the implementation must guarantee that this handler is not called + * for signals other than the one that it has been registered for. + */ +typedef void (*GNUNET_SIGNAL_Handler) (void); + +/** + * Install a signal handler that will be run if the + * given signal is received. + * + * @param signal the number of the signal + * @param handler the function to call + * @return context that can be used to restore, NULL on error + */ +struct GNUNET_SIGNAL_Context * +GNUNET_SIGNAL_handler_install (int signal, GNUNET_SIGNAL_Handler handler); + +/** + * Uninstall a previously installed signal hander. + * + * @param ctx context that was returned when the + * signal handler was installed + */ +void +GNUNET_SIGNAL_handler_uninstall (struct GNUNET_SIGNAL_Context *ctx); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_SIGNAL_LIB_H */ +#endif +/* end of gnunet_signal_lib.h */ diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h new file mode 100644 index 0000000..580282d --- /dev/null +++ b/src/include/gnunet_signatures.h @@ -0,0 +1,127 @@ +/* + This file is part of GNUnet. + (C) 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_signatures.h + * @brief constants for network signatures + * @author Christian Grothoff + */ + +#ifndef GNUNET_SIGNATURES_H +#define GNUNET_SIGNATURES_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +/** + * Test signature, not valid for anything other than writing + * a test. (Note that the signature verification code will + * accept this value). + */ +#define GNUNET_SIGNATURE_PURPOSE_TEST 0 + +/** + * Signature for confirming that this peer uses a particular address. + */ +#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN 1 + +/** + * Signature for confirming that this peer intends to disconnect. + */ +#define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DISCONNECT 2 + +/** + * Purpose is to set a session key. + */ +#define GNUNET_SIGNATURE_PURPOSE_SET_KEY 3 + +/** + * Signature for a namespace/pseudonym advertisement (by + * the namespace owner). + */ +#define GNUNET_SIGNATURE_PURPOSE_NAMESPACE_ADVERTISEMENT 4 + +/** + * Signature by which a peer affirms that it is + * providing a certain bit of content (used + * in LOCation URIs). + */ +#define GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT 5 + +/** + * Signature in a KBlock of the FS module. + */ +#define GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK 6 + +/** + * Signature of content URI placed into a namespace. + */ +#define GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK 7 + +/** + * Signature of advertisment for a namespace. + */ +#define GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK 8 + +/** + * Keyword-based signature of advertisment for a namespace. + */ +#define GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG 9 + +/** + * + */ +#define GNUNET_SIGNATURE_PURPOSE_RESOLVER_RESPONSE 10 + +/** + * Signature of an GNUNET_DNS_Record + */ +#define GNUNET_SIGNATURE_PURPOSE_DNS_RECORD 11 + +/** + * Signature of a chat message. + */ +#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE 12 + +/** + * Signature of confirmation receipt for a chat message. + */ +#define GNUNET_SIGNATURE_PURPOSE_CHAT_RECEIPT 13 + +/** + * Signature of a network size estimate message. + */ +#define GNUNET_SIGNATURE_PURPOSE_NSE_SEND 14 + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_SIGNATURES_H */ +#endif +/* end of gnunet_signatures.h */ diff --git a/src/include/gnunet_statistics_service.h b/src/include/gnunet_statistics_service.h new file mode 100644 index 0000000..bfd65f8 --- /dev/null +++ b/src/include/gnunet_statistics_service.h @@ -0,0 +1,205 @@ +/* + This file is part of GNUnet + (C) 2009, 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_statistics_service.h + * @brief API to create, modify and access statistics about + * the operation of GNUnet; all statistical values + * must be of type "unsigned long long". + * @author Christian Grothoff + */ + +#ifndef GNUNET_STATISTICS_SERVICE_H +#define GNUNET_STATISTICS_SERVICE_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" +#include "gnunet_configuration_lib.h" +#include "gnunet_scheduler_lib.h" + +/** + * Version of the statistics API. + */ +#define GNUNET_STATISTICS_VERSION 0x00000000 + +/** + * Opaque handle for the statistics service. + */ +struct GNUNET_STATISTICS_Handle; + +/** + * Callback function to process statistic values. + * + * @param cls closure + * @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 + */ +typedef int (*GNUNET_STATISTICS_Iterator) (void *cls, const char *subsystem, + const char *name, uint64_t value, + int is_persistent); + +/** + * Get handle for the statistics service. + * + * @param subsystem name of subsystem using the service + * @param cfg services configuration in use + * @return handle to use + */ +struct GNUNET_STATISTICS_Handle * +GNUNET_STATISTICS_create (const char *subsystem, + const struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Destroy a handle (free all state associated with + * it). + * + * @param h statistics handle to destroy + * @param sync_first set to GNUNET_YES if pending SET requests should + * be completed + */ +void +GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h, int sync_first); + + +/** + * Watch statistics from the peer (be notified whenever they change). + * + * @param handle identification of the statistics service + * @param subsystem limit to the specified subsystem, never NULL + * @param name name of the statistic value, never NULL + * @param proc function to call on each value + * @param proc_cls closure for proc + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle, + const char *subsystem, const char *name, + GNUNET_STATISTICS_Iterator proc, void *proc_cls); + + +/** + * Stop watching statistics from the peer. + * + * @param handle identification of the statistics service + * @param subsystem limit to the specified subsystem, never NULL + * @param name name of the statistic value, never NULL + * @param proc function to call on each value + * @param proc_cls closure for proc + * @return GNUNET_OK on success, GNUNET_SYSERR on error (no such watch) + */ +int +GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle, + const char *subsystem, const char *name, + GNUNET_STATISTICS_Iterator proc, void *proc_cls); + + +/** + * Continuation called by the "get_all" and "get" functions. + * + * @param cls closure + * @param success GNUNET_OK if statistics were + * successfully obtained, GNUNET_SYSERR if not. + */ +typedef void (*GNUNET_STATISTICS_Callback) (void *cls, int success); + + +/** + * Handle that can be used to cancel a statistics 'get' operation. + */ +struct GNUNET_STATISTICS_GetHandle; + +/** + * Get statistic from the peer. + * + * @param handle identification of the statistics service + * @param subsystem limit to the specified subsystem, NULL for our subsystem + * @param name name of the statistic value, NULL for all values + * @param timeout after how long should we give up (and call + * notify with buf NULL and size 0)? + * @param cont continuation to call when done (can be NULL) + * @param proc function to call on each value + * @param cls closure for proc and cont + * @return NULL on error + */ +struct GNUNET_STATISTICS_GetHandle * +GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, + const char *subsystem, const char *name, + struct GNUNET_TIME_Relative timeout, + GNUNET_STATISTICS_Callback cont, + GNUNET_STATISTICS_Iterator proc, void *cls); + + +/** + * Cancel a 'get' request. Must be called before the 'cont' + * function is called. + * + * @param gh handle of the request to cancel + */ +void +GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh); + + +/** + * Set statistic value for the peer. Will always use our + * subsystem (the argument used when "handle" was created). + * + * @param handle identification of the statistics service + * @param name name of the statistic value + * @param value new value to set + * @param make_persistent should the value be kept across restarts? + */ +void +GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, + const char *name, uint64_t value, int make_persistent); + +/** + * Set statistic value for the peer. Will always use our + * subsystem (the argument used when "handle" was created). + * + * @param handle identification of the statistics service + * @param name name of the statistic value + * @param delta change in value (added to existing value) + * @param make_persistent should the value be kept across restarts? + */ +void +GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, + const char *name, int64_t delta, int make_persistent); + + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/gnunet_stream_lib.h b/src/include/gnunet_stream_lib.h new file mode 100644 index 0000000..930cc1d --- /dev/null +++ b/src/include/gnunet_stream_lib.h @@ -0,0 +1,297 @@ +/* + This file is part of GNUnet. + (C) 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 + 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_stream_lib.h + * @brief stream handling using mesh API + * @author Sree Harsha Totakura + */ + +#ifndef GNUNET_STREAM_LIB_H +#define GNUNET_STREAM_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 +} +#endif +#endif + +#include "gnunet_util_lib.h" +#include "gnunet_mesh_service.h" + +/** + * Stream status + */ +enum GNUNET_STREAM_Status + { + /** + * All previous read/write operations are successfully done + */ + GNUNET_STREAM_OK = 0, + + /** + * A timeout occured while reading/writing the stream + */ + GNUNET_STREAM_TIMEOUT = 1, + + /** + * Other side has shutdown the socket for this type of operation + * (reading/writing) + */ + GNUNET_STREAM_SHUTDOWN = 2, + + /** + * A serious error occured while operating on this stream + */ + GNUNET_STREAM_SYSERR = 3 + }; + +/** + * Opaque handler for stream + */ +struct GNUNET_STREAM_Socket; + +/** + * Functions of this type will be called when a stream is established + * + * @param cls the closure from GNUNET_STREAM_open + * @param socket socket to use to communicate with the other side (read/write) + */ +typedef void (*GNUNET_STREAM_OpenCallback) (void *cls, + struct GNUNET_STREAM_Socket *socket); + + +/** + * Options for the stream. + */ +enum GNUNET_STREAM_Option + { + /** + * End of the option list. + */ + GNUNET_STREAM_OPTION_END = 0, + + /** + * Option to set the initial retransmission timeout (when do we retransmit + * a packet that did not yield an acknowledgement for the first time?). + * Repeated retransmissions will then use an exponential back-off. + * Takes a 'struct GNUNET_TIME_Relative' as the only argument. A value + * 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 + }; + + +/** + * Tries to open a stream to the target peer + * + * @param cfg configuration to use + * @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_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 + * opened + */ +struct GNUNET_STREAM_Socket * +GNUNET_STREAM_open (const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_PeerIdentity *target, + GNUNET_MESH_ApplicationType app_port, + GNUNET_STREAM_OpenCallback open_cb, + void *open_cb_cls, + ...); + + +/** + * Shutdown the stream for reading or writing (man 2 shutdown). + * + * @param socket the stream socket + * @param how SHUT_RD, SHUT_WR or SHUT_RDWR + */ +void +GNUNET_STREAM_shutdown (struct GNUNET_STREAM_Socket *socket, + int how); + + +/** + * Closes the stream + * + * @param socket the stream socket + */ +void +GNUNET_STREAM_close (struct GNUNET_STREAM_Socket *socket); + + +/** + * Functions of this type are called upon new stream connection from other peers + * + * @param cls the closure from GNUNET_STREAM_listen + * @param socket the socket representing the stream + * @param initiator the identity of the peer who wants to establish a stream + * with us + * @return GNUNET_OK to keep the socket open, GNUNET_SYSERR to close the + * stream (the socket will be invalid after the call) + */ +typedef int (*GNUNET_STREAM_ListenCallback) (void *cls, + struct GNUNET_STREAM_Socket *socket, + const struct + GNUNET_PeerIdentity *initiator); + + +/** + * A socket for listening. + */ +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 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 + * @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); + + +/** + * Closes the listen socket + * + * @param socket the listen socket + */ +void +GNUNET_STREAM_listen_close (struct GNUNET_STREAM_ListenSocket *socket); + + +/** + * Functions of this signature are called whenever writing operations + * 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 size the number of bytes written + */ +typedef void (*GNUNET_STREAM_CompletionContinuation) (void *cls, + enum GNUNET_STREAM_Status + status, + size_t size); + + +/** + * Handle to cancel IO write operations. + */ +struct GNUNET_STREAM_IOWriteHandle; + + +/** + * Handle to cancel IO read operations. + */ +struct GNUNET_STREAM_IOReadHandle; + +/** + * Tries to write the given data to the stream + * + * @param socket the socket representing a stream + * @param data the data buffer from where the data is written into the stream + * @param size the number of bytes to be written from the data buffer + * @param timeout the timeout period + * @param write_cont the function to call upon writing some bytes into the stream + * @param write_cont_cls the closure + * @return handle to cancel the operation; NULL if a previous write is pending + */ +struct GNUNET_STREAM_IOWriteHandle * +GNUNET_STREAM_write (struct GNUNET_STREAM_Socket *socket, + const void *data, + size_t size, + struct GNUNET_TIME_Relative timeout, + GNUNET_STREAM_CompletionContinuation write_cont, + void *write_cont_cls); + + +/** + * Functions of this signature are called whenever data is available from the + * stream. + * + * @param cls the closure from GNUNET_STREAM_read + * @param status the status of the stream at the time this function is called + * @param data traffic from the other side + * @param size the number of bytes available in data read + * @return number of bytes of processed from 'data' (any data remaining should be + * given to the next time the read processor is called). + */ +typedef size_t (*GNUNET_STREAM_DataProcessor) (void *cls, + enum GNUNET_STREAM_Status status, + const void *data, + size_t size); + + +/** + * Tries to read data from the stream + * + * @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 + */ +struct GNUNET_STREAM_IOReadHandle * +GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket, + struct GNUNET_TIME_Relative timeout, + GNUNET_STREAM_DataProcessor proc, + void *proc_cls); + + +/** + * Cancel pending write operation. + * + * @param ioh handle to operation to cancel + */ +void +GNUNET_STREAM_io_write_cancel (struct GNUNET_STREAM_IOWriteHandle *ioh); + + +/** + * Cancel pending read operation. + * + * @param ioh handle to operation to cancel + */ +void +GNUNET_STREAM_io_read_cancel (struct GNUNET_STREAM_IOReadHandle *ioh); + + +#if 0 +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif /* STREAM_PROTOCOL_H */ diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h new file mode 100644 index 0000000..8101a81 --- /dev/null +++ b/src/include/gnunet_strings_lib.h @@ -0,0 +1,226 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_strings_lib.h + * @brief strings and string handling functions (including malloc + * and string tokenizing) + * + * @author Christian Grothoff + * @author Krista Bennett + * @author Gerd Knorr <kraxel@bytesex.org> + * @author Ioana Patrascu + * @author Tzvetan Horozov + */ + +#ifndef GNUNET_STRINGS_LIB_H +#define GNUNET_STRINGS_LIB_H + +/* we need size_t, and since it can be both unsigned int + or unsigned long long, this IS platform dependent; + but "stdlib.h" should be portable 'enough' to be + unconditionally available... */ +#include <stdlib.h> + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_time_lib.h" + + +/** + * Convert a given fancy human-readable size to bytes. + * + * @param fancy_size human readable string (i.e. 1 MB) + * @param size set to the size in bytes + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size, + unsigned long long *size); + + +/** + * Convert a given fancy human-readable time to our internal + * representation. + * + * @param fancy_size human readable string (i.e. 1 minute) + * @param rtime set to the relative time + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_size, + struct GNUNET_TIME_Relative *rtime); + + +/** + * Convert a given filesize into a fancy human-readable format. + * + * @param size number of bytes + * @return fancy representation of the size (possibly rounded) for humans + */ +char * +GNUNET_STRINGS_byte_size_fancy (unsigned long long size); + + +/** + * Convert the len characters long character sequence + * given in input that is in the given input charset + * to a string in given output charset. + * @return the converted string (0-terminated), + * if conversion fails, a copy of the orignal + * string is returned. + */ +char * +GNUNET_STRINGS_conv (const char *input, size_t len, + const char *input_charset, const char *output_charset); + +/** + * Convert the len characters long character sequence + * given in input that is in the given charset + * to UTF-8. + * + * @param input the input string (not necessarily 0-terminated) + * @param len the number of bytes in the input + * @param charset character set to convert from + * @return the converted string (0-terminated) + */ +char * +GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset); + +/** + * Convert the len bytes-long UTF-8 string + * given in input to the given charset. + + * @return the converted string (0-terminated), + * if conversion fails, a copy of the orignal + * string is returned. + */ +char * +GNUNET_STRINGS_from_utf8 (const char *input, size_t len, const char *charset); + + +/** + * Complete filename (a la shell) from abbrevition. + * + * @param fil the name of the file, may contain ~/ or + * be relative to the current directory + * @return the full file name, + * NULL is returned on error + */ +char * +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"). + * + * 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 + * amount of space will be calculated + * @param size number of bytes available in buffer + * @param count number of strings that follow + * @param ... count 0-terminated strings to copy to buffer + * @return number of bytes written to the buffer + * (or number of bytes that would have been written) + */ +size_t +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. + * + * @param buffer the buffer to parse + * @param size size of the buffer + * @param count number of strings to locate + * @param ... pointers to where to store the strings + * @return offset of the character after the last 0-termination + * in the buffer, or 0 on error. + */ +unsigned int +GNUNET_STRINGS_buffer_tokenize (const char *buffer, size_t size, + unsigned int count, ...); + + + +/** + * "man ctime_r", except for GNUnet time; also, unlike ctime, the + * return value does not include the newline character. + * + * @param t the absolute time to convert + * @return timestamp in human-readable form + */ +char * +GNUNET_STRINGS_absolute_time_to_string (struct GNUNET_TIME_Absolute t); + + +/** + * Give relative time in human-readable fancy format. + * + * @param delta time in milli seconds + * @return string in human-readable form + */ +char * +GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta); + +/** + * "man basename" + * Returns a pointer to a part of filename (allocates nothing)! + * + * @param filename filename to extract basename from + * @return short (base) name of the file (that is, everything following the + * last directory separator in filename. If filename ends with a + * directory separator, the result will be a zero-length string. + * If filename has no directory separators, the result is filename + * itself. + */ +const char * +GNUNET_STRINGS_get_short_name (const char *filename); + +#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_testing_lib.h b/src/include/gnunet_testing_lib.h new file mode 100644 index 0000000..03b8376 --- /dev/null +++ b/src/include/gnunet_testing_lib.h @@ -0,0 +1,1231 @@ +/* + This file is part of GNUnet + (C) 2008, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + */ + +/** + * @file 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! + * @author Christian Grothoff + */ + +#ifndef GNUNET_TESTING_LIB_H +#define GNUNET_TESTING_LIB_H + +#include "gnunet_util_lib.h" +#include "gnunet_statistics_service.h" + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#define 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. + */ +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 that we started last. + */ + struct GNUNET_OS_Process *proc; + + /** + * 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]; + +}; + + +/** + * Handle to a group of GNUnet peers. + */ +struct GNUNET_TESTING_PeerGroup; + + +/** + * Prototype of a function that will be called whenever + * two daemons are connected by the testing library. + * + * @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) + */ +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); + + +/** + * Prototype of a callback function indicating that two peers + * are currently connected. + * + * @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) + */ +typedef void (*GNUNET_TESTING_NotifyTopology) (void *cls, + const struct GNUNET_PeerIdentity + * first, + const struct GNUNET_PeerIdentity + * second, const char *emsg); + + +/** + * 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.). + * + * @param daemon the daemon to finish starting + */ +void +GNUNET_TESTING_daemon_continue_startup (struct GNUNET_TESTING_Daemon *daemon); + + +/** + * Check whether the given daemon is running. + * + * @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. + * + * @param d the daemon that should be restarted + * @param cb function called once the daemon is (re)started + * @param cb_cls closure for cb + */ +void +GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, + GNUNET_TESTING_NotifyDaemonRunning cb, + void *cb_cls); + + +/** + * Start a peer that has previously been stopped using the daemon_stop + * call (and files weren't deleted and the allow restart flag) + * + * @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 + */ +void +GNUNET_TESTING_daemon_start_stopped (struct GNUNET_TESTING_Daemon *daemon, + struct GNUNET_TIME_Relative timeout, + GNUNET_TESTING_NotifyDaemonRunning cb, + void *cb_cls); + + +/** + * Starts a GNUnet daemon's service. + * + * @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_service (struct GNUNET_TESTING_Daemon *d, + const char *service, + struct GNUNET_TIME_Relative timeout, + GNUNET_TESTING_NotifyDaemonRunning cb, + void *cb_cls); + + +/** + * Starts a GNUnet daemon's service which has been previously turned off. + * + * @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. + * + * @param pg handle to the set of running peers + * @param position the number of the peer to return + */ +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); + + + +/** + * Restart all peers in the given group. + * + * @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 + */ +void +GNUNET_TESTING_daemons_restart (struct GNUNET_TESTING_PeerGroup *pg, + GNUNET_TESTING_NotifyCompletion callback, + void *callback_cls); + + +/** + * Shutdown all peers started in the given group. + * + * @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 + */ +void +GNUNET_TESTING_daemons_stop (struct GNUNET_TESTING_PeerGroup *pg, + struct GNUNET_TIME_Relative timeout, + GNUNET_TESTING_NotifyCompletion cb, void *cb_cls); + + +/** + * Count the number of running peers. + * + * @param pg handle for the peer group + * + * @return the number of currently running peers in the peer group + */ +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); + + +/** + * Callback function to process statistic values. + * + * @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 + */ +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); + + +/** + * Iterate over all (running) peers in the peer group, retrieve + * all statistics from each. + * + * @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 + */ +void +GNUNET_TESTING_get_statistics (struct GNUNET_TESTING_PeerGroup *pg, + GNUNET_STATISTICS_Callback cont, + GNUNET_TESTING_STATISTICS_Iterator proc, + void *cls); + + +/** + * 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. + * + * @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 + */ +int +GNUNET_TESTING_topology_get (enum GNUNET_TESTING_Topology *topology, + const char *topology_string); + + +/** + * Get connect topology option from string input. + * + * @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 + */ +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); + + +/** + * 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 + */ +void +GNUNET_TESTING_resume_connections (struct GNUNET_TESTING_PeerGroup *pg); + + +/** + * 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. + * + * @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 + */ +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); + + +/** + * Start or stop an individual peer from the given group. + * + * @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. + * + * @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 + */ +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); + + +/** + * Print current topology to a graphviz readable file. + * + * @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 + * + */ +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); + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h new file mode 100644 index 0000000..7090c33 --- /dev/null +++ b/src/include/gnunet_time_lib.h @@ -0,0 +1,429 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_time_lib.h + * @brief functions related to time + * + * @author Christian Grothoff + */ + +#ifndef GNUNET_TIME_LIB_H +#define GNUNET_TIME_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" + +/** + * Time for absolute times used by GNUnet, in milliseconds. + */ +struct GNUNET_TIME_Absolute +{ + /** + * The actual value. + */ + uint64_t abs_value; +}; + +/** + * Time for relative time used by GNUnet, in milliseconds. + * Always positive, so we can only refer to future time. + */ +struct GNUNET_TIME_Relative +{ + /** + * The actual value. + */ + uint64_t rel_value; +}; + +GNUNET_NETWORK_STRUCT_BEGIN + +/** + * Time for relative time used by GNUnet, in milliseconds and in network byte order. + */ +struct GNUNET_TIME_RelativeNBO +{ + /** + * The actual value (in network byte order). + */ + uint64_t rel_value__ GNUNET_PACKED; +}; + + +/** + * Time for absolute time used by GNUnet, in milliseconds and in network byte order. + */ +struct GNUNET_TIME_AbsoluteNBO +{ + /** + * The actual value (in network byte order). + */ + uint64_t abs_value__ GNUNET_PACKED; +}; +GNUNET_NETWORK_STRUCT_END + +/** + * Relative time zero. + */ +#define GNUNET_TIME_UNIT_ZERO GNUNET_TIME_relative_get_zero() + +/** + * Absolute time zero. + */ +#define GNUNET_TIME_UNIT_ZERO_ABS GNUNET_TIME_absolute_get_zero() + +/** + * One millisecond, our basic time unit. + */ +#define GNUNET_TIME_UNIT_MILLISECONDS GNUNET_TIME_relative_get_unit() + +/** + * One second. + */ +#define GNUNET_TIME_UNIT_SECONDS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 1000) + +/** + * One minute. + */ +#define GNUNET_TIME_UNIT_MINUTES GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) + +/** + * One hour. + */ +#define GNUNET_TIME_UNIT_HOURS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60) + +/** + * One day. + */ +#define GNUNET_TIME_UNIT_DAYS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 24) + +/** + * One week. + */ +#define GNUNET_TIME_UNIT_WEEKS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 7) + +/** + * One month (30 days). + */ +#define GNUNET_TIME_UNIT_MONTHS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 30) + +/** + * One year (365 days). + */ +#define GNUNET_TIME_UNIT_YEARS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 365) + +/** + * Constant used to specify "forever". This constant + * will be treated specially in all time operations. + */ +#define GNUNET_TIME_UNIT_FOREVER_REL GNUNET_TIME_relative_get_forever () + +/** + * Constant used to specify "forever". This constant + * will be treated specially in all time operations. + */ +#define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever () + +/** + * Return relative time of 0ms. + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_get_zero (void); + +/** + * Return absolute time of 0ms. + */ +struct GNUNET_TIME_Absolute +GNUNET_TIME_absolute_get_zero (void); + +/** + * Return relative time of 1ms. + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_get_unit (void); + +/** + * Return "forever". + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_get_forever (void); + +/** + * Return "forever". + */ +struct GNUNET_TIME_Absolute +GNUNET_TIME_absolute_get_forever (void); + +/** + * Get the current time. + * + * @return the current time + */ +struct GNUNET_TIME_Absolute +GNUNET_TIME_absolute_get (void); + +/** + * Convert relative time to an absolute time in the + * future. + * + * @param rel relative time to convert + * @return timestamp that is "rel" in the future, or FOREVER if rel==FOREVER (or if we would overflow) + */ +struct GNUNET_TIME_Absolute +GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel); + +/** + * Return the minimum of two relative time values. + * + * @param t1 first timestamp + * @param t2 other timestamp + * @return timestamp that is smaller + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1, + struct GNUNET_TIME_Relative t2); + + +/** + * Return the maximum of two relative time values. + * + * @param t1 first timestamp + * @param t2 other timestamp + * @return timestamp that is larger + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1, + struct GNUNET_TIME_Relative t2); + +/** + * Return the minimum of two absolute time values. + * + * @param t1 first timestamp + * @param t2 other timestamp + * @return timestamp that is smaller + */ +struct GNUNET_TIME_Absolute +GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1, + struct GNUNET_TIME_Absolute t2); + +/** + * Return the maximum of two absolute time values. + * + * @param t1 first timestamp + * @param t2 other timestamp + * @return timestamp that is smaller + */ +struct GNUNET_TIME_Absolute +GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1, + struct GNUNET_TIME_Absolute t2); + +/** + * Given a timestamp in the future, how much time + * remains until then? + * + * @param future some absolute time, typically in the future + * @return future - now, or 0 if now >= future, or FOREVER if future==FOREVER. + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future); + + +/** + * Calculate the estimate time of arrival/completion + * for an operation. + * + * @param start when did the operation start? + * @param finished how much has been done? + * @param total how much must be done overall (same unit as for "finished") + * @return remaining duration for the operation, + * assuming it continues at the same speed + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, uint64_t finished, + uint64_t total); + + +/** + * Compute the time difference between the given start and end times. + * Use this function instead of actual subtraction to ensure that + * "FOREVER" and overflows are handeled correctly. + * + * @param start some absolute time + * @param end some absolute time (typically larger or equal to start) + * @return 0 if start >= end; FOREVER if end==FOREVER; otherwise end - start + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start, + struct GNUNET_TIME_Absolute end); + +/** + * Get the duration of an operation as the + * difference of the current time and the given start time "hence". + * + * @param whence some absolute time, typically in the past + * @return aborts if hence==FOREVER, 0 if hence > now, otherwise now-hence. + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_absolute_get_duration (struct GNUNET_TIME_Absolute whence); + + +/** + * Add a given relative duration to the + * given start time. + * + * @param start some absolute time + * @param duration some relative time to add + * @return FOREVER if either argument is FOREVER or on overflow; start+duration otherwise + */ +struct GNUNET_TIME_Absolute +GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, + struct GNUNET_TIME_Relative duration); + + +/** + * Subtract a given relative duration from the + * given start time. + * + * @param start some absolute time + * @param duration some relative time to subtract + * @return ZERO if start <= duration, or FOREVER if start time is FOREVER; start-duration otherwise + */ +struct GNUNET_TIME_Absolute +GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start, + struct GNUNET_TIME_Relative duration); + +/** + * Multiply relative time by a given factor. + * + * @param rel some duration + * @param factor integer to multiply with + * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, + unsigned int factor); + +/** + * Divide relative time by a given factor. + * + * @param rel some duration + * @param factor integer to divide by + * @return FOREVER if rel=FOREVER or factor==0; otherwise rel/factor + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, + unsigned int factor); + +/** + * Add relative times together. + * + * @param a1 some relative time + * @param a2 some other relative time + * @return FOREVER if either argument is FOREVER or on overflow; a1+a2 otherwise + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, + struct GNUNET_TIME_Relative a2); + +/** + * Subtract relative timestamp from the other. + * + * @param a1 first timestamp + * @param a2 second timestamp + * @return ZERO if a2>=a1 (including both FOREVER), FOREVER if a1 is FOREVER, a1-a2 otherwise + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1, + struct GNUNET_TIME_Relative a2); + + +/** + * Convert relative time to network byte order. + * + * @param a time to convert + * @return converted time value + */ +struct GNUNET_TIME_RelativeNBO +GNUNET_TIME_relative_hton (struct GNUNET_TIME_Relative a); + +/** + * Convert relative time from network byte order. + * + * @param a time to convert + * @return converted time value + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_ntoh (struct GNUNET_TIME_RelativeNBO a); + +/** + * Convert relative time to network byte order. + * + * @param a time to convert + * @return converted time value + */ +struct GNUNET_TIME_AbsoluteNBO +GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a); + +/** + * Convert relative time from network byte order. + * + * @param a time to convert + * @return converted time value + */ +struct GNUNET_TIME_Absolute +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 + */ +void +GNUNET_TIME_set_offset (long long offset); + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_TIME_LIB_H */ +#endif +/* end of gnunet_time_lib.h */ diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h new file mode 100644 index 0000000..9b39a41 --- /dev/null +++ b/src/include/gnunet_transport_plugin.h @@ -0,0 +1,487 @@ +/* + This file is part of GNUnet + (C) 2009, 2010 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file include/gnunet_transport_plugin.h + * @brief API for the transport services. This header + * specifies the struct that is given to the plugin's entry + * method and the other struct that must be returned. + * Note that the destructors of transport plugins will + * be given the value returned by the constructor + * and is expected to return a NULL pointer. + * @author Christian Grothoff + */ +#ifndef PLUGIN_TRANSPORT_H +#define PLUGIN_TRANSPORT_H + +#include "gnunet_configuration_lib.h" +#include "gnunet_scheduler_lib.h" +#include "gnunet_statistics_service.h" +#include "gnunet_transport_service.h" + +/** + * Opaque pointer that plugins can use to distinguish specific + * connections to a given peer. Typically used by stateful plugins to + * allow the service to refer to specific streams instead of a more + * general notion of "some connection" to the given peer. This is + * 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. + */ +struct Session; + +/** + * Every 'struct Session' must begin with this header. + */ +struct SessionHeader +{ + + /** + * Cached signature for PONG generation for the session. Do not use + * in the plugin! + */ + struct GNUNET_CRYPTO_RsaSignature pong_signature; + + /** + * Expiration time for signature. Do not use in the plugin! + */ + struct GNUNET_TIME_Absolute pong_sig_expires; + +}; + +/** + * Function that will be called whenever the plugin internally + * cleans up a session pointer and hence the service needs to + * discard all of those sessions as well. Plugins that do not + * use sessions can simply omit calling this function and always + * use NULL wherever a session pointer is needed. This function + * should be called BEFORE a potential "TransmitContinuation" + * from the "TransmitFunction". + * + * @param cls closure + * @param peer which peer was the session for + * @param session which session is being destoyed + */ +typedef void (*GNUNET_TRANSPORT_SessionEnd) (void *cls, + const struct GNUNET_PeerIdentity * + peer, struct Session * session); + + +/** + * Function called by the transport for each received message. + * This function should also be called with "NULL" for the + * message to signal that the other peer disconnected. + * + * @param cls closure + * @param peer (claimed) identity of the other peer + * @param message the message, NULL if we only care about + * learning about the delay until we should receive again + * @param session identifier used for this session (NULL for plugins + * that do not offer bi-directional communication to the sender + * using the same "connection") + * @param sender_address binary address of the sender (if we established the + * connection or are otherwise sure of it; should be NULL + * for inbound TCP/UDP connections since it it not clear + * that we could establish ourselves a connection to that + * IP address and get the same system) + * @param sender_address_len number of bytes in sender_address + * @return how long the plugin should wait until receiving more data + * (plugins that do not support this, can ignore the return value) + */ +typedef struct + GNUNET_TIME_Relative (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls, + const struct + GNUNET_PeerIdentity + * peer, + const struct + GNUNET_MessageHeader + * message, + const struct + GNUNET_ATS_Information + * ats, + uint32_t + ats_count, + struct + Session * + session, + const char + *sender_address, + uint16_t + sender_address_len); + + +/** + * Function that will be called to figure if an address is an loopback, + * LAN, WAN etc. address + * + * @param cls closure + * @param addr binary address + * @param addrlen length of the address + * @return ATS Information containing the network type + */ +typedef const struct GNUNET_ATS_Information +(*GNUNET_TRANSPORT_AddressToType) (void *cls, + const struct sockaddr *addr, + size_t addrlen); + +/** + * Function that will be called for each address the transport + * is aware that it might be reachable under. + * + * @param cls closure + * @param add_remove should the address added (YES) or removed (NO) from the + * set of valid addresses? + * @param addr one of the addresses of the host + * the specific address format depends on the transport + * @param addrlen length of the address + */ +typedef void (*GNUNET_TRANSPORT_AddressNotification) (void *cls, int add_remove, + const void *addr, + size_t addrlen); + + +/** + * Function that will be called whenever the plugin receives data over + * the network and wants to determine how long it should wait until + * the next time it reads from the given peer. Note that some plugins + * (such as UDP) may not be able to wait (for a particular peer), so + * the waiting part is optional. Plugins that can wait should call + * this function, sleep the given amount of time, and call it again + * (with zero bytes read) UNTIL it returns zero and only then read. + * + * @param cls closure + * @param peer which peer did we read data from + * @param amount_recved number of bytes read (can be zero) + * @return how long to wait until reading more from this peer + * (to enforce inbound quotas) + */ +typedef struct GNUNET_TIME_Relative (*GNUNET_TRANSPORT_TrafficReport) (void + *cls, + const + struct + GNUNET_PeerIdentity + * peer, + size_t + amount_recved); + + +/** + * Function that returns a HELLO message. + */ +typedef const struct GNUNET_MessageHeader + *(*GNUNET_TRANSPORT_GetHelloCallback) (void); + + +/** + * The transport service will pass a pointer to a struct + * of this type as the first and only argument to the + * entry point of each transport plugin. + */ +struct GNUNET_TRANSPORT_PluginEnvironment +{ + /** + * Configuration to use. + */ + const struct GNUNET_CONFIGURATION_Handle *cfg; + + /** + * Identity of this peer. + */ + const struct GNUNET_PeerIdentity *my_identity; + + /** + * Closure for the various callbacks. + */ + void *cls; + + /** + * Handle for reporting statistics. + */ + struct GNUNET_STATISTICS_Handle *stats; + + /** + * Function that should be called by the transport plugin + * whenever a message is received. + */ + GNUNET_TRANSPORT_PluginReceiveCallback receive; + + + /** + * Function that returns our HELLO. + */ + GNUNET_TRANSPORT_GetHelloCallback get_our_hello; + + /** + * Function that must be called by each plugin to notify the + * transport service about the addresses under which the transport + * provided by the plugin can be reached. + */ + GNUNET_TRANSPORT_AddressNotification notify_address; + + /** + * Function that must be called by the plugin when a non-NULL + * session handle stops being valid (is destroyed). + */ + GNUNET_TRANSPORT_SessionEnd session_end; + + /** + * Function that will be called to figure if an address is an loopback, + * LAN, WAN etc. address + */ + GNUNET_TRANSPORT_AddressToType get_address_type; + + + /** + * What is the maximum number of connections that this transport + * should allow? Transports that do not have sessions (such as + * UDP) can ignore this value. + */ + uint32_t max_connections; + +}; + + +/** + * Function called by the GNUNET_TRANSPORT_TransmitFunction + * upon "completion". In the case that a peer disconnects, + * this function must be called for each pending request + * (with a 'failure' indication) AFTER notifying the service + * about the disconnect event (so that the service won't try + * to transmit more messages, believing the connection still + * exists...). + * + * @param cls closure + * @param target who was the recipient of the message? + * @param result GNUNET_OK on success + * GNUNET_SYSERR if the target disconnected; + * disconnect will ALSO be signalled using + * the ReceiveCallback. + */ +typedef void (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls, + const struct + GNUNET_PeerIdentity * + target, int result); + +/** + * The new send function with just the session and no address + * + * Function that can be used by the transport service to transmit + * a message using the plugin. Note that in the case of a + * peer disconnecting, the continuation MUST be called + * prior to the disconnect notification itself. This function + * will be called with this peer's HELLO message to initiate + * a fresh connection to another peer. + * + * @param cls closure + * @param session which session must be used + * @param msgbuf the message to transmit + * @param msgbuf_size number of bytes in 'msgbuf' + * @param priority how important is the message (most plugins will + * ignore message priority and just FIFO) + * @param timeout how long to wait at most for the transmission (does not + * require plugins to discard the message after the timeout, + * just advisory for the desired delay; most plugins will ignore + * this as well) + * @param cont continuation to call once the message has + * been transmitted (or if the transport is ready + * for the next transmission call; or if the + * peer disconnected...); can be NULL + * @param cont_cls closure for cont + * @return number of bytes used (on the physical network, with overheads); + * -1 on hard errors (i.e. address invalid); 0 is a legal value + * and does NOT mean that the message was not transmitted (DV) + */ +typedef ssize_t (*GNUNET_TRANSPORT_TransmitFunction) (void *cls, + struct Session *session, + const char *msgbuf, size_t msgbuf_size, + unsigned int priority, + struct GNUNET_TIME_Relative to, + GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls); + + +/** + * Function that can be called to force a disconnect from the + * specified neighbour. This should also cancel all previously + * scheduled transmissions. Obviously the transmission may have been + * partially completed already, which is OK. The plugin is supposed + * to close the connection (if applicable) and no longer call the + * transmit continuation(s). + * + * Finally, plugin MUST NOT call the services's receive function to + * notify the service that the connection to the specified target was + * closed after a getting this call. + * + * @param cls closure + * @param target peer for which the last transmission is + * to be cancelled + */ +typedef void (*GNUNET_TRANSPORT_DisconnectFunction) (void *cls, + const struct + GNUNET_PeerIdentity * + target); + + +/** + * Function called by the pretty printer for the resolved address for + * each human-readable address obtained. + * + * @param cls closure + * @param hostname one of the names for the host, NULL + * on the last call to the callback + */ +typedef void (*GNUNET_TRANSPORT_AddressStringCallback) (void *cls, + const char *address); + + +/** + * Convert the transports address to a nice, human-readable + * format. + * + * @param cls closure + * @param name name of the transport that generated the address + * @param addr one of the addresses of the host, NULL for the last address + * the specific address format depends on the transport + * @param addrlen length of the address + * @param numeric should (IP) addresses be displayed in numeric form? + * @param timeout after how long should we give up? + * @param asc function to call on each string + * @param asc_cls closure for asc + */ +typedef void (*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls, + const char *type, + const void *addr, + size_t addrlen, + int numeric, + struct + GNUNET_TIME_Relative + timeout, + GNUNET_TRANSPORT_AddressStringCallback + asc, void *asc_cls); + + +/** + * Another peer has suggested an address for this peer and transport + * plugin. Check that this could be a valid address. This function + * is not expected to 'validate' the address in the sense of trying to + * connect to it but simply to see if the binary format is technically + * legal for establishing a connection to this peer (and make sure that + * the address really corresponds to our network connection/settings + * and not some potential man-in-the-middle). + * + * @param addr pointer to the address + * @param addrlen length of addr + * @return GNUNET_OK if this is a plausible address for this peer + * and transport, GNUNET_SYSERR if not + */ +typedef int (*GNUNET_TRANSPORT_CheckAddress) (void *cls, const void *addr, + size_t addrlen); + +/** + * Create a new session to transmit data to the target + * This session will used to send data to this peer and the plugin will + * notify us by calling the env->session_end function + * + * @param cls the plugin + * @param target the neighbour id + * @param addr pointer to the address + * @param addrlen length of addr + * @return the session if the address is valid, NULL otherwise + */ +typedef struct Session * (*GNUNET_TRANSPORT_CreateSession) (void *cls, + const struct GNUNET_HELLO_Address *address); + + +/** + * Function called for a quick conversion of the binary address to + * a numeric address. Note that the caller must not free the + * address and that the next call to this function is allowed + * to override the address again. + * + * @param cls closure + * @param addr binary address + * @param addr_len length of the address + * @return string representing the same address + */ +typedef const char *(*GNUNET_TRANSPORT_AddressToString) (void *cls, + const void *addr, + size_t addrlen); + + +/** + * Each plugin is required to return a pointer to a struct of this + * type as the return value from its entry point. + */ +struct GNUNET_TRANSPORT_PluginFunctions +{ + + /** + * Closure for all of the callbacks. + */ + void *cls; + + /** + * Function that the transport service will use to transmit data to + * another peer. May be NULL for plugins that only support + * receiving data. After this call, the plugin call the specified + * continuation with success or error before notifying us about the + * target having disconnected. + */ + GNUNET_TRANSPORT_TransmitFunction send; + + /** + * Function that can be used to force the plugin to disconnect from + * the given peer and cancel all previous transmissions (and their + * continuations). + */ + GNUNET_TRANSPORT_DisconnectFunction disconnect; + + /** + * Function to pretty-print addresses. NOTE: this function is not + * yet used by transport-service, but will be used in the future + * once the transport-API has been completed. + */ + GNUNET_TRANSPORT_AddressPrettyPrinter address_pretty_printer; + + /** + * Function that will be called to check if a binary address + * for this plugin is well-formed and corresponds to an + * address for THIS peer (as per our configuration). Naturally, + * if absolutely necessary, plugins can be a bit conservative in + * their answer, but in general plugins should make sure that the + * address does not redirect traffic to a 3rd party that might + * try to man-in-the-middle our traffic. + */ + GNUNET_TRANSPORT_CheckAddress check_address; + + /** + * Function that will be called to convert a binary address + * to a string (numeric conversion only). + */ + GNUNET_TRANSPORT_AddressToString address_to_string; + + /** + * Function that will be called tell the plugin to create a session + * object + */ + GNUNET_TRANSPORT_CreateSession get_session; +}; + + +#endif diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h new file mode 100644 index 0000000..5c939a0 --- /dev/null +++ b/src/include/gnunet_transport_service.h @@ -0,0 +1,413 @@ +/* + This file is part of GNUnet. + (C) 2009, 2010, 2011 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_transport_service.h + * @brief low-level P2P IO + * @author Christian Grothoff + */ + +#ifndef GNUNET_TRANSPORT_SERVICE_H +#define GNUNET_TRANSPORT_SERVICE_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_util_lib.h" +#include "gnunet_ats_service.h" + +/** + * Version number of the transport API. + */ +#define GNUNET_TRANSPORT_VERSION 0x00000000 + + +/** + * Function called by the transport for each received message. + * + * @param cls closure + * @param peer (claimed) identity of the other peer + * @param message the message + * @param ats performance data + * @param ats_count number of entries in ats + */ +typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls, + const struct + GNUNET_PeerIdentity * peer, + const struct + GNUNET_MessageHeader * + message, + const struct + GNUNET_ATS_Information * ats, + uint32_t ats_count); + + +/** + * Opaque handle to the service. + */ +struct GNUNET_TRANSPORT_Handle; + + +/** + * Function called to notify transport users that another + * peer connected to us. + * + * @param cls closure + * @param peer the peer that connected + * @param ats performance data + * @param ats_count number of entries in ats (excluding 0-termination) + */ +typedef void (*GNUNET_TRANSPORT_NotifyConnect) (void *cls, + const struct GNUNET_PeerIdentity + * peer, + const struct + GNUNET_ATS_Information * ats, + uint32_t ats_count); + +/** + * Function called to notify transport users that another + * peer disconnected from us. + * + * @param cls closure + * @param peer the peer that disconnected + */ +typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls, + const struct + GNUNET_PeerIdentity * peer); + + +/** + * 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 + * of the iteration. + * + * @param cls closure + * @param address NULL on error or end of iteration, + * otherwise 0-terminated printable UTF-8 string + */ +typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls, + const char *address); + + +/** + * Function to call with a binary format of an address + * + * @param cls closure + * @param peer peer this update is about (never NULL) + * @param address address, NULL for disconnect notification in monitor mode + */ +typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls, + const struct + GNUNET_PeerIdentity * + peer, + const struct + GNUNET_HELLO_Address * + address); + + +/** + * Connect to the transport service. Note that the connection may + * complete (or fail) asynchronously. + * + * @param cfg configuration to use + * @param self our own identity (API should check that it matches + * the identity found by transport), or NULL (no check) + * @param cls closure for the callbacks + * @param rec receive function to call + * @param nc function to call on connect events + * @param nd function to call on disconnect events + * @return NULL on error + */ +struct GNUNET_TRANSPORT_Handle * +GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_PeerIdentity *self, void *cls, + GNUNET_TRANSPORT_ReceiveCallback rec, + GNUNET_TRANSPORT_NotifyConnect nc, + GNUNET_TRANSPORT_NotifyDisconnect nd); + + +/** + * Disconnect from the transport service. + * + * @param handle handle returned from connect + */ +void +GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle); + + +/** + * 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 + */ +void +GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle, + const struct GNUNET_PeerIdentity *target); + + +/** + * Opaque handle for a transmission-ready request. + */ +struct GNUNET_TRANSPORT_TransmitHandle; + + +/** + * Check if we could queue a message of the given size for + * transmission. The transport service will take both its internal + * buffers and bandwidth limits imposed by the other peer into + * consideration when answering this query. + * + * @param handle connection to transport service + * @param target who should receive the message + * @param size how big is the message we want to transmit? + * @param priority how important is the message? @deprecated - remove? + * @param timeout after how long should we give up (and call + * notify with buf NULL and size 0)? + * @param notify function to call when we are ready to + * send such a message + * @param notify_cls closure for notify + * @return NULL if someone else is already waiting to be notified + * non-NULL if the notify callback was queued (can be used to cancel + * using GNUNET_TRANSPORT_notify_transmit_ready_cancel) + */ +struct GNUNET_TRANSPORT_TransmitHandle * +GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle, + const struct GNUNET_PeerIdentity + *target, size_t size, uint32_t priority, + struct GNUNET_TIME_Relative timeout, + GNUNET_CONNECTION_TransmitReadyNotify + notify, void *notify_cls); + + +/** + * Cancel the specified transmission-ready notification. + * + * @param th handle of the transmission notification request to cancel + */ +void +GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct + GNUNET_TRANSPORT_TransmitHandle + *th); + + + +/** + * Function called whenever there is an update to the + * HELLO of this peer. + * + * @param cls closure + * @param hello our updated HELLO + */ +typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback) (void *cls, + const struct + GNUNET_MessageHeader * + hello); + + +/** + * Handle to cancel a 'GNUNET_TRANSPORT_get_hello' operation. + */ +struct GNUNET_TRANSPORT_GetHelloHandle; + + +/** + * Obtain updates on changes to the HELLO message for this peer. + * + * @param handle connection to transport service + * @param rec function to call with the HELLO + * @param rec_cls closure for rec + * @return handle to cancel the operation + */ +struct GNUNET_TRANSPORT_GetHelloHandle * +GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle, + GNUNET_TRANSPORT_HelloUpdateCallback rec, + void *rec_cls); + + +/** + * Stop receiving updates about changes to our HELLO message. + * + * @param ghh handle returned from 'GNUNET_TRANSPORT_get_hello') + */ +void +GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh); + + +/** + * Offer the transport service the HELLO of another peer. Note that + * the transport service may just ignore this message if the HELLO is + * malformed or useless due to our local configuration. + * + * @param handle connection to transport service + * @param hello the hello message + * @param cont continuation to call when HELLO has been sent + * @param cls closure for continuation + */ +void +GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, + const struct GNUNET_MessageHeader *hello, + GNUNET_SCHEDULER_Task cont, void *cls); + + +/** + * Handle to cancel a pending address lookup. + */ +struct GNUNET_TRANSPORT_AddressToStringContext; + + +/** + * Convert a binary address into a human readable address. + * + * @param cfg configuration to use + * @param address address to convert (binary format) + * @param numeric should (IP) addresses be displayed in numeric form + * (otherwise do reverse DNS lookup) + * @param timeout how long is the lookup allowed to take at most + * @param aluc function to call with the results + * @param aluc_cls closure for aluc + * @return handle to cancel the operation, NULL on error + */ +struct GNUNET_TRANSPORT_AddressToStringContext * +GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle + *cfg, + const struct GNUNET_HELLO_Address *address, + int numeric, + struct GNUNET_TIME_Relative timeout, + GNUNET_TRANSPORT_AddressToStringCallback + aluc, void *aluc_cls); + + +/** + * Cancel request for address conversion. + * + * @param alc handle for the request to cancel + */ +void +GNUNET_TRANSPORT_address_to_string_cancel (struct + GNUNET_TRANSPORT_AddressToStringContext + *alc); + + +/** + * Return all the known addresses for a specific peer or all peers. + * Returns continously 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 + * time with 'NULL' for the address and the peer. After this, the operation must no + * longer be explicitly cancelled. + * + * @param cfg configuration to use + * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers + * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL), + * GNUNET_NO to monitor the set of addresses used (continuously, must be explicitly canceled, NOT implemented yet!) + * @param timeout how long is the lookup allowed to take at most + * @param peer_address_callback function to call with the results + * @param peer_address_callback_cls closure for peer_address_callback + */ +struct GNUNET_TRANSPORT_PeerIterateContext * +GNUNET_TRANSPORT_peer_get_active_addresses (const struct + GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_PeerIdentity + *peer, int one_shot, + struct GNUNET_TIME_Relative timeout, + GNUNET_TRANSPORT_PeerIterateCallback + peer_address_callback, + void *peer_address_callback_cls); + + +/** + * Cancel request for peer lookup. + * + * @param alc handle for the request to cancel + */ +void +GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct + GNUNET_TRANSPORT_PeerIterateContext + *alc); + + +/** + * Handle for blacklisting peers. + */ +struct GNUNET_TRANSPORT_Blacklist; + + +/** + * Function that decides if a connection is acceptable or not. + * + * @param cls closure + * @param pid peer to approve or disapproave + * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not + */ +typedef int (*GNUNET_TRANSPORT_BlacklistCallback) (void *cls, + const struct + GNUNET_PeerIdentity * pid); + + +/** + * Install a blacklist callback. The service will be queried for all + * existing connections as well as any fresh connections to check if + * they are permitted. If the blacklisting callback is unregistered, + * all hosts that were denied in the past will automatically be + * whitelisted again. Cancelling the blacklist handle is also the + * only way to re-enable connections from peers that were previously + * blacklisted. + * + * @param cfg configuration to use + * @param cb callback to invoke to check if connections are allowed + * @param cb_cls closure for cb + * @return NULL on error, otherwise handle for cancellation + */ +struct GNUNET_TRANSPORT_Blacklist * +GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_TRANSPORT_BlacklistCallback cb, + void *cb_cls); + + +/** + * Abort the blacklist. Note that this function is the only way for + * removing a peer from the blacklist. + * + * @param br handle of the request that is to be cancelled + */ +void +GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br); + + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +/* ifndef GNUNET_TRANSPORT_SERVICE_H */ +#endif +/* end of gnunet_transport_service.h */ diff --git a/src/include/gnunet_tun_lib.h b/src/include/gnunet_tun_lib.h new file mode 100644 index 0000000..dac11d6 --- /dev/null +++ b/src/include/gnunet_tun_lib.h @@ -0,0 +1,420 @@ +/* + This file is part of GNUnet. + (C) 2010, 2011, 2012 Christian Grothoff + + 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_tun_lib.h + * @brief standard TCP/IP network structs and IP checksum calculations for TUN interaction + * @author Philipp Toelke + * @author Christian Grothoff + */ +#ifndef GNUNET_TUN_LIB_H +#define GNUNET_TUN_LIB_H + +#include "gnunet_util_lib.h" + + +/* see http://www.iana.org/assignments/ethernet-numbers */ +#ifndef ETH_P_IPV4 +/** + * Number for IPv4 + */ +#define ETH_P_IPV4 0x0800 +#endif + +#ifndef ETH_P_IPV6 +/** + * Number for IPv6 + */ +#define ETH_P_IPV6 0x86DD +#endif + + +GNUNET_NETWORK_STRUCT_BEGIN + +/** + * Header from Linux TUN interface. + */ +struct GNUNET_TUN_Layer2PacketHeader +{ + /** + * Some flags (unused). + */ + uint16_t flags GNUNET_PACKED; + + /** + * Here we get an ETH_P_-number. + */ + uint16_t proto GNUNET_PACKED; +}; + + +/** + * Standard IPv4 header. + */ +struct GNUNET_TUN_IPv4Header +{ +#if __BYTE_ORDER == __LITTLE_ENDIAN + unsigned int header_length:4 GNUNET_PACKED; + unsigned int version:4 GNUNET_PACKED; +#elif __BYTE_ORDER == __BIG_ENDIAN + unsigned int version:4 GNUNET_PACKED; + unsigned int header_length:4 GNUNET_PACKED; +#else + #error byteorder undefined +#endif + uint8_t diff_serv; + + /** + * Length of the packet, including this header. + */ + uint16_t total_length GNUNET_PACKED; + + /** + * Unique random ID for matching up fragments. + */ + uint16_t identification GNUNET_PACKED; + + unsigned int flags:3 GNUNET_PACKED; + + unsigned int fragmentation_offset:13 GNUNET_PACKED; + + /** + * How many more hops can this packet be forwarded? + */ + uint8_t ttl; + + /** + * L4-protocol, for example, IPPROTO_UDP or IPPROTO_TCP. + */ + uint8_t protocol; + + /** + * Checksum. + */ + uint16_t checksum GNUNET_PACKED; + + /** + * Origin of the packet. + */ + struct in_addr source_address GNUNET_PACKED; + + /** + * Destination of the packet. + */ + struct in_addr destination_address GNUNET_PACKED; +}; + + +/** + * Standard IPv6 header. + */ +struct GNUNET_TUN_IPv6Header +{ +#if __BYTE_ORDER == __LITTLE_ENDIAN + unsigned int traffic_class_h:4 GNUNET_PACKED; + unsigned int version:4 GNUNET_PACKED; + unsigned int traffic_class_l:4 GNUNET_PACKED; + unsigned int flow_label:20 GNUNET_PACKED; +#elif __BYTE_ORDER == __BIG_ENDIAN + unsigned int version:4 GNUNET_PACKED; + unsigned int traffic_class:8 GNUNET_PACKED; + unsigned int flow_label:20 GNUNET_PACKED; +#else + #error byteorder undefined +#endif + /** + * Length of the payload, excluding this header. + */ + uint16_t payload_length GNUNET_PACKED; + + /** + * For example, IPPROTO_UDP or IPPROTO_TCP. + */ + uint8_t next_header; + + /** + * How many more hops can this packet be forwarded? + */ + uint8_t hop_limit; + + /** + * Origin of the packet. + */ + struct in6_addr source_address GNUNET_PACKED; + + /** + * Destination of the packet. + */ + struct in6_addr destination_address GNUNET_PACKED; +}; + + +/** + * TCP packet header. + */ +struct GNUNET_TUN_TcpHeader +{ + uint16_t source_port GNUNET_PACKED; + uint16_t destination_port GNUNET_PACKED; + + /** + * Sequence number. + */ + uint32_t seq GNUNET_PACKED; + + /** + * Acknowledgement number. + */ + uint32_t ack GNUNET_PACKED; +#if __BYTE_ORDER == __LITTLE_ENDIAN + /** + * Reserved. Must be zero. + */ + unsigned int reserved : 4 GNUNET_PACKED; + /** + * Number of 32-bit words in TCP header. + */ + unsigned int off : 4 GNUNET_PACKED; +#elif __BYTE_ORDER == __BIG_ENDIAN + /** + * Number of 32-bit words in TCP header. + */ + unsigned int off : 4 GNUNET_PACKED; + /** + * Reserved. Must be zero. + */ + unsigned int reserved : 4 GNUNET_PACKED; +#else + #error byteorder undefined +#endif + + /** + * Flags (SYN, FIN, ACK, etc.) + */ + uint8_t flags; + + /** + * Window size. + */ + uint16_t window_size GNUNET_PACKED; + + /** + * Checksum. + */ + uint16_t crc GNUNET_PACKED; + + /** + * Urgent pointer. + */ + uint16_t urgent_pointer GNUNET_PACKED; +}; + + +/** + * UDP packet header. + */ +struct GNUNET_TUN_UdpHeader +{ + uint16_t source_port GNUNET_PACKED; + uint16_t destination_port GNUNET_PACKED; + uint16_t len GNUNET_PACKED; + uint16_t crc GNUNET_PACKED; +}; + + +/** + * DNS header. + */ +struct GNUNET_TUN_DnsHeader +{ + uint16_t id GNUNET_PACKED; + uint16_t flags GNUNET_PACKED; + uint16_t qdcount GNUNET_PACKED; + uint16_t ancount GNUNET_PACKED; + uint16_t nscount GNUNET_PACKED; + uint16_t arcount GNUNET_PACKED; +}; + +#define GNUNET_TUN_ICMPTYPE_ECHO_REPLY 0 +#define GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE 3 +#define GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH 4 +#define GNUNET_TUN_ICMPTYPE_REDIRECT_MESSAGE 5 +#define GNUNET_TUN_ICMPTYPE_ECHO_REQUEST 8 +#define GNUNET_TUN_ICMPTYPE_ROUTER_ADVERTISEMENT 9 +#define GNUNET_TUN_ICMPTYPE_ROUTER_SOLICITATION 10 +#define GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED 11 + +#define GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE 1 +#define GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG 2 +#define GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED 3 +#define GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM 4 +#define GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST 128 +#define GNUNET_TUN_ICMPTYPE6_ECHO_REPLY 129 + + +/** + * ICMP header. + */ +struct GNUNET_TUN_IcmpHeader { + uint8_t type; + uint8_t code; + uint16_t crc GNUNET_PACKED; + + union { + /** + * ICMP Echo (request/reply) + */ + struct { + uint16_t identifier GNUNET_PACKED; + uint16_t sequence_number GNUNET_PACKED; + } echo; + + /** + * ICMP Destination Unreachable (RFC 1191) + */ + struct ih_pmtu { + uint16_t empty GNUNET_PACKED; + uint16_t next_hop_mtu GNUNET_PACKED; + /* followed by original IP header + first 8 bytes of original IP datagram */ + } destination_unreachable; + + /** + * ICMP Redirect + */ + struct in_addr redirect_gateway_address GNUNET_PACKED; + + /** + * MTU for packets that are too big (IPv6). + */ + uint32_t packet_too_big_mtu GNUNET_PACKED; + + } quench; + +}; + + +GNUNET_NETWORK_STRUCT_END + + +/** + * Initialize an IPv4 header. + * + * @param ip header to initialize + * @param protocol protocol to use (i.e. IPPROTO_UDP) + * @param payload_length number of bytes of payload that follow (excluding IPv4 header) + * @param src source IP address to use + * @param dst destination IP address to use + */ +void +GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip, + uint8_t protocol, + uint16_t payload_length, + const struct in_addr *src, + const struct in_addr *dst); + + +/** + * Initialize an IPv6 header. + * + * @param ip header to initialize + * @param protocol protocol to use (i.e. IPPROTO_UDP) + * @param payload_length number of bytes of payload that follow (excluding IPv4 header) + * @param src source IP address to use + * @param dst destination IP address to use + */ +void +GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip, + uint8_t protocol, + uint16_t payload_length, + const struct in6_addr *src, + const struct in6_addr *dst); + +/** + * Calculate IPv4 TCP checksum. + * + * @param ip ipv4 header fully initialized + * @param tcp TCP header (initialized except for CRC) + * @param payload the TCP payload + * @param payload_length number of bytes of TCP payload + */ +void +GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, + struct GNUNET_TUN_TcpHeader *tcp, + const void *payload, + uint16_t payload_length); + +/** + * Calculate IPv6 TCP checksum. + * + * @param ip ipv6 header fully initialized + * @param tcp TCP header (initialized except for CRC) + * @param payload the TCP payload + * @param payload_length number of bytes of TCP payload + */ +void +GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, + struct GNUNET_TUN_TcpHeader *tcp, + const void *payload, + uint16_t payload_length); + +/** + * Calculate IPv4 UDP checksum. + * + * @param ip ipv4 header fully initialized + * @param udp UDP header (initialized except for CRC) + * @param payload the UDP payload + * @param payload_length number of bytes of UDP payload + */ +void +GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip, + struct GNUNET_TUN_UdpHeader *udp, + const void *payload, + uint16_t payload_length); + + +/** + * Calculate IPv6 UDP checksum. + * + * @param ip ipv6 header fully initialized + * @param udp UDP header (initialized except for CRC) + * @param payload the UDP payload + * @param payload_length number of bytes of UDP payload + */ +void +GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip, + struct GNUNET_TUN_UdpHeader *udp, + const void *payload, + uint16_t payload_length); + + +/** + * Calculate ICMP checksum. + * + * @param icmp IMCP header (initialized except for CRC) + * @param payload the ICMP payload + * @param payload_length number of bytes of ICMP payload + */ +void +GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp, + const void *payload, + uint16_t payload_length); + + +#endif diff --git a/src/include/gnunet_util_lib.h b/src/include/gnunet_util_lib.h new file mode 100644 index 0000000..5f01cde --- /dev/null +++ b/src/include/gnunet_util_lib.h @@ -0,0 +1,71 @@ +/* + This file is part of GNUnet + (C) 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/gnunet_util_lib.h + * @brief convenience header including all headers of subsystems in + * gnunet_util library + * @author Christian Grothoff + */ + +#ifndef GNUNET_UTIL_LIB_H +#define GNUNET_UTIL_LIB_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_common.h" +#include "gnunet_bandwidth_lib.h" +#include "gnunet_bio_lib.h" +#include "gnunet_client_lib.h" +#include "gnunet_configuration_lib.h" +#include "gnunet_connection_lib.h" +#include "gnunet_container_lib.h" +#include "gnunet_crypto_lib.h" +#include "gnunet_disk_lib.h" +#include "gnunet_getopt_lib.h" +#include "gnunet_helper_lib.h" +#include "gnunet_network_lib.h" +#include "gnunet_os_lib.h" +#include "gnunet_peer_lib.h" +#include "gnunet_plugin_lib.h" +#include "gnunet_program_lib.h" +#include "gnunet_protocols.h" +#include "gnunet_pseudonym_lib.h" +#include "gnunet_scheduler_lib.h" +#include "gnunet_server_lib.h" +#include "gnunet_service_lib.h" +#include "gnunet_signal_lib.h" +#include "gnunet_strings_lib.h" +#include "gnunet_time_lib.h" + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/include/gnunet_vpn_service.h b/src/include/gnunet_vpn_service.h new file mode 100644 index 0000000..ecf6cf5 --- /dev/null +++ b/src/include/gnunet_vpn_service.h @@ -0,0 +1,162 @@ +/* + 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/gnunet_vpn_service.h + * @brief API to access the VPN service. + * @author Christian Grothoff + */ +#ifndef GNUNET_VPN_SERVICE_H +#define GNUNET_VPN_SERVICE_H + +#include "gnunet_util_lib.h" + + +/** + * Opaque VPN handle + */ +struct GNUNET_VPN_Handle; + +/** + * Opaque redirection request handle. + */ +struct GNUNET_VPN_RedirectionRequest; + + +/** + * Callback invoked from the VPN service once a redirection is + * available. Provides the IP address that can now be used to + * reach the requested destination. + * + * @param cls closure + * @param af address family, AF_INET or AF_INET6; AF_UNSPEC on error; + * will match 'result_af' from the request + * @param address IP address (struct in_addr or struct in_addr6, depending on 'af') + * that the VPN allocated for the redirection; + * traffic to this IP will now be redirected to the + * specified target peer; NULL on error + */ +typedef void (*GNUNET_VPN_AllocationCallback)(void *cls, + int af, + const void *address); + + +/** + * Cancel redirection request with the service. + * + * @param rr request to cancel + */ +void +GNUNET_VPN_cancel_request (struct GNUNET_VPN_RedirectionRequest *rr); + + +/** + * Tell the VPN that a forwarding to a particular peer offering a + * particular service is requested. The VPN is to reserve a + * particular IP for the redirection and return it. The VPN will + * begin the redirection as soon as possible and maintain it as long + * as it is actively used and keeping it is feasible. Given resource + * limitations, the longest inactive mappings will be destroyed. + * + * @param vh VPN handle + * @param result_af desired address family for the returned allocation + * can also be AF_UNSPEC + * @param protocol protocol, IPPROTO_UDP or IPPROTO_TCP + * @param peer target peer for the redirection + * @param serv service descriptor to give to the peer + * @param nac GNUNET_YES to notify via callback only after completion of + * the MESH-level connection, + * GNUNET_NO to notify as soon as the IP has been reserved + * @param expiration_time at what time should the redirection expire? + * (this should not impact connections that are active at that time) + * @param cb function to call with the IP + * @param cb_cls closure for cb + * @return handle to cancel the request (means the callback won't be + * invoked anymore; the mapping may or may not be established + * anyway) + */ +struct GNUNET_VPN_RedirectionRequest * +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, + int nac, + struct GNUNET_TIME_Absolute expiration_time, + GNUNET_VPN_AllocationCallback cb, + void *cb_cls); + + +/** + * Tell the VPN that forwarding to the Internet via some exit node is + * requested. Note that both UDP and TCP traffic will be forwarded, + * but possibly to different exit nodes. The VPN is to reserve a + * particular IP for the redirection and return it. The VPN will + * begin the redirection as soon as possible and maintain it as long + * as it is actively used and keeping it is feasible. Given resource + * limitations, the longest inactive mappings will be destroyed. + * + * @param vh VPN handle + * @param result_af desired address family for the returned allocation, + * can also be AF_UNSPEC + * @param addr_af address family for 'addr', AF_INET or AF_INET6 + * @param addr destination IP address on the Internet; destination + * port is to be taken from the VPN packet itself + * @param nac GNUNET_YES to notify via callback only after completion of + * the MESH-level connection, + * GNUNET_NO to notify as soon as the IP has been reserved + * @param expiration_time at what time should the redirection expire? + * (this should not impact connections that are active at that time) + * @param cb function to call with the IP + * @param cb_cls closure for cb + * @return handle to cancel the request (means the callback won't be + * invoked anymore; the mapping may or may not be established + * anyway) + */ +struct GNUNET_VPN_RedirectionRequest * +GNUNET_VPN_redirect_to_ip (struct GNUNET_VPN_Handle *vh, + int result_af, + int addr_af, + const void *addr, + int nac, + struct GNUNET_TIME_Absolute expiration_time, + GNUNET_VPN_AllocationCallback cb, + void *cb_cls); + + +/** + * Connect to the VPN service + * + * @param cfg configuration to use + * @return VPN handle + */ +struct GNUNET_VPN_Handle * +GNUNET_VPN_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); + + +/** + * Disconnect from the VPN service. + * + * @param vh VPN handle + */ +void +GNUNET_VPN_disconnect (struct GNUNET_VPN_Handle *vh); + +#endif diff --git a/src/include/platform.h b/src/include/platform.h new file mode 100644 index 0000000..7383e48 --- /dev/null +++ b/src/include/platform.h @@ -0,0 +1,258 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 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/platform.h + * @brief plaform specifics + * + * @author Nils Durner + * + * This file should never be included by installed + * header files (thos starting with "gnunet_"). + */ + +#ifndef PLATFORM_H +#define PLATFORM_H + +#ifndef HAVE_USED_CONFIG_H +#define HAVE_USED_CONFIG_H +#if HAVE_CONFIG_H +#include "gnunet_config.h" +#endif +#endif + +#ifdef WINDOWS +#define BREAKPOINT asm("int $3;"); +#define GNUNET_SIGCHLD 17 +#else +#define BREAKPOINT +#define GNUNET_SIGCHLD SIGCHLD +#endif + +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif + +#define ALLOW_EXTRA_CHECKS GNUNET_NO + +/** + * For strptime (glibc2 needs this). + */ +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE +#endif + +#ifndef _REENTRANT +#define _REENTRANT +#endif + +/* configuration options */ + +#define VERBOSE_STATS 0 + +#ifdef CYGWIN +#include <sys/reent.h> +#endif + +#ifdef _MSC_VER +#ifndef FD_SETSIZE +#define FD_SETSIZE 1024 +#endif +#include <Winsock2.h> +#include <ws2tcpip.h> +#else +#ifndef MINGW +#include <netdb.h> +#include <sys/socket.h> +#include <sys/un.h> +#if HAVE_NETINET_IN_H +#include <netinet/in.h> +#endif +#if HAVE_NETINET_IN_SYSTM_H +#include <netinet/in_systm.h> +#endif +#include <netinet/ip.h> /* superset of previous */ +#include <arpa/inet.h> +#include <netinet/tcp.h> +#include <pwd.h> +#include <sys/ioctl.h> +#include <sys/wait.h> +#include <grp.h> +#else +#include "winproc.h" +#endif +#endif + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <stdarg.h> +#include <errno.h> +#include <signal.h> +#include <libgen.h> +#ifdef WINDOWS +#include <malloc.h> /* for alloca(), on other OSes it's in stdlib.h */ +#endif +#ifndef _MSC_VER +#include <unistd.h> /* KLB_FIX */ +#endif +#include <sys/stat.h> +#include <sys/types.h> +#ifndef _MSC_VER +#include <dirent.h> /* KLB_FIX */ +#endif +#include <fcntl.h> +#include <math.h> +#if HAVE_SYS_PARAM_H +#include <sys/param.h> +#endif +#if TIME_WITH_SYS_TIME +#include <sys/time.h> +#include <time.h> +#else +#if HAVE_SYS_TIME_H +#include <sys/time.h> +#else +#include <time.h> +#endif +#endif + +#ifdef SOMEBSD +#include <net/if.h> +#endif +#ifdef GNUNET_freeBSD +#include <semaphore.h> +#endif +#ifdef DARWIN +#include <dlfcn.h> +#include <semaphore.h> +#include <net/if.h> +#endif +#ifdef LINUX +#include <net/if.h> +#endif +#ifdef SOLARIS +#include <sys/sockio.h> +#include <sys/filio.h> +#include <sys/loadavg.h> +#include <semaphore.h> +#endif +#if HAVE_UCRED_H +#include <ucred.h> +#endif +#ifdef CYGWIN +#include <windows.h> +#include <cygwin/if.h> +#endif +#if HAVE_IFADDRS_H +#include <ifaddrs.h> +#endif +#include <errno.h> +#include <limits.h> + +#if HAVE_VFORK_H +#include <vfork.h> +#endif + +#include <ctype.h> +#if HAVE_SYS_RESOURCE_H +#include <sys/resource.h> +#endif + +#if HAVE_ENDIAN_H +#include <endian.h> +#endif +#if HAVE_SYS_ENDIAN_H +#include <sys/endian.h> +#endif + +#include "plibc.h" + +#include <locale.h> +#ifndef FRAMEWORK_BUILD +#include "gettext.h" +/** + * GNU gettext support macro. + */ +#define _(String) dgettext("gnunet",String) +#define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor" +#else +#include "libintlemu.h" +#define _(String) dgettext("org.gnunet.gnunet",String) +#define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor" +#endif + +#ifdef CYGWIN +#define SIOCGIFCONF _IOW('s', 100, struct ifconf) /* get if list */ +#define SIOCGIFFLAGS _IOW('s', 101, struct ifreq) /* Get if flags */ +#define SIOCGIFADDR _IOW('s', 102, struct ifreq) /* Get if addr */ +#endif + +#ifndef MINGW +#include <sys/mman.h> +#endif + +#ifdef FREEBSD +#define __BYTE_ORDER BYTE_ORDER +#define __BIG_ENDIAN BIG_ENDIAN +#endif + +#ifdef DARWIN +#define __BYTE_ORDER BYTE_ORDER +#define __BIG_ENDIAN BIG_ENDIAN + /* not available on darwin, override configure */ +#undef HAVE_STAT64 +#undef HAVE_MREMAP +#endif + + +#if !HAVE_ATOLL +long long +atoll (const char *nptr); +#endif + +#if ENABLE_NLS +#include "langinfo.h" +#endif + +#ifndef SIZE_MAX +#define SIZE_MAX ((size_t)(-1)) +#endif + +#ifndef O_LARGEFILE +#define O_LARGEFILE 0 +#endif + +#if defined(__sparc__) +#define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove(&__tmp, &(val), sizeof((val))); __tmp; }) +#else +#define MAKE_UNALIGNED(val) val +#endif + +#if WINDOWS +#define FDTYPE HANDLE +#define SOCKTYPE SOCKET +#else +#define FDTYPE int +#define SOCKTYPE int +#endif + +#endif diff --git a/src/include/plibc.h b/src/include/plibc.h new file mode 100644 index 0000000..70cbd9e --- /dev/null +++ b/src/include/plibc.h @@ -0,0 +1,864 @@ +/* + This file is part of PlibC. + (C) 2005, 2006, 2007, 2008, 2009, 2010 Nils Durner (and other contributing authors) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/** + * @file include/plibc.h + * @brief PlibC header + * @attention This file is usually not installed under Unix, + * so ship it with your application + * @version $Revision$ + */ + +#ifndef _PLIBC_H_ +#define _PLIBC_H_ + +#ifndef SIGALRM + #define SIGALRM 14 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stddef.h> + +#ifdef Q_OS_WIN32 + #define WINDOWS 1 +#endif + +#define HAVE_PLIBC_FD 0 + +#ifdef WINDOWS + +#if ENABLE_NLS + #include "langinfo.h" +#endif + +#include <ws2tcpip.h> +#include <windows.h> +#include <sys/types.h> +#include <time.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <dirent.h> +#include <errno.h> +#include <stdarg.h> + +#define __BYTE_ORDER BYTE_ORDER +#define __BIG_ENDIAN BIG_ENDIAN + +/* Conflicts with our definitions */ +#define __G_WIN32_H__ + +/* Convert LARGE_INTEGER to double */ +#define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \ + (double)((x).LowPart)) +#ifndef __MINGW64__ +struct stat64 +{ + _dev_t st_dev; + _ino_t st_ino; + _mode_t st_mode; + short st_nlink; + short st_uid; + short st_gid; + _dev_t st_rdev; + __int64 st_size; + __time64_t st_atime; + __time64_t st_mtime; + __time64_t st_ctime; +}; +#endif +typedef unsigned int sa_family_t; + +struct sockaddr_un { + short sun_family; /*AF_UNIX*/ + char sun_path[108]; /*path name */ +}; + +#ifndef pid_t + #define pid_t DWORD +#endif + +#ifndef error_t + #define error_t int +#endif + +#ifndef WEXITSTATUS + #define WEXITSTATUS(status) (((status) & 0xff00) >> 8) +#endif + +#ifndef MSG_DONTWAIT + #define MSG_DONTWAIT 0 +#endif + +enum +{ + _SC_PAGESIZE = 30, + _SC_PAGE_SIZE = 30 +}; + +/* Thanks to the Cygwin project */ +#define ENOCSI 43 /* No CSI structure available */ +#define EL2HLT 44 /* Level 2 halted */ +#ifndef EDEADLK + #define EDEADLK 45 /* Deadlock condition */ +#endif +#ifndef ENOLCK + #define ENOLCK 46 /* No record locks available */ +#endif +#define EBADE 50 /* Invalid exchange */ +#define EBADR 51 /* Invalid request descriptor */ +#define EXFULL 52 /* Exchange full */ +#define ENOANO 53 /* No anode */ +#define EBADRQC 54 /* Invalid request code */ +#define EBADSLT 55 /* Invalid slot */ +#ifndef EDEADLOCK + #define EDEADLOCK EDEADLK /* File locking deadlock error */ +#endif +#define EBFONT 57 /* Bad font file fmt */ +#define ENOSTR 60 /* Device not a stream */ +#define ENODATA 61 /* No data (for no delay io) */ +#define ETIME 62 /* Timer expired */ +#define ENOSR 63 /* Out of streams resources */ +#define ENONET 64 /* Machine is not on the network */ +#define ENOPKG 65 /* Package not installed */ +#define EREMOTE 66 /* The object is remote */ +#define ENOLINK 67 /* The link has been severed */ +#define EADV 68 /* Advertise error */ +#define ESRMNT 69 /* Srmount error */ +#define ECOMM 70 /* Communication error on send */ +#define EPROTO 71 /* Protocol error */ +#define EMULTIHOP 74 /* Multihop attempted */ +#define ELBIN 75 /* Inode is remote (not really error) */ +#define EDOTDOT 76 /* Cross mount point (not really error) */ +#define EBADMSG 77 /* Trying to read unreadable message */ +#define ENOTUNIQ 80 /* Given log. name not unique */ +#define EBADFD 81 /* f.d. invalid for this operation */ +#define EREMCHG 82 /* Remote address changed */ +#define ELIBACC 83 /* Can't access a needed shared lib */ +#define ELIBBAD 84 /* Accessing a corrupted shared lib */ +#define ELIBSCN 85 /* .lib section in a.out corrupted */ +#define ELIBMAX 86 /* Attempting to link in too many libs */ +#define ELIBEXEC 87 /* Attempting to exec a shared library */ +#ifndef ENOSYS + #define ENOSYS 88 /* Function not implemented */ +#endif +#define ENMFILE 89 /* No more files */ +#ifndef ENOTEMPTY + #define ENOTEMPTY 90 /* Directory not empty */ +#endif +#ifndef ENAMETOOLONG + #define ENAMETOOLONG 91 /* File or path name too long */ +#endif +#define ELOOP 92 /* Too many symbolic links */ +#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ +#define EPFNOSUPPORT 96 /* Protocol family not supported */ +#define ECONNRESET 104 /* Connection reset by peer */ +#define ENOBUFS 105 /* No buffer space available */ +#define EAFNOSUPPORT 106 /* Address family not supported by protocol family */ +#define EPROTOTYPE 107 /* Protocol wrong type for socket */ +#define ENOTSOCK 108 /* Socket operation on non-socket */ +#define ENOPROTOOPT 109 /* Protocol not available */ +#define ESHUTDOWN 110 /* Can't send after socket shutdown */ +#define ECONNREFUSED 111 /* Connection refused */ +#define EADDRINUSE 112 /* Address already in use */ +#define ECONNABORTED 113 /* Connection aborted */ +#define ENETUNREACH 114 /* Network is unreachable */ +#define ENETDOWN 115 /* Network interface is not configured */ +#ifndef ETIMEDOUT + #define ETIMEDOUT 116 /* Connection timed out */ +#endif +#define EHOSTDOWN 117 /* Host is down */ +#define EHOSTUNREACH 118 /* Host is unreachable */ +#define EINPROGRESS 119 /* Connection already in progress */ +#define EALREADY 120 /* Socket already connected */ +#define EDESTADDRREQ 121 /* Destination address required */ +#define EMSGSIZE 122 /* Message too long */ +#define EPROTONOSUPPORT 123 /* Unknown protocol */ +#define ESOCKTNOSUPPORT 124 /* Socket type not supported */ +#define EADDRNOTAVAIL 125 /* Address not available */ +#define ENETRESET 126 /* Connection aborted by network */ +#define EISCONN 127 /* Socket is already connected */ +#define ENOTCONN 128 /* Socket is not connected */ +#define ETOOMANYREFS 129 /* Too many references: cannot splice */ +#define EPROCLIM 130 /* Too many processes */ +#define EUSERS 131 /* Too many users */ +#define EDQUOT 132 /* Disk quota exceeded */ +#define ESTALE 133 /* Unknown error */ +#ifndef ENOTSUP + #define ENOTSUP 134 /* Not supported */ +#endif +#define ENOMEDIUM 135 /* No medium (in tape drive) */ +#define ENOSHARE 136 /* No such host or network path */ +#define ECASECLASH 137 /* Filename exists with different case */ +#define EWOULDBLOCK EAGAIN /* Operation would block */ +#define EOVERFLOW 139 /* Value too large for defined data type */ + +#undef HOST_NOT_FOUND +#define HOST_NOT_FOUND 1 +#undef TRY_AGAIN +#define TRY_AGAIN 2 +#undef NO_RECOVERY +#define NO_RECOVERY 3 +#undef NO_ADDRESS +#define NO_ADDRESS 4 + +#define PROT_READ 0x1 +#define PROT_WRITE 0x2 +#define MAP_SHARED 0x1 +#define MAP_PRIVATE 0x2 /* unsupported */ +#define MAP_FIXED 0x10 +#define MAP_ANONYMOUS 0x20 /* unsupported */ +#define MAP_FAILED ((void *)-1) + +#define MS_ASYNC 1 /* sync memory asynchronously */ +#define MS_INVALIDATE 2 /* invalidate the caches */ +#define MS_SYNC 4 /* synchronous memory sync */ + +struct statfs +{ + long f_type; /* type of filesystem (see below) */ + long f_bsize; /* optimal transfer block size */ + long f_blocks; /* total data blocks in file system */ + long f_bfree; /* free blocks in fs */ + long f_bavail; /* free blocks avail to non-superuser */ + long f_files; /* total file nodes in file system */ + long f_ffree; /* free file nodes in fs */ + long f_fsid; /* file system id */ + long f_namelen; /* maximum length of filenames */ + long f_spare[6]; /* spare for later */ +}; + +extern const struct in6_addr in6addr_any; /* :: */ +extern const struct in6_addr in6addr_loopback; /* ::1 */ + +/* Taken from the Wine project <http://www.winehq.org> + /wine/include/winternl.h */ +enum SYSTEM_INFORMATION_CLASS +{ + SystemBasicInformation = 0, + Unknown1, + SystemPerformanceInformation = 2, + SystemTimeOfDayInformation = 3, /* was SystemTimeInformation */ + Unknown4, + SystemProcessInformation = 5, + Unknown6, + Unknown7, + SystemProcessorPerformanceInformation = 8, + Unknown9, + Unknown10, + SystemDriverInformation, + Unknown12, + Unknown13, + Unknown14, + Unknown15, + SystemHandleList, + Unknown17, + Unknown18, + Unknown19, + Unknown20, + SystemCacheInformation, + Unknown22, + SystemInterruptInformation = 23, + SystemExceptionInformation = 33, + SystemRegistryQuotaInformation = 37, + SystemLookasideInformation = 45 +}; + +typedef struct +{ + LARGE_INTEGER IdleTime; + LARGE_INTEGER KernelTime; + LARGE_INTEGER UserTime; + LARGE_INTEGER Reserved1[2]; + ULONG Reserved2; +} SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION; + +#define sleep(secs) (Sleep(secs * 1000)) + +/*********************** statfs *****************************/ +/* fake block size */ +#define FAKED_BLOCK_SIZE 512 + +/* linux-compatible values for fs type */ +#define MSDOS_SUPER_MAGIC 0x4d44 +#define NTFS_SUPER_MAGIC 0x5346544E + +/*********************** End of statfs ***********************/ + +#define SHUT_RDWR SD_BOTH + +/* Operations for flock() */ +#define LOCK_SH 1 /* shared lock */ +#define LOCK_EX 2 /* exclusive lock */ +#define LOCK_NB 4 /* or'd with one of the above to prevent + blocking */ +#define LOCK_UN 8 /* remove lock */ + +/* Not supported under MinGW */ +#define S_IRGRP 0 +#define S_IWGRP 0 +#define S_IROTH 0 +#define S_IXGRP 0 +#define S_IWOTH 0 +#define S_IXOTH 0 +#define S_ISUID 0 +#define S_ISGID 0 +#define S_ISVTX 0 +#define S_IRWXG 0 +#define S_IRWXO 0 + +#define SHUT_WR SD_SEND +#define SHUT_RD SD_RECEIVE +#define SHUT_RDWR SD_BOTH + +#define SIGKILL 9 +#define SIGTERM 15 + +#define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__) + +BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest); +BOOL _plibc_DereferenceShortcut(char *pszShortcut); +char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags); +char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags); + +long QueryRegistry(HKEY hMainKey, const char *pszKey, const char *pszSubKey, + char *pszBuffer, long *pdLength); +long QueryRegistryW(HKEY hMainKey, const wchar_t *pszKey, const wchar_t *pszSubKey, + wchar_t *pszBuffer, long *pdLength); + +BOOL __win_IsHandleMarkedAsBlocking(int hHandle); +void __win_SetHandleBlockingMode(int s, BOOL bBlocking); +void __win_DiscardHandleBlockingMode(int s); +int _win_isSocketValid(int s); +int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows); +int plibc_conv_to_win_pathw(const wchar_t *pszUnix, wchar_t *pwszWindows); + +int plibc_conv_to_win_pathwconv(const char *pszUnix, wchar_t *pwszWindows); +int plibc_conv_to_win_pathwconv_ex(const char *pszUnix, wchar_t *pszWindows, int derefLinks); + +unsigned plibc_get_handle_count(); + +typedef void (*TPanicProc) (int, char *); +void plibc_set_panic_proc(TPanicProc proc); + +int flock(int fd, int operation); +int fsync(int fildes); +int inet_pton(int af, const char *src, void *dst); +int inet_pton4(const char *src, u_char *dst, int pton); +#if USE_IPV6 +int inet_pton6(const char *src, u_char *dst); +#endif +int truncate(const char *fname, int distance); +int statfs(const char *path, struct statfs *buf); +const char *hstrerror(int err); +int mkstemp(char *tmplate); +char *strptime (const char *buf, const char *format, struct tm *tm); +const char *inet_ntop(int af, const void *src, char *dst, size_t size); +struct tm *gmtime_r(const time_t *clock, struct tm *result); + +int plibc_init(char *pszOrg, char *pszApp); +void plibc_shutdown(); +int plibc_initialized(); + +void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine); +void SetErrnoFromWinsockError(long lWinError); +void SetHErrnoFromWinError(long lWinError); +void SetErrnoFromHRESULT(HRESULT hRes); +int GetErrnoFromWinsockError(long lWinError); +FILE *_win_fopen(const char *filename, const char *mode); +int _win_fclose(FILE *); +DIR *_win_opendir(const char *dirname); +struct dirent *_win_readdir(DIR *dirp); +int _win_closedir(DIR *dirp); +int _win_open(const char *filename, int oflag, ...); +#ifdef ENABLE_NLS +char *_win_bindtextdomain(const char *domainname, const char *dirname); +#endif +int _win_chdir(const char *path); +int _win_close(int fd); +int _win_creat(const char *path, mode_t mode); +char *_win_ctime(const time_t *clock); +char *_win_ctime_r(const time_t *clock, char *buf); +int _win_fstat(int handle, struct stat *buffer); +int _win_ftruncate(int fildes, off_t length); +void _win_gettimeofday(struct timeval *tp, void *tzp); +int _win_kill(pid_t pid, int sig); +int _win_pipe(int *phandles); +int _win_rmdir(const char *path); +int _win_access( const char *path, int mode ); +int _win_chmod(const char *filename, int pmode); +char *realpath(const char *file_name, char *resolved_name); +long _win_random(void); +void _win_srandom(unsigned int seed); +int _win_remove(const char *path); +int _win_rename(const char *oldname, const char *newname); +int _win_stat(const char *path, struct stat *buffer); +int _win_stat64(const char *path, struct stat64 *buffer); +long _win_sysconf(int name); +int _win_unlink(const char *filename); +int _win_write(int fildes, const void *buf, size_t nbyte); +int _win_read(int fildes, void *buf, size_t nbyte); +size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE *stream); +size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream ); +int _win_symlink(const char *path1, const char *path2); +void *_win_mmap(void *start, size_t len, int access, int flags, int fd, + unsigned long long offset); +int _win_msync(void *start, size_t length, int flags); +int _win_munmap(void *start, size_t length); +int _win_lstat(const char *path, struct stat *buf); +int _win_lstat64(const char *path, struct stat64 *buf); +int _win_readlink(const char *path, char *buf, size_t bufsize); +int _win_accept(int s, struct sockaddr *addr, int *addrlen); + +int _win_printf(const char *format,...); +int _win_wprintf(const wchar_t *format, ...); + +int _win_fprintf(FILE *f,const char *format,...); +int _win_fwprintf(FILE *f,const wchar_t *format, ...); + +int _win_vprintf(const char *format, va_list ap); +int _win_vfwprintf(FILE *stream, const wchar_t *format, va_list arg_ptr); + +int _win_vfprintf(FILE *stream, const char *format, va_list arg_ptr); +int _win_vwprintf(const wchar_t *format, va_list ap); + +int _win_vsprintf(char *dest,const char *format, va_list arg_ptr); +int _win_vswprintf(wchar_t *dest, const wchar_t *format, va_list arg_ptr); + +int _win_vsnprintf(char* str, size_t size, const char *format, va_list arg_ptr); +int _win_vsnwprintf(wchar_t* wstr, size_t size, const wchar_t *format, va_list arg_ptr); + +int _win_snprintf(char *str,size_t size,const char *format,...); +int _win_snwprintf(wchar_t *str, size_t size, const wchar_t *format, ...); + +int _win_sprintf(char *dest,const char *format,...); +int _win_swprintf(wchar_t *dest, const wchar_t *format, ...); + +int _win_vsscanf(const char* str, const char* format, va_list arg_ptr); +int _win_vswscanf(const wchar_t* wstr, const wchar_t* format, va_list arg_ptr); + +int _win_sscanf(const char *str, const char *format, ...); +int _win_swscanf(const wchar_t *wstr, const wchar_t *format, ...); + +int _win_vfscanf(FILE *stream, const char *format, va_list arg_ptr); +int _win_vfwscanf(FILE *stream, const wchar_t *format, va_list arg_ptr); + +int _win_vscanf(const char *format, va_list arg_ptr); +int _win_vwscanf(const wchar_t *format, va_list arg_ptr); + +int _win_scanf(const char *format, ...); +int _win_wscanf(const wchar_t *format, ...); + +int _win_fscanf(FILE *stream, const char *format, ...); +int _win_fwscanf(FILE *stream, const wchar_t *format, ...); + + +pid_t _win_waitpid(pid_t pid, int *stat_loc, int options); +int _win_bind(int s, const struct sockaddr *name, int namelen); +int _win_connect(int s,const struct sockaddr *name, int namelen); +int _win_getpeername(int s, struct sockaddr *name, + int *namelen); +int _win_getsockname(int s, struct sockaddr *name, + int *namelen); +int _win_getsockopt(int s, int level, int optname, char *optval, + int *optlen); +int _win_listen(int s, int backlog); +int _win_recv(int s, char *buf, int len, int flags); +int _win_recvfrom(int s, void *buf, int len, int flags, + struct sockaddr *from, int *fromlen); +int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds, + const struct timeval *tv); +int _win_send(int s, const char *buf, int len, int flags); +int _win_sendto(int s, const char *buf, int len, int flags, + const struct sockaddr *to, int tolen); +int _win_setsockopt(int s, int level, int optname, const void *optval, + int optlen); +int _win_shutdown(int s, int how); +int _win_socket(int af, int type, int protocol); +struct hostent *_win_gethostbyaddr(const char *addr, int len, int type); +struct hostent *_win_gethostbyname(const char *name); +struct hostent *gethostbyname2(const char *name, int af); +char *_win_strerror(int errnum); +int IsWinNT(); +char *index(const char *s, int c); + +#if !HAVE_STRNDUP +char *strndup (const char *s, size_t n); +#endif +#if !HAVE_STRNLEN +size_t strnlen (const char *str, size_t maxlen); +#endif +char *stpcpy(char *dest, const char *src); +char *strcasestr(const char *haystack_start, const char *needle_start); +#ifndef __MINGW64__ +#define strcasecmp(a, b) stricmp(a, b) +#define wcscasecmp(a, b) wcsicmp(a, b) +#define strncasecmp(a, b, c) strnicmp(a, b, c) +#define wcsncasecmp(a, b, c) wcsnicmp(a, b, c) +#endif +#endif /* WINDOWS */ + +#ifndef WINDOWS + #define DIR_SEPARATOR '/' + #define DIR_SEPARATOR_STR "/" + #define PATH_SEPARATOR ':' + #define PATH_SEPARATOR_STR ":" + #define NEWLINE "\n" + +#ifdef ENABLE_NLS + #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n) +#endif + #define CREAT(p, m) creat(p, m) + #define PLIBC_CTIME(c) ctime(c) + #define CTIME_R(c, b) ctime_r(c, b) + #undef FOPEN + #define FOPEN(f, m) fopen(f, m) + #define FCLOSE(f) fclose(f) + #define FTRUNCATE(f, l) ftruncate(f, l) + #define OPENDIR(d) opendir(d) + #define CLOSEDIR(d) closedir(d) + #define READDIR(d) readdir(d) + #define OPEN open + #define CHDIR(d) chdir(d) + #define CLOSE(f) close(f) + #define LSEEK(f, o, w) lseek(f, o, w) + #define RMDIR(f) rmdir(f) + #define ACCESS(p, m) access(p, m) + #define CHMOD(f, p) chmod(f, p) + #define FSTAT(h, b) fstat(h, b) + #define PLIBC_KILL(p, s) kill(p, s) + #define PIPE(h) pipe(h) + #define REMOVE(p) remove(p) + #define RENAME(o, n) rename(o, n) + #define STAT(p, b) stat(p, b) + #define STAT64(p, b) stat64(p, b) + #define SYSCONF(n) sysconf(n) + #define UNLINK(f) unlink(f) + #define WRITE(f, b, n) write(f, b, n) + #define READ(f, b, n) read(f, b, n) + #define GN_FREAD(b, s, c, f) fread(b, s, c, f) + #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f) + #define SYMLINK(a, b) symlink(a, b) + #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o) + #define MKFIFO(p, m) mkfifo(p, m) + #define MSYNC(s, l, f) msync(s, l, f) + #define MUNMAP(s, l) munmap(s, l) + #define STRERROR(i) strerror(i) + #define RANDOM() random() + #define SRANDOM(s) srandom(s) + #define READLINK(p, b, s) readlink(p, b, s) + #define LSTAT(p, b) lstat(p, b) + #define LSTAT64(p, b) lstat64(p, b) + #define PRINTF printf + #define FPRINTF fprintf + #define VPRINTF(f, a) vprintf(f, a) + #define VFPRINTF(s, f, a) vfprintf(s, f, a) + #define VSPRINTF(d, f, a) vsprintf(d, f, a) + #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a) + #define _REAL_SNPRINTF snprintf + #define SPRINTF sprintf + #define VSSCANF(s, f, a) vsscanf(s, f, a) + #define SSCANF sscanf + #define VFSCANF(s, f, a) vfscanf(s, f, a) + #define VSCANF(f, a) vscanf(f, a) + #define SCANF scanf + #define FSCANF fscanf + #define WAITPID(p, s, o) waitpid(p, s, o) + #define ACCEPT(s, a, l) accept(s, a, l) + #define BIND(s, n, l) bind(s, n, l) + #define CONNECT(s, n, l) connect(s, n, l) + #define GETPEERNAME(s, n, l) getpeername(s, n, l) + #define GETSOCKNAME(s, n, l) getsockname(s, n, l) + #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p) + #define LISTEN(s, b) listen(s, b) + #define RECV(s, b, l, f) recv(s, b, l, f) + #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o) + #define SELECT(n, r, w, e, t) select(n, r, w, e, t) + #define SEND(s, b, l, f) send(s, b, l, f) + #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n) + #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n) + #define SHUTDOWN(s, h) shutdown(s, h) + #define SOCKET(a, t, p) socket(a, t, p) + #define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t) + #define GETHOSTBYNAME(n) gethostbyname(n) + #define GETTIMEOFDAY(t, n) gettimeofday(t, n) + #define INSQUE(e, p) insque(e, p) + #define REMQUE(e) remque(e) + #define HSEARCH(i, a) hsearch(i, a) + #define HCREATE(n) hcreate(n) + #define HDESTROY() hdestroy() + #define HSEARCH_R(i, a, r, h) hsearch_r(i, a, r, h) + #define HCREATE_R(n, h) hcreate_r(n, h) + #define HDESTROY_R(h) hdestroy_r(h) + #define TSEARCH(k, r, c) tsearch(k, r, c) + #define TFIND(k, r, c) tfind(k, r, c) + #define TDELETE(k, r, c) tdelete(k, r, c) + #define TWALK(r, a) twalk(r, a) + #define TDESTROY(r, f) tdestroy(r, f) + #define LFIND(k, b, n, s, c) lfind(k, b, n, s, c) + #define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c) +#else + #define DIR_SEPARATOR '\\' + #define DIR_SEPARATOR_STR "\\" + #define PATH_SEPARATOR ';' + #define PATH_SEPARATOR_STR ";" + #define NEWLINE "\r\n" + +#ifdef ENABLE_NLS + #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n) +#endif + #define CREAT(p, m) _win_creat(p, m) + #define PLIBC_CTIME(c) _win_ctime(c) + #define CTIME_R(c, b) _win_ctime_r(c, b) + #define FOPEN(f, m) _win_fopen(f, m) + #define FCLOSE(f) _win_fclose(f) + #define FTRUNCATE(f, l) _win_ftruncate(f, l) + #define OPENDIR(d) _win_opendir(d) + #define CLOSEDIR(d) _win_closedir(d) + #define READDIR(d) _win_readdir(d) + #define OPEN _win_open + #define CHDIR(d) _win_chdir(d) + #define CLOSE(f) _win_close(f) + #define PLIBC_KILL(p, s) _win_kill(p, s) + #define LSEEK(f, o, w) _win_lseek(f, o, w) + #define FSTAT(h, b) _win_fstat(h, b) + #define RMDIR(f) _win_rmdir(f) + #define ACCESS(p, m) _win_access(p, m) + #define CHMOD(f, p) _win_chmod(f, p) + #define PIPE(h) _win_pipe(h) + #define RANDOM() _win_random() + #define SRANDOM(s) _win_srandom(s) + #define REMOVE(p) _win_remove(p) + #define RENAME(o, n) _win_rename(o, n) + #define STAT(p, b) _win_stat(p, b) + #define STAT64(p, b) _win_stat64(p, b) + #define SYSCONF(n) _win_sysconf(n) + #define UNLINK(f) _win_unlink(f) + #define WRITE(f, b, n) _win_write(f, b, n) + #define READ(f, b, n) _win_read(f, b, n) + #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f) + #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f) + #define SYMLINK(a, b) _win_symlink(a, b) + #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o) + #define MKFIFO(p, m) _win_mkfifo(p, m) + #define MSYNC(s, l, f) _win_msync(s, l, f) + #define MUNMAP(s, l) _win_munmap(s, l) + #define STRERROR(i) _win_strerror(i) + #define READLINK(p, b, s) _win_readlink(p, b, s) + #define LSTAT(p, b) _win_lstat(p, b) + #define LSTAT64(p, b) _win_lstat64(p, b) + #define PRINTF(f, ...) _win_printf(f , __VA_ARGS__) + #define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__) + #define VPRINTF(f, a) _win_vprintf(f, a) + #define VFPRINTF(s, f, a) _win_vfprintf(s, f, a) + #define VSPRINTF(d, f, a) _win_vsprintf(d, f, a) + #define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a) + #define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt, __VA_ARGS__) + #define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__) + #define VSSCANF(s, f, a) _win_vsscanf(s, f, a) + #define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__) + #define VFSCANF(s, f, a) _win_vfscanf(s, f, a) + #define VSCANF(f, a) _win_vscanf(f, a) + #define SCANF(f, ...) _win_scanf(f, __VA_ARGS__) + #define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__) + #define WAITPID(p, s, o) _win_waitpid(p, s, o) + #define ACCEPT(s, a, l) _win_accept(s, a, l) + #define BIND(s, n, l) _win_bind(s, n, l) + #define CONNECT(s, n, l) _win_connect(s, n, l) + #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l) + #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l) + #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p) + #define LISTEN(s, b) _win_listen(s, b) + #define RECV(s, b, l, f) _win_recv(s, b, l, f) + #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o) + #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t) + #define SEND(s, b, l, f) _win_send(s, b, l, f) + #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n) + #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n) + #define SHUTDOWN(s, h) _win_shutdown(s, h) + #define SOCKET(a, t, p) _win_socket(a, t, p) + #define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t) + #define GETHOSTBYNAME(n) _win_gethostbyname(n) + #define GETTIMEOFDAY(t, n) _win_gettimeofday(t, n) + #define INSQUE(e, p) _win_insque(e, p) + #define REMQUE(e) _win_remque(e) + #define HSEARCH(i, a) _win_hsearch(i, a) + #define HCREATE(n) _win_hcreate(n) + #define HDESTROY() _win_hdestroy() + #define HSEARCH_R(i, a, r, h) _win_hsearch_r(i, a, r, h) + #define HCREATE_R(n, h) _win_hcreate_r(n, h) + #define HDESTROY_R(h) _win_hdestroy_r(h) + #define TSEARCH(k, r, c) _win_tsearch(k, r, c) + #define TFIND(k, r, c) _win_tfind(k, r, c) + #define TDELETE(k, r, c) _win_tdelete(k, r, c) + #define TWALK(r, a) _win_twalk(r, a) + #define TDESTROY(r, f) _win_tdestroy(r, f) + #define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c) + #define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c) +#endif + +/* search.h */ + +/* Prototype structure for a linked-list data structure. + This is the type used by the `insque' and `remque' functions. */ + +struct PLIBC_SEARCH_QELEM + { + struct qelem *q_forw; + struct qelem *q_back; + char q_data[1]; + }; + + +/* Insert ELEM into a doubly-linked list, after PREV. */ +void _win_insque (void *__elem, void *__prev); + +/* Unlink ELEM from the doubly-linked list that it is in. */ +void _win_remque (void *__elem); + + +/* For use with hsearch(3). */ +typedef int (*PLIBC_SEARCH__compar_fn_t) (__const void *, __const void *); + +typedef PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t; + +/* Action which shall be performed in the call the hsearch. */ +typedef enum + { + PLIBC_SEARCH_FIND, + PLIBC_SEARCH_ENTER + } +PLIBC_SEARCH_ACTION; + +typedef struct PLIBC_SEARCH_entry + { + char *key; + void *data; + } +PLIBC_SEARCH_ENTRY; + +/* The reentrant version has no static variables to maintain the state. + Instead the interface of all functions is extended to take an argument + which describes the current status. */ +typedef struct _PLIBC_SEARCH_ENTRY +{ + unsigned int used; + PLIBC_SEARCH_ENTRY entry; +} +_PLIBC_SEARCH_ENTRY; + + +/* Family of hash table handling functions. The functions also + have reentrant counterparts ending with _r. The non-reentrant + functions all work on a signle internal hashing table. */ + +/* Search for entry matching ITEM.key in internal hash table. If + ACTION is `FIND' return found entry or signal error by returning + NULL. If ACTION is `ENTER' replace existing data (if any) with + ITEM.data. */ +PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action); + +/* Create a new hashing table which will at most contain NEL elements. */ +int _win_hcreate (size_t __nel); + +/* Destroy current internal hashing table. */ +void _win_hdestroy (void); + +/* Data type for reentrant functions. */ +struct PLIBC_SEARCH_hsearch_data + { + struct _PLIBC_SEARCH_ENTRY *table; + unsigned int size; + unsigned int filled; + }; + +/* Reentrant versions which can handle multiple hashing tables at the + same time. */ +int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action, PLIBC_SEARCH_ENTRY **__retval, + struct PLIBC_SEARCH_hsearch_data *__htab); +int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab); +void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab); + + +/* The tsearch routines are very interesting. They make many + assumptions about the compiler. It assumes that the first field + in node must be the "key" field, which points to the datum. + Everything depends on that. */ +/* For tsearch */ +typedef enum +{ + PLIBC_SEARCH_preorder, + PLIBC_SEARCH_postorder, + PLIBC_SEARCH_endorder, + PLIBC_SEARCH_leaf +} +PLIBC_SEARCH_VISIT; + +/* Search for an entry matching the given KEY in the tree pointed to + by *ROOTP and insert a new element if not found. */ +void *_win_tsearch (__const void *__key, void **__rootp, + PLIBC_SEARCH__compar_fn_t __compar); + +/* Search for an entry matching the given KEY in the tree pointed to + by *ROOTP. If no matching entry is available return NULL. */ +void *_win_tfind (__const void *__key, void *__const *__rootp, + PLIBC_SEARCH__compar_fn_t __compar); + +/* Remove the element matching KEY from the tree pointed to by *ROOTP. */ +void *_win_tdelete (__const void *__restrict __key, + void **__restrict __rootp, + PLIBC_SEARCH__compar_fn_t __compar); + +typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep, PLIBC_SEARCH_VISIT __value, + int __level); + +/* Walk through the whole tree and call the ACTION callback for every node + or leaf. */ +void _win_twalk (__const void *__root, PLIBC_SEARCH__action_fn_t __action); + +/* Callback type for function to free a tree node. If the keys are atomic + data this function should do nothing. */ +typedef void (*PLIBC_SEARCH__free_fn_t) (void *__nodep); + +/* Destroy the whole tree, call FREEFCT for each node or leaf. */ +void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct); + + +/* Perform linear search for KEY by comparing by COMPAR in an array + [BASE,BASE+NMEMB*SIZE). */ +void *_win_lfind (__const void *__key, __const void *__base, + size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar); + +/* Perform linear search for KEY by comparing by COMPAR function in + array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */ +void *_win_lsearch (__const void *__key, void *__base, + size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar); + + +#ifdef __cplusplus +} +#endif + + +#endif //_PLIBC_H_ + +/* end of plibc.h */ diff --git a/src/include/winproc.h b/src/include/winproc.h new file mode 100644 index 0000000..3670a74 --- /dev/null +++ b/src/include/winproc.h @@ -0,0 +1,234 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 2003, 2004, 2005 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/winproc.h + * @brief Definitions for MS Windows + * @author Nils Durner + */ + +#ifndef _WINPROC_H +#define _WINPROC_H + +#include <io.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/timeb.h> +#include <time.h> +#include <dirent.h> +#ifndef FD_SETSIZE +#define FD_SETSIZE 1024 +#endif +#include <winsock2.h> +#include <ws2tcpip.h> +#include <windows.h> +#include <winerror.h> +#include <iphlpapi.h> +#include <shlobj.h> +#include <objbase.h> +#include <sys/param.h> /* #define BYTE_ORDER */ +#include <ntsecapi.h> +#include <lm.h> +#include <aclapi.h> + + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifndef MAX_NAME_LENGTH +#define MAX_NAME_LENGTH 25 +#endif + + typedef DWORD WINAPI (*TNtQuerySystemInformation) (int, PVOID, ULONG, PULONG); + typedef DWORD WINAPI (*TGetIfEntry) (PMIB_IFROW pIfRow); + typedef DWORD WINAPI (*TGetIpAddrTable) (PMIB_IPADDRTABLE pIpAddrTable, + PULONG pdwSize, BOOL bOrder); + typedef DWORD WINAPI (*TGetIfTable) (PMIB_IFTABLE pIfTable, PULONG pdwSize, + BOOL bOrder); + typedef DWORD WINAPI (*TGetBestInterfaceEx) (struct sockaddr *, PDWORD); + /* TODO: Explicitly import -A variants (i.e. TCreateHardLinkA) or -W + * variants (TCreateHardLinkW), etc. + */ + typedef DWORD WINAPI (*TCreateHardLink) (LPCTSTR lpFileName, + LPCTSTR lpExistingFileName, + LPSECURITY_ATTRIBUTES + lpSecurityAttributes); + typedef SC_HANDLE WINAPI (*TOpenSCManager) (LPCTSTR lpMachineName, + LPCTSTR lpDatabaseName, + DWORD dwDesiredAccess); + typedef SC_HANDLE WINAPI (*TCreateService) (SC_HANDLE hSCManager, + LPCTSTR lpServiceName, + LPCTSTR lpDisplayName, + DWORD dwDesiredAccess, + DWORD dwServiceType, + DWORD dwStartType, + DWORD dwErrorControl, + LPCTSTR lpBinaryPathName, + LPCTSTR lpLoadOrderGroup, + LPDWORD lpdwTagId, + LPCTSTR lpDependencies, + LPCTSTR lpServiceStartName, + LPCTSTR lpPassword); + typedef BOOL WINAPI (*TCloseServiceHandle) (SC_HANDLE hSCObject); + typedef BOOL WINAPI (*TDeleteService) (SC_HANDLE hService); + typedef SERVICE_STATUS_HANDLE WINAPI (*TRegisterServiceCtrlHandler) (LPCTSTR + lpServiceName, + LPHANDLER_FUNCTION + lpHandlerProc); + typedef BOOL WINAPI (*TSetServiceStatus) (SERVICE_STATUS_HANDLE + hServiceStatus, + LPSERVICE_STATUS lpServiceStatus); + typedef BOOL WINAPI (*TStartServiceCtrlDispatcher) (const + LPSERVICE_TABLE_ENTRY + lpServiceTable); + typedef BOOL WINAPI (*TControlService) (SC_HANDLE hService, DWORD dwControl, + LPSERVICE_STATUS lpServiceStatus); + typedef SC_HANDLE WINAPI (*TOpenService) (SC_HANDLE hSCManager, + LPCTSTR lpServiceName, + DWORD dwDesiredAccess); + typedef DWORD WINAPI (*TGetAdaptersInfo) (PIP_ADAPTER_INFO pAdapterInfo, + PULONG pOutBufLen); + typedef NET_API_STATUS WINAPI (*TNetUserAdd) (LPCWSTR, DWORD, PBYTE, PDWORD); + typedef NET_API_STATUS WINAPI (*TNetUserSetInfo) (LPCWSTR servername, + LPCWSTR username, + DWORD level, LPBYTE buf, + LPDWORD parm_err); + typedef NTSTATUS NTAPI (*TLsaOpenPolicy) (PLSA_UNICODE_STRING, + PLSA_OBJECT_ATTRIBUTES, ACCESS_MASK, + PLSA_HANDLE); + typedef NTSTATUS NTAPI (*TLsaAddAccountRights) (LSA_HANDLE, PSID, + PLSA_UNICODE_STRING, ULONG); + typedef NTSTATUS NTAPI (*TLsaRemoveAccountRights) (LSA_HANDLE, PSID, BOOLEAN, + PLSA_UNICODE_STRING, + ULONG); + typedef NTSTATUS NTAPI (*TLsaClose) (LSA_HANDLE); + typedef BOOL WINAPI (*TLookupAccountName) (LPCTSTR lpSystemName, + LPCTSTR lpAccountName, PSID Sid, + LPDWORD cbSid, + LPTSTR ReferencedDomainName, + LPDWORD cchReferencedDomainName, + PSID_NAME_USE peUse); + + typedef BOOL WINAPI (*TGetFileSecurity) (LPCTSTR lpFileName, + SECURITY_INFORMATION + RequestedInformation, + PSECURITY_DESCRIPTOR + pSecurityDescriptor, DWORD nLength, + LPDWORD lpnLengthNeeded); + typedef BOOL WINAPI (*TInitializeSecurityDescriptor) (PSECURITY_DESCRIPTOR + pSecurityDescriptor, + DWORD dwRevision); + typedef BOOL WINAPI (*TGetSecurityDescriptorDacl) (PSECURITY_DESCRIPTOR + pSecurityDescriptor, + LPBOOL lpbDaclPresent, + PACL * pDacl, + LPBOOL lpbDaclDefaulted); + typedef BOOL WINAPI (*TGetAclInformation) (PACL pAcl, LPVOID pAclInformation, + DWORD nAclInformationLength, + ACL_INFORMATION_CLASS + dwAclInformationClass); + typedef BOOL WINAPI (*TInitializeAcl) (PACL pAcl, DWORD nAclLength, + DWORD dwAclRevision); + typedef BOOL WINAPI (*TGetAce) (PACL pAcl, DWORD dwAceIndex, LPVOID * pAce); + typedef BOOL WINAPI (*TEqualSid) (PSID pSid1, PSID pSid2); + typedef BOOL WINAPI (*TAddAce) (PACL pAcl, DWORD dwAceRevision, + DWORD dwStartingAceIndex, LPVOID pAceList, + DWORD nAceListLength); + typedef BOOL WINAPI (*TAddAccessAllowedAce) (PACL pAcl, DWORD dwAceRevision, + DWORD AccessMask, PSID pSid); + typedef BOOL WINAPI (*TSetNamedSecurityInfo) (LPTSTR pObjectName, + SE_OBJECT_TYPE ObjectType, + SECURITY_INFORMATION + SecurityInfo, PSID psidOwner, + PSID psidGroup, PACL pDacl, + PACL pSacl); + + extern TGetBestInterfaceEx GNGetBestInterfaceEx; + extern TNtQuerySystemInformation GNNtQuerySystemInformation; + extern TGetIfEntry GNGetIfEntry; + extern TGetIpAddrTable GNGetIpAddrTable; + extern TGetIfTable GNGetIfTable; + extern TCreateHardLink GNCreateHardLink; + extern TOpenSCManager GNOpenSCManager; + extern TCreateService GNCreateService; + extern TCloseServiceHandle GNCloseServiceHandle; + extern TDeleteService GNDeleteService; + extern TRegisterServiceCtrlHandler GNRegisterServiceCtrlHandler; + extern TSetServiceStatus GNSetServiceStatus; + extern TStartServiceCtrlDispatcher GNStartServiceCtrlDispatcher; + extern TControlService GNControlService; + extern TOpenService GNOpenService; + extern TGetAdaptersInfo GNGetAdaptersInfo; + extern TNetUserAdd GNNetUserAdd; + extern TNetUserSetInfo GNNetUserSetInfo; + extern TLsaOpenPolicy GNLsaOpenPolicy; + extern TLsaAddAccountRights GNLsaAddAccountRights; + extern TLsaRemoveAccountRights GNLsaRemoveAccountRights; + extern TLsaClose GNLsaClose; + extern TLookupAccountName GNLookupAccountName; + extern TGetFileSecurity GNGetFileSecurity; + extern TInitializeSecurityDescriptor GNInitializeSecurityDescriptor; + extern TGetSecurityDescriptorDacl GNGetSecurityDescriptorDacl; + extern TGetAclInformation GNGetAclInformation; + extern TInitializeAcl GNInitializeAcl; + extern TGetAce GNGetAce; + extern TEqualSid GNEqualSid; + extern TAddAce GNAddAce; + extern TAddAccessAllowedAce GNAddAccessAllowedAce; + extern TSetNamedSecurityInfo GNSetNamedSecurityInfo; + + + BOOL CreateShortcut (const char *pszSrc, const char *pszDest); + BOOL DereferenceShortcut (char *pszShortcut); + long QueryRegistry (HKEY hMainKey, const char *pszKey, const char *pszSubKey, + char *pszBuffer, long *pdLength); + int ListNICs (void (*callback) (void *, const char *, int), void *cls); + BOOL AddPathAccessRights (char *lpszFileName, char *lpszAccountName, + DWORD dwAccessMask); + char *winErrorStr (const char *prefix, int dwErr); + void EnumNICs (PMIB_IFTABLE * pIfTable, PMIB_IPADDRTABLE * pAddrTable); + +#define ENUMNICS3_MASK_OK 0x01 +#define ENUMNICS3_BCAST_OK 0x02 + + struct EnumNICs3_results + { + unsigned char flags; + int is_default; + char pretty_name[1001]; + size_t addr_size; + SOCKADDR_STORAGE address; + SOCKADDR_STORAGE mask; + SOCKADDR_STORAGE broadcast; + }; + + int EnumNICs3 (struct EnumNICs3_results **, int *EnumNICs3_results_count); + void EnumNICs3_free (struct EnumNICs3_results *); + int GNInitWinEnv (); + void GNShutdownWinEnv (); + +#ifdef __cplusplus +} +#endif + +#endif |