mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-18 20:57:56 +00:00
Overhaul Makefile and header files
Make .o files in separate subdirectories for servald and library Factor struct __sourceloc and __WHENCE__ from "log.h" into "whence.h" Factor sid_t etc from "serval.h" into "serval_types.h" Factor rhizome_bid_t etc from "rhizome.h" into "rhizome_types.h" Do not include "serval.h" in library sources Add log_stderr.c and logMessage.c for stand-alone executables
This commit is contained in:
parent
06f7eed260
commit
21f51965c1
@ -6,6 +6,7 @@ include $(LOCAL_PATH)/sourcefiles.mk
|
|||||||
SERVALD_SRC_FILES = \
|
SERVALD_SRC_FILES = \
|
||||||
$(SQLITE3_SOURCES) \
|
$(SQLITE3_SOURCES) \
|
||||||
$(SERVAL_CLIENT_SOURCES) \
|
$(SERVAL_CLIENT_SOURCES) \
|
||||||
|
$(MDP_CLIENT_SOURCES) \
|
||||||
$(SERVAL_DAEMON_SOURCES) \
|
$(SERVAL_DAEMON_SOURCES) \
|
||||||
$(ANDROIDONLY_SOURCES)
|
$(ANDROIDONLY_SOURCES)
|
||||||
NACL_BASE = nacl/src
|
NACL_BASE = nacl/src
|
||||||
|
126
Makefile.in
126
Makefile.in
@ -10,26 +10,25 @@ include $(NACL_BASE)/nacl.mk
|
|||||||
include sourcefiles.mk
|
include sourcefiles.mk
|
||||||
include headerfiles.mk
|
include headerfiles.mk
|
||||||
|
|
||||||
SERVALD_SRCS = \
|
SERVAL_DAEMON_OBJS = \
|
||||||
$(SQLITE3_SOURCES) \
|
$(addprefix objs_servald/, $(SERVAL_CLIENT_SOURCES:.c=.o)) \
|
||||||
$(NACL_SOURCES) \
|
$(addprefix objs_servald/, $(MDP_CLIENT_SOURCES:.c=.o)) \
|
||||||
$(SERVAL_CLIENT_SOURCES) \
|
$(addprefix objs_servald/, $(SERVAL_DAEMON_SOURCES:.c=.o))
|
||||||
$(SERVAL_DAEMON_SOURCES)
|
SERVALD_OBJS = \
|
||||||
|
$(addprefix objs_servald/, $(notdir $(SQLITE3_SOURCES:.c=.o))) \
|
||||||
|
$(addprefix objs_servald/, $(NACL_SOURCES:.c=.o)) \
|
||||||
|
$(SERVAL_DAEMON_OBJS)
|
||||||
|
LIB_SERVAL_OBJS = \
|
||||||
|
$(addprefix objs_lib/, $(SERVAL_CLIENT_SOURCES:.c=.o)) \
|
||||||
|
$(addprefix objs_lib/, $(SERVAL_LIB_SOURCES:.c=.o)) \
|
||||||
|
$(addprefix objs_lib/, $(MDP_CLIENT_SOURCES:.c=.o))
|
||||||
|
|
||||||
MONITOR_CLIENT_SRCS = \
|
MONITOR_CLIENT_OBJS = \
|
||||||
$(SERVAL_CLIENT_SOURCES) \
|
$(addprefix objs_lib/, $(SERVAL_CLIENT_SOURCES:.c=.o)) \
|
||||||
monitor-client.c
|
$(addprefix objs_lib/, $(MONITOR_CLIENT_SRCS:.c=.o))
|
||||||
|
|
||||||
MDP_CLIENT_SRCS = \
|
SIMULATOR_OBJS = \
|
||||||
$(SERVAL_CLIENT_SOURCES) \
|
$(addprefix objs/, $(SIMULATOR_SOURCES:.c=.o))
|
||||||
mdp_client.c \
|
|
||||||
mdp_net.c
|
|
||||||
|
|
||||||
SERVALD_OBJS= $(SERVALD_SRCS:.c=.o)
|
|
||||||
SERVAL_DAEMON_OBJS= $(SERVAL_DAEMON_SOURCES:.c=.o)
|
|
||||||
MONITOR_CLIENT_OBJS= $(MONITOR_CLIENT_SRCS:.c=.o)
|
|
||||||
MDP_CLIENT_OBJS= $(MDP_CLIENT_SRCS:.c=.o)
|
|
||||||
SIMULATOR_OBJS= $(SIMULATOR_SOURCES:.c=.o)
|
|
||||||
|
|
||||||
LDFLAGS=@LDFLAGS@ @LIBS@ @PTHREAD_LIBS@
|
LDFLAGS=@LDFLAGS@ @LIBS@ @PTHREAD_LIBS@
|
||||||
|
|
||||||
@ -61,54 +60,75 @@ all: servald libmonitorclient.so libmonitorclient.a test
|
|||||||
|
|
||||||
test: tfw_createfile directory_service fakeradio config_test simulator
|
test: tfw_createfile directory_service fakeradio config_test simulator
|
||||||
|
|
||||||
sqlite-amalgamation-3070900/sqlite3.o: sqlite-amalgamation-3070900/sqlite3.c
|
|
||||||
@echo CC $<
|
|
||||||
@$(CC) $(CFLAGS) $(DEFS) -c $< -o sqlite-amalgamation-3070900/sqlite3.o
|
|
||||||
|
|
||||||
version.o: $(SERVALD_OBJS) version_string.sh $(wildcard VERSION.txt) COPYRIGHT.txt Makefile
|
|
||||||
@echo CC version_servald.c
|
|
||||||
@V=`./version_string.sh --ignore-untracked` \
|
|
||||||
&& C="`sed -e :a -e N -e '$$!ba' -e 's/[\\\\"]/\\\\&/g' -e 's/\\n/\\\\n/g' COPYRIGHT.txt`" \
|
|
||||||
&& $(CC) -c version_servald.c -o $@ -DSERVALD_VERSION="\"$$V\"" -DSERVALD_COPYRIGHT="\"$$C\""
|
|
||||||
|
|
||||||
Makefile: $(wildcard Makefile.in) $(wildcard configure)
|
Makefile: $(wildcard Makefile.in) $(wildcard configure)
|
||||||
$(warning Makefile may be out of date, please run ./configure)
|
$(warning Makefile may be out of date, please run ./configure)
|
||||||
|
|
||||||
configure: $(wildcard configure.in)
|
configure: $(wildcard configure.in)
|
||||||
$(warning configure may be out of date, please run autoreconf -f -i)
|
$(warning configure may be out of date, please run autoreconf -f -i)
|
||||||
|
|
||||||
|
objs/version.o: $(SERVALD_OBJS) version_string.sh $(wildcard VERSION.txt) COPYRIGHT.txt Makefile
|
||||||
|
@echo CC version_servald.c
|
||||||
|
@V=`./version_string.sh --ignore-untracked` \
|
||||||
|
&& C="`sed -e :a -e N -e '$$!ba' -e 's/[\\\\"]/\\\\&/g' -e 's/\\n/\\\\n/g' COPYRIGHT.txt`" \
|
||||||
|
&& $(CC) -c version_servald.c -o $@ -DSERVALD_VERSION="\"$$V\"" -DSERVALD_COPYRIGHT="\"$$C\""
|
||||||
|
|
||||||
|
#' <-- fixes vim syntax highlighting
|
||||||
|
|
||||||
|
objs_servald/sqlite3.o: sqlite-amalgamation-3070900/sqlite3.c
|
||||||
|
@echo SERVALD CC $<
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
@$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
|
||||||
|
|
||||||
|
# No object files in source directory!
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
|
|
||||||
|
objs/%.o: %.c
|
||||||
@echo CC $<
|
@echo CC $<
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
@$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
|
||||||
|
|
||||||
|
objs_servald/%.o: %.c
|
||||||
|
@echo SERVALD CC $<
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
@$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
|
||||||
|
|
||||||
|
objs_lib/%.o: %.c
|
||||||
|
@echo LIB CC $<
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
@$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
|
@$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
|
||||||
|
|
||||||
$(SERVAL_DAEMON_OBJS): $(HDRS)
|
$(SERVAL_DAEMON_OBJS): $(HDRS)
|
||||||
|
$(LIB_SERVAL_OBJS): $(HDRS)
|
||||||
$(MONITOR_CLIENT_OBJS): $(HDRS)
|
$(MONITOR_CLIENT_OBJS): $(HDRS)
|
||||||
$(MDP_CLIENT_OBJS): $(HDRS)
|
|
||||||
$(SIMULATOR_OBJS): $(HDRS)
|
$(SIMULATOR_OBJS): $(HDRS)
|
||||||
|
|
||||||
servald: $(SERVALD_OBJS) version.o
|
servald: $(SERVALD_OBJS) objs/version.o
|
||||||
@echo LINK $@
|
@echo LINK $@
|
||||||
@$(CC) $(CFLAGS) -Wall -o $@ $(SERVALD_OBJS) version.o $(LDFLAGS)
|
@$(CC) $(CFLAGS) -Wall -o $@ $(SERVALD_OBJS) objs/version.o $(LDFLAGS)
|
||||||
|
|
||||||
directory_service: $(MDP_CLIENT_OBJS) version.o directory_service.o
|
libserval.a: $(LIB_SERVAL_OBJS) objs/version.o
|
||||||
@echo LINK $@
|
@echo AR $@
|
||||||
@$(CC) $(CFLAGS) -Wall -o $@ $(MDP_CLIENT_OBJS) version.o directory_service.o $(LDFLAGS)
|
@$(AR) -cr $@ $(LIB_SERVAL_OBJS) objs/version.o
|
||||||
|
|
||||||
tfw_createfile: tfw_createfile.o str.o strbuf.o strbuf_helpers.o
|
directory_service: objs/directory_service.o libserval.a
|
||||||
@echo LINK $@
|
@echo LINK $@
|
||||||
@$(CC) $(CFLAGS) -Wall -o $@ tfw_createfile.o str.o strbuf.o strbuf_helpers.o
|
@$(CC) $(CFLAGS) -Wall -o $@ objs/directory_service.o libserval.a $(LDFLAGS)
|
||||||
|
|
||||||
fakeradio: fakeradio.o
|
tfw_createfile: objs/tfw_createfile.o libserval.a
|
||||||
@echo LINK $@
|
@echo LINK $@
|
||||||
@$(CC) $(CFLAGS) -Wall -o $@ fakeradio.o
|
@$(CC) $(CFLAGS) -Wall -o $@ objs/tfw_createfile.o libserval.a $(LDFLAGS)
|
||||||
|
|
||||||
simulator: $(SIMULATOR_OBJS)
|
fakeradio: objs/fakeradio.o libserval.a
|
||||||
@echo LINK $@
|
@echo LINK $@
|
||||||
@$(CC) $(CFLAGS) -Wall -o $@ $(SIMULATOR_OBJS) $(LDFLAGS)
|
@$(CC) $(CFLAGS) -Wall -o $@ objs/fakeradio.o libserval.a $(LDFLAGS)
|
||||||
|
|
||||||
config_test: config_test.o conf_om.o conf_schema.o conf_parse.o str.o strbuf.o strbuf_helpers.o mem.o dataformats.o net.o log_util.o
|
simulator: $(SIMULATOR_OBJS) libserval.a
|
||||||
@echo LINK $@
|
@echo LINK $@
|
||||||
@$(CC) $(CFLAGS) -Wall -o $@ config_test.o conf_om.o conf_schema.o conf_parse.o str.o strbuf.o strbuf_helpers.o mem.o dataformats.o net.o log_util.o $(LDFLAGS)
|
@$(CC) $(CFLAGS) -Wall -o $@ $(SIMULATOR_OBJS) libserval.a $(LDFLAGS)
|
||||||
|
|
||||||
|
config_test: objs/config_test.o objs/conf_om.o objs/conf_schema.o objs/conf_parse.o libserval.a
|
||||||
|
@echo LINK $@
|
||||||
|
@$(CC) $(CFLAGS) -Wall -o $@ objs/config_test.o objs/conf_om.o objs/conf_schema.o objs/conf_parse.o libserval.a $(LDFLAGS)
|
||||||
|
|
||||||
copyright:
|
copyright:
|
||||||
@if [ -x "$(COPYRIGHT_TOOL)" ]; then \
|
@if [ -x "$(COPYRIGHT_TOOL)" ]; then \
|
||||||
@ -123,17 +143,17 @@ COPYRIGHT_TOOL := $(call findPATH,sp-copyright-tool)
|
|||||||
|
|
||||||
# This does not build on 64 bit elf platforms as NaCL isn't built with -fPIC
|
# This does not build on 64 bit elf platforms as NaCL isn't built with -fPIC
|
||||||
# DOC 20120615
|
# DOC 20120615
|
||||||
libserval.so: $(SERVALD_OBJS) version.o
|
libserval.so: $(SERVALD_OBJS) objs/version.o
|
||||||
@echo LINK $@
|
@echo LINK $@
|
||||||
@$(CC) $(CFLAGS) -Wall -shared -o $@ $(SERVALD_OBJS) version.o $(LDFLAGS)
|
@$(CC) $(CFLAGS) -Wall -shared -o $@ $(SERVALD_OBJS) objs/version.o $(LDFLAGS)
|
||||||
|
|
||||||
libmonitorclient.so: $(MONITOR_CLIENT_OBJS) version.o
|
libmonitorclient.so: $(MONITOR_CLIENT_OBJS) objs/version.o
|
||||||
@echo LINK $@
|
@echo LINK $@
|
||||||
@$(CC) $(CFLAGS) -Wall -shared -o $@ $(MONITOR_CLIENT_OBJS) version.o $(LDFLAGS)
|
@$(CC) $(CFLAGS) -Wall -shared -o $@ $(MONITOR_CLIENT_OBJS) objs/version.o $(LDFLAGS)
|
||||||
|
|
||||||
libmonitorclient.a: $(MONITOR_CLIENT_OBJS) version.o
|
libmonitorclient.a: $(MONITOR_CLIENT_OBJS) objs/version.o
|
||||||
@echo AR $@
|
@echo AR $@
|
||||||
@$(AR) -cr $@ $(MONITOR_CLIENT_OBJS) version.o
|
@$(AR) -cr $@ $(MONITOR_CLIENT_OBJS) objs/version.o
|
||||||
|
|
||||||
install: servald
|
install: servald
|
||||||
$(INSTALL_PROGRAM) -D servald $(DESTDIR)$(sbindir)/servald
|
$(INSTALL_PROGRAM) -D servald $(DESTDIR)$(sbindir)/servald
|
||||||
@ -142,8 +162,8 @@ uninstall:
|
|||||||
$(RM) $(DESTDIR)$(sbindir)/servald
|
$(RM) $(DESTDIR)$(sbindir)/servald
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@$(RM) $(SERVALD_OBJS) $(MONITOR_CLIENT_OBJS) $(MDP_CLIENT_OBJS) \
|
@$(RM) -r objs/* objs_servald/* objs_lib/* \
|
||||||
tfw_createfile.o version.o \
|
servald libservald.so \
|
||||||
fakeradio.o fakeradio \
|
libserval.a libmonitorclient.so libmonitorclient.a \
|
||||||
tfw_createfile servald \
|
fakeradio \
|
||||||
libservald.so libmonitorclient.so libmonitorclient.a
|
tfw_createfile
|
||||||
|
11
cli.c
11
cli.c
@ -18,14 +18,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <strings.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "cli.h"
|
#include "constants.h"
|
||||||
|
#include "serval_types.h"
|
||||||
|
#include "rhizome_types.h"
|
||||||
|
#include "fdqueue.h"
|
||||||
|
#include "os.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "serval.h"
|
#include "str.h"
|
||||||
#include "rhizome.h"
|
|
||||||
#include "strbuf_helpers.h"
|
#include "strbuf_helpers.h"
|
||||||
#include "dataformats.h"
|
#include "dataformats.h"
|
||||||
|
#include "cli.h"
|
||||||
|
|
||||||
int cli_usage(const struct cli_schema *commands, XPRINTF xpf)
|
int cli_usage(const struct cli_schema *commands, XPRINTF xpf)
|
||||||
{
|
{
|
||||||
|
@ -51,9 +51,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#ifdef HAVE_STRINGS_H
|
|
||||||
#include <strings.h>
|
|
||||||
#endif
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@ -70,6 +67,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
#include "strbuf_helpers.h"
|
#include "strbuf_helpers.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
|
#include "os.h"
|
||||||
#include "mdp_client.h"
|
#include "mdp_client.h"
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
#include "overlay_address.h"
|
#include "overlay_address.h"
|
||||||
|
2
conf.c
2
conf.c
@ -21,7 +21,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <inttypes.h> // for PRIu64 on Android
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
#include "instance.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
4
conf.h
4
conf.h
@ -229,9 +229,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
#include "serval_types.h"
|
||||||
|
#include "rhizome_types.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
#include "serval.h"
|
|
||||||
#include "rhizome.h"
|
|
||||||
#include "httpd.h"
|
#include "httpd.h"
|
||||||
|
|
||||||
#define CONFIG_FILE_MAX_SIZE (32 * 1024)
|
#define CONFIG_FILE_MAX_SIZE (32 * 1024)
|
||||||
|
@ -19,6 +19,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
#include "net.h"
|
||||||
|
#include "mem.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "mem.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
#include "strbuf_helpers.h"
|
#include "strbuf_helpers.h"
|
||||||
|
@ -108,46 +108,6 @@ int main(int argc, char **argv)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct __sourceloc __whence = __NOWHERE__;
|
void cf_on_config_change()
|
||||||
|
|
||||||
static const char *_trimbuildpath(const char *path)
|
|
||||||
{
|
{
|
||||||
/* Remove common path prefix */
|
|
||||||
int lastsep = 0;
|
|
||||||
int i;
|
|
||||||
for (i = 0; __FILE__[i] && path[i]; ++i) {
|
|
||||||
if (i && path[i - 1] == '/')
|
|
||||||
lastsep = i;
|
|
||||||
if (__FILE__[i] != path[i])
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return &path[lastsep];
|
|
||||||
}
|
|
||||||
|
|
||||||
void logMessage(int level, struct __sourceloc whence, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
const char *levelstr = "UNKWN:";
|
|
||||||
switch (level) {
|
|
||||||
case LOG_LEVEL_FATAL: levelstr = "FATAL:"; break;
|
|
||||||
case LOG_LEVEL_ERROR: levelstr = "ERROR:"; break;
|
|
||||||
case LOG_LEVEL_INFO: levelstr = "INFO:"; break;
|
|
||||||
case LOG_LEVEL_WARN: levelstr = "WARN:"; break;
|
|
||||||
case LOG_LEVEL_DEBUG: levelstr = "DEBUG:"; break;
|
|
||||||
}
|
|
||||||
fprintf(stderr, "%s ", levelstr);
|
|
||||||
if (whence.file) {
|
|
||||||
fprintf(stderr, "%s", _trimbuildpath(whence.file));
|
|
||||||
if (whence.line)
|
|
||||||
fprintf(stderr, ":%u", whence.line);
|
|
||||||
if (whence.function)
|
|
||||||
fprintf(stderr, ":%s()", whence.function);
|
|
||||||
fputc(' ', stderr);
|
|
||||||
} else if (whence.function) {
|
|
||||||
fprintf(stderr, "%s() ", whence.function);
|
|
||||||
}
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vfprintf(stderr, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
fputc('\n', stderr);
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
Interactive console primitives
|
||||||
Copyright (C) 2014 Serval Project Inc.
|
Copyright (C) 2014 Serval Project Inc.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
@ -16,10 +17,15 @@
|
|||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef __SERVAL_DNA__CONSOLE_H
|
||||||
|
#define __SERVAL_DNA__CONSOLE_H
|
||||||
|
|
||||||
|
#include "cli.h"
|
||||||
|
|
||||||
struct command_state;
|
struct command_state;
|
||||||
struct command_state *command_register(struct cli_schema *commands, int fd);
|
struct command_state *command_register(struct cli_schema *commands, int fd);
|
||||||
uint8_t is_command_closed(struct command_state *state);
|
uint8_t is_command_closed(struct command_state *state);
|
||||||
void command_close(struct command_state *state);
|
void command_close(struct command_state *state);
|
||||||
void command_free(struct command_state *state);
|
void command_free(struct command_state *state);
|
||||||
|
|
||||||
|
#endif // __SERVAL_DNA__CONSOLE_H
|
||||||
|
11
constants.h
11
constants.h
@ -32,12 +32,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
# define UNUSED(x) x
|
# define UNUSED(x) x
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SID_SIZE 32 // == crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES
|
// UDP Port numbers for various Serval services.
|
||||||
#define SAS_SIZE 32 // == crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES
|
#define PORT_DNA 4110
|
||||||
#define DID_MINSIZE 5
|
|
||||||
#define DID_MAXSIZE 32
|
|
||||||
|
|
||||||
#define SID_STRLEN (SID_SIZE*2)
|
|
||||||
|
|
||||||
#define OVERLAY_MAX_INTERFACES 16
|
#define OVERLAY_MAX_INTERFACES 16
|
||||||
|
|
||||||
@ -191,7 +187,4 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#define UNLOCK_CHALLENGE (0xF1)
|
#define UNLOCK_CHALLENGE (0xF1)
|
||||||
#define UNLOCK_RESPONSE (0xF2)
|
#define UNLOCK_RESPONSE (0xF2)
|
||||||
|
|
||||||
// should there be a types.h to hold this?
|
|
||||||
typedef char bool_t;
|
|
||||||
|
|
||||||
#endif // __SERVAL_DNA__CONSTANTS_H
|
#endif // __SERVAL_DNA__CONSTANTS_H
|
||||||
|
@ -17,9 +17,11 @@ along with this program; if not, write to the Free Software
|
|||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define __RHIZOME_TYPES_INLINE
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "serval.h"
|
#include "serval_types.h"
|
||||||
#include "rhizome.h"
|
#include "rhizome_types.h"
|
||||||
|
#include "os.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "dataformats.h"
|
#include "dataformats.h"
|
||||||
|
|
||||||
|
@ -30,13 +30,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "serval.h"
|
#include "serval_types.h"
|
||||||
|
#include "cli.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "overlay_address.h"
|
#include "overlay_address.h"
|
||||||
#include "overlay_packet.h"
|
#include "overlay_packet.h"
|
||||||
#include "overlay_buffer.h"
|
#include "overlay_buffer.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "keyring.h"
|
#include "keyring.h"
|
||||||
|
#include "serval.h" // for overlay_send_frame()
|
||||||
|
|
||||||
struct subscriber *directory_service;
|
struct subscriber *directory_service;
|
||||||
|
|
||||||
|
@ -51,13 +51,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include "serval.h"
|
#include "sighandlers.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
#include "strbuf_helpers.h"
|
#include "strbuf_helpers.h"
|
||||||
#include "overlay_address.h"
|
|
||||||
#include "dataformats.h"
|
#include "dataformats.h"
|
||||||
|
#include "overlay_address.h"
|
||||||
|
#include "serval.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The challenge with making an interface for calling an external program to
|
The challenge with making an interface for calling an external program to
|
||||||
|
22
fakeradio.c
22
fakeradio.c
@ -29,9 +29,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <strings.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#define PACKET_SIZE 255
|
#define PACKET_SIZE 255
|
||||||
int chars_per_ms=1;
|
int chars_per_ms=1;
|
||||||
@ -130,25 +129,6 @@ int processCommand(struct radio_state *s)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dump(char *name, unsigned char *addr, size_t len)
|
|
||||||
{
|
|
||||||
unsigned i,j;
|
|
||||||
if (name)
|
|
||||||
fprintf(stderr,"Dump of %s\n",name);
|
|
||||||
for(i=0;i<len;i+=16){
|
|
||||||
fprintf(stderr," %04x :",i);
|
|
||||||
for(j=0;j<16&&(i+j)<len;j++)
|
|
||||||
fprintf(stderr," %02x",addr[i+j]);
|
|
||||||
for(;j<16;j++)
|
|
||||||
fprintf(stderr," ");
|
|
||||||
fprintf(stderr," ");
|
|
||||||
for(j=0;j<16&&(i+j)<len;j++)
|
|
||||||
fprintf(stderr,"%c",addr[i+j]>=' '&&addr[i+j]<0x7f?addr[i+j]:'.');
|
|
||||||
fprintf(stderr,"\n");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void store_char(struct radio_state *s, unsigned char c)
|
static void store_char(struct radio_state *s, unsigned char c)
|
||||||
{
|
{
|
||||||
if(s->txb_len<sizeof(s->txbuffer)){
|
if(s->txb_len<sizeof(s->txbuffer)){
|
||||||
|
@ -46,8 +46,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
POSSIBILITY OF SUCH DAMAGE.
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <inttypes.h> // for PRIu64 on Android
|
||||||
#include "fdqueue.h"
|
#include "fdqueue.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
#include "net.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
#include "strbuf_helpers.h"
|
#include "strbuf_helpers.h"
|
||||||
|
@ -9,6 +9,7 @@ HDRS= fifo.h \
|
|||||||
httpd.h \
|
httpd.h \
|
||||||
instance.h \
|
instance.h \
|
||||||
meshms.h \
|
meshms.h \
|
||||||
|
serval_types.h \
|
||||||
serval.h \
|
serval.h \
|
||||||
keyring.h \
|
keyring.h \
|
||||||
socket.h \
|
socket.h \
|
||||||
@ -18,6 +19,7 @@ HDRS= fifo.h \
|
|||||||
mem.h \
|
mem.h \
|
||||||
os.h \
|
os.h \
|
||||||
uuid.h \
|
uuid.h \
|
||||||
|
sighandlers.h \
|
||||||
strbuf.h \
|
strbuf.h \
|
||||||
strbuf_helpers.h \
|
strbuf_helpers.h \
|
||||||
sha2.h \
|
sha2.h \
|
||||||
|
@ -20,9 +20,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include "serval.h"
|
#include "serval_types.h"
|
||||||
#include "conf.h"
|
|
||||||
#include "http_server.h"
|
#include "http_server.h"
|
||||||
|
#include "sighandlers.h"
|
||||||
|
#include "conf.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
|
@ -21,7 +21,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#define __SERVAL_DNA__HTTP_SERVER_H
|
#define __SERVAL_DNA__HTTP_SERVER_H
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include "constants.h"
|
#include "serval_types.h"
|
||||||
|
#include "net.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
#include "strbuf_helpers.h"
|
#include "strbuf_helpers.h"
|
||||||
#include "fdqueue.h"
|
#include "fdqueue.h"
|
||||||
|
5
httpd.c
5
httpd.c
@ -17,11 +17,14 @@ along with this program; if not, write to the Free Software
|
|||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/ioctl.h>
|
||||||
#include "serval.h"
|
#include "serval.h"
|
||||||
#include "conf.h"
|
|
||||||
#include "httpd.h"
|
#include "httpd.h"
|
||||||
|
#include "conf.h"
|
||||||
#include "overlay_address.h"
|
#include "overlay_address.h"
|
||||||
#include "overlay_interface.h"
|
#include "overlay_interface.h"
|
||||||
|
#include "mem.h"
|
||||||
|
#include "net.h"
|
||||||
|
|
||||||
#define RHIZOME_SERVER_MAX_LIVE_REQUESTS 32
|
#define RHIZOME_SERVER_MAX_LIVE_REQUESTS 32
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "serval.h"
|
#include "instance.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
|
3
log.c
3
log.c
@ -36,7 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#define __SERVAL_LOG_INLINE
|
#include "serval.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
@ -47,7 +47,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include "xprintf.h"
|
#include "xprintf.h"
|
||||||
|
|
||||||
int serverMode = 0;
|
int serverMode = 0;
|
||||||
const struct __sourceloc __whence = __NOWHERE__;
|
|
||||||
|
|
||||||
#define NO_FILE ((FILE *)1)
|
#define NO_FILE ((FILE *)1)
|
||||||
|
|
||||||
|
64
log.h
64
log.h
@ -19,70 +19,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#ifndef __SERVAL_DNA__LOG_H
|
#ifndef __SERVAL_DNA__LOG_H
|
||||||
#define __SERVAL_DNA__LOG_H
|
#define __SERVAL_DNA__LOG_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <sys/types.h> // for size_t
|
||||||
|
#include <stdio.h> // for NULL
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include "whence.h"
|
||||||
/*
|
|
||||||
* Every log message identifies the location in the source code at which the
|
|
||||||
* message was produced. This location is represented by a struct __sourceloc,
|
|
||||||
* which is passed by value to the logMessage() function and its ilk.
|
|
||||||
*
|
|
||||||
* A struct __sourceloc value is generated by the __HERE__ macro, which uses
|
|
||||||
* the cpp(1) built-in macros __FILE__, __LINE__ and __FUNCTION__ to generate
|
|
||||||
* its elements. The __NOWHERE__ macro creates a struct __sourceloc with NULL
|
|
||||||
* and zero fields. If you pass __NOWHERE__ to logMessage(), it will omit
|
|
||||||
* location information from the log line. The __NOWHENCE__ macro creates a
|
|
||||||
* special source __sourceloc that logging primitives should interpret to
|
|
||||||
* suppress the output of the usual source-code location information.
|
|
||||||
*
|
|
||||||
* Sometimes, a function wants to log a message as though its caller were the
|
|
||||||
* origin of the message. This is typical of "primitive" type functions that
|
|
||||||
* are used in many places throughout the code, and whose internal workings are
|
|
||||||
* generally well-debugged and of little interest for ongoing development. In
|
|
||||||
* this case, the code pattern is to declare the underscore-prefixed function
|
|
||||||
* as taking a struct __sourceloc argument, and a macro that invokes the
|
|
||||||
* function, passing the __HERE__ macro for that argument:
|
|
||||||
*
|
|
||||||
* int _primitive(struct __sourceloc __whence, int arg1, const char *arg2);
|
|
||||||
*
|
|
||||||
* #define primitive(arg1, arg2) _primitive(__HERE__, (arg1), (arg2))
|
|
||||||
*
|
|
||||||
* Within the _primitive() function, the standard logging macros defined below
|
|
||||||
* (WHYF(), WARNF(), INFOF(), DEBUGF() etc.) will use the __whence argument
|
|
||||||
* instead of __HERE__ when logging their message. This is achieved using a
|
|
||||||
* dirty trick: in the function *definition*, the __sourceloc argument MUST be
|
|
||||||
* named '__whence'. The trick is that there is a global variable called
|
|
||||||
* '__whence' which always contains the value of __NOWHERE__. If that variable
|
|
||||||
* is lexically obscured by a local variable or parameter called '__whence',
|
|
||||||
* then the DEBUG macros will use __whence, otherwise they will use __HERE__.
|
|
||||||
* This logic is encapsulated in the __WHENCE__ macro, to make it available to
|
|
||||||
* for other purposes. For example, a better definition of the primitive()
|
|
||||||
* macro above would be:
|
|
||||||
*
|
|
||||||
* #define primitive(arg1, arg2) _primitive(__WHENCE__, (arg1), (arg2))
|
|
||||||
*
|
|
||||||
* Then, if it were invoked from within another primitive-type function, it
|
|
||||||
* would log messages with the __sourceloc of that primitive's caller, which is
|
|
||||||
* probably the most useful for diagnosis.
|
|
||||||
*
|
|
||||||
* @author Andrew Bettison <andrew@servalproject.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct __sourceloc {
|
|
||||||
const char *file;
|
|
||||||
unsigned int line;
|
|
||||||
const char *function;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern const struct __sourceloc __whence; // see above
|
|
||||||
|
|
||||||
#define __HERE__ ((struct __sourceloc){ .file = __FILE__, .line = __LINE__, .function = __FUNCTION__ })
|
|
||||||
#define __NOWHERE__ ((struct __sourceloc){ .file = NULL, .line = 0, .function = NULL })
|
|
||||||
#define __NOWHENCE__ ((struct __sourceloc){ .file = "", .line = 0, .function = NULL })
|
|
||||||
#define __WHENCE__ (__whence.file ? __whence : __HERE__)
|
|
||||||
|
|
||||||
#ifndef __SERVAL_LOG_INLINE
|
#ifndef __SERVAL_LOG_INLINE
|
||||||
# if __GNUC__ && !__GNUC_STDC_INLINE__
|
# if __GNUC__ && !__GNUC_STDC_INLINE__
|
||||||
|
24
logMessage.c
Normal file
24
logMessage.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
Serval DNA logging
|
||||||
|
Copyright 2013-2014 Serval Project Inc.
|
||||||
|
|
||||||
|
This program 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
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This compilation unit simply provides a statically linkable logMessage() function for those other
|
||||||
|
// units that did not inline it.
|
||||||
|
|
||||||
|
#define __SERVAL_LOG_INLINE
|
||||||
|
#include "log.h"
|
96
log_stderr.c
Normal file
96
log_stderr.c
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
Serval logging to standard error
|
||||||
|
Copyright 2014 Serval Project Inc.
|
||||||
|
|
||||||
|
This program 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
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
/* An implementation of the Serval logging API that writes directly to standard error
|
||||||
|
* using stdio buffered output.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int serverMode=0;
|
||||||
|
|
||||||
|
static const char *_trimbuildpath(const char *path)
|
||||||
|
{
|
||||||
|
/* Remove common path prefix */
|
||||||
|
int lastsep = 0;
|
||||||
|
int i;
|
||||||
|
for (i = 0; __FILE__[i] && path[i]; ++i) {
|
||||||
|
if (i && path[i - 1] == '/')
|
||||||
|
lastsep = i;
|
||||||
|
if (__FILE__[i] != path[i])
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return &path[lastsep];
|
||||||
|
}
|
||||||
|
|
||||||
|
void vlogMessage(int level, struct __sourceloc whence, const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
const char *levelstr = "UNKWN:";
|
||||||
|
switch (level) {
|
||||||
|
case LOG_LEVEL_FATAL:
|
||||||
|
levelstr = "FATAL:";
|
||||||
|
break;
|
||||||
|
case LOG_LEVEL_ERROR:
|
||||||
|
levelstr = "ERROR:";
|
||||||
|
break;
|
||||||
|
case LOG_LEVEL_INFO:
|
||||||
|
levelstr = "INFO:";
|
||||||
|
break;
|
||||||
|
case LOG_LEVEL_WARN:
|
||||||
|
levelstr = "WARN:";
|
||||||
|
break;
|
||||||
|
case LOG_LEVEL_DEBUG:
|
||||||
|
levelstr = "DEBUG:";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct timeval tv;
|
||||||
|
struct tm tm;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
localtime_r(&tv.tv_sec, &tm);
|
||||||
|
char buf[50];
|
||||||
|
strftime(buf, sizeof buf, "%T", &tm);
|
||||||
|
fprintf(stderr, "%s.%03u ", buf, (unsigned int)tv.tv_usec / 1000);
|
||||||
|
|
||||||
|
fprintf(stderr, "%s ", levelstr);
|
||||||
|
if (whence.file) {
|
||||||
|
fprintf(stderr, "%s", _trimbuildpath(whence.file));
|
||||||
|
if (whence.line)
|
||||||
|
fprintf(stderr, ":%u", whence.line);
|
||||||
|
if (whence.function)
|
||||||
|
fprintf(stderr, ":%s()", whence.function);
|
||||||
|
fputc(' ', stderr);
|
||||||
|
} else if (whence.function) {
|
||||||
|
fprintf(stderr, "%s() ", whence.function);
|
||||||
|
}
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
fputc('\n', stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logFlush()
|
||||||
|
{
|
||||||
|
fflush(stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logConfigChanged()
|
||||||
|
{
|
||||||
|
}
|
1
main.c
1
main.c
@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software
|
|||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
#include "serval.h"
|
#include "serval.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <inttypes.h> // for PRIx64 on Android
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "serval.h"
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
|
@ -19,6 +19,10 @@
|
|||||||
#ifndef __SERVAL_DNA__MDP_CLIENT_H
|
#ifndef __SERVAL_DNA__MDP_CLIENT_H
|
||||||
#define __SERVAL_DNA__MDP_CLIENT_H
|
#define __SERVAL_DNA__MDP_CLIENT_H
|
||||||
|
|
||||||
|
#include "constants.h"
|
||||||
|
#include "serval_types.h"
|
||||||
|
#include "os.h"
|
||||||
|
#include "net.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
// define 3rd party mdp API without any structure padding
|
// define 3rd party mdp API without any structure padding
|
||||||
|
@ -17,7 +17,9 @@
|
|||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "serval.h"
|
#include <inttypes.h> // for PRIx64 on Android
|
||||||
|
#include "serval_types.h"
|
||||||
|
#include "instance.h"
|
||||||
#include "overlay_address.h"
|
#include "overlay_address.h"
|
||||||
#include "overlay_packet.h"
|
#include "overlay_packet.h"
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
2
meshms.c
2
meshms.c
@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#define __MESHMS_INLINE
|
#define __MESHMS_INLINE
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "serval.h"
|
#include "serval.h"
|
||||||
#include "rhizome.h"
|
#include "rhizome_types.h"
|
||||||
#include "meshms.h"
|
#include "meshms.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
1
meshms.h
1
meshms.h
@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "serval.h"
|
|
||||||
#include "rhizome.h"
|
#include "rhizome.h"
|
||||||
|
|
||||||
#define MESHMS_MESSAGE_MAX_LEN 4095
|
#define MESHMS_MESSAGE_MAX_LEN 4095
|
||||||
|
@ -21,10 +21,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#ifdef HAVE_STRINGS_H
|
|
||||||
#include <strings.h>
|
|
||||||
#endif
|
|
||||||
#include <string.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
@ -19,10 +19,11 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include "serval.h"
|
#include "serval_types.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "mdp_client.h"
|
#include "mdp_client.h"
|
||||||
#include "msp_client.h"
|
#include "msp_client.h"
|
||||||
|
#include "mem.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "dataformats.h"
|
#include "dataformats.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#ifndef __SERVAL_DNA__MSP_CLIENT_H
|
#ifndef __SERVAL_DNA__MSP_CLIENT_H
|
||||||
#define __SERVAL_DNA__MSP_CLIENT_H
|
#define __SERVAL_DNA__MSP_CLIENT_H
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h" // for MDP_MTU
|
||||||
|
|
||||||
#ifndef __MSP_CLIENT_INLINE
|
#ifndef __MSP_CLIENT_INLINE
|
||||||
# if __GNUC__ && !__GNUC_STDC_INLINE__
|
# if __GNUC__ && !__GNUC_STDC_INLINE__
|
||||||
|
11
msp_proxy.c
11
msp_proxy.c
@ -17,13 +17,18 @@
|
|||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "serval.h"
|
#include <signal.h>
|
||||||
|
#include "serval_types.h"
|
||||||
|
#include "mdp_client.h"
|
||||||
|
#include "msp_client.h"
|
||||||
|
#include "fdqueue.h"
|
||||||
|
#include "cli.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "mem.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
#include "strbuf_helpers.h"
|
#include "strbuf_helpers.h"
|
||||||
#include "dataformats.h"
|
#include "dataformats.h"
|
||||||
#include "mdp_client.h"
|
|
||||||
#include "msp_client.h"
|
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
struct buffer{
|
struct buffer{
|
||||||
|
2
net.c
2
net.c
@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "serval.h"
|
#include "serval_types.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
11
net.h
11
net.h
@ -24,7 +24,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#ifdef HAVE_NETINET_IN_H
|
#ifdef HAVE_NETINET_IN_H
|
||||||
#include <netinet/in.h> // for struct in_addr
|
#include <netinet/in.h> // for struct in_addr
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(FORASTERISK) && !defined(s_addr)
|
||||||
|
#ifdef HAVE_ARPA_INET_H
|
||||||
#include <arpa/inet.h> // for in_addr_t
|
#include <arpa/inet.h> // for in_addr_t
|
||||||
|
#else
|
||||||
|
typedef uint32_t in_addr_t;
|
||||||
|
struct in_addr {
|
||||||
|
in_addr_t s_addr;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "log.h" // for __WHENCE__ and struct __sourceloc
|
#include "log.h" // for __WHENCE__ and struct __sourceloc
|
||||||
|
|
||||||
/* Build a struct in_addr from a host-byte-order integer.
|
/* Build a struct in_addr from a host-byte-order integer.
|
||||||
|
4
nonce.c
4
nonce.c
@ -17,7 +17,9 @@ along with this program; if not, write to the Free Software
|
|||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "serval.h"
|
#include "constants.h"
|
||||||
|
#include "os.h"
|
||||||
|
#include "cli.h"
|
||||||
|
|
||||||
int nonce_initialised=0;
|
int nonce_initialised=0;
|
||||||
unsigned char nonce_buffer[128];
|
unsigned char nonce_buffer[128];
|
||||||
|
12
os.h
12
os.h
@ -20,11 +20,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#ifndef __SERVAL_DNA__OS_H
|
#ifndef __SERVAL_DNA__OS_H
|
||||||
#define __SERVAL_DNA__OS_H
|
#define __SERVAL_DNA__OS_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <sys/types.h> // for off64_t
|
||||||
|
#include <stdio.h> // for NULL
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h> // for int64_t
|
||||||
#include <unistd.h>
|
#include <unistd.h> // for lseek()
|
||||||
#include <sys/types.h>
|
#ifdef HAVE_STRINGS_H
|
||||||
|
#include <strings.h> // for bcopy()
|
||||||
|
#endif
|
||||||
|
#include <string.h> // for memcmp()
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#ifndef __SERVAL_DNA__OS_INLINE
|
#ifndef __SERVAL_DNA__OS_INLINE
|
||||||
|
@ -21,7 +21,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#define __SERVAL_DNA__OVERLAY_ADDRESS_H
|
#define __SERVAL_DNA__OVERLAY_ADDRESS_H
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
#include "os.h" // for time_ms_t
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
#include "overlay_buffer.h" // for struct overlay_buffer
|
||||||
|
|
||||||
// not reachable
|
// not reachable
|
||||||
#define REACHABLE_NONE 0
|
#define REACHABLE_NONE 0
|
||||||
|
@ -21,8 +21,7 @@
|
|||||||
#define __SERVAL_DNA__OVERLAY_PACKET_H
|
#define __SERVAL_DNA__OVERLAY_PACKET_H
|
||||||
|
|
||||||
#include "overlay_address.h"
|
#include "overlay_address.h"
|
||||||
#include "serval.h"
|
#include "serval_types.h"
|
||||||
#include "conf.h"
|
|
||||||
|
|
||||||
#define FRAME_NOT_SENT -1
|
#define FRAME_NOT_SENT -1
|
||||||
#define FRAME_DONT_SEND -2
|
#define FRAME_DONT_SEND -2
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
POSSIBILITY OF SUCH DAMAGE.
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <inttypes.h> // for PRIu64 on Android
|
||||||
#include "fdqueue.h"
|
#include "fdqueue.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
|
|
||||||
|
82
rhizome.h
82
rhizome.h
@ -22,12 +22,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#define __SERVAL_DNA__RHIZOME_H
|
#define __SERVAL_DNA__RHIZOME_H
|
||||||
|
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
#include <limits.h>
|
#include "serval_types.h"
|
||||||
#include "sha2.h"
|
#include "rhizome_types.h"
|
||||||
|
#include "overlay_address.h"
|
||||||
|
#include "overlay_packet.h"
|
||||||
|
#include "fdqueue.h"
|
||||||
|
#include "os.h"
|
||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
#include "nacl.h"
|
|
||||||
|
|
||||||
#ifndef __RHIZOME_INLINE
|
#ifndef __RHIZOME_INLINE
|
||||||
# if __GNUC__ && !__GNUC_STDC_INLINE__
|
# if __GNUC__ && !__GNUC_STDC_INLINE__
|
||||||
@ -37,80 +40,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define RHIZOME_BUNDLE_ID_BYTES crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES
|
|
||||||
#define RHIZOME_BUNDLE_ID_STRLEN (RHIZOME_BUNDLE_ID_BYTES * 2)
|
|
||||||
#define RHIZOME_BUNDLE_KEY_BYTES (crypto_sign_edwards25519sha512batch_SECRETKEYBYTES - crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES)
|
|
||||||
#define RHIZOME_BUNDLE_KEY_STRLEN (RHIZOME_BUNDLE_KEY_BYTES * 2)
|
|
||||||
#define RHIZOME_FILEHASH_BYTES SHA512_DIGEST_LENGTH
|
|
||||||
#define RHIZOME_FILEHASH_STRLEN (RHIZOME_FILEHASH_BYTES * 2)
|
|
||||||
|
|
||||||
#define RHIZOME_CRYPT_KEY_BYTES crypto_stream_xsalsa20_ref_KEYBYTES
|
|
||||||
#define RHIZOME_CRYPT_KEY_STRLEN (RHIZOME_CRYPT_KEY_BYTES * 2)
|
|
||||||
|
|
||||||
// TODO Rename MANIFEST_ID to BUNDLE_ID
|
|
||||||
// The following constants are deprecated, use the BUNDLE_ID forms instead
|
|
||||||
#define RHIZOME_MANIFEST_ID_BYTES RHIZOME_BUNDLE_ID_BYTES
|
|
||||||
#define RHIZOME_MANIFEST_ID_STRLEN RHIZOME_BUNDLE_ID_STRLEN
|
|
||||||
|
|
||||||
// assumed to always be 2^n
|
// assumed to always be 2^n
|
||||||
#define RHIZOME_CRYPT_PAGE_SIZE 4096
|
#define RHIZOME_CRYPT_PAGE_SIZE 4096
|
||||||
|
|
||||||
/* Fundamental data type: Rhizome Bundle ID
|
|
||||||
*
|
|
||||||
* @author Andrew Bettison <andrew@servalproject.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct rhizome_bid_binary {
|
|
||||||
unsigned char binary[RHIZOME_MANIFEST_ID_BYTES];
|
|
||||||
} rhizome_bid_t;
|
|
||||||
|
|
||||||
#define RHIZOME_BID_ZERO ((rhizome_bid_t){{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}})
|
|
||||||
#define RHIZOME_BID_MAX ((rhizome_bid_t){{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}})
|
|
||||||
#define rhizome_bid_t_is_zero(bid) is_all_matching((bid).binary, sizeof (*(rhizome_bid_t*)0).binary, 0)
|
|
||||||
#define rhizome_bid_t_is_max(bid) is_all_matching((bid).binary, sizeof (*(rhizome_bid_t*)0).binary, 0xff)
|
|
||||||
#define alloca_tohex_rhizome_bid_t(bid) alloca_tohex((bid).binary, sizeof (*(rhizome_bid_t*)0).binary)
|
|
||||||
int cmp_rhizome_bid_t(const rhizome_bid_t *a, const rhizome_bid_t *b);
|
|
||||||
int str_to_rhizome_bid_t(rhizome_bid_t *bid, const char *hex);
|
|
||||||
int strn_to_rhizome_bid_t(rhizome_bid_t *bid, const char *hex, const char **endp);
|
|
||||||
|
|
||||||
/* Fundamental data type: Rhizome File Hash
|
|
||||||
*
|
|
||||||
* @author Andrew Bettison <andrew@servalproject.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct rhizome_filehash_binary {
|
|
||||||
unsigned char binary[RHIZOME_FILEHASH_BYTES];
|
|
||||||
} rhizome_filehash_t;
|
|
||||||
|
|
||||||
#define RHIZOME_FILEHASH_NONE ((rhizome_filehash_t){{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}})
|
|
||||||
#define rhizome_filehash_t_is_zero(fh) is_all_matching((fh).binary, sizeof (*(rhizome_filehash_t*)0).binary, 0)
|
|
||||||
#define rhizome_filehash_t_is_max(fh) is_all_matching((fh).binary, sizeof (*(rhizome_filehash_t*)0).binary, 0xff)
|
|
||||||
#define alloca_tohex_rhizome_filehash_t(fh) alloca_tohex((fh).binary, sizeof (*(rhizome_filehash_t*)0).binary)
|
|
||||||
int cmp_rhizome_filehash_t(const rhizome_filehash_t *a, const rhizome_filehash_t *b);
|
|
||||||
int str_to_rhizome_filehash_t(rhizome_filehash_t *fh, const char *hex);
|
|
||||||
int strn_to_rhizome_filehash_t(rhizome_filehash_t *fh, const char *hex, const char **endp);
|
|
||||||
|
|
||||||
/* Fundamental data type: Rhizome Bundle Key
|
|
||||||
*
|
|
||||||
* @author Andrew Bettison <andrew@servalproject.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct rhizome_bk_binary {
|
|
||||||
unsigned char binary[RHIZOME_BUNDLE_KEY_BYTES];
|
|
||||||
} rhizome_bk_t;
|
|
||||||
|
|
||||||
#define RHIZOME_BK_NONE ((rhizome_bk_t){{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}})
|
|
||||||
|
|
||||||
__RHIZOME_INLINE int rhizome_is_bk_none(const rhizome_bk_t *bk) {
|
|
||||||
return is_all_matching(bk->binary, sizeof bk->binary, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define alloca_tohex_rhizome_bk_t(bk) alloca_tohex((bk).binary, sizeof (*(rhizome_bk_t*)0).binary)
|
|
||||||
int cmp_rhizome_bk_t(const rhizome_bk_t *a, const rhizome_bk_t *b);
|
|
||||||
int str_to_rhizome_bk_t(rhizome_bk_t *bk, const char *hex);
|
|
||||||
int strn_to_rhizome_bk_t(rhizome_bk_t *bk, const char *hex, const char **endp);
|
|
||||||
|
|
||||||
|
|
||||||
extern time_ms_t rhizome_voice_timeout;
|
extern time_ms_t rhizome_voice_timeout;
|
||||||
|
|
||||||
#define RHIZOME_PRIORITY_HIGHEST RHIZOME_PRIORITY_SERVAL_CORE
|
#define RHIZOME_PRIORITY_HIGHEST RHIZOME_PRIORITY_SERVAL_CORE
|
||||||
@ -141,8 +73,6 @@ typedef struct rhizome_signature {
|
|||||||
#define MAX_MANIFEST_VARS 256
|
#define MAX_MANIFEST_VARS 256
|
||||||
#define MAX_MANIFEST_BYTES 8192
|
#define MAX_MANIFEST_BYTES 8192
|
||||||
|
|
||||||
#define RHIZOME_SIZE_UNSET UINT64_MAX
|
|
||||||
|
|
||||||
typedef struct rhizome_manifest
|
typedef struct rhizome_manifest
|
||||||
{
|
{
|
||||||
int manifest_record_number;
|
int manifest_record_number;
|
||||||
|
114
rhizome_types.h
Normal file
114
rhizome_types.h
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
/*
|
||||||
|
Serval Rhizome foundation types
|
||||||
|
Copyright (C) 2012-2014 Serval Project Inc.
|
||||||
|
|
||||||
|
This program 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
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SERVAL_DNA__RHIZOME_TYPES_H
|
||||||
|
#define __SERVAL_DNA__RHIZOME_TYPES_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include "nacl.h"
|
||||||
|
#include "sha2.h"
|
||||||
|
#include "str.h"
|
||||||
|
|
||||||
|
#ifndef __RHIZOME_TYPES_INLINE
|
||||||
|
# if __GNUC__ && !__GNUC_STDC_INLINE__
|
||||||
|
# define __RHIZOME_TYPES_INLINE extern inline
|
||||||
|
# else
|
||||||
|
# define __RHIZOME_TYPES_INLINE inline
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define RHIZOME_BUNDLE_ID_BYTES crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES
|
||||||
|
#define RHIZOME_BUNDLE_ID_STRLEN (RHIZOME_BUNDLE_ID_BYTES * 2)
|
||||||
|
#define RHIZOME_BUNDLE_KEY_BYTES (crypto_sign_edwards25519sha512batch_SECRETKEYBYTES - crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES)
|
||||||
|
#define RHIZOME_BUNDLE_KEY_STRLEN (RHIZOME_BUNDLE_KEY_BYTES * 2)
|
||||||
|
#define RHIZOME_FILEHASH_BYTES SHA512_DIGEST_LENGTH
|
||||||
|
#define RHIZOME_FILEHASH_STRLEN (RHIZOME_FILEHASH_BYTES * 2)
|
||||||
|
#define RHIZOME_CRYPT_KEY_BYTES crypto_stream_xsalsa20_ref_KEYBYTES
|
||||||
|
#define RHIZOME_CRYPT_KEY_STRLEN (RHIZOME_CRYPT_KEY_BYTES * 2)
|
||||||
|
|
||||||
|
// TODO Rename MANIFEST_ID to BUNDLE_ID
|
||||||
|
// The following constants are deprecated, use the BUNDLE_ID forms instead
|
||||||
|
#define RHIZOME_MANIFEST_ID_BYTES RHIZOME_BUNDLE_ID_BYTES
|
||||||
|
#define RHIZOME_MANIFEST_ID_STRLEN RHIZOME_BUNDLE_ID_STRLEN
|
||||||
|
|
||||||
|
/* Fundamental data type: Rhizome Bundle ID
|
||||||
|
*
|
||||||
|
* @author Andrew Bettison <andrew@servalproject.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct rhizome_bid_binary {
|
||||||
|
unsigned char binary[RHIZOME_MANIFEST_ID_BYTES];
|
||||||
|
} rhizome_bid_t;
|
||||||
|
|
||||||
|
#define RHIZOME_BID_ZERO ((rhizome_bid_t){{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}})
|
||||||
|
#define RHIZOME_BID_MAX ((rhizome_bid_t){{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}})
|
||||||
|
#define rhizome_bid_t_is_zero(bid) is_all_matching((bid).binary, sizeof (*(rhizome_bid_t*)0).binary, 0)
|
||||||
|
#define rhizome_bid_t_is_max(bid) is_all_matching((bid).binary, sizeof (*(rhizome_bid_t*)0).binary, 0xff)
|
||||||
|
#define alloca_tohex_rhizome_bid_t(bid) alloca_tohex((bid).binary, sizeof (*(rhizome_bid_t*)0).binary)
|
||||||
|
int cmp_rhizome_bid_t(const rhizome_bid_t *a, const rhizome_bid_t *b);
|
||||||
|
int str_to_rhizome_bid_t(rhizome_bid_t *bid, const char *hex);
|
||||||
|
int strn_to_rhizome_bid_t(rhizome_bid_t *bid, const char *hex, const char **endp);
|
||||||
|
|
||||||
|
/* Fundamental data type: Rhizome File Hash
|
||||||
|
*
|
||||||
|
* @author Andrew Bettison <andrew@servalproject.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct rhizome_filehash_binary {
|
||||||
|
unsigned char binary[RHIZOME_FILEHASH_BYTES];
|
||||||
|
} rhizome_filehash_t;
|
||||||
|
|
||||||
|
#define RHIZOME_FILEHASH_NONE ((rhizome_filehash_t){{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}})
|
||||||
|
#define rhizome_filehash_t_is_zero(fh) is_all_matching((fh).binary, sizeof (*(rhizome_filehash_t*)0).binary, 0)
|
||||||
|
#define rhizome_filehash_t_is_max(fh) is_all_matching((fh).binary, sizeof (*(rhizome_filehash_t*)0).binary, 0xff)
|
||||||
|
#define alloca_tohex_rhizome_filehash_t(fh) alloca_tohex((fh).binary, sizeof (*(rhizome_filehash_t*)0).binary)
|
||||||
|
int cmp_rhizome_filehash_t(const rhizome_filehash_t *a, const rhizome_filehash_t *b);
|
||||||
|
int str_to_rhizome_filehash_t(rhizome_filehash_t *fh, const char *hex);
|
||||||
|
int strn_to_rhizome_filehash_t(rhizome_filehash_t *fh, const char *hex, const char **endp);
|
||||||
|
|
||||||
|
/* Fundamental data type: Rhizome Bundle Key
|
||||||
|
*
|
||||||
|
* @author Andrew Bettison <andrew@servalproject.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct rhizome_bk_binary {
|
||||||
|
unsigned char binary[RHIZOME_BUNDLE_KEY_BYTES];
|
||||||
|
} rhizome_bk_t;
|
||||||
|
|
||||||
|
#define RHIZOME_BK_NONE ((rhizome_bk_t){{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}})
|
||||||
|
|
||||||
|
__RHIZOME_TYPES_INLINE int rhizome_is_bk_none(const rhizome_bk_t *bk) {
|
||||||
|
return is_all_matching(bk->binary, sizeof bk->binary, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define alloca_tohex_rhizome_bk_t(bk) alloca_tohex((bk).binary, sizeof (*(rhizome_bk_t*)0).binary)
|
||||||
|
int cmp_rhizome_bk_t(const rhizome_bk_t *a, const rhizome_bk_t *b);
|
||||||
|
int str_to_rhizome_bk_t(rhizome_bk_t *bk, const char *hex);
|
||||||
|
int strn_to_rhizome_bk_t(rhizome_bk_t *bk, const char *hex, const char **endp);
|
||||||
|
|
||||||
|
/* Fundamental data type: Rhizome payload size
|
||||||
|
*
|
||||||
|
* @author Andrew Bettison <andrew@servalproject.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define RHIZOME_SIZE_UNSET UINT64_MAX
|
||||||
|
|
||||||
|
#endif // __SERVAL_DNA__RHIZOME_TYPES_H
|
57
serval.h
57
serval.h
@ -54,11 +54,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#ifdef HAVE_STRINGS_H
|
|
||||||
#include <strings.h>
|
|
||||||
#endif
|
|
||||||
#include <string.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -98,17 +93,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
# endif
|
# endif
|
||||||
#endif //!WIN32
|
#endif //!WIN32
|
||||||
|
|
||||||
#if !defined(FORASTERISK) && !defined(s_addr)
|
|
||||||
#ifdef HAVE_ARPA_INET_H
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#else
|
|
||||||
typedef uint32_t in_addr_t;
|
|
||||||
struct in_addr {
|
|
||||||
in_addr_t s_addr;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_SYS_SOCKET_H
|
#ifdef HAVE_SYS_SOCKET_H
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#endif
|
#endif
|
||||||
@ -133,6 +117,8 @@ struct in_addr {
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "serval_types.h"
|
||||||
|
#include "sighandlers.h"
|
||||||
#include "instance.h"
|
#include "instance.h"
|
||||||
#include "fdqueue.h"
|
#include "fdqueue.h"
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
@ -143,10 +129,6 @@ struct in_addr {
|
|||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
/* UDP Port numbers for various Serval services.
|
|
||||||
The overlay mesh works over DNA */
|
|
||||||
#define PORT_DNA 4110
|
|
||||||
|
|
||||||
#define BATCH 1
|
#define BATCH 1
|
||||||
#define NONBATCH 0
|
#define NONBATCH 0
|
||||||
|
|
||||||
@ -171,31 +153,6 @@ struct in_addr {
|
|||||||
extern const char version_servald[];
|
extern const char version_servald[];
|
||||||
extern const char copyright_servald[];
|
extern const char copyright_servald[];
|
||||||
|
|
||||||
/* Fundamental types.
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct sid_binary {
|
|
||||||
unsigned char binary[SID_SIZE];
|
|
||||||
} sid_t;
|
|
||||||
|
|
||||||
#define SID_ANY ((sid_t){{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}})
|
|
||||||
#define SID_BROADCAST ((sid_t){{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}})
|
|
||||||
|
|
||||||
// is the SID entirely 0xFF?
|
|
||||||
#define is_sid_t_broadcast(SID) is_all_matching((SID).binary, sizeof (*(sid_t*)0).binary, 0xFF)
|
|
||||||
|
|
||||||
// is the SID entirely 0x00?
|
|
||||||
#define is_sid_t_any(SID) is_all_matching((SID).binary, sizeof (*(sid_t*)0).binary, 0)
|
|
||||||
|
|
||||||
#define alloca_tohex_sid_t(sid) alloca_tohex((sid).binary, sizeof (*(sid_t*)0).binary)
|
|
||||||
#define alloca_tohex_sid_t_trunc(sid,strlen) tohex((char *)alloca((strlen)+1), (strlen), (sid).binary)
|
|
||||||
|
|
||||||
int cmp_sid_t(const sid_t *a, const sid_t *b);
|
|
||||||
int str_to_sid_t(sid_t *sid, const char *hex);
|
|
||||||
int strn_to_sid_t(sid_t *sid, const char *hex, size_t hexlen, const char **endp);
|
|
||||||
|
|
||||||
#define alloca_tohex_sas(sas) alloca_tohex((sas), SAS_SIZE)
|
|
||||||
|
|
||||||
struct cli_parsed;
|
struct cli_parsed;
|
||||||
|
|
||||||
extern int servalShutdown;
|
extern int servalShutdown;
|
||||||
@ -277,10 +234,6 @@ int rhizome_opendb();
|
|||||||
|
|
||||||
int parseCommandLine(struct cli_context *context, const char *argv0, int argc, const char *const *argv);
|
int parseCommandLine(struct cli_context *context, const char *argv0, int argc, const char *const *argv);
|
||||||
|
|
||||||
typedef uint32_t mdp_port_t;
|
|
||||||
#define PRImdp_port_t "#010" PRIx32
|
|
||||||
|
|
||||||
|
|
||||||
/* Server-side MDP functions */
|
/* Server-side MDP functions */
|
||||||
void mdp_init_response(const struct internal_mdp_header *in, struct internal_mdp_header *out);
|
void mdp_init_response(const struct internal_mdp_header *in, struct internal_mdp_header *out);
|
||||||
void overlay_mdp_encode_ports(struct overlay_buffer *plaintext, mdp_port_t dst_port, mdp_port_t src_port);
|
void overlay_mdp_encode_ports(struct overlay_buffer *plaintext, mdp_port_t dst_port, mdp_port_t src_port);
|
||||||
@ -344,12 +297,6 @@ int dna_helper_start();
|
|||||||
int dna_helper_shutdown();
|
int dna_helper_shutdown();
|
||||||
int dna_helper_enqueue(struct subscriber *source, mdp_port_t source_port, const char *did);
|
int dna_helper_enqueue(struct subscriber *source, mdp_port_t source_port, const char *did);
|
||||||
int parseDnaReply(const char *buf, size_t len, char *token, char *did, char *name, char *uri, const char **bufp);
|
int parseDnaReply(const char *buf, size_t len, char *token, char *did, char *name, char *uri, const char **bufp);
|
||||||
extern int sigPipeFlag;
|
|
||||||
extern int sigIoFlag;
|
|
||||||
extern int sigIntFlag;
|
|
||||||
void sigPipeHandler(int signal);
|
|
||||||
void sigIoHandler(int signal);
|
|
||||||
void sigIntHandler(int signal);
|
|
||||||
|
|
||||||
int overlay_mdp_setup_sockets();
|
int overlay_mdp_setup_sockets();
|
||||||
|
|
||||||
|
@ -49,11 +49,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
|
||||||
#include <strings.h>
|
|
||||||
#include "xprintf.h"
|
#include "xprintf.h"
|
||||||
|
|
||||||
#define MAX_SPACES 120
|
#define MAX_SPACES 120
|
||||||
|
73
serval_types.h
Normal file
73
serval_types.h
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
Serval DNA foundation types
|
||||||
|
Copyright (C) 2012-2014 Serval Project Inc.
|
||||||
|
|
||||||
|
This program 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
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SERVAL_DNA__SERVAL_TYPES_H
|
||||||
|
#define __SERVAL_DNA__SERVAL_TYPES_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* Conveniences to assist readability
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef char bool_t;
|
||||||
|
|
||||||
|
/* Serval ID (aka Subscriber ID)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define SID_SIZE 32 // == crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES
|
||||||
|
#define SAS_SIZE 32 // == crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES
|
||||||
|
|
||||||
|
#define SID_STRLEN (SID_SIZE*2)
|
||||||
|
|
||||||
|
typedef struct sid_binary {
|
||||||
|
unsigned char binary[SID_SIZE];
|
||||||
|
} sid_t;
|
||||||
|
|
||||||
|
#define SID_ANY ((sid_t){{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}})
|
||||||
|
#define SID_BROADCAST ((sid_t){{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}})
|
||||||
|
|
||||||
|
// is the SID entirely 0xFF?
|
||||||
|
#define is_sid_t_broadcast(SID) is_all_matching((SID).binary, sizeof (*(sid_t*)0).binary, 0xFF)
|
||||||
|
|
||||||
|
// is the SID entirely 0x00?
|
||||||
|
#define is_sid_t_any(SID) is_all_matching((SID).binary, sizeof (*(sid_t*)0).binary, 0)
|
||||||
|
|
||||||
|
#define alloca_tohex_sid_t(sid) alloca_tohex((sid).binary, sizeof (*(sid_t*)0).binary)
|
||||||
|
#define alloca_tohex_sid_t_trunc(sid,strlen) tohex((char *)alloca((strlen)+1), (strlen), (sid).binary)
|
||||||
|
|
||||||
|
int cmp_sid_t(const sid_t *a, const sid_t *b);
|
||||||
|
int str_to_sid_t(sid_t *sid, const char *hex);
|
||||||
|
int strn_to_sid_t(sid_t *sid, const char *hex, size_t hexlen, const char **endp);
|
||||||
|
|
||||||
|
#define alloca_tohex_sas(sas) alloca_tohex((sas), SAS_SIZE)
|
||||||
|
|
||||||
|
/* MDP port number
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef uint32_t mdp_port_t;
|
||||||
|
#define PRImdp_port_t "#010" PRIx32
|
||||||
|
|
||||||
|
/* DID (phone number)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define DID_MINSIZE 5
|
||||||
|
#define DID_MAXSIZE 32
|
||||||
|
|
||||||
|
#endif // __SERVAL_DNA__SERVAL_TYPES_H
|
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Serval Distributed Numbering Architecture (DNA)
|
Serval DNA signal handlers
|
||||||
|
Copyright (C) 2014 Serval Project Inc.
|
||||||
Copyright (C) 2012 Paul Gardner-Stephen
|
Copyright (C) 2012 Paul Gardner-Stephen
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
@ -18,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
|
#include "sighandlers.h"
|
||||||
|
|
||||||
int sigPipeFlag=0;
|
int sigPipeFlag=0;
|
||||||
int sigIoFlag=0;
|
int sigIoFlag=0;
|
||||||
|
31
sighandlers.h
Normal file
31
sighandlers.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
Serval DNA signal handlers
|
||||||
|
Copyright (C) 2014 Serval Project Inc.
|
||||||
|
|
||||||
|
This program 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
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SERVAL_DNA__SIGHANDLERS_H
|
||||||
|
#define __SERVAL_DNA__SIGHANDLERS_H
|
||||||
|
|
||||||
|
extern int sigPipeFlag;
|
||||||
|
extern int sigIoFlag;
|
||||||
|
extern int sigIntFlag;
|
||||||
|
|
||||||
|
void sigPipeHandler(int signal);
|
||||||
|
void sigIoHandler(int signal);
|
||||||
|
void sigIntHandler(int signal);
|
||||||
|
|
||||||
|
#endif // __SERVAL_DNA__SIGHANDLERS_H
|
73
simulator.c
73
simulator.c
@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
@ -108,82 +109,10 @@ struct command_state *stdin_state;
|
|||||||
struct network *networks=NULL;
|
struct network *networks=NULL;
|
||||||
static void unicast_alarm(struct sched_ent *alarm);
|
static void unicast_alarm(struct sched_ent *alarm);
|
||||||
|
|
||||||
const struct __sourceloc __whence = __NOWHERE__;
|
|
||||||
|
|
||||||
static const char *_trimbuildpath(const char *path)
|
|
||||||
{
|
|
||||||
/* Remove common path prefix */
|
|
||||||
int lastsep = 0;
|
|
||||||
int i;
|
|
||||||
for (i = 0; __FILE__[i] && path[i]; ++i) {
|
|
||||||
if (i && path[i - 1] == '/')
|
|
||||||
lastsep = i;
|
|
||||||
if (__FILE__[i] != path[i])
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return &path[lastsep];
|
|
||||||
}
|
|
||||||
|
|
||||||
void cf_on_config_change()
|
void cf_on_config_change()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void logMessage(int level, struct __sourceloc whence, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
const char *levelstr = "UNKWN:";
|
|
||||||
switch (level) {
|
|
||||||
case LOG_LEVEL_FATAL:
|
|
||||||
levelstr = "FATAL:";
|
|
||||||
break;
|
|
||||||
case LOG_LEVEL_ERROR:
|
|
||||||
levelstr = "ERROR:";
|
|
||||||
break;
|
|
||||||
case LOG_LEVEL_INFO:
|
|
||||||
levelstr = "INFO:";
|
|
||||||
break;
|
|
||||||
case LOG_LEVEL_WARN:
|
|
||||||
levelstr = "WARN:";
|
|
||||||
break;
|
|
||||||
case LOG_LEVEL_DEBUG:
|
|
||||||
levelstr = "DEBUG:";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct timeval tv;
|
|
||||||
struct tm tm;
|
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
localtime_r(&tv.tv_sec, &tm);
|
|
||||||
char buf[50];
|
|
||||||
strftime(buf, sizeof buf, "%T", &tm);
|
|
||||||
fprintf(stderr, "%s.%03u ", buf, (unsigned int)tv.tv_usec / 1000);
|
|
||||||
|
|
||||||
fprintf(stderr, "%s ", levelstr);
|
|
||||||
if (whence.file) {
|
|
||||||
fprintf(stderr, "%s", _trimbuildpath(whence.file));
|
|
||||||
if (whence.line)
|
|
||||||
fprintf(stderr, ":%u", whence.line);
|
|
||||||
if (whence.function)
|
|
||||||
fprintf(stderr, ":%s()", whence.function);
|
|
||||||
fputc(' ', stderr);
|
|
||||||
} else if (whence.function) {
|
|
||||||
fprintf(stderr, "%s() ", whence.function);
|
|
||||||
}
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vfprintf(stderr, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
fputc('\n', stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void logFlush()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void logConfigChanged()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int serverMode=0;
|
|
||||||
|
|
||||||
static void recv_packet(int fd, struct network *network, struct peer *destination)
|
static void recv_packet(int fd, struct network *network, struct peer *destination)
|
||||||
{
|
{
|
||||||
struct socket_address addr;
|
struct socket_address addr;
|
||||||
|
2
socket.c
2
socket.c
@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
|
||||||
#include "serval.h"
|
#include "instance.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
@ -1,20 +1,26 @@
|
|||||||
# The "client" source files do not depend on "serval.h" or "rhizome.h", ie,
|
# The "client" source files do not depend on "serval.h" or "rhizome.h", ie,
|
||||||
# they can be linked into executables other than servald.
|
# they can be linked into executables other than servald.
|
||||||
SERVAL_CLIENT_SOURCES = \
|
SERVAL_CLIENT_SOURCES = \
|
||||||
|
cli.c \
|
||||||
conf.c \
|
conf.c \
|
||||||
conf_om.c \
|
conf_om.c \
|
||||||
conf_parse.c \
|
conf_parse.c \
|
||||||
conf_schema.c \
|
conf_schema.c \
|
||||||
|
console.c \
|
||||||
dataformats.c \
|
dataformats.c \
|
||||||
|
fdqueue.c \
|
||||||
fifo.c \
|
fifo.c \
|
||||||
instance.c \
|
instance.c \
|
||||||
log.c \
|
limit.c \
|
||||||
|
logMessage.c \
|
||||||
log_util.c \
|
log_util.c \
|
||||||
mem.c \
|
mem.c \
|
||||||
net.c \
|
net.c \
|
||||||
os.c \
|
os.c \
|
||||||
|
performance_timing.c \
|
||||||
randombytes.c \
|
randombytes.c \
|
||||||
rotbuf.c \
|
rotbuf.c \
|
||||||
|
sighandlers.c \
|
||||||
socket.c \
|
socket.c \
|
||||||
srandomdev.c \
|
srandomdev.c \
|
||||||
strbuf.c \
|
strbuf.c \
|
||||||
@ -22,8 +28,14 @@ SERVAL_CLIENT_SOURCES = \
|
|||||||
str.c \
|
str.c \
|
||||||
strlcpy.c \
|
strlcpy.c \
|
||||||
uuid.c \
|
uuid.c \
|
||||||
|
whence.c \
|
||||||
xprintf.c
|
xprintf.c
|
||||||
|
|
||||||
|
# These objects do not belong in the Serval DNA daemon but are available for
|
||||||
|
# client applications.
|
||||||
|
SERVAL_LIB_SOURCES = \
|
||||||
|
log_stderr.c
|
||||||
|
|
||||||
# These source files are imported and do not depend on any local header files.
|
# These source files are imported and do not depend on any local header files.
|
||||||
# They also take a long time to compile, so their dependencies should be as
|
# They also take a long time to compile, so their dependencies should be as
|
||||||
# narrow as possible to avoid unnecessary recompilations when developers modify
|
# narrow as possible to avoid unnecessary recompilations when developers modify
|
||||||
@ -33,26 +45,21 @@ SQLITE3_SOURCES = \
|
|||||||
|
|
||||||
# The source files for building the Serval DNA daemon.
|
# The source files for building the Serval DNA daemon.
|
||||||
SERVAL_DAEMON_SOURCES = \
|
SERVAL_DAEMON_SOURCES = \
|
||||||
cli.c \
|
|
||||||
commandline.c \
|
commandline.c \
|
||||||
console.c \
|
|
||||||
crypto.c \
|
crypto.c \
|
||||||
directory_client.c \
|
directory_client.c \
|
||||||
dna_helper.c \
|
dna_helper.c \
|
||||||
encode.c \
|
encode.c \
|
||||||
fdqueue.c \
|
|
||||||
golay.c \
|
golay.c \
|
||||||
httpd.c \
|
httpd.c \
|
||||||
http_server.c \
|
http_server.c \
|
||||||
keyring.c \
|
keyring.c \
|
||||||
|
log.c \
|
||||||
lsif.c \
|
lsif.c \
|
||||||
limit.c \
|
|
||||||
main.c \
|
main.c \
|
||||||
radio_link.c \
|
radio_link.c \
|
||||||
meshms.c \
|
meshms.c \
|
||||||
meshms_restful.c \
|
meshms_restful.c \
|
||||||
mdp_client.c \
|
|
||||||
mdp_net.c \
|
|
||||||
msp_client.c \
|
msp_client.c \
|
||||||
msp_proxy.c \
|
msp_proxy.c \
|
||||||
monitor.c \
|
monitor.c \
|
||||||
@ -72,7 +79,6 @@ SERVAL_DAEMON_SOURCES = \
|
|||||||
overlay_olsr.c \
|
overlay_olsr.c \
|
||||||
overlay_packetformats.c \
|
overlay_packetformats.c \
|
||||||
overlay_payload.c \
|
overlay_payload.c \
|
||||||
performance_timing.c \
|
|
||||||
route_link.c \
|
route_link.c \
|
||||||
rhizome.c \
|
rhizome.c \
|
||||||
rhizome_bundle.c \
|
rhizome_bundle.c \
|
||||||
@ -89,7 +95,6 @@ SERVAL_DAEMON_SOURCES = \
|
|||||||
serval_packetvisualise.c \
|
serval_packetvisualise.c \
|
||||||
server.c \
|
server.c \
|
||||||
sha2.c \
|
sha2.c \
|
||||||
sighandlers.c \
|
|
||||||
vomp.c \
|
vomp.c \
|
||||||
vomp_console.c \
|
vomp_console.c \
|
||||||
fec-3.0.1/ccsds_tables.c \
|
fec-3.0.1/ccsds_tables.c \
|
||||||
@ -98,8 +103,12 @@ SERVAL_DAEMON_SOURCES = \
|
|||||||
fec-3.0.1/init_rs_char.c \
|
fec-3.0.1/init_rs_char.c \
|
||||||
context1.c
|
context1.c
|
||||||
|
|
||||||
SIMULATOR_SOURCES = cli.c conf.c conf_om.c conf_parse.c conf_schema.c \
|
MDP_CLIENT_SOURCES = \
|
||||||
console.c simulator.c socket.c fdqueue.c performance_timing.c \
|
mdp_client.c \
|
||||||
str.c os.c mem.c net.c log_util.c strbuf.c strbuf_helpers.c \
|
mdp_net.c
|
||||||
dataformats.c xprintf.c instance.c limit.c version.c
|
|
||||||
|
|
||||||
|
SIMULATOR_SOURCES = \
|
||||||
|
simulator.c
|
||||||
|
|
||||||
|
MONITOR_CLIENT_SRCS = \
|
||||||
|
monitor-client.c
|
||||||
|
21
whence.c
Normal file
21
whence.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2014 Serval Project Inc.
|
||||||
|
|
||||||
|
This program 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
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "whence.h"
|
||||||
|
|
||||||
|
const struct __sourceloc __whence = __NOWHERE__;
|
83
whence.h
Normal file
83
whence.h
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 2012 Serval Project Inc.
|
||||||
|
|
||||||
|
This program 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
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SERVAL_DNA__WHENCE_H
|
||||||
|
#define __SERVAL_DNA__WHENCE_H
|
||||||
|
|
||||||
|
#include <stdio.h> // for NULL
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Every log message identifies the location in the source code at which the
|
||||||
|
* message was produced. This location is represented by a struct __sourceloc,
|
||||||
|
* which is passed by value to the logMessage() function and its ilk.
|
||||||
|
*
|
||||||
|
* A struct __sourceloc value is generated by the __HERE__ macro, which uses
|
||||||
|
* the cpp(1) built-in macros __FILE__, __LINE__ and __FUNCTION__ to generate
|
||||||
|
* its elements. The __NOWHERE__ macro creates a struct __sourceloc with NULL
|
||||||
|
* and zero fields. If you pass __NOWHERE__ to logMessage(), it will omit
|
||||||
|
* location information from the log line. The __NOWHENCE__ macro creates a
|
||||||
|
* special source __sourceloc that logging primitives should interpret to
|
||||||
|
* suppress the output of the usual source-code location information.
|
||||||
|
*
|
||||||
|
* Sometimes, a function wants to log a message as though its caller were the
|
||||||
|
* origin of the message. This is typical of "primitive" type functions that
|
||||||
|
* are used in many places throughout the code, and whose internal workings are
|
||||||
|
* generally well-debugged and of little interest for ongoing development. In
|
||||||
|
* this case, the code pattern is to declare the underscore-prefixed function
|
||||||
|
* as taking a struct __sourceloc argument, and a macro that invokes the
|
||||||
|
* function, passing the __HERE__ macro for that argument:
|
||||||
|
*
|
||||||
|
* int _primitive(struct __sourceloc __whence, int arg1, const char *arg2);
|
||||||
|
*
|
||||||
|
* #define primitive(arg1, arg2) _primitive(__HERE__, (arg1), (arg2))
|
||||||
|
*
|
||||||
|
* Within the _primitive() function, the standard logging macros defined below
|
||||||
|
* (WHYF(), WARNF(), INFOF(), DEBUGF() etc.) will use the __whence argument
|
||||||
|
* instead of __HERE__ when logging their message. This is achieved using a
|
||||||
|
* dirty trick: in the function *definition*, the __sourceloc argument MUST be
|
||||||
|
* named '__whence'. The trick is that there is a global variable called
|
||||||
|
* '__whence' which always contains the value of __NOWHERE__. If that variable
|
||||||
|
* is lexically obscured by a local variable or parameter called '__whence',
|
||||||
|
* then the DEBUG macros will use __whence, otherwise they will use __HERE__.
|
||||||
|
* This logic is encapsulated in the __WHENCE__ macro, to make it available to
|
||||||
|
* for other purposes. For example, a better definition of the primitive()
|
||||||
|
* macro above would be:
|
||||||
|
*
|
||||||
|
* #define primitive(arg1, arg2) _primitive(__WHENCE__, (arg1), (arg2))
|
||||||
|
*
|
||||||
|
* Then, if it were invoked from within another primitive-type function, it
|
||||||
|
* would log messages with the __sourceloc of that primitive's caller, which is
|
||||||
|
* probably the most useful for diagnosis.
|
||||||
|
*
|
||||||
|
* @author Andrew Bettison <andrew@servalproject.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct __sourceloc {
|
||||||
|
const char *file;
|
||||||
|
unsigned int line;
|
||||||
|
const char *function;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const struct __sourceloc __whence; // see above
|
||||||
|
|
||||||
|
#define __HERE__ ((struct __sourceloc){ .file = __FILE__, .line = __LINE__, .function = __FUNCTION__ })
|
||||||
|
#define __NOWHERE__ ((struct __sourceloc){ .file = NULL, .line = 0, .function = NULL })
|
||||||
|
#define __NOWHENCE__ ((struct __sourceloc){ .file = "", .line = 0, .function = NULL })
|
||||||
|
#define __WHENCE__ (__whence.file ? __whence : __HERE__)
|
||||||
|
|
||||||
|
#endif // __SERVAL_DNA__WHENCE_H
|
Loading…
Reference in New Issue
Block a user