Commit Graph

3686 Commits

Author SHA1 Message Date
Andrew Bettison
ccacd19dfa Add global keyring assertions
Many functions require that the global 'keyring' pointer is set,
but there were no assertions to document this precondition.
2016-11-14 11:28:08 +10:30
Andrew Bettison
6d2eb268ed Add 'cmd_cleanup' trigger
The new 'cmd_cleanup' trigger replaces the old command_cleanup()
function, which was causing linking problems on OS X and inverted strict
dependency.  The keyring cmd_cleanup calls keyring_free(global_keyring),
instead of merely asserting keyring == NULL, so the error exit cases of
many CLI functions have been simplified.
2016-11-14 11:28:03 +10:30
Andrew Bettison
931f25a9e7 Fix strlcpy.c compile error on OS X 2016-11-09 19:03:45 +10:30
Jeremy Lakeman
bd9083d57d Fix tests with clean work folder, renamed libservald to libservaldaemon 2016-11-07 14:23:45 +10:30
Andrew Bettison
a8e394d299 Add "keyring remove" command
Adds a CLI and RESTful API operation for "keyring remove", with simple
test cases.  Added the corresponding Java API operation.  Updated the
API documentation.

API change: for consistency with RESTful API design, the GET
/restful/keyring/add operation now returns "201 Created" not "200 OK" if
successful.
2016-11-07 13:07:49 +10:30
Andrew Bettison
e47d0ce1c7 Fix the RESTful keyring add/set http_status_message
For successful requests (200), was being returned as "application/json",
but should be "OK".
2016-11-07 11:38:20 +10:30
Andrew Bettison
24266b5f3b Add 'api.restful.authorization' config option 2016-11-07 11:38:20 +10:30
Jeremy Lakeman
5b75221c91 Fix compiler warnings when building with android ndk 13b 2016-11-07 10:38:23 +10:30
Jeremy Lakeman
159188d08c Don't overflow the stack if logging config causes more logging due to using memory diagnostics 2016-10-31 15:23:06 +10:30
Jeremy Lakeman
f4210e06d8 Make sure all restful newsince responses can be sorted by the front end 2016-10-31 10:56:10 +10:30
Jeremy Lakeman
84caa24d0f Pass identity name as meshmb manifest name 2016-10-26 13:09:35 +10:30
Jeremy Lakeman
eff46c9030 Add manifest name to meshmb restful output 2016-10-26 13:09:34 +10:30
Jeremy Lakeman
8e9877b3ce Add filter by service / name to restful rhizome list 2016-10-26 13:09:32 +10:30
Jeremy Lakeman
86d4d87ff2 Add java API for restful meshmb send and list 2016-10-26 13:09:30 +10:30
Jeremy Lakeman
4b1f64c0e3 Generalise meshms json list parsing into an abstract class 2016-10-26 13:08:31 +10:30
Jeremy Lakeman
09d04d7c8f Add restful api for listing broadcast messages 2016-10-26 13:08:19 +10:30
Jeremy Lakeman
c2956568d6 Send a meshmb message via restful api 2016-10-26 13:08:13 +10:30
Jeremy Lakeman
7f6316b7df Remove dependence on keyring list order 2016-10-26 13:01:37 +10:30
Jeremy Lakeman
26e38e79cb Tidy up handling of http server socket addresses & log spam 2016-10-25 16:04:41 +10:30
Jeremy Lakeman
9feda5258c Allow client to specify external interface name in config match expression 2016-10-25 16:04:41 +10:30
Andrew Bettison
176de6fa42 Fix Makefile failure when <jni.h> not present
This condition had not been tested since Makefile.in was overhauled.
2016-10-25 09:39:56 +10:30
Andrew Bettison
a72f6ae91b Use AC_CONFIG_SRCDIR in configure.ac
Adds a safety check to ensure that the --srcdir option to ./configure is valid.
2016-10-25 09:34:32 +10:30
Andrew Bettison
6201b97fa3 Shorten trigger names for OS X
Trigger names cannot exceed 11 characters on OS X, so the new "config_change" trigger
has been renamed to "conf_change" and the "config_change_log" trigger has been renamed
to "conf_log".
2016-10-25 09:34:32 +10:30
Jeremy Lakeman
5fbd6a79ef Add feature for meshmb cli to force linking into deamon 2016-10-20 09:28:08 -04:00
Jeremy Lakeman
30aa1c16b8 Set authorship to remote if the sender sid can be generated from the id 2016-10-20 08:51:46 -04:00
Jeremy Lakeman
65831e31d4 Report the state of each network interface in routing table 2016-10-20 08:48:35 -04:00
Jeremy Lakeman
fe7a839df5 Don't depend on the ability to correctly resolve localhost 2016-10-20 08:37:24 -04:00
Jeremy Lakeman
75dfcff213 Fix meshms restful newsince with empty conversation 2016-10-20 08:37:24 -04:00
Andrew Bettison
95cce9109f Fix Android server thread start bug
Was failing to start if a stale pidfile was present.

