aboutsummaryrefslogtreecommitdiff
path: root/src/lockmanager
diff options
context:
space:
mode:
Diffstat (limited to 'src/lockmanager')
-rw-r--r--src/lockmanager/Makefile.am26
-rw-r--r--src/lockmanager/Makefile.in283
-rw-r--r--src/lockmanager/gnunet-service-lockmanager.c269
-rw-r--r--src/lockmanager/lockmanager.conf.in1
-rw-r--r--src/lockmanager/lockmanager_api.c325
-rw-r--r--src/lockmanager/test_lockmanager_api.c171
-rw-r--r--src/lockmanager/test_lockmanager_api.conf8
-rw-r--r--src/lockmanager/test_lockmanager_api_acquireretry.c224
-rw-r--r--src/lockmanager/test_lockmanager_api_lockrelease.c168
-rw-r--r--src/lockmanager/test_lockmanager_api_servercrash.c190
10 files changed, 874 insertions, 791 deletions
diff --git a/src/lockmanager/Makefile.am b/src/lockmanager/Makefile.am
index 0fbc20b..6a41fe5 100644
--- a/src/lockmanager/Makefile.am
+++ b/src/lockmanager/Makefile.am
@@ -11,10 +11,12 @@ endif
pkgcfgdir= $(pkgdatadir)/config.d/
+libexecdir= $(pkglibdir)/libexec/
+
pkgcfg_DATA = \
lockmanager.conf
-bin_PROGRAMS = \
+libexec_PROGRAMS = \
gnunet-service-lockmanager
lib_LTLIBRARIES = \
@@ -32,37 +34,49 @@ libgnunetlockmanager_la_SOURCES = \
lockmanager_api.c lockmanager.h
libgnunetlockmanager_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
- $(XLIB)
+ $(XLIB) \
+ $(LTLIBINTL)
libgnunetlockmanager_la_LDFLAGS = \
$(GN_LIB_LDFLAGS) $(WINFLAGS) \
-version-info 0:0:0
check_PROGRAMS = \
- test-lockmanager-api \
- test-lockmanager-api-lockrelease \
- test-lockmanager-api-servercrash
+ test_lockmanager_api \
+ test_lockmanager_api_lockrelease \
+ test_lockmanager_api_servercrash \
+ test_lockmanager_api_acquireretry
EXTRA_DIST = \
test_lockmanager_api.conf
if ENABLE_TEST_RUN
-TESTS = $(check_PROGRAMS)
+ TESTS = $(check_PROGRAMS)
endif
test_lockmanager_api_SOURCES = \
test_lockmanager_api.c
test_lockmanager_api_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
libgnunetlockmanager.la
test_lockmanager_api_lockrelease_SOURCES = \
test_lockmanager_api_lockrelease.c
test_lockmanager_api_lockrelease_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
libgnunetlockmanager.la
test_lockmanager_api_servercrash_SOURCES = \
test_lockmanager_api_servercrash.c
test_lockmanager_api_servercrash_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ libgnunetlockmanager.la
+
+test_lockmanager_api_acquireretry_SOURCES = \
+ test_lockmanager_api_acquireretry.c
+test_lockmanager_api_acquireretry_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
libgnunetlockmanager.la \ No newline at end of file
diff --git a/src/lockmanager/Makefile.in b/src/lockmanager/Makefile.in
index 6a90407..0c4db3b 100644
--- a/src/lockmanager/Makefile.in
+++ b/src/lockmanager/Makefile.in
@@ -1,9 +1,9 @@
-# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# Makefile.in generated by automake 1.11.6 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
-# Inc.
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
+# Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -18,6 +18,23 @@
VPATH = @srcdir@
+am__make_dryrun = \
+ { \
+ am__dry=no; \
+ case $$MAKEFLAGS in \
+ *\\[\ \ ]*) \
+ echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \
+ | grep '^AM OK$$' >/dev/null || am__dry=yes;; \
+ *) \
+ for am__flg in $$MAKEFLAGS; do \
+ case $$am__flg in \
+ *=*|--*) ;; \
+ *n*) am__dry=yes; break;; \
+ esac; \
+ done;; \
+ esac; \
+ test $$am__dry = yes; \
+ }
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
@@ -37,24 +54,26 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
-bin_PROGRAMS = gnunet-service-lockmanager$(EXEEXT)
-check_PROGRAMS = test-lockmanager-api$(EXEEXT) \
- test-lockmanager-api-lockrelease$(EXEEXT) \
- test-lockmanager-api-servercrash$(EXEEXT)
+libexec_PROGRAMS = gnunet-service-lockmanager$(EXEEXT)
+check_PROGRAMS = test_lockmanager_api$(EXEEXT) \
+ test_lockmanager_api_lockrelease$(EXEEXT) \
+ test_lockmanager_api_servercrash$(EXEEXT) \
+ test_lockmanager_api_acquireretry$(EXEEXT)
subdir = src/lockmanager
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/lockmanager.conf.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/absolute-header.m4 \
$(top_srcdir)/m4/align.m4 $(top_srcdir)/m4/argz.m4 \
- $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/iconv.m4 \
- $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \
- $(top_srcdir)/m4/lib-prefix.m4 $(top_srcdir)/m4/libcurl.m4 \
- $(top_srcdir)/m4/libgcrypt.m4 $(top_srcdir)/m4/libtool.m4 \
- $(top_srcdir)/m4/libunistring.m4 $(top_srcdir)/m4/ltdl.m4 \
- $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
- $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
- $(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/po.m4 \
+ $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/glib-2.0.m4 \
+ $(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/lib-ld.m4 \
+ $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
+ $(top_srcdir)/m4/libcurl.m4 $(top_srcdir)/m4/libgcrypt.m4 \
+ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/libunistring.m4 \
+ $(top_srcdir)/m4/ltdl.m4 $(top_srcdir)/m4/ltoptions.m4 \
+ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+ $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \
+ $(top_srcdir)/m4/pkg.m4 $(top_srcdir)/m4/po.m4 \
$(top_srcdir)/m4/progtest.m4 $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
@@ -84,24 +103,30 @@ am__nobase_list = $(am__nobase_strip_setup); \
am__base_list = \
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
-am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \
+am__uninstall_files_from_dir = { \
+ test -z "$$files" \
+ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+ $(am__cd) "$$dir" && rm -f $$files; }; \
+ }
+am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(libexecdir)" \
"$(DESTDIR)$(pkgcfgdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 =
libgnunetlockmanager_la_DEPENDENCIES = \
$(top_builddir)/src/util/libgnunetutil.la \
- $(am__DEPENDENCIES_1)
+ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am_libgnunetlockmanager_la_OBJECTS = lockmanager_api.lo
libgnunetlockmanager_la_OBJECTS = \
$(am_libgnunetlockmanager_la_OBJECTS)
-AM_V_lt = $(am__v_lt_$(V))
-am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
libgnunetlockmanager_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
$(AM_CFLAGS) $(CFLAGS) $(libgnunetlockmanager_la_LDFLAGS) \
$(LDFLAGS) -o $@
-PROGRAMS = $(bin_PROGRAMS)
+PROGRAMS = $(libexec_PROGRAMS)
am_gnunet_service_lockmanager_OBJECTS = \
gnunet-service-lockmanager.$(OBJEXT)
gnunet_service_lockmanager_OBJECTS = \
@@ -110,6 +135,15 @@ am_test_lockmanager_api_OBJECTS = test_lockmanager_api.$(OBJEXT)
test_lockmanager_api_OBJECTS = $(am_test_lockmanager_api_OBJECTS)
test_lockmanager_api_DEPENDENCIES = \
$(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ libgnunetlockmanager.la
+am_test_lockmanager_api_acquireretry_OBJECTS = \
+ test_lockmanager_api_acquireretry.$(OBJEXT)
+test_lockmanager_api_acquireretry_OBJECTS = \
+ $(am_test_lockmanager_api_acquireretry_OBJECTS)
+test_lockmanager_api_acquireretry_DEPENDENCIES = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
libgnunetlockmanager.la
am_test_lockmanager_api_lockrelease_OBJECTS = \
test_lockmanager_api_lockrelease.$(OBJEXT)
@@ -117,6 +151,7 @@ test_lockmanager_api_lockrelease_OBJECTS = \
$(am_test_lockmanager_api_lockrelease_OBJECTS)
test_lockmanager_api_lockrelease_DEPENDENCIES = \
$(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
libgnunetlockmanager.la
am_test_lockmanager_api_servercrash_OBJECTS = \
test_lockmanager_api_servercrash.$(OBJEXT)
@@ -124,6 +159,7 @@ test_lockmanager_api_servercrash_OBJECTS = \
$(am_test_lockmanager_api_servercrash_OBJECTS)
test_lockmanager_api_servercrash_DEPENDENCIES = \
$(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
libgnunetlockmanager.la
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -135,32 +171,39 @@ LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
-AM_V_CC = $(am__v_CC_$(V))
-am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY))
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
am__v_CC_0 = @echo " CC " $@;
-AM_V_at = $(am__v_at_$(V))
-am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
am__v_at_0 = @
CCLD = $(CC)
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
-AM_V_CCLD = $(am__v_CCLD_$(V))
-am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY))
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
-AM_V_GEN = $(am__v_GEN_$(V))
-am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
am__v_GEN_0 = @echo " GEN " $@;
SOURCES = $(libgnunetlockmanager_la_SOURCES) \
$(gnunet_service_lockmanager_SOURCES) \
$(test_lockmanager_api_SOURCES) \
+ $(test_lockmanager_api_acquireretry_SOURCES) \
$(test_lockmanager_api_lockrelease_SOURCES) \
$(test_lockmanager_api_servercrash_SOURCES)
DIST_SOURCES = $(libgnunetlockmanager_la_SOURCES) \
$(gnunet_service_lockmanager_SOURCES) \
$(test_lockmanager_api_SOURCES) \
+ $(test_lockmanager_api_acquireretry_SOURCES) \
$(test_lockmanager_api_lockrelease_SOURCES) \
$(test_lockmanager_api_servercrash_SOURCES)
+am__can_run_installinfo = \
+ case $$AM_UPDATE_INFO_DIR in \
+ n|no|NO) false;; \
+ *) (install-info --version) >/dev/null 2>&1;; \
+ esac
DATA = $(pkgcfg_DATA)
ETAGS = etags
CTAGS = ctags
@@ -202,6 +245,10 @@ EXEEXT = @EXEEXT@
EXT_LIBS = @EXT_LIBS@
EXT_LIB_PATH = @EXT_LIB_PATH@
FGREP = @FGREP@
+GLIB_CFLAGS = @GLIB_CFLAGS@
+GLIB_GENMARSHAL = @GLIB_GENMARSHAL@
+GLIB_LIBS = @GLIB_LIBS@
+GLIB_MKENUMS = @GLIB_MKENUMS@
GMSGFMT = @GMSGFMT@
GMSGFMT_015 = @GMSGFMT_015@
GNUNETDNS_GROUP = @GNUNETDNS_GROUP@
@@ -212,6 +259,7 @@ GN_LIBINTL = @GN_LIBINTL@
GN_LIB_LDFLAGS = @GN_LIB_LDFLAGS@
GN_PLUGIN_LDFLAGS = @GN_PLUGIN_LDFLAGS@
GN_USER_HOME_DIR = @GN_USER_HOME_DIR@
+GOBJECT_QUERY = @GOBJECT_QUERY@
GREP = @GREP@
HAVE_LIBUNISTRING = @HAVE_LIBUNISTRING@
INCLTDL = @INCLTDL@
@@ -234,6 +282,8 @@ LIBCURL_CPPFLAGS = @LIBCURL_CPPFLAGS@
LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@
LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@
LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@
+LIBGTOP_CFLAGS = @LIBGTOP_CFLAGS@
+LIBGTOP_LIBS = @LIBGTOP_LIBS@
LIBICONV = @LIBICONV@
LIBINTL = @LIBINTL@
LIBLTDL = @LIBLTDL@
@@ -255,6 +305,7 @@ LT_CONFIG_H = @LT_CONFIG_H@
LT_DLLOADERS = @LT_DLLOADERS@
LT_DLPREOPEN = @LT_DLPREOPEN@
MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
MONKEYPREFIX = @MONKEYPREFIX@
MSGFMT = @MSGFMT@
@@ -264,6 +315,7 @@ MYSQL_CPPFLAGS = @MYSQL_CPPFLAGS@
MYSQL_LDFLAGS = @MYSQL_LDFLAGS@
NM = @NM@
NMEDIT = @NMEDIT@
+NSS_DIR = @NSS_DIR@
OBJC = @OBJC@
OBJCDEPMODE = @OBJCDEPMODE@
OBJCFLAGS = @OBJCFLAGS@
@@ -279,6 +331,7 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
POSTGRES_CPPFLAGS = @POSTGRES_CPPFLAGS@
POSTGRES_LDFLAGS = @POSTGRES_LDFLAGS@
POSUB = @POSUB@
@@ -310,6 +363,7 @@ abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
@@ -332,6 +386,7 @@ datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
+gitcommand = @gitcommand@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
@@ -342,10 +397,9 @@ includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
-libexecdir = @libexecdir@
+libexecdir = $(pkglibdir)/libexec/
localedir = @localedir@
localstatedir = @localstatedir@
-lt_ECHO = @lt_ECHO@
ltdl_LIBOBJS = @ltdl_LIBOBJS@
ltdl_LTLIBOBJS = @ltdl_LTLIBOBJS@
mandir = @mandir@
@@ -363,6 +417,7 @@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
subdirs = @subdirs@
+svnversioncommand = @svnversioncommand@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target = @target@
@@ -399,7 +454,8 @@ libgnunetlockmanager_la_SOURCES = \
libgnunetlockmanager_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
- $(XLIB)
+ $(XLIB) \
+ $(LTLIBINTL)
libgnunetlockmanager_la_LDFLAGS = \
$(GN_LIB_LDFLAGS) $(WINFLAGS) \
@@ -414,6 +470,7 @@ test_lockmanager_api_SOURCES = \
test_lockmanager_api_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
libgnunetlockmanager.la
test_lockmanager_api_lockrelease_SOURCES = \
@@ -421,6 +478,7 @@ test_lockmanager_api_lockrelease_SOURCES = \
test_lockmanager_api_lockrelease_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
libgnunetlockmanager.la
test_lockmanager_api_servercrash_SOURCES = \
@@ -428,6 +486,15 @@ test_lockmanager_api_servercrash_SOURCES = \
test_lockmanager_api_servercrash_LDADD = \
$(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ libgnunetlockmanager.la
+
+test_lockmanager_api_acquireretry_SOURCES = \
+ test_lockmanager_api_acquireretry.c
+
+test_lockmanager_api_acquireretry_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
libgnunetlockmanager.la
all: all-am
@@ -468,7 +535,6 @@ lockmanager.conf: $(top_builddir)/config.status $(srcdir)/lockmanager.conf.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
@$(NORMAL_INSTALL)
- test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)"
@list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
list2=; for p in $$list; do \
if test -f $$p; then \
@@ -476,6 +542,8 @@ install-libLTLIBRARIES: $(lib_LTLIBRARIES)
else :; fi; \
done; \
test -z "$$list2" || { \
+ echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \
echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
}
@@ -497,12 +565,24 @@ clean-libLTLIBRARIES:
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
-libgnunetlockmanager.la: $(libgnunetlockmanager_la_OBJECTS) $(libgnunetlockmanager_la_DEPENDENCIES)
+libgnunetlockmanager.la: $(libgnunetlockmanager_la_OBJECTS) $(libgnunetlockmanager_la_DEPENDENCIES) $(EXTRA_libgnunetlockmanager_la_DEPENDENCIES)
$(AM_V_CCLD)$(libgnunetlockmanager_la_LINK) -rpath $(libdir) $(libgnunetlockmanager_la_OBJECTS) $(libgnunetlockmanager_la_LIBADD) $(LIBS)
-install-binPROGRAMS: $(bin_PROGRAMS)
+
+clean-checkPROGRAMS:
+ @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \
+ echo " rm -f" $$list; \
+ rm -f $$list || exit $$?; \
+ test -n "$(EXEEXT)" || exit 0; \
+ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f" $$list; \
+ rm -f $$list
+install-libexecPROGRAMS: $(libexec_PROGRAMS)
@$(NORMAL_INSTALL)
- test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
- @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+ @list='$(libexec_PROGRAMS)'; test -n "$(libexecdir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(libexecdir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(libexecdir)" || exit 1; \
+ fi; \
for p in $$list; do echo "$$p $$p"; done | \
sed 's/$(EXEEXT)$$//' | \
while read p p1; do if test -f $$p || test -f $$p1; \
@@ -519,49 +599,43 @@ install-binPROGRAMS: $(bin_PROGRAMS)
while read type dir files; do \
if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
test -z "$$files" || { \
- echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \
- $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \
+ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(libexecdir)$$dir'"; \
+ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(libexecdir)$$dir" || exit $$?; \
} \
; done
-uninstall-binPROGRAMS:
+uninstall-libexecPROGRAMS:
@$(NORMAL_UNINSTALL)
- @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+ @list='$(libexec_PROGRAMS)'; test -n "$(libexecdir)" || list=; \
files=`for p in $$list; do echo "$$p"; done | \
sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
-e 's/$$/$(EXEEXT)/' `; \
test -n "$$list" || exit 0; \
- echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
- cd "$(DESTDIR)$(bindir)" && rm -f $$files
-
-clean-binPROGRAMS:
- @list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \
- echo " rm -f" $$list; \
- rm -f $$list || exit $$?; \
- test -n "$(EXEEXT)" || exit 0; \
- list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
- echo " rm -f" $$list; \
- rm -f $$list
+ echo " ( cd '$(DESTDIR)$(libexecdir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(libexecdir)" && rm -f $$files
-clean-checkPROGRAMS:
- @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \
+clean-libexecPROGRAMS:
+ @list='$(libexec_PROGRAMS)'; test -n "$$list" || exit 0; \
echo " rm -f" $$list; \
rm -f $$list || exit $$?; \
test -n "$(EXEEXT)" || exit 0; \
list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
echo " rm -f" $$list; \
rm -f $$list
-gnunet-service-lockmanager$(EXEEXT): $(gnunet_service_lockmanager_OBJECTS) $(gnunet_service_lockmanager_DEPENDENCIES)
+gnunet-service-lockmanager$(EXEEXT): $(gnunet_service_lockmanager_OBJECTS) $(gnunet_service_lockmanager_DEPENDENCIES) $(EXTRA_gnunet_service_lockmanager_DEPENDENCIES)
@rm -f gnunet-service-lockmanager$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(gnunet_service_lockmanager_OBJECTS) $(gnunet_service_lockmanager_LDADD) $(LIBS)
-test-lockmanager-api$(EXEEXT): $(test_lockmanager_api_OBJECTS) $(test_lockmanager_api_DEPENDENCIES)
- @rm -f test-lockmanager-api$(EXEEXT)
+test_lockmanager_api$(EXEEXT): $(test_lockmanager_api_OBJECTS) $(test_lockmanager_api_DEPENDENCIES) $(EXTRA_test_lockmanager_api_DEPENDENCIES)
+ @rm -f test_lockmanager_api$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_lockmanager_api_OBJECTS) $(test_lockmanager_api_LDADD) $(LIBS)
-test-lockmanager-api-lockrelease$(EXEEXT): $(test_lockmanager_api_lockrelease_OBJECTS) $(test_lockmanager_api_lockrelease_DEPENDENCIES)
- @rm -f test-lockmanager-api-lockrelease$(EXEEXT)
+test_lockmanager_api_acquireretry$(EXEEXT): $(test_lockmanager_api_acquireretry_OBJECTS) $(test_lockmanager_api_acquireretry_DEPENDENCIES) $(EXTRA_test_lockmanager_api_acquireretry_DEPENDENCIES)
+ @rm -f test_lockmanager_api_acquireretry$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(test_lockmanager_api_acquireretry_OBJECTS) $(test_lockmanager_api_acquireretry_LDADD) $(LIBS)
+test_lockmanager_api_lockrelease$(EXEEXT): $(test_lockmanager_api_lockrelease_OBJECTS) $(test_lockmanager_api_lockrelease_DEPENDENCIES) $(EXTRA_test_lockmanager_api_lockrelease_DEPENDENCIES)
+ @rm -f test_lockmanager_api_lockrelease$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_lockmanager_api_lockrelease_OBJECTS) $(test_lockmanager_api_lockrelease_LDADD) $(LIBS)
-test-lockmanager-api-servercrash$(EXEEXT): $(test_lockmanager_api_servercrash_OBJECTS) $(test_lockmanager_api_servercrash_DEPENDENCIES)
- @rm -f test-lockmanager-api-servercrash$(EXEEXT)
+test_lockmanager_api_servercrash$(EXEEXT): $(test_lockmanager_api_servercrash_OBJECTS) $(test_lockmanager_api_servercrash_DEPENDENCIES) $(EXTRA_test_lockmanager_api_servercrash_DEPENDENCIES)
+ @rm -f test_lockmanager_api_servercrash$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_lockmanager_api_servercrash_OBJECTS) $(test_lockmanager_api_servercrash_LDADD) $(LIBS)
mostlyclean-compile:
@@ -573,32 +647,30 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnunet-service-lockmanager.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/lockmanager_api.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_lockmanager_api.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_lockmanager_api_acquireretry.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_lockmanager_api_lockrelease.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_lockmanager_api_servercrash.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
.c.obj:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
-@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
-@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
@@ -607,8 +679,11 @@ clean-libtool:
-rm -rf .libs _libs
install-pkgcfgDATA: $(pkgcfg_DATA)
@$(NORMAL_INSTALL)
- test -z "$(pkgcfgdir)" || $(MKDIR_P) "$(DESTDIR)$(pkgcfgdir)"
@list='$(pkgcfg_DATA)'; test -n "$(pkgcfgdir)" || list=; \
+ if test -n "$$list"; then \
+ echo " $(MKDIR_P) '$(DESTDIR)$(pkgcfgdir)'"; \
+ $(MKDIR_P) "$(DESTDIR)$(pkgcfgdir)" || exit 1; \
+ fi; \
for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
echo "$$d$$p"; \
@@ -622,9 +697,7 @@ uninstall-pkgcfgDATA:
@$(NORMAL_UNINSTALL)
@list='$(pkgcfg_DATA)'; test -n "$(pkgcfgdir)" || list=; \
files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
- test -n "$$files" || exit 0; \
- echo " ( cd '$(DESTDIR)$(pkgcfgdir)' && rm -f" $$files ")"; \
- cd "$(DESTDIR)$(pkgcfgdir)" && rm -f $$files
+ dir='$(DESTDIR)$(pkgcfgdir)'; $(am__uninstall_files_from_dir)
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
@@ -759,14 +832,15 @@ check-TESTS: $(TESTS)
fi; \
dashes=`echo "$$dashes" | sed s/./=/g`; \
if test "$$failed" -eq 0; then \
- echo "$$grn$$dashes"; \
+ col="$$grn"; \
else \
- echo "$$red$$dashes"; \
+ col="$$red"; \
fi; \
- echo "$$banner"; \
- test -z "$$skipped" || echo "$$skipped"; \
- test -z "$$report" || echo "$$report"; \
- echo "$$dashes$$std"; \
+ echo "$${col}$$dashes$${std}"; \
+ echo "$${col}$$banner$${std}"; \
+ test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \
+ test -z "$$report" || echo "$${col}$$report$${std}"; \
+ echo "$${col}$$dashes$${std}"; \
test "$$failed" -eq 0; \
else :; fi
@@ -805,10 +879,8 @@ check-am: all-am
$(MAKE) $(AM_MAKEFLAGS) check-TESTS
check: check-am
all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(DATA)
-install-binPROGRAMS: install-libLTLIBRARIES
-
installdirs:
- for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(pkgcfgdir)"; do \
+ for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(libexecdir)" "$(DESTDIR)$(pkgcfgdir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
@@ -821,10 +893,15 @@ install-am: all-am
installcheck: installcheck-am
install-strip:
- $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
- install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
- `test -z '$(STRIP)' || \
- echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+ if test -z '$(STRIP)'; then \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ install; \
+ else \
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+ fi
mostlyclean-generic:
clean-generic:
@@ -838,8 +915,8 @@ maintainer-clean-generic:
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
-clean-am: clean-binPROGRAMS clean-checkPROGRAMS clean-generic \
- clean-libLTLIBRARIES clean-libtool mostlyclean-am
+clean-am: clean-checkPROGRAMS clean-generic clean-libLTLIBRARIES \
+ clean-libexecPROGRAMS clean-libtool mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
@@ -865,7 +942,7 @@ install-dvi: install-dvi-am
install-dvi-am:
-install-exec-am: install-binPROGRAMS install-libLTLIBRARIES
+install-exec-am: install-libLTLIBRARIES install-libexecPROGRAMS
install-html: install-html-am
@@ -905,27 +982,27 @@ ps: ps-am
ps-am:
-uninstall-am: uninstall-binPROGRAMS uninstall-libLTLIBRARIES \
+uninstall-am: uninstall-libLTLIBRARIES uninstall-libexecPROGRAMS \
uninstall-pkgcfgDATA
.MAKE: check-am install-am install-strip
.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \
- clean-binPROGRAMS clean-checkPROGRAMS clean-generic \
- clean-libLTLIBRARIES clean-libtool ctags distclean \
+ clean-checkPROGRAMS clean-generic clean-libLTLIBRARIES \
+ clean-libexecPROGRAMS clean-libtool ctags distclean \
distclean-compile distclean-generic distclean-libtool \
distclean-tags distdir dvi dvi-am html html-am info info-am \
- install install-am install-binPROGRAMS install-data \
- install-data-am install-dvi install-dvi-am install-exec \
- install-exec-am install-html install-html-am install-info \
- install-info-am install-libLTLIBRARIES install-man install-pdf \
- install-pdf-am install-pkgcfgDATA install-ps install-ps-am \
- install-strip installcheck installcheck-am installdirs \
- maintainer-clean maintainer-clean-generic mostlyclean \
- mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
- pdf pdf-am ps ps-am tags uninstall uninstall-am \
- uninstall-binPROGRAMS uninstall-libLTLIBRARIES \
- uninstall-pkgcfgDATA
+ install install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am \
+ install-libLTLIBRARIES install-libexecPROGRAMS install-man \
+ install-pdf install-pdf-am install-pkgcfgDATA install-ps \
+ install-ps-am install-strip installcheck installcheck-am \
+ installdirs maintainer-clean maintainer-clean-generic \
+ mostlyclean mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \
+ uninstall-am uninstall-libLTLIBRARIES \
+ uninstall-libexecPROGRAMS uninstall-pkgcfgDATA
# Tell versions [3.59,3.63) of GNU make to not export all variables.
diff --git a/src/lockmanager/gnunet-service-lockmanager.c b/src/lockmanager/gnunet-service-lockmanager.c
index 8ec9889..e509fc6 100644
--- a/src/lockmanager/gnunet-service-lockmanager.c
+++ b/src/lockmanager/gnunet-service-lockmanager.c
@@ -58,7 +58,7 @@ struct WaitList
* The next client structure
*/
struct WaitList *next;
-
+
/**
* The prev client structure
*/
@@ -204,15 +204,12 @@ static struct ClientList *cl_tail;
* @param key set to the key
*/
static void
-get_key (const char *domain_name,
- uint32_t lock_number,
- struct GNUNET_HashCode *key)
+get_key (const char *domain_name, uint32_t lock_number,
+ struct GNUNET_HashCode *key)
{
uint32_t *last_32;
- GNUNET_CRYPTO_hash (domain_name,
- strlen (domain_name),
- key);
+ GNUNET_CRYPTO_hash (domain_name, strlen (domain_name), key);
last_32 = (uint32_t *) key;
*last_32 ^= lock_number;
}
@@ -226,18 +223,18 @@ get_key (const char *domain_name,
* @param value value in the hash map (struct Lock)
* @return GNUNET_YES if we should continue to
* iterate,
- * GNUNET_NO if not.
+ * GNUNET_NO if not.
*/
static int
-match_iterator (void *cls, const GNUNET_HashCode *key, void *value)
+match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct LockMatch *match = cls;
struct Lock *lock = value;
- if ( (match->lock_num == lock->lock_num)
- && (0 == strcmp (match->domain_name, lock->domain_name)) )
+ if ((match->lock_num == lock->lock_num) &&
+ (0 == strcmp (match->domain_name, lock->domain_name)))
{
- match->matched_entry = lock;
+ match->matched_entry = lock;
return GNUNET_NO;
}
return GNUNET_YES;
@@ -252,9 +249,7 @@ match_iterator (void *cls, const GNUNET_HashCode *key, void *value)
* @return the lock if found; NULL if not
*/
static struct Lock *
-find_lock (const char *domain_name,
- const uint32_t lock_num)
-
+find_lock (const char *domain_name, const uint32_t lock_num)
{
struct LockMatch match;
struct GNUNET_HashCode key;
@@ -263,9 +258,7 @@ find_lock (const char *domain_name,
match.domain_name = domain_name;
match.matched_entry = NULL;
get_key (domain_name, lock_num, &key);
- GNUNET_CONTAINER_multihashmap_get_multiple (lock_map,
- &key,
- &match_iterator,
+ GNUNET_CONTAINER_multihashmap_get_multiple (lock_map, &key, &match_iterator,
&match);
return match.matched_entry;
}
@@ -279,8 +272,7 @@ find_lock (const char *domain_name,
* @return pointer to the lock structure which is added to lock map
*/
static struct Lock *
-add_lock (const char *domain_name,
- uint32_t lock_num)
+add_lock (const char *domain_name, uint32_t lock_num)
{
struct Lock *lock;
struct GNUNET_HashCode key;
@@ -295,9 +287,7 @@ add_lock (const char *domain_name,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Adding a lock with num: %d and domain: %s to the lock map\n",
lock->lock_num, lock->domain_name);
- GNUNET_CONTAINER_multihashmap_put (lock_map,
- &key,
- lock,
+ GNUNET_CONTAINER_multihashmap_put (lock_map, &key, lock,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
return lock;
}
@@ -312,16 +302,14 @@ static void
remove_lock (struct Lock *lock)
{
struct GNUNET_HashCode key;
-
+
GNUNET_assert (NULL == lock->wl_head);
- get_key (lock->domain_name,
- lock->lock_num,
- &key);
+ get_key (lock->domain_name, lock->lock_num, &key);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Removing lock with num: %u, domain: %s from lock map\n",
- lock->lock_num, lock->domain_name);
- GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove
- (lock_map, &key, lock));
+ "Removing lock with num: %u, domain: %s from lock map\n", lock->lock_num,
+ lock->domain_name);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (lock_map, &key, lock));
GNUNET_free (lock->domain_name);
GNUNET_free (lock);
}
@@ -336,13 +324,12 @@ remove_lock (struct Lock *lock)
* @return the matching LockList entry; NULL if no match is found
*/
static struct LockList *
-cl_ll_find_lock (struct ClientList *cl_entry,
- const struct Lock *lock)
+cl_ll_find_lock (struct ClientList *cl_entry, const struct Lock *lock)
{
struct LockList *ll_entry;
- for (ll_entry = cl_entry->ll_head;
- NULL != ll_entry; ll_entry = ll_entry->next)
+ for (ll_entry = cl_entry->ll_head; NULL != ll_entry;
+ ll_entry = ll_entry->next)
{
if (lock == ll_entry->lock)
return ll_entry;
@@ -358,8 +345,7 @@ cl_ll_find_lock (struct ClientList *cl_entry,
* @param lock the lock to be added to the cl_entry's lock list
*/
static void
-cl_ll_add_lock (struct ClientList *cl_entry,
- struct Lock *lock)
+cl_ll_add_lock (struct ClientList *cl_entry, struct Lock *lock)
{
struct LockList *ll_entry;
@@ -368,8 +354,7 @@ cl_ll_add_lock (struct ClientList *cl_entry,
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Adding a lock with num: %u and domain: %s to lock list\n",
lock->lock_num, lock->domain_name);
- GNUNET_CONTAINER_DLL_insert_tail (cl_entry->ll_head,
- cl_entry->ll_tail,
+ GNUNET_CONTAINER_DLL_insert_tail (cl_entry->ll_head, cl_entry->ll_tail,
ll_entry);
}
@@ -381,17 +366,13 @@ cl_ll_add_lock (struct ClientList *cl_entry,
* @param ll_entry the LockList entry to be deleted
*/
static void
-cl_ll_remove_lock (struct ClientList *cl_entry,
- struct LockList *ll_entry)
+cl_ll_remove_lock (struct ClientList *cl_entry, struct LockList *ll_entry)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Removing lock with num: %u, domain: %s from lock list of a client\n",
- ll_entry->lock->lock_num,
- ll_entry->lock->domain_name);
+ ll_entry->lock->lock_num, ll_entry->lock->domain_name);
GNUNET_assert (NULL != cl_entry->ll_head);
- GNUNET_CONTAINER_DLL_remove (cl_entry->ll_head,
- cl_entry->ll_tail,
- ll_entry);
+ GNUNET_CONTAINER_DLL_remove (cl_entry->ll_head, cl_entry->ll_tail, ll_entry);
GNUNET_free (ll_entry);
}
@@ -405,14 +386,11 @@ cl_ll_remove_lock (struct ClientList *cl_entry,
* was found
*/
static struct WaitList *
-lock_wl_find (const struct Lock *lock,
- const struct ClientList *cl_entry)
+lock_wl_find (const struct Lock *lock, const struct ClientList *cl_entry)
{
struct WaitList *wl_entry;
- for (wl_entry = lock->wl_head;
- NULL != wl_entry;
- wl_entry = wl_entry->next)
+ for (wl_entry = lock->wl_head; NULL != wl_entry; wl_entry = wl_entry->next)
{
if (cl_entry == wl_entry->cl_entry)
return wl_entry;
@@ -428,20 +406,16 @@ lock_wl_find (const struct Lock *lock,
* @param cl_entry the client to queue for the lock's wait list
*/
static void
-lock_wl_add_client (struct Lock *lock,
- struct ClientList *cl_entry)
+lock_wl_add_client (struct Lock *lock, struct ClientList *cl_entry)
{
struct WaitList *wl_entry;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Adding a client to lock's wait list (lock num: %u, domain: %s)\n",
- lock->lock_num,
- lock->domain_name);
+ lock->lock_num, lock->domain_name);
wl_entry = GNUNET_malloc (sizeof (struct WaitList));
wl_entry->cl_entry = cl_entry;
- GNUNET_CONTAINER_DLL_insert_tail (lock->wl_head,
- lock->wl_tail,
- wl_entry);
+ GNUNET_CONTAINER_DLL_insert_tail (lock->wl_head, lock->wl_tail, wl_entry);
}
@@ -452,15 +426,12 @@ lock_wl_add_client (struct Lock *lock,
* @param wl_entry the wait list entry to be removed
*/
static void
-lock_wl_remove (struct Lock *lock,
- struct WaitList *wl_entry)
+lock_wl_remove (struct Lock *lock, struct WaitList *wl_entry)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Removing client from wait list of lock with num: %u, domain: %s\n",
lock->lock_num, lock->domain_name);
- GNUNET_CONTAINER_DLL_remove (lock->wl_head,
- lock->wl_tail,
- wl_entry);
+ GNUNET_CONTAINER_DLL_remove (lock->wl_head, lock->wl_tail, wl_entry);
GNUNET_free (wl_entry);
}
@@ -472,7 +443,7 @@ lock_wl_remove (struct Lock *lock,
* @return the ClientList entry; NULL if the client is not found
*/
static struct ClientList *
-cl_find_client (const struct GNUNET_SERVER_Client *client)
+cl_find_client (const struct GNUNET_SERVER_Client *client)
{
struct ClientList *current;
@@ -493,15 +464,12 @@ static struct ClientList *
cl_add_client (struct GNUNET_SERVER_Client *client)
{
struct ClientList *new_client;
-
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding a client to the client list\n");
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding a client to the client list\n");
new_client = GNUNET_malloc (sizeof (struct ClientList));
GNUNET_SERVER_client_keep (client);
new_client->client = client;
- GNUNET_CONTAINER_DLL_insert_tail (cl_head,
- cl_tail,
- new_client);
+ GNUNET_CONTAINER_DLL_insert_tail (cl_head, cl_tail, new_client);
return new_client;
}
@@ -515,12 +483,9 @@ static void
cl_remove_client (struct ClientList *cl_entry)
{
GNUNET_assert (NULL == cl_entry->ll_head);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Removing a client from the client list\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Removing a client from the client list\n");
GNUNET_SERVER_client_drop (cl_entry->client);
- GNUNET_CONTAINER_DLL_remove (cl_head,
- cl_tail,
- cl_entry);
+ GNUNET_CONTAINER_DLL_remove (cl_head, cl_tail, cl_entry);
GNUNET_free (cl_entry);
}
@@ -533,7 +498,7 @@ cl_remove_client (struct ClientList *cl_entry)
* @param buf where the callee should write the message
* @return number of bytes written to buf
*/
-static size_t
+static size_t
transmit_notify (void *cls, size_t size, void *buf)
{
struct GNUNET_LOCKMANAGER_Message *msg = cls;
@@ -548,8 +513,7 @@ transmit_notify (void *cls, size_t size, void *buf)
GNUNET_assert (size >= msg_size);
memcpy (buf, msg, msg_size);
GNUNET_free (msg);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Message of size %u sent\n", msg_size);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Message of size %u sent\n", msg_size);
return msg_size;
}
@@ -562,8 +526,7 @@ transmit_notify (void *cls, size_t size, void *buf)
* @param lock_num the number of the successfully acquired lock
*/
static void
-send_success_msg (struct GNUNET_SERVER_Client *client,
- const char *domain_name,
+send_success_msg (struct GNUNET_SERVER_Client *client, const char *domain_name,
int lock_num)
{
struct GNUNET_LOCKMANAGER_Message *reply;
@@ -578,13 +541,10 @@ send_success_msg (struct GNUNET_SERVER_Client *client,
reply->lock = htonl (lock_num);
strncpy ((char *) &reply[1], domain_name, domain_name_len);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Sending SUCCESS message for lock with num: %u, domain: %s\n",
- lock_num, domain_name);
- GNUNET_SERVER_notify_transmit_ready (client,
- reply_size,
- TIMEOUT,
- &transmit_notify,
- reply);
+ "Sending SUCCESS message for lock with num: %u, domain: %s\n", lock_num,
+ domain_name);
+ GNUNET_SERVER_notify_transmit_ready (client, reply_size, TIMEOUT,
+ &transmit_notify, reply);
}
@@ -596,8 +556,7 @@ send_success_msg (struct GNUNET_SERVER_Client *client,
* @param message GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE message
*/
static void
-handle_acquire (void *cls,
- struct GNUNET_SERVER_Client *client,
+handle_acquire (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_LOCKMANAGER_Message *request;
@@ -617,23 +576,26 @@ handle_acquire (void *cls,
request = (struct GNUNET_LOCKMANAGER_Message *) message;
domain_name = (const char *) &request[1];
msize -= sizeof (struct GNUNET_LOCKMANAGER_Message);
- if ('\0' != domain_name[msize])
+ if ('\0' != domain_name[msize - 1])
{
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Bad domain `%.*s' - byte with index %u is %X, not 0.\n", msize,
+ domain_name, msize - 1, (unsigned int) domain_name[msize - 1]);
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
lock_num = ntohl (request->lock);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received an ACQUIRE message for lock num: %u domain: %s\n",
- lock_num, domain_name);
- if (NULL == (cl_entry = cl_find_client (client)))
- cl_entry = cl_add_client (client); /* Add client if not in client list */
- if (NULL != (lock = find_lock (domain_name,lock_num)))
+ "Received an ACQUIRE message for lock num: %u domain: %s\n", lock_num,
+ domain_name);
+ if (NULL == (cl_entry = cl_find_client (client)))
+ cl_entry = cl_add_client (client); /* Add client if not in client list */
+ if (NULL != (lock = find_lock (domain_name, lock_num)))
{
if (lock->cl_entry == cl_entry)
- { /* Client is requesting a lock it already owns */
- GNUNET_break (0);
+ { /* Client is requesting a lock it already owns */
+ GNUNET_break_op (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
@@ -669,17 +631,13 @@ process_lock_release (struct Lock *lock)
wl_entry = lock->wl_head;
if (NULL == wl_entry)
{
- remove_lock (lock); /* No clients waiting for this lock - delete */
+ remove_lock (lock); /* No clients waiting for this lock - delete */
return;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Giving lock to a client from wait list\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving lock to a client from wait list\n");
lock->cl_entry = wl_entry->cl_entry;
- lock_wl_remove(lock, wl_entry);
- send_success_msg (lock->cl_entry->client,
- lock->domain_name,
- lock->lock_num);
- return;
+ lock_wl_remove (lock, wl_entry);
+ send_success_msg (lock->cl_entry->client, lock->domain_name, lock->lock_num);
}
@@ -691,8 +649,7 @@ process_lock_release (struct Lock *lock)
* @param message the LOCKMANAGER_RELEASE message
*/
static void
-handle_release (void *cls,
- struct GNUNET_SERVER_Client *client,
+handle_release (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
const struct GNUNET_LOCKMANAGER_Message *request;
@@ -706,7 +663,7 @@ handle_release (void *cls,
msize = ntohs (message->size);
if (msize <= sizeof (struct GNUNET_LOCKMANAGER_Message))
- {
+ {
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
@@ -714,27 +671,27 @@ handle_release (void *cls,
request = (const struct GNUNET_LOCKMANAGER_Message *) message;
domain_name = (const char *) &request[1];
msize -= sizeof (struct GNUNET_LOCKMANAGER_Message);
- if ('\0' != domain_name[msize-1])
+ if ('\0' != domain_name[msize - 1])
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
-
+
}
lock_num = ntohl (request->lock);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received RELEASE message for lock with num: %d, domain: %s\n",
- lock_num, domain_name);
+ "Received RELEASE message for lock with num: %d, domain: %s\n", lock_num,
+ domain_name);
if (NULL == (cl_entry = cl_find_client (client)))
{
- GNUNET_break(0);
+ GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
lock = find_lock (domain_name, lock_num);
- if(NULL == lock)
- {
+ if (NULL == lock)
+ {
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
@@ -773,11 +730,12 @@ client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
struct ClientList *cl_entry;
struct LockList *ll_entry;
struct Lock *lock;
+ struct WaitList *wl_entry;
if (NULL == client)
return;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "A client has been disconnected -- freeing its locks and resources\n");
+ "A client has been disconnected -- freeing its locks and resources\n");
cl_entry = cl_find_client (client);
if (NULL == cl_entry)
return;
@@ -785,7 +743,14 @@ client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
{
lock = ll_entry->lock;
cl_ll_remove_lock (cl_entry, ll_entry);
- process_lock_release (lock);
+ if (lock->cl_entry == cl_entry)
+ process_lock_release (lock);
+ else
+ {
+ wl_entry = lock_wl_find (lock, cl_entry);
+ GNUNET_assert (NULL != wl_entry);
+ lock_wl_remove (lock, wl_entry);
+ }
}
cl_remove_client (cl_entry);
}
@@ -801,10 +766,8 @@ client_disconnect_cb (void *cls, struct GNUNET_SERVER_Client *client)
* iterate,
* GNUNET_NO if not.
*/
-static int
-lock_delete_iterator (void *cls,
- const GNUNET_HashCode * key,
- void *value)
+static int
+lock_delete_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct Lock *lock = value;
@@ -813,10 +776,8 @@ lock_delete_iterator (void *cls,
{
lock_wl_remove (lock, lock->wl_head);
}
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove(lock_map,
- key,
- lock));
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (lock_map, key, lock));
GNUNET_free (lock->domain_name);
GNUNET_free (lock);
return GNUNET_YES;
@@ -830,26 +791,23 @@ lock_delete_iterator (void *cls,
* @param tc the TaskContext from scheduler
*/
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Shutting down lock manager\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down lock manager\n");
/* Clean the global ClientList */
while (NULL != cl_head)
{
- while (NULL != cl_head->ll_head) /* Clear the LockList */
+ while (NULL != cl_head->ll_head) /* Clear the LockList */
{
cl_ll_remove_lock (cl_head, cl_head->ll_head);
}
cl_remove_client (cl_head);
}
/* Clean the global hash table */
- GNUNET_CONTAINER_multihashmap_iterate (lock_map,
- &lock_delete_iterator,
- NULL);
+ GNUNET_CONTAINER_multihashmap_iterate (lock_map, &lock_delete_iterator, NULL);
GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (lock_map));
GNUNET_CONTAINER_multihashmap_destroy (lock_map);
+ lock_map = NULL;
}
@@ -860,25 +818,19 @@ shutdown_task (void *cls,
* @param server the initialized server
* @param cfg configuration to use
*/
-static void
-lockmanager_run (void *cls,
- struct GNUNET_SERVER_Handle * server,
+static void
+lockmanager_run (void *cls, struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- static const struct GNUNET_SERVER_MessageHandler message_handlers[] =
- {
- {&handle_acquire, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE, 0},
- {&handle_release, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE, 0},
- {NULL}
- };
- GNUNET_SERVER_add_handlers (server,
- message_handlers);
- GNUNET_SERVER_disconnect_notify (server,
- &client_disconnect_cb,
- NULL);
- lock_map = GNUNET_CONTAINER_multihashmap_create (30);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task,
+ static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
+ {&handle_acquire, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE, 0},
+ {&handle_release, NULL, GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE, 0},
+ {NULL}
+ };
+ GNUNET_SERVER_add_handlers (server, message_handlers);
+ GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
+ lock_map = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
NULL);
}
@@ -886,14 +838,13 @@ lockmanager_run (void *cls,
/**
* The starting point of execution
*/
-int main (int argc, char *const *argv)
+int
+main (int argc, char *const *argv)
{
- return
- (GNUNET_OK ==
- GNUNET_SERVICE_run (argc,
- argv,
- "lockmanager",
- GNUNET_SERVICE_OPTION_NONE,
- &lockmanager_run,
- NULL)) ? 0 : 1;
+ return (GNUNET_OK ==
+ GNUNET_SERVICE_run (argc, argv, "lockmanager",
+ GNUNET_SERVICE_OPTION_NONE, &lockmanager_run,
+ NULL)) ? 0 : 1;
}
+
+/* end of gnunet-service-lockmanager.c */
diff --git a/src/lockmanager/lockmanager.conf.in b/src/lockmanager/lockmanager.conf.in
index 75b9244..42d5743 100644
--- a/src/lockmanager/lockmanager.conf.in
+++ b/src/lockmanager/lockmanager.conf.in
@@ -3,7 +3,6 @@ AUTOSTART = YES
@UNIXONLY@ PORT = 2100
HOSTNAME = localhost
HOME = $SERVICEHOME
-CONFIG = $DEFAULTCONFIG
BINARY = gnunet-service-lockmanager
ACCEPT_FROM = 127.0.0.1;
ACCEPT_FROM6 = ::1;
diff --git a/src/lockmanager/lockmanager_api.c b/src/lockmanager/lockmanager_api.c
index 99f5ab5..3b9e70e 100644
--- a/src/lockmanager/lockmanager_api.c
+++ b/src/lockmanager/lockmanager_api.c
@@ -24,11 +24,6 @@
* @author Sree Harsha Totakura
*/
-/**
- * To be fixed:
- * Should the handle be freed when the connection to service is lost?
- * Should cancel_request have a call back (else simultaneous calls break)
- */
#include "platform.h"
#include "gnunet_common.h"
@@ -63,11 +58,17 @@ struct MessageQueue
* The prev pointer for doubly linked list
*/
struct MessageQueue *prev;
-
+
/**
* The LOCKMANAGER Message
*/
struct GNUNET_LOCKMANAGER_Message *msg;
+
+ /**
+ * If this is a AQUIRE_LOCK message, this is the
+ * affiliated locking request.
+ */
+ struct GNUNET_LOCKMANAGER_LockingRequest *lr;
};
@@ -100,6 +101,11 @@ struct GNUNET_LOCKMANAGER_Handle
* Double linked list tail for message queue
*/
struct MessageQueue *mq_tail;
+
+ /**
+ * Are we currently handling replies?
+ */
+ int in_replies;
};
@@ -119,6 +125,12 @@ struct GNUNET_LOCKMANAGER_LockingRequest
GNUNET_LOCKMANAGER_StatusCallback status_cb;
/**
+ * Entry in the request message queue for aquiring this
+ * lock; NULL after request has been sent.
+ */
+ struct MessageQueue *mqe;
+
+ /**
* Closure for the status callback
*/
void *status_cb_cls;
@@ -127,7 +139,7 @@ struct GNUNET_LOCKMANAGER_LockingRequest
* The locking domain of this request
*/
char *domain;
-
+
/**
* The lock
*/
@@ -137,6 +149,11 @@ struct GNUNET_LOCKMANAGER_LockingRequest
* The status of the lock
*/
enum GNUNET_LOCKMANAGER_Status status;
+
+ /**
+ * set to GNUNET_YES if acquire message for this lock is till in messga queue
+ */
+ int acquire_sent;
};
@@ -163,6 +180,16 @@ struct LockingRequestMatch
/**
+ * Handler for server replies
+ *
+ * @param cls the LOCKMANAGER_Handle
+ * @param msg received message, NULL on timeout or fatal error
+ */
+static void
+handle_replies (void *cls, const struct GNUNET_MessageHeader *msg);
+
+
+/**
* Transmit notify for sending message to server
*
* @param cls the lockmanager handle
@@ -170,7 +197,7 @@ struct LockingRequestMatch
* @param buf where the callee should write the message
* @return number of bytes written to buf
*/
-static size_t
+static size_t
transmit_notify (void *cls, size_t size, void *buf)
{
struct GNUNET_LOCKMANAGER_Handle *handle = cls;
@@ -178,34 +205,48 @@ transmit_notify (void *cls, size_t size, void *buf)
uint16_t msg_size;
handle->transmit_handle = NULL;
+ queue_entity = handle->mq_head;
+ GNUNET_assert (NULL != queue_entity);
if ((0 == size) || (NULL == buf))
{
- /* FIXME: Timed out -- requeue? */
+ handle->transmit_handle =
+ GNUNET_CLIENT_notify_transmit_ready (handle->conn,
+ ntohs (queue_entity->msg->
+ header.size),
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES, &transmit_notify,
+ handle);
return 0;
}
- queue_entity = handle->mq_head;
- GNUNET_assert (NULL != queue_entity);
msg_size = ntohs (queue_entity->msg->header.size);
GNUNET_assert (size >= msg_size);
memcpy (buf, queue_entity->msg, msg_size);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Message of size %u sent\n", msg_size);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Message of size %u sent\n", msg_size);
+ if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE ==
+ ntohs (queue_entity->msg->header.type))
+ {
+ GNUNET_break (GNUNET_NO == queue_entity->lr->acquire_sent);
+ queue_entity->lr->acquire_sent = GNUNET_YES;
+ queue_entity->lr->mqe = NULL;
+ }
GNUNET_free (queue_entity->msg);
- GNUNET_CONTAINER_DLL_remove (handle->mq_head,
- handle->mq_tail,
- queue_entity);
+ GNUNET_CONTAINER_DLL_remove (handle->mq_head, handle->mq_tail, queue_entity);
GNUNET_free (queue_entity);
queue_entity = handle->mq_head;
if (NULL != queue_entity)
{
handle->transmit_handle =
- GNUNET_CLIENT_notify_transmit_ready (handle->conn,
- ntohs
- (queue_entity->msg->header.size),
- TIMEOUT,
- GNUNET_YES,
- &transmit_notify,
- handle);
+ GNUNET_CLIENT_notify_transmit_ready (handle->conn,
+ ntohs (queue_entity->msg->
+ header.size), TIMEOUT,
+ GNUNET_YES, &transmit_notify,
+ handle);
+ }
+ if (GNUNET_NO == handle->in_replies)
+ {
+ handle->in_replies = GNUNET_YES;
+ GNUNET_CLIENT_receive (handle->conn, &handle_replies, handle,
+ GNUNET_TIME_UNIT_FOREVER_REL);
}
return msg_size;
}
@@ -216,29 +257,31 @@ transmit_notify (void *cls, size_t size, void *buf)
*
* @param handle the lockmanager handle whose queue will be used
* @param msg the message to be queued
+ * @param request the locking reqeust responsible for queueing this message
+ * @return the MessageQueue entity that has been queued
*/
-static void
+static struct MessageQueue *
queue_message (struct GNUNET_LOCKMANAGER_Handle *handle,
- struct GNUNET_LOCKMANAGER_Message *msg)
+ struct GNUNET_LOCKMANAGER_Message *msg,
+ struct GNUNET_LOCKMANAGER_LockingRequest *request)
{
struct MessageQueue *queue_entity;
GNUNET_assert (NULL != msg);
queue_entity = GNUNET_malloc (sizeof (struct MessageQueue));
queue_entity->msg = msg;
- GNUNET_CONTAINER_DLL_insert_tail (handle->mq_head,
- handle->mq_tail,
+ queue_entity->lr = request;
+ GNUNET_CONTAINER_DLL_insert_tail (handle->mq_head, handle->mq_tail,
queue_entity);
if (NULL == handle->transmit_handle)
{
handle->transmit_handle =
- GNUNET_CLIENT_notify_transmit_ready (handle->conn,
- ntohs (msg->header.size),
- TIMEOUT,
- GNUNET_YES,
- &transmit_notify,
- handle);
+ GNUNET_CLIENT_notify_transmit_ready (handle->conn,
+ ntohs (msg->header.size), TIMEOUT,
+ GNUNET_YES, &transmit_notify,
+ handle);
}
+ return queue_entity;
}
@@ -250,15 +293,12 @@ queue_message (struct GNUNET_LOCKMANAGER_Handle *handle,
* @param key set to the key
*/
static void
-get_key (const char *domain_name,
- uint32_t lock_number,
- struct GNUNET_HashCode *key)
+get_key (const char *domain_name, uint32_t lock_number,
+ struct GNUNET_HashCode *key)
{
uint32_t *last_32;
- GNUNET_CRYPTO_hash (domain_name,
- strlen (domain_name),
- key);
+ GNUNET_CRYPTO_hash (domain_name, strlen (domain_name), key);
last_32 = (uint32_t *) key;
*last_32 ^= lock_number;
}
@@ -272,17 +312,17 @@ get_key (const char *domain_name,
* @param value value in the hash map (struct GNUNET_LOCKMANAGER_LockingRequest)
* @return GNUNET_YES if we should continue to
* iterate,
- * GNUNET_NO if not.
+ * GNUNET_NO if not.
*/
static int
-match_iterator (void *cls, const GNUNET_HashCode *key, void *value)
+match_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct LockingRequestMatch *match = cls;
struct GNUNET_LOCKMANAGER_LockingRequest *lr = value;
- if ( (match->lock == lr->lock) && (0 == strcmp (match->domain, lr->domain)) )
+ if ((match->lock == lr->lock) && (0 == strcmp (match->domain, lr->domain)))
{
- match->matched_entry = lr;
+ match->matched_entry = lr;
return GNUNET_NO;
}
return GNUNET_YES;
@@ -297,12 +337,11 @@ match_iterator (void *cls, const GNUNET_HashCode *key, void *value)
* @param domain the locking domain name
* @param lock the lock number
* @return the found LockingRequest; NULL if a matching LockingRequest wasn't
- * found
+ * found
*/
static struct GNUNET_LOCKMANAGER_LockingRequest *
hashmap_find_lockingrequest (const struct GNUNET_CONTAINER_MultiHashMap *map,
- const char *domain,
- uint32_t lock)
+ const char *domain, uint32_t lock)
{
struct GNUNET_HashCode hash;
struct LockingRequestMatch lock_match;
@@ -311,9 +350,7 @@ hashmap_find_lockingrequest (const struct GNUNET_CONTAINER_MultiHashMap *map,
lock_match.domain = domain;
lock_match.lock = lock;
get_key (domain, lock, &hash);
- GNUNET_CONTAINER_multihashmap_get_multiple (map,
- &hash,
- &match_iterator,
+ GNUNET_CONTAINER_multihashmap_get_multiple (map, &hash, &match_iterator,
&lock_match);
return lock_match.matched_entry;
}
@@ -335,16 +372,40 @@ call_status_cb_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Calling status change for SUCCESS on lock num: %d, domain: %s\n",
r->lock, r->domain);
- r->status_cb (r->status_cb_cls,
- r->domain,
- r->lock,
- r->status);
+ r->status_cb (r->status_cb_cls, r->domain, r->lock, r->status);
}
}
/**
- * Iterator to call relase and free all LockingRequest entries
+ * Function to generate acquire message for a lock
+ *
+ * @param domain_name the domain name of the lock
+ * @param lock the lock number
+ * @return the generated GNUNET_LOCKMANAGER_Message
+ */
+static struct GNUNET_LOCKMANAGER_Message *
+generate_acquire_msg (const char *domain_name, uint32_t lock)
+{
+ struct GNUNET_LOCKMANAGER_Message *msg;
+ size_t domain_name_len;
+ uint16_t msg_size;
+
+ domain_name_len = strlen (domain_name) + 1;
+ msg_size = sizeof (struct GNUNET_LOCKMANAGER_Message) + domain_name_len;
+ msg = GNUNET_malloc (msg_size);
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE);
+ msg->header.size = htons (msg_size);
+ msg->lock = htonl (lock);
+ memcpy (&msg[1], domain_name, domain_name_len);
+ return msg;
+}
+
+
+/**
+ * Iterator to call relase on locks; acquire messages are sent for all
+ * locks. In addition, if a lock is acquired before, it is not released and its
+ * status callback is called to signal its release
*
* @param cls the lockmanager handle
* @param key current key code
@@ -354,29 +415,29 @@ call_status_cb_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
* GNUNET_NO if not.
*/
static int
-release_iterator(void *cls,
- const GNUNET_HashCode * key,
- void *value)
+release_n_retry_iterator (void *cls, const struct GNUNET_HashCode *key,
+ void *value)
{
- struct GNUNET_LOCKMANAGER_Handle *h = cls;
struct GNUNET_LOCKMANAGER_LockingRequest *r = value;
+ struct GNUNET_LOCKMANAGER_Handle *h = cls;
+ struct GNUNET_LOCKMANAGER_Message *msg;
+ if (GNUNET_NO == r->acquire_sent) /* an acquire is still in queue */
+ return GNUNET_YES;
+ r->acquire_sent = GNUNET_NO;
+ msg = generate_acquire_msg (r->domain, r->lock);
+ r->mqe = queue_message (h, msg, r);
+ if (GNUNET_LOCKMANAGER_RELEASE == r->status)
+ return GNUNET_YES;
if (NULL != r->status_cb)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Calling status change for RELEASE on lock num: %d, domain: %s\n",
r->lock, r->domain);
- r->status_cb (r->status_cb_cls,
- r->domain,
- r->lock,
+ r->status = GNUNET_LOCKMANAGER_RELEASE;
+ r->status_cb (r->status_cb_cls, r->domain, r->lock,
GNUNET_LOCKMANAGER_RELEASE);
}
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (h->hashmap,
- key,
- value));
- GNUNET_free (r->domain);
- GNUNET_free (r);
return GNUNET_YES;
}
@@ -387,9 +448,8 @@ release_iterator(void *cls,
* @param cls the LOCKMANAGER_Handle
* @param msg received message, NULL on timeout or fatal error
*/
-static void
-handle_replies (void *cls,
- const struct GNUNET_MessageHeader *msg)
+static void
+handle_replies (void *cls, const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_LOCKMANAGER_Handle *handle = cls;
const struct GNUNET_LOCKMANAGER_Message *m;
@@ -398,22 +458,21 @@ handle_replies (void *cls,
struct GNUNET_HashCode hash;
uint32_t lock;
uint16_t msize;
-
+
+ handle->in_replies = GNUNET_NO;
if (NULL == msg)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Lockmanager service not available or went down\n");
- /* Should release all locks and free its locking requests */
+ /* Should release all locks and retry to acquire them */
GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap,
- &release_iterator,
- handle);
+ &release_n_retry_iterator, handle);
return;
}
- GNUNET_CLIENT_receive (handle->conn,
- &handle_replies,
- handle,
+ handle->in_replies = GNUNET_YES;
+ GNUNET_CLIENT_receive (handle->conn, &handle_replies, handle,
GNUNET_TIME_UNIT_FOREVER_REL);
- if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS != ntohs(msg->type))
+ if (GNUNET_MESSAGE_TYPE_LOCKMANAGER_SUCCESS != ntohs (msg->type))
{
GNUNET_break (0);
return;
@@ -427,20 +486,18 @@ handle_replies (void *cls,
m = (const struct GNUNET_LOCKMANAGER_Message *) msg;
domain = (const char *) &m[1];
msize -= sizeof (struct GNUNET_LOCKMANAGER_Message);
- if ('\0' != domain[msize-1])
+ if ('\0' != domain[msize - 1])
{
GNUNET_break (0);
return;
}
lock = ntohl (m->lock);
- get_key (domain, lock, &hash);
+ get_key (domain, lock, &hash);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Received SUCCESS message for lock: %d, domain %s\n",
- lock, domain);
- if (NULL == (lr = hashmap_find_lockingrequest (handle->hashmap,
- domain,
- lock)))
+ "Received SUCCESS message for lock: %d, domain %s\n", lock, domain);
+ if (NULL ==
+ (lr = hashmap_find_lockingrequest (handle->hashmap, domain, lock)))
{
GNUNET_break (0);
return;
@@ -451,11 +508,10 @@ handle_replies (void *cls,
return;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Changing status for lock: %d in domain: %s to SUCCESS\n",
- lr->lock, lr->domain);
+ "Changing status for lock: %d in domain: %s to SUCCESS\n", lr->lock,
+ lr->domain);
lr->status = GNUNET_LOCKMANAGER_SUCCESS;
- GNUNET_SCHEDULER_add_continuation (&call_status_cb_task,
- lr,
+ GNUNET_SCHEDULER_add_continuation (&call_status_cb_task, lr,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
}
@@ -471,19 +527,14 @@ handle_replies (void *cls,
* GNUNET_NO if not.
*/
static int
-free_iterator(void *cls,
- const GNUNET_HashCode * key,
- void *value)
+free_iterator (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct GNUNET_LOCKMANAGER_Handle *h = cls;
struct GNUNET_LOCKMANAGER_LockingRequest *r = value;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Clearing locking request\n");
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (h->hashmap,
- key,
- value));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Clearing locking request\n");
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (h->hashmap, key, value));
GNUNET_free (r->domain);
GNUNET_free (r);
return GNUNET_YES;
@@ -515,14 +566,12 @@ GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
GNUNET_free (h);
LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__);
return NULL;
- }
- h->hashmap = GNUNET_CONTAINER_multihashmap_create (15);
+ }
+ h->hashmap = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO);
GNUNET_assert (NULL != h->hashmap);
- GNUNET_CLIENT_receive (h->conn,
- &handle_replies,
- h,
+ h->in_replies = GNUNET_YES;
+ GNUNET_CLIENT_receive (h->conn, &handle_replies, h,
GNUNET_TIME_UNIT_FOREVER_REL);
-
LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__);
return h;
}
@@ -544,8 +593,7 @@ GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle)
LOG (GNUNET_ERROR_TYPE_WARNING,
"Some locking requests are still present. Cancel them before "
"calling %s\n", __func__);
- GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap,
- &free_iterator,
+ GNUNET_CONTAINER_multihashmap_iterate (handle->hashmap, &free_iterator,
handle);
}
GNUNET_CONTAINER_multihashmap_destroy (handle->hashmap);
@@ -557,9 +605,7 @@ GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle)
head = handle->mq_head;
while (NULL != head)
{
- GNUNET_CONTAINER_DLL_remove (handle->mq_head,
- handle->mq_tail,
- head);
+ GNUNET_CONTAINER_DLL_remove (handle->mq_head, handle->mq_tail, head);
GNUNET_free (head->msg);
GNUNET_free (head);
head = handle->mq_head;
@@ -595,18 +641,15 @@ GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle)
*/
struct GNUNET_LOCKMANAGER_LockingRequest *
GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle,
- const char *domain_name,
- uint32_t lock,
- GNUNET_LOCKMANAGER_StatusCallback
- status_cb,
+ const char *domain_name, uint32_t lock,
+ GNUNET_LOCKMANAGER_StatusCallback status_cb,
void *status_cb_cls)
{
struct GNUNET_LOCKMANAGER_LockingRequest *r;
struct GNUNET_LOCKMANAGER_Message *msg;
struct GNUNET_HashCode hash;
- uint16_t msg_size;
size_t domain_name_length;
-
+
LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__);
r = GNUNET_malloc (sizeof (struct GNUNET_LOCKMANAGER_LockingRequest));
domain_name_length = strlen (domain_name) + 1;
@@ -616,30 +659,25 @@ GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle,
r->status = GNUNET_LOCKMANAGER_RELEASE;
r->status_cb = status_cb;
r->status_cb_cls = status_cb_cls;
+ r->acquire_sent = GNUNET_NO;
memcpy (r->domain, domain_name, domain_name_length);
- msg_size = sizeof (struct GNUNET_LOCKMANAGER_Message) + domain_name_length;
- msg = GNUNET_malloc (msg_size);
- msg->header.type = htons (GNUNET_MESSAGE_TYPE_LOCKMANAGER_ACQUIRE);
- msg->header.size = htons (msg_size);
- msg->lock = htonl (lock);
- memcpy (&msg[1], r->domain, domain_name_length);
+ msg = generate_acquire_msg (r->domain, r->lock);
LOG (GNUNET_ERROR_TYPE_DEBUG, "Queueing ACQUIRE message\n");
- queue_message (handle, msg);
+ r->mqe = queue_message (handle, msg, r);
get_key (r->domain, r->lock, &hash);
- GNUNET_CONTAINER_multihashmap_put (r->handle->hashmap,
- &hash,
- r,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (r->handle->hashmap, &hash,
+ r,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__);
return r;
}
-
/**
* Function to cancel the locking request generated by
- * GNUNET_LOCKMANAGER_acquire_lock. If the lock is acquired us then the lock is
- * released. GNUNET_LOCKMANAGER_StatusCallback will not be called upon any
+ * GNUNET_LOCKMANAGER_acquire_lock. If the lock is acquired by us then the lock
+ * is released. GNUNET_LOCKMANAGER_StatusCallback will not be called upon any
* status changes resulting due to this call.
*
* @param request the LockingRequest to cancel
@@ -654,24 +692,41 @@ GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest
size_t domain_name_length;
LOG (GNUNET_ERROR_TYPE_DEBUG, "%s()\n", __func__);
- /* FIXME: Stop ACQUIRE retransmissions */
+ if (GNUNET_NO == request->acquire_sent)
+ {
+ GNUNET_assert (NULL != request->mqe);
+ if ((NULL != request->handle->transmit_handle) &&
+ (request->handle->mq_head == request->mqe))
+ {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (request->
+ handle->transmit_handle);
+ request->handle->transmit_handle = NULL;
+ }
+ GNUNET_CONTAINER_DLL_remove (request->handle->mq_head,
+ request->handle->mq_tail, request->mqe);
+ GNUNET_free (request->mqe->msg);
+ GNUNET_free (request->mqe);
+ request->status = GNUNET_LOCKMANAGER_RELEASE;
+ }
if (GNUNET_LOCKMANAGER_SUCCESS == request->status)
{
domain_name_length = strlen (request->domain) + 1;
- msg_size = sizeof (struct GNUNET_LOCKMANAGER_Message)
- + domain_name_length;
+ msg_size = sizeof (struct GNUNET_LOCKMANAGER_Message) + domain_name_length;
msg = GNUNET_malloc (msg_size);
msg->header.type = htons (GNUNET_MESSAGE_TYPE_LOCKMANAGER_RELEASE);
msg->header.size = htons (msg_size);
msg->lock = htonl (request->lock);
memcpy (&msg[1], request->domain, domain_name_length);
- queue_message (request->handle, msg);
+ GNUNET_assert (NULL == request->mqe);
+ (void) queue_message (request->handle, msg, request);
}
get_key (request->domain, request->lock, &hash);
GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove
- (request->handle->hashmap, &hash, request));
+ GNUNET_CONTAINER_multihashmap_remove (request->handle->hashmap,
+ &hash, request));
GNUNET_free (request->domain);
GNUNET_free (request);
LOG (GNUNET_ERROR_TYPE_DEBUG, "%s() END\n", __func__);
}
+
+/* end of lockmanager_api.c */
diff --git a/src/lockmanager/test_lockmanager_api.c b/src/lockmanager/test_lockmanager_api.c
index e8d0412..dd9d48f 100644
--- a/src/lockmanager/test_lockmanager_api.c
+++ b/src/lockmanager/test_lockmanager_api.c
@@ -27,11 +27,11 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_lockmanager_service.h"
+#include "gnunet_testing_lib.h"
-#define VERBOSE GNUNET_YES
-
-#define VERBOSE_ARM 1
-
+/**
+ * Generic logging shortcut
+ */
#define LOG(kind,...) \
GNUNET_log (kind, __VA_ARGS__)
@@ -43,15 +43,15 @@
* Enumeration of testing steps
*/
enum Test
- {
- TEST_FAIL,
+{
+ TEST_FAIL,
- TEST_INIT,
+ TEST_INIT,
- LOCK1_ACQUIRE,
+ LOCK1_ACQUIRE,
- LOCK2_ACQUIRE
- };
+ LOCK2_ACQUIRE
+};
/**
@@ -60,14 +60,9 @@ enum Test
static enum Test result;
/**
- * The process id of the GNUNET ARM process
- */
-static struct GNUNET_OS_Process *arm_pid = NULL;
-
-/**
* Configuration Handle
*/
-static struct GNUNET_CONFIGURATION_Handle *config;
+static const struct GNUNET_CONFIGURATION_Handle *config;
/**
* The handle to the lockmanager service
@@ -96,28 +91,19 @@ static GNUNET_SCHEDULER_TaskIdentifier abort_task_id;
* @param tc the task context
*/
static void
-do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (GNUNET_SCHEDULER_NO_TASK != abort_task_id)
- {
- GNUNET_SCHEDULER_cancel (abort_task_id);
- abort_task_id = GNUNET_SCHEDULER_NO_TASK;
- }
+ {
+ GNUNET_SCHEDULER_cancel (abort_task_id);
+ abort_task_id = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL != request)
GNUNET_LOCKMANAGER_cancel_request (request);
if (NULL != request2)
GNUNET_LOCKMANAGER_cancel_request (request2);
GNUNET_LOCKMANAGER_disconnect (handle);
- if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Kill gnunet-service-arm manually\n");
- }
- GNUNET_OS_process_wait (arm_pid);
- GNUNET_OS_process_destroy (arm_pid);
-
- if (NULL != config)
- GNUNET_CONFIGURATION_destroy (config);
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -128,7 +114,7 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
* @param tc the task context
*/
static void
-do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n");
abort_task_id = GNUNET_SCHEDULER_NO_TASK;
@@ -141,22 +127,20 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
*
* @param cls the closure from GNUNET_LOCKMANAGER_lock call
*
- * @param domain_name the locking domain of the lock
+ * @param domain_name the locking domain of the lock
*
* @param lock the lock for which this status is relevant
*
* @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully
* acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost
*/
-static void
-status_cb (void *cls,
- const char *domain_name,
- uint32_t lock,
+static void
+status_cb (void *cls, const char *domain_name, uint32_t lock,
enum GNUNET_LOCKMANAGER_Status status)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Status change callback called on lock: %d of domain: %s\n",
- lock, domain_name);
+ "Status change callback called on lock: %d of domain: %s\n", lock,
+ domain_name);
switch (result)
{
case LOCK1_ACQUIRE:
@@ -165,46 +149,19 @@ status_cb (void *cls,
//GNUNET_LOCKMANAGER_cancel_request (request);
//request = NULL;
result = LOCK2_ACQUIRE;
- request2 = GNUNET_LOCKMANAGER_acquire_lock (handle,
- "GNUNET_LOCKMANAGER_TESTING",
- 100,
- &status_cb,
- NULL);
+ request2 =
+ GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING",
+ 100, &status_cb, NULL);
GNUNET_assert (NULL != request2);
break;
case LOCK2_ACQUIRE:
GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status);
GNUNET_assert (NULL != request);
- GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1),
- &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), &do_shutdown, NULL);
break;
default:
GNUNET_break (0);
- }
-}
-
-
-/**
- * Testing function
- *
- * @param cls NULL
- * @param tc the task context
- */
-static void
-test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- handle = GNUNET_LOCKMANAGER_connect (config);
- GNUNET_assert (NULL != handle);
- result = LOCK1_ACQUIRE;
- request = GNUNET_LOCKMANAGER_acquire_lock (handle,
- "GNUNET_LOCKMANAGER_TESTING",
- 99,
- &status_cb,
- NULL);
- abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10),
- &do_abort,
- NULL);
+ }
}
@@ -212,68 +169,34 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
* Main point of test execution
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Peer *peer)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n");
- config = GNUNET_CONFIGURATION_dup (cfg);
- arm_pid =
- GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
-#if VERBOSE_ARM
- "-L", "DEBUG",
-#endif
- "-c", "test_lockmanager_api.conf", NULL);
-
- GNUNET_assert (NULL != arm_pid);
- GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (3),
- &test,
- NULL);
+ config = cfg;
+ handle = GNUNET_LOCKMANAGER_connect (config);
+ GNUNET_assert (NULL != handle);
+ result = LOCK1_ACQUIRE;
+ request =
+ GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99,
+ &status_cb, NULL);
+ abort_task_id =
+ GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (30), &do_abort, NULL);
}
/**
* Main function
*/
-int main (int argc, char **argv)
+int
+main (int argc, char **argv)
{
- int ret;
-
- char *const argv2[] = { "test-lockmanager-api",
- "-c", "test_lockmanager_api.conf",
-#if VERBOSE
- "-L", "DEBUG",
-#endif
- NULL
- };
-
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
-
- GNUNET_log_setup ("test-lockmanager-api",
-#if VERBOSE
- "DEBUG",
-#else
- "WARNING",
-#endif
- NULL);
-
- ret =
- GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
- "test-lockmanager-api", "nohelp", options, &run, NULL);
- if (GNUNET_OK != ret)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n",
- ret);
+ if (0 !=
+ GNUNET_TESTING_peer_run ("test_lockmanager_api",
+ "test_lockmanager_api.conf", &run, NULL))
return 1;
- }
- if (TEST_FAIL == result)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "test failed\n");
- return 1;
- }
- LOG (GNUNET_ERROR_TYPE_INFO, "test OK\n");
- return 0;
+ return (TEST_FAIL == result) ? 1 : 0;
}
+
+/* end of test_lockmanager_api.c */
diff --git a/src/lockmanager/test_lockmanager_api.conf b/src/lockmanager/test_lockmanager_api.conf
index 894f409..4ac6b56 100644
--- a/src/lockmanager/test_lockmanager_api.conf
+++ b/src/lockmanager/test_lockmanager_api.conf
@@ -1,5 +1,4 @@
[lockmanager]
-DEBUG = YES
AUTOSTART = NO
PORT = 12112
ACCEPT_FROM = 127.0.0.1;
@@ -28,7 +27,6 @@ DATABASE = sqlite
[transport]
PLUGINS = tcp
-DEBUG = NO
ACCEPT_FROM6 = ::1;
ACCEPT_FROM = 127.0.0.1;
NEIGHBOUR_LIMIT = 50
@@ -44,7 +42,6 @@ PORT = 12092
[arm]
DEFAULTSERVICES = core lockmanager
PORT = 12366
-DEBUG = NO
[transport-tcp]
TIMEOUT = 300 s
@@ -53,7 +50,6 @@ PORT = 12368
[TESTING]
NUM_PEERS = 5
WEAKRANDOM = YES
-DEBUG = YES
HOSTKEYSFILE = ../../contrib/testing_hostkeys.dat
MAX_CONCURRENT_SSH = 10
USE_PROGRESSBARS = YES
@@ -63,7 +59,6 @@ PEERGROUP_TIMEOUT = 2400 s
HOSTKEY = $SERVICEHOME/.hostkey
[PATHS]
-DEFAULTCONFIG = test_lockmanager_api.conf
SERVICEHOME = /tmp/test-lockmanager/
[dns]
@@ -71,3 +66,6 @@ AUTOSTART = NO
[nse]
AUTOSTART = NO
+
+[consensus]
+AUTOSTART = NO
diff --git a/src/lockmanager/test_lockmanager_api_acquireretry.c b/src/lockmanager/test_lockmanager_api_acquireretry.c
new file mode 100644
index 0000000..d2c88e5
--- /dev/null
+++ b/src/lockmanager/test_lockmanager_api_acquireretry.c
@@ -0,0 +1,224 @@
+/*
+ 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 lockmanager/test_lockmanager_api_acquireretry.c
+ * @brief Test cases for lockmanager_api where the server crashes and comes
+ * back; the api should try to acqurie the lock again
+ * @author Sree Harsha Totakura
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_lockmanager_service.h"
+#include "gnunet_testing_lib.h"
+
+/**
+ * Generic logging shorthand
+ */
+#define LOG(kind,...) \
+ GNUNET_log (kind, __VA_ARGS__)
+
+/**
+ * Relative seconds shorthand
+ */
+#define TIME_REL_SECS(sec) \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
+
+/**
+ * Various stages in test
+ */
+enum Test
+{
+ /**
+ * Signal test failure
+ */
+ TEST_FAIL,
+
+ /**
+ * Testing just began
+ */
+ TEST_INIT,
+
+ /**
+ * Client has successfully acquired the lock
+ */
+ TEST_CLIENT_LOCK_SUCCESS,
+
+ /**
+ * Client has lost the lock
+ */
+ TEST_CLIENT_LOCK_RELEASE,
+
+ /**
+ * Client has again acquired the lock
+ */
+ TEST_CLIENT_LOCK_AGAIN_SUCCESS
+};
+
+/**
+ * Configuration Handle
+ */
+static const struct GNUNET_CONFIGURATION_Handle *config;
+
+/**
+ * The handle to the lockmanager service
+ */
+static struct GNUNET_LOCKMANAGER_Handle *handle;
+
+/**
+ * The locking request
+ */
+static struct GNUNET_LOCKMANAGER_LockingRequest *request;
+
+/**
+ * Abort task identifier
+ */
+static GNUNET_SCHEDULER_TaskIdentifier abort_task_id;
+
+/**
+ * The test result
+ */
+enum Test result;
+
+/**
+ * Our peer
+ */
+static struct GNUNET_TESTING_Peer *self;
+
+
+/**
+ * Shutdown nicely
+ *
+ * @param cls
+ * @param tc the task context
+ */
+static void
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if (GNUNET_SCHEDULER_NO_TASK != abort_task_id)
+ {
+ GNUNET_SCHEDULER_cancel (abort_task_id);
+ abort_task_id = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (NULL != handle)
+ GNUNET_LOCKMANAGER_disconnect (handle);
+}
+
+/**
+ * Abort
+ *
+ * @param cls
+ * @param tc the task context
+ */
+static void
+do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n");
+ abort_task_id = GNUNET_SCHEDULER_NO_TASK;
+ result = TEST_FAIL;
+ do_shutdown (cls, tc);
+}
+
+
+/**
+ * Callback for lock status changes
+ *
+ * @param cls the handle
+ *
+ * @param domain_name the locking domain of the lock
+ *
+ * @param lock the lock for which this status is relevant
+ *
+ * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully
+ * acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost
+ */
+static void
+status_cb (void *cls, const char *domain_name, uint32_t lock,
+ enum GNUNET_LOCKMANAGER_Status status)
+{
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Status change callback called on lock: %d of domain: %s\n", lock,
+ domain_name);
+ switch (result)
+ {
+ case TEST_INIT:
+ GNUNET_assert (handle == cls);
+ GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status);
+ result = TEST_CLIENT_LOCK_SUCCESS;
+ /* We should kill the lockmanager process */
+ GNUNET_TESTING_peer_stop (self);
+ break;
+ case TEST_CLIENT_LOCK_SUCCESS:
+ GNUNET_assert (handle == cls);
+ GNUNET_assert (GNUNET_LOCKMANAGER_RELEASE == status);
+ result = TEST_CLIENT_LOCK_RELEASE;
+ /* Now we should start again the lockmanager process */
+ GNUNET_TESTING_peer_start (self);
+ break;
+ case TEST_CLIENT_LOCK_RELEASE:
+ GNUNET_assert (handle == cls);
+ GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status);
+ result = TEST_CLIENT_LOCK_AGAIN_SUCCESS;
+ GNUNET_LOCKMANAGER_cancel_request (request);
+ request = NULL;
+ GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (1), &do_shutdown, NULL);
+ break;
+ default:
+ GNUNET_assert (0); /* We should never reach here */
+ }
+}
+
+
+/**
+ * Main point of test execution
+ */
+static void
+run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Peer *peer)
+{
+ config = cfg;
+ self = peer;
+ result = TEST_INIT;
+ handle = GNUNET_LOCKMANAGER_connect (config);
+ GNUNET_assert (NULL != handle);
+ request =
+ GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99,
+ &status_cb, handle);
+ GNUNET_assert (NULL != request);
+ abort_task_id =
+ GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (30), &do_abort, NULL);
+}
+
+
+/**
+ * Main function
+ */
+int
+main (int argc, char **argv)
+{
+ if (0 !=
+ GNUNET_TESTING_peer_run ("test_lockmanager_api_acquireretry",
+ "test_lockmanager_api.conf", &run, NULL))
+ return 1;
+ return (TEST_CLIENT_LOCK_AGAIN_SUCCESS != result) ? 1 : 0;
+}
+
+/* end of test_lockmanager_api_acquireretry.c */
diff --git a/src/lockmanager/test_lockmanager_api_lockrelease.c b/src/lockmanager/test_lockmanager_api_lockrelease.c
index 7e24d10..ba4881a 100644
--- a/src/lockmanager/test_lockmanager_api_lockrelease.c
+++ b/src/lockmanager/test_lockmanager_api_lockrelease.c
@@ -26,15 +26,18 @@
#include "platform.h"
#include "gnunet_util_lib.h"
+#include "gnunet_testing_lib.h"
#include "gnunet_lockmanager_service.h"
-#define VERBOSE GNUNET_YES
-
-#define VERBOSE_ARM 1
-
+/**
+ * Generic Logging shorthand
+ */
#define LOG(kind,...) \
GNUNET_log (kind, __VA_ARGS__)
+/**
+ * Relative seconds shorthand
+ */
#define TIME_REL_SECONDS(min) \
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min)
@@ -42,28 +45,28 @@
* Various steps of the test
*/
enum Test
- {
+{
/**
* Signal test failure
*/
- TEST_FAIL,
+ TEST_FAIL,
/**
* Testing just began
*/
- TEST_INIT,
+ TEST_INIT,
/**
* Client 1 has got the lock successfully; Client 2 should try to acquire
* the lock now; after some time client 1 has to release the lock
*/
- TEST_CLIENT1_LOCK_SUCCESS,
+ TEST_CLIENT1_LOCK_SUCCESS,
/**
* Client 2 has got the lock; Should release it and call shutdown
*/
- TEST_CLIENT2_LOCK_SUCCESS,
- };
+ TEST_CLIENT2_LOCK_SUCCESS,
+};
/**
* The testing result
@@ -71,14 +74,9 @@ enum Test
static enum Test result;
/**
- * The process id of the GNUNET ARM process
- */
-static struct GNUNET_OS_Process *arm_pid = NULL;
-
-/**
* Configuration Handle
*/
-static struct GNUNET_CONFIGURATION_Handle *config;
+static const struct GNUNET_CONFIGURATION_Handle *config;
/**
* The handle to the lockmanager service
@@ -113,26 +111,15 @@ static GNUNET_SCHEDULER_TaskIdentifier abort_task_id;
* @param tc the task context
*/
static void
-do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (GNUNET_SCHEDULER_NO_TASK != abort_task_id)
{
GNUNET_SCHEDULER_cancel (abort_task_id);
abort_task_id = GNUNET_SCHEDULER_NO_TASK;
}
-
GNUNET_LOCKMANAGER_disconnect (handle);
GNUNET_LOCKMANAGER_disconnect (handle2);
- if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Kill gnunet-service-arm manually\n");
- }
- GNUNET_OS_process_wait (arm_pid);
- GNUNET_OS_process_destroy (arm_pid);
-
- if (NULL != config)
- GNUNET_CONFIGURATION_destroy (config);
}
@@ -143,7 +130,7 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
* @param tc the task context
*/
static void
-do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n");
abort_task_id = GNUNET_SCHEDULER_NO_TASK;
@@ -157,33 +144,29 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
*
* @param cls the handle
*
- * @param domain_name the locking domain of the lock
+ * @param domain_name the locking domain of the lock
*
* @param lock the lock for which this status is relevant
*
* @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully
* acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost
*/
-static void
-status_cb (void *cls,
- const char *domain_name,
- uint32_t lock,
+static void
+status_cb (void *cls, const char *domain_name, uint32_t lock,
enum GNUNET_LOCKMANAGER_Status status)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Status change callback called on lock: %d of domain: %s\n",
- lock, domain_name);
+ "Status change callback called on lock: %d of domain: %s\n", lock,
+ domain_name);
GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status);
switch (result)
{
case TEST_INIT:
GNUNET_assert (handle == cls);
result = TEST_CLIENT1_LOCK_SUCCESS;
- request2 = GNUNET_LOCKMANAGER_acquire_lock (handle2,
- "GNUNET_LOCKMANAGER_TESTING",
- 99,
- &status_cb,
- handle2);
+ request2 =
+ GNUNET_LOCKMANAGER_acquire_lock (handle2, "GNUNET_LOCKMANAGER_TESTING",
+ 99, &status_cb, handle2);
GNUNET_assert (NULL != request2);
GNUNET_LOCKMANAGER_cancel_request (request);
request = NULL;
@@ -192,9 +175,7 @@ status_cb (void *cls,
GNUNET_assert (handle2 == cls);
result = TEST_CLIENT2_LOCK_SUCCESS;
GNUNET_LOCKMANAGER_cancel_request (request2);
- GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1),
- &do_shutdown,
- NULL);
+ GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), &do_shutdown, NULL);
break;
default:
GNUNET_assert (0); /* We should never reach here */
@@ -204,98 +185,39 @@ status_cb (void *cls,
/**
- * Testing function
- *
- * @param cls NULL
- * @param tc the task context
+ * Main point of test execution
*/
static void
-test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
+run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Peer *peer)
+{
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n");
+ config = cfg;
result = TEST_INIT;
handle = GNUNET_LOCKMANAGER_connect (config);
GNUNET_assert (NULL != handle);
handle2 = GNUNET_LOCKMANAGER_connect (config);
-
- request = GNUNET_LOCKMANAGER_acquire_lock (handle,
- "GNUNET_LOCKMANAGER_TESTING",
- 99,
- &status_cb,
- handle);
- GNUNET_assert (NULL != request);
- abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10),
- &do_abort,
- NULL);
-}
-
-
-/**
- * Main point of test execution
- */
-static void
-run (void *cls, char *const *args, const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n");
- config = GNUNET_CONFIGURATION_dup (cfg);
- arm_pid =
- GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
-#if VERBOSE_ARM
- "-L", "DEBUG",
-#endif
- "-c", "test_lockmanager_api.conf", NULL);
- GNUNET_assert (NULL != arm_pid);
- GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (3),
- &test,
- NULL);
+ request =
+ GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99,
+ &status_cb, handle);
+ GNUNET_assert (NULL != request);
+ abort_task_id =
+ GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10), &do_abort, NULL);
}
/**
* Main function
*/
-int main (int argc, char **argv)
+int
+main (int argc, char **argv)
{
- int ret;
-
- char *const argv2[] = { "test-lockmanager-api-lockrelease",
- "-c", "test_lockmanager_api.conf",
-#if VERBOSE
- "-L", "DEBUG",
-#endif
- NULL
- };
-
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
-
- GNUNET_log_setup ("test-lockmanager-api-lockrelease",
-#if VERBOSE
- "DEBUG",
-#else
- "WARNING",
-#endif
- NULL);
-
- ret =
- GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
- "test-lockmanager-api-lockrelease",
- "nohelp", options, &run, NULL);
-
- if (GNUNET_OK != ret)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n",
- ret);
+ if (0 !=
+ GNUNET_TESTING_peer_run ("test_lockmanager_api_lockrelease",
+ "test_lockmanager_api.conf", &run, NULL))
return 1;
- }
- if (TEST_CLIENT2_LOCK_SUCCESS != result)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "test failed\n");
- return 1;
- }
- LOG (GNUNET_ERROR_TYPE_INFO, "test OK\n");
- return 0;
+ return (TEST_CLIENT2_LOCK_SUCCESS != result) ? 1 : 0;
}
+
+/* end of test_lockmanager_api_lockrelease.c */
diff --git a/src/lockmanager/test_lockmanager_api_servercrash.c b/src/lockmanager/test_lockmanager_api_servercrash.c
index 3fa6418..a37d614 100644
--- a/src/lockmanager/test_lockmanager_api_servercrash.c
+++ b/src/lockmanager/test_lockmanager_api_servercrash.c
@@ -27,14 +27,17 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_lockmanager_service.h"
+#include "gnunet_testing_lib.h"
-#define VERBOSE GNUNET_YES
-
-#define VERBOSE_ARM 1
-
+/**
+ * Generic logging shorthand
+ */
#define LOG(kind,...) \
GNUNET_log (kind, __VA_ARGS__)
+/**
+ * Relative seconds shorthand
+ */
#define TIME_REL_SECONDS(min) \
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, min)
@@ -42,34 +45,34 @@
* Various steps of the test
*/
enum Test
- {
+{
/**
* Signal test failure
*/
- TEST_FAIL,
+ TEST_FAIL,
/**
* Testing just began
*/
- TEST_INIT,
+ TEST_INIT,
/**
* Client 1 has got the lock successfully; Client 2 should try to acquire
* the lock now; after some time client 1 has to release the lock
*/
- TEST_CLIENT1_LOCK_SUCCESS,
+ TEST_CLIENT1_LOCK_SUCCESS,
/**
* Client 2 has got the lock; Server should crash now;
*/
- TEST_CLIENT2_LOCK_SUCCESS,
+ TEST_CLIENT2_LOCK_SUCCESS,
/**
* Client 2 should get lock release due to server crash; Should call
* shutdown now
*/
- TEST_CLIENT2_SERVER_CRASH_SUCCESS
- };
+ TEST_CLIENT2_SERVER_CRASH_SUCCESS
+};
/**
* The testing result
@@ -77,14 +80,9 @@ enum Test
static enum Test result;
/**
- * The process id of the GNUNET ARM process
- */
-static struct GNUNET_OS_Process *arm_pid = NULL;
-
-/**
* Configuration Handle
*/
-static struct GNUNET_CONFIGURATION_Handle *config;
+static const struct GNUNET_CONFIGURATION_Handle *config;
/**
* The handle to the lockmanager service
@@ -111,6 +109,11 @@ static struct GNUNET_LOCKMANAGER_LockingRequest *request2;
*/
static GNUNET_SCHEDULER_TaskIdentifier abort_task_id;
+/**
+ * Our peer
+ */
+static struct GNUNET_TESTING_Peer *self;
+
/**
* Shutdown nicely
@@ -119,7 +122,7 @@ static GNUNET_SCHEDULER_TaskIdentifier abort_task_id;
* @param tc the task context
*/
static void
-do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (GNUNET_SCHEDULER_NO_TASK != abort_task_id)
{
@@ -130,18 +133,6 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
GNUNET_LOCKMANAGER_disconnect (handle);
if (NULL != handle2)
GNUNET_LOCKMANAGER_disconnect (handle2);
- if (NULL != arm_pid)
- {
- if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Kill gnunet-service-arm manually\n");
- }
- GNUNET_OS_process_wait (arm_pid);
- GNUNET_OS_process_destroy (arm_pid);
- }
- if (NULL != config)
- GNUNET_CONFIGURATION_destroy (config);
}
@@ -152,7 +143,7 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
* @param tc the task context
*/
static void
-do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "Aborting test...\n");
abort_task_id = GNUNET_SCHEDULER_NO_TASK;
@@ -166,33 +157,29 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc)
*
* @param cls the handle
*
- * @param domain_name the locking domain of the lock
+ * @param domain_name the locking domain of the lock
*
* @param lock the lock for which this status is relevant
*
* @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully
* acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost
*/
-static void
-status_cb (void *cls,
- const char *domain_name,
- uint32_t lock,
+static void
+status_cb (void *cls, const char *domain_name, uint32_t lock,
enum GNUNET_LOCKMANAGER_Status status)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Status change callback called on lock: %d of domain: %s\n",
- lock, domain_name);
+ "Status change callback called on lock: %d of domain: %s\n", lock,
+ domain_name);
switch (result)
{
case TEST_INIT:
GNUNET_assert (handle == cls);
GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status);
result = TEST_CLIENT1_LOCK_SUCCESS;
- request2 = GNUNET_LOCKMANAGER_acquire_lock (handle2,
- "GNUNET_LOCKMANAGER_TESTING",
- 99,
- &status_cb,
- handle2);
+ request2 =
+ GNUNET_LOCKMANAGER_acquire_lock (handle2, "GNUNET_LOCKMANAGER_TESTING",
+ 99, &status_cb, handle2);
GNUNET_assert (NULL != request2);
GNUNET_LOCKMANAGER_cancel_request (request);
request = NULL;
@@ -201,15 +188,8 @@ status_cb (void *cls,
GNUNET_assert (handle2 == cls);
GNUNET_assert (GNUNET_LOCKMANAGER_SUCCESS == status);
result = TEST_CLIENT2_LOCK_SUCCESS;
- /* We should kill the lockmanager process */
- if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Kill gnunet-service-arm manually\n");
- }
- GNUNET_OS_process_wait (arm_pid);
- GNUNET_OS_process_destroy (arm_pid);
- arm_pid =NULL;
+ /* We should stop our peer to simulate crash in lockmanager service */
+ GNUNET_TESTING_peer_stop (self);
break;
case TEST_CLIENT2_LOCK_SUCCESS:
GNUNET_assert (handle2 == cls);
@@ -217,110 +197,50 @@ status_cb (void *cls,
GNUNET_assert (99 == lock);
GNUNET_assert (0 == strcmp (domain_name, "GNUNET_LOCKMANAGER_TESTING"));
result = TEST_CLIENT2_SERVER_CRASH_SUCCESS;
- GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1),
- &do_shutdown,
- NULL);
+ GNUNET_LOCKMANAGER_cancel_request (request2);
+ request2 = NULL;
+ GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (1), &do_shutdown, NULL);
break;
default:
GNUNET_assert (0); /* We should never reach here */
}
-
}
/**
- * Testing function
- *
- * @param cls NULL
- * @param tc the task context
+ * Main point of test execution
*/
static void
-test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
+run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Peer *peer)
+{
+ config = cfg;
+ self = peer;
result = TEST_INIT;
handle = GNUNET_LOCKMANAGER_connect (config);
GNUNET_assert (NULL != handle);
handle2 = GNUNET_LOCKMANAGER_connect (config);
-
- request = GNUNET_LOCKMANAGER_acquire_lock (handle,
- "GNUNET_LOCKMANAGER_TESTING",
- 99,
- &status_cb,
- handle);
- GNUNET_assert (NULL != request);
- abort_task_id = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10),
- &do_abort,
- NULL);
-}
-
-/**
- * Main point of test execution
- */
-static void
-run (void *cls, char *const *args, const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting test...\n");
- config = GNUNET_CONFIGURATION_dup (cfg);
- arm_pid =
- GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
- "gnunet-service-arm",
-#if VERBOSE_ARM
- "-L", "DEBUG",
-#endif
- "-c", "test_lockmanager_api.conf", NULL);
-
- GNUNET_assert (NULL != arm_pid);
- GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (3),
- &test,
- NULL);
+ request =
+ GNUNET_LOCKMANAGER_acquire_lock (handle, "GNUNET_LOCKMANAGER_TESTING", 99,
+ &status_cb, handle);
+ GNUNET_assert (NULL != request);
+ abort_task_id =
+ GNUNET_SCHEDULER_add_delayed (TIME_REL_SECONDS (10), &do_abort, NULL);
}
/**
* Main function
*/
-int main (int argc, char **argv)
+int
+main (int argc, char **argv)
{
- int ret;
-
- char *const argv2[] = { "test-lockmanager-api-servercrash",
- "-c", "test_lockmanager_api.conf",
-#if VERBOSE
- "-L", "DEBUG",
-#endif
- NULL
- };
-
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
-
- GNUNET_log_setup ("test-lockmanager-api-servercrash",
-#if VERBOSE
- "DEBUG",
-#else
- "WARNING",
-#endif
- NULL);
-
- ret =
- GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
- "test-lockmanager-api-servercrash",
- "nohelp", options, &run, NULL);
-
- if (GNUNET_OK != ret)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "run failed with error code %d\n",
- ret);
+ if (0 !=
+ GNUNET_TESTING_peer_run ("test_lockmanager_api_servercrash",
+ "test_lockmanager_api.conf", &run, NULL))
return 1;
- }
- if (TEST_CLIENT2_SERVER_CRASH_SUCCESS != result)
- {
- LOG (GNUNET_ERROR_TYPE_WARNING, "test failed\n");
- return 1;
- }
- LOG (GNUNET_ERROR_TYPE_INFO, "test OK\n");
- return 0;
+ return (TEST_CLIENT2_SERVER_CRASH_SUCCESS != result) ? 1 : 0;
}
+
+/* end of test_lockmanager_api_servercrash.c */