mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-20 21:53:12 +00:00
Merge branch 'development' into 'naf4'
This commit is contained in:
commit
1e96a8745d
@ -6,7 +6,7 @@ SERVALD_SRC_FILES = $(SERVAL_SOURCES) $(ANDROIDONLY_SOURCES)
|
||||
|
||||
SERVALD_LOCAL_CFLAGS = \
|
||||
-g \
|
||||
-DSERVALD_VERSION="\"Android\"" \
|
||||
-DSERVALD_VERSION="\"Android\"" -DSERVALD_COPYRIGHT="\"Android\"" \
|
||||
-DSHELL -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" \
|
||||
-DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" \
|
||||
-DHAVE_LIBC=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 \
|
||||
@ -17,7 +17,7 @@ SERVALD_LOCAL_CFLAGS = \
|
||||
-DHAVE_SYS_MMAN_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_POLL_H=1 -DHAVE_NETDB_H=1 \
|
||||
-DHAVE_JNI_H=1 -DHAVE_STRUCT_UCRED=1 -DHAVE_CRYPTO_SIGN_NACL_GE25519_H=1 \
|
||||
-DBYTE_ORDER=_BYTE_ORDER -DHAVE_LINUX_STRUCT_UCRED -DUSE_ABSTRACT_NAMESPACE \
|
||||
-DHAVE_BCOPY -DHAVE_BZERO \
|
||||
-DHAVE_BCOPY -DHAVE_BZERO -DHAVE_NETINET_IN_H \
|
||||
-I$(NACL_INC) \
|
||||
-I$(SQLITE3_INC)
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
Portions Copyright (C) 2010-2013 Serval Project Inc.
|
||||
Portions Copyright (C) 2010-2013 Paul Gardner-Stephen
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Portions Copyright (C) 2000-2001 Aaron D. Gifford
|
||||
Portions Copyright (C) 2010-2012 Serval Project Pty Limited
|
||||
Portions Copyright (C) 2006-2008 Linpro AS
|
||||
|
19
Makefile.in
19
Makefile.in
@ -83,6 +83,12 @@ INSTALL_DATA= $(INSTALL) -m 644
|
||||
|
||||
-include Makefile.dbg
|
||||
|
||||
# More warnings, discover problems that only happen on some archs
|
||||
CFLAGS+=-Wextra
|
||||
# Security enhancements from Debian
|
||||
CFLAGS+=-fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2
|
||||
LDFLAGS+=-Wl,-z,relro
|
||||
|
||||
DEFS= @DEFS@
|
||||
|
||||
.PHONY: all test clean
|
||||
@ -127,16 +133,19 @@ fakeradio: fakeradio.o
|
||||
|
||||
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
|
||||
@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
|
||||
@$(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)
|
||||
|
||||
copyright: COPYRIGHT.txt
|
||||
copyright:
|
||||
@if [ -x "$(COPYRIGHT_TOOL)" ]; then \
|
||||
echo GENERATE COPYRIGHT.txt; \
|
||||
$(COPYRIGHT_TOOL) -o COPYRIGHT.txt condense *.c *.h; \
|
||||
else \
|
||||
echo 'sp-copyright-tool is not in $$PATH; COPYRIGHT.txt not updated'; \
|
||||
fi
|
||||
|
||||
findPATH = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))
|
||||
COPYRIGHT_TOOL := $(call findPATH,sp-copyright-tool)
|
||||
|
||||
COPYRIGHT.txt: *.c *.h $(COPYRIGHT_TOOL)
|
||||
$(COPYRIGHT_TOOL) -o $@ condense *.c *.h
|
||||
|
||||
# This does not build on 64 bit elf platforms as NaCL isn't built with -fPIC
|
||||
# DOC 20120615
|
||||
libservald.so: $(OBJS) version.o
|
||||
|
14
cli.c
14
cli.c
@ -44,7 +44,7 @@ int cli_usage_args(const int argc, const char *const *args, const struct cli_sch
|
||||
unsigned cmd;
|
||||
int matched_any = 0;
|
||||
for (cmd = 0; commands[cmd].function; ++cmd) {
|
||||
unsigned opt;
|
||||
int opt;
|
||||
const char *word;
|
||||
int matched = 1;
|
||||
for (opt = 0; matched && opt < argc && (word = commands[cmd].words[opt]); ++opt)
|
||||
@ -99,7 +99,7 @@ int cli_parse(const int argc, const char *const *args, const struct cli_schema *
|
||||
cmdpa.labelc = 0;
|
||||
cmdpa.varargi = -1;
|
||||
const char *pattern = NULL;
|
||||
unsigned arg = 0;
|
||||
int arg = 0;
|
||||
unsigned opt = 0;
|
||||
while ((pattern = commands[cmd].words[opt])) {
|
||||
//DEBUGF("cmd=%d opt=%d pattern='%s' args[arg=%d]='%s'", cmd, opt, pattern, arg, arg < argc ? args[arg] : "");
|
||||
@ -167,7 +167,7 @@ int cli_parse(const int argc, const char *const *args, const struct cli_schema *
|
||||
pattern += 1;
|
||||
patlen -= 2;
|
||||
}
|
||||
unsigned oarg = arg;
|
||||
int oarg = arg;
|
||||
const char *text = NULL;
|
||||
const char *label = NULL;
|
||||
unsigned labellen = 0;
|
||||
@ -195,7 +195,7 @@ int cli_parse(const int argc, const char *const *args, const struct cli_schema *
|
||||
// Look for a match.
|
||||
const char *prefix = NULL;
|
||||
unsigned prefixlen = 0;
|
||||
char prefixarglen = 0;
|
||||
unsigned prefixarglen = 0;
|
||||
const char *caret = strchr(word, '<');
|
||||
if (wordlen > 2 && caret && word[wordlen-1] == '>') {
|
||||
if ((prefixarglen = prefixlen = caret - word)) {
|
||||
@ -277,7 +277,7 @@ void _debug_cli_parsed(struct __sourceloc __whence, const struct cli_parsed *par
|
||||
{
|
||||
DEBUG_argv("command", parsed->argc, parsed->args);
|
||||
strbuf b = strbuf_alloca(1024);
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < parsed->labelc; ++i) {
|
||||
const struct labelv *lab = &parsed->labelv[i];
|
||||
strbuf_sprintf(b, " %s=%s", alloca_toprint(-1, lab->label, lab->len), alloca_str_toprint(lab->text));
|
||||
@ -297,10 +297,10 @@ int cli_invoke(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
|
||||
int _cli_arg(struct __sourceloc __whence, const struct cli_parsed *parsed, char *label, const char **dst, int (*validator)(const char *arg), char *defaultvalue)
|
||||
{
|
||||
int labellen = strlen(label);
|
||||
unsigned labellen = strlen(label);
|
||||
if (dst)
|
||||
*dst = defaultvalue;
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < parsed->labelc; ++i) {
|
||||
if (parsed->labelv[i].len == labellen && strncasecmp(label, parsed->labelv[i].label, labellen) == 0) {
|
||||
const char *value = parsed->labelv[i].text;
|
||||
|
3
cli.h
3
cli.h
@ -92,8 +92,7 @@ int cli_optional_did(const char *text);
|
||||
|
||||
int cli_putchar(struct cli_context *context, char c);
|
||||
int cli_puts(struct cli_context *context, const char *str);
|
||||
int cli_printf(struct cli_context *context, const char *fmt, ...)
|
||||
__attribute__ (( format(printf,2,3) ));
|
||||
void cli_printf(struct cli_context *context, const char *fmt, ...) __attribute__ (( format(printf,2,3) ));
|
||||
int cli_delim(struct cli_context *context, const char *opt);
|
||||
void cli_columns(struct cli_context *context, int columns, const char *names[]);
|
||||
void cli_row_count(struct cli_context *context, int rows);
|
||||
|
146
commandline.c
146
commandline.c
@ -17,6 +17,35 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/wait.h>
|
||||
#include <math.h>
|
||||
@ -50,13 +79,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
extern struct cli_schema command_line_options[];
|
||||
|
||||
int commandline_usage(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int commandline_usage(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
printf("Serval DNA version %s\nUsage:\n", version_servald);
|
||||
return cli_usage_parsed(parsed, XPRINTF_STDIO(stdout));
|
||||
}
|
||||
|
||||
int version_message(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int version_message(const struct cli_parsed *UNUSED(parsed), struct cli_context *UNUSED(context))
|
||||
{
|
||||
printf("Serval DNA version %s\n%s\n", version_servald, copyright_servald);
|
||||
printf("\
|
||||
@ -79,15 +108,19 @@ jmethodID startResultSet, setColumnName, putString, putBlob, putLong, putDouble,
|
||||
|
||||
static int outv_growbuf(struct cli_context *context, size_t needed)
|
||||
{
|
||||
size_t newsize = (context->outv_limit - context->outv_current < needed) ? (context->outv_limit - context->outv_buffer) + needed : 0;
|
||||
if (newsize) {
|
||||
assert(context->outv_current <= context->outv_limit);
|
||||
size_t remaining = (size_t)(context->outv_limit - context->outv_current);
|
||||
if (remaining < needed) {
|
||||
size_t cursize = context->outv_current - context->outv_buffer;
|
||||
size_t newsize = cursize + needed;
|
||||
// Round up to nearest multiple of OUTV_BUFFER_ALLOCSIZE.
|
||||
newsize = newsize + OUTV_BUFFER_ALLOCSIZE - ((newsize - 1) % OUTV_BUFFER_ALLOCSIZE + 1);
|
||||
size_t length = context->outv_current - context->outv_buffer;
|
||||
assert(newsize > cursize);
|
||||
assert((size_t)(newsize - cursize) >= needed);
|
||||
context->outv_buffer = realloc(context->outv_buffer, newsize);
|
||||
if (context->outv_buffer == NULL)
|
||||
return WHYF("Out of memory allocating %lu bytes", (unsigned long) newsize);
|
||||
context->outv_current = context->outv_buffer + length;
|
||||
context->outv_current = context->outv_buffer + cursize;
|
||||
context->outv_limit = context->outv_buffer + newsize;
|
||||
}
|
||||
return 0;
|
||||
@ -136,7 +169,7 @@ int Throw(JNIEnv *env, const char *class, const char *msg)
|
||||
/* JNI entry point to command line. See org.servalproject.servald.ServalD class for the Java side.
|
||||
JNI method descriptor: "(Ljava/util/List;[Ljava/lang/String;)I"
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_servalproject_servald_ServalD_rawCommand(JNIEnv *env, jobject this, jobject outv, jobjectArray args)
|
||||
JNIEXPORT jint JNICALL Java_org_servalproject_servald_ServalD_rawCommand(JNIEnv *env, jobject UNUSED(this), jobject outv, jobjectArray args)
|
||||
{
|
||||
struct cli_context context;
|
||||
bzero(&context, sizeof(context));
|
||||
@ -311,36 +344,45 @@ int cli_puts(struct cli_context *context, const char *str)
|
||||
}
|
||||
|
||||
/* Write a formatted string to output. If in a JNI call, then this appends the string to the
|
||||
current output field, excluding the terminating null. Returns the number of bytes
|
||||
written/appended, or -1 on error.
|
||||
current output field, excluding the terminating null.
|
||||
*/
|
||||
int cli_printf(struct cli_context *context, const char *fmt, ...)
|
||||
void cli_printf(struct cli_context *context, const char *fmt, ...)
|
||||
{
|
||||
int ret = 0;
|
||||
va_list ap;
|
||||
#ifdef HAVE_JNI_H
|
||||
if (context && context->jni_env) {
|
||||
assert(context->outv_current <= context->outv_limit);
|
||||
size_t avail = context->outv_limit - context->outv_current;
|
||||
va_start(ap, fmt);
|
||||
int count = vsnprintf(context->outv_current, avail, fmt, ap);
|
||||
va_end(ap);
|
||||
if (count >= avail) {
|
||||
if (outv_growbuf(context, count) == -1)
|
||||
return -1;
|
||||
va_start(ap, fmt);
|
||||
vsprintf(context->outv_current, fmt, ap);
|
||||
va_end(ap);
|
||||
if (count < 0) {
|
||||
WHYF("vsnprintf(%p,%zu,%s,...) failed", context->outv_current, avail, alloca_str_toprint(fmt));
|
||||
return;
|
||||
} else if ((size_t)count < avail) {
|
||||
context->outv_current += count;
|
||||
return;
|
||||
}
|
||||
context->outv_current += count;
|
||||
ret = count;
|
||||
if (outv_growbuf(context, count) == -1)
|
||||
return;
|
||||
avail = context->outv_limit - context->outv_current;
|
||||
va_start(ap, fmt);
|
||||
count = vsprintf(context->outv_current, fmt, ap);
|
||||
va_end(ap);
|
||||
if (count < 0) {
|
||||
WHYF("vsprintf(%p,%s,...) failed", context->outv_current, alloca_str_toprint(fmt));
|
||||
return;
|
||||
}
|
||||
assert((size_t)count < avail);
|
||||
context->outv_current += (size_t)count;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
va_start(ap, fmt);
|
||||
ret = vfprintf(stdout, fmt, ap);
|
||||
if (vfprintf(stdout, fmt, ap) < 0)
|
||||
WHYF("vfprintf(stdout,%s,...) failed", alloca_str_toprint(fmt));
|
||||
va_end(ap);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void cli_columns(struct cli_context *context, int columns, const char *names[])
|
||||
@ -490,7 +532,7 @@ int app_echo(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
if (config.debug.verbose)
|
||||
DEBUG_cli_parsed(parsed);
|
||||
int escapes = !cli_arg(parsed, "-e", NULL, NULL, NULL);
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = parsed->varargi; i < parsed->argc; ++i) {
|
||||
const char *arg = parsed->args[i];
|
||||
if (config.debug.verbose)
|
||||
@ -506,7 +548,7 @@ int app_echo(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_log(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int app_log(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (config.debug.verbose)
|
||||
DEBUG_cli_parsed(parsed);
|
||||
@ -1009,7 +1051,7 @@ int app_mdp_ping(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
uint8_t recv_payload[12];
|
||||
ssize_t len = mdp_recv(mdp_sockfd, &mdp_recv_header, recv_payload, sizeof(recv_payload));
|
||||
|
||||
if (len<0){
|
||||
if (len == -1){
|
||||
WHY_perror("mdp_recv");
|
||||
break;
|
||||
}
|
||||
@ -1027,7 +1069,7 @@ int app_mdp_ping(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (len<sizeof(recv_payload)){
|
||||
if ((size_t)len < sizeof(recv_payload)){
|
||||
DEBUGF("Ignoring ping response as it is too short");
|
||||
continue;
|
||||
}
|
||||
@ -1204,7 +1246,7 @@ int app_config_dump(const struct cli_parsed *parsed, struct cli_context *context
|
||||
return ret == CFOK ? 0 : 1;
|
||||
}
|
||||
|
||||
int app_config_set(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int app_config_set(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (config.debug.verbose)
|
||||
DEBUG_cli_parsed(parsed);
|
||||
@ -1228,8 +1270,8 @@ int app_config_set(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
// </kludge>
|
||||
const char *var[parsed->argc - 1];
|
||||
const char *val[parsed->argc - 1];
|
||||
int nvar = 0;
|
||||
int i;
|
||||
unsigned nvar = 0;
|
||||
unsigned i;
|
||||
for (i = 1; i < parsed->argc; ++i) {
|
||||
const char *arg = parsed->args[i];
|
||||
int iv;
|
||||
@ -1597,7 +1639,7 @@ cleanup:
|
||||
return status;
|
||||
}
|
||||
|
||||
int app_rhizome_append_manifest(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int app_rhizome_append_manifest(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (config.debug.verbose)
|
||||
DEBUG_cli_parsed(parsed);
|
||||
@ -1621,7 +1663,7 @@ int app_rhizome_append_manifest(const struct cli_parsed *parsed, struct cli_cont
|
||||
return ret;
|
||||
}
|
||||
|
||||
int app_rhizome_delete(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int app_rhizome_delete(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (config.debug.verbose)
|
||||
DEBUG_cli_parsed(parsed);
|
||||
@ -1791,7 +1833,7 @@ int app_rhizome_extract(const struct cli_parsed *parsed, struct cli_context *con
|
||||
retfile = rhizome_extract_file(m, filepath);
|
||||
}else{
|
||||
// Save the file without attempting to decrypt
|
||||
int64_t length;
|
||||
uint64_t length;
|
||||
retfile = rhizome_dump_file(&m->filehash, filepath, &length);
|
||||
}
|
||||
}
|
||||
@ -1841,7 +1883,7 @@ int app_rhizome_export_file(const struct cli_parsed *parsed, struct cli_context
|
||||
return -1;
|
||||
if (!rhizome_exists(&hash))
|
||||
return 1;
|
||||
int64_t length;
|
||||
uint64_t length;
|
||||
int ret = rhizome_dump_file(&hash, filepath, &length);
|
||||
if (ret)
|
||||
return ret == -1 ? -1 : 1;
|
||||
@ -1951,7 +1993,7 @@ int app_rhizome_list(const struct cli_parsed *parsed, struct cli_context *contex
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_keyring_create(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int app_keyring_create(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (config.debug.verbose)
|
||||
DEBUG_cli_parsed(parsed);
|
||||
@ -1962,7 +2004,7 @@ int app_keyring_create(const struct cli_parsed *parsed, struct cli_context *cont
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_keyring_dump(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int app_keyring_dump(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (config.debug.verbose)
|
||||
DEBUG_cli_parsed(parsed);
|
||||
@ -1989,7 +2031,7 @@ int app_keyring_dump(const struct cli_parsed *parsed, struct cli_context *contex
|
||||
return ret;
|
||||
}
|
||||
|
||||
int app_keyring_load(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int app_keyring_load(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (config.debug.verbose)
|
||||
DEBUG_cli_parsed(parsed);
|
||||
@ -2039,7 +2081,7 @@ int app_keyring_list(const struct cli_parsed *parsed, struct cli_context *contex
|
||||
keyring_file *k = keyring_open_instance_cli(parsed);
|
||||
if (!k)
|
||||
return -1;
|
||||
int cn, in;
|
||||
unsigned cn, in;
|
||||
for (cn = 0; cn < k->context_count; ++cn)
|
||||
for (in = 0; in < k->contexts[cn]->identity_count; ++in) {
|
||||
const sid_t *sidp = NULL;
|
||||
@ -2058,7 +2100,7 @@ int app_keyring_list(const struct cli_parsed *parsed, struct cli_context *contex
|
||||
|
||||
static void cli_output_identity(struct cli_context *context, const keyring_identity *id)
|
||||
{
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i=0;i<id->keypair_count;i++){
|
||||
keypair *kp=id->keypairs[i];
|
||||
switch(kp->type){
|
||||
@ -2107,6 +2149,7 @@ int app_keyring_add(const struct cli_parsed *parsed, struct cli_context *context
|
||||
if (!k)
|
||||
return -1;
|
||||
keyring_enter_pin(k, pin);
|
||||
assert(k->context_count > 0);
|
||||
const keyring_identity *id = keyring_create_identity(k, k->contexts[k->context_count - 1], pin);
|
||||
if (id == NULL) {
|
||||
keyring_free(k);
|
||||
@ -2152,7 +2195,7 @@ int app_keyring_set_did(const struct cli_parsed *parsed, struct cli_context *con
|
||||
if (!(keyring = keyring_open_instance_cli(parsed)))
|
||||
return -1;
|
||||
|
||||
int cn=0,in=0,kp=0;
|
||||
unsigned cn=0, in=0, kp=0;
|
||||
int r=0;
|
||||
if (!keyring_find_sid(keyring, &cn, &in, &kp, &sid))
|
||||
r=WHY("No matching SID");
|
||||
@ -2187,7 +2230,7 @@ static int app_keyring_set_tag(const struct cli_parsed *parsed, struct cli_conte
|
||||
if (str_to_sid_t(&sid, sidhex) == -1)
|
||||
return WHY("str_to_sid_t() failed");
|
||||
|
||||
int cn=0,in=0,kp=0;
|
||||
unsigned cn=0, in=0, kp=0;
|
||||
int r=0;
|
||||
if (!keyring_find_sid(keyring, &cn, &in, &kp, &sid))
|
||||
r=WHY("No matching SID");
|
||||
@ -2226,7 +2269,7 @@ ssize_t mdp_poll_recv(int mdp_sock, time_ms_t timeout, struct mdp_header *rev_he
|
||||
return len;
|
||||
}
|
||||
|
||||
static int handle_pins(const struct cli_parsed *parsed, struct cli_context *context, int revoke)
|
||||
static int handle_pins(const struct cli_parsed *parsed, struct cli_context *UNUSED(context), int revoke)
|
||||
{
|
||||
const char *pin, *sid_hex;
|
||||
if (cli_arg(parsed, "entry-pin", &pin, NULL, "") == -1 ||
|
||||
@ -2248,22 +2291,21 @@ static int handle_pins(const struct cli_parsed *parsed, struct cli_context *cont
|
||||
}else{
|
||||
request->action=ACTION_UNLOCK;
|
||||
}
|
||||
int len = sizeof(struct mdp_identity_request);
|
||||
|
||||
if (pin && *pin){
|
||||
size_t len = sizeof(struct mdp_identity_request);
|
||||
if (pin && *pin) {
|
||||
request->type=TYPE_PIN;
|
||||
int pin_len = strlen(pin)+1;
|
||||
if (pin_len+len > sizeof(request_payload))
|
||||
size_t pin_siz = strlen(pin) + 1;
|
||||
if (pin_siz + len > sizeof(request_payload))
|
||||
return WHY("Supplied pin is too long");
|
||||
bcopy(pin, &request_payload[len], pin_len);
|
||||
len+=pin_len;
|
||||
bcopy(pin, &request_payload[len], pin_siz);
|
||||
len += pin_siz;
|
||||
}else if(sid_hex && *sid_hex){
|
||||
request->type=TYPE_SID;
|
||||
sid_t sid;
|
||||
if (str_to_sid_t(&sid, sid_hex) == -1)
|
||||
return WHY("str_to_sid_t() failed");
|
||||
bcopy(sid.binary, &request_payload[len], sizeof(sid));
|
||||
len+=sizeof(sid);
|
||||
len += sizeof(sid);
|
||||
}
|
||||
|
||||
if (!mdp_send(mdp_sock, &header, request_payload, len)){
|
||||
@ -2404,7 +2446,7 @@ int app_id_self(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
overlay_mdp_client_close(mdp_sockfd);
|
||||
return WHY("MDP Server returned something other than an address list");
|
||||
}
|
||||
int i;
|
||||
unsigned i;
|
||||
for(i=0;i<a.addrlist.frame_sid_count;i++) {
|
||||
count++;
|
||||
cli_printf(context, "%s", alloca_tohex_sid_t(a.addrlist.sids[i]));
|
||||
@ -2444,7 +2486,7 @@ int app_count_peers(const struct cli_parsed *parsed, struct cli_context *context
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_byteorder_test(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int app_byteorder_test(const struct cli_parsed *UNUSED(parsed), struct cli_context *UNUSED(context))
|
||||
{
|
||||
uint64_t in=0x1234;
|
||||
uint64_t out;
|
||||
@ -2791,7 +2833,7 @@ int app_reverse_lookup(const struct cli_parsed *parsed, struct cli_context *cont
|
||||
}
|
||||
|
||||
void context_switch_test(int);
|
||||
int app_mem_test(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int app_mem_test(const struct cli_parsed *UNUSED(parsed), struct cli_context *UNUSED(context))
|
||||
{
|
||||
size_t mem_size;
|
||||
size_t addr;
|
||||
@ -3007,5 +3049,5 @@ struct cli_schema command_line_options[]={
|
||||
{app_pa_phone,{"phone",NULL}, 0,
|
||||
"Run phone test application"},
|
||||
#endif
|
||||
{NULL,{NULL}}
|
||||
{NULL,{NULL},0,NULL}
|
||||
};
|
||||
|
25
conf_om.c
25
conf_om.c
@ -119,7 +119,7 @@ static int cf_om_make_child(struct cf_om_node **const parentp, const char *const
|
||||
if (!*parentp && (*parentp = emalloc_zero(sizeof **parentp)) == NULL)
|
||||
return -1;
|
||||
size_t keylen = keyend - key;
|
||||
int i = 0;
|
||||
unsigned i = 0;
|
||||
struct cf_om_node *child;
|
||||
if ((*parentp)->nodc) {
|
||||
// Binary search for matching child.
|
||||
@ -132,9 +132,9 @@ static int cf_om_make_child(struct cf_om_node **const parentp, const char *const
|
||||
c = strncmp(key, child->key, keylen);
|
||||
if (c == 0 && child->key[keylen])
|
||||
c = -1;
|
||||
//DEBUGF(" m=%d n=%d i=%d child->key=%s c=%d", m, n, i, alloca_str_toprint(child->key), c);
|
||||
//DEBUGF(" m=%u n=%u i=%u child->key=%s c=%d", m, n, i, alloca_str_toprint(child->key), c);
|
||||
if (c == 0) {
|
||||
//DEBUGF(" found i=%d", i);
|
||||
//DEBUGF(" found i=%u", i);
|
||||
return i;
|
||||
}
|
||||
if (c > 0)
|
||||
@ -144,7 +144,6 @@ static int cf_om_make_child(struct cf_om_node **const parentp, const char *const
|
||||
} while (m <= n);
|
||||
}
|
||||
// At this point, i is the index where a new child should be inserted.
|
||||
assert(i >= 0);
|
||||
assert(i <= (*parentp)->nodc);
|
||||
if ((child = emalloc_zero(sizeof *child)) == NULL)
|
||||
return -1;
|
||||
@ -156,11 +155,11 @@ static int cf_om_make_child(struct cf_om_node **const parentp, const char *const
|
||||
++(*parentp)->nodc;
|
||||
if ((*parentp)->nodc > NELS((*parentp)->nodv))
|
||||
*parentp = realloc(*parentp, sizeof(**parentp) + sizeof((*parentp)->nodv[0]) * ((*parentp)->nodc - NELS((*parentp)->nodv)));
|
||||
int j;
|
||||
unsigned j;
|
||||
for (j = (*parentp)->nodc - 1; j > i; --j)
|
||||
(*parentp)->nodv[j] = (*parentp)->nodv[j-1];
|
||||
(*parentp)->nodv[i] = child;
|
||||
//DEBUGF(" insert i=%d", i);
|
||||
//DEBUGF(" insert i=%u", i);
|
||||
return i;
|
||||
}
|
||||
|
||||
@ -184,7 +183,7 @@ int cf_om_get_child(const struct cf_om_node *parent, const char *key, const char
|
||||
if (keyend == NULL)
|
||||
keyend = key + strlen(key);
|
||||
// TODO: use binary search, since child nodes are already sorted by key
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < parent->nodc; ++i)
|
||||
if (memcmp(parent->nodv[i]->key, key, keyend - key) == 0 && parent->nodv[i]->key[keyend - key] == '\0')
|
||||
return i;
|
||||
@ -318,7 +317,7 @@ void cf_om_dump_node(const struct cf_om_node *node, int indent)
|
||||
alloca_str_toprint(node->key),
|
||||
alloca_str_toprint(node->text)
|
||||
);
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < node->nodc; ++i)
|
||||
cf_om_dump_node(node->nodv[i], indent + 1);
|
||||
}
|
||||
@ -445,7 +444,7 @@ int cf_om_iter_next(struct cf_om_iterator *it)
|
||||
return 0;
|
||||
while (1) {
|
||||
const struct cf_om_node *parent = it->stack[it->sp].node;
|
||||
int i = it->stack[it->sp].index++;
|
||||
unsigned i = it->stack[it->sp].index++;
|
||||
if (i < parent->nodc) {
|
||||
it->node = parent->nodv[i];
|
||||
if (it->node == NULL)
|
||||
@ -487,7 +486,7 @@ void _cf_warn_nodev(struct __sourceloc __whence, const struct cf_om_node *node,
|
||||
|
||||
void _cf_warn_childrenv(struct __sourceloc __whence, const struct cf_om_node *parent, const char *fmt, va_list ap)
|
||||
{
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < parent->nodc; ++i) {
|
||||
_cf_warn_nodev(__whence, parent->nodv[i], NULL, fmt, ap);
|
||||
_cf_warn_childrenv(__whence, parent->nodv[i], fmt, ap);
|
||||
@ -549,7 +548,7 @@ void _cf_warn_unsupported_node(struct __sourceloc __whence, const struct cf_om_n
|
||||
|
||||
void _cf_warn_unsupported_children(struct __sourceloc __whence, const struct cf_om_node *parent)
|
||||
{
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < parent->nodc; ++i) {
|
||||
if (parent->nodv[i]->text)
|
||||
_cf_warn_unsupported_node(__whence, parent->nodv[i]);
|
||||
@ -572,7 +571,7 @@ strbuf strbuf_cf_flags(strbuf sb, int flags)
|
||||
{ CFINVALID, "CFINVALID" },
|
||||
{ CFUNSUPPORTED, "CFUNSUPPORTED" },
|
||||
};
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < NELS(flagdefs); ++i) {
|
||||
if (flags & flagdefs[i].flag) {
|
||||
if (strbuf_len(sb) != n)
|
||||
@ -624,7 +623,7 @@ strbuf strbuf_cf_flag_reason(strbuf sb, int flags)
|
||||
{ CFSUB(CFINVALID), "contains invalid element" },
|
||||
{ CFSUB(CFUNSUPPORTED), "contains unsupported element" },
|
||||
};
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < NELS(flagdefs); ++i) {
|
||||
if (flags & flagdefs[i].flag) {
|
||||
if (strbuf_len(sb) != n)
|
||||
|
51
conf_parse.c
51
conf_parse.c
@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "constants.h"
|
||||
#include "log.h"
|
||||
#include "conf.h"
|
||||
|
||||
@ -212,7 +213,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
__ITEM(__element, (0 __flags)|__TEXT|__CHILDREN, cf_opt_##__repr(&strct->__element, child))
|
||||
#define END_STRUCT \
|
||||
{ \
|
||||
int i; \
|
||||
unsigned i; \
|
||||
for (i = 0; i < node->nodc; ++i) { \
|
||||
if (node->nodv[i]->text && !(used[i] & __TEXT)) { \
|
||||
cf_warn_unsupported_node(node->nodv[i]); \
|
||||
@ -246,7 +247,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
int (*keycmp)(const void *, const void *) = NULL; \
|
||||
int (*validator)(const struct cf_om_node *, struct config_##__name *, int) = (NULL, ##__validator); \
|
||||
int result = CFOK; \
|
||||
int i, n; \
|
||||
unsigned i, n; \
|
||||
for (n = 0, i = 0; i < node->nodc && n < NELS(array->av); ++i) { \
|
||||
const struct cf_om_node *child = node->nodv[i]; \
|
||||
int ret = CFEMPTY;
|
||||
@ -259,7 +260,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
ret &= CF__FLAGS; \
|
||||
result |= CFSUB(ret); \
|
||||
if (ret == CFOK && (flags & __NO_DUPLICATES)) { \
|
||||
int j; \
|
||||
unsigned j; \
|
||||
for (j = 0; j < n; ++j) { \
|
||||
if (__cmpfunc __cmpfuncargs == 0) { \
|
||||
cf_warn_duplicate_node(child, NULL); \
|
||||
@ -364,7 +365,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
int config_##__name##__get(const struct config_##__name *array,
|
||||
#define KEY_ATOM(__type, __keyrepr) \
|
||||
const __type *key) { \
|
||||
int i; \
|
||||
unsigned i; \
|
||||
for (i = 0; i < array->ac; ++i) \
|
||||
if ((cf_cmp_##__keyrepr(key, &array->av[i].key)) == 0) \
|
||||
return i; \
|
||||
@ -372,7 +373,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
}
|
||||
#define KEY_STRING(__strsize, __keyrepr) \
|
||||
const char *key) { \
|
||||
int i; \
|
||||
unsigned i; \
|
||||
for (i = 0; i < array->ac; ++i) \
|
||||
if ((cf_cmp_##__keyrepr(&key[0], &array->av[i].key[0])) == 0) \
|
||||
return i; \
|
||||
@ -417,7 +418,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#define __ADD_CHILD(nodep, __elementstr) \
|
||||
if ((i = cf_om_add_child(nodep, __elementstr)) == -1) \
|
||||
return -1; \
|
||||
childp = &(*nodep)->nodv[i];
|
||||
childp = &(*nodep)->nodv[(unsigned)i];
|
||||
#define __ATOM(nodep, __text) \
|
||||
if (((*nodep)->text = str_edup(__text)) == NULL) \
|
||||
return -1;
|
||||
@ -515,7 +516,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
int cf_fmt_config_##__name(struct cf_om_node **parentp, const struct config_##__name *strct) { \
|
||||
return cf_xfmt_config_##__name(parentp, strct, NULL); \
|
||||
} \
|
||||
int cf_xfmt_config_##__name(struct cf_om_node **parentp, const struct config_##__name *strct, const struct config_##__name *dflt) { \
|
||||
int cf_xfmt_config_##__name(struct cf_om_node **parentp, const struct config_##__name *strct, const struct config_##__name *UNUSED(dflt)) { \
|
||||
int result = CFOK; \
|
||||
int ret;
|
||||
#define __FMT_TEXT(__repr, __eltname, __eltexpr, __defaultvar) \
|
||||
@ -561,11 +562,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
else { \
|
||||
const char *funcname = NULL;
|
||||
#define __FMT_NODE_END \
|
||||
cf_om_remove_null_child(parentp, n); \
|
||||
cf_om_remove_null_child(parentp, (unsigned) n); \
|
||||
if (ret != CFOK) \
|
||||
WARNF("%s() returned %s", funcname, strbuf_str(strbuf_cf_flags(strbuf_alloca(300), ret))); \
|
||||
if (n < (*parentp)->nodc && cf_om_remove_empty_child(parentp, n)) { \
|
||||
WHYF("%s() returned empty node at n=%d", funcname, n); \
|
||||
if ((unsigned)n < (*parentp)->nodc && cf_om_remove_empty_child(parentp, (unsigned) n)) { \
|
||||
WHYF("%s() returned empty node at n=%u", funcname, (unsigned) n); \
|
||||
ret = CFERROR; \
|
||||
} \
|
||||
} \
|
||||
@ -576,7 +577,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#define NODE(__type, __element, __default, __repr, __flags, __comment) \
|
||||
{ \
|
||||
__FMT_NODE_START(__element) \
|
||||
ret = cf_fmt_##__repr(&(*parentp)->nodv[n], &strct->__element); \
|
||||
ret = cf_fmt_##__repr(&(*parentp)->nodv[(unsigned)n], &strct->__element); \
|
||||
funcname = "cf_fmt_" #__repr; \
|
||||
__FMT_NODE_END \
|
||||
}
|
||||
@ -586,10 +587,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
if (#__dfllabel[0]) { \
|
||||
struct config_##__structname dfl; \
|
||||
cf_dfl_config_##__structname##_cf_##__dfllabel(&dfl); \
|
||||
ret = cf_xfmt_config_##__structname(&(*parentp)->nodv[n], &strct->__element, &dfl); \
|
||||
ret = cf_xfmt_config_##__structname(&(*parentp)->nodv[(unsigned)n], &strct->__element, &dfl); \
|
||||
funcname = "cf_xfmt_config_" #__structname; \
|
||||
} else { \
|
||||
ret = cf_fmt_config_##__structname(&(*parentp)->nodv[n], &strct->__element); \
|
||||
ret = cf_fmt_config_##__structname(&(*parentp)->nodv[(unsigned)n], &strct->__element); \
|
||||
funcname = "cf_fmt_config_" #__structname; \
|
||||
} \
|
||||
__FMT_NODE_END \
|
||||
@ -597,7 +598,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#define NODE_STRUCT(__structname, __element, __repr, __flags, __dfllabel...) \
|
||||
{ \
|
||||
__FMT_NODE_START(__element) \
|
||||
ret = cf_fmt_##__repr(&(*parentp)->nodv[n], &strct->__element); \
|
||||
ret = cf_fmt_##__repr(&(*parentp)->nodv[(unsigned)n], &strct->__element); \
|
||||
funcname = "cf_fmt_" #__repr; \
|
||||
__FMT_NODE_END \
|
||||
}
|
||||
@ -619,12 +620,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#define SUB_STRUCT_DEFAULT(__name, __element, __dfllabel...)
|
||||
#define END_STRUCT_DEFAULT
|
||||
#define ARRAY(__name, __flags, __validator...) \
|
||||
int cf_xfmt_config_##__name(struct cf_om_node **parentp, const struct config_##__name *array, const struct config_##__name *dflt) { \
|
||||
int cf_xfmt_config_##__name(struct cf_om_node **parentp, const struct config_##__name *array, const struct config_##__name *UNUSED(dflt)) { \
|
||||
return cf_fmt_config_##__name(parentp, array); \
|
||||
} \
|
||||
int cf_fmt_config_##__name(struct cf_om_node **parentp, const struct config_##__name *array) { \
|
||||
int result = CFOK; \
|
||||
int i; \
|
||||
unsigned i; \
|
||||
for (i = 0; i < array->ac; ++i) {
|
||||
#define __ARRAY_KEY(__keyfunc, __keyexpr) \
|
||||
const char *key = NULL; \
|
||||
@ -646,15 +647,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
} \
|
||||
if (ret == CFOK) {
|
||||
#define __ARRAY_VALUE(__valuefunc) \
|
||||
cf_om_remove_null_child(parentp, n); \
|
||||
cf_om_remove_null_child(parentp, (unsigned)n); \
|
||||
if (ret != CFOK) \
|
||||
WARNF(#__valuefunc "() returned %s", strbuf_str(strbuf_cf_flags(strbuf_alloca(300), ret))); \
|
||||
if (n < (*parentp)->nodc && cf_om_remove_empty_child(parentp, n)) { \
|
||||
WHYF(#__valuefunc "() returned empty node at n=%d", n); \
|
||||
if ((unsigned)n < (*parentp)->nodc && cf_om_remove_empty_child(parentp, (unsigned)n)) { \
|
||||
WHYF(#__valuefunc "() returned empty node at n=%u", (unsigned)n); \
|
||||
ret = CFERROR; \
|
||||
}
|
||||
#define __ARRAY_TEXT(__valuefunc, __eltexpr) \
|
||||
ret = __valuefunc(&(*parentp)->nodv[n]->text, __eltexpr); \
|
||||
ret = __valuefunc(&(*parentp)->nodv[(unsigned)n]->text, __eltexpr); \
|
||||
__ARRAY_VALUE(__valuefunc)
|
||||
#define END_ARRAY(__size) \
|
||||
} \
|
||||
@ -676,19 +677,19 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#define VALUE_STRING(__strsize, __eltrepr) \
|
||||
__ARRAY_TEXT(cf_fmt_##__eltrepr, &array->av[i].value[0])
|
||||
#define VALUE_NODE(__type, __eltrepr) \
|
||||
ret = cf_fmt_##__eltrepr(&(*parentp)->nodv[n], &array->av[i].value); \
|
||||
ret = cf_fmt_##__eltrepr(&(*parentp)->nodv[(unsigned)n], &array->av[i].value); \
|
||||
__ARRAY_VALUE(cf_fmt_##__eltrepr)
|
||||
#define VALUE_SUB_STRUCT(__structname, __dfllabel...) \
|
||||
if (#__dfllabel[0]) { \
|
||||
struct config_##__structname dfl; \
|
||||
cf_dfl_config_##__structname##_cf_##__dfllabel(&dfl); \
|
||||
ret = cf_xfmt_config_##__structname(&(*parentp)->nodv[n], &array->av[i].value, &dfl); \
|
||||
ret = cf_xfmt_config_##__structname(&(*parentp)->nodv[(unsigned)n], &array->av[i].value, &dfl); \
|
||||
} else { \
|
||||
ret = cf_fmt_config_##__structname(&(*parentp)->nodv[n], &array->av[i].value); \
|
||||
ret = cf_fmt_config_##__structname(&(*parentp)->nodv[(unsigned)n], &array->av[i].value); \
|
||||
} \
|
||||
__ARRAY_VALUE(cf_fmt_config_##__structname)
|
||||
#define VALUE_NODE_STRUCT(__structname, __eltrepr) \
|
||||
ret = cf_fmt_##__eltrepr(&(*parentp)->nodv[n], &array->av[i].value); \
|
||||
ret = cf_fmt_##__eltrepr(&(*parentp)->nodv[(unsigned)n], &array->av[i].value); \
|
||||
__ARRAY_VALUE(cf_fmt_##__eltrepr)
|
||||
#include "conf_schema.h"
|
||||
#undef STRUCT
|
||||
@ -757,7 +758,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#define ARRAY(__name, __flags, __validator...) \
|
||||
int cf_cmp_config_##__name(const struct config_##__name *a, const struct config_##__name *b) { \
|
||||
int c; \
|
||||
int i; \
|
||||
unsigned i; \
|
||||
for (i = 0; i < a->ac && i < b->ac; ++i) {
|
||||
#define KEY_ATOM(__type, __keyrepr) \
|
||||
if ((c = cf_cmp_##__keyrepr(&a->av[i].key, &b->av[i].key))) \
|
||||
|
@ -504,7 +504,7 @@ int cf_cmp_ushort_nonzero(const unsigned short *a, const unsigned short *b)
|
||||
int vld_argv(const struct cf_om_node *parent, struct config_argv *array, int result)
|
||||
{
|
||||
unsigned short last_key = 0;
|
||||
int i;
|
||||
unsigned i;
|
||||
if (array->ac) {
|
||||
unsigned short last_key = array->av[0].key;
|
||||
for (i = 1; i < array->ac; ++i) {
|
||||
|
13
constants.h
13
constants.h
@ -19,7 +19,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#ifndef __SERVAL_DNA__CONSTANTS_H
|
||||
#define __SERVAL_DNA__CONSTANTS_H
|
||||
|
||||
#define NELS(a) (sizeof (a) / sizeof *(a))
|
||||
/* Useful macros not specific to Serval DNA
|
||||
*/
|
||||
|
||||
// Number of elements in an array (Warning: does not work if A is a pointer!).
|
||||
#define NELS(A) (sizeof (A) / sizeof *(A))
|
||||
|
||||
// To suppress the "unused parameter" warning from -Wunused-parameter.
|
||||
#ifdef __GNUC__
|
||||
# define UNUSED(x) x __attribute__((__unused__))
|
||||
#else
|
||||
# define UNUSED(x) x
|
||||
#endif
|
||||
|
||||
/* Packet format:
|
||||
|
||||
|
4
crypto.c
4
crypto.c
@ -102,10 +102,10 @@ int crypto_create_signature(unsigned char *key,
|
||||
}
|
||||
|
||||
// sign the hash of a message, adding the signature to the end of the message buffer.
|
||||
int crypto_sign_message(struct subscriber *source, unsigned char *content, int buffer_len, int *content_len)
|
||||
int crypto_sign_message(struct subscriber *source, unsigned char *content, size_t buffer_len, size_t *content_len)
|
||||
{
|
||||
if (*content_len + SIGNATURE_BYTES > buffer_len)
|
||||
return WHYF("Insufficient space in message buffer to add signature. %d, need %d",buffer_len, *content_len + SIGNATURE_BYTES);
|
||||
return WHYF("Insufficient space in message buffer to add signature. %zu, need %zu",buffer_len, *content_len + SIGNATURE_BYTES);
|
||||
|
||||
unsigned char *key=keyring_find_sas_private(keyring, &source->sid, NULL);
|
||||
if (!key)
|
||||
|
2
crypto.h
2
crypto.h
@ -30,7 +30,7 @@ int crypto_verify_message(struct subscriber *subscriber, unsigned char *message,
|
||||
int crypto_create_signature(unsigned char *key,
|
||||
unsigned char *content, int content_len,
|
||||
unsigned char *signature, int *sig_length);
|
||||
int crypto_sign_message(struct subscriber *source, unsigned char *content, int buffer_len, int *content_len);
|
||||
int crypto_sign_message(struct subscriber *source, unsigned char *content, size_t buffer_len, size_t *content_len);
|
||||
int crypto_sign_compute_public_key(const unsigned char *skin, unsigned char *pk);
|
||||
|
||||
#endif
|
||||
|
@ -75,19 +75,16 @@ static void directory_send(struct subscriber *directory_service, const sid_t *si
|
||||
|
||||
// send a registration packet for each unlocked identity
|
||||
static void directory_send_keyring(struct subscriber *directory_service){
|
||||
int cn=0, in=0, kp=0, k2;
|
||||
|
||||
unsigned cn=0, in=0, kp=0;
|
||||
for (; !keyring_sanitise_position(keyring, &cn, &in, &kp); ++kp){
|
||||
keyring_identity *i = keyring->contexts[cn]->identities[in];
|
||||
|
||||
if (i->keypairs[kp]->type == KEYTYPE_CRYPTOBOX){
|
||||
const sid_t *sidp = (const sid_t *) i->keypairs[0]->public_key;
|
||||
|
||||
unsigned k2;
|
||||
for(k2=0; k2 < i->keypair_count; k2++){
|
||||
if (i->keypairs[k2]->type==KEYTYPE_DID){
|
||||
const char *unpackedDid = (const char *) i->keypairs[k2]->private_key;
|
||||
const char *name = (const char *) i->keypairs[k2]->public_key;
|
||||
|
||||
directory_send(directory_service, sidp, unpackedDid, name);
|
||||
// send the first DID only
|
||||
break;
|
||||
|
42
dna_helper.c
42
dna_helper.c
@ -17,6 +17,36 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
@ -88,8 +118,8 @@ static int dna_helper_started = 0;
|
||||
|
||||
#define DECLARE_SCHED_ENT(FUNCTION, VARIABLE) \
|
||||
static void FUNCTION(struct sched_ent *alarm); \
|
||||
static struct profile_total VARIABLE##_timing={.name="" #FUNCTION "",}; \
|
||||
static struct sched_ent VARIABLE = {.function = FUNCTION, .stats = & VARIABLE##_timing, .poll.fd = -1, };
|
||||
static struct profile_total VARIABLE##_timing={.name="" #FUNCTION "",._next=NULL,._initialised=0,.max_time=0,.total_time=0,.child_time=0,.calls=0}; \
|
||||
static struct sched_ent VARIABLE = {.function = FUNCTION, .stats = & VARIABLE##_timing, .poll={.fd=-1}};
|
||||
|
||||
DECLARE_SCHED_ENT(monitor_requests, sched_requests);
|
||||
DECLARE_SCHED_ENT(monitor_replies, sched_replies);
|
||||
@ -183,7 +213,7 @@ dna_helper_start()
|
||||
// Construct argv[] for execv() and log messages.
|
||||
const char *argv[config.dna.helper.argv.ac + 2];
|
||||
argv[0] = config.dna.helper.executable;
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < config.dna.helper.argv.ac; ++i)
|
||||
argv[i + 1] = config.dna.helper.argv.av[i].value;
|
||||
argv[i + 1] = NULL;
|
||||
@ -325,6 +355,7 @@ static void monitor_requests(struct sched_ent *alarm)
|
||||
strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_requests.poll.revents))
|
||||
);
|
||||
}
|
||||
assert(alarm == &sched_requests);
|
||||
// On Linux, poll(2) returns ERR when the remote reader dies. On Mac OS X, poll(2) returns NVAL,
|
||||
// which is documented to mean the file descriptor is not open, but testing revealed that in this
|
||||
// case it is still open. See issue #5.
|
||||
@ -451,6 +482,7 @@ static void monitor_replies(struct sched_ent *alarm)
|
||||
strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_replies.poll.revents))
|
||||
);
|
||||
}
|
||||
assert(alarm == &sched_replies);
|
||||
if (sched_replies.poll.revents & POLLIN) {
|
||||
size_t remaining = reply_buffer + sizeof reply_buffer - reply_bufend;
|
||||
ssize_t nread = read_nonblock(sched_replies.poll.fd, reply_bufend, remaining);
|
||||
@ -503,6 +535,7 @@ static void monitor_errors(struct sched_ent *alarm)
|
||||
strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_errors.poll.revents))
|
||||
);
|
||||
}
|
||||
assert(alarm == &sched_errors);
|
||||
if (sched_errors.poll.revents & POLLIN) {
|
||||
char buffer[1024];
|
||||
ssize_t nread = read_nonblock(sched_errors.poll.fd, buffer, sizeof buffer);
|
||||
@ -521,6 +554,7 @@ static void monitor_errors(struct sched_ent *alarm)
|
||||
|
||||
static void harvester(struct sched_ent *alarm)
|
||||
{
|
||||
assert(alarm == &sched_harvester);
|
||||
// While the helper process appears to still be running, keep calling this function.
|
||||
// Otherwise, wait a while before re-starting the helper.
|
||||
if (dna_helper_harvest(0) <= 0) {
|
||||
@ -541,6 +575,7 @@ static void harvester(struct sched_ent *alarm)
|
||||
|
||||
static void restart_delayer(struct sched_ent *alarm)
|
||||
{
|
||||
assert(alarm == &sched_restart);
|
||||
if (dna_helper_pid == 0) {
|
||||
if (config.debug.dnahelper)
|
||||
DEBUG("DNAHELPER re-enable restart");
|
||||
@ -550,6 +585,7 @@ static void restart_delayer(struct sched_ent *alarm)
|
||||
|
||||
static void reply_timeout(struct sched_ent *alarm)
|
||||
{
|
||||
assert(alarm == &sched_timeout);
|
||||
if (awaiting_reply) {
|
||||
WHY("DNAHELPER reply timeout");
|
||||
dna_helper_kill();
|
||||
|
44
fakeradio.c
44
fakeradio.c
@ -42,13 +42,13 @@ struct radio_state {
|
||||
int state;
|
||||
const char *name;
|
||||
char commandbuffer[128];
|
||||
int cb_len;
|
||||
unsigned cb_len;
|
||||
unsigned char txbuffer[1280];
|
||||
int txb_len;
|
||||
int tx_count;
|
||||
int wait_count;
|
||||
unsigned txb_len;
|
||||
unsigned tx_count;
|
||||
unsigned wait_count;
|
||||
unsigned char rxbuffer[512];
|
||||
int rxb_len;
|
||||
unsigned rxb_len;
|
||||
int64_t last_char_ms;
|
||||
int64_t next_rssi_time_ms;
|
||||
int rssi_output;
|
||||
@ -130,9 +130,9 @@ int processCommand(struct radio_state *s)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int dump(char *name, unsigned char *addr, int len)
|
||||
int dump(char *name, unsigned char *addr, size_t len)
|
||||
{
|
||||
int i,j;
|
||||
unsigned i,j;
|
||||
if (name)
|
||||
fprintf(stderr,"Dump of %s\n",name);
|
||||
for(i=0;i<len;i+=16){
|
||||
@ -205,22 +205,21 @@ int read_bytes(struct radio_state *s)
|
||||
return bytes;
|
||||
}
|
||||
|
||||
int write_bytes(struct radio_state *s)
|
||||
void write_bytes(struct radio_state *s)
|
||||
{
|
||||
int wrote=s->rxb_len;
|
||||
ssize_t wrote = s->rxb_len;
|
||||
if (wrote>8)
|
||||
wrote=8;
|
||||
if (s->last_char_ms)
|
||||
wrote = write(s->fd, s->rxbuffer, wrote);
|
||||
if (wrote>0){
|
||||
if (wrote != -1){
|
||||
log_time();
|
||||
fprintf(stderr, "Wrote to %s\n", s->name);
|
||||
dump(NULL, s->rxbuffer, wrote);
|
||||
if (wrote < s->rxb_len)
|
||||
bcopy(&s->rxbuffer[wrote], s->rxbuffer, s->rxb_len - wrote);
|
||||
s->rxb_len -= wrote;
|
||||
dump(NULL, s->rxbuffer, (size_t)wrote);
|
||||
if ((size_t)wrote < s->rxb_len)
|
||||
bcopy(&s->rxbuffer[(size_t)wrote], s->rxbuffer, s->rxb_len - (size_t)wrote);
|
||||
s->rxb_len -= (size_t)wrote;
|
||||
}
|
||||
return wrote;
|
||||
}
|
||||
|
||||
int transmitter=0;
|
||||
@ -286,21 +285,21 @@ int build_heartbeat(struct radio_state *s){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int transfer_bytes(struct radio_state *radios)
|
||||
void transfer_bytes(struct radio_state *radios)
|
||||
{
|
||||
// if there's data to transmit, copy a radio packet from one device to the other
|
||||
int receiver = transmitter^1;
|
||||
struct radio_state *r = &radios[receiver];
|
||||
struct radio_state *t = &radios[transmitter];
|
||||
int bytes=t->txb_len;
|
||||
size_t bytes = t->txb_len;
|
||||
|
||||
if (bytes > PACKET_SIZE)
|
||||
bytes = PACKET_SIZE;
|
||||
|
||||
// try to send some number of whole mavlink frames from our buffer
|
||||
{
|
||||
int p=0, send=0;
|
||||
while(p < bytes){
|
||||
size_t p=0, send=0;
|
||||
while (p < bytes){
|
||||
|
||||
if (t->txbuffer[p]==MAVLINK10_STX){
|
||||
// a mavlink header
|
||||
@ -315,7 +314,7 @@ int transfer_bytes(struct radio_state *radios)
|
||||
break;
|
||||
|
||||
// how big is this mavlink frame?
|
||||
int size = t->txbuffer[p+1];
|
||||
size_t size = t->txbuffer[p+1];
|
||||
|
||||
// if the size is valid, try to send the whole packet at once
|
||||
if (size <= PACKET_SIZE - MAVLINK_HDR){
|
||||
@ -359,7 +358,7 @@ int transfer_bytes(struct radio_state *radios)
|
||||
fprintf(stderr, "Transferring %d byte packet from %s to %s\n", bytes, t->name, r->name);
|
||||
}
|
||||
|
||||
int i, j;
|
||||
unsigned i, j;
|
||||
int dropped=0;
|
||||
|
||||
// preamble length in bits that must arrive intact
|
||||
@ -394,14 +393,13 @@ int transfer_bytes(struct radio_state *radios)
|
||||
// set the wait time for the next transmission
|
||||
next_transmit_time = gettime_ms() + 5 + bytes/chars_per_ms;
|
||||
|
||||
if (bytes==0 || --t->tx_count<=0){
|
||||
if (bytes==0 || t->tx_count == 0 || --t->tx_count == 0){
|
||||
// swap who's turn it is to transmit after sending 3 packets or running out of data.
|
||||
transmitter = receiver;
|
||||
r->tx_count=3;
|
||||
// add Tx->Rx change time (it's about 40ms between receiving empty packets)
|
||||
next_transmit_time+=15;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
int calc_ber(double target_packet_fraction)
|
||||
|
42
fdqueue.c
42
fdqueue.c
@ -17,6 +17,35 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fdqueue.h"
|
||||
#include "conf.h"
|
||||
#include "str.h"
|
||||
@ -29,7 +58,7 @@ int fdcount=0;
|
||||
struct sched_ent *fd_callbacks[MAX_WATCHED_FDS];
|
||||
struct sched_ent *next_alarm=NULL;
|
||||
struct sched_ent *next_deadline=NULL;
|
||||
struct profile_total poll_stats={NULL,0,"Idle (in poll)",0,0,0};
|
||||
struct profile_total poll_stats={NULL,0,"Idle (in poll)",0,0,0,0};
|
||||
|
||||
#define alloca_alarm_name(alarm) ((alarm)->stats ? alloca_str_toprint((alarm)->stats->name) : "Unnamed")
|
||||
|
||||
@ -103,6 +132,10 @@ int _schedule(struct __sourceloc __whence, struct sched_ent *alarm)
|
||||
if (!alarm->function)
|
||||
return WHY("Can't schedule if you haven't set the function pointer");
|
||||
|
||||
// don't bother to schedule an alarm that will (by definition) never run
|
||||
if (alarm->alarm == TIME_NEVER_WILL)
|
||||
return 0;
|
||||
|
||||
if (alarm->deadline < alarm->alarm)
|
||||
alarm->deadline = alarm->alarm;
|
||||
|
||||
@ -191,6 +224,13 @@ int _watch(struct __sourceloc __whence, struct sched_ent *alarm)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int is_watching(struct sched_ent *alarm)
|
||||
{
|
||||
if (alarm->_poll_index <0 || fds[alarm->_poll_index].fd!=alarm->poll.fd)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// stop watching a file handle
|
||||
int _unwatch(struct __sourceloc __whence, struct sched_ent *alarm)
|
||||
{
|
||||
|
32
fdqueue.h
32
fdqueue.h
@ -17,6 +17,35 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __SERVAL_DNA__FDQUEUE_H
|
||||
#define __SERVAL_DNA__FDQUEUE_H
|
||||
|
||||
@ -63,6 +92,7 @@ struct sched_ent{
|
||||
};
|
||||
|
||||
int is_scheduled(const struct sched_ent *alarm);
|
||||
int is_watching(struct sched_ent *alarm);
|
||||
int _schedule(struct __sourceloc, struct sched_ent *alarm);
|
||||
int _unschedule(struct __sourceloc, struct sched_ent *alarm);
|
||||
int _watch(struct __sourceloc, struct sched_ent *alarm);
|
||||
@ -82,7 +112,7 @@ int fd_func_exit(struct __sourceloc, struct call_stats *this_call);
|
||||
void dump_stack(int log_level);
|
||||
unsigned fd_depth();
|
||||
|
||||
#define IN() static struct profile_total _aggregate_stats={NULL,0,__FUNCTION__,0,0,0}; \
|
||||
#define IN() static struct profile_total _aggregate_stats={NULL,0,__FUNCTION__,0,0,0,0}; \
|
||||
struct call_stats _this_call={.totals=&_aggregate_stats}; \
|
||||
fd_func_enter(__HERE__, &_this_call);
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
rs = NULL;
|
||||
/* Check parameter ranges */
|
||||
if(symsize < 0 || symsize > 8*sizeof(data_t)){
|
||||
if(symsize < 0 || symsize > (int)(8*sizeof(data_t))){
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
@ -1593,7 +1593,7 @@ static void http_request_send_response(struct http_request *r)
|
||||
if (r->phase != PAUSE)
|
||||
http_request_set_idle_timeout(r);
|
||||
// If we wrote less than we tried, then go back to polling, otherwise keep generating content.
|
||||
if (written < (size_t) unsent)
|
||||
if ((size_t) written < (size_t) unsent)
|
||||
return;
|
||||
}
|
||||
if (r->debug_flag && *r->debug_flag)
|
||||
|
119
keyring.c
119
keyring.c
@ -238,10 +238,12 @@ static void wipestr(char *str)
|
||||
*str++ = ' ';
|
||||
}
|
||||
|
||||
void keyring_release_identity(keyring_file *k, int cn, int id){
|
||||
void keyring_release_identity(keyring_file *k, unsigned cn, unsigned id)
|
||||
{
|
||||
if (config.debug.keyring)
|
||||
DEBUGF("Releasing k=%p, cn=%d, id=%d", k, cn, id);
|
||||
DEBUGF("Releasing k=%p, cn=%u, id=%u", k, cn, id);
|
||||
keyring_context *c=k->contexts[cn];
|
||||
assert(c->identity_count > 0);
|
||||
c->identity_count--;
|
||||
keyring_free_identity(c->identities[id]);
|
||||
if (id!=c->identity_count)
|
||||
@ -249,6 +251,7 @@ void keyring_release_identity(keyring_file *k, int cn, int id){
|
||||
c->identities[c->identity_count]=NULL;
|
||||
if (c->identity_count==0){
|
||||
keyring_free_context(c);
|
||||
assert(k->context_count > 0);
|
||||
k->context_count --;
|
||||
if (cn!=k->context_count)
|
||||
k->contexts[cn] = k->contexts[k->context_count];
|
||||
@ -258,8 +261,8 @@ void keyring_release_identity(keyring_file *k, int cn, int id){
|
||||
|
||||
void keyring_release_subscriber(keyring_file *k, const sid_t *sid)
|
||||
{
|
||||
int cn=0,in=0,kp=0;
|
||||
if (keyring_find_sid(keyring, &cn, &in, &kp, sid)
|
||||
unsigned cn=0, in=0, kp=0;
|
||||
if (keyring_find_sid(k, &cn, &in, &kp, sid)
|
||||
&& keyring->contexts[cn]->identities[in]->subscriber != my_subscriber)
|
||||
keyring_release_identity(keyring, cn, in);
|
||||
}
|
||||
@ -328,7 +331,7 @@ int keyring_enter_keyringpin(keyring_file *k, const char *pin)
|
||||
return WHY("Too many loaded contexts already");
|
||||
if (k->context_count < 1)
|
||||
return WHY("Cannot enter PIN without keyring salt being available");
|
||||
int cn;
|
||||
unsigned cn;
|
||||
for (cn = 0; cn < k->context_count; ++cn)
|
||||
if (strcmp(k->contexts[cn]->KeyRingPin, pin) == 0)
|
||||
return cn;
|
||||
@ -444,7 +447,7 @@ struct keytype {
|
||||
size_t packed_size;
|
||||
void (*creator)(keypair *);
|
||||
int (*packer)(const keypair *, struct rotbuf *);
|
||||
int (*unpacker)(keypair *, struct rotbuf *, int);
|
||||
int (*unpacker)(keypair *, struct rotbuf *, size_t);
|
||||
void (*dumper)(const keypair *, XPRINTF, int);
|
||||
int (*loader)(keypair *, const char *);
|
||||
};
|
||||
@ -630,14 +633,15 @@ static int load_unknown(keypair *kp, const char *text)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int unpack_private_public(keypair *kp, struct rotbuf *rb, int key_length)
|
||||
static int unpack_private_public(keypair *kp, struct rotbuf *rb, size_t key_length)
|
||||
{
|
||||
assert(key_length == kp->private_key_len + kp->public_key_len);
|
||||
rotbuf_getbuf(rb, kp->private_key, kp->private_key_len);
|
||||
rotbuf_getbuf(rb, kp->public_key, kp->public_key_len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int unpack_private_only(keypair *kp, struct rotbuf *rb, int key_length)
|
||||
static int unpack_private_only(keypair *kp, struct rotbuf *rb, size_t key_length)
|
||||
{
|
||||
if (!kp->private_key){
|
||||
kp->private_key_len = key_length;
|
||||
@ -648,7 +652,7 @@ static int unpack_private_only(keypair *kp, struct rotbuf *rb, int key_length)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int unpack_public_only(keypair *kp, struct rotbuf *rb, int key_length)
|
||||
static int unpack_public_only(keypair *kp, struct rotbuf *rb, size_t key_length)
|
||||
{
|
||||
if (!kp->public_key){
|
||||
kp->public_key_len = key_length;
|
||||
@ -659,8 +663,9 @@ static int unpack_public_only(keypair *kp, struct rotbuf *rb, int key_length)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int unpack_cryptobox(keypair *kp, struct rotbuf *rb, int key_length)
|
||||
static int unpack_cryptobox(keypair *kp, struct rotbuf *rb, size_t key_length)
|
||||
{
|
||||
assert(key_length == kp->private_key_len);
|
||||
rotbuf_getbuf(rb, kp->private_key, kp->private_key_len);
|
||||
if (!rb->wrap)
|
||||
_derive_scalarmult_public(kp->public_key, kp->private_key);
|
||||
@ -675,7 +680,7 @@ static int pack_did_name(const keypair *kp, struct rotbuf *rb)
|
||||
return pack_private_public(kp, rb);
|
||||
}
|
||||
|
||||
static int unpack_did_name(keypair *kp, struct rotbuf *rb, int key_length)
|
||||
static int unpack_did_name(keypair *kp, struct rotbuf *rb, size_t key_length)
|
||||
{
|
||||
if (unpack_private_public(kp, rb, key_length) == -1)
|
||||
return -1;
|
||||
@ -683,7 +688,7 @@ static int unpack_did_name(keypair *kp, struct rotbuf *rb, int key_length)
|
||||
return strnchr((const char *)kp->public_key, kp->public_key_len, '\0') == NULL ? -1 : 0;
|
||||
}
|
||||
|
||||
static void dump_did_name(const keypair *kp, XPRINTF xpf, int include_secret)
|
||||
static void dump_did_name(const keypair *kp, XPRINTF xpf, int UNUSED(include_secret))
|
||||
{
|
||||
xprintf(xpf, " DID=%s", alloca_str_toprint_quoted((const char *)kp->private_key, "\"\""));
|
||||
xprintf(xpf, " Name=%s", alloca_str_toprint_quoted((const char *)kp->public_key, "\"\""));
|
||||
@ -958,9 +963,9 @@ static int cmp_keypair(const keypair *a, const keypair *b)
|
||||
if (c == 0 && a->public_key_len) {
|
||||
assert(a->public_key != NULL);
|
||||
assert(b->public_key != NULL);
|
||||
int len=a->public_key_len;
|
||||
if (len>b->public_key_len)
|
||||
len=b->public_key_len;
|
||||
size_t len = a->public_key_len;
|
||||
if (len > b->public_key_len)
|
||||
len = b->public_key_len;
|
||||
c = memcmp(a->public_key, b->public_key, len);
|
||||
if (c==0 && a->public_key_len!=b->public_key_len)
|
||||
c = a->public_key_len - b->public_key_len;
|
||||
@ -968,9 +973,9 @@ static int cmp_keypair(const keypair *a, const keypair *b)
|
||||
if (c == 0 && a->private_key_len) {
|
||||
assert(a->private_key != NULL);
|
||||
assert(b->private_key != NULL);
|
||||
int len=a->private_key_len;
|
||||
if (len>b->private_key_len)
|
||||
len=b->private_key_len;
|
||||
size_t len = a->private_key_len;
|
||||
if (len > b->private_key_len)
|
||||
len = b->private_key_len;
|
||||
c = memcmp(a->private_key, b->private_key, len);
|
||||
if (c==0 && a->private_key_len!=b->private_key_len)
|
||||
c = a->private_key_len - b->private_key_len;
|
||||
@ -1168,7 +1173,7 @@ static int keyring_decrypt_pkr(keyring_file *k, unsigned cn, const char *pin, in
|
||||
goto kdp_safeexit;
|
||||
}
|
||||
// Add any unlocked subscribers to our memory table, flagged as local SIDs.
|
||||
int i=0;
|
||||
unsigned i;
|
||||
for (i=0;i<id->keypair_count;i++){
|
||||
if (id->keypairs[i]->type == KEYTYPE_CRYPTOBOX) {
|
||||
add_subscriber(id, i);
|
||||
@ -1237,7 +1242,7 @@ int keyring_enter_pin(keyring_file *k, const char *pin)
|
||||
if (b->bitmap[byte]&(1<<bit)) {
|
||||
/* Slot is occupied, so check it.
|
||||
We have to check it for each keyring context (ie keyring pin) */
|
||||
int cn;
|
||||
unsigned cn;
|
||||
for (cn = 0; cn < k->context_count; ++cn)
|
||||
if (keyring_decrypt_pkr(k, cn, pin, slot) == 0)
|
||||
++identitiesFound;
|
||||
@ -1444,7 +1449,7 @@ int keyring_set_did(keyring_identity *id, const char *did, const char *name)
|
||||
if (!name) name="Mr. Smith";
|
||||
|
||||
/* Find where to put it */
|
||||
int i;
|
||||
unsigned i;
|
||||
for(i=0;i<id->keypair_count;i++)
|
||||
if (id->keypairs[i]->type==KEYTYPE_DID) {
|
||||
if (config.debug.keyring)
|
||||
@ -1461,27 +1466,27 @@ int keyring_set_did(keyring_identity *id, const char *did, const char *name)
|
||||
if (config.debug.keyring)
|
||||
DEBUG("Created DID record for identity");
|
||||
}
|
||||
|
||||
|
||||
/* Store DID unpacked for ease of searching */
|
||||
int len=strlen(did);
|
||||
size_t len=strlen(did);
|
||||
if (len>31)
|
||||
len=31;
|
||||
bcopy(did,&id->keypairs[i]->private_key[0],len);
|
||||
bzero(&id->keypairs[i]->private_key[len],32-len);
|
||||
len=strlen(name);
|
||||
if (len>63)
|
||||
len=strlen(name);
|
||||
if (len>63)
|
||||
len=63;
|
||||
bcopy(name,&id->keypairs[i]->public_key[0],len);
|
||||
bzero(&id->keypairs[i]->public_key[len],64-len);
|
||||
|
||||
|
||||
if (config.debug.keyring){
|
||||
dump("storing did",&id->keypairs[i]->private_key[0],32);
|
||||
dump("storing name",&id->keypairs[i]->public_key[0],64);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int keyring_find_did(const keyring_file *k, int *cn, int *in, int *kp, const char *did)
|
||||
int keyring_find_did(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp, const char *did)
|
||||
{
|
||||
for(;keyring_next_keytype(k,cn,in,kp,KEYTYPE_DID);++(*kp)) {
|
||||
/* Compare DIDs */
|
||||
@ -1527,8 +1532,8 @@ int keyring_pack_tag(unsigned char *packed, size_t *packed_len, const char *name
|
||||
|
||||
int keyring_set_public_tag(keyring_identity *id, const char *name, const unsigned char *value, size_t length)
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<id->keypair_count;i++){
|
||||
unsigned i;
|
||||
for (i=0;i<id->keypair_count;i++){
|
||||
const char *tag_name;
|
||||
const unsigned char *tag_value;
|
||||
size_t tag_length;
|
||||
@ -1570,7 +1575,7 @@ int keyring_set_public_tag(keyring_identity *id, const char *name, const unsigne
|
||||
return 0;
|
||||
}
|
||||
|
||||
int keyring_find_public_tag(const keyring_file *k, int *cn, int *in, int *kp, const char *name, const unsigned char **value, size_t *length)
|
||||
int keyring_find_public_tag(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp, const char *name, const unsigned char **value, size_t *length)
|
||||
{
|
||||
for(;keyring_next_keytype(k,cn,in,kp,KEYTYPE_PUBLIC_TAG);++(*kp)) {
|
||||
keypair *keypair=k->contexts[*cn]->identities[*in]->keypairs[*kp];
|
||||
@ -1585,7 +1590,7 @@ int keyring_find_public_tag(const keyring_file *k, int *cn, int *in, int *kp, co
|
||||
return 0;
|
||||
}
|
||||
|
||||
int keyring_find_public_tag_value(const keyring_file *k, int *cn, int *in, int *kp, const char *name, const unsigned char *value, size_t length)
|
||||
int keyring_find_public_tag_value(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp, const char *name, const unsigned char *value, size_t length)
|
||||
{
|
||||
const unsigned char *stored_value;
|
||||
size_t stored_length;
|
||||
@ -1596,16 +1601,16 @@ int keyring_find_public_tag_value(const keyring_file *k, int *cn, int *in, int *
|
||||
return 0;
|
||||
}
|
||||
|
||||
int keyring_identity_find_keytype(const keyring_file *k, int cn, int in, int keytype)
|
||||
int keyring_identity_find_keytype(const keyring_file *k, unsigned cn, unsigned in, unsigned keytype)
|
||||
{
|
||||
int kp;
|
||||
for (kp = 0; kp < keyring->contexts[cn]->identities[in]->keypair_count; ++kp)
|
||||
if (keyring->contexts[cn]->identities[in]->keypairs[kp]->type == keytype)
|
||||
unsigned kp;
|
||||
for (kp = 0; kp < k->contexts[cn]->identities[in]->keypair_count; ++kp)
|
||||
if (k->contexts[cn]->identities[in]->keypairs[kp]->type == keytype)
|
||||
return kp;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int keyring_next_keytype(const keyring_file *k, int *cn, int *in, int *kp, int keytype)
|
||||
int keyring_next_keytype(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp, unsigned keytype)
|
||||
{
|
||||
for (; keyring_sanitise_position(k, cn, in, kp) == 0; ++*kp)
|
||||
if (k->contexts[*cn]->identities[*in]->keypairs[*kp]->type == keytype)
|
||||
@ -1613,15 +1618,13 @@ int keyring_next_keytype(const keyring_file *k, int *cn, int *in, int *kp, int k
|
||||
return 0;
|
||||
}
|
||||
|
||||
int keyring_next_identity(const keyring_file *k, int *cn, int *in, int *kp)
|
||||
int keyring_next_identity(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp)
|
||||
{
|
||||
return keyring_next_keytype(k, cn, in, kp, KEYTYPE_CRYPTOBOX);
|
||||
}
|
||||
|
||||
int keyring_sanitise_position(const keyring_file *k,int *cn,int *in,int *kp)
|
||||
int keyring_sanitise_position(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp)
|
||||
{
|
||||
if (!k)
|
||||
return 1;
|
||||
/* Sanity check passed in position */
|
||||
while(1){
|
||||
if ((*cn)>=k->context_count)
|
||||
@ -1646,15 +1649,13 @@ int keyring_sanitise_position(const keyring_file *k,int *cn,int *in,int *kp)
|
||||
unsigned char *keyring_find_sas_private(keyring_file *k, const sid_t *sidp, unsigned char **sas_public_out)
|
||||
{
|
||||
IN();
|
||||
int cn=0,in=0,kp=0;
|
||||
|
||||
unsigned cn=0, in=0, kp=0;
|
||||
if (!keyring_find_sid(k,&cn,&in,&kp,sidp))
|
||||
RETURNNULL(WHYNULL("Could not find SID in keyring, so can't find SAS"));
|
||||
|
||||
kp = keyring_identity_find_keytype(k, cn, in, KEYTYPE_CRYPTOSIGN);
|
||||
if (kp==-1)
|
||||
int kpi = keyring_identity_find_keytype(k, cn, in, KEYTYPE_CRYPTOSIGN);
|
||||
if (kpi == -1)
|
||||
RETURNNULL(WHYNULL("Identity lacks SAS"));
|
||||
|
||||
kp = (unsigned) kpi;
|
||||
unsigned char *sas_private=
|
||||
k->contexts[cn]->identities[in]->keypairs[kp]->private_key;
|
||||
unsigned char *sas_public=
|
||||
@ -1668,7 +1669,8 @@ unsigned char *keyring_find_sas_private(keyring_file *k, const sid_t *sidp, unsi
|
||||
}
|
||||
if (config.debug.keyring)
|
||||
DEBUGF("Found SAS entry for %s*", alloca_tohex(sidp->binary, 7));
|
||||
if (sas_public_out) *sas_public_out=sas_public;
|
||||
if (sas_public_out)
|
||||
*sas_public_out = sas_public;
|
||||
RETURN(sas_private);
|
||||
OUT();
|
||||
}
|
||||
@ -1789,10 +1791,10 @@ int keyring_send_unlock(struct subscriber *subscriber)
|
||||
mdp.out.src.port=MDP_PORT_KEYMAPREQUEST;
|
||||
mdp.out.src.sid = my_subscriber->sid;
|
||||
mdp.out.payload[0]=UNLOCK_REQUEST;
|
||||
int len=1;
|
||||
size_t len = 1;
|
||||
if (crypto_sign_message(subscriber, mdp.out.payload, sizeof(mdp.out.payload), &len))
|
||||
return -1;
|
||||
mdp.out.payload_length=len;
|
||||
mdp.out.payload_length = len;
|
||||
return overlay_mdp_dispatch(&mdp, NULL);
|
||||
}
|
||||
|
||||
@ -1838,7 +1840,7 @@ static int keyring_respond_challenge(struct subscriber *subscriber, overlay_mdp_
|
||||
mdp.out.src.sid = my_subscriber->sid;
|
||||
mdp.out.payload[0]=UNLOCK_RESPONSE;
|
||||
bcopy(&req->out.payload[1], &mdp.out.payload[1], req->out.payload_length -1);
|
||||
int len=req->out.payload_length;
|
||||
size_t len = req->out.payload_length;
|
||||
if (crypto_sign_message(subscriber, mdp.out.payload, sizeof(mdp.out.payload), &len))
|
||||
return -1;
|
||||
mdp.out.payload_length=len;
|
||||
@ -1937,7 +1939,7 @@ int keyring_send_sas_request(struct subscriber *subscriber){
|
||||
return 0;
|
||||
}
|
||||
|
||||
int keyring_find_sid(const keyring_file *k, int *cn, int *in, int *kp, const sid_t *sidp)
|
||||
int keyring_find_sid(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp, const sid_t *sidp)
|
||||
{
|
||||
for(; keyring_next_keytype(k,cn,in,kp,KEYTYPE_CRYPTOBOX); ++(*kp)) {
|
||||
if (memcmp(sidp->binary, k->contexts[*cn]->identities[*in]->keypairs[*kp]->public_key, SID_SIZE) == 0)
|
||||
@ -1949,7 +1951,7 @@ int keyring_find_sid(const keyring_file *k, int *cn, int *in, int *kp, const sid
|
||||
void keyring_identity_extract(const keyring_identity *id, const sid_t **sidp, const char **didp, const char **namep)
|
||||
{
|
||||
int todo = (sidp ? 1 : 0) | (didp ? 2 : 0) | (namep ? 4 : 0);
|
||||
int kpn;
|
||||
unsigned kpn;
|
||||
for (kpn = 0; todo && kpn < id->keypair_count; ++kpn) {
|
||||
keypair *kp = id->keypairs[kpn];
|
||||
switch (kp->type) {
|
||||
@ -2073,7 +2075,7 @@ struct nm_record {
|
||||
unsigned char nm_bytes[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES];
|
||||
};
|
||||
|
||||
int nm_slots_used=0;
|
||||
unsigned nm_slots_used=0;
|
||||
/* 512 x 96 bytes = 48KB, not too big */
|
||||
#define NM_CACHE_SLOTS 512
|
||||
struct nm_record nm_cache[NM_CACHE_SLOTS];
|
||||
@ -2085,9 +2087,8 @@ unsigned char *keyring_get_nm_bytes(const sid_t *known_sidp, const sid_t *unknow
|
||||
if (!unknown_sidp) { RETURNNULL(WHYNULL("unknown pub key is null")); }
|
||||
if (!keyring) { RETURNNULL(WHYNULL("keyring is null")); }
|
||||
|
||||
int i;
|
||||
|
||||
/* See if we have it cached already */
|
||||
unsigned i;
|
||||
for(i=0;i<nm_slots_used;i++)
|
||||
{
|
||||
if (cmp_sid_t(&nm_cache[i].known_key, known_sidp) != 0) continue;
|
||||
@ -2097,9 +2098,9 @@ unsigned char *keyring_get_nm_bytes(const sid_t *known_sidp, const sid_t *unknow
|
||||
|
||||
/* Not in the cache, so prepare to cache it (or return failure if known is not
|
||||
in fact a known key */
|
||||
int cn=0,in=0,kp=0;
|
||||
unsigned cn=0, in=0, kp=0;
|
||||
if (!keyring_find_sid(keyring,&cn,&in,&kp,known_sidp))
|
||||
{ RETURNNULL(WHYNULL("known key is not in fact known.")); }
|
||||
RETURNNULL(WHYNULL("known key is not in fact known."));
|
||||
|
||||
/* work out where to store it */
|
||||
if (nm_slots_used<NM_CACHE_SLOTS) {
|
||||
@ -2144,7 +2145,7 @@ static void keyring_dump_keypair(const keypair *kp, XPRINTF xpf, int include_sec
|
||||
|
||||
int keyring_dump(keyring_file *k, XPRINTF xpf, int include_secret)
|
||||
{
|
||||
int cn, in, kp;
|
||||
unsigned cn, in, kp;
|
||||
unsigned nids = 0;
|
||||
for (cn = in = kp = 0; keyring_sanitise_position(k, &cn, &in, &kp) == 0; ++in)
|
||||
++nids;
|
||||
|
24
keyring.h
24
keyring.h
@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#define __SERVAL_DNA__KEYRING_H
|
||||
|
||||
typedef struct keypair {
|
||||
int type;
|
||||
unsigned type;
|
||||
unsigned char *private_key;
|
||||
size_t private_key_len;
|
||||
unsigned char *public_key;
|
||||
@ -70,7 +70,7 @@ typedef struct keyring_bam {
|
||||
|
||||
#define KEYRING_MAX_CONTEXTS 256
|
||||
typedef struct keyring_file {
|
||||
int context_count;
|
||||
unsigned context_count;
|
||||
keyring_bam *bam;
|
||||
keyring_context *contexts[KEYRING_MAX_CONTEXTS];
|
||||
FILE *file;
|
||||
@ -78,7 +78,7 @@ typedef struct keyring_file {
|
||||
} keyring_file;
|
||||
|
||||
void keyring_free(keyring_file *k);
|
||||
void keyring_release_identity(keyring_file *k, int cn, int id);
|
||||
void keyring_release_identity(keyring_file *k, unsigned cn, unsigned id);
|
||||
#define KEYTYPE_CRYPTOBOX 0x01 // must be lowest
|
||||
#define KEYTYPE_CRYPTOSIGN 0x02
|
||||
#define KEYTYPE_RHIZOME 0x03
|
||||
@ -98,17 +98,17 @@ keyring_file *keyring_open_instance();
|
||||
keyring_file *keyring_open_instance_cli(const struct cli_parsed *parsed);
|
||||
int keyring_enter_pin(keyring_file *k, const char *pin);
|
||||
int keyring_set_did(keyring_identity *id, const char *did, const char *name);
|
||||
int keyring_sanitise_position(const keyring_file *k,int *cn,int *in,int *kp);
|
||||
int keyring_next_keytype(const keyring_file *k, int *cn, int *in, int *kp, int keytype);
|
||||
int keyring_next_identity(const keyring_file *k,int *cn,int *in,int *kp);
|
||||
int keyring_identity_find_keytype(const keyring_file *k, int cn, int in, int keytype);
|
||||
int keyring_find_did(const keyring_file *k,int *cn,int *in,int *kp, const char *did);
|
||||
int keyring_find_sid(const keyring_file *k,int *cn,int *in,int *kp, const sid_t *sidp);
|
||||
int keyring_sanitise_position(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp);
|
||||
int keyring_next_keytype(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp, unsigned keytype);
|
||||
int keyring_next_identity(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp);
|
||||
int keyring_identity_find_keytype(const keyring_file *k, unsigned cn, unsigned in, unsigned keytype);
|
||||
int keyring_find_did(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp, const char *did);
|
||||
int keyring_find_sid(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp, const sid_t *sidp);
|
||||
unsigned char *keyring_find_sas_private(keyring_file *k, const sid_t *sidp, unsigned char **sas_public);
|
||||
int keyring_send_sas_request(struct subscriber *subscriber);
|
||||
|
||||
int keyring_commit(keyring_file *k);
|
||||
keyring_identity *keyring_create_identity(keyring_file *k,keyring_context *c, const char *pin);
|
||||
keyring_identity *keyring_create_identity(keyring_file *k, keyring_context *c, const char *pin);
|
||||
int keyring_seed(keyring_file *k);
|
||||
void keyring_identity_extract(const keyring_identity *id, const sid_t **sidp, const char **didp, const char **namep);
|
||||
int keyring_load(keyring_file *k, const char *keyring_pin, unsigned entry_pinc, const char **entry_pinv, FILE *input);
|
||||
@ -121,8 +121,8 @@ int keyring_send_unlock(struct subscriber *subscriber);
|
||||
void keyring_release_subscriber(keyring_file *k, const sid_t *sid);
|
||||
|
||||
int keyring_set_public_tag(keyring_identity *id, const char *name, const unsigned char *value, size_t length);
|
||||
int keyring_find_public_tag(const keyring_file *k, int *cn, int *in, int *kp, const char *name, const unsigned char **value, size_t *length);
|
||||
int keyring_find_public_tag_value(const keyring_file *k, int *cn, int *in, int *kp, const char *name, const unsigned char *value, size_t length);
|
||||
int keyring_find_public_tag(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp, const char *name, const unsigned char **value, size_t *length);
|
||||
int keyring_find_public_tag_value(const keyring_file *k, unsigned *cn, unsigned *in, unsigned *kp, const char *name, const unsigned char *value, size_t length);
|
||||
int keyring_unpack_tag(const unsigned char *packed, size_t packed_len, const char **name, const unsigned char **value, size_t *length);
|
||||
int keyring_pack_tag(unsigned char *packed, size_t *packed_len, const char *name, const unsigned char *value, size_t length);
|
||||
|
||||
|
2
log.c
2
log.c
@ -271,7 +271,7 @@ static void _log_prefix_whence(_log_iterator *it, struct __sourceloc whence)
|
||||
}
|
||||
}
|
||||
|
||||
static void _log_end_line(_log_iterator *it, int level)
|
||||
static void _log_end_line(_log_iterator *it, int UNUSED(level))
|
||||
{
|
||||
#ifdef ANDROID
|
||||
if (it->config == &config.log.android) {
|
||||
|
13
lsif.c
13
lsif.c
@ -124,7 +124,7 @@ int
|
||||
lsif(void) {
|
||||
char buf[8192];
|
||||
struct ifconf ifc;
|
||||
int sck, nInterfaces, ofs;
|
||||
int sck;
|
||||
struct ifreq *ifr;
|
||||
struct in_addr addr, netmask;
|
||||
|
||||
@ -138,7 +138,7 @@ lsif(void) {
|
||||
}
|
||||
|
||||
/* Query available interfaces. */
|
||||
ifc.ifc_len = sizeof(buf);
|
||||
ifc.ifc_len = sizeof buf;
|
||||
ifc.ifc_buf = buf;
|
||||
if(ioctl(sck, SIOCGIFCONF, &ifc) < 0) {
|
||||
WHY_perror("ioctl(SIOCGIFCONF)");
|
||||
@ -147,10 +147,9 @@ lsif(void) {
|
||||
}
|
||||
|
||||
/* Iterate through the list of interfaces. */
|
||||
nInterfaces = 0;
|
||||
ofs = 0;
|
||||
|
||||
while (ofs < ifc.ifc_len && ofs < sizeof(buf)) {
|
||||
unsigned nInterfaces = 0;
|
||||
unsigned ofs = 0;
|
||||
while (ofs < (unsigned)ifc.ifc_len && ofs < sizeof buf) {
|
||||
ifr = (struct ifreq *)(ifc.ifc_ifcu.ifcu_buf + ofs);
|
||||
ofs += _SIZEOF_ADDR_IFREQ(*ifr);
|
||||
|
||||
@ -183,7 +182,7 @@ lsif(void) {
|
||||
nInterfaces++;
|
||||
}
|
||||
|
||||
if (config.debug.overlayinterfaces) DEBUGF("Examined %d interface addresses", nInterfaces);
|
||||
if (config.debug.overlayinterfaces) DEBUGF("Examined %u interface addresses", nInterfaces);
|
||||
|
||||
close(sck);
|
||||
return 0;
|
||||
|
@ -119,8 +119,10 @@ ssize_t mdp_recv(int socket, struct mdp_header *header, uint8_t *payload, ssize_
|
||||
};
|
||||
|
||||
ssize_t len = recvmsg(socket, &hdr, 0);
|
||||
if (len<sizeof(struct mdp_header))
|
||||
return WHYF("Received message is too short (%d)", (int)len);
|
||||
if (len == -1)
|
||||
return WHYF_perror("recvmsg(%d,%p,0)", socket, &hdr);
|
||||
if ((size_t)len < sizeof(struct mdp_header))
|
||||
return WHYF("Received message is too short (%zu)", (size_t)len);
|
||||
addr.addrlen=hdr.msg_namelen;
|
||||
// double check that the incoming address matches the servald daemon
|
||||
if (cmp_sockaddr(&addr, &mdp_addr) != 0
|
||||
|
10
meshms.c
10
meshms.c
@ -90,7 +90,7 @@ static void free_conversations(struct conversations *conv){
|
||||
static int get_my_conversation_bundle(const sid_t *my_sidp, rhizome_manifest *m)
|
||||
{
|
||||
/* Find our private key */
|
||||
int cn=0,in=0,kp=0;
|
||||
unsigned cn=0, in=0, kp=0;
|
||||
if (!keyring_find_sid(keyring,&cn,&in,&kp,my_sidp))
|
||||
return WHYF("SID was not found in keyring: %s", alloca_tohex_sid_t(*my_sidp));
|
||||
|
||||
@ -171,7 +171,7 @@ static int get_database_conversations(const sid_t *my_sid, const sid_t *their_si
|
||||
}
|
||||
while (sqlite_step_retry(&retry, statement) == SQLITE_ROW) {
|
||||
const char *id_hex = (const char *)sqlite3_column_text(statement, 0);
|
||||
int64_t version = sqlite3_column_int64(statement, 1);
|
||||
uint64_t version = sqlite3_column_int64(statement, 1);
|
||||
int64_t size = sqlite3_column_int64(statement, 2);
|
||||
int64_t tail = sqlite3_column_int64(statement, 3);
|
||||
const char *sender = (const char *)sqlite3_column_text(statement, 4);
|
||||
@ -263,7 +263,7 @@ static int ply_read_open(struct ply_read *ply, const rhizome_bid_t *bid, rhizome
|
||||
return -1;
|
||||
int ret = rhizome_open_decrypt_read(m, &ply->read);
|
||||
if (ret == 1)
|
||||
WARNF("Payload was not found for manifest %s, %"PRId64, alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version);
|
||||
WARNF("Payload was not found for manifest %s, %"PRIu64, alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
assert(m->filesize != RHIZOME_SIZE_UNSET);
|
||||
@ -742,7 +742,7 @@ int app_meshms_conversations(const struct cli_parsed *parsed, struct cli_context
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_meshms_send_message(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int app_meshms_send_message(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
const char *my_sidhex, *their_sidhex, *message;
|
||||
if (cli_arg(parsed, "sender_sid", &my_sidhex, str_is_subscriber_id, "") == -1
|
||||
@ -977,7 +977,7 @@ static int mark_read(struct conversations *conv, const sid_t *their_sid, const c
|
||||
return ret;
|
||||
}
|
||||
|
||||
int app_meshms_mark_read(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int app_meshms_mark_read(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
const char *my_sidhex, *their_sidhex, *offset_str;
|
||||
if (cli_arg(parsed, "sender_sid", &my_sidhex, str_is_subscriber_id, "") == -1
|
||||
|
@ -31,7 +31,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#include "cli.h"
|
||||
#include "monitor-client.h"
|
||||
|
||||
int remote_print(char *cmd, int argc, char **argv, unsigned char *data, int dataLen, void *context){
|
||||
int remote_print(char *cmd, int argc, char **argv, unsigned char *data, int dataLen, void *UNUSED(context))
|
||||
{
|
||||
int i;
|
||||
printf("%s",cmd);
|
||||
for (i=0;i<argc;i++){
|
||||
@ -48,7 +49,7 @@ struct monitor_command_handler monitor_handlers[]={
|
||||
{.command="", .handler=remote_print},
|
||||
};
|
||||
|
||||
int app_monitor_cli(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int app_monitor_cli(const struct cli_parsed *UNUSED(parsed), struct cli_context *UNUSED(context))
|
||||
{
|
||||
struct pollfd fds[2];
|
||||
struct monitor_state *state;
|
||||
|
47
monitor.c
47
monitor.c
@ -17,6 +17,35 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
Android does unix domain sockets, but only stream sockets, not datagram sockets.
|
||||
So we need a separate monitor interface for Android. A bit of a pain, but in
|
||||
@ -362,7 +391,7 @@ void monitor_get_all_supported_codecs(unsigned char *codecs){
|
||||
}
|
||||
}
|
||||
|
||||
static int monitor_announce_all_peers(struct subscriber *subscriber, void *context)
|
||||
static int monitor_announce_all_peers(struct subscriber *subscriber, void *UNUSED(context))
|
||||
{
|
||||
if (subscriber->reachable&REACHABLE)
|
||||
monitor_announce_peer(&subscriber->sid);
|
||||
@ -376,7 +405,7 @@ static int monitor_set(const struct cli_parsed *parsed, struct cli_context *cont
|
||||
c->flags|=MONITOR_VOMP;
|
||||
// store the list of supported codecs against the monitor connection,
|
||||
// since we need to forget about them when the client disappears.
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 2; i < parsed->argc; ++i) {
|
||||
int codec = atoi(parsed->args[i]);
|
||||
if (codec>=0 && codec <=255)
|
||||
@ -462,7 +491,7 @@ static int monitor_call(const struct cli_parsed *parsed, struct cli_context *con
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int monitor_call_ring(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
static int monitor_call_ring(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
struct vomp_call_state *call=vomp_find_call_by_session(strtol(parsed->args[1],NULL,16));
|
||||
if (!call)
|
||||
@ -472,7 +501,7 @@ static int monitor_call_ring(const struct cli_parsed *parsed, struct cli_context
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int monitor_call_pickup(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
static int monitor_call_pickup(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
struct vomp_call_state *call=vomp_find_call_by_session(strtol(parsed->args[1],NULL,16));
|
||||
if (!call)
|
||||
@ -500,7 +529,7 @@ static int monitor_call_audio(const struct cli_parsed *parsed, struct cli_contex
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int monitor_call_hangup(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
static int monitor_call_hangup(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
struct vomp_call_state *call=vomp_find_call_by_session(strtol(parsed->args[1],NULL,16));
|
||||
if (!call)
|
||||
@ -518,7 +547,7 @@ static int monitor_call_dtmf(const struct cli_parsed *parsed, struct cli_context
|
||||
return monitor_write_error(c,"Invalid call token");
|
||||
const char *digits = parsed->args[2];
|
||||
|
||||
int i;
|
||||
unsigned i;
|
||||
for(i=0;i<strlen(digits);i++) {
|
||||
int digit=vomp_parse_dtmf_digit(digits[i]);
|
||||
if (digit<0)
|
||||
@ -548,7 +577,7 @@ struct cli_schema monitor_commands[] = {
|
||||
{monitor_call_audio,{"audio","<token>","<type>","[<time>]","[<sequence>]",NULL},0,""},
|
||||
{monitor_call_hangup, {"hangup","<token>",NULL},0,""},
|
||||
{monitor_call_dtmf, {"dtmf","<token>","<digits>",NULL},0,""},
|
||||
{NULL},
|
||||
{NULL, {NULL, NULL, NULL, NULL},0,NULL},
|
||||
};
|
||||
|
||||
int monitor_process_command(struct monitor_context *c)
|
||||
@ -563,7 +592,7 @@ int monitor_process_command(struct monitor_context *c)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int monitor_help(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
static int monitor_help(const struct cli_parsed *UNUSED(parsed), struct cli_context *context)
|
||||
{
|
||||
struct monitor_context *c=context->context;
|
||||
strbuf b = strbuf_alloca(16384);
|
||||
@ -576,7 +605,7 @@ static int monitor_help(const struct cli_parsed *parsed, struct cli_context *con
|
||||
int monitor_announce_bundle(rhizome_manifest *m)
|
||||
{
|
||||
char msg[1024];
|
||||
int len = snprintf(msg,1024,"\n*%d:BUNDLE:%s\n",
|
||||
int len = snprintf(msg,1024,"\n*%zd:BUNDLE:%s\n",
|
||||
m->manifest_all_bytes,
|
||||
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic));
|
||||
bcopy(m->manifestdata, &msg[len], m->manifest_all_bytes);
|
||||
|
@ -26,7 +26,7 @@ int crypto_auth(unsigned char *out,const unsigned char *in,unsigned long long in
|
||||
{
|
||||
unsigned char h[32];
|
||||
unsigned char padded[128];
|
||||
int i;
|
||||
unsigned i;
|
||||
unsigned long long bits = 512 + (inlen << 3);
|
||||
|
||||
for (i = 0;i < 32;++i) h[i] = iv[i];
|
||||
|
@ -26,7 +26,7 @@ int crypto_auth(unsigned char *out,const unsigned char *in,unsigned long long in
|
||||
{
|
||||
unsigned char h[64];
|
||||
unsigned char padded[256];
|
||||
int i;
|
||||
unsigned i;
|
||||
unsigned long long bytes = 128 + inlen;
|
||||
|
||||
for (i = 0;i < 64;++i) h[i] = iv[i];
|
||||
|
@ -26,7 +26,7 @@ int crypto_hash(unsigned char *out,const unsigned char *in,unsigned long long in
|
||||
{
|
||||
unsigned char h[32];
|
||||
unsigned char padded[128];
|
||||
int i;
|
||||
unsigned i;
|
||||
unsigned long long bits = inlen << 3;
|
||||
|
||||
for (i = 0;i < 32;++i) h[i] = iv[i];
|
||||
|
@ -26,7 +26,7 @@ int crypto_hash(unsigned char *out,const unsigned char *in,unsigned long long in
|
||||
{
|
||||
unsigned char h[64];
|
||||
unsigned char padded[256];
|
||||
int i;
|
||||
unsigned i;
|
||||
unsigned long long bytes = inlen;
|
||||
|
||||
for (i = 0;i < 64;++i) h[i] = iv[i];
|
||||
|
@ -5,6 +5,35 @@ Public domain.
|
||||
Derived from public domain code by D. J. Bernstein.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "crypto_scalarmult.h"
|
||||
|
||||
static void add(unsigned int out[32],const unsigned int a[32],const unsigned int b[32])
|
||||
@ -137,7 +166,6 @@ static void mainloop(unsigned int work[64],const unsigned char e[32])
|
||||
unsigned int s[32];
|
||||
unsigned int t[32];
|
||||
unsigned int u[32];
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
unsigned int b;
|
||||
int pos;
|
||||
|
@ -19,7 +19,7 @@ int crypto_stream(
|
||||
{
|
||||
unsigned char in[16];
|
||||
unsigned char block[64];
|
||||
int i;
|
||||
unsigned i;
|
||||
unsigned int u;
|
||||
|
||||
if (!clen) return 0;
|
||||
|
@ -20,7 +20,7 @@ int crypto_stream_xor(
|
||||
{
|
||||
unsigned char in[16];
|
||||
unsigned char block[64];
|
||||
int i;
|
||||
unsigned i;
|
||||
unsigned int u;
|
||||
|
||||
if (!mlen) return 0;
|
||||
|
@ -19,7 +19,7 @@ int crypto_stream(
|
||||
{
|
||||
unsigned char in[16];
|
||||
unsigned char block[64];
|
||||
int i;
|
||||
unsigned i;
|
||||
unsigned int u;
|
||||
|
||||
if (!clen) return 0;
|
||||
|
@ -20,7 +20,7 @@ int crypto_stream_xor(
|
||||
{
|
||||
unsigned char in[16];
|
||||
unsigned char block[64];
|
||||
int i;
|
||||
unsigned i;
|
||||
unsigned int u;
|
||||
|
||||
if (!mlen) return 0;
|
||||
|
@ -19,7 +19,7 @@ int crypto_stream(
|
||||
{
|
||||
unsigned char in[16];
|
||||
unsigned char block[64];
|
||||
int i;
|
||||
unsigned i;
|
||||
unsigned int u;
|
||||
|
||||
if (!clen) return 0;
|
||||
|
@ -20,7 +20,7 @@ int crypto_stream_xor(
|
||||
{
|
||||
unsigned char in[16];
|
||||
unsigned char block[64];
|
||||
int i;
|
||||
unsigned i;
|
||||
unsigned int u;
|
||||
|
||||
if (!mlen) return 0;
|
||||
|
10
net.c
10
net.c
@ -81,7 +81,7 @@ ssize_t _write_all(int fd, const void *buf, size_t len, struct __sourceloc __whe
|
||||
if (written == -1)
|
||||
return WHYF_perror("write_all: write(%d,%p %s,%zu)",
|
||||
fd, buf, alloca_toprint(30, buf, len), len);
|
||||
if (written != len)
|
||||
if ((size_t)written != len)
|
||||
return WHYF_perror("write_all: write(%d,%p %s,%zu) returned %zd",
|
||||
fd, buf, alloca_toprint(30, buf, len), len, (size_t)written);
|
||||
return written;
|
||||
@ -96,7 +96,7 @@ ssize_t _writev_all(int fd, const struct iovec *iov, int iovcnt, struct __source
|
||||
ssize_t written = writev(fd, iov, iovcnt);
|
||||
if (written == -1)
|
||||
return WHYF_perror("writev_all: writev(%d,%s len=%zu)", fd, alloca_iovec(iov, iovcnt), len);
|
||||
if (written != len)
|
||||
if ((size_t)written != len)
|
||||
return WHYF_perror("writev_all: writev(%d,%s len=%zu) returned %zd", fd, alloca_iovec(iov, iovcnt), len, (size_t)written);
|
||||
return written;
|
||||
}
|
||||
@ -123,9 +123,9 @@ ssize_t _write_nonblock(int fd, const void *buf, size_t len, struct __sourceloc
|
||||
ssize_t _write_all_nonblock(int fd, const void *buf, size_t len, struct __sourceloc __whence)
|
||||
{
|
||||
ssize_t written = _write_nonblock(fd, buf, len, __whence);
|
||||
if (written != -1 && written != len)
|
||||
return WHYF("write_all_nonblock: write(%d,%p %s,%lu) returned %ld",
|
||||
fd, buf, alloca_toprint(30, buf, len), (unsigned long)len, (long)written);
|
||||
if (written != -1 && (size_t)written != len)
|
||||
return WHYF("write_all_nonblock: write(%d,%p %s,%zu) returned %zd",
|
||||
fd, buf, alloca_toprint(30, buf, len), len, (size_t)written);
|
||||
return written;
|
||||
}
|
||||
|
||||
|
2
nonce.c
2
nonce.c
@ -49,7 +49,7 @@ int generate_nonce(unsigned char *nonce,int bytes)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_nonce_test(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int app_nonce_test(const struct cli_parsed *UNUSED(parsed), struct cli_context *context)
|
||||
{
|
||||
int i,j;
|
||||
unsigned char nonces[0x10001][32];
|
||||
|
6
os.c
6
os.c
@ -156,9 +156,9 @@ ssize_t read_symlink(const char *path, char *buf, size_t len)
|
||||
}
|
||||
ssize_t nr = readlink(path, buf, len);
|
||||
if (nr == -1)
|
||||
return WHYF_perror("readlink(%s)", path);
|
||||
if (nr >= len)
|
||||
return WHYF("buffer overrun from readlink(%s, len=%lu)", path, (unsigned long) len);
|
||||
return WHYF_perror("readlink(%s,%p,%zu)", path, buf, len);
|
||||
if ((size_t)nr >= len)
|
||||
return WHYF("buffer overrun from readlink(%s, len=%zu)", path, len);
|
||||
buf[nr] = '\0';
|
||||
return nr;
|
||||
}
|
||||
|
2
os.h
2
os.h
@ -55,6 +55,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
typedef int64_t time_ms_t;
|
||||
#define PRItime_ms_t PRId64
|
||||
#define TIME_NEVER_WILL INT64_MAX
|
||||
#define TIME_NEVER_HAS INT64_MIN
|
||||
|
||||
time_ms_t gettime_ms();
|
||||
time_ms_t sleep_ms(time_ms_t milliseconds);
|
||||
|
153
overlay_buffer.c
153
overlay_buffer.c
@ -44,11 +44,11 @@ struct overlay_buffer *_ob_new(struct __sourceloc __whence)
|
||||
|
||||
// index an existing static buffer.
|
||||
// and allow other callers to use the ob_ convenience methods for reading and writing up to size bytes.
|
||||
struct overlay_buffer *_ob_static(struct __sourceloc __whence, unsigned char *bytes, int size)
|
||||
struct overlay_buffer *_ob_static(struct __sourceloc __whence, unsigned char *bytes, size_t size)
|
||||
{
|
||||
struct overlay_buffer *ret = emalloc_zero(sizeof(struct overlay_buffer));
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_static(bytes=%p, size=%d) return %p", bytes, size, ret);
|
||||
DEBUGF("ob_static(bytes=%p, size=%zu) return %p", bytes, size, ret);
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
ret->bytes = bytes;
|
||||
@ -61,18 +61,18 @@ struct overlay_buffer *_ob_static(struct __sourceloc __whence, unsigned char *by
|
||||
// create a new overlay buffer from an existing piece of another buffer.
|
||||
// Both buffers will point to the same memory region.
|
||||
// It is up to the caller to ensure this buffer is not used after the parent buffer is freed.
|
||||
struct overlay_buffer *_ob_slice(struct __sourceloc __whence, struct overlay_buffer *b, int offset, int length)
|
||||
struct overlay_buffer *_ob_slice(struct __sourceloc __whence, struct overlay_buffer *b, size_t offset, size_t length)
|
||||
{
|
||||
if (offset+length > b->allocSize) {
|
||||
if (offset + length > b->allocSize) {
|
||||
WHY("Buffer isn't long enough to slice");
|
||||
return NULL;
|
||||
}
|
||||
struct overlay_buffer *ret = emalloc_zero(sizeof(struct overlay_buffer));
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_slice(b=%p, offset=%d, length=%d) return %p", b, offset, length, ret);
|
||||
DEBUGF("ob_slice(b=%p, offset=%zu, length=%zu) return %p", b, offset, length, ret);
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
ret->bytes = b->bytes+offset;
|
||||
ret->bytes = b->bytes + offset;
|
||||
ret->allocSize = length;
|
||||
ret->allocated = NULL;
|
||||
ob_unlimitsize(ret);
|
||||
@ -91,9 +91,11 @@ struct overlay_buffer *_ob_dup(struct __sourceloc __whence, struct overlay_buffe
|
||||
ret->checkpointLength = b->checkpointLength;
|
||||
if (b->bytes && b->allocSize){
|
||||
// duplicate any bytes that might be relevant
|
||||
int byteCount = b->sizeLimit;
|
||||
if (byteCount < b->position)
|
||||
byteCount = b->position;
|
||||
size_t byteCount = b->position;
|
||||
if (b->sizeLimit != SIZE_MAX) {
|
||||
assert(b->position <= b->sizeLimit);
|
||||
byteCount = b->sizeLimit;
|
||||
}
|
||||
if (byteCount > b->allocSize)
|
||||
byteCount = b->allocSize;
|
||||
if (byteCount)
|
||||
@ -117,7 +119,7 @@ int _ob_checkpoint(struct __sourceloc __whence, struct overlay_buffer *b)
|
||||
assert(b != NULL);
|
||||
b->checkpointLength = b->position;
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_checkpoint(b=%p) checkpointLength=%d", b, b->checkpointLength);
|
||||
DEBUGF("ob_checkpoint(b=%p) checkpointLength=%zu", b, b->checkpointLength);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -126,30 +128,29 @@ int _ob_rewind(struct __sourceloc __whence, struct overlay_buffer *b)
|
||||
assert(b != NULL);
|
||||
b->position = b->checkpointLength;
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_rewind(b=%p) position=%d", b, b->position);
|
||||
DEBUGF("ob_rewind(b=%p) position=%zu", b, b->position);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _ob_limitsize(struct __sourceloc __whence, struct overlay_buffer *b, int bytes)
|
||||
void _ob_limitsize(struct __sourceloc __whence, struct overlay_buffer *b, size_t bytes)
|
||||
{
|
||||
assert(b != NULL);
|
||||
assert(bytes >= 0);
|
||||
assert(b->position >= 0);
|
||||
assert(bytes != SIZE_MAX);
|
||||
assert(b->position <= bytes);
|
||||
assert(b->checkpointLength <= bytes);
|
||||
if (b->bytes && b->allocated == NULL)
|
||||
assert(bytes <= b->allocSize);
|
||||
b->sizeLimit = bytes;
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_limitsize(b=%p, bytes=%d) sizeLimit=%d", b, bytes, b->sizeLimit);
|
||||
DEBUGF("ob_limitsize(b=%p, bytes=%zu) sizeLimit=%zu", b, bytes, b->sizeLimit);
|
||||
}
|
||||
|
||||
void _ob_unlimitsize(struct __sourceloc __whence, struct overlay_buffer *b)
|
||||
{
|
||||
assert(b != NULL);
|
||||
b->sizeLimit = -1;
|
||||
b->sizeLimit = SIZE_MAX;
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_unlimitsize(b=%p) sizeLimit=%d", b, b->sizeLimit);
|
||||
DEBUGF("ob_unlimitsize(b=%p) sizeLimit=%zu", b, b->sizeLimit);
|
||||
}
|
||||
|
||||
void _ob_flip(struct __sourceloc __whence, struct overlay_buffer *b)
|
||||
@ -167,17 +168,15 @@ ssize_t _ob_makespace(struct __sourceloc __whence, struct overlay_buffer *b, siz
|
||||
{
|
||||
assert(b != NULL);
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_makespace(b=%p, bytes=%zd) b->bytes=%p b->position=%d b->allocSize=%d",
|
||||
DEBUGF("ob_makespace(b=%p, bytes=%zd) b->bytes=%p b->position=%zu b->allocSize=%zu",
|
||||
b, bytes, b->bytes, b->position, b->allocSize);
|
||||
assert(b->position >= 0);
|
||||
if (b->sizeLimit != -1)
|
||||
assert(b->sizeLimit >= 0);
|
||||
assert(b->allocSize >= 0);
|
||||
assert(b->position <= b->sizeLimit);
|
||||
assert(b->position <= b->allocSize);
|
||||
if (b->position)
|
||||
assert(b->bytes != NULL);
|
||||
if (b->sizeLimit != -1 && b->position + bytes > b->sizeLimit) {
|
||||
if (b->position + bytes > b->sizeLimit) {
|
||||
if (config.debug.packetformats)
|
||||
DEBUGF("ob_makespace(): asked for space to %zu, beyond size limit of %u", b->position + bytes, b->sizeLimit);
|
||||
DEBUGF("ob_makespace(): asked for space to %zu, beyond size limit of %zu", b->position + bytes, b->sizeLimit);
|
||||
return 0;
|
||||
}
|
||||
if (b->position + bytes <= b->allocSize)
|
||||
@ -185,10 +184,10 @@ ssize_t _ob_makespace(struct __sourceloc __whence, struct overlay_buffer *b, siz
|
||||
// Don't realloc a static buffer.
|
||||
if (b->bytes && b->allocated == NULL) {
|
||||
if (config.debug.packetformats)
|
||||
DEBUGF("ob_makespace(): asked for space to %zu, beyond static buffer size of %u", b->position + bytes, b->allocSize);
|
||||
DEBUGF("ob_makespace(): asked for space to %zu, beyond static buffer size of %zu", b->position + bytes, b->allocSize);
|
||||
return 0;
|
||||
}
|
||||
int newSize=b->position+bytes;
|
||||
size_t newSize = b->position + bytes;
|
||||
if (newSize<64) newSize=64;
|
||||
if (newSize&63) newSize+=64-(newSize&63);
|
||||
if (newSize>1024 && (newSize&1023))
|
||||
@ -196,7 +195,7 @@ ssize_t _ob_makespace(struct __sourceloc __whence, struct overlay_buffer *b, siz
|
||||
if (newSize>65536 && (newSize&65535))
|
||||
newSize+=65536-(newSize&65535);
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("realloc(b->bytes=%p,newSize=%d)", b->bytes,newSize);
|
||||
DEBUGF("realloc(b->bytes=%p, newSize=%zu)", b->bytes, newSize);
|
||||
/* XXX OSX realloc() seems to be able to corrupt things if the heap is not happy when calling realloc(), making debugging memory corruption much harder.
|
||||
So will do a three-stage malloc,bcopy,free to see if we can tease bugs out that way. */
|
||||
/*
|
||||
@ -247,35 +246,35 @@ void _ob_append_byte(struct __sourceloc __whence, struct overlay_buffer *b, unsi
|
||||
if (ob_makespace(b, bytes)) {
|
||||
b->bytes[b->position] = byte;
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_append_byte(b=%p, byte=0x%02x) %p[%d]=%02x position=%d", b, byte, b->bytes, b->position, byte, b->position + bytes);
|
||||
DEBUGF("ob_append_byte(b=%p, byte=0x%02x) %p[%d]=%02x position=%zu", b, byte, b->bytes, b->position, byte, b->position + bytes);
|
||||
} else {
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_append_byte(b=%p, byte=0x%02x) OVERRUN position=%d", b, byte, b->position + bytes);
|
||||
DEBUGF("ob_append_byte(b=%p, byte=0x%02x) OVERRUN position=%zu", b, byte, b->position + bytes);
|
||||
}
|
||||
b->position += bytes;
|
||||
}
|
||||
|
||||
unsigned char *_ob_append_space(struct __sourceloc __whence, struct overlay_buffer *b, int count)
|
||||
unsigned char *_ob_append_space(struct __sourceloc __whence, struct overlay_buffer *b, size_t count)
|
||||
{
|
||||
assert(count > 0);
|
||||
unsigned char *r = ob_makespace(b, count) ? &b->bytes[b->position] : NULL;
|
||||
b->position += count;
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_append_space(b=%p, count=%d) position=%d return %p", b, count, b->position, r);
|
||||
DEBUGF("ob_append_space(b=%p, count=%zu) position=%zu return %p", b, count, b->position, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
void _ob_append_bytes(struct __sourceloc __whence, struct overlay_buffer *b, const unsigned char *bytes, int count)
|
||||
void _ob_append_bytes(struct __sourceloc __whence, struct overlay_buffer *b, const unsigned char *bytes, size_t count)
|
||||
{
|
||||
assert(count > 0);
|
||||
unsigned char *r = ob_makespace(b, count) ? &b->bytes[b->position] : NULL;
|
||||
if (r) {
|
||||
bcopy(bytes, r, count);
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_append_bytes(b=%p, bytes=%p, count=%d) position=%d return %p", b, bytes, count, b->position + count, r);
|
||||
DEBUGF("ob_append_bytes(b=%p, bytes=%p, count=%zu) position=%zu return %p", b, bytes, count, b->position + count, r);
|
||||
} else {
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_append_bytes(b=%p, bytes=%p, count=%d) OVERRUN position=%d return NULL", b, bytes, count, b->position + count);
|
||||
DEBUGF("ob_append_bytes(b=%p, bytes=%p, count=%zu) OVERRUN position=%zu return NULL", b, bytes, count, b->position + count);
|
||||
}
|
||||
if (config.debug.overlaybuffer)
|
||||
dump("ob_append_bytes", bytes, count);
|
||||
@ -294,10 +293,10 @@ void _ob_append_ui16(struct __sourceloc __whence, struct overlay_buffer *b, uint
|
||||
b->bytes[b->position] = (v >> 8) & 0xFF;
|
||||
b->bytes[b->position+1] = v & 0xFF;
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_append_ui16(b=%p, v=%u) %p[%d]=%s position=%d", b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
|
||||
DEBUGF("ob_append_ui16(b=%p, v=%u) %p[%d]=%s position=%zu", b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
|
||||
} else {
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_append_ui16(b=%p, v=%u) OVERRUN position=%d", b, v, b->position + bytes);
|
||||
DEBUGF("ob_append_ui16(b=%p, v=%u) OVERRUN position=%zu", b, v, b->position + bytes);
|
||||
}
|
||||
b->position += bytes;
|
||||
}
|
||||
@ -311,11 +310,11 @@ void _ob_append_ui32(struct __sourceloc __whence, struct overlay_buffer *b, uint
|
||||
b->bytes[b->position+2] = (v >> 8) & 0xFF;
|
||||
b->bytes[b->position+3] = v & 0xFF;
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_append_ui32(b=%p, v=%"PRIu32") %p[%d]=%s position=%d",
|
||||
DEBUGF("ob_append_ui32(b=%p, v=%"PRIu32") %p[%d]=%s position=%zu",
|
||||
b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
|
||||
} else {
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_append_ui32(b=%p, v=%"PRIu32") OVERRUN position=%d", b, v, b->position + bytes);
|
||||
DEBUGF("ob_append_ui32(b=%p, v=%"PRIu32") OVERRUN position=%zu", b, v, b->position + bytes);
|
||||
}
|
||||
b->position += bytes;
|
||||
}
|
||||
@ -333,11 +332,11 @@ void _ob_append_ui64(struct __sourceloc __whence, struct overlay_buffer *b, uint
|
||||
b->bytes[b->position+6] = (v >> 8) & 0xFF;
|
||||
b->bytes[b->position+7] = v & 0xFF;
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_append_ui64(b=%p, v=%"PRIu64") %p[%d]=%s position=%d",
|
||||
DEBUGF("ob_append_ui64(b=%p, v=%"PRIu64") %p[%d]=%s position=%zu",
|
||||
b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
|
||||
} else {
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_append_ui64(b=%p, v=%"PRIu64") OVERRUN position=%d", b, v, b->position + bytes);
|
||||
DEBUGF("ob_append_ui64(b=%p, v=%"PRIu64") OVERRUN position=%zu", b, v, b->position + bytes);
|
||||
}
|
||||
b->position += bytes;
|
||||
}
|
||||
@ -407,19 +406,19 @@ void _ob_append_rfs(struct __sourceloc __whence, struct overlay_buffer *b, int l
|
||||
|
||||
|
||||
// make sure a range of bytes is valid for reading
|
||||
int test_offset(struct overlay_buffer *b,int start,int length)
|
||||
static int test_offset(struct overlay_buffer *b, size_t length)
|
||||
{
|
||||
if (!b) return -1;
|
||||
if (start<0) return -1;
|
||||
if (b->sizeLimit>=0 && start+length>b->sizeLimit) return -1;
|
||||
if (start+length>b->allocSize) return -1;
|
||||
if (b->position + length > b->sizeLimit)
|
||||
return -1;
|
||||
if (b->position + length > b->allocSize)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// next byte without advancing
|
||||
int ob_peek(struct overlay_buffer *b)
|
||||
{
|
||||
if (test_offset(b, b->position, 1))
|
||||
if (test_offset(b, 1))
|
||||
return -1;
|
||||
return b->bytes[b->position];
|
||||
}
|
||||
@ -429,19 +428,19 @@ void ob_skip(struct overlay_buffer *b, unsigned n)
|
||||
b->position += n;
|
||||
}
|
||||
|
||||
int ob_get_bytes(struct overlay_buffer *b, unsigned char *buff, int len){
|
||||
if (test_offset(b, b->position, len))
|
||||
int ob_get_bytes(struct overlay_buffer *b, unsigned char *buff, size_t len)
|
||||
{
|
||||
if (test_offset(b, len))
|
||||
return -1;
|
||||
|
||||
bcopy(b->bytes + b->position, buff, len);
|
||||
b->position+=len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char * ob_get_bytes_ptr(struct overlay_buffer *b, int len){
|
||||
if (test_offset(b, b->position, len))
|
||||
unsigned char * ob_get_bytes_ptr(struct overlay_buffer *b, size_t len)
|
||||
{
|
||||
if (test_offset(b, len))
|
||||
return NULL;
|
||||
|
||||
unsigned char *ret = b->bytes + b->position;
|
||||
b->position+=len;
|
||||
return ret;
|
||||
@ -449,9 +448,8 @@ unsigned char * ob_get_bytes_ptr(struct overlay_buffer *b, int len){
|
||||
|
||||
uint32_t ob_get_ui32(struct overlay_buffer *b)
|
||||
{
|
||||
if (test_offset(b, b->position, 4))
|
||||
if (test_offset(b, 4))
|
||||
return 0xFFFFFFFF; // ... unsigned
|
||||
|
||||
uint32_t ret = b->bytes[b->position] << 24
|
||||
| b->bytes[b->position +1] << 16
|
||||
| b->bytes[b->position +2] << 8
|
||||
@ -462,9 +460,8 @@ uint32_t ob_get_ui32(struct overlay_buffer *b)
|
||||
|
||||
uint64_t ob_get_ui64(struct overlay_buffer *b)
|
||||
{
|
||||
if (test_offset(b, b->position, 8))
|
||||
if (test_offset(b, 8))
|
||||
return 0xFFFFFFFF; // ... unsigned
|
||||
|
||||
uint64_t ret = (uint64_t)b->bytes[b->position] << 56
|
||||
| (uint64_t)b->bytes[b->position +1] << 48
|
||||
| (uint64_t)b->bytes[b->position +2] << 40
|
||||
@ -479,9 +476,8 @@ uint64_t ob_get_ui64(struct overlay_buffer *b)
|
||||
|
||||
uint16_t ob_get_ui16(struct overlay_buffer *b)
|
||||
{
|
||||
if (test_offset(b, b->position, 2))
|
||||
if (test_offset(b, 2))
|
||||
return 0xFFFF; // ... unsigned
|
||||
|
||||
uint16_t ret = b->bytes[b->position] << 8
|
||||
| b->bytes[b->position +1];
|
||||
b->position+=2;
|
||||
@ -520,18 +516,16 @@ uint64_t ob_get_packed_ui64(struct overlay_buffer *b)
|
||||
|
||||
int ob_get(struct overlay_buffer *b)
|
||||
{
|
||||
if (test_offset(b, b->position, 1))
|
||||
if (test_offset(b, 1))
|
||||
return -1;
|
||||
return b->bytes[b->position++];
|
||||
}
|
||||
|
||||
void _ob_set_ui16(struct __sourceloc __whence, struct overlay_buffer *b, int offset, uint16_t v)
|
||||
void _ob_set_ui16(struct __sourceloc __whence, struct overlay_buffer *b, size_t offset, uint16_t v)
|
||||
{
|
||||
const int bytes = 2;
|
||||
assert(b != NULL);
|
||||
assert(offset >= 0);
|
||||
if (b->sizeLimit != -1)
|
||||
assert(offset + bytes <= b->sizeLimit);
|
||||
assert(offset + bytes <= b->sizeLimit);
|
||||
assert(offset + bytes <= b->allocSize);
|
||||
b->bytes[offset] = (v >> 8) & 0xFF;
|
||||
b->bytes[offset+1] = v & 0xFF;
|
||||
@ -539,13 +533,11 @@ void _ob_set_ui16(struct __sourceloc __whence, struct overlay_buffer *b, int off
|
||||
DEBUGF("ob_set_ui16(b=%p, offset=%d, v=%u) %p[%d]=%s", b, offset, v, b->bytes, offset, alloca_tohex(&b->bytes[offset], bytes));
|
||||
}
|
||||
|
||||
void _ob_set(struct __sourceloc __whence, struct overlay_buffer *b, int offset, unsigned char byte)
|
||||
void _ob_set(struct __sourceloc __whence, struct overlay_buffer *b, size_t offset, unsigned char byte)
|
||||
{
|
||||
const int bytes = 1;
|
||||
assert(b != NULL);
|
||||
assert(offset >= 0);
|
||||
if (b->sizeLimit != -1)
|
||||
assert(offset + bytes <= b->sizeLimit);
|
||||
assert(offset + bytes <= b->sizeLimit);
|
||||
assert(offset + bytes <= b->allocSize);
|
||||
b->bytes[offset] = byte;
|
||||
if (config.debug.overlaybuffer)
|
||||
@ -558,28 +550,26 @@ void _ob_patch_rfs(struct __sourceloc __whence, struct overlay_buffer *b)
|
||||
}
|
||||
|
||||
|
||||
int ob_position(struct overlay_buffer *b)
|
||||
size_t ob_position(struct overlay_buffer *b)
|
||||
{
|
||||
return b->position;
|
||||
}
|
||||
|
||||
int ob_limit(struct overlay_buffer *b)
|
||||
size_t ob_limit(struct overlay_buffer *b)
|
||||
{
|
||||
return b->sizeLimit;
|
||||
}
|
||||
|
||||
int ob_remaining(struct overlay_buffer *b)
|
||||
size_t ob_remaining(struct overlay_buffer *b)
|
||||
{
|
||||
assert(b->sizeLimit != -1);
|
||||
return b->sizeLimit - b->position;
|
||||
assert(b->sizeLimit != SIZE_MAX);
|
||||
assert(b->position <= b->sizeLimit);
|
||||
return (size_t)(b->sizeLimit - b->position);
|
||||
}
|
||||
|
||||
int _ob_overrun(struct __sourceloc __whence, struct overlay_buffer *b)
|
||||
{
|
||||
assert(b->allocSize >= 0);
|
||||
if (b->sizeLimit != -1)
|
||||
assert(b->sizeLimit >= 0);
|
||||
int ret = b->position > (b->sizeLimit != -1 && b->sizeLimit < b->allocSize ? b->sizeLimit : b->allocSize);
|
||||
int ret = b->position > (b->sizeLimit != SIZE_MAX && b->sizeLimit < b->allocSize ? b->sizeLimit : b->allocSize);
|
||||
if (config.debug.overlaybuffer)
|
||||
DEBUGF("ob_overrun(b=%p) return %d", b, ret);
|
||||
return ret;
|
||||
@ -599,8 +589,13 @@ int asprintable(int c)
|
||||
|
||||
int ob_dump(struct overlay_buffer *b, char *desc)
|
||||
{
|
||||
DEBUGF("overlay_buffer '%s' at %p (%p) : position=%d, size=%d", desc, b, b->bytes, b->position, b->sizeLimit);
|
||||
if (b->bytes && (b->position || b->sizeLimit))
|
||||
dump(desc, b->bytes, b->position?b->position:b->sizeLimit);
|
||||
DEBUGF("overlay_buffer '%s' at %p (%p) : position=%zu, size=%zu", desc, b, b->bytes, b->position, b->sizeLimit);
|
||||
if (b->bytes) {
|
||||
if (b->sizeLimit != SIZE_MAX && b->sizeLimit > 0) {
|
||||
assert(b->position <= b->sizeLimit);
|
||||
dump(desc, b->bytes, b->sizeLimit);
|
||||
} else if (b->position > 0)
|
||||
dump(desc, b->bytes, b->position);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -24,43 +24,43 @@ struct overlay_buffer {
|
||||
unsigned char *bytes;
|
||||
|
||||
// remembered position for rewinding
|
||||
int checkpointLength;
|
||||
size_t checkpointLength;
|
||||
|
||||
// position of data read / written
|
||||
int position;
|
||||
size_t position;
|
||||
|
||||
// maximum allowed bytes for reading / writing
|
||||
int sizeLimit;
|
||||
size_t sizeLimit;
|
||||
|
||||
// size of buffer
|
||||
int allocSize;
|
||||
size_t allocSize;
|
||||
|
||||
// is this an allocated buffer? can it be resized? Should it be freed?
|
||||
unsigned char * allocated;
|
||||
|
||||
// length position for later patching
|
||||
int var_length_offset;
|
||||
size_t var_length_offset;
|
||||
};
|
||||
|
||||
struct overlay_buffer *_ob_new(struct __sourceloc __whence);
|
||||
struct overlay_buffer *_ob_static(struct __sourceloc __whence, unsigned char *bytes, int size);
|
||||
struct overlay_buffer *_ob_slice(struct __sourceloc __whence, struct overlay_buffer *b, int offset, int length);
|
||||
struct overlay_buffer *_ob_static(struct __sourceloc __whence, unsigned char *bytes, size_t size);
|
||||
struct overlay_buffer *_ob_slice(struct __sourceloc __whence, struct overlay_buffer *b, size_t offset, size_t length);
|
||||
struct overlay_buffer *_ob_dup(struct __sourceloc __whence, struct overlay_buffer *b);
|
||||
void _ob_free(struct __sourceloc __whence, struct overlay_buffer *b);
|
||||
int _ob_checkpoint(struct __sourceloc __whence, struct overlay_buffer *b);
|
||||
int _ob_rewind(struct __sourceloc __whence, struct overlay_buffer *b);
|
||||
void _ob_limitsize(struct __sourceloc __whence, struct overlay_buffer *b,int bytes);
|
||||
void _ob_limitsize(struct __sourceloc __whence, struct overlay_buffer *b, size_t bytes);
|
||||
void _ob_flip(struct __sourceloc __whence, struct overlay_buffer *b);
|
||||
void _ob_unlimitsize(struct __sourceloc __whence, struct overlay_buffer *b);
|
||||
ssize_t _ob_makespace(struct __sourceloc whence, struct overlay_buffer *b, size_t bytes);
|
||||
void _ob_set(struct __sourceloc __whence, struct overlay_buffer *b, int ofs, unsigned char byte);
|
||||
void _ob_set_ui16(struct __sourceloc __whence, struct overlay_buffer *b, int offset, uint16_t v);
|
||||
void _ob_set(struct __sourceloc __whence, struct overlay_buffer *b, size_t ofs, unsigned char byte);
|
||||
void _ob_set_ui16(struct __sourceloc __whence, struct overlay_buffer *b, size_t offset, uint16_t v);
|
||||
void _ob_patch_rfs(struct __sourceloc __whence, struct overlay_buffer *b);
|
||||
|
||||
void _ob_append_byte(struct __sourceloc whence, struct overlay_buffer *b,unsigned char byte);
|
||||
void _ob_append_bytes(struct __sourceloc whence, struct overlay_buffer *b,const unsigned char *bytes,int count);
|
||||
void _ob_append_bytes(struct __sourceloc whence, struct overlay_buffer *b,const unsigned char *bytes, size_t count);
|
||||
void _ob_append_buffer(struct __sourceloc whence, struct overlay_buffer *b,struct overlay_buffer *s);
|
||||
unsigned char *_ob_append_space(struct __sourceloc whence, struct overlay_buffer *b,int count);
|
||||
unsigned char *_ob_append_space(struct __sourceloc whence, struct overlay_buffer *b, size_t count);
|
||||
void _ob_append_ui16(struct __sourceloc whence, struct overlay_buffer *b, uint16_t v);
|
||||
void _ob_append_ui32(struct __sourceloc whence, struct overlay_buffer *b, uint32_t v);
|
||||
void _ob_append_ui64(struct __sourceloc whence, struct overlay_buffer *b, uint64_t v);
|
||||
@ -99,8 +99,8 @@ int ob_peek(struct overlay_buffer *b);
|
||||
void ob_skip(struct overlay_buffer *b, unsigned n);
|
||||
// get one byte from the current position, -ve number indicates failure
|
||||
int ob_get(struct overlay_buffer *b);
|
||||
int ob_get_bytes(struct overlay_buffer *b, unsigned char *buff, int len);
|
||||
unsigned char * ob_get_bytes_ptr(struct overlay_buffer *b, int len);
|
||||
int ob_get_bytes(struct overlay_buffer *b, unsigned char *buff, size_t len);
|
||||
unsigned char * ob_get_bytes_ptr(struct overlay_buffer *b, size_t len);
|
||||
uint64_t ob_get_ui64(struct overlay_buffer *b);
|
||||
uint32_t ob_get_ui32(struct overlay_buffer *b);
|
||||
uint16_t ob_get_ui16(struct overlay_buffer *b);
|
||||
@ -110,9 +110,9 @@ uint32_t ob_get_packed_ui32(struct overlay_buffer *b);
|
||||
uint64_t ob_get_packed_ui64(struct overlay_buffer *b);
|
||||
|
||||
// information routines
|
||||
int ob_position(struct overlay_buffer *b);
|
||||
int ob_limit(struct overlay_buffer *b);
|
||||
int ob_remaining(struct overlay_buffer *b);
|
||||
size_t ob_position(struct overlay_buffer *b);
|
||||
size_t ob_limit(struct overlay_buffer *b);
|
||||
size_t ob_remaining(struct overlay_buffer *b);
|
||||
int _ob_overrun(struct __sourceloc, struct overlay_buffer *b);
|
||||
unsigned char* ob_ptr(struct overlay_buffer *b);
|
||||
|
||||
|
@ -39,7 +39,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#endif
|
||||
|
||||
int overlay_ready=0;
|
||||
int overlay_interface_count=0;
|
||||
unsigned overlay_interface_count=0;
|
||||
overlay_interface overlay_interfaces[OVERLAY_MAX_INTERFACES];
|
||||
int overlay_last_interface_number=-1;
|
||||
|
||||
@ -282,7 +282,7 @@ overlay_interface_read_any(struct sched_ent *alarm)
|
||||
DEBUGF("Could not find matching interface for packet received from %s", inet_ntoa(recvaddr.inet.sin_addr));
|
||||
return;
|
||||
}
|
||||
packetOkOverlay(interface, packet, plen, recvttl, &recvaddr);
|
||||
packetOkOverlay(interface, packet, plen, &recvaddr);
|
||||
}
|
||||
if (alarm->poll.revents & (POLLHUP | POLLERR)) {
|
||||
INFO("Closing broadcast socket due to error");
|
||||
@ -593,7 +593,7 @@ static void interface_read_dgram(struct overlay_interface *interface)
|
||||
overlay_interface_close(interface);
|
||||
return;
|
||||
}
|
||||
packetOkOverlay(interface, packet, plen, recvttl, &recvaddr);
|
||||
packetOkOverlay(interface, packet, plen, &recvaddr);
|
||||
}
|
||||
|
||||
struct file_packet{
|
||||
@ -687,7 +687,7 @@ static void interface_read_file(struct overlay_interface *interface)
|
||||
struct socket_address srcaddr;
|
||||
srcaddr.addrlen = sizeof packet.src_addr;
|
||||
srcaddr.inet = packet.src_addr;
|
||||
packetOkOverlay(interface, packet.payload, packet.payload_length, -1, &srcaddr);
|
||||
packetOkOverlay(interface, packet.payload, packet.payload_length, &srcaddr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -810,13 +810,13 @@ int overlay_broadcast_ensemble(struct network_destination *destination, struct o
|
||||
{
|
||||
assert(destination && destination->interface);
|
||||
const unsigned char *bytes = ob_ptr(buffer);
|
||||
int len = ob_position(buffer);
|
||||
size_t len = ob_position(buffer);
|
||||
|
||||
struct overlay_interface *interface = destination->interface;
|
||||
destination->last_tx = gettime_ms();
|
||||
|
||||
if (config.debug.packettx){
|
||||
DEBUGF("Sending this packet via interface %s (len=%d)",interface->name,len);
|
||||
DEBUGF("Sending this packet via interface %s (len=%zu)",interface->name, len);
|
||||
DEBUG_packet_visualise(NULL, bytes, len);
|
||||
}
|
||||
|
||||
@ -826,7 +826,7 @@ int overlay_broadcast_ensemble(struct network_destination *destination, struct o
|
||||
}
|
||||
|
||||
if (interface->debug)
|
||||
DEBUGF("Sending on %s, len %d: %s", interface->name, len, alloca_tohex(bytes, len>64?64:len));
|
||||
DEBUGF("Sending on %s, len %zu: %s", interface->name, len, alloca_tohex(bytes, len>64?64:len));
|
||||
|
||||
interface->tx_count++;
|
||||
|
||||
@ -842,11 +842,11 @@ int overlay_broadcast_ensemble(struct network_destination *destination, struct o
|
||||
.pid = getpid(),
|
||||
};
|
||||
|
||||
if (len > sizeof(packet.payload)){
|
||||
if (len > sizeof packet.payload) {
|
||||
WARN("Truncating long packet to fit within MTU byte limit for dummy interface");
|
||||
len = sizeof(packet.payload);
|
||||
len = sizeof packet.payload;
|
||||
}
|
||||
packet.payload_length=len;
|
||||
packet.payload_length = len;
|
||||
bcopy(bytes, packet.payload, len);
|
||||
ob_free(buffer);
|
||||
/* This lseek() is unneccessary because the dummy file is opened in O_APPEND mode. It's
|
||||
@ -886,22 +886,22 @@ int overlay_broadcast_ensemble(struct network_destination *destination, struct o
|
||||
case SOCK_DGRAM:
|
||||
{
|
||||
if (config.debug.overlayinterfaces)
|
||||
DEBUGF("Sending %zu byte overlay frame on %s to %s", (size_t)len, interface->name, inet_ntoa(destination->address.sin_addr));
|
||||
DEBUGF("Sending %zu byte overlay frame on %s to %s", len, interface->name, inet_ntoa(destination->address.sin_addr));
|
||||
ssize_t sent = sendto(interface->alarm.poll.fd,
|
||||
bytes, (size_t)len, 0,
|
||||
(struct sockaddr *)&destination->address, sizeof(destination->address));
|
||||
ob_free(buffer);
|
||||
if (sent == -1 || (size_t)sent != (size_t)len) {
|
||||
if (sent == -1 || (size_t)sent != len) {
|
||||
if (sent == -1)
|
||||
WHYF_perror("sendto(fd=%d,len=%zu,addr=%s) on interface %s",
|
||||
interface->alarm.poll.fd,
|
||||
(size_t)len,
|
||||
len,
|
||||
alloca_sockaddr((struct sockaddr *)&destination->address, sizeof destination->address),
|
||||
interface->name
|
||||
);
|
||||
else
|
||||
WHYF("sendto() sent %zu bytes of overlay frame (%zu) to interface %s (socket=%d)",
|
||||
(size_t)sent, (size_t)len, interface->name, interface->alarm.poll.fd);
|
||||
(size_t)sent, len, interface->name, interface->alarm.poll.fd);
|
||||
// close the interface if we had any error while sending broadcast packets,
|
||||
// unicast packets should not bring the interface down
|
||||
if (destination == interface->destination)
|
||||
@ -934,11 +934,11 @@ overlay_interface_register(char *name,
|
||||
|
||||
// Find the matching non-dummy interface rule.
|
||||
const struct config_network_interface *ifconfig = NULL;
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < config.interfaces.ac; ++i, ifconfig = NULL) {
|
||||
ifconfig = &config.interfaces.av[i].value;
|
||||
if (ifconfig->socket_type==SOCK_DGRAM) {
|
||||
int j;
|
||||
unsigned j;
|
||||
for (j = 0; j < ifconfig->match.patc; ++j){
|
||||
if (fnmatch(ifconfig->match.patv[j], name, 0) == 0)
|
||||
break;
|
||||
@ -1011,7 +1011,7 @@ overlay_interface_register(char *name,
|
||||
void overlay_interface_discover(struct sched_ent *alarm)
|
||||
{
|
||||
/* Mark all UP interfaces as DETECTING, so we can tell which interfaces are new, and which are dead */
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < overlay_interface_count; i++)
|
||||
if (overlay_interfaces[i].state==INTERFACE_STATE_UP)
|
||||
overlay_interfaces[i].state=INTERFACE_STATE_DETECTING;
|
||||
@ -1027,7 +1027,7 @@ void overlay_interface_discover(struct sched_ent *alarm)
|
||||
detect_real_interfaces = 1;
|
||||
continue;
|
||||
}
|
||||
int j;
|
||||
unsigned j;
|
||||
for (j = 0; j < overlay_interface_count; j++){
|
||||
if (overlay_interfaces[j].socket_type == ifconfig->socket_type &&
|
||||
strcasecmp(overlay_interfaces[j].name, ifconfig->file) == 0 &&
|
||||
|
@ -18,6 +18,35 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@ -42,17 +71,17 @@ static struct profile_total mdp_stats = { .name="overlay_mdp_poll" };
|
||||
static struct sched_ent mdp_sock = {
|
||||
.function = overlay_mdp_poll,
|
||||
.stats = &mdp_stats,
|
||||
.poll.fd = -1,
|
||||
.poll={.fd = -1},
|
||||
};
|
||||
|
||||
static struct profile_total mdp_stats2 = { .name="mdp_poll2" };
|
||||
static struct sched_ent mdp_sock2 = {
|
||||
.function = mdp_poll2,
|
||||
.stats = &mdp_stats2,
|
||||
.poll.fd = -1,
|
||||
.poll={.fd = -1},
|
||||
};
|
||||
|
||||
static int overlay_saw_mdp_frame(struct overlay_frame *frame, overlay_mdp_frame *mdp, time_ms_t now);
|
||||
static int overlay_saw_mdp_frame(struct overlay_frame *frame, overlay_mdp_frame *mdp);
|
||||
static int mdp_send2(struct socket_address *client, struct mdp_header *header,
|
||||
const uint8_t *payload, size_t payload_len);
|
||||
|
||||
@ -206,7 +235,7 @@ static int overlay_mdp_releasebindings(struct socket_address *client)
|
||||
|
||||
}
|
||||
|
||||
static int overlay_mdp_process_bind_request(int sock, struct subscriber *subscriber, mdp_port_t port,
|
||||
static int overlay_mdp_process_bind_request(struct subscriber *subscriber, mdp_port_t port,
|
||||
int flags, struct socket_address *client)
|
||||
{
|
||||
if (config.debug.mdprequests)
|
||||
@ -417,7 +446,7 @@ int overlay_mdp_decrypt(struct overlay_frame *f, overlay_mdp_frame *mdp)
|
||||
OUT();
|
||||
}
|
||||
|
||||
int overlay_saw_mdp_containing_frame(struct overlay_frame *f, time_ms_t now)
|
||||
int overlay_saw_mdp_containing_frame(struct overlay_frame *f)
|
||||
{
|
||||
IN();
|
||||
/* Take frame source and destination and use them to populate mdp->in->{src,dst}
|
||||
@ -440,7 +469,7 @@ int overlay_saw_mdp_containing_frame(struct overlay_frame *f, time_ms_t now)
|
||||
RETURN(-1);
|
||||
|
||||
/* and do something with it! */
|
||||
RETURN(overlay_saw_mdp_frame(f, &mdp,now));
|
||||
RETURN(overlay_saw_mdp_frame(f, &mdp));
|
||||
OUT();
|
||||
}
|
||||
|
||||
@ -453,7 +482,7 @@ int overlay_mdp_swap_src_dst(overlay_mdp_frame *mdp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int overlay_saw_mdp_frame(struct overlay_frame *frame, overlay_mdp_frame *mdp, time_ms_t now)
|
||||
static int overlay_saw_mdp_frame(struct overlay_frame *frame, overlay_mdp_frame *mdp)
|
||||
{
|
||||
IN();
|
||||
int i;
|
||||
@ -737,7 +766,7 @@ static int overlay_send_frame(
|
||||
|
||||
if (ob_overrun(plaintext)) {
|
||||
if (config.debug.mdprequests)
|
||||
DEBUGF("Frame overrun: position=%d allocSize=%d sizeLimit=%d",
|
||||
DEBUGF("Frame overrun: position=%zu allocSize=%zu sizeLimit=%zu",
|
||||
plaintext->position, plaintext->allocSize, plaintext->sizeLimit);
|
||||
op_free(frame);
|
||||
ob_free(plaintext);
|
||||
@ -887,7 +916,7 @@ int overlay_mdp_dispatch(overlay_mdp_frame *mdp, struct socket_address *client)
|
||||
DEBUGF("[%u] destination->sid=%s", __d, destination ? alloca_tohex_sid_t(destination->sid) : "NULL");
|
||||
if (!destination || destination->reachable == REACHABLE_SELF){
|
||||
/* Packet is addressed to us / broadcast, we should process it first. */
|
||||
overlay_saw_mdp_frame(NULL,mdp,gettime_ms());
|
||||
overlay_saw_mdp_frame(NULL,mdp);
|
||||
if (destination) {
|
||||
/* Is local, and is not broadcast, so shouldn't get sent out on the wire. */
|
||||
if (config.debug.mdprequests)
|
||||
@ -1021,6 +1050,7 @@ static void overlay_mdp_scan(struct sched_ent *alarm)
|
||||
struct sockaddr_in addr={
|
||||
.sin_family=AF_INET,
|
||||
.sin_port=htons(PORT_DNA),
|
||||
.sin_addr={0},
|
||||
};
|
||||
struct scan_state *state = (struct scan_state *)alarm;
|
||||
uint32_t stop = state->last;
|
||||
@ -1105,15 +1135,14 @@ static int mdp_process_identity_request(struct socket_address *client, struct md
|
||||
size_t ofs=0;
|
||||
while(ofs < payload_len){
|
||||
if (!payload[ofs++]){
|
||||
int cn, in;
|
||||
for (cn = keyring->context_count -1; cn>=0; --cn) {
|
||||
keyring_context *cx = keyring->contexts[cn];
|
||||
for (in = cx->identity_count -1; in>=0; --in) {
|
||||
keyring_identity *id = cx->identities[in];
|
||||
if (id->subscriber != my_subscriber
|
||||
&& strcmp(id->PKRPin, pin) == 0){
|
||||
unsigned cn;
|
||||
for (cn = keyring->context_count; cn > 0;) {
|
||||
keyring_context *cx = keyring->contexts[--cn];
|
||||
unsigned in;
|
||||
for (in = cx->identity_count; in > 0;) {
|
||||
keyring_identity *id = cx->identities[--in];
|
||||
if (id->subscriber != my_subscriber && strcmp(id->PKRPin, pin) == 0)
|
||||
keyring_release_identity(keyring, cn, in);
|
||||
}
|
||||
}
|
||||
}
|
||||
pin=(char *)&payload[ofs++];
|
||||
@ -1162,7 +1191,7 @@ static int mdp_process_identity_request(struct socket_address *client, struct md
|
||||
static int mdp_search_identities(struct socket_address *client, struct mdp_header *header,
|
||||
const uint8_t *payload, size_t payload_len)
|
||||
{
|
||||
int cn=0, in=0, kp=0;
|
||||
unsigned cn=0, in=0, kp=0;
|
||||
const char *tag=NULL;
|
||||
const unsigned char *value=NULL;
|
||||
size_t value_len=0;
|
||||
@ -1374,7 +1403,7 @@ static void mdp_process_packet(struct socket_address *client, struct mdp_header
|
||||
|
||||
if (config.debug.mdprequests)
|
||||
DEBUGF("Attempting to process mdp packet locally");
|
||||
overlay_saw_mdp_frame(NULL, &mdp, gettime_ms());
|
||||
overlay_saw_mdp_frame(NULL, &mdp);
|
||||
}
|
||||
|
||||
if (config.debug.mdprequests)
|
||||
@ -1444,11 +1473,11 @@ static void mdp_poll2(struct sched_ent *alarm)
|
||||
struct iovec iov[]={
|
||||
{
|
||||
.iov_base = (void *)&header,
|
||||
.iov_len = sizeof(struct mdp_header)
|
||||
.iov_len = sizeof header
|
||||
},
|
||||
{
|
||||
.iov_base = (void *)payload,
|
||||
.iov_len = sizeof(payload)
|
||||
.iov_len = sizeof payload
|
||||
}
|
||||
};
|
||||
|
||||
@ -1460,17 +1489,17 @@ static void mdp_poll2(struct sched_ent *alarm)
|
||||
};
|
||||
|
||||
ssize_t len = recvmsg(alarm->poll.fd, &hdr, 0);
|
||||
if (len<0){
|
||||
WHY_perror("recvmsg");
|
||||
if (len == -1){
|
||||
WHYF_perror("recvmsg(%d,%p,0)", alarm->poll.fd, &hdr);
|
||||
return;
|
||||
}
|
||||
if (len<sizeof(struct mdp_header)){
|
||||
WHYF("Expected length %d, got %d from %s", (int)sizeof(struct mdp_header), (int)len, alloca_socket_address(&client));
|
||||
if ((size_t)len < sizeof header) {
|
||||
WHYF("Expected length %zu, got %zu from %s", sizeof header, (size_t)len, alloca_socket_address(&client));
|
||||
return;
|
||||
}
|
||||
|
||||
client.addrlen = hdr.msg_namelen;
|
||||
size_t payload_len = len - sizeof(header);
|
||||
size_t payload_len = (size_t)(len - sizeof header);
|
||||
mdp_process_packet(&client, &header, payload, payload_len);
|
||||
}
|
||||
}
|
||||
@ -1492,7 +1521,7 @@ static void overlay_mdp_poll(struct sched_ent *alarm)
|
||||
&client, alloca_socket_address(&client)
|
||||
);
|
||||
|
||||
if (len > 0) {
|
||||
if ((size_t)len > 0) {
|
||||
if (client.addrlen <= sizeof(sa_family_t))
|
||||
WHYF("got client.addrlen=%d too short -- ignoring frame len=%zu", (int)client.addrlen, (size_t)len);
|
||||
else {
|
||||
@ -1567,7 +1596,7 @@ static void overlay_mdp_poll(struct sched_ent *alarm)
|
||||
}
|
||||
|
||||
}
|
||||
if (overlay_mdp_process_bind_request(alarm->poll.fd, subscriber, mdp->bind.port,
|
||||
if (overlay_mdp_process_bind_request(subscriber, mdp->bind.port,
|
||||
mdp->packetTypeAndFlags, &client))
|
||||
overlay_mdp_reply_error(alarm->poll.fd, &client, 3, "Port already in use");
|
||||
else
|
||||
|
@ -154,7 +154,7 @@ int overlay_mdp_service_rhizomeresponse(overlay_mdp_frame *mdp)
|
||||
a slot to capture this files as it is being requested
|
||||
by someone else.
|
||||
*/
|
||||
rhizome_received_content(bidprefix,version,offset, count, bytes, type);
|
||||
rhizome_received_content(bidprefix,version,offset, count, bytes);
|
||||
|
||||
RETURN(0);
|
||||
}
|
||||
@ -168,7 +168,7 @@ int overlay_mdp_service_rhizomeresponse(overlay_mdp_frame *mdp)
|
||||
int overlay_mdp_service_dnalookup(overlay_mdp_frame *mdp)
|
||||
{
|
||||
IN();
|
||||
int cn=0,in=0,kp=0;
|
||||
unsigned cn=0, in=0, kp=0;
|
||||
char did[64+1];
|
||||
int pll=mdp->out.payload_length;
|
||||
if (pll>64) pll=64;
|
||||
@ -351,8 +351,8 @@ end:
|
||||
|
||||
static int overlay_mdp_service_manifest_requests(struct overlay_frame *frame, const uint8_t *payload, size_t len)
|
||||
{
|
||||
int offset=0;
|
||||
while (offset<len) {
|
||||
size_t offset = 0;
|
||||
while (offset < len) {
|
||||
rhizome_manifest *m = rhizome_new_manifest();
|
||||
if (!m)
|
||||
return WHY("Unable to allocate manifest");
|
||||
|
@ -16,6 +16,35 @@
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
Integration with olsr routing.
|
||||
@ -48,8 +77,7 @@ static struct profile_total read_timing={
|
||||
static struct sched_ent read_watch={
|
||||
.function=olsr_read,
|
||||
.stats=&read_timing,
|
||||
.poll.fd=-1,
|
||||
.poll.events=POLLIN,
|
||||
.poll={.fd=-1,.events=POLLIN},
|
||||
};
|
||||
|
||||
int olsr_init_socket(void){
|
||||
@ -67,6 +95,7 @@ int olsr_init_socket(void){
|
||||
.sin_family = AF_INET,
|
||||
.sin_addr.s_addr = htonl(INADDR_LOOPBACK),
|
||||
.sin_port = htons(config.olsr.local_port),
|
||||
.sin_zero = {0},
|
||||
};
|
||||
|
||||
fd = socket(AF_INET,SOCK_DGRAM,0);
|
||||
@ -167,12 +196,12 @@ static void parse_frame(struct overlay_buffer *buff){
|
||||
frame.modifiers=ob_get(buff);
|
||||
|
||||
if (config.debug.overlayinterfaces)
|
||||
DEBUGF("Received %d byte payload via olsr", buff->sizeLimit - buff->position);
|
||||
DEBUGF("Received %zu byte payload via olsr", buff->sizeLimit - buff->position);
|
||||
|
||||
// the remaining bytes are an mdp payload, process it
|
||||
frame.payload = buff;
|
||||
|
||||
overlay_saw_mdp_containing_frame(&frame, gettime_ms());
|
||||
overlay_saw_mdp_containing_frame(&frame);
|
||||
|
||||
// TODO relay this packet to other non-olsr networks.
|
||||
|
||||
@ -217,6 +246,7 @@ static int send_packet(unsigned char *header, int header_len, unsigned char *pay
|
||||
.sin_family=AF_INET,
|
||||
.sin_addr.s_addr=htonl(INADDR_LOOPBACK),
|
||||
.sin_port=htons(config.olsr.remote_port),
|
||||
.sin_zero = {0},
|
||||
};
|
||||
|
||||
struct iovec iov[]={
|
||||
@ -267,7 +297,7 @@ int olsr_send(struct overlay_frame *frame){
|
||||
ob_append_byte(b, frame->modifiers);
|
||||
|
||||
if (config.debug.overlayinterfaces)
|
||||
DEBUGF("Sending %d byte payload via olsr", frame->payload->sizeLimit);
|
||||
DEBUGF("Sending %zu byte payload via olsr", frame->payload->sizeLimit);
|
||||
|
||||
// send the packet
|
||||
int ret = send_packet(b->bytes, b->position, frame->payload->bytes, frame->payload->sizeLimit);
|
||||
|
@ -78,9 +78,9 @@ int overlay_packet_init_header(int packet_version, int encapsulation,
|
||||
}
|
||||
|
||||
// a frame destined for one of our local addresses, or broadcast, has arrived. Process it.
|
||||
int process_incoming_frame(time_ms_t now, struct overlay_interface *interface, struct overlay_frame *f, struct decode_context *context){
|
||||
int process_incoming_frame(time_ms_t now, struct overlay_interface *UNUSED(interface), struct overlay_frame *f, struct decode_context *context)
|
||||
{
|
||||
IN();
|
||||
int id = (interface - overlay_interfaces);
|
||||
switch(f->type)
|
||||
{
|
||||
case OF_TYPE_SELFANNOUNCE_ACK:
|
||||
@ -88,11 +88,11 @@ int process_incoming_frame(time_ms_t now, struct overlay_interface *interface, s
|
||||
break;
|
||||
// data frames
|
||||
case OF_TYPE_RHIZOME_ADVERT:
|
||||
overlay_rhizome_saw_advertisements(id,context,f,now);
|
||||
overlay_rhizome_saw_advertisements(context,f);
|
||||
break;
|
||||
case OF_TYPE_DATA:
|
||||
case OF_TYPE_DATA_VOICE:
|
||||
overlay_saw_mdp_containing_frame(f,now);
|
||||
overlay_saw_mdp_containing_frame(f);
|
||||
break;
|
||||
case OF_TYPE_PLEASEEXPLAIN:
|
||||
process_explain(f);
|
||||
@ -238,7 +238,7 @@ int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *f
|
||||
RETURN(WHY("Unable to read packet seq"));
|
||||
// TODO unicast
|
||||
if ((flags & PAYLOAD_FLAG_ONE_HOP) || !(flags & PAYLOAD_FLAG_TO_BROADCAST)){
|
||||
if (link_received_duplicate(context->sender, context->interface, context->sender_interface, seq, 0)){
|
||||
if (link_received_duplicate(context->sender, seq)){
|
||||
if (config.debug.verbose && config.debug.overlayframes)
|
||||
DEBUG("Don't process or forward duplicate payloads");
|
||||
forward=process=0;
|
||||
@ -321,7 +321,7 @@ int parseEnvelopeHeader(struct decode_context *context, struct overlay_interface
|
||||
}
|
||||
|
||||
int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, size_t len,
|
||||
int recvttl, struct socket_address *recvaddr)
|
||||
struct socket_address *recvaddr)
|
||||
{
|
||||
IN();
|
||||
/*
|
||||
@ -425,7 +425,7 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s
|
||||
}
|
||||
|
||||
// TODO allow for single byte length?
|
||||
unsigned int payload_len;
|
||||
size_t payload_len;
|
||||
|
||||
switch (context.encapsulation){
|
||||
case ENCAP_SINGLE:
|
||||
@ -459,7 +459,7 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s
|
||||
|
||||
if (header_valid!=0){
|
||||
|
||||
f.payload = ob_slice(b, b->position, payload_len);
|
||||
f.payload = ob_slice(b, ob_position(b), payload_len);
|
||||
if (!f.payload){
|
||||
// out of memory?
|
||||
WHY("Unable to slice payload");
|
||||
|
@ -94,7 +94,7 @@ int overlay_frame_append_payload(struct decode_context *context, int encapsulati
|
||||
alloca_tohex_sid_t(p->destination->sid),p->type,
|
||||
"append_payload stuffing into packet");
|
||||
if (p->payload)
|
||||
dump("payload contents", &p->payload->bytes[0],p->payload->position);
|
||||
dump("payload contents", &p->payload->bytes[0], ob_position(p->payload));
|
||||
}
|
||||
|
||||
struct broadcast *broadcast=NULL;
|
||||
|
@ -56,7 +56,7 @@ struct sched_ent next_packet;
|
||||
struct profile_total send_packet;
|
||||
|
||||
static void overlay_send_packet(struct sched_ent *alarm);
|
||||
static int overlay_calc_queue_time(overlay_txqueue *queue, struct overlay_frame *frame);
|
||||
static int overlay_calc_queue_time(struct overlay_frame *frame);
|
||||
|
||||
int overlay_queue_init(){
|
||||
/* Set default congestion levels for queues */
|
||||
@ -219,7 +219,7 @@ int overlay_payload_enqueue(struct overlay_frame *p)
|
||||
if (p->queue==OQ_ISOCHRONOUS_VOICE)
|
||||
rhizome_saw_voice_traffic();
|
||||
|
||||
overlay_calc_queue_time(queue, p);
|
||||
overlay_calc_queue_time(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -283,7 +283,8 @@ static void remove_destination(struct overlay_frame *frame, int i){
|
||||
|
||||
// update the alarm time and return 1 if changed
|
||||
static int
|
||||
overlay_calc_queue_time(overlay_txqueue *queue, struct overlay_frame *frame){
|
||||
overlay_calc_queue_time(struct overlay_frame *frame)
|
||||
{
|
||||
|
||||
time_ms_t next_allowed_packet=0;
|
||||
// check all interfaces
|
||||
@ -334,7 +335,7 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim
|
||||
while(frame){
|
||||
if (frame->enqueued_at + queue->latencyTarget < now){
|
||||
if (config.debug.overlayframes)
|
||||
DEBUGF("Dropping frame type %x (length %d) for %s due to expiry timeout",
|
||||
DEBUGF("Dropping frame type %x (length %zu) for %s due to expiry timeout",
|
||||
frame->type, frame->payload->checkpointLength,
|
||||
frame->destination?alloca_tohex_sid_t(frame->destination->sid):"All");
|
||||
frame = overlay_queue_remove(queue, frame);
|
||||
@ -492,7 +493,7 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim
|
||||
|
||||
skip:
|
||||
// if we can't send the payload now, check when we should try next
|
||||
overlay_calc_queue_time(queue, frame);
|
||||
overlay_calc_queue_time(frame);
|
||||
frame = frame->next;
|
||||
}
|
||||
}
|
||||
@ -528,7 +529,8 @@ overlay_fill_send_packet(struct outgoing_packet *packet, time_ms_t now) {
|
||||
}
|
||||
|
||||
// when the queue timer elapses, send a packet
|
||||
static void overlay_send_packet(struct sched_ent *alarm){
|
||||
static void overlay_send_packet(struct sched_ent *UNUSED(alarm))
|
||||
{
|
||||
struct outgoing_packet packet;
|
||||
bzero(&packet, sizeof(struct outgoing_packet));
|
||||
packet.seq=-1;
|
||||
@ -594,7 +596,7 @@ int overlay_queue_ack(struct subscriber *neighbour, struct network_destination *
|
||||
if (config.debug.ack)
|
||||
DEBUGF("RE-TX DUE TO NACK: Requeue packet %p to %s sent by seq %d due to ack of seq %d", frame, alloca_tohex_sid_t(neighbour->sid), frame_seq, ack_seq);
|
||||
frame->delay_until = now;
|
||||
overlay_calc_queue_time(&overlay_tx[i], frame);
|
||||
overlay_calc_queue_time(frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,35 @@
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "fdqueue.h"
|
||||
#include "conf.h"
|
||||
|
||||
@ -138,7 +167,7 @@ int fd_clearstats()
|
||||
|
||||
int fd_showstats()
|
||||
{
|
||||
struct profile_total total={NULL, 0, "Total", 0,0,0};
|
||||
struct profile_total total={NULL, 0, "Total", 0,0,0,0};
|
||||
|
||||
stats_head = sort(stats_head);
|
||||
|
||||
|
22
radio_link.c
22
radio_link.c
@ -93,18 +93,18 @@ struct radio_link_state{
|
||||
|
||||
// decoded length of next link layer packet
|
||||
// including all header and footer bytes
|
||||
int payload_length;
|
||||
size_t payload_length;
|
||||
// last rx seq for reassembly
|
||||
int seq;
|
||||
// offset within payload that we have found a valid looking header
|
||||
int payload_start;
|
||||
unsigned payload_start;
|
||||
// offset after payload_start for incoming bytes
|
||||
int payload_offset;
|
||||
unsigned payload_offset;
|
||||
|
||||
// small buffer for assembling mdp payloads.
|
||||
uint8_t dst[MDP_MTU];
|
||||
// length of recovered packet
|
||||
int packet_length;
|
||||
size_t packet_length;
|
||||
|
||||
// next firmware heartbeat
|
||||
time_ms_t next_heartbeat;
|
||||
@ -118,7 +118,7 @@ struct radio_link_state{
|
||||
int32_t remaining_space;
|
||||
|
||||
// next serial write
|
||||
uint64_t next_tx_allowed;
|
||||
time_ms_t next_tx_allowed;
|
||||
// partially sent packet
|
||||
struct overlay_buffer *tx_packet;
|
||||
|
||||
@ -433,7 +433,7 @@ static int radio_link_parse(struct overlay_interface *interface, struct radio_li
|
||||
if (config.debug.radio_link)
|
||||
DEBUGF("PDU Complete (length=%d)",state->packet_length);
|
||||
|
||||
packetOkOverlay(interface, state->dst, state->packet_length, -1, NULL);
|
||||
packetOkOverlay(interface, state->dst, state->packet_length, NULL);
|
||||
state->packet_length=sizeof(state->dst)+1;
|
||||
}
|
||||
return 1;
|
||||
@ -443,17 +443,17 @@ static int decode_length(struct radio_link_state *state, unsigned char *p)
|
||||
{
|
||||
// look for a valid golay encoded length
|
||||
int errs=0;
|
||||
int length = golay_decode(&errs, p);
|
||||
if (length<0 || ((length >>8) & 0xF) != (length&0xF))
|
||||
int gd = golay_decode(&errs, p);
|
||||
if (gd<0 || ((gd >>8) & 0xF) != (gd&0xF))
|
||||
return -1;
|
||||
length=length&0xFF;
|
||||
size_t length = gd&0xFF;
|
||||
length += RADIO_HEADER_LENGTH + RADIO_CRC_LENGTH;
|
||||
|
||||
if (length!=17 && (length <= FEC_LENGTH || length > LINK_MTU))
|
||||
return -1;
|
||||
|
||||
if (config.debug.radio_link && (errs || state->payload_length!=*p))
|
||||
DEBUGF("Decoded length %d to %d with %d errs", *p, length, errs);
|
||||
DEBUGF("Decoded length %u to %zu with %d errs", *p, length, errs);
|
||||
|
||||
state->payload_length=length;
|
||||
return 0;
|
||||
@ -465,7 +465,7 @@ int radio_link_decode(struct overlay_interface *interface, uint8_t c)
|
||||
IN();
|
||||
struct radio_link_state *state=interface->radio_link_state;
|
||||
|
||||
if (state->payload_start + state->payload_offset >= sizeof(state->payload)){
|
||||
if (state->payload_start + state->payload_offset >= sizeof state->payload){
|
||||
// drop one byte if we run out of space
|
||||
if (config.debug.radio_link)
|
||||
DEBUGF("Dropped %02x, buffer full", state->payload[0]);
|
||||
|
51
rhizome.c
51
rhizome.c
@ -18,6 +18,35 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "serval.h"
|
||||
@ -106,7 +135,7 @@ int rhizome_bundle_import_files(rhizome_manifest *m, const char *manifest_path,
|
||||
if (ret==0){
|
||||
buffer_len = read_uint16(marker);
|
||||
if (buffer_len < 1 || buffer_len > MAX_MANIFEST_BYTES)
|
||||
ret=WHYF("Invalid manifest length %zd", buffer_len);
|
||||
ret=WHYF("Invalid manifest length %zu", buffer_len);
|
||||
}
|
||||
|
||||
if (ret==0){
|
||||
@ -115,10 +144,8 @@ int rhizome_bundle_import_files(rhizome_manifest *m, const char *manifest_path,
|
||||
}
|
||||
|
||||
if (ret==0){
|
||||
ret = fread(buffer, 1, buffer_len, f);
|
||||
if (ret==buffer_len)
|
||||
ret=0;
|
||||
else
|
||||
ssize_t nread = fread(buffer, 1, buffer_len, f);
|
||||
if ((size_t)nread != buffer_len)
|
||||
ret=WHY_perror("Unable to read manifest contents");
|
||||
}
|
||||
|
||||
@ -138,11 +165,11 @@ int rhizome_bundle_import_files(rhizome_manifest *m, const char *manifest_path,
|
||||
return WHY("could not verify manifest");
|
||||
|
||||
/* Do we already have this manifest or newer? */
|
||||
int64_t dbVersion = -1;
|
||||
if (sqlite_exec_int64(&dbVersion, "SELECT version FROM MANIFESTS WHERE id = ?;", RHIZOME_BID_T, &m->cryptoSignPublic, END) == -1)
|
||||
uint64_t dbVersion = 0;
|
||||
if (sqlite_exec_uint64(&dbVersion, "SELECT version FROM MANIFESTS WHERE id = ?;", RHIZOME_BID_T, &m->cryptoSignPublic, END) == -1)
|
||||
return WHY("Select failure");
|
||||
|
||||
if (dbVersion>=m->version)
|
||||
if (dbVersion >= m->version)
|
||||
return 2;
|
||||
|
||||
int status = rhizome_import_file(m, filepath);
|
||||
@ -274,8 +301,8 @@ int rhizome_add_manifest(rhizome_manifest *m, int ttl)
|
||||
return WHY("Manifest does not have an ID");
|
||||
|
||||
/* Discard the new manifest unless it is newer than the most recent known version with the same ID */
|
||||
int64_t storedversion = -1;
|
||||
switch (sqlite_exec_int64(&storedversion, "SELECT version FROM MANIFESTS WHERE id = ?;", RHIZOME_BID_T, &m->cryptoSignPublic, END)) {
|
||||
uint64_t storedversion = -1;
|
||||
switch (sqlite_exec_uint64(&storedversion, "SELECT version FROM MANIFESTS WHERE id = ?;", RHIZOME_BID_T, &m->cryptoSignPublic, END)) {
|
||||
case -1:
|
||||
return WHY("Select failed");
|
||||
case 0:
|
||||
@ -283,11 +310,11 @@ int rhizome_add_manifest(rhizome_manifest *m, int ttl)
|
||||
break;
|
||||
case 1:
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("Found existing version=%"PRId64", new version=%"PRId64, storedversion, m->version);
|
||||
DEBUGF("Found existing version=%"PRIu64", new version=%"PRIu64, storedversion, m->version);
|
||||
if (m->version < storedversion)
|
||||
return WHY("Newer version exists");
|
||||
if (m->version == storedversion)
|
||||
return WHYF("Already have %s:%"PRId64", not adding", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version);
|
||||
return WHYF("Already have %s:%"PRIu64", not adding", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version);
|
||||
break;
|
||||
default:
|
||||
return WHY("Select found too many rows!");
|
||||
|
35
rhizome.h
35
rhizome.h
@ -161,9 +161,8 @@ typedef struct rhizome_manifest
|
||||
|
||||
/* Version of the manifest. Typically the number of milliseconds since 1970.
|
||||
* A value of zero (0) means it has not been set yet.
|
||||
* TODO: change this to uint64_t.
|
||||
*/
|
||||
int64_t version;
|
||||
uint64_t version;
|
||||
|
||||
/* Payload is described by the offset of its tail (number of missing bytes
|
||||
* before the first byte in the payload), its size (number of bytes) and the
|
||||
@ -360,7 +359,7 @@ typedef struct rhizome_manifest
|
||||
#define rhizome_manifest_del_author(m) _rhizome_manifest_del_author(__WHENCE__,(m))
|
||||
|
||||
void _rhizome_manifest_set_id(struct __sourceloc, rhizome_manifest *, const rhizome_bid_t *);
|
||||
void _rhizome_manifest_set_version(struct __sourceloc, rhizome_manifest *, int64_t); // TODO change to uint64_t
|
||||
void _rhizome_manifest_set_version(struct __sourceloc, rhizome_manifest *, uint64_t);
|
||||
void _rhizome_manifest_set_filesize(struct __sourceloc, rhizome_manifest *, uint64_t);
|
||||
void _rhizome_manifest_set_filehash(struct __sourceloc, rhizome_manifest *, const rhizome_filehash_t *);
|
||||
void _rhizome_manifest_set_tail(struct __sourceloc, rhizome_manifest *, uint64_t);
|
||||
@ -445,7 +444,7 @@ sqlite_retry_state sqlite_retry_state_init(int serverLimit, int serverSleep, int
|
||||
|
||||
struct rhizome_manifest_summary {
|
||||
rhizome_bid_t bid;
|
||||
int64_t version;
|
||||
uint64_t version;
|
||||
size_t body_len;
|
||||
};
|
||||
|
||||
@ -538,8 +537,8 @@ void _sqlite_retry_done(struct __sourceloc, sqlite_retry_state *retry, const cha
|
||||
int _sqlite_step(struct __sourceloc, int log_level, sqlite_retry_state *retry, sqlite3_stmt *statement);
|
||||
int _sqlite_exec_void(struct __sourceloc, int log_level, const char *sqltext, ...);
|
||||
int _sqlite_exec_void_retry(struct __sourceloc, int log_level, sqlite_retry_state *retry, const char *sqltext, ...);
|
||||
int _sqlite_exec_int64(struct __sourceloc, int64_t *result, const char *sqltext, ...);
|
||||
int _sqlite_exec_int64_retry(struct __sourceloc, sqlite_retry_state *retry, int64_t *result, const char *sqltext, ...);
|
||||
int _sqlite_exec_uint64(struct __sourceloc, uint64_t *result, const char *sqltext, ...);
|
||||
int _sqlite_exec_uint64_retry(struct __sourceloc, sqlite_retry_state *retry, uint64_t *result, const char *sqltext, ...);
|
||||
int _sqlite_exec_strbuf(struct __sourceloc, strbuf sb, const char *sqltext, ...);
|
||||
int _sqlite_exec_strbuf_retry(struct __sourceloc, sqlite_retry_state *retry, strbuf sb, const char *sqltext, ...);
|
||||
int _sqlite_vexec_strbuf_retry(struct __sourceloc, sqlite_retry_state *retry, strbuf sb, const char *sqltext, va_list ap);
|
||||
@ -565,8 +564,8 @@ int _sqlite_vexec_strbuf_retry(struct __sourceloc, sqlite_retry_state *retry, st
|
||||
#define sqlite_exec_void_loglevel(ll,sql,arg,...) _sqlite_exec_void(__WHENCE__, (ll), (sql), arg, ##__VA_ARGS__)
|
||||
#define sqlite_exec_void_retry(rs,sql,arg,...) _sqlite_exec_void_retry(__WHENCE__, LOG_LEVEL_ERROR, (rs), (sql), arg, ##__VA_ARGS__)
|
||||
#define sqlite_exec_void_retry_loglevel(ll,rs,sql,arg,...) _sqlite_exec_void_retry(__WHENCE__, (ll), (rs), (sql), arg, ##__VA_ARGS__)
|
||||
#define sqlite_exec_int64(res,sql,arg,...) _sqlite_exec_int64(__WHENCE__, (res), (sql), arg, ##__VA_ARGS__)
|
||||
#define sqlite_exec_int64_retry(rs,res,sql,arg,...) _sqlite_exec_int64_retry(__WHENCE__, (rs), (res), (sql), arg, ##__VA_ARGS__)
|
||||
#define sqlite_exec_uint64(res,sql,arg,...) _sqlite_exec_uint64(__WHENCE__, (res), (sql), arg, ##__VA_ARGS__)
|
||||
#define sqlite_exec_uint64_retry(rs,res,sql,arg,...) _sqlite_exec_uint64_retry(__WHENCE__, (rs), (res), (sql), arg, ##__VA_ARGS__)
|
||||
#define sqlite_exec_strbuf(sb,sql,arg,...) _sqlite_exec_strbuf(__WHENCE__, (sb), (sql), arg, ##__VA_ARGS__)
|
||||
#define sqlite_exec_strbuf_retry(rs,sb,sql,arg,...) _sqlite_exec_strbuf_retry(__WHENCE__, (rs), (sb), (sql), arg, ##__VA_ARGS__)
|
||||
|
||||
@ -575,7 +574,7 @@ int rhizome_manifest_extract_signature(rhizome_manifest *m, unsigned *ofs);
|
||||
int rhizome_update_file_priority(const char *fileid);
|
||||
int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found);
|
||||
int rhizome_manifest_to_bar(rhizome_manifest *m,unsigned char *bar);
|
||||
int64_t rhizome_bar_version(const unsigned char *bar);
|
||||
uint64_t rhizome_bar_version(const unsigned char *bar);
|
||||
uint64_t rhizome_bar_bidprefix_ll(unsigned char *bar);
|
||||
int rhizome_is_bar_interesting(unsigned char *bar);
|
||||
int rhizome_is_manifest_interesting(rhizome_manifest *m);
|
||||
@ -604,7 +603,7 @@ int rhizome_bk_xor_stream(
|
||||
const size_t rs_len,
|
||||
unsigned char *xor_stream,
|
||||
int xor_stream_byte_count);
|
||||
int rhizome_bk2secret(rhizome_manifest *m,
|
||||
int rhizome_bk2secret(
|
||||
const rhizome_bid_t *bidp,
|
||||
const unsigned char *rs, const size_t rs_len,
|
||||
/* The BK need only be the length of the secret half of the secret key */
|
||||
@ -618,7 +617,6 @@ int rhizome_secret2bk(
|
||||
unsigned char bkout[RHIZOME_BUNDLE_KEY_BYTES],
|
||||
const unsigned char secret[crypto_sign_edwards25519sha512batch_SECRETKEYBYTES]
|
||||
);
|
||||
unsigned char *rhizome_bundle_shared_secret(rhizome_manifest *m);
|
||||
int rhizome_sign_hash_with_key(rhizome_manifest *m,const unsigned char *sk,
|
||||
const unsigned char *pk,rhizome_signature *out);
|
||||
int rhizome_verify_bundle_privatekey(const unsigned char *sk, const unsigned char *pk);
|
||||
@ -690,7 +688,7 @@ struct rhizome_write
|
||||
unsigned char nonce[crypto_stream_xsalsa20_NONCEBYTES];
|
||||
|
||||
SHA512_CTX sha512_context;
|
||||
int64_t blob_rowid;
|
||||
uint64_t blob_rowid;
|
||||
int blob_fd;
|
||||
sqlite3_blob *sql_blob;
|
||||
};
|
||||
@ -709,11 +707,11 @@ struct rhizome_read
|
||||
unsigned char key[RHIZOME_CRYPT_KEY_BYTES];
|
||||
unsigned char nonce[crypto_stream_xsalsa20_NONCEBYTES];
|
||||
|
||||
int64_t hash_offset;
|
||||
uint64_t hash_offset;
|
||||
SHA512_CTX sha512_context;
|
||||
char invalid;
|
||||
|
||||
int64_t blob_rowid;
|
||||
uint64_t blob_rowid;
|
||||
int blob_fd;
|
||||
|
||||
uint64_t tail;
|
||||
@ -765,8 +763,7 @@ typedef struct rhizome_http_request
|
||||
} rhizome_http_request;
|
||||
|
||||
int rhizome_received_content(const unsigned char *bidprefix,uint64_t version,
|
||||
uint64_t offset, size_t count,unsigned char *bytes,
|
||||
int type);
|
||||
uint64_t offset, size_t count,unsigned char *bytes);
|
||||
int64_t rhizome_database_create_blob_for(const char *filehashhex_or_tempid,
|
||||
int64_t fileLength,int priority);
|
||||
int rhizome_server_set_response(rhizome_http_request *r, const struct http_response *h);
|
||||
@ -810,7 +807,7 @@ void rhizome_direct_bundle_iterator_unlimit(rhizome_direct_bundle_cursor *r);
|
||||
int rhizome_direct_bundle_iterator_pickle_range(rhizome_direct_bundle_cursor *r,
|
||||
unsigned char *pickled,
|
||||
int pickle_buffer_size);
|
||||
rhizome_manifest *rhizome_direct_get_manifest(unsigned char *bid_prefix,int prefix_length);
|
||||
rhizome_manifest *rhizome_direct_get_manifest(unsigned char *bid_prefix, size_t prefix_length);
|
||||
int rhizome_direct_bundle_iterator_unpickle_range(rhizome_direct_bundle_cursor *r,
|
||||
const unsigned char *pickled,
|
||||
int pickle_buffer_size);
|
||||
@ -913,6 +910,8 @@ struct http_response_parts {
|
||||
char *content_start;
|
||||
};
|
||||
|
||||
#define HTTP_RESPONSE_CONTENT_LENGTH_UNSET UINT64_MAX
|
||||
|
||||
int unpack_http_response(char *response, struct http_response_parts *parts);
|
||||
|
||||
/* rhizome storage methods */
|
||||
@ -943,7 +942,7 @@ ssize_t rhizome_read_buffered(struct rhizome_read *read, struct rhizome_read_buf
|
||||
int rhizome_read_close(struct rhizome_read *read);
|
||||
int rhizome_open_decrypt_read(rhizome_manifest *m, struct rhizome_read *read_state);
|
||||
int rhizome_extract_file(rhizome_manifest *m, const char *filepath);
|
||||
int rhizome_dump_file(const rhizome_filehash_t *hashp, const char *filepath, int64_t *length);
|
||||
int rhizome_dump_file(const rhizome_filehash_t *hashp, const char *filepath, uint64_t *lengthp);
|
||||
int rhizome_read_cached(const rhizome_bid_t *bid, uint64_t version, time_ms_t timeout,
|
||||
uint64_t fileOffset, unsigned char *buffer, size_t length);
|
||||
int rhizome_cache_close();
|
||||
|
@ -38,13 +38,13 @@ static const char *rhizome_manifest_get(const rhizome_manifest *m, const char *v
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int64_t rhizome_manifest_get_ll(rhizome_manifest *m, const char *var)
|
||||
static uint64_t rhizome_manifest_get_ui64(rhizome_manifest *m, const char *var)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < m->var_count; ++i)
|
||||
if (strcmp(m->vars[i], var) == 0) {
|
||||
int64_t val;
|
||||
return str_to_int64(m->values[i], 10, &val, NULL) ? val : -1;
|
||||
uint64_t val;
|
||||
return str_to_uint64(m->values[i], 10, &val, NULL) ? val : -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@ -75,7 +75,7 @@ static int _rhizome_manifest_del(struct __sourceloc __whence, rhizome_manifest *
|
||||
}
|
||||
|
||||
#define rhizome_manifest_set(m,var,value) _rhizome_manifest_set(__WHENCE__, (m), (var), (value))
|
||||
#define rhizome_manifest_set_ll(m,var,value) _rhizome_manifest_set_ll(__WHENCE__, (m), (var), (value))
|
||||
#define rhizome_manifest_set_ui64(m,var,value) _rhizome_manifest_set_ui64(__WHENCE__, (m), (var), (value))
|
||||
#define rhizome_manifest_del(m,var) _rhizome_manifest_del(__WHENCE__, (m), (var))
|
||||
|
||||
static const char *_rhizome_manifest_set(struct __sourceloc __whence, rhizome_manifest *m, const char *var, const char *value)
|
||||
@ -108,10 +108,10 @@ static const char *_rhizome_manifest_set(struct __sourceloc __whence, rhizome_ma
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const char *_rhizome_manifest_set_ll(struct __sourceloc __whence, rhizome_manifest *m, char *var, int64_t value)
|
||||
static const char *_rhizome_manifest_set_ui64(struct __sourceloc __whence, rhizome_manifest *m, char *var, uint64_t value)
|
||||
{
|
||||
char str[50];
|
||||
snprintf(str, sizeof str, "%" PRId64, value);
|
||||
snprintf(str, sizeof str, "%" PRIu64, value);
|
||||
return rhizome_manifest_set(m, var, str);
|
||||
}
|
||||
|
||||
@ -136,16 +136,16 @@ void _rhizome_manifest_set_id(struct __sourceloc __whence, rhizome_manifest *m,
|
||||
}
|
||||
}
|
||||
|
||||
void _rhizome_manifest_set_version(struct __sourceloc __whence, rhizome_manifest *m, int64_t version)
|
||||
void _rhizome_manifest_set_version(struct __sourceloc __whence, rhizome_manifest *m, uint64_t version)
|
||||
{
|
||||
const char *v = rhizome_manifest_set_ll(m, "version", version);
|
||||
const char *v = rhizome_manifest_set_ui64(m, "version", version);
|
||||
assert(v); // TODO: remove known manifest fields from vars[]
|
||||
m->version = version;
|
||||
}
|
||||
|
||||
void _rhizome_manifest_set_filesize(struct __sourceloc __whence, rhizome_manifest *m, uint64_t size)
|
||||
{
|
||||
const char *v = rhizome_manifest_set_ll(m, "filesize", size);
|
||||
const char *v = rhizome_manifest_set_ui64(m, "filesize", size);
|
||||
assert(v); // TODO: remove known manifest fields from vars[]
|
||||
m->filesize = size;
|
||||
if (m->filesize == 0)
|
||||
@ -171,7 +171,7 @@ void _rhizome_manifest_set_filehash(struct __sourceloc __whence, rhizome_manifes
|
||||
|
||||
void _rhizome_manifest_set_tail(struct __sourceloc __whence, rhizome_manifest *m, uint64_t tail)
|
||||
{
|
||||
const char *v = rhizome_manifest_set_ll(m, "tail", tail);
|
||||
const char *v = rhizome_manifest_set_ui64(m, "tail", tail);
|
||||
assert(v); // TODO: remove known manifest fields from vars[]
|
||||
m->tail = tail;
|
||||
m->is_journal = (tail != RHIZOME_SIZE_UNSET);
|
||||
@ -245,7 +245,7 @@ void _rhizome_manifest_del_name(struct __sourceloc __whence, rhizome_manifest *m
|
||||
|
||||
void _rhizome_manifest_set_date(struct __sourceloc __whence, rhizome_manifest *m, time_ms_t date)
|
||||
{
|
||||
const char *v = rhizome_manifest_set_ll(m, "date", date);
|
||||
const char *v = rhizome_manifest_set_ui64(m, "date", (uint64_t)date);
|
||||
assert(v); // TODO: remove known manifest fields from vars[]
|
||||
m->date = date;
|
||||
m->has_date = 1;
|
||||
@ -316,11 +316,15 @@ void _rhizome_manifest_set_crypt(struct __sourceloc __whence, rhizome_manifest *
|
||||
|
||||
void _rhizome_manifest_set_rowid(struct __sourceloc __whence, rhizome_manifest *m, uint64_t rowid)
|
||||
{
|
||||
if (config.debug.rhizome_manifest)
|
||||
DEBUGF("SET manifest[%d].rowid = %"PRIu64, m->manifest_record_number, rowid);
|
||||
m->rowid = rowid;
|
||||
}
|
||||
|
||||
void _rhizome_manifest_set_inserttime(struct __sourceloc __whence, rhizome_manifest *m, time_ms_t time)
|
||||
{
|
||||
if (config.debug.rhizome_manifest)
|
||||
DEBUGF("SET manifest[%d].inserttime = %"PRItime_ms_t, m->manifest_record_number, time);
|
||||
m->inserttime = time;
|
||||
}
|
||||
|
||||
@ -474,7 +478,7 @@ int rhizome_manifest_inspect(const char *buf, size_t len, struct rhizome_manifes
|
||||
state = Error; // invalid "id" field
|
||||
} else if (has_version == 1) {
|
||||
const char *e;
|
||||
if (str_to_uint64(begin, 10, (uint64_t*)&summ->version, &e) && e == eol)
|
||||
if (str_to_uint64(begin, 10, &summ->version, &e) && e == eol)
|
||||
has_version = 2;
|
||||
else
|
||||
state = Error; // invalid "version" field
|
||||
@ -1023,7 +1027,7 @@ int rhizome_manifest_selfsign(rhizome_manifest *m)
|
||||
int rhizome_write_manifest_file(rhizome_manifest *m, const char *path, char append)
|
||||
{
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("write manifest (%d bytes) to %s", m->manifest_all_bytes, path);
|
||||
DEBUGF("write manifest (%zd bytes) to %s", m->manifest_all_bytes, path);
|
||||
if (!m)
|
||||
return WHY("Manifest is null.");
|
||||
if (!m->finalised)
|
||||
@ -1176,7 +1180,7 @@ int rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t
|
||||
int rhizome_lookup_author(rhizome_manifest *m)
|
||||
{
|
||||
IN();
|
||||
int cn, in, kp;
|
||||
unsigned cn, in, kp;
|
||||
switch (m->authorship) {
|
||||
case AUTHOR_NOT_CHECKED:
|
||||
if (config.debug.rhizome)
|
||||
|
@ -31,14 +31,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#include "keyring.h"
|
||||
#include "dataformats.h"
|
||||
|
||||
/* Work out the encrypt/decrypt key for the supplied manifest.
|
||||
If the manifest is not encrypted, then return NULL.
|
||||
*/
|
||||
unsigned char *rhizome_bundle_shared_secret(rhizome_manifest *m)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int rhizome_manifest_createid(rhizome_manifest *m)
|
||||
{
|
||||
if (crypto_sign_edwards25519sha512batch_keypair(m->cryptoSignPublic.binary, m->cryptoSignSecret))
|
||||
@ -133,7 +125,7 @@ int rhizome_bk_xor_stream(
|
||||
* Returns 0 if the BK decodes correctly to the bundle secret, 1 if not. Returns -1 if there is an
|
||||
* error.
|
||||
*/
|
||||
int rhizome_bk2secret(rhizome_manifest *m,
|
||||
int rhizome_bk2secret(
|
||||
const rhizome_bid_t *bidp,
|
||||
const unsigned char *rs, const size_t rs_len,
|
||||
/* The BK need only be the length of the secret half of the secret key */
|
||||
@ -196,17 +188,18 @@ int rhizome_secret2bk(
|
||||
enum rhizome_secret_disposition find_rhizome_secret(const sid_t *authorSidp, size_t *rs_len, const unsigned char **rs)
|
||||
{
|
||||
IN();
|
||||
int cn=0, in=0, kp=0;
|
||||
unsigned cn=0, in=0, kp=0;
|
||||
if (!keyring_find_sid(keyring,&cn,&in,&kp, authorSidp)) {
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("identity sid=%s is not in keyring", alloca_tohex_sid_t(*authorSidp));
|
||||
RETURN(IDENTITY_NOT_FOUND);
|
||||
}
|
||||
kp = keyring_identity_find_keytype(keyring, cn, in, KEYTYPE_RHIZOME);
|
||||
if (kp == -1) {
|
||||
int kpi = keyring_identity_find_keytype(keyring, cn, in, KEYTYPE_RHIZOME);
|
||||
if (kpi == -1) {
|
||||
WARNF("Identity sid=%s has no Rhizome Secret", alloca_tohex_sid_t(*authorSidp));
|
||||
RETURN(IDENTITY_HAS_NO_RHIZOME_SECRET);
|
||||
}
|
||||
kp = (unsigned)kpi;
|
||||
int rslen = keyring->contexts[cn]->identities[in]->keypairs[kp]->private_key_len;
|
||||
assert(rslen >= 16);
|
||||
assert(rslen <= 1024);
|
||||
@ -242,7 +235,7 @@ void rhizome_authenticate_author(rhizome_manifest *m)
|
||||
case FOUND_RHIZOME_SECRET:
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("author has Rhizome secret");
|
||||
switch (rhizome_bk2secret(m, &m->cryptoSignPublic, rs, rs_len, m->bundle_key.binary, m->cryptoSignSecret)) {
|
||||
switch (rhizome_bk2secret(&m->cryptoSignPublic, rs, rs_len, m->bundle_key.binary, m->cryptoSignSecret)) {
|
||||
case 0:
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("authentic");
|
||||
@ -357,7 +350,7 @@ void rhizome_find_bundle_author_and_secret(rhizome_manifest *m)
|
||||
assert(is_sid_t_any(m->author));
|
||||
if (!m->has_bundle_key)
|
||||
RETURNVOID;
|
||||
int cn = 0, in = 0, kp = 0;
|
||||
unsigned cn = 0, in = 0, kp = 0;
|
||||
for (; keyring_next_identity(keyring, &cn, &in, &kp); ++kp) {
|
||||
const sid_t *authorSidp = (const sid_t *) keyring->contexts[cn]->identities[in]->keypairs[kp]->public_key;
|
||||
//if (config.debug.rhizome) DEBUGF("try author identity sid=%s", alloca_tohex_sid_t(*authorSidp));
|
||||
@ -373,7 +366,7 @@ void rhizome_find_bundle_author_and_secret(rhizome_manifest *m)
|
||||
unsigned char *secretp = m->cryptoSignSecret;
|
||||
if (m->haveSecret)
|
||||
secretp = alloca(sizeof m->cryptoSignSecret);
|
||||
if (rhizome_bk2secret(m, &m->cryptoSignPublic, rs, rs_len, m->bundle_key.binary, secretp) == 0) {
|
||||
if (rhizome_bk2secret(&m->cryptoSignPublic, rs, rs_len, m->bundle_key.binary, secretp) == 0) {
|
||||
if (m->haveSecret) {
|
||||
if (memcmp(secretp, m->cryptoSignSecret, sizeof m->cryptoSignSecret) != 0)
|
||||
FATALF("Bundle secret does not match derived secret");
|
||||
@ -542,7 +535,7 @@ int rhizome_manifest_extract_signature(rhizome_manifest *m, unsigned *ofs)
|
||||
RETURN(0);
|
||||
}
|
||||
}
|
||||
WARNF("Unsupported signature at ofs=%u: type=%#02x", sig - m->manifestdata, sigType);
|
||||
WARNF("Unsupported signature at ofs=%u: type=%#02x", (unsigned)(sig - m->manifestdata), sigType);
|
||||
RETURN(3);
|
||||
}
|
||||
|
||||
@ -608,7 +601,7 @@ int rhizome_derive_payload_key(rhizome_manifest *m)
|
||||
return 0;
|
||||
if (m->has_sender && m->has_recipient){
|
||||
unsigned char *nm_bytes=NULL;
|
||||
int cn=0,in=0,kp=0;
|
||||
unsigned cn=0, in=0, kp=0;
|
||||
if (!keyring_find_sid(keyring, &cn, &in, &kp, &m->sender)){
|
||||
cn=in=kp=0;
|
||||
if (!keyring_find_sid(keyring, &cn, &in, &kp, &m->recipient)){
|
||||
|
@ -82,8 +82,8 @@ uuid_t rhizome_db_uuid;
|
||||
/* XXX Requires a messy join that might be slow. */
|
||||
int rhizome_manifest_priority(sqlite_retry_state *retry, const rhizome_bid_t *bidp)
|
||||
{
|
||||
int64_t result = 0;
|
||||
if (sqlite_exec_int64_retry(retry, &result,
|
||||
uint64_t result = 0;
|
||||
if (sqlite_exec_uint64_retry(retry, &result,
|
||||
"SELECT max(grouplist.priorty) FROM GROUPLIST,MANIFESTS,GROUPMEMBERSHIPS"
|
||||
" WHERE MANIFESTS.id = ?"
|
||||
" AND GROUPLIST.id = GROUPMEMBERSHIPS.groupid"
|
||||
@ -116,7 +116,7 @@ static int sqlite_trace_done;
|
||||
*
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
static void sqlite_trace_callback(void *context, const char *rendered_sql)
|
||||
static void sqlite_trace_callback(void *UNUSED(context), const char *rendered_sql)
|
||||
{
|
||||
if (sqlite_trace_func())
|
||||
logMessage(LOG_LEVEL_DEBUG, sqlite_trace_whence ? *sqlite_trace_whence : __HERE__, "%s", rendered_sql);
|
||||
@ -130,7 +130,7 @@ static void sqlite_trace_callback(void *context, const char *rendered_sql)
|
||||
*
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
static void sqlite_profile_callback(void *context, const char *rendered_sql, sqlite_uint64 nanosec)
|
||||
static void sqlite_profile_callback(void *context, const char *rendered_sql, sqlite_uint64 UNUSED(nanosec))
|
||||
{
|
||||
if (!sqlite_trace_done)
|
||||
sqlite_trace_callback(context, rendered_sql);
|
||||
@ -159,7 +159,7 @@ int (*sqlite_set_tracefunc(int (*newfunc)()))()
|
||||
return oldfunc;
|
||||
}
|
||||
|
||||
void sqlite_log(void *ignored, int result, const char *msg)
|
||||
void sqlite_log(void *UNUSED(ignored), int result, const char *msg)
|
||||
{
|
||||
WARNF("Sqlite: %d %s", result, msg);
|
||||
}
|
||||
@ -264,8 +264,8 @@ int rhizome_opendb()
|
||||
|
||||
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
|
||||
|
||||
int64_t version;
|
||||
if (sqlite_exec_int64_retry(&retry, &version, "PRAGMA user_version;", END) == -1)
|
||||
uint64_t version;
|
||||
if (sqlite_exec_uint64_retry(&retry, &version, "PRAGMA user_version;", END) == -1)
|
||||
RETURN(-1);
|
||||
|
||||
if (version<1){
|
||||
@ -958,7 +958,7 @@ int _sqlite_exec_void_retry(struct __sourceloc __whence, int log_level, sqlite_r
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int _sqlite_vexec_int64(struct __sourceloc __whence, sqlite_retry_state *retry, int64_t *result, const char *sqltext, va_list ap)
|
||||
static int _sqlite_vexec_uint64(struct __sourceloc __whence, sqlite_retry_state *retry, uint64_t *result, const char *sqltext, va_list ap)
|
||||
{
|
||||
sqlite3_stmt *statement = _sqlite_prepare(__whence, LOG_LEVEL_ERROR, retry, sqltext);
|
||||
if (!statement)
|
||||
@ -981,7 +981,7 @@ static int _sqlite_vexec_int64(struct __sourceloc __whence, sqlite_retry_state *
|
||||
if (!sqlite_code_ok(stepcode) || ret == -1)
|
||||
return -1;
|
||||
if (sqlite_trace_func())
|
||||
DEBUGF("rowcount=%d changes=%d result=%"PRId64, rowcount, sqlite3_changes(rhizome_db), *result);
|
||||
DEBUGF("rowcount=%d changes=%d result=%"PRIu64, rowcount, sqlite3_changes(rhizome_db), *result);
|
||||
return rowcount;
|
||||
}
|
||||
|
||||
@ -995,28 +995,28 @@ static int _sqlite_vexec_int64(struct __sourceloc __whence, sqlite_retry_state *
|
||||
*
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
int _sqlite_exec_int64(struct __sourceloc __whence, int64_t *result, const char *sqlformat,...)
|
||||
int _sqlite_exec_uint64(struct __sourceloc __whence, uint64_t *result, const char *sqlformat,...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, sqlformat);
|
||||
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
|
||||
int ret = _sqlite_vexec_int64(__whence, &retry, result, sqlformat, ap);
|
||||
int ret = _sqlite_vexec_uint64(__whence, &retry, result, sqlformat, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Same as sqlite_exec_int64() but if the statement cannot be executed because the database is
|
||||
/* Same as sqlite_exec_uint64() but if the statement cannot be executed because the database is
|
||||
* currently locked for updates, then will call sqlite_retry() on the supplied retry state variable
|
||||
* instead of its own, internal one. If 'retry' is passed as NULL, then will not sleep and retry at
|
||||
* all in the event of a busy condition, but will log it as an error and return immediately.
|
||||
*
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
int _sqlite_exec_int64_retry(struct __sourceloc __whence, sqlite_retry_state *retry, int64_t *result, const char *sqlformat,...)
|
||||
int _sqlite_exec_uint64_retry(struct __sourceloc __whence, sqlite_retry_state *retry, uint64_t *result, const char *sqlformat,...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, sqlformat);
|
||||
int ret = _sqlite_vexec_int64(__whence, retry, result, sqlformat, ap);
|
||||
int ret = _sqlite_vexec_uint64(__whence, retry, result, sqlformat, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
@ -1071,16 +1071,18 @@ int _sqlite_vexec_strbuf_retry(struct __sourceloc __whence, sqlite_retry_state *
|
||||
return sqlite_code_ok(stepcode) && ret != -1 ? rowcount : -1;
|
||||
}
|
||||
|
||||
int64_t rhizome_database_used_bytes()
|
||||
static uint64_t rhizome_database_used_bytes()
|
||||
{
|
||||
int64_t db_page_size;
|
||||
int64_t db_page_count;
|
||||
int64_t db_free_page_count;
|
||||
if ( sqlite_exec_int64(&db_page_size, "PRAGMA page_size;", END) == -1LL
|
||||
|| sqlite_exec_int64(&db_page_count, "PRAGMA page_count;", END) == -1LL
|
||||
|| sqlite_exec_int64(&db_free_page_count, "PRAGMA free_count;", END) == -1LL
|
||||
)
|
||||
return WHY("Cannot measure database used bytes");
|
||||
uint64_t db_page_size;
|
||||
uint64_t db_page_count;
|
||||
uint64_t db_free_page_count;
|
||||
if ( sqlite_exec_uint64(&db_page_size, "PRAGMA page_size;", END) == -1LL
|
||||
|| sqlite_exec_uint64(&db_page_count, "PRAGMA page_count;", END) == -1LL
|
||||
|| sqlite_exec_uint64(&db_free_page_count, "PRAGMA free_count;", END) == -1LL
|
||||
) {
|
||||
WHY("Cannot measure database used bytes");
|
||||
return UINT64_MAX;
|
||||
}
|
||||
return db_page_size * (db_page_count - db_free_page_count);
|
||||
}
|
||||
|
||||
@ -1092,7 +1094,7 @@ int rhizome_database_filehash_from_id(const rhizome_bid_t *bidp, uint64_t versio
|
||||
INT64, version, RHIZOME_BID_T, bidp, END) == -1)
|
||||
RETURN(-1);
|
||||
if (strbuf_overrun(hash_sb) || str_to_rhizome_filehash_t(hashp, strbuf_str(hash_sb)) == -1)
|
||||
RETURN(WHYF("malformed file hash for bid=%s version=%"PRId64, alloca_tohex_rhizome_bid_t(*bidp), version));
|
||||
RETURN(WHYF("malformed file hash for bid=%s version=%"PRIu64, alloca_tohex_rhizome_bid_t(*bidp), version));
|
||||
RETURN(0);
|
||||
OUT();
|
||||
}
|
||||
@ -1208,17 +1210,19 @@ int rhizome_cleanup(struct rhizome_cleanup_report *report)
|
||||
int rhizome_make_space(int group_priority, uint64_t bytes)
|
||||
{
|
||||
/* Asked for impossibly large amount */
|
||||
if (bytes>=(config.rhizome.database_size-65536))
|
||||
const size_t margin = 65536;
|
||||
const uint64_t limit = config.rhizome.database_size > margin ? config.rhizome.database_size - margin : 1;
|
||||
if (bytes >= limit)
|
||||
return WHYF("bytes=%"PRIu64" is too large", bytes);
|
||||
|
||||
int64_t db_used = rhizome_database_used_bytes();
|
||||
if (db_used == -1)
|
||||
uint64_t db_used = rhizome_database_used_bytes();
|
||||
if (db_used == UINT64_MAX)
|
||||
return -1;
|
||||
|
||||
rhizome_cleanup(NULL);
|
||||
|
||||
/* If there is already enough space now, then do nothing more */
|
||||
if (db_used<=(config.rhizome.database_size-bytes-65536))
|
||||
if (db_used + bytes <= limit)
|
||||
return 0;
|
||||
|
||||
/* Okay, not enough space, so free up some. */
|
||||
@ -1228,9 +1232,7 @@ int rhizome_make_space(int group_priority, uint64_t bytes)
|
||||
INT, group_priority, END);
|
||||
if (!statement)
|
||||
return -1;
|
||||
while (bytes > (config.rhizome.database_size - 65536 - rhizome_database_used_bytes())
|
||||
&& sqlite_step_retry(&retry, statement) == SQLITE_ROW
|
||||
) {
|
||||
while (db_used + bytes > limit && sqlite_step_retry(&retry, statement) == SQLITE_ROW) {
|
||||
/* Make sure we can drop this blob, and if so drop it, and recalculate number of bytes required */
|
||||
const char *id;
|
||||
/* Get values */
|
||||
@ -1255,6 +1257,8 @@ int rhizome_make_space(int group_priority, uint64_t bytes)
|
||||
* to be paranoid, and it also protects against inconsistency in the database.
|
||||
*/
|
||||
rhizome_drop_stored_file(&hash, group_priority + 1);
|
||||
if ((db_used = rhizome_database_used_bytes()) == UINT64_MAX)
|
||||
break;
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
@ -1456,7 +1460,7 @@ int rhizome_store_bundle(rhizome_manifest *m)
|
||||
|
||||
if (sqlite_exec_void_retry(&retry, "COMMIT;", END) != -1){
|
||||
// This message used in tests; do not modify or remove.
|
||||
INFOF("RHIZOME ADD MANIFEST service=%s bid=%s version=%"PRId64,
|
||||
INFOF("RHIZOME ADD MANIFEST service=%s bid=%s version=%"PRIu64,
|
||||
m->service ? m->service : "NULL",
|
||||
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic),
|
||||
m->version
|
||||
@ -1588,7 +1592,7 @@ int rhizome_list_next(sqlite_retry_state *retry, struct rhizome_list_cursor *c)
|
||||
const char *q_manifestid = (const char *) sqlite3_column_text(c->_statement, 0);
|
||||
const char *manifestblob = (char *) sqlite3_column_blob(c->_statement, 1);
|
||||
size_t manifestblobsize = sqlite3_column_bytes(c->_statement, 1); // must call after sqlite3_column_blob()
|
||||
int64_t q_version = sqlite3_column_int64(c->_statement, 2);
|
||||
uint64_t q_version = sqlite3_column_int64(c->_statement, 2);
|
||||
int64_t q_inserttime = sqlite3_column_int64(c->_statement, 3);
|
||||
const char *q_author = (const char *) sqlite3_column_text(c->_statement, 4);
|
||||
sid_t *author = NULL;
|
||||
@ -1609,7 +1613,7 @@ int rhizome_list_next(sqlite_retry_state *retry, struct rhizome_list_cursor *c)
|
||||
continue;
|
||||
}
|
||||
if (m->version != q_version) {
|
||||
WHYF("MANIFESTS row id=%s version=%"PRId64" does not match manifest blob version=%"PRId64" -- skipped",
|
||||
WHYF("MANIFESTS row id=%s version=%"PRIu64" does not match manifest blob version=%"PRIu64" -- skipped",
|
||||
q_manifestid, q_version, m->version);
|
||||
continue;
|
||||
}
|
||||
@ -1666,20 +1670,21 @@ void rhizome_bytes_to_hex_upper(unsigned const char *in, char *out, int byteCoun
|
||||
int rhizome_update_file_priority(const char *fileid)
|
||||
{
|
||||
/* work out the highest priority of any referrer */
|
||||
int64_t highestPriority = -1;
|
||||
uint64_t highestPriority = 0;
|
||||
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
|
||||
if (sqlite_exec_int64_retry(&retry, &highestPriority,
|
||||
if (sqlite_exec_uint64_retry(&retry, &highestPriority,
|
||||
"SELECT max(grouplist.priority) FROM MANIFESTS, GROUPMEMBERSHIPS, GROUPLIST"
|
||||
" WHERE MANIFESTS.filehash = ?"
|
||||
" AND GROUPMEMBERSHIPS.manifestid = MANIFESTS.id"
|
||||
" AND GROUPMEMBERSHIPS.groupid = GROUPLIST.id;",
|
||||
TEXT_TOUPPER, fileid, END) == -1)
|
||||
TEXT_TOUPPER, fileid, END
|
||||
) == -1
|
||||
)
|
||||
return -1;
|
||||
if ( highestPriority >= 0
|
||||
&& sqlite_exec_void_retry(&retry,
|
||||
"UPDATE files SET highestPriority = ? WHERE id = ?;",
|
||||
INT, highestPriority, TEXT_TOUPPER, fileid, END
|
||||
) == -1
|
||||
if (sqlite_exec_void_retry(&retry,
|
||||
"UPDATE files SET highestPriority = ? WHERE id = ?;",
|
||||
INT64, highestPriority, TEXT_TOUPPER, fileid, END
|
||||
) == -1
|
||||
)
|
||||
return WHYF("cannot update priority for fileid=%s", fileid);
|
||||
return 0;
|
||||
@ -1777,7 +1782,7 @@ static int unpack_manifest_row(rhizome_manifest *m, sqlite3_stmt *statement)
|
||||
{
|
||||
const char *q_id = (const char *) sqlite3_column_text(statement, 0);
|
||||
const char *q_blob = (char *) sqlite3_column_blob(statement, 1);
|
||||
int64_t q_version = sqlite3_column_int64(statement, 2);
|
||||
uint64_t q_version = sqlite3_column_int64(statement, 2);
|
||||
int64_t q_inserttime = sqlite3_column_int64(statement, 3);
|
||||
const char *q_author = (const char *) sqlite3_column_text(statement, 4);
|
||||
size_t q_blobsize = sqlite3_column_bytes(statement, 1); // must call after sqlite3_column_blob()
|
||||
@ -1792,7 +1797,7 @@ static int unpack_manifest_row(rhizome_manifest *m, sqlite3_stmt *statement)
|
||||
rhizome_manifest_set_author(m, &author);
|
||||
}
|
||||
if (m->version != q_version)
|
||||
WARNF("Version mismatch, manifest is %"PRId64", database is %"PRId64, m->version, q_version);
|
||||
WARNF("Version mismatch, manifest is %"PRIu64", database is %"PRIu64, m->version, q_version);
|
||||
rhizome_manifest_set_rowid(m, q_rowid);
|
||||
rhizome_manifest_set_inserttime(m, q_inserttime);
|
||||
return 0;
|
||||
@ -1955,7 +1960,7 @@ int rhizome_delete_file(const rhizome_filehash_t *hashp)
|
||||
return rhizome_delete_file_retry(&retry, hashp);
|
||||
}
|
||||
|
||||
static int is_interesting(const char *id_hex, int64_t version)
|
||||
static int is_interesting(const char *id_hex, uint64_t version)
|
||||
{
|
||||
IN();
|
||||
int ret=1;
|
||||
@ -1988,7 +1993,7 @@ static int is_interesting(const char *id_hex, int64_t version)
|
||||
|
||||
int rhizome_is_bar_interesting(unsigned char *bar)
|
||||
{
|
||||
int64_t version = rhizome_bar_version(bar);
|
||||
uint64_t version = rhizome_bar_version(bar);
|
||||
char id_hex[RHIZOME_BAR_PREFIX_BYTES *2 + 2];
|
||||
tohex(id_hex, RHIZOME_BAR_PREFIX_BYTES * 2, &bar[RHIZOME_BAR_PREFIX_OFFSET]);
|
||||
strcat(id_hex, "%");
|
||||
|
@ -350,8 +350,8 @@ rhizome_direct_bundle_cursor *rhizome_direct_get_fill_response(unsigned char *bu
|
||||
rhizome_bar_bidprefix_ll(&usbuffer[10+us*RHIZOME_BAR_BYTES]));
|
||||
} else {
|
||||
/* We each have a version of this bundle, so see whose is newer */
|
||||
int64_t them_version = rhizome_bar_version(&buffer[10+them*RHIZOME_BAR_BYTES]);
|
||||
int64_t us_version = rhizome_bar_version(&usbuffer[10+us*RHIZOME_BAR_BYTES]);
|
||||
uint64_t them_version = rhizome_bar_version(&buffer[10+them*RHIZOME_BAR_BYTES]);
|
||||
uint64_t us_version = rhizome_bar_version(&usbuffer[10+us*RHIZOME_BAR_BYTES]);
|
||||
if (them_version>us_version) {
|
||||
/* They have the newer version of the bundle */
|
||||
c->buffer[c->buffer_offset_bytes+c->buffer_used]=0x01; /* Please send */
|
||||
@ -359,10 +359,10 @@ rhizome_direct_bundle_cursor *rhizome_direct_get_fill_response(unsigned char *bu
|
||||
&c->buffer[c->buffer_offset_bytes+c->buffer_used+1],
|
||||
RHIZOME_BAR_PREFIX_BYTES);
|
||||
c->buffer_used+=1+RHIZOME_BAR_PREFIX_BYTES;
|
||||
DEBUGF("They have newer version of bundle %016"PRIx64"* (%"PRId64" versus %"PRId64")",
|
||||
DEBUGF("They have newer version of bundle %016"PRIx64"* (%"PRIu64" versus %"PRIu64")",
|
||||
rhizome_bar_bidprefix_ll(&usbuffer[10+us*RHIZOME_BAR_BYTES]),
|
||||
rhizome_bar_version(&usbuffer[10+us*RHIZOME_BAR_BYTES]),
|
||||
rhizome_bar_version(&buffer[10+them*RHIZOME_BAR_BYTES]));
|
||||
them_version,
|
||||
us_version);
|
||||
} else if (them_version<us_version) {
|
||||
/* We have the newer version of the bundle */
|
||||
c->buffer[c->buffer_offset_bytes+c->buffer_used]=0x02; /* I have [newer] */
|
||||
@ -370,10 +370,10 @@ rhizome_direct_bundle_cursor *rhizome_direct_get_fill_response(unsigned char *bu
|
||||
&c->buffer[c->buffer_offset_bytes+c->buffer_used+1],
|
||||
RHIZOME_BAR_PREFIX_BYTES);
|
||||
c->buffer_used+=1+RHIZOME_BAR_PREFIX_BYTES;
|
||||
DEBUGF("We have newer version of bundle %016"PRIx64"* (%"PRId64" versus %"PRId64")",
|
||||
DEBUGF("We have newer version of bundle %016"PRIx64"* (%"PRIu64" versus %"PRIu64")",
|
||||
rhizome_bar_bidprefix_ll(&usbuffer[10+us*RHIZOME_BAR_BYTES]),
|
||||
rhizome_bar_version(&usbuffer[10+us*RHIZOME_BAR_BYTES]),
|
||||
rhizome_bar_version(&buffer[10+them*RHIZOME_BAR_BYTES]));
|
||||
us_version,
|
||||
them_version);
|
||||
} else {
|
||||
DEBUGF("We both have the same version of %016"PRIx64"*",
|
||||
rhizome_bar_bidprefix_ll(&buffer[10+them*RHIZOME_BAR_BYTES]));
|
||||
@ -391,7 +391,7 @@ rhizome_direct_bundle_cursor *rhizome_direct_get_fill_response(unsigned char *bu
|
||||
return c;
|
||||
}
|
||||
|
||||
rhizome_manifest *rhizome_direct_get_manifest(unsigned char *bid_prefix,int prefix_length)
|
||||
rhizome_manifest *rhizome_direct_get_manifest(unsigned char *bid_prefix, size_t prefix_length)
|
||||
{
|
||||
/* Give a BID prefix, e.g., from a BAR, find the matching manifest and return it.
|
||||
Of course, it is possible that more than one manifest matches. This should
|
||||
@ -407,7 +407,6 @@ rhizome_manifest *rhizome_direct_get_manifest(unsigned char *bid_prefix,int pref
|
||||
*/
|
||||
rhizome_bid_t low = RHIZOME_BID_ZERO;
|
||||
rhizome_bid_t high = RHIZOME_BID_MAX;
|
||||
assert(prefix_length >= 0);
|
||||
assert(prefix_length <= sizeof(rhizome_bid_t));
|
||||
bcopy(bid_prefix, low.binary, prefix_length);
|
||||
bcopy(bid_prefix, high.binary, prefix_length);
|
||||
@ -500,7 +499,7 @@ static int rhizome_sync_with_peers(int mode, int peer_count, const struct config
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_rhizome_direct_sync(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int app_rhizome_direct_sync(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (config.debug.verbose)
|
||||
DEBUG_cli_parsed(parsed);
|
||||
@ -527,7 +526,7 @@ int app_rhizome_direct_sync(const struct cli_parsed *parsed, struct cli_context
|
||||
return -1;
|
||||
} else {
|
||||
const struct config_rhizome_peer *peers[config.rhizome.direct.peer.ac];
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < config.rhizome.direct.peer.ac; ++i)
|
||||
peers[i] = &config.rhizome.direct.peer.av[i].value;
|
||||
return rhizome_sync_with_peers(mode, config.rhizome.direct.peer.ac, peers);
|
||||
|
@ -337,6 +337,8 @@ static void rhizome_direct_process_mime_body(struct http_request *hr, const char
|
||||
|
||||
int rhizome_direct_import(rhizome_http_request *r, const char *remainder)
|
||||
{
|
||||
if (*remainder)
|
||||
return 1;
|
||||
if (r->http.verb != HTTP_VERB_POST) {
|
||||
http_request_simple_response(&r->http, 405, NULL);
|
||||
return 0;
|
||||
@ -354,6 +356,8 @@ int rhizome_direct_import(rhizome_http_request *r, const char *remainder)
|
||||
|
||||
int rhizome_direct_enquiry(rhizome_http_request *r, const char *remainder)
|
||||
{
|
||||
if (*remainder)
|
||||
return 1;
|
||||
if (r->http.verb != HTTP_VERB_POST) {
|
||||
http_request_simple_response(&r->http, 405, NULL);
|
||||
return 0;
|
||||
@ -376,6 +380,8 @@ int rhizome_direct_enquiry(rhizome_http_request *r, const char *remainder)
|
||||
*/
|
||||
int rhizome_direct_addfile(rhizome_http_request *r, const char *remainder)
|
||||
{
|
||||
if (*remainder)
|
||||
return 1;
|
||||
if (r->http.verb != HTTP_VERB_POST) {
|
||||
http_request_simple_response(&r->http, 405, NULL);
|
||||
return 0;
|
||||
@ -402,23 +408,23 @@ int rhizome_direct_addfile(rhizome_http_request *r, const char *remainder)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rhizome_direct_dispatch(rhizome_http_request *r, const char *remainder)
|
||||
int rhizome_direct_dispatch(rhizome_http_request *r, const char *UNUSED(remainder))
|
||||
{
|
||||
if ( config.rhizome.api.addfile.uri_path[0]
|
||||
&& strcmp(r->http.path, config.rhizome.api.addfile.uri_path) == 0
|
||||
)
|
||||
return rhizome_direct_addfile(r, remainder);
|
||||
return rhizome_direct_addfile(r, "");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int receive_http_response(int sock, char *buffer, size_t buffer_len, struct http_response_parts *parts)
|
||||
{
|
||||
int len = 0;
|
||||
int count;
|
||||
size_t len = 0;
|
||||
ssize_t count;
|
||||
do {
|
||||
if ((count = read(sock, &buffer[len], buffer_len - len)) == -1)
|
||||
return WHYF_perror("read(%d, %p, %d)", sock, &buffer[len], (int)buffer_len - len);
|
||||
len += count;
|
||||
len += (size_t)count;
|
||||
} while (len < buffer_len && count != 0 && !is_http_header_complete(buffer, len, len));
|
||||
if (config.debug.rhizome_rx)
|
||||
DEBUGF("Received HTTP response %s", alloca_toprint(-1, buffer, len));
|
||||
@ -428,13 +434,13 @@ static int receive_http_response(int sock, char *buffer, size_t buffer_len, stru
|
||||
INFOF("Failed HTTP request: server returned %03u %s", parts->code, parts->reason);
|
||||
return -1;
|
||||
}
|
||||
if (parts->content_length == -1) {
|
||||
if (parts->content_length == HTTP_RESPONSE_CONTENT_LENGTH_UNSET) {
|
||||
if (config.debug.rhizome_rx)
|
||||
DEBUGF("Invalid HTTP reply: missing Content-Length header");
|
||||
return -1;
|
||||
}
|
||||
if (config.debug.rhizome_rx)
|
||||
DEBUGF("content_length=%"PRId64, parts->content_length);
|
||||
DEBUGF("content_length=%"PRIu64, parts->content_length);
|
||||
return len - (parts->content_start - buffer);
|
||||
}
|
||||
|
||||
@ -638,7 +644,7 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
|
||||
DEBUGF("bundle id = %s", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic));
|
||||
DEBUGF("bundle filehash = %s", alloca_tohex_rhizome_filehash_t(m->filehash));
|
||||
DEBUGF("file size = %"PRId64, m->filesize);
|
||||
DEBUGF("version = %"PRId64, m->version);
|
||||
DEBUGF("version = %"PRIu64, m->version);
|
||||
}
|
||||
|
||||
/* We now have everything we need to compose the POST request and send it.
|
||||
@ -658,7 +664,7 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
|
||||
"\r\n";
|
||||
/* Work out what the content length should be */
|
||||
if (config.debug.rhizome_tx)
|
||||
DEBUGF("manifest_all_bytes=%u, manifest_body_bytes=%u", m->manifest_all_bytes, m->manifest_body_bytes);
|
||||
DEBUGF("manifest_all_bytes=%zu, manifest_body_bytes=%zu", m->manifest_all_bytes, m->manifest_body_bytes);
|
||||
assert(m->filesize != RHIZOME_SIZE_UNSET);
|
||||
size_t content_length =
|
||||
strlen(template2) - 2 /* minus 2 for the "%s" that gets replaced */
|
||||
|
@ -79,7 +79,7 @@ struct rhizome_fetch_slot {
|
||||
|
||||
/* MDP transport specific elements */
|
||||
rhizome_bid_t bid;
|
||||
int64_t bidVersion;
|
||||
uint64_t bidVersion;
|
||||
int prefix_length;
|
||||
int mdpIdleTimeout;
|
||||
time_ms_t mdp_last_request_time;
|
||||
@ -151,10 +151,11 @@ static const char * fetch_state(int state)
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t rhizome_active_fetch_bytes_received(int q)
|
||||
static uint64_t rhizome_active_fetch_bytes_received(unsigned q)
|
||||
{
|
||||
if (q<0 || q>=NQUEUES) return -1;
|
||||
if (rhizome_fetch_queues[q].active.state==RHIZOME_FETCH_FREE) return -1;
|
||||
assert(q < NQUEUES);
|
||||
if (rhizome_fetch_queues[q].active.state == RHIZOME_FETCH_FREE)
|
||||
return 0;
|
||||
return rhizome_fetch_queues[q].active.write_state.file_offset;
|
||||
}
|
||||
|
||||
@ -180,13 +181,13 @@ static uint64_t rhizome_fetch_queue_bytes()
|
||||
|
||||
void rhizome_fetch_log_short_status()
|
||||
{
|
||||
int i,active=0;
|
||||
unsigned active = 0;
|
||||
unsigned i;
|
||||
for(i=0;i<NQUEUES;i++)
|
||||
if (rhizome_fetch_queues[i].active.state!=RHIZOME_FETCH_FREE)
|
||||
active++;
|
||||
if (!active)
|
||||
return;
|
||||
|
||||
INFOF("Rhizome transfer progress: %"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64" (remaining %"PRIu64")",
|
||||
rhizome_active_fetch_bytes_received(0),
|
||||
rhizome_active_fetch_bytes_received(1),
|
||||
@ -244,7 +245,7 @@ static struct profile_total fetch_stats = { .name="rhizome_fetch_poll" };
|
||||
*/
|
||||
static struct rhizome_fetch_queue *rhizome_find_queue(unsigned char log_size)
|
||||
{
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < NQUEUES; ++i) {
|
||||
struct rhizome_fetch_queue *q = &rhizome_fetch_queues[i];
|
||||
if (log_size < q->log_size_threshold)
|
||||
@ -261,8 +262,8 @@ static struct rhizome_fetch_queue *rhizome_find_queue(unsigned char log_size)
|
||||
*/
|
||||
static struct rhizome_fetch_slot *rhizome_find_fetch_slot(uint64_t size)
|
||||
{
|
||||
int i;
|
||||
unsigned char log_size = log2ll(size);
|
||||
unsigned i;
|
||||
for (i = 0; i < NQUEUES; ++i) {
|
||||
struct rhizome_fetch_queue *q = &rhizome_fetch_queues[i];
|
||||
if (log_size < q->log_size_threshold && q->active.state == RHIZOME_FETCH_FREE)
|
||||
@ -275,7 +276,7 @@ static struct rhizome_fetch_slot *rhizome_find_fetch_slot(uint64_t size)
|
||||
// find the first matching active slot for this bundle
|
||||
static struct rhizome_fetch_slot *fetch_search_slot(const unsigned char *id, int prefix_length)
|
||||
{
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < NQUEUES; ++i) {
|
||||
struct rhizome_fetch_queue *q = &rhizome_fetch_queues[i];
|
||||
|
||||
@ -328,7 +329,7 @@ static struct rhizome_fetch_candidate *rhizome_fetch_insert(struct rhizome_fetch
|
||||
struct rhizome_fetch_candidate * e = &q->candidate_queue[q->candidate_queue_size - 1];
|
||||
if (config.debug.rhizome_rx)
|
||||
DEBUGF("insert queue[%d] candidate[%u]", (int)(q - rhizome_fetch_queues), i);
|
||||
assert(i >= 0 && i < q->candidate_queue_size);
|
||||
assert(i < q->candidate_queue_size);
|
||||
assert(i == 0 || c[-1].manifest);
|
||||
if (e->manifest) // queue is full
|
||||
rhizome_manifest_free(e->manifest);
|
||||
@ -350,7 +351,7 @@ static struct rhizome_fetch_candidate *rhizome_fetch_insert(struct rhizome_fetch
|
||||
*/
|
||||
static void rhizome_fetch_unqueue(struct rhizome_fetch_queue *q, unsigned i)
|
||||
{
|
||||
assert(i >= 0 && i < q->candidate_queue_size);
|
||||
assert(i < q->candidate_queue_size);
|
||||
struct rhizome_fetch_candidate *c = &q->candidate_queue[i];
|
||||
if (config.debug.rhizome_rx)
|
||||
DEBUGF("unqueue queue[%d] candidate[%d] manifest=%p", (int)(q - rhizome_fetch_queues), i, c->manifest);
|
||||
@ -370,7 +371,7 @@ static void candidate_unqueue(struct rhizome_fetch_candidate *c)
|
||||
for (i = 0; i < NQUEUES; ++i) {
|
||||
struct rhizome_fetch_queue *q = &rhizome_fetch_queues[i];
|
||||
unsigned index = c - q->candidate_queue;
|
||||
if (index>=0 && index < q->candidate_queue_size){
|
||||
if (index < q->candidate_queue_size){
|
||||
rhizome_fetch_unqueue(q, index);
|
||||
return;
|
||||
}
|
||||
@ -383,7 +384,7 @@ static void candidate_unqueue(struct rhizome_fetch_candidate *c)
|
||||
*/
|
||||
int rhizome_any_fetch_active()
|
||||
{
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < NQUEUES; ++i)
|
||||
if (rhizome_fetch_queues[i].active.state != RHIZOME_FETCH_FREE)
|
||||
return 1;
|
||||
@ -396,7 +397,7 @@ int rhizome_any_fetch_active()
|
||||
*/
|
||||
int rhizome_any_fetch_queued()
|
||||
{
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < NQUEUES; ++i)
|
||||
if (rhizome_fetch_queues[i].candidate_queue[0].manifest)
|
||||
return 1;
|
||||
@ -476,7 +477,7 @@ static int rhizome_import_received_bundle(struct rhizome_manifest *m)
|
||||
{
|
||||
m->finalised = 1;
|
||||
if (config.debug.rhizome_rx) {
|
||||
DEBUGF("manifest len=%u has %u signatories. Associated filesize=%"PRIu64" bytes",
|
||||
DEBUGF("manifest len=%zu has %u signatories. Associated filesize=%"PRIu64" bytes",
|
||||
m->manifest_all_bytes, m->sig_count, m->filesize);
|
||||
dump("manifest", m->manifestdata, m->manifest_all_bytes);
|
||||
}
|
||||
@ -492,12 +493,12 @@ static int schedule_fetch(struct rhizome_fetch_slot *slot)
|
||||
slot->start_time=gettime_ms();
|
||||
slot->alarm.poll.fd = -1;
|
||||
slot->write_state.blob_fd=-1;
|
||||
slot->write_state.blob_rowid=-1;
|
||||
slot->write_state.blob_rowid = 0;
|
||||
|
||||
if (slot->manifest) {
|
||||
slot->bid = slot->manifest->cryptoSignPublic;
|
||||
slot->prefix_length = sizeof slot->bid.binary;
|
||||
slot->bidVersion=slot->manifest->version;
|
||||
slot->bidVersion = slot->manifest->version;
|
||||
/* Don't provide a filename, because we will stream the file straight into
|
||||
the database. */
|
||||
slot->manifest->dataFileName = NULL;
|
||||
@ -667,7 +668,7 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m, const struct
|
||||
*/
|
||||
|
||||
if (config.debug.rhizome_rx)
|
||||
DEBUGF("Fetching bundle slot=%d bid=%s version=%"PRId64" size=%"PRIu64" peerip=%s",
|
||||
DEBUGF("Fetching bundle slot=%d bid=%s version=%"PRIu64" size=%"PRIu64" peerip=%s",
|
||||
slotno(slot),
|
||||
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic),
|
||||
m->version,
|
||||
@ -708,7 +709,7 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m, const struct
|
||||
}
|
||||
}
|
||||
}
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < NQUEUES; ++i) {
|
||||
struct rhizome_fetch_slot *as = &rhizome_fetch_queues[i].active;
|
||||
const rhizome_manifest *am = as->manifest;
|
||||
@ -827,7 +828,8 @@ static void rhizome_start_next_queued_fetch(struct rhizome_fetch_slot *slot)
|
||||
static void rhizome_start_next_queued_fetches(struct sched_ent *alarm)
|
||||
{
|
||||
IN();
|
||||
int i;
|
||||
assert(alarm == &sched_activate);
|
||||
unsigned i;
|
||||
for (i = 0; i < NQUEUES; ++i)
|
||||
rhizome_start_next_queued_fetch(&rhizome_fetch_queues[i].active);
|
||||
OUT();
|
||||
@ -838,7 +840,7 @@ int rhizome_fetch_has_queue_space(unsigned char log2_size){
|
||||
struct rhizome_fetch_queue *q = rhizome_find_queue(log2_size);
|
||||
if (q){
|
||||
// is there an empty candidate?
|
||||
unsigned j=0;
|
||||
unsigned j;
|
||||
for (j=0;j < q->candidate_queue_size;j++)
|
||||
if (!q->candidate_queue[j].manifest)
|
||||
return 1;
|
||||
@ -876,7 +878,7 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sock
|
||||
int priority=100; /* normal priority */
|
||||
|
||||
if (config.debug.rhizome_rx)
|
||||
DEBUGF("Considering import bid=%s version=%"PRId64" size=%"PRIu64" priority=%d:",
|
||||
DEBUGF("Considering import bid=%s version=%"PRIu64" size=%"PRIu64" priority=%d:",
|
||||
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version, m->filesize, priority);
|
||||
|
||||
if (!rhizome_is_manifest_interesting(m)) {
|
||||
@ -887,9 +889,9 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sock
|
||||
}
|
||||
|
||||
if (config.debug.rhizome_rx) {
|
||||
int64_t stored_version;
|
||||
if (sqlite_exec_int64(&stored_version, "SELECT version FROM MANIFESTS WHERE id = ?", RHIZOME_BID_T, &m->cryptoSignPublic, END) > 0)
|
||||
DEBUGF(" is new (have version %"PRId64")", stored_version);
|
||||
uint64_t stored_version;
|
||||
if (sqlite_exec_uint64(&stored_version, "SELECT version FROM MANIFESTS WHERE id = ?", RHIZOME_BID_T, &m->cryptoSignPublic, END) > 0)
|
||||
DEBUGF(" is new (have version %"PRIu64")", stored_version);
|
||||
}
|
||||
|
||||
assert(m->filesize != RHIZOME_SIZE_UNSET);
|
||||
@ -1024,8 +1026,7 @@ static int rhizome_fetch_close(struct rhizome_fetch_slot *slot)
|
||||
rhizome_manifest_free(slot->previous);
|
||||
slot->previous = NULL;
|
||||
|
||||
if (slot->write_state.blob_fd>=0 ||
|
||||
slot->write_state.blob_rowid>=0)
|
||||
if (slot->write_state.blob_fd != -1 || slot->write_state.blob_rowid != 0)
|
||||
rhizome_fail_write(&slot->write_state);
|
||||
|
||||
// Release the fetch slot.
|
||||
@ -1161,7 +1162,7 @@ static int pipe_journal(struct rhizome_fetch_slot *slot){
|
||||
uint64_t length = slot->previous->filesize - slot->manifest->tail - slot->write_state.file_offset;
|
||||
|
||||
// of course there might not be any overlap
|
||||
if (start>=0 && start < slot->previous->filesize && length>0){
|
||||
if (start < slot->previous->filesize && length>0){
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("Copying %"PRId64" bytes from previous journal", length);
|
||||
rhizome_journal_pipe(&slot->write_state, &slot->previous->filehash, start, length);
|
||||
@ -1393,7 +1394,7 @@ int rhizome_write_content(struct rhizome_fetch_slot *slot, unsigned char *buffer
|
||||
|
||||
int rhizome_received_content(const unsigned char *bidprefix,
|
||||
uint64_t version, uint64_t offset,
|
||||
size_t count, unsigned char *bytes, int type)
|
||||
size_t count, unsigned char *bytes)
|
||||
{
|
||||
IN();
|
||||
if (!is_rhizome_mdp_enabled()) {
|
||||
@ -1539,7 +1540,7 @@ void rhizome_fetch_poll(struct sched_ent *alarm)
|
||||
rhizome_fetch_switch_to_mdp(slot);
|
||||
return;
|
||||
}
|
||||
if (parts.content_length == -1) {
|
||||
if (parts.content_length == HTTP_RESPONSE_CONTENT_LENGTH_UNSET) {
|
||||
if (config.debug.rhizome_rx)
|
||||
DEBUGF("Invalid HTTP reply: missing Content-Length header");
|
||||
rhizome_fetch_switch_to_mdp(slot);
|
||||
@ -1617,7 +1618,7 @@ int unpack_http_response(char *response, struct http_response_parts *parts)
|
||||
parts->code = 0;
|
||||
parts->reason = NULL;
|
||||
parts->range_start=0;
|
||||
parts->content_length = -1;
|
||||
parts->content_length = HTTP_RESPONSE_CONTENT_LENGTH_UNSET;
|
||||
parts->content_start = NULL;
|
||||
char *p = NULL;
|
||||
if (!str_startswith(response, "HTTP/1.0 ", (const char **)&p)) {
|
||||
|
@ -279,7 +279,7 @@ void rhizome_server_poll(struct sched_ent *alarm)
|
||||
request->uuid = rhizome_http_request_uuid_counter++;
|
||||
request->data_file_name[0] = '\0';
|
||||
request->u.read_state.blob_fd = -1;
|
||||
request->u.read_state.blob_rowid = -1;
|
||||
request->u.read_state.blob_rowid = 0;
|
||||
if (peerip)
|
||||
request->http.client_sockaddr_in = *peerip;
|
||||
request->http.handle_headers = rhizome_dispatch;
|
||||
@ -500,7 +500,7 @@ static int restful_rhizome_bundlelist_json_content_chunk(sqlite_retry_state *ret
|
||||
strbuf_putc(b, ',');
|
||||
strbuf_json_hex(b, m->cryptoSignPublic.binary, sizeof m->cryptoSignPublic.binary);
|
||||
strbuf_putc(b, ',');
|
||||
strbuf_sprintf(b, "%"PRId64, m->version);
|
||||
strbuf_sprintf(b, "%"PRIu64, m->version);
|
||||
strbuf_putc(b, ',');
|
||||
if (m->has_date)
|
||||
strbuf_sprintf(b, "%"PRItime_ms_t, m->date);
|
||||
@ -663,6 +663,7 @@ static int rhizome_file_content(struct http_request *hr, unsigned char *buf, siz
|
||||
const size_t preferred_bufsz = 16 * blocksz;
|
||||
// Reads the next part of the payload into the supplied buffer.
|
||||
rhizome_http_request *r = (rhizome_http_request *) hr;
|
||||
assert(r->u.read_state.length != RHIZOME_SIZE_UNSET);
|
||||
assert(r->u.read_state.offset < r->u.read_state.length);
|
||||
uint64_t remain = r->u.read_state.length - r->u.read_state.offset;
|
||||
size_t readlen = bufsz;
|
||||
@ -708,11 +709,11 @@ static int rhizome_file_page(rhizome_http_request *r, const char *remainder)
|
||||
}
|
||||
if (n != 0)
|
||||
return 1;
|
||||
if (r->u.read_state.length == -1 && rhizome_read(&r->u.read_state, NULL, 0)) {
|
||||
if (r->u.read_state.length == RHIZOME_SIZE_UNSET && rhizome_read(&r->u.read_state, NULL, 0)) {
|
||||
rhizome_read_close(&r->u.read_state);
|
||||
return 1;
|
||||
}
|
||||
assert(r->u.read_state.length != -1);
|
||||
assert(r->u.read_state.length != RHIZOME_SIZE_UNSET);
|
||||
r->http.response.header.resource_length = r->u.read_state.length;
|
||||
if (r->http.request_header.content_range_count > 0) {
|
||||
assert(r->http.request_header.content_range_count == 1);
|
||||
|
@ -120,12 +120,12 @@ int rhizome_manifest_to_bar(rhizome_manifest *m,unsigned char *bar)
|
||||
OUT();
|
||||
}
|
||||
|
||||
int64_t rhizome_bar_version(const unsigned char *bar)
|
||||
uint64_t rhizome_bar_version(const unsigned char *bar)
|
||||
{
|
||||
int64_t version=0;
|
||||
uint64_t version=0;
|
||||
int i;
|
||||
for(i=0;i<7;i++)
|
||||
version|=((int64_t)(bar[RHIZOME_BAR_VERSION_OFFSET+6-i]))<<(8LL*i);
|
||||
version|=((uint64_t)(bar[RHIZOME_BAR_VERSION_OFFSET+6-i]))<<(8LL*i);
|
||||
return version;
|
||||
}
|
||||
|
||||
@ -168,12 +168,12 @@ static int append_bars(struct overlay_buffer *e, sqlite_retry_state *retry, cons
|
||||
DEBUG("Found a BAR that is the wrong size - ignoring");
|
||||
continue;
|
||||
}
|
||||
if (ob_remaining(e) < blob_bytes) {
|
||||
if (ob_remaining(e) < RHIZOME_BAR_BYTES) {
|
||||
// out of room
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
ob_append_bytes(e, (unsigned char *)data, blob_bytes);
|
||||
ob_append_bytes(e, (unsigned char *)data, RHIZOME_BAR_BYTES);
|
||||
*last_rowid=rowid;
|
||||
}
|
||||
if (statement)
|
||||
@ -184,7 +184,7 @@ static int append_bars(struct overlay_buffer *e, sqlite_retry_state *retry, cons
|
||||
/* Periodically queue BAR advertisements
|
||||
Always advertise the most recent 3 manifests in the table, cycle through the rest of the table, adding 17 BAR's at a time
|
||||
*/
|
||||
int64_t bundles_available=0;
|
||||
static uint64_t bundles_available=0;
|
||||
void overlay_rhizome_advertise(struct sched_ent *alarm)
|
||||
{
|
||||
bundles_available=0;
|
||||
@ -204,7 +204,7 @@ void overlay_rhizome_advertise(struct sched_ent *alarm)
|
||||
goto end;
|
||||
|
||||
/* Get number of bundles available */
|
||||
if (sqlite_exec_int64_retry(&retry, &bundles_available, "SELECT COUNT(BAR) FROM MANIFESTS;", END) != 1){
|
||||
if (sqlite_exec_uint64_retry(&retry, &bundles_available, "SELECT COUNT(BAR) FROM MANIFESTS;", END) != 1){
|
||||
WHY("Could not count BARs for advertisement");
|
||||
goto end;
|
||||
}
|
||||
@ -272,7 +272,7 @@ int rhizome_advertise_manifest(struct subscriber *dest, rhizome_manifest *m){
|
||||
if (overlay_payload_enqueue(frame) == -1)
|
||||
goto error;
|
||||
if (config.debug.rhizome_ads)
|
||||
DEBUGF("Advertising manifest %s %"PRId64" to %s",
|
||||
DEBUGF("Advertising manifest %s %"PRIu64" to %s",
|
||||
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version, dest?alloca_tohex_sid_t(dest->sid):"broadcast");
|
||||
return 0;
|
||||
error:
|
||||
@ -282,7 +282,7 @@ error:
|
||||
|
||||
time_ms_t lookup_time=0;
|
||||
|
||||
int overlay_rhizome_saw_advertisements(int i, struct decode_context *context, struct overlay_frame *f, time_ms_t now)
|
||||
int overlay_rhizome_saw_advertisements(struct decode_context *context, struct overlay_frame *f)
|
||||
{
|
||||
IN();
|
||||
if (!f)
|
||||
@ -329,7 +329,7 @@ int overlay_rhizome_saw_advertisements(int i, struct decode_context *context, st
|
||||
}
|
||||
|
||||
if (config.debug.rhizome_ads)
|
||||
DEBUGF("manifest id=%s version=%"PRId64, alloca_tohex_rhizome_bid_t(summ.bid), summ.version);
|
||||
DEBUGF("manifest id=%s version=%"PRIu64, alloca_tohex_rhizome_bid_t(summ.bid), summ.version);
|
||||
|
||||
// If it looks like there is no signature at all, ignore the announcement but don't brown-list
|
||||
// the manifest ID, so that we will still process other offers of the same manifest with
|
||||
@ -421,7 +421,7 @@ next:
|
||||
if (log2_size!=0xFF && rhizome_fetch_has_queue_space(log2_size)!=1)
|
||||
continue;
|
||||
|
||||
int64_t version = rhizome_bar_version(bar);
|
||||
uint64_t version = rhizome_bar_version(bar);
|
||||
// are we already fetching this bundle [or later]?
|
||||
rhizome_manifest *m=rhizome_fetch_search(&bar[RHIZOME_BAR_PREFIX_OFFSET], RHIZOME_BAR_PREFIX_BYTES);
|
||||
if (m && m->version >= version)
|
||||
|
@ -27,8 +27,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
int rhizome_exists(const rhizome_filehash_t *hashp)
|
||||
{
|
||||
int64_t gotfile = 0;
|
||||
if (sqlite_exec_int64(&gotfile, "SELECT COUNT(*) FROM FILES WHERE id = ? and datavalid = 1;", RHIZOME_FILEHASH_T, hashp, END) != 1)
|
||||
uint64_t gotfile = 0;
|
||||
if (sqlite_exec_uint64(&gotfile, "SELECT COUNT(*) FROM FILES WHERE id = ? and datavalid = 1;", RHIZOME_FILEHASH_T, hashp, END) != 1)
|
||||
return 0;
|
||||
return gotfile;
|
||||
}
|
||||
@ -221,17 +221,17 @@ static int write_data(struct rhizome_write *write_state, uint64_t file_offset, u
|
||||
WARNF("Writing file data out of order! [%"PRId64",%"PRId64"]", file_offset, write_state->written_offset);
|
||||
|
||||
if (write_state->blob_fd != -1) {
|
||||
int ofs=0;
|
||||
size_t ofs = 0;
|
||||
// keep trying until all of the data is written.
|
||||
if (lseek64(write_state->blob_fd, (off64_t) file_offset, SEEK_SET) == -1)
|
||||
return WHYF_perror("lseek64(%d,%"PRIu64",SEEK_SET)", write_state->blob_fd, file_offset);
|
||||
while(ofs < data_size){
|
||||
int r=write(write_state->blob_fd, buffer + ofs, data_size - ofs);
|
||||
if (r<0)
|
||||
while (ofs < data_size){
|
||||
ssize_t r = write(write_state->blob_fd, buffer + ofs, (size_t)(data_size - ofs));
|
||||
if (r == -1)
|
||||
return WHY_perror("write");
|
||||
if (config.debug.externalblobs)
|
||||
DEBUGF("Wrote %d bytes to fd %d", r, write_state->blob_fd);
|
||||
ofs+=r;
|
||||
DEBUGF("Wrote %zd bytes to fd %d", (size_t)r, write_state->blob_fd);
|
||||
ofs += (size_t)r;
|
||||
}
|
||||
}else{
|
||||
if (!write_state->sql_blob)
|
||||
@ -467,7 +467,7 @@ int rhizome_fail_write(struct rhizome_write *write)
|
||||
|
||||
int rhizome_finish_write(struct rhizome_write *write)
|
||||
{
|
||||
if (write->blob_rowid==-1 && write->blob_fd == -1)
|
||||
if (write->blob_rowid==0 && write->blob_fd == -1)
|
||||
return WHY("Can't finish a write that has already been closed");
|
||||
if (write->buffer_list){
|
||||
if (rhizome_random_write(write, 0, NULL, 0))
|
||||
@ -565,7 +565,7 @@ int rhizome_finish_write(struct rhizome_write *write)
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("Stored file %s", alloca_tohex_rhizome_filehash_t(write->id));
|
||||
}
|
||||
write->blob_rowid=-1;
|
||||
write->blob_rowid = 0;
|
||||
return 0;
|
||||
|
||||
dbfailure:
|
||||
@ -666,7 +666,7 @@ static int rhizome_write_derive_key(rhizome_manifest *m, struct rhizome_write *w
|
||||
return -1;
|
||||
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("Encrypting payload contents for %s, %"PRId64, alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version);
|
||||
DEBUGF("Encrypting payload contents for %s, %"PRIu64, alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version);
|
||||
|
||||
write->crypt=1;
|
||||
if (m->is_journal && m->tail > 0)
|
||||
@ -713,16 +713,16 @@ failure:
|
||||
int rhizome_open_read(struct rhizome_read *read, const rhizome_filehash_t *hashp)
|
||||
{
|
||||
read->id = *hashp;
|
||||
read->blob_rowid = -1;
|
||||
read->blob_rowid = 0;
|
||||
read->blob_fd = -1;
|
||||
if (sqlite_exec_int64(&read->blob_rowid,
|
||||
if (sqlite_exec_uint64(&read->blob_rowid,
|
||||
"SELECT FILEBLOBS.rowid "
|
||||
"FROM FILEBLOBS, FILES "
|
||||
"WHERE FILEBLOBS.id = FILES.id"
|
||||
" AND FILES.id = ?"
|
||||
" AND FILES.datavalid != 0", RHIZOME_FILEHASH_T, &read->id, END) == -1)
|
||||
return -1;
|
||||
if (read->blob_rowid != -1) {
|
||||
if (read->blob_rowid != 0) {
|
||||
read->length = RHIZOME_SIZE_UNSET; // discover the length on opening the db BLOB
|
||||
} else {
|
||||
// No row in FILEBLOBS, look for an external blob file.
|
||||
@ -763,7 +763,7 @@ static ssize_t rhizome_read_retry(sqlite_retry_state *retry, struct rhizome_read
|
||||
DEBUGF("Read %zu bytes from fd=%d @%"PRIx64, (size_t) rd, read_state->blob_fd, read_state->offset);
|
||||
RETURN(rd);
|
||||
}
|
||||
if (read_state->blob_rowid == -1)
|
||||
if (read_state->blob_rowid == 0)
|
||||
RETURN(WHY("file not open"));
|
||||
sqlite3_blob *blob = NULL;
|
||||
int ret;
|
||||
@ -782,7 +782,7 @@ static ssize_t rhizome_read_retry(sqlite_retry_state *retry, struct rhizome_read
|
||||
// the length.
|
||||
size_t bytes_read = 0;
|
||||
if (buffer && bufsz && read_state->offset < read_state->length) {
|
||||
bytes_read = read_state->length - read_state->offset;
|
||||
bytes_read = (size_t)(read_state->length - read_state->offset);
|
||||
if (bytes_read > bufsz)
|
||||
bytes_read = bufsz;
|
||||
assert(bytes_read > 0);
|
||||
@ -821,7 +821,7 @@ ssize_t rhizome_read(struct rhizome_read *read_state, unsigned char *buffer, siz
|
||||
SHA512_Update(&read_state->sha512_context, buffer, bytes_read);
|
||||
read_state->hash_offset += bytes_read;
|
||||
// if we hash everything and the has doesn't match, we need to delete the payload
|
||||
if (read_state->hash_offset>=read_state->length){
|
||||
if (read_state->hash_offset >= read_state->length){
|
||||
rhizome_filehash_t hash_out;
|
||||
SHA512_Final(hash_out.binary, &read_state->sha512_context);
|
||||
SHA512_End(&read_state->sha512_context, NULL);
|
||||
@ -1051,7 +1051,7 @@ int rhizome_read_cached(const rhizome_bid_t *bidp, uint64_t version, time_ms_t t
|
||||
}
|
||||
|
||||
entry->read_state.offset = fileOffset;
|
||||
if (entry->read_state.length !=-1 && fileOffset >= entry->read_state.length)
|
||||
if (entry->read_state.length != RHIZOME_SIZE_UNSET && fileOffset >= entry->read_state.length)
|
||||
return 0;
|
||||
|
||||
if (entry->expires < timeout){
|
||||
@ -1110,7 +1110,7 @@ static int read_derive_key(rhizome_manifest *m, struct rhizome_read *read_state)
|
||||
return WHY("Unable to decrypt bundle, valid key not found");
|
||||
}
|
||||
if (config.debug.rhizome)
|
||||
DEBUGF("Decrypting payload contents for bid=%s version=%"PRId64, alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version);
|
||||
DEBUGF("Decrypting payload contents for bid=%s version=%"PRIu64, alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version);
|
||||
if (m->is_journal && m->tail > 0)
|
||||
read_state->tail = m->tail;
|
||||
bcopy(m->payloadKey, read_state->key, sizeof(read_state->key));
|
||||
@ -1147,7 +1147,7 @@ int rhizome_extract_file(rhizome_manifest *m, const char *filepath)
|
||||
*
|
||||
* Returns -1 on error, 0 if dumped successfully, 1 if not found.
|
||||
*/
|
||||
int rhizome_dump_file(const rhizome_filehash_t *hashp, const char *filepath, int64_t *length)
|
||||
int rhizome_dump_file(const rhizome_filehash_t *hashp, const char *filepath, uint64_t *lengthp)
|
||||
{
|
||||
struct rhizome_read read_state;
|
||||
bzero(&read_state, sizeof read_state);
|
||||
@ -1156,8 +1156,8 @@ int rhizome_dump_file(const rhizome_filehash_t *hashp, const char *filepath, int
|
||||
|
||||
if (ret == 0) {
|
||||
ret = write_file(&read_state, filepath);
|
||||
if (length)
|
||||
*length = read_state.length;
|
||||
if (lengthp)
|
||||
*lengthp = read_state.length;
|
||||
}
|
||||
rhizome_read_close(&read_state);
|
||||
return ret;
|
||||
@ -1166,7 +1166,8 @@ int rhizome_dump_file(const rhizome_filehash_t *hashp, const char *filepath, int
|
||||
// pipe data from one payload to another
|
||||
static int rhizome_pipe(struct rhizome_read *read, struct rhizome_write *write, uint64_t length)
|
||||
{
|
||||
if (length > write->file_length - write->file_offset)
|
||||
assert(write->file_offset <= write->file_length);
|
||||
if (length > (uint64_t)(write->file_length - write->file_offset))
|
||||
return WHY("Unable to pipe that much data");
|
||||
|
||||
unsigned char buffer[RHIZOME_CRYPT_PAGE_SIZE];
|
||||
|
@ -120,7 +120,7 @@ static void rhizome_sync_send_requests(struct subscriber *subscriber, struct rhi
|
||||
if (log2_size!=0xFF && rhizome_fetch_has_queue_space(log2_size)!=1)
|
||||
continue;
|
||||
|
||||
int64_t version = rhizome_bar_version(state->bars[i].bar);
|
||||
uint64_t version = rhizome_bar_version(state->bars[i].bar);
|
||||
// are we already fetching this bundle [or later]?
|
||||
rhizome_manifest *m=rhizome_fetch_search(prefix, RHIZOME_BAR_PREFIX_BYTES);
|
||||
if (m && m->version >= version)
|
||||
@ -176,14 +176,14 @@ static int sync_bundle_inserted(struct subscriber *subscriber, void *context)
|
||||
return 0;
|
||||
|
||||
const unsigned char *id = &bar[RHIZOME_BAR_PREFIX_OFFSET];
|
||||
int64_t version = rhizome_bar_version(bar);
|
||||
uint64_t version = rhizome_bar_version(bar);
|
||||
|
||||
struct rhizome_sync *state = subscriber->sync_state;
|
||||
int i;
|
||||
for (i=state->bar_count -1;i>=0;i--){
|
||||
unsigned char *this_bar = state->bars[i].bar;
|
||||
unsigned char *this_id = &this_bar[RHIZOME_BAR_PREFIX_OFFSET];
|
||||
int64_t this_version = rhizome_bar_version(this_bar);
|
||||
uint64_t this_version = rhizome_bar_version(this_bar);
|
||||
if (memcmp(this_id, id, RHIZOME_BAR_PREFIX_BYTES)==0 && version >= this_version){
|
||||
// remove this BAR and shift the last BAR down to this position if required.
|
||||
if (config.debug.rhizome)
|
||||
|
19
route_link.c
19
route_link.c
@ -461,7 +461,8 @@ next:
|
||||
RETURN(best_link);
|
||||
}
|
||||
|
||||
static int monitor_announce(struct subscriber *subscriber, void *context){
|
||||
static int monitor_announce(struct subscriber *subscriber, void *UNUSED(context))
|
||||
{
|
||||
if (subscriber->reachable & REACHABLE){
|
||||
struct link_state *state = get_link_state(subscriber);
|
||||
monitor_announce_link(state->hop_count, state->transmitter, subscriber);
|
||||
@ -487,7 +488,7 @@ static int append_link_state(struct overlay_buffer *payload, char flags,
|
||||
flags|=FLAG_HAS_ACK;
|
||||
if (drop_rate!=-1)
|
||||
flags|=FLAG_HAS_DROP_RATE;
|
||||
int length_pos = ob_position(payload);
|
||||
size_t length_pos = ob_position(payload);
|
||||
ob_append_byte(payload, 0);
|
||||
ob_append_byte(payload, flags);
|
||||
overlay_address_append(NULL, payload, receiver);
|
||||
@ -506,7 +507,7 @@ static int append_link_state(struct overlay_buffer *payload, char flags,
|
||||
if (ob_overrun(payload))
|
||||
return -1;
|
||||
// patch the record length
|
||||
int end_pos = ob_position(payload);
|
||||
size_t end_pos = ob_position(payload);
|
||||
ob_set(payload, length_pos, end_pos - length_pos);
|
||||
ob_checkpoint(payload);
|
||||
return 0;
|
||||
@ -765,7 +766,7 @@ static int neighbour_find_best_link(struct neighbour *n)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int neighbour_link_sent(struct overlay_frame *frame, int sequence, void *context)
|
||||
static int neighbour_link_sent(struct overlay_frame *UNUSED(frame), int sequence, void *context)
|
||||
{
|
||||
struct subscriber *subscriber = context;
|
||||
struct neighbour *neighbour = get_neighbour(subscriber, 0);
|
||||
@ -897,7 +898,7 @@ static void link_send(struct sched_ent *alarm)
|
||||
ob_limitsize(frame->payload, 400);
|
||||
overlay_mdp_encode_ports(frame->payload, MDP_PORT_LINKSTATE, MDP_PORT_LINKSTATE);
|
||||
ob_checkpoint(frame->payload);
|
||||
int pos = ob_position(frame->payload);
|
||||
size_t pos = ob_position(frame->payload);
|
||||
enum_subscribers(NULL, append_link, frame->payload);
|
||||
ob_rewind(frame->payload);
|
||||
if (ob_position(frame->payload) == pos)
|
||||
@ -1077,7 +1078,7 @@ int link_state_ack_soon(struct subscriber *subscriber)
|
||||
}
|
||||
|
||||
// our neighbour is sending a duplicate frame, did we see the original?
|
||||
int link_received_duplicate(struct subscriber *subscriber, struct overlay_interface *interface, int sender_interface, int payload_seq, int unicast)
|
||||
int link_received_duplicate(struct subscriber *subscriber, int payload_seq)
|
||||
{
|
||||
struct neighbour *neighbour = get_neighbour(subscriber, 0);
|
||||
if (!neighbour)
|
||||
@ -1106,7 +1107,7 @@ int link_received_duplicate(struct subscriber *subscriber, struct overlay_interf
|
||||
}
|
||||
|
||||
// remote peer has confirmed hearing a recent unicast packet
|
||||
int link_unicast_ack(struct subscriber *subscriber, struct overlay_interface *interface, struct sockaddr_in addr)
|
||||
int link_unicast_ack(struct subscriber *UNUSED(subscriber), struct overlay_interface *UNUSED(interface), struct sockaddr_in UNUSED(addr))
|
||||
{
|
||||
// TODO find / create network destination, keep it alive
|
||||
return 0;
|
||||
@ -1242,7 +1243,7 @@ int link_receive(struct overlay_frame *frame, overlay_mdp_frame *mdp)
|
||||
|
||||
struct subscriber *receiver=NULL, *transmitter=NULL;
|
||||
struct overlay_interface *interface = NULL;
|
||||
int start_pos = ob_position(payload);
|
||||
size_t start_pos = ob_position(payload);
|
||||
int length = ob_get(payload);
|
||||
if (length <=0)
|
||||
break;
|
||||
@ -1441,7 +1442,7 @@ void link_explained(struct subscriber *subscriber)
|
||||
update_alarm(__WHENCE__, now + 5);
|
||||
}
|
||||
|
||||
void link_interface_down(struct overlay_interface *interface)
|
||||
void link_interface_down(struct overlay_interface *UNUSED(interface))
|
||||
{
|
||||
clean_neighbours(gettime_ms());
|
||||
}
|
||||
|
54
serval.h
54
serval.h
@ -18,6 +18,35 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __SERVAL_DNA__SERVAL_H
|
||||
#define __SERVAL_DNA__SERVAL_H
|
||||
|
||||
@ -237,7 +266,7 @@ struct overlay_buffer;
|
||||
struct overlay_frame;
|
||||
struct broadcast;
|
||||
|
||||
#define STRUCT_SCHED_ENT_UNUSED {.poll.fd=-1, ._poll_index=-1,}
|
||||
#define STRUCT_SCHED_ENT_UNUSED {.poll={.fd=-1}, ._poll_index=-1,}
|
||||
|
||||
extern int overlayMode;
|
||||
|
||||
@ -266,14 +295,14 @@ struct slip_decode_state{
|
||||
int encapsulator;
|
||||
int state;
|
||||
unsigned char *src;
|
||||
int src_size;
|
||||
unsigned src_size;
|
||||
char rssi_text[RSSI_TEXT_SIZE];
|
||||
int rssi_len;
|
||||
int packet_length;
|
||||
unsigned rssi_len;
|
||||
unsigned packet_length;
|
||||
unsigned char dst[OVERLAY_INTERFACE_RX_BUFFER_SIZE];
|
||||
uint32_t crc;
|
||||
int src_offset;
|
||||
int dst_offset;
|
||||
unsigned src_offset;
|
||||
unsigned dst_offset;
|
||||
};
|
||||
|
||||
struct overlay_interface;
|
||||
@ -406,7 +435,7 @@ void insertTransactionInCache(unsigned char *transaction_id);
|
||||
|
||||
int overlay_forward_payload(struct overlay_frame *f);
|
||||
int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, size_t len,
|
||||
int recvttl, struct socket_address *recvaddr);
|
||||
struct socket_address *recvaddr);
|
||||
int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *frame,
|
||||
struct overlay_buffer *buffer, struct subscriber **nexthop);
|
||||
int parseEnvelopeHeader(struct decode_context *context, struct overlay_interface *interface,
|
||||
@ -431,7 +460,7 @@ void rhizome_sync_status_html(struct strbuf *b, struct subscriber *subscriber);
|
||||
int rhizome_cache_count();
|
||||
int overlay_add_local_identity(unsigned char *s);
|
||||
|
||||
extern int overlay_interface_count;
|
||||
extern unsigned overlay_interface_count;
|
||||
|
||||
extern int overlay_local_identity_count;
|
||||
extern unsigned char *overlay_local_identities[OVERLAY_MAX_LOCAL_IDENTITIES];
|
||||
@ -447,10 +476,10 @@ int overlay_queue_schedule_next(time_ms_t next_allowed_packet);
|
||||
int overlay_send_tick_packet(struct network_destination *destination);
|
||||
int overlay_queue_ack(struct subscriber *neighbour, struct network_destination *destination, uint32_t ack_mask, int ack_seq);
|
||||
|
||||
int overlay_rhizome_saw_advertisements(int i, struct decode_context *context, struct overlay_frame *f, time_ms_t now);
|
||||
int overlay_rhizome_saw_advertisements(struct decode_context *context, struct overlay_frame *f);
|
||||
int rhizome_server_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
||||
int rhizome_saw_voice_traffic();
|
||||
int overlay_saw_mdp_containing_frame(struct overlay_frame *f, time_ms_t now);
|
||||
int overlay_saw_mdp_containing_frame(struct overlay_frame *f);
|
||||
|
||||
int serval_packetvisualise(const char *message, const unsigned char *packet, size_t len);
|
||||
int serval_packetvisualise_xpf(XPRINTF xpf, const char *message, const unsigned char *packet, size_t len);
|
||||
@ -540,7 +569,7 @@ struct vomp_call_state;
|
||||
void set_codec_flag(int codec, unsigned char *flags);
|
||||
int is_codec_set(int codec, unsigned char *flags);
|
||||
|
||||
struct vomp_call_state *vomp_find_call_by_session(int session_token);
|
||||
struct vomp_call_state *vomp_find_call_by_session(unsigned int session_token);
|
||||
int vomp_mdp_received(overlay_mdp_frame *mdp);
|
||||
int vomp_parse_dtmf_digit(char c);
|
||||
int vomp_dial(struct subscriber *local, struct subscriber *remote, const char *local_did, const char *remote_did);
|
||||
@ -680,11 +709,10 @@ int upper7_decode(struct slip_decode_state *state,unsigned char byte);
|
||||
uint32_t Crc32_ComputeBuf( uint32_t inCrc32, const void *buf,
|
||||
size_t bufLen );
|
||||
void rhizome_fetch_log_short_status();
|
||||
extern int64_t bundles_available;
|
||||
extern char crash_handler_clue[1024];
|
||||
|
||||
|
||||
int link_received_duplicate(struct subscriber *subscriber, struct overlay_interface *interface, int sender_interface, int previous_seq, int unicast);
|
||||
int link_received_duplicate(struct subscriber *subscriber, int previous_seq);
|
||||
int link_received_packet(struct decode_context *context, int sender_seq, char unicast);
|
||||
int link_receive(struct overlay_frame *frame, overlay_mdp_frame *mdp);
|
||||
void link_explained(struct subscriber *subscriber);
|
||||
|
@ -18,6 +18,36 @@ 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
@ -59,7 +89,7 @@ int main(int argc,char **argv)
|
||||
|
||||
#endif
|
||||
|
||||
int serval_packetvisualise_renderaddress(XPRINTF xpf, const unsigned char *packet, size_t *ofs, int senderP)
|
||||
static int serval_packetvisualise_renderaddress(XPRINTF xpf, const unsigned char *packet, size_t *ofs)
|
||||
{
|
||||
unsigned int len = packet[(*ofs)++];
|
||||
xprintf(xpf,"(0x%02x) ",len);
|
||||
@ -81,7 +111,7 @@ int serval_packetvisualise_renderaddress(XPRINTF xpf, const unsigned char *packe
|
||||
xprintf(xpf,"<illegal address token 0x%02x>",len);
|
||||
return -1;
|
||||
}
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i=0;i<len;i++)
|
||||
xprintf(xpf,"%02X",packet[(*ofs)++]);
|
||||
if (len<32) xprintf(xpf,"*");
|
||||
@ -176,7 +206,7 @@ int isOverlayPacket(XPRINTF xpf, const unsigned char *packet, size_t *ofs, size_
|
||||
}
|
||||
|
||||
xprintf(xpf, "%sSender; ", indent(4));
|
||||
int ret=serval_packetvisualise_renderaddress(xpf,packet,ofs,0);
|
||||
int ret=serval_packetvisualise_renderaddress(xpf,packet,ofs);
|
||||
xprintf(xpf, "\n");
|
||||
if (ret)
|
||||
return ret;
|
||||
@ -217,7 +247,7 @@ int isOverlayPacket(XPRINTF xpf, const unsigned char *packet, size_t *ofs, size_
|
||||
|
||||
if (!payload_flags & 1){
|
||||
xprintf(xpf, "%sSender; ", indent(6));
|
||||
int ret=serval_packetvisualise_renderaddress(xpf,packet,ofs,0);
|
||||
int ret=serval_packetvisualise_renderaddress(xpf,packet,ofs);
|
||||
xprintf(xpf, "\n");
|
||||
if (ret)
|
||||
return ret;
|
||||
@ -233,13 +263,13 @@ int isOverlayPacket(XPRINTF xpf, const unsigned char *packet, size_t *ofs, size_
|
||||
}
|
||||
}else{
|
||||
xprintf(xpf, "%sDestination; ", indent(6));
|
||||
int ret=serval_packetvisualise_renderaddress(xpf,packet,ofs,0);
|
||||
int ret=serval_packetvisualise_renderaddress(xpf,packet,ofs);
|
||||
xprintf(xpf, "\n");
|
||||
if (ret)
|
||||
return ret;
|
||||
if (!(payload_flags & 4)){
|
||||
xprintf(xpf, "%sNext Hop; ", indent(6));
|
||||
int ret=serval_packetvisualise_renderaddress(xpf,packet,ofs,0);
|
||||
int ret=serval_packetvisualise_renderaddress(xpf,packet,ofs);
|
||||
xprintf(xpf, "\n");
|
||||
if (ret)
|
||||
return ret;
|
||||
@ -261,7 +291,7 @@ int isOverlayPacket(XPRINTF xpf, const unsigned char *packet, size_t *ofs, size_
|
||||
xprintf(xpf, "%sMDP Sequence; 0x%02x\n", indent(6), packet[(*ofs)++]);
|
||||
}
|
||||
|
||||
int payload_len = 0;
|
||||
uint16_t payload_len = 0;
|
||||
if (encapsulation==1){
|
||||
payload_len=packet[(*ofs)++]<<8;
|
||||
payload_len|=packet[(*ofs)++];
|
||||
@ -321,8 +351,7 @@ int serval_packetvisualise_xpf(XPRINTF xpf, const char *message, const unsigned
|
||||
_dump(xpf, packet, len, 0, " ");
|
||||
size_t ofs=0;
|
||||
xprintf(xpf," Packet Structure:\n");
|
||||
if (isOverlayPacket(xpf,packet,&ofs,len))
|
||||
;
|
||||
if (isOverlayPacket(xpf,packet,&ofs,len)) { }
|
||||
if (ofs<len) {
|
||||
xprintf(xpf," WARNING: The last %d (0x%x) bytes of the packet were not parsed.\n",(int)(len-ofs),(int)(len-ofs));
|
||||
}
|
||||
@ -331,9 +360,10 @@ int serval_packetvisualise_xpf(XPRINTF xpf, const char *message, const unsigned
|
||||
|
||||
static void _dump(XPRINTF xpf, const unsigned char *data, size_t len, size_t ofs, const char *prefix)
|
||||
{
|
||||
int i, j;
|
||||
unsigned i;
|
||||
for (i = ofs & 0xFFFFFFF0; i < len; i += 16) {
|
||||
xprintf(xpf, "%s%04x:", prefix, i);
|
||||
unsigned j;
|
||||
for (j = 0; j < 16; ++j)
|
||||
if (i + j >= ofs && i + j < len)
|
||||
xprintf(xpf," %02x", data[i+j]);
|
||||
|
6
server.c
6
server.c
@ -33,7 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#define EXEC_NARGS 20
|
||||
char *exec_args[EXEC_NARGS + 1];
|
||||
int exec_argc = 0;
|
||||
unsigned exec_argc = 0;
|
||||
|
||||
int servalShutdown = 0;
|
||||
|
||||
@ -74,7 +74,7 @@ int server_pid()
|
||||
void server_save_argv(int argc, const char *const *argv)
|
||||
{
|
||||
/* Save our argv[] to use for relaunching */
|
||||
for (exec_argc = 0; exec_argc < argc && exec_argc < EXEC_NARGS; ++exec_argc)
|
||||
for (exec_argc = 0; exec_argc < (unsigned)argc && exec_argc < EXEC_NARGS; ++exec_argc)
|
||||
exec_args[exec_argc] = strdup(argv[exec_argc]);
|
||||
exec_args[exec_argc] = NULL;
|
||||
}
|
||||
@ -392,7 +392,7 @@ void crash_handler(int signal)
|
||||
|
||||
BACKTRACE;
|
||||
if (config.server.respawn_on_crash) {
|
||||
int i;
|
||||
unsigned i;
|
||||
for(i=0;i<overlay_interface_count;i++)
|
||||
if (overlay_interfaces[i].alarm.poll.fd>-1)
|
||||
close(overlay_interfaces[i].alarm.poll.fd);
|
||||
|
39
sha2.c
39
sha2.c
@ -31,6 +31,35 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h> /* memcpy()/memset() or bcopy()/bzero() */
|
||||
#include <assert.h> /* assert() */
|
||||
#ifdef HAVE_SYS_ENDIAN_H
|
||||
@ -242,7 +271,7 @@ void SHA512_Transform(SHA512_CTX*, const sha2_word64*);
|
||||
|
||||
/*** SHA-XYZ INITIAL HASH VALUES AND CONSTANTS ************************/
|
||||
/* Hash constant words K for SHA-256: */
|
||||
const static sha2_word32 K256[64] = {
|
||||
static const sha2_word32 K256[64] = {
|
||||
0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL,
|
||||
0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL,
|
||||
0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL,
|
||||
@ -262,7 +291,7 @@ const static sha2_word32 K256[64] = {
|
||||
};
|
||||
|
||||
/* Initial hash value H for SHA-256: */
|
||||
const static sha2_word32 sha256_initial_hash_value[8] = {
|
||||
static const sha2_word32 sha256_initial_hash_value[8] = {
|
||||
0x6a09e667UL,
|
||||
0xbb67ae85UL,
|
||||
0x3c6ef372UL,
|
||||
@ -274,7 +303,7 @@ const static sha2_word32 sha256_initial_hash_value[8] = {
|
||||
};
|
||||
|
||||
/* Hash constant words K for SHA-384 and SHA-512: */
|
||||
const static sha2_word64 K512[80] = {
|
||||
static const sha2_word64 K512[80] = {
|
||||
0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL,
|
||||
0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL,
|
||||
0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,
|
||||
@ -318,7 +347,7 @@ const static sha2_word64 K512[80] = {
|
||||
};
|
||||
|
||||
/* Initial hash value H for SHA-384 */
|
||||
const static sha2_word64 sha384_initial_hash_value[8] = {
|
||||
static const sha2_word64 sha384_initial_hash_value[8] = {
|
||||
0xcbbb9d5dc1059ed8ULL,
|
||||
0x629a292a367cd507ULL,
|
||||
0x9159015a3070dd17ULL,
|
||||
@ -330,7 +359,7 @@ const static sha2_word64 sha384_initial_hash_value[8] = {
|
||||
};
|
||||
|
||||
/* Initial hash value H for SHA-512 */
|
||||
const static sha2_word64 sha512_initial_hash_value[8] = {
|
||||
static const sha2_word64 sha512_initial_hash_value[8] = {
|
||||
0x6a09e667f3bcc908ULL,
|
||||
0xbb67ae8584caa73bULL,
|
||||
0x3c6ef372fe94f82bULL,
|
||||
|
@ -17,16 +17,18 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
int sigPipeFlag=0;
|
||||
int sigIoFlag=0;
|
||||
|
||||
void sigPipeHandler(int signal)
|
||||
void sigPipeHandler(int UNUSED(signal))
|
||||
{
|
||||
sigPipeFlag++;
|
||||
return;
|
||||
}
|
||||
|
||||
void sigIoHandler(int signal)
|
||||
void sigIoHandler(int UNUSED(signal))
|
||||
{
|
||||
sigIoFlag++;
|
||||
return;
|
||||
|
27
slip.c
27
slip.c
@ -236,10 +236,10 @@ int upper7_decode(struct slip_decode_state *state,unsigned char byte)
|
||||
u7d_calls++;
|
||||
if (config.debug.slipdecode)
|
||||
snprintf(crash_handler_clue,1024,
|
||||
"upper7_decode() call #%d: state=%d, byte=0x%02x, rssi_len=%d, dst_offset=%d",
|
||||
"upper7_decode() call #%d: state=%d, byte=0x%02x, rssi_len=%u, dst_offset=%u",
|
||||
u7d_calls,state->state,byte,state->rssi_len,state->dst_offset);
|
||||
if (config.debug.slipbytestream)
|
||||
WHYF("call #%d: state=%d, byte=0x%02x, rssi_len=%d, dst_offset=%d",
|
||||
WHYF("call #%d: state=%d, byte=0x%02x, rssi_len=%u, dst_offset=%u",
|
||||
u7d_calls,state->state,byte,state->rssi_len,state->dst_offset);
|
||||
|
||||
// Parse out inline RSSI reports
|
||||
@ -252,13 +252,11 @@ int upper7_decode(struct slip_decode_state *state,unsigned char byte)
|
||||
// for CRC verification etc.
|
||||
state->state=UPPER7_STATE_NOTINPACKET; RETURN(1);
|
||||
} else if (byte>=' '&&byte<=0x7f) {
|
||||
if (state->rssi_len<0) state->rssi_len=0;
|
||||
if (state->rssi_len<RSSI_TEXT_SIZE)
|
||||
state->rssi_text[state->rssi_len++]=byte;
|
||||
RETURN(0);
|
||||
} else if (byte=='\r'||byte=='\n') {
|
||||
if (state->rssi_len>=RSSI_TEXT_SIZE) state->rssi_len=RSSI_TEXT_SIZE-1;
|
||||
if (state->rssi_len<0) state->rssi_len=0;
|
||||
state->rssi_text[state->rssi_len]=0;
|
||||
parse_rfd900_rssi(state->rssi_text);
|
||||
state->rssi_len=0;
|
||||
@ -274,9 +272,8 @@ int upper7_decode(struct slip_decode_state *state,unsigned char byte)
|
||||
byte&=0x7f;
|
||||
if (state->packet_length>=OVERLAY_INTERFACE_RX_BUFFER_SIZE
|
||||
||(state->dst_offset+7)>=OVERLAY_INTERFACE_RX_BUFFER_SIZE
|
||||
||state->dst_offset<0)
|
||||
{
|
||||
WARNF("state=%p, state->dst_offset=%d, ->packet_length=%d, ->state=%d. State reset.",
|
||||
) {
|
||||
WARNF("state=%p, state->dst_offset=%u, ->packet_length=%u, ->state=%d. State reset.",
|
||||
state,state->dst_offset,state->packet_length,state->state);
|
||||
state->state=UPPER7_STATE_NOTINPACKET;
|
||||
state->dst_offset=0;
|
||||
@ -294,7 +291,7 @@ int upper7_decode(struct slip_decode_state *state,unsigned char byte)
|
||||
state->dst_offset=0;
|
||||
} else {
|
||||
if (config.debug.packetradio)
|
||||
DEBUGF("Ignoring jumbo packet of %d bytes",state->packet_length);
|
||||
DEBUGF("Ignoring jumbo packet of %u bytes",state->packet_length);
|
||||
state->state=UPPER7_STATE_NOTINPACKET;
|
||||
}
|
||||
RETURN(0);
|
||||
@ -306,9 +303,8 @@ int upper7_decode(struct slip_decode_state *state,unsigned char byte)
|
||||
case UPPER7_STATE_D0:
|
||||
if (state->packet_length>=OVERLAY_INTERFACE_RX_BUFFER_SIZE
|
||||
||(state->dst_offset+7)>=OVERLAY_INTERFACE_RX_BUFFER_SIZE
|
||||
||state->dst_offset<0)
|
||||
{
|
||||
WARNF("state->dst_offset=%d, ->packet_length=%d, ->state=%d. State reset (again).",
|
||||
) {
|
||||
WARNF("state->dst_offset=%u, ->packet_length=%u, ->state=%d. State reset (again).",
|
||||
state->dst_offset,state->packet_length,state->state);
|
||||
state->state=UPPER7_STATE_NOTINPACKET;
|
||||
state->dst_offset=0;
|
||||
@ -376,7 +372,7 @@ int slip_decode(struct slip_decode_state *state)
|
||||
*/
|
||||
while(state->src_offset < state->src_size){
|
||||
// clear the valid bit flag if we hit the end of the destination buffer
|
||||
if (state->dst_offset>=sizeof(state->dst))
|
||||
if (state->dst_offset >= sizeof state->dst)
|
||||
state->state&=~DC_VALID;
|
||||
|
||||
if (state->state&DC_ESC){
|
||||
@ -447,10 +443,9 @@ int slip_decode(struct slip_decode_state *state)
|
||||
case SLIP_FORMAT_UPPER7:
|
||||
{
|
||||
if (config.debug.slip) {
|
||||
if (state->rssi_len<0) state->rssi_len=0;
|
||||
if (state->rssi_len>=RSSI_TEXT_SIZE) state->rssi_len=RSSI_TEXT_SIZE-1;
|
||||
state->rssi_text[state->rssi_len]=0;
|
||||
DEBUGF("RX state=%d, rssi_len=%d, rssi_text='%s',src=%p, src_size=%d",
|
||||
DEBUGF("RX state=%d, rssi_len=%u, rssi_text='%s',src=%p, src_size=%u",
|
||||
state->state,state->rssi_len,state->rssi_text,
|
||||
state->src,state->src_size);
|
||||
}
|
||||
@ -464,14 +459,14 @@ int slip_decode(struct slip_decode_state *state)
|
||||
uint32_t crc=Crc32_ComputeBuf( 0, state->dst, state->packet_length);
|
||||
if (crc!=state->crc) {
|
||||
if (config.debug.packetradio||config.debug.rejecteddata)
|
||||
DEBUGF("Rejected packet of %d bytes due to CRC mis-match (%08x vs %08x)",
|
||||
DEBUGF("Rejected packet of %u bytes due to CRC mis-match (%08x vs %08x)",
|
||||
state->packet_length,crc,state->crc);
|
||||
if (config.debug.rejecteddata) {
|
||||
dump("bad packet",state->dst,state->packet_length);
|
||||
}
|
||||
} else {
|
||||
if (config.debug.packetradio)
|
||||
DEBUGF("Accepted packet of %d bytes (CRC ok)",state->packet_length);
|
||||
DEBUGF("Accepted packet of %u bytes (CRC ok)",state->packet_length);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
3
socket.c
3
socket.c
@ -80,7 +80,8 @@ int _make_local_sockaddr(struct __sourceloc __whence, struct socket_address *add
|
||||
*/
|
||||
int real_sockaddr(const struct socket_address *src_addr, struct socket_address *dst_addr)
|
||||
{
|
||||
int src_path_len = src_addr->addrlen - sizeof src_addr->local.sun_family;
|
||||
assert(src_addr->addrlen > sizeof src_addr->local.sun_family);
|
||||
size_t src_path_len = src_addr->addrlen - sizeof src_addr->local.sun_family;
|
||||
if ( src_addr->addrlen >= sizeof src_addr->local.sun_family + 1
|
||||
&& src_addr->local.sun_family == AF_UNIX
|
||||
&& src_addr->local.sun_path[0] != '\0'
|
||||
|
31
srandomdev.c
31
srandomdev.c
@ -17,6 +17,35 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 Verdens Gang AS
|
||||
* Copyright (c) 2006-2008 Linpro AS
|
||||
@ -69,7 +98,7 @@ srandomdev(void)
|
||||
#ifndef WIN32
|
||||
FILE *fd;
|
||||
fd = fopen("/dev/urandom", "r");
|
||||
if (fd >= 0) {
|
||||
if (NULL != fd) {
|
||||
if (fread(&seed, sizeof seed, 1, fd) != 1)
|
||||
WARNF("fread(\"/dev/urandom\") failed -- falling back to gettimeofday()");
|
||||
else
|
||||
|
2
str.c
2
str.c
@ -632,7 +632,7 @@ int parse_argv(char *cmdline, char delim, char **argv, int max_argv)
|
||||
}
|
||||
|
||||
/* Like strstr() but doesn't depend on null termination */
|
||||
char *str_str(char *haystack, const char *needle, int haystack_len)
|
||||
char *str_str(char *haystack, const char *needle, size_t haystack_len)
|
||||
{
|
||||
size_t needle_len = strlen(needle);
|
||||
if (needle_len == 0)
|
||||
|
4
str.h
4
str.h
@ -280,7 +280,7 @@ size_t toprint_len(const char *srcBuf, size_t srcBytes, const char quotes[2]);
|
||||
size_t toprint_str_len(const char *srcStr, const char quotes[2]);
|
||||
size_t strn_fromprint(unsigned char *dst, size_t dstsiz, const char *src, size_t srclen, char endquote, const char **afterp);
|
||||
|
||||
#define alloca_toprint_quoted(dstlen,buf,len,quotes) toprint((char *)alloca((dstlen) == -1 ? toprint_len((const char *)(buf),(len), (quotes)) + 1 : (dstlen)), (dstlen), (const char *)(buf), (len), (quotes))
|
||||
#define alloca_toprint_quoted(dstlen,buf,len,quotes) toprint((char *)alloca((dstlen) == -1 ? toprint_len((const char *)(buf),(len), (quotes)) + 1 : (size_t)(dstlen)), (size_t)(dstlen), (const char *)(buf), (len), (quotes))
|
||||
#define alloca_toprint(dstlen,buf,len) alloca_toprint_quoted(dstlen,buf,len,"``")
|
||||
|
||||
#define alloca_str_toprint_quoted(str, quotes) toprint_str((char *)alloca(toprint_str_len((str), (quotes)) + 1), -1, (str), (quotes))
|
||||
@ -378,7 +378,7 @@ int strn_str_casecmp(const char *str1, size_t len1, const char *str2);
|
||||
* @author Paul Gardner-Stephen <paul@servalproject.org>
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
char *str_str(char *haystack, const char *needle, int haystack_len);
|
||||
char *str_str(char *haystack, const char *needle, size_t haystack_len);
|
||||
|
||||
/* Parse a string as an integer in ASCII radix notation in the given 'base' (eg, base=10 means
|
||||
* decimal).
|
||||
|
8
strbuf.h
8
strbuf.h
@ -76,6 +76,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h> // for SIZE_MAX on Debian/Unbuntu/...
|
||||
#include <limits.h> // for SIZE_MAX on Android
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
@ -442,15 +444,15 @@ __STRBUF_INLINE size_t strbuf_len(const_strbuf sb) {
|
||||
}
|
||||
|
||||
|
||||
/** Return remaining space in the strbuf, not counting the terminating nul. Return
|
||||
* the maximum possible size_t value if the strbuf is of undefined size.
|
||||
/** Return remaining space in the strbuf, not counting the terminating nul.
|
||||
* Return SIZE_MAX if the strbuf is of undefined size.
|
||||
*
|
||||
* Invariant: strbuf_size(sb) == -1 || strbuf_remaining(sb) == strbuf_size(sb) - strbuf_len(sb)
|
||||
*
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
__STRBUF_INLINE size_t strbuf_remaining(const_strbuf sb) {
|
||||
return sb->end ? sb->end - strbuf_end(sb) : ~(size_t)0;
|
||||
return !sb->end ? SIZE_MAX : sb->current > sb->end ? 0 : (size_t)(sb->end - sb->current);
|
||||
}
|
||||
|
||||
/** Return the number of chars appended to the strbuf so far, not counting the
|
||||
|
@ -17,6 +17,35 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
@ -58,7 +87,7 @@ static inline strbuf _toprint(strbuf sb, char c)
|
||||
return sb;
|
||||
}
|
||||
|
||||
static strbuf inline _overrun(strbuf sb, const char *suffix)
|
||||
inline static strbuf _overrun(strbuf sb, const char *suffix)
|
||||
{
|
||||
if (strbuf_overrun(sb)) {
|
||||
strbuf_trunc(sb, -strlen(suffix));
|
||||
@ -67,7 +96,7 @@ static strbuf inline _overrun(strbuf sb, const char *suffix)
|
||||
return sb;
|
||||
}
|
||||
|
||||
static strbuf inline _overrun_quote(strbuf sb, char quote, const char *suffix)
|
||||
inline static strbuf _overrun_quote(strbuf sb, char quote, const char *suffix)
|
||||
{
|
||||
if (strbuf_overrun(sb)) {
|
||||
strbuf_trunc(sb, -strlen(suffix) - (quote ? 1 : 0));
|
||||
@ -364,7 +393,7 @@ strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr, socklen_t
|
||||
default: {
|
||||
strbuf_append_socket_domain(sb, addr->sa_family);
|
||||
size_t len = addrlen > sizeof addr->sa_family ? addrlen - sizeof addr->sa_family : 0;
|
||||
int i;
|
||||
unsigned i;
|
||||
for (i = 0; i < len; ++i) {
|
||||
strbuf_putc(sb, i ? ',' : ':');
|
||||
strbuf_sprintf(sb, "%02x", addr->sa_data[i]);
|
||||
|
@ -1713,6 +1713,7 @@ fork_wait_all() {
|
||||
fi
|
||||
done
|
||||
[ $running -eq 0 ] && return 0
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,35 @@ along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
@ -56,7 +85,7 @@ int main(int argc, char **argv)
|
||||
for (i = 1; i < argc; ++i) {
|
||||
const char *arg = argv[i];
|
||||
if (str_startswith(arg, "--size=", &arg)) {
|
||||
if (!str_to_uint64_scaled(arg, 10, &size, NULL) || size < 0)
|
||||
if (!str_to_uint64_scaled(arg, 10, &size, NULL))
|
||||
fatal("illegal --size= argument: %s", arg);
|
||||
}
|
||||
else if (str_startswith(arg, "--label=", &arg))
|
||||
@ -69,13 +98,11 @@ int main(int argc, char **argv)
|
||||
for (i = 0; i != sizeof buf; ++i)
|
||||
buf[i] = stripe(i);
|
||||
const size_t labellen = strlen(label);
|
||||
int bouncemax = sizeof buf - labellen;
|
||||
if (bouncemax < 0)
|
||||
bouncemax = sizeof buf;
|
||||
int bounce = 3;
|
||||
unsigned bouncemax = labellen < sizeof buf ? sizeof buf - labellen : sizeof buf;
|
||||
unsigned bounce = 3;
|
||||
int bouncedelta = 1;
|
||||
while (!ferror(stdout) && offset < size) {
|
||||
int n = sprintf(buf, "%"PRId64, offset);
|
||||
unsigned n = sprintf(buf, "%"PRId64, offset);
|
||||
buf[n] = stripe(n);
|
||||
size_t labelsiz = labellen;
|
||||
if (labelsiz && bounce < sizeof buf) {
|
||||
@ -83,7 +110,7 @@ int main(int argc, char **argv)
|
||||
labelsiz = sizeof buf - bounce;
|
||||
memcpy(buf + bounce, label, labelsiz);
|
||||
}
|
||||
int remain = size - offset - 1;
|
||||
unsigned remain = size - offset - 1;
|
||||
if (remain > sizeof buf)
|
||||
remain = sizeof buf;
|
||||
fwrite(buf, remain, 1, stdout);
|
||||
|
53
vomp.c
53
vomp.c
@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "serval.h"
|
||||
#include "str.h"
|
||||
#include "conf.h"
|
||||
@ -171,7 +172,7 @@ struct vomp_call_state {
|
||||
time_ms_t create_time;
|
||||
time_ms_t last_activity;
|
||||
time_ms_t audio_clock;
|
||||
int remote_audio_clock;
|
||||
unsigned remote_audio_clock;
|
||||
|
||||
// last local & remote status we sent to all interested parties
|
||||
int last_sent_status;
|
||||
@ -184,7 +185,7 @@ struct vomp_call_state {
|
||||
This is partly to deal with denial of service attacks that might occur by causing
|
||||
the ejection of newly allocated session numbers before the caller has had a chance
|
||||
to progress the call to a further state. */
|
||||
int vomp_call_count=0;
|
||||
unsigned vomp_call_count=0;
|
||||
// TODO allocate call structures dynamically
|
||||
struct vomp_call_state vomp_call_states[VOMP_MAX_CALLS];
|
||||
struct profile_total vomp_stats;
|
||||
@ -329,9 +330,9 @@ int is_codec_set(int codec, unsigned char *flags){
|
||||
return flags[codec >> 3] & (1<<(codec & 7));
|
||||
}
|
||||
|
||||
struct vomp_call_state *vomp_find_call_by_session(int session_token)
|
||||
struct vomp_call_state *vomp_find_call_by_session(unsigned int session_token)
|
||||
{
|
||||
int i;
|
||||
unsigned i;
|
||||
for(i=0;i<vomp_call_count;i++)
|
||||
if (session_token==vomp_call_states[i].local.session)
|
||||
return &vomp_call_states[i];
|
||||
@ -340,14 +341,14 @@ struct vomp_call_state *vomp_find_call_by_session(int session_token)
|
||||
|
||||
static int vomp_generate_session_id()
|
||||
{
|
||||
int session_id=0;
|
||||
unsigned int session_id=0;
|
||||
while (!session_id)
|
||||
{
|
||||
if (urandombytes((unsigned char *)&session_id,sizeof(int)))
|
||||
if (urandombytes((unsigned char *)&session_id, sizeof session_id))
|
||||
return WHY("Insufficient entropy");
|
||||
session_id&=VOMP_SESSION_MASK;
|
||||
if (config.debug.vomp) DEBUGF("session=0x%08x",session_id);
|
||||
int i;
|
||||
unsigned i;
|
||||
/* reject duplicate call session numbers */
|
||||
for(i=0;i<vomp_call_count;i++)
|
||||
if (session_id==vomp_call_states[i].local.session
|
||||
@ -399,11 +400,10 @@ static struct vomp_call_state *vomp_find_or_create_call(struct subscriber *remot
|
||||
int sender_state,
|
||||
int recvr_state)
|
||||
{
|
||||
int i;
|
||||
struct vomp_call_state *call;
|
||||
|
||||
if (config.debug.vomp)
|
||||
DEBUGF("%d calls already in progress.",vomp_call_count);
|
||||
DEBUGF("%u calls already in progress.",vomp_call_count);
|
||||
unsigned i;
|
||||
for(i=0;i<vomp_call_count;i++)
|
||||
{
|
||||
call = &vomp_call_states[i];
|
||||
@ -697,35 +697,33 @@ static int vomp_update(struct vomp_call_state *call)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int to_absolute_value(int short_value, int reference_value){
|
||||
short_value = (reference_value & 0xFFFF0000) | short_value;
|
||||
|
||||
if (short_value + 0x8000 < reference_value)
|
||||
short_value+=0x10000;
|
||||
|
||||
if (short_value > reference_value + 0x8000)
|
||||
short_value-=0x10000;
|
||||
|
||||
return short_value;
|
||||
static uint32_t to_absolute_value(uint16_t short_value, unsigned int reference_value)
|
||||
{
|
||||
uint32_t abs_value = (reference_value & 0xFFFF0000) | short_value;
|
||||
if (abs_value + 0x8000 < reference_value)
|
||||
abs_value += 0x10000;
|
||||
if (abs_value > reference_value + 0x8000)
|
||||
abs_value -= 0x10000;
|
||||
return abs_value;
|
||||
}
|
||||
|
||||
static int vomp_process_audio(struct vomp_call_state *call, overlay_mdp_frame *mdp, time_ms_t now)
|
||||
{
|
||||
int ofs=6;
|
||||
size_t ofs=6;
|
||||
|
||||
if(ofs>=mdp->in.payload_length)
|
||||
return 0;
|
||||
|
||||
int codec=mdp->in.payload[ofs++];
|
||||
|
||||
int time = mdp->in.payload[ofs]<<8 | mdp->in.payload[ofs+1]<<0;
|
||||
uint16_t time = mdp->in.payload[ofs]<<8 | mdp->in.payload[ofs+1]<<0;
|
||||
ofs+=2;
|
||||
int sequence = mdp->in.payload[ofs]<<8 | mdp->in.payload[ofs+1]<<0;
|
||||
uint16_t sequence = mdp->in.payload[ofs]<<8 | mdp->in.payload[ofs+1]<<0;
|
||||
ofs+=2;
|
||||
|
||||
// rebuild absolute time value from short relative time.
|
||||
int decoded_time = to_absolute_value(time, call->remote_audio_clock);
|
||||
int decoded_sequence = to_absolute_value(sequence, call->remote.sequence);
|
||||
uint32_t decoded_time = to_absolute_value(time, call->remote_audio_clock);
|
||||
uint32_t decoded_sequence = to_absolute_value(sequence, call->remote.sequence);
|
||||
|
||||
if (call->remote_audio_clock < decoded_time &&
|
||||
call->remote.sequence < decoded_sequence){
|
||||
@ -733,7 +731,7 @@ static int vomp_process_audio(struct vomp_call_state *call, overlay_mdp_frame *m
|
||||
call->remote.sequence = decoded_sequence;
|
||||
}else if (call->remote_audio_clock < decoded_time ||
|
||||
call->remote.sequence < decoded_sequence){
|
||||
WARNF("Mismatch while decoding sequence and time offset (%d, %d) + (%d, %d) = (%d, %d)",
|
||||
WARNF("Mismatch while decoding sequence and time offset (%u, %u) + (%u, %u) = (%u, %u)",
|
||||
time, sequence,
|
||||
call->remote_audio_clock, call->remote.sequence,
|
||||
decoded_time, decoded_sequence);
|
||||
@ -774,11 +772,12 @@ static int vomp_call_destroy(struct vomp_call_state *call)
|
||||
DEBUGF("Destroying call %06x:%06x [%s,%s]", call->local.session, call->remote.session, call->local.did,call->remote.did);
|
||||
|
||||
/* now release the call structure */
|
||||
int i = (call - vomp_call_states);
|
||||
unsigned i = (call - vomp_call_states);
|
||||
unschedule(&call->alarm);
|
||||
call->local.session=0;
|
||||
call->remote.session=0;
|
||||
|
||||
assert(vomp_call_count > 0);
|
||||
vomp_call_count--;
|
||||
if (i!=vomp_call_count){
|
||||
unschedule(&vomp_call_states[vomp_call_count].alarm);
|
||||
|
@ -16,6 +16,35 @@
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
Portions Copyright (C) 2013 Petter Reinholdtsen
|
||||
Some rights reserved
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <stdio.h>
|
||||
@ -64,7 +93,8 @@ static void send_audio(int session_id, unsigned char *buffer, int len, int codec
|
||||
monitor_client_writeline_and_data(monitor_client_fd, buffer, len, "audio %06x %d\n", session_id, codec);
|
||||
}
|
||||
|
||||
static int remote_call(char *cmd, int argc, char **argv, unsigned char *data, int dataLen, void *context){
|
||||
static int remote_call(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsigned char *UNUSED(data), int UNUSED(dataLen), void *UNUSED(context))
|
||||
{
|
||||
int token = strtol(argv[0], NULL, 16);
|
||||
|
||||
if (call_token != -1){
|
||||
@ -82,7 +112,8 @@ static int remote_call(char *cmd, int argc, char **argv, unsigned char *data, in
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int remote_ringing(char *cmd, int argc, char **argv, unsigned char *data, int dataLen, void *context){
|
||||
static int remote_ringing(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsigned char *UNUSED(data), int UNUSED(dataLen), void *UNUSED(context))
|
||||
{
|
||||
int token = strtol(argv[0], NULL, 16);
|
||||
if (call_token == token){
|
||||
printf("They're ringing\n");
|
||||
@ -92,7 +123,8 @@ static int remote_ringing(char *cmd, int argc, char **argv, unsigned char *data,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int remote_pickup(char *cmd, int argc, char **argv, unsigned char *data, int dataLen, void *context){
|
||||
static int remote_pickup(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsigned char *UNUSED(data), int UNUSED(dataLen), void *UNUSED(context))
|
||||
{
|
||||
int token = strtol(argv[0], NULL, 16);
|
||||
if (call_token == token){
|
||||
printf("They've picked up\n");
|
||||
@ -102,7 +134,8 @@ static int remote_pickup(char *cmd, int argc, char **argv, unsigned char *data,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int remote_dialing(char *cmd, int argc, char **argv, unsigned char *data, int dataLen, void *context){
|
||||
static int remote_dialing(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsigned char *UNUSED(data), int UNUSED(dataLen), void *UNUSED(context))
|
||||
{
|
||||
int token = strtol(argv[0], NULL, 16);
|
||||
if (call_token == -1){
|
||||
call_token=token;
|
||||
@ -114,7 +147,8 @@ static int remote_dialing(char *cmd, int argc, char **argv, unsigned char *data,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int remote_hangup(char *cmd, int argc, char **argv, unsigned char *data, int dataLen, void *context){
|
||||
static int remote_hangup(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsigned char *UNUSED(data), int UNUSED(dataLen), void *UNUSED(context))
|
||||
{
|
||||
int token = strtol(argv[0], NULL, 16);
|
||||
if (call_token == token){
|
||||
printf("Call ended\n");
|
||||
@ -124,7 +158,8 @@ static int remote_hangup(char *cmd, int argc, char **argv, unsigned char *data,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int remote_audio(char *cmd, int argc, char **argv, unsigned char *data, int dataLen, void *context){
|
||||
static int remote_audio(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsigned char *UNUSED(data), int UNUSED(dataLen), void *UNUSED(context))
|
||||
{
|
||||
int token = strtol(argv[0], NULL, 16);
|
||||
if (call_token == token){
|
||||
int codec = strtol(argv[1], NULL, 10);
|
||||
@ -142,7 +177,8 @@ static int remote_audio(char *cmd, int argc, char **argv, unsigned char *data, i
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int remote_codecs(char *cmd, int argc, char **argv, unsigned char *data, int dataLen, void *context){
|
||||
static int remote_codecs(char *UNUSED(cmd), int UNUSED(argc), char **argv, unsigned char *UNUSED(data), int UNUSED(dataLen), void *UNUSED(context))
|
||||
{
|
||||
int token = strtol(argv[0], NULL, 16);
|
||||
if (call_token == token){
|
||||
int i;
|
||||
@ -156,7 +192,8 @@ static int remote_codecs(char *cmd, int argc, char **argv, unsigned char *data,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int remote_print(char *cmd, int argc, char **argv, unsigned char *data, int dataLen, void *context){
|
||||
static int remote_print(char *cmd, int argc, char **argv, unsigned char *data, int dataLen, void *UNUSED(context))
|
||||
{
|
||||
int i;
|
||||
printf("%s",cmd);
|
||||
for (i=0;i<argc;i++){
|
||||
@ -170,7 +207,8 @@ static int remote_print(char *cmd, int argc, char **argv, unsigned char *data, i
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int remote_noop(char *cmd, int argc, char **argv, unsigned char *data, int dataLen, void *context){
|
||||
static int remote_noop(char *UNUSED(cmd), int UNUSED(argc), char **UNUSED(argv), unsigned char *UNUSED(data), int UNUSED(dataLen), void *UNUSED(context))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -188,7 +226,7 @@ struct monitor_command_handler console_handlers[]={
|
||||
{.command="MONITORSTATUS", .handler=remote_noop},
|
||||
};
|
||||
|
||||
static int console_dial(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
static int console_dial(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (call_token!=-1){
|
||||
printf("Already in a call\n");
|
||||
@ -201,7 +239,7 @@ static int console_dial(const struct cli_parsed *parsed, struct cli_context *con
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int console_answer(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
static int console_answer(const struct cli_parsed *UNUSED(parsed), struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (call_token==-1){
|
||||
printf("No active call to answer\n");
|
||||
@ -211,7 +249,7 @@ static int console_answer(const struct cli_parsed *parsed, struct cli_context *c
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int console_hangup(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
static int console_hangup(const struct cli_parsed *UNUSED(parsed), struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (call_token==-1){
|
||||
printf("No call to hangup\n");
|
||||
@ -221,7 +259,7 @@ static int console_hangup(const struct cli_parsed *parsed, struct cli_context *c
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int console_audio(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
static int console_audio(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (call_token==-1){
|
||||
printf("No active call\n");
|
||||
@ -229,8 +267,8 @@ static int console_audio(const struct cli_parsed *parsed, struct cli_context *co
|
||||
}else{
|
||||
static char buf[256];
|
||||
static struct strbuf str_buf = STRUCT_STRBUF_EMPTY;
|
||||
int i;
|
||||
strbuf_init(&str_buf, buf, sizeof(buf));
|
||||
unsigned i;
|
||||
for (i = 0; i < parsed->argc; ++i) {
|
||||
if (i)
|
||||
strbuf_putc(&str_buf, ' ');
|
||||
@ -253,10 +291,10 @@ struct cli_schema console_commands[]={
|
||||
{console_hangup,{"hangup",NULL},0,"Hangup the phone line"},
|
||||
{console_usage,{"help",NULL},0,"This usage message"},
|
||||
{console_audio,{"say","...",NULL},0,"Send a text string to the other party"},
|
||||
{NULL},
|
||||
{NULL, {NULL, NULL, NULL}, 0, NULL},
|
||||
};
|
||||
|
||||
static int console_usage(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
static int console_usage(const struct cli_parsed *UNUSED(parsed), struct cli_context *UNUSED(context))
|
||||
{
|
||||
cli_usage(console_commands, XPRINTF_STDIO(stdout));
|
||||
fflush(stdout);
|
||||
@ -324,7 +362,7 @@ static void monitor_read(struct sched_ent *alarm){
|
||||
}
|
||||
}
|
||||
|
||||
int app_vomp_console(const struct cli_parsed *parsed, struct cli_context *context)
|
||||
int app_vomp_console(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
|
||||
{
|
||||
if (config.debug.verbose)
|
||||
DEBUG_cli_parsed(parsed);
|
||||
@ -332,17 +370,19 @@ int app_vomp_console(const struct cli_parsed *parsed, struct cli_context *contex
|
||||
.name="read_lines",
|
||||
};
|
||||
struct line_state stdin_state={
|
||||
.alarm.poll.fd = STDIN_FILENO,
|
||||
.alarm.poll.events = POLLIN,
|
||||
.alarm.function = read_lines,
|
||||
.alarm.stats=&stdin_profile,
|
||||
.alarm = {
|
||||
.poll = {.fd = STDIN_FILENO,.events = POLLIN},
|
||||
.function = read_lines,
|
||||
.stats=&stdin_profile
|
||||
},
|
||||
.fd=0,
|
||||
.process_line=console_command,
|
||||
};
|
||||
static struct profile_total monitor_profile={
|
||||
.name="monitor_read",
|
||||
};
|
||||
struct sched_ent monitor_alarm={
|
||||
.poll.events = POLLIN,
|
||||
.poll = {.fd = STDIN_FILENO,.events = POLLIN},
|
||||
.function = monitor_read,
|
||||
.stats=&monitor_profile,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user