Introduced the 'debug.server' config option to help diagnose pidfile
issues.
2016-10-20 13:29:01 +10:30
Andrew Bettison
5191d424cb Fix broken Android build
Renamed libservald.so to libservaldaemon.so everywhere to avoid conflicts
with the "servald" module name in Android.mk, and to avoid the overly
generic name "libserval".

Include the JNI entry points in the Android build.
2016-10-20 13:28:12 +10:30
Andrew Bettison
641298b0e6 Fix JNI command-line exception return path
If an exception was raised while executing a CLI command via JNI, then
a warning was logged while cleaning up: calling GetObjectArrayElement()
while an exception is pending.  This fix removes that call.
2016-10-20 13:28:12 +10:30
Andrew Bettison
e2086249ac Load config earlier in the JNI server entry point 2016-10-20 13:28:12 +10:30
Andrew Bettison
1efe6686fc Use config.h instead of -DHAVE_FOO=1
swiftc(1) requires every -D option to be prefixed with -Xcc, which
is not easy to achieve using autoconf.

Now instead of setting configuration macros like HAVE_LSEEK64 on the
command line using -D, they are defined in config.h, which is generated
by ./configure, ignored by Git, and included by all headers and source
files that use any configuration macro.

The dependency on Makefile has been replaced with a dependency on
Makefile.in and config.h, which helps avoid some redundant full
recompiles after running ./configure, because the configure script
does not overwrit config.h if its content does not change.
2016-10-19 16:27:20 +10:30
Andrew Bettison
42f62d2b8b Move JNI setInstancePath() into own source file 2016-10-19 16:26:00 +10:30
Andrew Bettison
a3f3de571a Minor fixes to Makefile.in 2016-10-19 10:54:44 +10:30
Andrew Bettison
8325aacc5d Fix broken Batphone build
Recent changes such as the Makefile.in overhaul and the introduction of
feature-driven linking broke the Android build.  This commit fixes the
breakage:
- detects the presence of gettid() in configure.ac and only defines
  gettid() in serval.c if HAVE_GETTID is not defined
- builds libserval.so not libservald.so on Android, to avoid a conflict
  on the module name "servald" in Android.mk
- renames cli_cleanup() to command_cleanup(), defines it in
  commandline.h instead of cli.h, and supplies it in android.c
- supplies the 'keyring' global in android.c
- removes log_stderr.c from the Android build, since it conflicted with
  log.c
2016-10-19 09:52:07 +10:30
Andrew Bettison
6627c868d0 Fix a non-deterministic server test case failure
Very occasionally, when the file logger was creating the symlink from
'serval.log' to the current log file, there was a race with another
process doing exactly the same, causing one of them to log an
symlink-failed ERROR that caused the server/StartTwice test to fail
(when asserting that the "start" command contained no ERROR log
messages).  Now the symlink failure is logged at WARN level, which will
not cause the test to fail.
2016-10-19 09:50:30 +10:30
Andrew Bettison
94c58e8126 Fix a pidfile race in server_write_pid()
During the brief interval between a server creating its pidfile and
locking it, the pidfile could be removed by another process that
detected it as stale.  This caused a non-deterministic failure of the
server/StartTwice test case.

To fix this race, the server now creates and locks a temporary pidfile
which it then hard-links to the real pidfile, guaranteeing that the
pidfile is already locked in the instant that it appears.  This means
that an unlocked pidfile is guaranteed to be stale, not just in the
process of creation, so can be safely unlinked by any other process.
2016-10-19 09:47:52 +10:30
Andrew Bettison
192fefd7f2 Update INSTALL.md to describe built artifacts 2016-10-19 09:47:48 +10:30
Andrew Bettison
71cbe86566 Switch to feature-driven linking
This introduces a new way of linking Serval executables and dynamic
libraries from static libraries like libservald.a -- called
"feature-driven" linking.

The Makefile now links servald and serval-tests from libservald.a,
rather than from an explicit list of object (.o) files.  Thanks to the
section-based method for registering functions such as HTTP handlers,
CLI commands and MDP handlers, these object files had become
"stand-alone" and hence were no longer included in the link because
there was no unresolved reference that required them to be linked in.

The new "feature.h" provides the DECLARE_FEATURE(name) macro that each
stand-alone source file uses to declare the named feature(s) it
provides.  Each executable can call the USE_FEATURE(name) macro in any
of its explicitly-linked source files to cause the corresponding
object(s) to be included in the link, eg, servald_features.c.

The DEFINE_BINDING() macro has been extended so that every individual
MDP binding is given a feature name based on its port number macro, eg,
"mdp_binding_MDP_PORT_ECHO".

Some features have been factored into their own separate source files so
they can be omitted or included in a build independently of each other:
- the MDP bindings for MDP_PORT_DNALOOKUP, MDP_PORT_ECHO,
  MDP_PORT_TRACE, MDP_PORT_KEYMAPREQUEST, MDP_PORT_RHIZOME_xxx,
  MDP_PORT_PROBE, MDP_PORT_STUN, MDP_PORT_STUNREQ
- the CLI "log" and "echo" commands
- the CLI "rhizome direct" command

The JNI source files are only compiled if the <jni.h> header is present,
otherwise they are omitted from libservald.so.
2016-10-19 09:33:01 +10:30
Andrew Bettison
8cb3afa7dc Replace cf_on_config_change() with "config_change" trigger
This is required to support feature-driven linking, in which the exact
list of which functions to call in response to a configuration re-load
is not known until link time.

The "config_change_log" trigger is called before "config_change", so
that the logger can respond to the change before other subsystems.
2016-10-19 09:30:54 +10:30
Andrew Bettison
6dd823a9e8 Rename "features.h" to "lang.h"
In preparation for introducing "feature.h" for feature-driven linking.
2016-10-19 09:30:18 +10:30
Andrew Bettison
937e402794 Improve build-libsodium.sh
Add the --branch option to specify which libsodium branch to checkout
and build.

Invoke libsodium's autogen.sh script if libsodium's 'configure' script
is not present (eg, on development branches).
2016-10-13 17:00:17 +10:30
Andrew Bettison
43e76ec7b5 Change signature of strn_fromprint()
The 'dst' parameter is now (char *) instead of (unsigned char *) because
in general it is used to produce human-readable (ASCII) strings, not
binary data.
2016-10-13 16:23:18 +10:30
Andrew Bettison
c8bf8a7733 Refactor JNI out of CLI and server main loop
The CLI and server main loop now have no conditional JNI code.  All JNI
code has been moved into separate source files, which #include the new
"jni_common.h" instead of <jni.h>.  The "cli.h" header no longer
includes <jni.h>, so the rest of the Serval source code is now
unaffected by JNI definitions.

The 'cf_limbo' global variable is now thread-local, so that each thread
has its own independent copy of the loaded configuration.  The JNI
server entry point now calls cf_init() once.  The new 'cf_initialised'
flag prevents clobbering the config state by redundant calls to
cf_init().

The CLI "stop" command now sends SIGHUP to the specific thread in which
the server is running.  This is achieved by writing the PID and TID
(Linux Thread ID) into the pidfile, separated by a space, on systems
that support the Linux gettid() and tgkill() system calls.  The server's
signal handler has been overhauled, and its logging improved.
2016-10-13 16:23:18 +10:30
Andrew Bettison
41b3e304be Updated some copyright messages and COPYRIGHT.txt 2016-10-13 16:23:18 +10:30
Andrew Bettison
29a771e315 Overhaul Makefile.in
Changed the built libraries and updated INSTALL.md accordingly:
- the 'servaldwrap' executable is now built
- libservald.[a,so] now contains the full daemon executable
- libservalclient.[a,so] contains the client library
- libserval.a is no longer built

Building the 'servaldwrap' executable is a step towards ensuring that
the libservald.so library can be linked and executed, without requiring
an Android build to reveal any failure.

Added the SOURCE_PREFIX variable that allows the make to be invoked from
within any current working directory, not just the serval-dna
repository's root directory.

Fixed the serval_version.o target to invoke the version_string.sh
script with the --repository=DIR option, so that the build will work
even if the current working directory is not within the serval-dna
repository.

Re-ordered and added some comments for clarity, and added some missing
.PHONY declarations.
2016-10-13 16:23:09 +10:30
Andrew Bettison
4b2060554e Rename configure.in to configure.ac 2016-10-13 16:05:58 +10:30
Andrew Bettison
cd40025533 Make all cli_ output functions return void 2016-10-13 16:01:22 +10:30
Andrew Bettison
a15396b793 Add server status test case 2016-10-13 16:01:22 +10:30