Merge branch 'newconfig' into 'master'

This commit is contained in:
Andrew Bettison 2012-12-11 17:21:56 +10:30
commit 7d970d8f92
43 changed files with 408 additions and 475 deletions

View File

@ -208,7 +208,7 @@ int parseCommandLine(const char *argv0, int argc, const char *const *args)
rhizome_close_db(); rhizome_close_db();
OUT(); OUT();
if (debug&DEBUG_TIMING) if (config.debug.timing)
fd_showstats(); fd_showstats();
return result; return result;
} }
@ -335,7 +335,7 @@ void cli_flush()
int app_echo(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_echo(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
int i = 1; int i = 1;
int escapes = 0; int escapes = 0;
if (i < argc && strcmp(argv[i], "-e") == 0) { if (i < argc && strcmp(argv[i], "-e") == 0) {
@ -343,7 +343,7 @@ int app_echo(int argc, const char *const *argv, const struct command_line_option
++i; ++i;
} }
for (; i < argc; ++i) { for (; i < argc; ++i) {
if (debug & DEBUG_VERBOSE) if (config.debug.verbose)
DEBUGF("echo:argv[%d]=\"%s\"", i, argv[i]); DEBUGF("echo:argv[%d]=\"%s\"", i, argv[i]);
if (escapes) { if (escapes) {
unsigned char buf[strlen(argv[i])]; unsigned char buf[strlen(argv[i])];
@ -398,7 +398,7 @@ void lookup_send_request(unsigned char *srcsid, int srcport, unsigned char *dsts
int app_dna_lookup(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_dna_lookup(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
/* Create the instance directory if it does not yet exist */ /* Create the instance directory if it does not yet exist */
if (create_serval_instance_dir() == -1) if (create_serval_instance_dir() == -1)
@ -515,7 +515,7 @@ int app_dna_lookup(int argc, const char *const *argv, const struct command_line_
int app_server_start(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_server_start(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
/* Process optional arguments */ /* Process optional arguments */
int pid=-1; int pid=-1;
int cpid=-1; int cpid=-1;
@ -691,7 +691,7 @@ int app_server_start(int argc, const char *const *argv, const struct command_lin
int app_server_stop(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_server_stop(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
int pid, tries, running; int pid, tries, running;
const char *instancepath; const char *instancepath;
time_ms_t timeout; time_ms_t timeout;
@ -752,7 +752,7 @@ int app_server_stop(int argc, const char *const *argv, const struct command_line
int app_server_status(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_server_status(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
int pid; int pid;
const char *instancepath; const char *instancepath;
if (cli_arg(argc, argv, o, "instance path", &instancepath, cli_absolute_path, NULL) == -1) if (cli_arg(argc, argv, o, "instance path", &instancepath, cli_absolute_path, NULL) == -1)
@ -779,7 +779,7 @@ int app_server_status(int argc, const char *const *argv, const struct command_li
int app_mdp_ping(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_mdp_ping(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
const char *sid, *count; const char *sid, *count;
if (cli_arg(argc, argv, o, "SID|broadcast", &sid, str_is_subscriber_id, "broadcast") == -1) if (cli_arg(argc, argv, o, "SID|broadcast", &sid, str_is_subscriber_id, "broadcast") == -1)
return -1; return -1;
@ -926,7 +926,7 @@ int app_mdp_ping(int argc, const char *const *argv, const struct command_line_op
int app_config_schema(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_config_schema(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
if (create_serval_instance_dir() == -1) if (create_serval_instance_dir() == -1)
return -1; return -1;
struct cf_om_node *root = NULL; struct cf_om_node *root = NULL;
@ -946,7 +946,7 @@ int app_config_schema(int argc, const char *const *argv, const struct command_li
int app_config_set(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_config_set(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
if (create_serval_instance_dir() == -1) if (create_serval_instance_dir() == -1)
return -1; return -1;
// <kludge> // <kludge>
@ -999,7 +999,7 @@ int app_config_set(int argc, const char *const *argv, const struct command_line_
int app_config_get(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_config_get(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
const char *var; const char *var;
if (cli_arg(argc, argv, o, "variable", &var, is_configvarpattern, NULL) == -1) if (cli_arg(argc, argv, o, "variable", &var, is_configvarpattern, NULL) == -1)
return -1; return -1;
@ -1033,7 +1033,7 @@ int app_config_get(int argc, const char *const *argv, const struct command_line_
int app_rhizome_hash_file(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_rhizome_hash_file(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
/* compute hash of file. We do this without a manifest, so it will necessarily /* compute hash of file. We do this without a manifest, so it will necessarily
return the hash of the file unencrypted. */ return the hash of the file unencrypted. */
const char *filepath; const char *filepath;
@ -1048,7 +1048,7 @@ int app_rhizome_hash_file(int argc, const char *const *argv, const struct comman
int app_rhizome_add_file(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_rhizome_add_file(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
const char *filepath, *manifestpath, *authorSidHex, *pin, *bskhex; const char *filepath, *manifestpath, *authorSidHex, *pin, *bskhex;
cli_arg(argc, argv, o, "filepath", &filepath, NULL, ""); cli_arg(argc, argv, o, "filepath", &filepath, NULL, "");
if (cli_arg(argc, argv, o, "author_sid", &authorSidHex, cli_optional_sid, "") == -1) if (cli_arg(argc, argv, o, "author_sid", &authorSidHex, cli_optional_sid, "") == -1)
@ -1075,7 +1075,7 @@ int app_rhizome_add_file(int argc, const char *const *argv, const struct command
if (!m) if (!m)
return WHY("Manifest struct could not be allocated -- not added to rhizome"); return WHY("Manifest struct could not be allocated -- not added to rhizome");
if (manifestpath[0] && access(manifestpath, R_OK) == 0) { if (manifestpath[0] && access(manifestpath, R_OK) == 0) {
if (debug & DEBUG_RHIZOME) DEBUGF("reading manifest from %s", manifestpath); if (config.debug.rhizome) DEBUGF("reading manifest from %s", manifestpath);
/* Don't verify the manifest, because it will fail if it is incomplete. /* Don't verify the manifest, because it will fail if it is incomplete.
This is okay, because we fill in any missing bits and sanity check before This is okay, because we fill in any missing bits and sanity check before
trying to write it out. */ trying to write it out. */
@ -1084,7 +1084,7 @@ int app_rhizome_add_file(int argc, const char *const *argv, const struct command
return WHY("Manifest file could not be loaded -- not added to rhizome"); return WHY("Manifest file could not be loaded -- not added to rhizome");
} }
} else { } else {
if (debug & DEBUG_RHIZOME) DEBUGF("manifest file %s does not exist -- creating new manifest", manifestpath); if (config.debug.rhizome) DEBUGF("manifest file %s does not exist -- creating new manifest", manifestpath);
} }
/* Fill in a few missing manifest fields, to make it easier to use when adding new files: /* Fill in a few missing manifest fields, to make it easier to use when adding new files:
- the default service is FILE - the default service is FILE
@ -1094,13 +1094,13 @@ int app_rhizome_add_file(int argc, const char *const *argv, const struct command
const char *service = rhizome_manifest_get(m, "service", NULL, 0); const char *service = rhizome_manifest_get(m, "service", NULL, 0);
if (service == NULL) { if (service == NULL) {
rhizome_manifest_set(m, "service", (service = RHIZOME_SERVICE_FILE)); rhizome_manifest_set(m, "service", (service = RHIZOME_SERVICE_FILE));
if (debug & DEBUG_RHIZOME) DEBUGF("missing 'service', set default service=%s", service); if (config.debug.rhizome) DEBUGF("missing 'service', set default service=%s", service);
} else { } else {
if (debug & DEBUG_RHIZOME) DEBUGF("manifest contains service=%s", service); if (config.debug.rhizome) DEBUGF("manifest contains service=%s", service);
} }
if (rhizome_manifest_get(m, "date", NULL, 0) == NULL) { if (rhizome_manifest_get(m, "date", NULL, 0) == NULL) {
rhizome_manifest_set_ll(m, "date", (long long) gettime_ms()); rhizome_manifest_set_ll(m, "date", (long long) gettime_ms());
if (debug & DEBUG_RHIZOME) DEBUGF("missing 'date', set default date=%s", rhizome_manifest_get(m, "date", NULL, 0)); if (config.debug.rhizome) DEBUGF("missing 'date', set default date=%s", rhizome_manifest_get(m, "date", NULL, 0));
} }
if (strcasecmp(RHIZOME_SERVICE_FILE, service) == 0) { if (strcasecmp(RHIZOME_SERVICE_FILE, service) == 0) {
const char *name = rhizome_manifest_get(m, "name", NULL, 0); const char *name = rhizome_manifest_get(m, "name", NULL, 0);
@ -1108,9 +1108,9 @@ int app_rhizome_add_file(int argc, const char *const *argv, const struct command
name = strrchr(filepath, '/'); name = strrchr(filepath, '/');
name = name ? name + 1 : filepath; name = name ? name + 1 : filepath;
rhizome_manifest_set(m, "name", name); rhizome_manifest_set(m, "name", name);
if (debug & DEBUG_RHIZOME) DEBUGF("missing 'name', set default name=\"%s\"", name); if (config.debug.rhizome) DEBUGF("missing 'name', set default name=\"%s\"", name);
} else { } else {
if (debug & DEBUG_RHIZOME) DEBUGF("manifest contains name=\"%s\"", name); if (config.debug.rhizome) DEBUGF("manifest contains name=\"%s\"", name);
} }
} }
/* If the author was not specified on the command-line, then the manifest's "sender" /* If the author was not specified on the command-line, then the manifest's "sender"
@ -1124,18 +1124,18 @@ int app_rhizome_add_file(int argc, const char *const *argv, const struct command
/* Bind an ID to the manifest, and also bind the file. Then finalise the manifest. /* Bind an ID to the manifest, and also bind the file. Then finalise the manifest.
But if the manifest already contains an ID, don't override it. */ But if the manifest already contains an ID, don't override it. */
if (authorSidHex[0]) { if (authorSidHex[0]) {
if (debug & DEBUG_RHIZOME) DEBUGF("author=%s", authorSidHex); if (config.debug.rhizome) DEBUGF("author=%s", authorSidHex);
memcpy(m->author, authorSid, SID_SIZE); memcpy(m->author, authorSid, SID_SIZE);
} }
const char *id = rhizome_manifest_get(m, "id", NULL, 0); const char *id = rhizome_manifest_get(m, "id", NULL, 0);
if (id == NULL) { if (id == NULL) {
if (debug & DEBUG_RHIZOME) DEBUG("creating new bundle"); if (config.debug.rhizome) DEBUG("creating new bundle");
if (rhizome_manifest_bind_id(m) == -1) { if (rhizome_manifest_bind_id(m) == -1) {
rhizome_manifest_free(m); rhizome_manifest_free(m);
return WHY("Could not bind manifest to an ID"); return WHY("Could not bind manifest to an ID");
} }
} else { } else {
if (debug & DEBUG_RHIZOME) DEBUGF("modifying existing bundle bid=%s", id); if (config.debug.rhizome) DEBUGF("modifying existing bundle bid=%s", id);
// Modifying an existing bundle. If an author SID is supplied, we must ensure that it is valid, // Modifying an existing bundle. If an author SID is supplied, we must ensure that it is valid,
// ie, that identity has permission to alter the bundle. If no author SID is supplied but a BSK // ie, that identity has permission to alter the bundle. If no author SID is supplied but a BSK
// is supplied, then use that to alter the bundle. Otherwise, search the keyring for an // is supplied, then use that to alter the bundle. Otherwise, search the keyring for an
@ -1170,7 +1170,7 @@ int app_rhizome_add_file(int argc, const char *const *argv, const struct command
} }
} }
if (bskhex[0]) { if (bskhex[0]) {
if (debug & DEBUG_RHIZOME) DEBUGF("bskhex=%s", bskhex); if (config.debug.rhizome) DEBUGF("bskhex=%s", bskhex);
if (m->haveSecret) { if (m->haveSecret) {
// If a bundle secret key was supplied that does not match the secret key derived from the // If a bundle secret key was supplied that does not match the secret key derived from the
// author, then warn but carry on using the author's. // author, then warn but carry on using the author's.
@ -1189,7 +1189,7 @@ int app_rhizome_add_file(int argc, const char *const *argv, const struct command
} }
// If we still don't know the bundle secret or the author, then search for an author. // If we still don't know the bundle secret or the author, then search for an author.
if (!m->haveSecret && is_sid_any(m->author)) { if (!m->haveSecret && is_sid_any(m->author)) {
if (debug & DEBUG_RHIZOME) DEBUG("bundle author not specified, searching keyring"); if (config.debug.rhizome) DEBUG("bundle author not specified, searching keyring");
int result = rhizome_find_bundle_author(m); int result = rhizome_find_bundle_author(m);
if (result != 0) { if (result != 0) {
rhizome_manifest_free(m); rhizome_manifest_free(m);
@ -1288,7 +1288,7 @@ int app_rhizome_add_file(int argc, const char *const *argv, const struct command
int app_rhizome_import_bundle(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_rhizome_import_bundle(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
const char *filepath, *manifestpath; const char *filepath, *manifestpath;
cli_arg(argc, argv, o, "filepath", &filepath, NULL, ""); cli_arg(argc, argv, o, "filepath", &filepath, NULL, "");
cli_arg(argc, argv, o, "manifestpath", &manifestpath, NULL, ""); cli_arg(argc, argv, o, "manifestpath", &manifestpath, NULL, "");
@ -1300,7 +1300,7 @@ int app_rhizome_import_bundle(int argc, const char *const *argv, const struct co
int app_rhizome_extract_manifest(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_rhizome_extract_manifest(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
const char *pins, *manifestid, *manifestpath; const char *pins, *manifestid, *manifestpath;
cli_arg(argc, argv, o, "pin,pin...", &pins, NULL, ""); cli_arg(argc, argv, o, "pin,pin...", &pins, NULL, "");
if (cli_arg(argc, argv, o, "manifestid", &manifestid, cli_manifestid, NULL) if (cli_arg(argc, argv, o, "manifestid", &manifestid, cli_manifestid, NULL)
@ -1344,7 +1344,7 @@ int app_rhizome_extract_manifest(int argc, const char *const *argv, const struct
int app_rhizome_extract_file(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_rhizome_extract_file(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
const char *fileid, *filepath, *keyhex; const char *fileid, *filepath, *keyhex;
if (cli_arg(argc, argv, o, "fileid", &fileid, cli_fileid, NULL) if (cli_arg(argc, argv, o, "fileid", &fileid, cli_fileid, NULL)
|| cli_arg(argc, argv, o, "filepath", &filepath, NULL, "") == -1) || cli_arg(argc, argv, o, "filepath", &filepath, NULL, "") == -1)
@ -1374,7 +1374,7 @@ int app_rhizome_extract_file(int argc, const char *const *argv, const struct com
int app_rhizome_list(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_rhizome_list(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
const char *pins, *service, *sender_sid, *recipient_sid, *offset, *limit; const char *pins, *service, *sender_sid, *recipient_sid, *offset, *limit;
cli_arg(argc, argv, o, "pin,pin...", &pins, NULL, ""); cli_arg(argc, argv, o, "pin,pin...", &pins, NULL, "");
cli_arg(argc, argv, o, "service", &service, NULL, ""); cli_arg(argc, argv, o, "service", &service, NULL, "");
@ -1394,7 +1394,7 @@ int app_rhizome_list(int argc, const char *const *argv, const struct command_lin
int app_keyring_create(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_keyring_create(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
const char *pin; const char *pin;
cli_arg(argc, argv, o, "pin,pin...", &pin, NULL, ""); cli_arg(argc, argv, o, "pin,pin...", &pin, NULL, "");
if (!keyring_open_with_pins(pin)) if (!keyring_open_with_pins(pin))
@ -1404,7 +1404,7 @@ int app_keyring_create(int argc, const char *const *argv, const struct command_l
int app_keyring_list(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_keyring_list(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
const char *pins; const char *pins;
cli_arg(argc, argv, o, "pin,pin...", &pins, NULL, ""); cli_arg(argc, argv, o, "pin,pin...", &pins, NULL, "");
keyring_file *k = keyring_open_with_pins(pins); keyring_file *k = keyring_open_with_pins(pins);
@ -1431,7 +1431,7 @@ int app_keyring_list(int argc, const char *const *argv, const struct command_lin
int app_keyring_add(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_keyring_add(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
const char *pin; const char *pin;
cli_arg(argc, argv, o, "pin", &pin, NULL, ""); cli_arg(argc, argv, o, "pin", &pin, NULL, "");
keyring_file *k = keyring_open_with_pins(""); keyring_file *k = keyring_open_with_pins("");
@ -1476,7 +1476,7 @@ int app_keyring_add(int argc, const char *const *argv, const struct command_line
int app_keyring_set_did(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_keyring_set_did(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
const char *sid, *did, *pin, *name; const char *sid, *did, *pin, *name;
cli_arg(argc, argv, o, "sid", &sid, str_is_subscriber_id, ""); cli_arg(argc, argv, o, "sid", &sid, str_is_subscriber_id, "");
cli_arg(argc, argv, o, "did", &did, cli_optional_did, ""); cli_arg(argc, argv, o, "did", &did, cli_optional_did, "");
@ -1505,7 +1505,7 @@ int app_keyring_set_did(int argc, const char *const *argv, const struct command_
int app_id_self(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_id_self(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
/* List my own identities */ /* List my own identities */
overlay_mdp_frame a; overlay_mdp_frame a;
bzero(&a, sizeof(overlay_mdp_frame)); bzero(&a, sizeof(overlay_mdp_frame));
@ -1569,7 +1569,7 @@ int app_count_peers(int argc, const char *const *argv, const struct command_line
int app_crypt_test(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_crypt_test(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
unsigned char nonce[crypto_box_curve25519xsalsa20poly1305_NONCEBYTES]; unsigned char nonce[crypto_box_curve25519xsalsa20poly1305_NONCEBYTES];
unsigned char k[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES]; unsigned char k[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES];
@ -1732,7 +1732,7 @@ int app_crypt_test(int argc, const char *const *argv, const struct command_line_
int app_node_info(int argc, const char *const *argv, const struct command_line_option *o, void *context) int app_node_info(int argc, const char *const *argv, const struct command_line_option *o, void *context)
{ {
if (debug & DEBUG_VERBOSE) DEBUG_argv("command", argc, argv); if (config.debug.verbose) DEBUG_argv("command", argc, argv);
const char *sid; const char *sid;
cli_arg(argc, argv, o, "sid", &sid, NULL, ""); cli_arg(argc, argv, o, "sid", &sid, NULL, "");

2
conf.c
View File

@ -179,7 +179,6 @@ int cf_init()
cf_limbo = 1; cf_limbo = 1;
if (cf_dfl_config_main(&config) == CFERROR) if (cf_dfl_config_main(&config) == CFERROR)
return -1; return -1;
debug = config.debug;
return 0; return 0;
} }
@ -211,7 +210,6 @@ static int load_and_parse(int permissive)
} }
} }
} }
debug = config.debug;
if (result == CFOK) if (result == CFOK)
return 0; return 0;
cf_limbo = 0; // let log messages out cf_limbo = 0; // let log messages out

4
conf.h
View File

@ -534,9 +534,9 @@ struct pattern_list {
#undef VALUE_NODE_STRUCT #undef VALUE_NODE_STRUCT
#undef END_ARRAY #undef END_ARRAY
int cf_opt_boolean(int *booleanp, const char *text); int cf_opt_char_boolean(char *booleanp, const char *text);
int cf_opt_int_boolean(int *booleanp, const char *text);
int cf_opt_absolute_path(char *str, size_t len, const char *text); int cf_opt_absolute_path(char *str, size_t len, const char *text);
int cf_opt_debugflags(debugflags_t *flagsp, const struct cf_om_node *node);
int cf_opt_rhizome_peer(struct config_rhizome_peer *, const struct cf_om_node *node); int cf_opt_rhizome_peer(struct config_rhizome_peer *, const struct cf_om_node *node);
int cf_opt_rhizome_peer_from_uri(struct config_rhizome_peer *, const char *uri); int cf_opt_rhizome_peer_from_uri(struct config_rhizome_peer *, const char *uri);
int cf_opt_str(char *str, size_t len, const char *text); int cf_opt_str(char *str, size_t len, const char *text);

View File

@ -32,7 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "strbuf_helpers.h" #include "strbuf_helpers.h"
#include "conf.h" #include "conf.h"
int cf_opt_boolean(int *booleanp, const char *text) int cf_opt_char_boolean(char *booleanp, const char *text)
{ {
if (!strcasecmp(text, "true") || !strcasecmp(text, "yes") || !strcasecmp(text, "on") || !strcasecmp(text, "1")) { if (!strcasecmp(text, "true") || !strcasecmp(text, "yes") || !strcasecmp(text, "on") || !strcasecmp(text, "1")) {
*booleanp = 1; *booleanp = 1;
@ -45,6 +45,15 @@ int cf_opt_boolean(int *booleanp, const char *text)
return CFINVALID; return CFINVALID;
} }
int cf_opt_int_boolean(int *booleanp, const char *text)
{
char b;
int ret = cf_opt_char_boolean(&b, text);
if (ret == CFOK)
*booleanp = b;
return ret;
}
int cf_opt_absolute_path(char *str, size_t len, const char *text) int cf_opt_absolute_path(char *str, size_t len, const char *text)
{ {
if (text[0] != '/') if (text[0] != '/')
@ -56,57 +65,6 @@ int cf_opt_absolute_path(char *str, size_t len, const char *text)
return CFOK; return CFOK;
} }
int cf_opt_debugflags(debugflags_t *flagsp, const struct cf_om_node *node)
{
//DEBUGF("%s", __FUNCTION__);
//cf_dump_node(node, 1);
debugflags_t setmask = 0;
debugflags_t clearmask = 0;
int setall = 0;
int clearall = 0;
int result = CFEMPTY;
int i;
for (i = 0; i < node->nodc; ++i) {
const struct cf_om_node *child = node->nodv[i];
cf_warn_unsupported_children(child);
debugflags_t mask = debugFlagMask(child->key);
int flag = -1;
if (!mask)
cf_warn_unsupported_node(child);
else if (child->text) {
int ret = cf_opt_boolean(&flag, child->text);
switch (ret) {
case CFERROR: return CFERROR;
case CFOK:
result &= ~CFEMPTY;
if (mask == ~0) {
if (flag)
setall = 1;
else
clearall = 1;
} else {
if (flag)
setmask |= mask;
else
clearmask |= mask;
}
break;
default:
cf_warn_node_value(child, ret);
result |= ret;
break;
}
}
}
if (setall)
*flagsp = ~0;
else if (clearall)
*flagsp = 0;
*flagsp &= ~clearmask;
*flagsp |= setmask;
return result;
}
int cf_opt_protocol(char *str, size_t len, const char *text) int cf_opt_protocol(char *str, size_t len, const char *text)
{ {
if (!str_is_uri_scheme(text)) if (!str_is_uri_scheme(text))

View File

@ -178,16 +178,47 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* @author Andrew Bettison <andrew@servalproject.com> * @author Andrew Bettison <andrew@servalproject.com>
*/ */
STRUCT(debug)
ATOM(char, verbose, 0, cf_opt_char_boolean,, "")
ATOM(char, dnaresponses, 0, cf_opt_char_boolean,, "")
ATOM(char, dnahelper, 0, cf_opt_char_boolean,, "")
ATOM(char, queues, 0, cf_opt_char_boolean,, "")
ATOM(char, timing, 0, cf_opt_char_boolean,, "")
ATOM(char, io, 0, cf_opt_char_boolean,, "")
ATOM(char, verbose_io, 0, cf_opt_char_boolean,, "")
ATOM(char, packetformats, 0, cf_opt_char_boolean,, "")
ATOM(char, gateway, 0, cf_opt_char_boolean,, "")
ATOM(char, keyring, 0, cf_opt_char_boolean,, "")
ATOM(char, security, 0, cf_opt_char_boolean,, "")
ATOM(char, mdprequests, 0, cf_opt_char_boolean,, "")
ATOM(char, peers, 0, cf_opt_char_boolean,, "")
ATOM(char, overlayframes, 0, cf_opt_char_boolean,, "")
ATOM(char, overlayabbreviations, 0, cf_opt_char_boolean,, "")
ATOM(char, overlayrouting, 0, cf_opt_char_boolean,, "")
ATOM(char, overlayroutemonitor, 0, cf_opt_char_boolean,, "")
ATOM(char, overlayinterfaces, 0, cf_opt_char_boolean,, "")
ATOM(char, broadcasts, 0, cf_opt_char_boolean,, "")
ATOM(char, packettx, 0, cf_opt_char_boolean,, "")
ATOM(char, packetrx, 0, cf_opt_char_boolean,, "")
ATOM(char, packetconstruction, 0, cf_opt_char_boolean,, "")
ATOM(char, rhizome, 0, cf_opt_char_boolean,, "")
ATOM(char, rhizome_tx, 0, cf_opt_char_boolean,, "")
ATOM(char, rhizome_rx, 0, cf_opt_char_boolean,, "")
ATOM(char, rhizome_ads, 0, cf_opt_char_boolean,, "")
ATOM(char, manifests, 0, cf_opt_char_boolean,, "")
ATOM(char, vomp, 0, cf_opt_char_boolean,, "")
END_STRUCT
STRUCT(log) STRUCT(log)
STRING(256, file, "", cf_opt_absolute_path,, "Absolute path of log file") STRING(256, file, "", cf_opt_absolute_path,, "Absolute path of log file")
ATOM(int, show_pid, 1, cf_opt_boolean,, "If true, all log lines contain PID of logging process") ATOM(int, show_pid, 1, cf_opt_int_boolean,, "If true, all log lines contain PID of logging process")
ATOM(int, show_time, 1, cf_opt_boolean,, "If true, all log lines contain time stamp") ATOM(int, show_time, 1, cf_opt_int_boolean,, "If true, all log lines contain time stamp")
END_STRUCT END_STRUCT
STRUCT(server) STRUCT(server)
STRING(256, chdir, "/", cf_opt_absolute_path,, "Absolute path of chdir(2) for server process") STRING(256, chdir, "/", cf_opt_absolute_path,, "Absolute path of chdir(2) for server process")
STRING(256, dummy_interface_dir, "", cf_opt_str_nonempty,, "Path of directory containing dummy interface files, either absolute or relative to instance directory") STRING(256, dummy_interface_dir, "", cf_opt_str_nonempty,, "Path of directory containing dummy interface files, either absolute or relative to instance directory")
ATOM(int, respawn_on_crash, 0, cf_opt_boolean,, "If true, server will exec(2) itself on fatal signals, eg SEGV") ATOM(int, respawn_on_crash, 0, cf_opt_int_boolean,, "If true, server will exec(2) itself on fatal signals, eg SEGV")
END_STRUCT END_STRUCT
STRUCT(monitor) STRUCT(monitor)
@ -210,7 +241,7 @@ SUB_STRUCT(mdp_iftypelist, iftype,)
END_STRUCT END_STRUCT
STRUCT(olsr) STRUCT(olsr)
ATOM(int, enable, 1, cf_opt_boolean,, "If true, OLSR is used for mesh routing") ATOM(int, enable, 1, cf_opt_int_boolean,, "If true, OLSR is used for mesh routing")
ATOM(uint16_t, remote_port,4130, cf_opt_uint16_nonzero,, "Remote port number") ATOM(uint16_t, remote_port,4130, cf_opt_uint16_nonzero,, "Remote port number")
ATOM(uint16_t, local_port, 4131, cf_opt_uint16_nonzero,, "Local port number") ATOM(uint16_t, local_port, 4131, cf_opt_uint16_nonzero,, "Local port number")
END_STRUCT END_STRUCT
@ -257,19 +288,19 @@ SUB_STRUCT(rhizome_api_addfile, addfile,)
END_STRUCT END_STRUCT
STRUCT(rhizome_http) STRUCT(rhizome_http)
ATOM(int, enable, 1, cf_opt_boolean,, "If true, Rhizome HTTP server is started") ATOM(int, enable, 1, cf_opt_int_boolean,, "If true, Rhizome HTTP server is started")
END_STRUCT END_STRUCT
STRUCT(rhizome_mdp) STRUCT(rhizome_mdp)
ATOM(int, enable, 1, cf_opt_boolean,, "If true, Rhizome MDP server is started") ATOM(int, enable, 1, cf_opt_int_boolean,, "If true, Rhizome MDP server is started")
END_STRUCT END_STRUCT
STRUCT(rhizome_advertise) STRUCT(rhizome_advertise)
ATOM(int, enable, 1, cf_opt_boolean,, "If true, Rhizome advertisements are sent") ATOM(int, enable, 1, cf_opt_int_boolean,, "If true, Rhizome advertisements are sent")
END_STRUCT END_STRUCT
STRUCT(rhizome) STRUCT(rhizome)
ATOM(int, enable, 1, cf_opt_boolean,, "If true, server opens Rhizome database when starting") ATOM(int, enable, 1, cf_opt_int_boolean,, "If true, server opens Rhizome database when starting")
STRING(256, datastore_path, "", cf_opt_absolute_path,, "Path of rhizome storage directory, absolute or relative to instance directory") STRING(256, datastore_path, "", cf_opt_absolute_path,, "Path of rhizome storage directory, absolute or relative to instance directory")
ATOM(uint64_t, database_size, 1000000, cf_opt_uint64_scaled,, "Size of database in bytes") ATOM(uint64_t, database_size, 1000000, cf_opt_uint64_scaled,, "Size of database in bytes")
ATOM(uint32_t, fetch_delay_ms, 50, cf_opt_uint32_nonzero,, "Delay from receiving first bundle advert to initiating fetch") ATOM(uint32_t, fetch_delay_ms, 50, cf_opt_uint32_nonzero,, "Delay from receiving first bundle advert to initiating fetch")
@ -297,17 +328,17 @@ VALUE_SUB_STRUCT(host)
END_ARRAY(32) END_ARRAY(32)
STRUCT(network_interface, vld_network_interface) STRUCT(network_interface, vld_network_interface)
ATOM(int, exclude, 0, cf_opt_boolean,, "If true, do not use matching interfaces") ATOM(int, exclude, 0, cf_opt_int_boolean,, "If true, do not use matching interfaces")
ATOM(struct pattern_list, match, PATTERN_LIST_EMPTY, cf_opt_pattern_list,, "Names that match network interface") ATOM(struct pattern_list, match, PATTERN_LIST_EMPTY, cf_opt_pattern_list,, "Names that match network interface")
STRING(256, dummy, "", cf_opt_str_nonempty,, "Path of dummy file, absolute or relative to server.dummy_interface_dir") STRING(256, dummy, "", cf_opt_str_nonempty,, "Path of dummy file, absolute or relative to server.dummy_interface_dir")
ATOM(struct in_addr, dummy_address, (struct in_addr){htonl(0x7F000001)}, cf_opt_in_addr,, "Dummy interface address") ATOM(struct in_addr, dummy_address, (struct in_addr){htonl(0x7F000001)}, cf_opt_in_addr,, "Dummy interface address")
ATOM(struct in_addr, dummy_netmask, (struct in_addr){htonl(0xFFFFFF00)}, cf_opt_in_addr,, "Dummy interface netmask") ATOM(struct in_addr, dummy_netmask, (struct in_addr){htonl(0xFFFFFF00)}, cf_opt_in_addr,, "Dummy interface netmask")
ATOM(int, dummy_filter_broadcasts, 0, cf_opt_boolean,, "If true, drop all incoming broadcast packets") ATOM(int, dummy_filter_broadcasts, 0, cf_opt_int_boolean,, "If true, drop all incoming broadcast packets")
ATOM(short, type, OVERLAY_INTERFACE_WIFI, cf_opt_interface_type,, "Type of network interface") ATOM(short, type, OVERLAY_INTERFACE_WIFI, cf_opt_interface_type,, "Type of network interface")
ATOM(uint16_t, port, RHIZOME_HTTP_PORT, cf_opt_uint16_nonzero,, "Port number for network interface") ATOM(uint16_t, port, RHIZOME_HTTP_PORT, cf_opt_uint16_nonzero,, "Port number for network interface")
ATOM(uint64_t, speed, 1000000, cf_opt_uint64_scaled,, "Speed in bits per second") ATOM(uint64_t, speed, 1000000, cf_opt_uint64_scaled,, "Speed in bits per second")
ATOM(int, mdp_tick_ms, -1, cf_opt_int32_nonneg,, "Override MDP tick interval for this interface") ATOM(int, mdp_tick_ms, -1, cf_opt_int32_nonneg,, "Override MDP tick interval for this interface")
ATOM(int, default_route, 0, cf_opt_boolean,, "If true, use this interface as a default route") ATOM(int, default_route, 0, cf_opt_int_boolean,, "If true, use this interface as a default route")
END_STRUCT END_STRUCT
ARRAY(interface_list, SORTED NO_DUPLICATES) ARRAY(interface_list, SORTED NO_DUPLICATES)
@ -323,7 +354,7 @@ SUB_STRUCT(server, server,)
SUB_STRUCT(monitor, monitor,) SUB_STRUCT(monitor, monitor,)
SUB_STRUCT(mdp, mdp,) SUB_STRUCT(mdp, mdp,)
SUB_STRUCT(dna, dna,) SUB_STRUCT(dna, dna,)
NODE(debugflags_t, debug, 0, cf_opt_debugflags, USES_CHILDREN, "Debug flags") SUB_STRUCT(debug, debug,)
SUB_STRUCT(rhizome, rhizome,) SUB_STRUCT(rhizome, rhizome,)
SUB_STRUCT(directory, directory,) SUB_STRUCT(directory, directory,)
SUB_STRUCT(olsr, olsr,) SUB_STRUCT(olsr, olsr,)

View File

@ -115,7 +115,7 @@ static void
dna_helper_close_pipes() dna_helper_close_pipes()
{ {
if (dna_helper_stdin != -1) { if (dna_helper_stdin != -1) {
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUGF("DNAHELPER closing stdin pipe fd=%d", dna_helper_stdin); DEBUGF("DNAHELPER closing stdin pipe fd=%d", dna_helper_stdin);
close(dna_helper_stdin); close(dna_helper_stdin);
dna_helper_stdin = -1; dna_helper_stdin = -1;
@ -125,7 +125,7 @@ dna_helper_close_pipes()
sched_requests.poll.fd = -1; sched_requests.poll.fd = -1;
} }
if (dna_helper_stdout != -1) { if (dna_helper_stdout != -1) {
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUGF("DNAHELPER closing stdout pipe fd=%d", dna_helper_stdout); DEBUGF("DNAHELPER closing stdout pipe fd=%d", dna_helper_stdout);
close(dna_helper_stdout); close(dna_helper_stdout);
dna_helper_stdout = -1; dna_helper_stdout = -1;
@ -135,7 +135,7 @@ dna_helper_close_pipes()
sched_replies.poll.fd = -1; sched_replies.poll.fd = -1;
} }
if (dna_helper_stderr != -1) { if (dna_helper_stderr != -1) {
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUGF("DNAHELPER closing stderr pipe fd=%d", dna_helper_stderr); DEBUGF("DNAHELPER closing stderr pipe fd=%d", dna_helper_stderr);
close(dna_helper_stderr); close(dna_helper_stderr);
dna_helper_stderr = -1; dna_helper_stderr = -1;
@ -281,7 +281,7 @@ dna_helper_kill()
awaiting_reply = 0; awaiting_reply = 0;
} }
if (dna_helper_pid > 0) { if (dna_helper_pid > 0) {
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUGF("DNAHELPER sending SIGTERM to pid=%d", dna_helper_pid); DEBUGF("DNAHELPER sending SIGTERM to pid=%d", dna_helper_pid);
if (kill(dna_helper_pid, SIGTERM) == -1) if (kill(dna_helper_pid, SIGTERM) == -1)
WHYF_perror("kill(%d, SIGTERM)", dna_helper_pid); WHYF_perror("kill(%d, SIGTERM)", dna_helper_pid);
@ -295,7 +295,7 @@ static int
dna_helper_harvest(int blocking) dna_helper_harvest(int blocking)
{ {
if (dna_helper_pid > 0) { if (dna_helper_pid > 0) {
if (blocking && (debug & DEBUG_DNAHELPER)) if (blocking && (config.debug.dnahelper))
DEBUGF("DNAHELPER waiting for pid=%d to die", dna_helper_pid); DEBUGF("DNAHELPER waiting for pid=%d to die", dna_helper_pid);
int status; int status;
pid_t pid = waitpid(dna_helper_pid, &status, blocking ? 0 : WNOHANG); pid_t pid = waitpid(dna_helper_pid, &status, blocking ? 0 : WNOHANG);
@ -320,7 +320,7 @@ dna_helper_harvest(int blocking)
int dna_helper_shutdown() int dna_helper_shutdown()
{ {
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUG("DNAHELPER shutting down"); DEBUG("DNAHELPER shutting down");
dna_helper_close_pipes(); dna_helper_close_pipes();
switch (dna_helper_kill()) { switch (dna_helper_kill()) {
@ -335,7 +335,7 @@ int dna_helper_shutdown()
static void monitor_requests(struct sched_ent *alarm) static void monitor_requests(struct sched_ent *alarm)
{ {
if (debug & DEBUG_DNAHELPER) { if (config.debug.dnahelper) {
DEBUGF("sched_requests.poll.fd=%d .revents=%s", DEBUGF("sched_requests.poll.fd=%d .revents=%s",
sched_requests.poll.fd, sched_requests.poll.fd,
strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_requests.poll.revents)) strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_requests.poll.revents))
@ -345,7 +345,7 @@ static void monitor_requests(struct sched_ent *alarm)
// which is documented to mean the file descriptor is not open, but testing revealed that in this // 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. // case it is still open. See issue #5.
if (sched_requests.poll.revents & (POLLHUP | POLLERR | POLLNVAL)) { if (sched_requests.poll.revents & (POLLHUP | POLLERR | POLLNVAL)) {
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUGF("DNAHELPER closing stdin fd=%d", dna_helper_stdin); DEBUGF("DNAHELPER closing stdin fd=%d", dna_helper_stdin);
close(dna_helper_stdin); close(dna_helper_stdin);
dna_helper_stdin = -1; dna_helper_stdin = -1;
@ -368,7 +368,7 @@ static void monitor_requests(struct sched_ent *alarm)
INFO("DNAHELPER got SIGPIPE on write -- stopping process"); INFO("DNAHELPER got SIGPIPE on write -- stopping process");
dna_helper_kill(); dna_helper_kill();
} else if (written > 0) { } else if (written > 0) {
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUGF("DNAHELPER wrote request %s", alloca_toprint(-1, request_bufptr, written)); DEBUGF("DNAHELPER wrote request %s", alloca_toprint(-1, request_bufptr, written));
request_bufptr += written; request_bufptr += written;
} }
@ -404,7 +404,7 @@ void handle_reply_line(const char *bufp, size_t len)
{ {
if (!dna_helper_started) { if (!dna_helper_started) {
if (len == 8 && strncmp(bufp, "STARTED\n", 8) == 0) { if (len == 8 && strncmp(bufp, "STARTED\n", 8) == 0) {
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUGF("DNAHELPER got STARTED ACK"); DEBUGF("DNAHELPER got STARTED ACK");
dna_helper_started = 1; dna_helper_started = 1;
// Start sending request if there is one pending. // Start sending request if there is one pending.
@ -418,7 +418,7 @@ void handle_reply_line(const char *bufp, size_t len)
} }
} else if (awaiting_reply) { } else if (awaiting_reply) {
if (len == 5 && strncmp(bufp, "DONE\n", 5) == 0) { if (len == 5 && strncmp(bufp, "DONE\n", 5) == 0) {
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUG("DNAHELPER reply DONE"); DEBUG("DNAHELPER reply DONE");
unschedule(&sched_timeout); unschedule(&sched_timeout);
awaiting_reply = 0; awaiting_reply = 0;
@ -449,7 +449,7 @@ void handle_reply_line(const char *bufp, size_t len)
else if (*replyend != '\n') else if (*replyend != '\n')
WHYF("DNAHELPER reply %s contains spurious trailing chars -- ignored", alloca_toprint(-1, bufp, len)); WHYF("DNAHELPER reply %s contains spurious trailing chars -- ignored", alloca_toprint(-1, bufp, len));
else { else {
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUGF("DNAHELPER reply %s", alloca_toprint(-1, bufp, len)); DEBUGF("DNAHELPER reply %s", alloca_toprint(-1, bufp, len));
overlay_mdp_dnalookup_reply(&request_mdp_data.src, my_subscriber->sid, uri, did, name); overlay_mdp_dnalookup_reply(&request_mdp_data.src, my_subscriber->sid, uri, did, name);
} }
@ -461,7 +461,7 @@ void handle_reply_line(const char *bufp, size_t len)
static void monitor_replies(struct sched_ent *alarm) static void monitor_replies(struct sched_ent *alarm)
{ {
if (debug & DEBUG_DNAHELPER) { if (config.debug.dnahelper) {
DEBUGF("sched_replies.poll.fd=%d .revents=%s", DEBUGF("sched_replies.poll.fd=%d .revents=%s",
sched_replies.poll.fd, sched_replies.poll.fd,
strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_replies.poll.revents)) strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_replies.poll.revents))
@ -478,7 +478,7 @@ static void monitor_replies(struct sched_ent *alarm)
while (nread > 0 && (nl = srv_strnstr(readp, nread, "\n"))) { while (nread > 0 && (nl = srv_strnstr(readp, nread, "\n"))) {
size_t len = nl - bufp + 1; size_t len = nl - bufp + 1;
if (discarding_until_nl) { if (discarding_until_nl) {
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUGF("Discarding %s", alloca_toprint(-1, bufp, len)); DEBUGF("Discarding %s", alloca_toprint(-1, bufp, len));
discarding_until_nl = 0; discarding_until_nl = 0;
} else { } else {
@ -493,7 +493,7 @@ static void monitor_replies(struct sched_ent *alarm)
reply_bufend = reply_buffer + len; reply_bufend = reply_buffer + len;
} else if (reply_bufend >= reply_buffer + sizeof reply_buffer) { } else if (reply_bufend >= reply_buffer + sizeof reply_buffer) {
WHY("DNAHELPER reply buffer overrun"); WHY("DNAHELPER reply buffer overrun");
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUGF("Discarding %s", alloca_toprint(-1, reply_buffer, sizeof reply_buffer)); DEBUGF("Discarding %s", alloca_toprint(-1, reply_buffer, sizeof reply_buffer));
reply_bufend = reply_buffer; reply_bufend = reply_buffer;
discarding_until_nl = 1; discarding_until_nl = 1;
@ -501,7 +501,7 @@ static void monitor_replies(struct sched_ent *alarm)
} }
} }
if (sched_replies.poll.revents & (POLLHUP | POLLERR | POLLNVAL)) { if (sched_replies.poll.revents & (POLLHUP | POLLERR | POLLNVAL)) {
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUGF("DNAHELPER closing stdout fd=%d", dna_helper_stdout); DEBUGF("DNAHELPER closing stdout fd=%d", dna_helper_stdout);
close(dna_helper_stdout); close(dna_helper_stdout);
dna_helper_stdout = -1; dna_helper_stdout = -1;
@ -513,7 +513,7 @@ static void monitor_replies(struct sched_ent *alarm)
static void monitor_errors(struct sched_ent *alarm) static void monitor_errors(struct sched_ent *alarm)
{ {
if (debug & DEBUG_DNAHELPER) { if (config.debug.dnahelper) {
DEBUGF("sched_errors.poll.fd=%d .revents=%s", DEBUGF("sched_errors.poll.fd=%d .revents=%s",
sched_errors.poll.fd, sched_errors.poll.fd,
strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_errors.poll.revents)) strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_errors.poll.revents))
@ -526,7 +526,7 @@ static void monitor_errors(struct sched_ent *alarm)
WHYF("DNAHELPER stderr %s", alloca_toprint(-1, buffer, nread)); WHYF("DNAHELPER stderr %s", alloca_toprint(-1, buffer, nread));
} }
if (sched_errors.poll.revents & (POLLHUP | POLLERR | POLLNVAL)) { if (sched_errors.poll.revents & (POLLHUP | POLLERR | POLLNVAL)) {
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUGF("DNAHELPER closing stderr fd=%d", dna_helper_stderr); DEBUGF("DNAHELPER closing stderr fd=%d", dna_helper_stderr);
close(dna_helper_stderr); close(dna_helper_stderr);
dna_helper_stderr = -1; dna_helper_stderr = -1;
@ -545,7 +545,7 @@ static void harvester(struct sched_ent *alarm)
schedule(&sched_harvester); schedule(&sched_harvester);
} else { } else {
const int delay_ms = 500; const int delay_ms = 500;
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUGF("DNAHELPER process died, pausing %d ms before restart", delay_ms); DEBUGF("DNAHELPER process died, pausing %d ms before restart", delay_ms);
dna_helper_pid = 0; // Will be set to -1 after delay dna_helper_pid = 0; // Will be set to -1 after delay
sched_restart.function = restart_delayer; sched_restart.function = restart_delayer;
@ -558,7 +558,7 @@ static void harvester(struct sched_ent *alarm)
static void restart_delayer(struct sched_ent *alarm) static void restart_delayer(struct sched_ent *alarm)
{ {
if (dna_helper_pid == 0) { if (dna_helper_pid == 0) {
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUG("DNAHELPER re-enable restart"); DEBUG("DNAHELPER re-enable restart");
dna_helper_pid = -1; dna_helper_pid = -1;
} }
@ -575,7 +575,7 @@ static void reply_timeout(struct sched_ent *alarm)
int int
dna_helper_enqueue(overlay_mdp_frame *mdp, const char *did, const unsigned char *requestorSid) dna_helper_enqueue(overlay_mdp_frame *mdp, const char *did, const unsigned char *requestorSid)
{ {
if (debug & DEBUG_DNAHELPER) if (config.debug.dnahelper)
DEBUGF("DNAHELPER request did=%s sid=%s", did, alloca_tohex_sid(requestorSid)); DEBUGF("DNAHELPER request did=%s sid=%s", did, alloca_tohex_sid(requestorSid));
if (dna_helper_pid == 0) if (dna_helper_pid == 0)
return 0; return 0;

View File

@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <poll.h> #include <poll.h>
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "str.h" #include "str.h"
#include "strbuf.h" #include "strbuf.h"
#include "strbuf_helpers.h" #include "strbuf_helpers.h"
@ -85,7 +86,7 @@ int is_scheduled(const struct sched_ent *alarm)
// on calling .poll.revents will be zero. // on calling .poll.revents will be zero.
int _schedule(struct __sourceloc __whence, struct sched_ent *alarm) int _schedule(struct __sourceloc __whence, struct sched_ent *alarm)
{ {
if (debug & DEBUG_IO) if (config.debug.io)
DEBUGF("schedule(alarm=%s)", alloca_alarm_name(alarm)); DEBUGF("schedule(alarm=%s)", alloca_alarm_name(alarm));
struct sched_ent *node = next_alarm, *last = NULL; struct sched_ent *node = next_alarm, *last = NULL;
@ -126,7 +127,7 @@ int _schedule(struct __sourceloc __whence, struct sched_ent *alarm)
// safe to unschedule twice... // safe to unschedule twice...
int _unschedule(struct __sourceloc __whence, struct sched_ent *alarm) int _unschedule(struct __sourceloc __whence, struct sched_ent *alarm)
{ {
if (debug & DEBUG_IO) if (config.debug.io)
DEBUGF("unschedule(alarm=%s)", alloca_alarm_name(alarm)); DEBUGF("unschedule(alarm=%s)", alloca_alarm_name(alarm));
struct sched_ent *prev = alarm->_prev; struct sched_ent *prev = alarm->_prev;
@ -150,7 +151,7 @@ int _unschedule(struct __sourceloc __whence, struct sched_ent *alarm)
// start watching a file handle, call this function again if you wish to change the event mask // start watching a file handle, call this function again if you wish to change the event mask
int _watch(struct __sourceloc __whence, struct sched_ent *alarm) int _watch(struct __sourceloc __whence, struct sched_ent *alarm)
{ {
if (debug & DEBUG_IO) if (config.debug.io)
DEBUGF("watch(alarm=%s)", alloca_alarm_name(alarm)); DEBUGF("watch(alarm=%s)", alloca_alarm_name(alarm));
if (!alarm->function) if (!alarm->function)
@ -158,10 +159,10 @@ int _watch(struct __sourceloc __whence, struct sched_ent *alarm)
if (alarm->_poll_index>=0 && fd_callbacks[alarm->_poll_index]==alarm){ if (alarm->_poll_index>=0 && fd_callbacks[alarm->_poll_index]==alarm){
// updating event flags // updating event flags
if (debug & DEBUG_IO) if (config.debug.io)
DEBUGF("Updating watch %s, #%d for %d", alloca_alarm_name(alarm), alarm->poll.fd, alarm->poll.events); DEBUGF("Updating watch %s, #%d for %d", alloca_alarm_name(alarm), alarm->poll.fd, alarm->poll.events);
}else{ }else{
if (debug & DEBUG_IO) if (config.debug.io)
DEBUGF("Adding watch %s, #%d for %d", alloca_alarm_name(alarm), alarm->poll.fd, alarm->poll.events); DEBUGF("Adding watch %s, #%d for %d", alloca_alarm_name(alarm), alarm->poll.fd, alarm->poll.events);
if (fdcount>=MAX_WATCHED_FDS) if (fdcount>=MAX_WATCHED_FDS)
return WHY("Too many file handles to watch"); return WHY("Too many file handles to watch");
@ -177,7 +178,7 @@ int _watch(struct __sourceloc __whence, struct sched_ent *alarm)
// stop watching a file handle // stop watching a file handle
int _unwatch(struct __sourceloc __whence, struct sched_ent *alarm) int _unwatch(struct __sourceloc __whence, struct sched_ent *alarm)
{ {
if (debug & DEBUG_IO) if (config.debug.io)
DEBUGF("unwatch(alarm=%s)", alloca_alarm_name(alarm)); DEBUGF("unwatch(alarm=%s)", alloca_alarm_name(alarm));
int index = alarm->_poll_index; int index = alarm->_poll_index;
@ -194,7 +195,7 @@ int _unwatch(struct __sourceloc __whence, struct sched_ent *alarm)
fds[fdcount].fd=-1; fds[fdcount].fd=-1;
fd_callbacks[fdcount]=NULL; fd_callbacks[fdcount]=NULL;
alarm->_poll_index=-1; alarm->_poll_index=-1;
if (debug & DEBUG_IO) if (config.debug.io)
DEBUGF("%s stopped watching #%d for %d", alloca_alarm_name(alarm), alarm->poll.fd, alarm->poll.events); DEBUGF("%s stopped watching #%d for %d", alloca_alarm_name(alarm), alarm->poll.fd, alarm->poll.events);
return 0; return 0;
} }
@ -252,7 +253,7 @@ int fd_poll()
usleep(ms*1000); usleep(ms*1000);
}else{ }else{
r = poll(fds, fdcount, ms); r = poll(fds, fdcount, ms);
if (debug & DEBUG_IO) { if (config.debug.io) {
strbuf b = strbuf_alloca(1024); strbuf b = strbuf_alloca(1024);
int i; int i;
for (i = 0; i < fdcount; ++i) { for (i = 0; i < fdcount; ++i) {

View File

@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "serval.h" #include "serval.h"
#include "str.h" #include "str.h"
#include "conf.h"
#include "rhizome.h" #include "rhizome.h"
#include "nacl.h" #include "nacl.h"
#include "overlay_address.h" #include "overlay_address.h"
@ -215,7 +216,7 @@ void keyring_free_identity(keyring_identity *id)
if (id->PKRPin) { if (id->PKRPin) {
/* Wipe pin before freeing (slightly tricky since this is a variable length string */ /* Wipe pin before freeing (slightly tricky since this is a variable length string */
for(i=0;id->PKRPin[i];i++) { for(i=0;id->PKRPin[i];i++) {
if (debug & DEBUG_KEYRING) if (config.debug.keyring)
DEBUGF("clearing PIN char '%c'", id->PKRPin[i]); DEBUGF("clearing PIN char '%c'", id->PKRPin[i]);
id->PKRPin[i]=' '; id->PKRPin[i]=' ';
} }
@ -969,7 +970,7 @@ int keyring_commit(keyring_file *k)
=KEYRING_PAGE_SIZE =KEYRING_PAGE_SIZE
*k->contexts[cn]->identities[in]->slot; *k->contexts[cn]->identities[in]->slot;
if (!file_offset) { if (!file_offset) {
if (debug * DEBUG_KEYRING) if (config.debug.keyring)
DEBUGF("ID %d:%d has slot=0", cn,in); DEBUGF("ID %d:%d has slot=0", cn,in);
} }
else if (fseeko(k->file,file_offset,SEEK_SET)) else if (fseeko(k->file,file_offset,SEEK_SET))
@ -995,7 +996,7 @@ int keyring_set_did(keyring_identity *id,char *did,char *name)
int i; int i;
for(i=0;i<id->keypair_count;i++) for(i=0;i<id->keypair_count;i++)
if (id->keypairs[i]->type==KEYTYPE_DID) { if (id->keypairs[i]->type==KEYTYPE_DID) {
if (debug & DEBUG_KEYRING) if (config.debug.keyring)
DEBUG("Identity contains DID"); DEBUG("Identity contains DID");
break; break;
} }
@ -1016,7 +1017,7 @@ int keyring_set_did(keyring_identity *id,char *did,char *name)
id->keypairs[i]->public_key=packedName; id->keypairs[i]->public_key=packedName;
id->keypairs[i]->public_key_len=64; id->keypairs[i]->public_key_len=64;
id->keypair_count++; id->keypair_count++;
if (debug & DEBUG_KEYRING) if (config.debug.keyring)
DEBUG("Created DID record for identity"); DEBUG("Created DID record for identity");
} }
@ -1028,7 +1029,7 @@ int keyring_set_did(keyring_identity *id,char *did,char *name)
bcopy(name,&id->keypairs[i]->public_key[0],len); bcopy(name,&id->keypairs[i]->public_key[0],len);
bzero(&id->keypairs[i]->public_key[len],64-len); bzero(&id->keypairs[i]->public_key[len],64-len);
if (debug & DEBUG_KEYRING){ if (config.debug.keyring){
dump("storing did",&id->keypairs[i]->private_key[0],32); dump("storing did",&id->keypairs[i]->private_key[0],32);
dump("storing name",&id->keypairs[i]->public_key[0],64); dump("storing name",&id->keypairs[i]->public_key[0],64);
} }
@ -1134,7 +1135,7 @@ unsigned char *keyring_find_sas_private(keyring_file *k,unsigned char *sid,
sas_private); sas_private);
keyring_commit(k); keyring_commit(k);
} }
if (debug & DEBUG_KEYRING) if (config.debug.keyring)
DEBUGF("Found SAS entry for %s*", alloca_tohex(sid, 7)); DEBUGF("Found SAS entry for %s*", alloca_tohex(sid, 7));
if (sas_public_out) *sas_public_out=sas_public; if (sas_public_out) *sas_public_out=sas_public;
RETURN(sas_private); RETURN(sas_private);
@ -1147,12 +1148,12 @@ static int keyring_store_sas(overlay_mdp_frame *req){
struct subscriber *subscriber = find_subscriber(req->in.src.sid,SID_SIZE,1); struct subscriber *subscriber = find_subscriber(req->in.src.sid,SID_SIZE,1);
if (subscriber->sas_valid){ if (subscriber->sas_valid){
if (debug & DEBUG_KEYRING) if (config.debug.keyring)
DEBUGF("Ignoring SID:SAS mapping for %s, already have one", alloca_tohex_sid(req->in.src.sid)); DEBUGF("Ignoring SID:SAS mapping for %s, already have one", alloca_tohex_sid(req->in.src.sid));
return 0; return 0;
} }
if (debug & DEBUG_KEYRING) if (config.debug.keyring)
DEBUGF("Received SID:SAS mapping, %d bytes", req->out.payload_length); DEBUGF("Received SID:SAS mapping, %d bytes", req->out.payload_length);
unsigned keytype = req->out.payload[0]; unsigned keytype = req->out.payload[0];
@ -1190,7 +1191,7 @@ static int keyring_store_sas(overlay_mdp_frame *req){
subscriber->sas_valid=1; subscriber->sas_valid=1;
subscriber->sas_last_request=-1; subscriber->sas_last_request=-1;
if (debug & DEBUG_KEYRING) if (config.debug.keyring)
DEBUGF("Stored SID:SAS mapping, SID=%s to SAS=%s", DEBUGF("Stored SID:SAS mapping, SID=%s to SAS=%s",
alloca_tohex_sid(req->out.src.sid), alloca_tohex_sid(req->out.src.sid),
alloca_tohex_sas(subscriber->sas_public) alloca_tohex_sas(subscriber->sas_public)
@ -1238,7 +1239,7 @@ int keyring_mapping_request(keyring_file *k, overlay_mdp_frame *req)
overlay_mdp_swap_src_dst(req); overlay_mdp_swap_src_dst(req);
req->out.ttl=0; req->out.ttl=0;
req->packetTypeAndFlags=MDP_TX; /* crypt and sign */ req->packetTypeAndFlags=MDP_TX; /* crypt and sign */
if (debug & DEBUG_KEYRING) if (config.debug.keyring)
DEBUGF("Sending SID:SAS mapping, %d bytes, %s:0x%X -> %s:0x%X", DEBUGF("Sending SID:SAS mapping, %d bytes, %s:0x%X -> %s:0x%X",
req->out.payload_length, req->out.payload_length,
alloca_tohex_sid(req->out.src.sid), req->out.src.port, alloca_tohex_sid(req->out.src.sid), req->out.src.port,
@ -1258,7 +1259,7 @@ int keyring_send_sas_request(struct subscriber *subscriber){
time_ms_t now = gettime_ms(); time_ms_t now = gettime_ms();
if (now < subscriber->sas_last_request + 100){ if (now < subscriber->sas_last_request + 100){
if (debug & DEBUG_KEYRING) if (config.debug.keyring)
INFO("Too soon to ask for SAS mapping again"); INFO("Too soon to ask for SAS mapping again");
return 0; return 0;
} }
@ -1266,7 +1267,7 @@ int keyring_send_sas_request(struct subscriber *subscriber){
if (!my_subscriber) if (!my_subscriber)
return WHY("couldn't request SAS (I don't know who I am)"); return WHY("couldn't request SAS (I don't know who I am)");
if (debug & DEBUG_KEYRING) if (config.debug.keyring)
DEBUGF("Requesting SAS mapping for SID=%s", alloca_tohex_sid(subscriber->sid)); DEBUGF("Requesting SAS mapping for SID=%s", alloca_tohex_sid(subscriber->sid));
/* request mapping (send request auth-crypted). */ /* request mapping (send request auth-crypted). */
@ -1283,7 +1284,7 @@ int keyring_send_sas_request(struct subscriber *subscriber){
if (overlay_mdp_dispatch(&mdp, 0 /* system generated */, NULL, 0)) if (overlay_mdp_dispatch(&mdp, 0 /* system generated */, NULL, 0))
return WHY("Failed to send SAS resolution request"); return WHY("Failed to send SAS resolution request");
if (debug & DEBUG_KEYRING) if (config.debug.keyring)
DEBUGF("Dispatched SAS resolution request"); DEBUGF("Dispatched SAS resolution request");
subscriber->sas_last_request=now; subscriber->sas_last_request=now;

36
log.c
View File

@ -43,8 +43,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
const struct __sourceloc __whence = __NOWHERE__; const struct __sourceloc __whence = __NOWHERE__;
debugflags_t debug = 0;
static FILE *logfile = NULL; static FILE *logfile = NULL;
/* The logbuf is used to accumulate log messages before the log file is open and ready for /* The logbuf is used to accumulate log messages before the log file is open and ready for
@ -279,40 +277,6 @@ int logDump(int level, struct __sourceloc whence, char *name, const unsigned cha
return 0; return 0;
} }
debugflags_t debugFlagMask(const char *flagname)
{
if (!strcasecmp(flagname,"all")) return DEBUG_ALL;
else if (!strcasecmp(flagname,"interfaces")) return DEBUG_OVERLAYINTERFACES;
else if (!strcasecmp(flagname,"rx")) return DEBUG_PACKETRX;
else if (!strcasecmp(flagname,"tx")) return DEBUG_PACKETTX;
else if (!strcasecmp(flagname,"verbose")) return DEBUG_VERBOSE;
else if (!strcasecmp(flagname,"verbio")) return DEBUG_VERBOSE_IO;
else if (!strcasecmp(flagname,"peers")) return DEBUG_PEERS;
else if (!strcasecmp(flagname,"dnaresponses")) return DEBUG_DNARESPONSES;
else if (!strcasecmp(flagname,"dnahelper")) return DEBUG_DNAHELPER;
else if (!strcasecmp(flagname,"vomp")) return DEBUG_VOMP;
else if (!strcasecmp(flagname,"packetformats")) return DEBUG_PACKETFORMATS;
else if (!strcasecmp(flagname,"packetconstruction")) return DEBUG_PACKETCONSTRUCTION;
else if (!strcasecmp(flagname,"gateway")) return DEBUG_GATEWAY;
else if (!strcasecmp(flagname,"keyring")) return DEBUG_KEYRING;
else if (!strcasecmp(flagname,"sockio")) return DEBUG_IO;
else if (!strcasecmp(flagname,"frames")) return DEBUG_OVERLAYFRAMES;
else if (!strcasecmp(flagname,"abbreviations")) return DEBUG_OVERLAYABBREVIATIONS;
else if (!strcasecmp(flagname,"routing")) return DEBUG_OVERLAYROUTING;
else if (!strcasecmp(flagname,"security")) return DEBUG_SECURITY;
else if (!strcasecmp(flagname,"rhizome")) return DEBUG_RHIZOME;
else if (!strcasecmp(flagname,"rhizometx")) return DEBUG_RHIZOME_TX;
else if (!strcasecmp(flagname,"rhizomerx")) return DEBUG_RHIZOME_RX;
else if (!strcasecmp(flagname,"rhizomeads")) return DEBUG_RHIZOME_ADS;
else if (!strcasecmp(flagname,"monitorroutes")) return DEBUG_OVERLAYROUTEMONITOR;
else if (!strcasecmp(flagname,"queues")) return DEBUG_QUEUES;
else if (!strcasecmp(flagname,"broadcasts")) return DEBUG_BROADCASTS;
else if (!strcasecmp(flagname,"manifests")) return DEBUG_MANIFESTS;
else if (!strcasecmp(flagname,"mdprequests")) return DEBUG_MDPREQUESTS;
else if (!strcasecmp(flagname,"timing")) return DEBUG_TIMING;
return 0;
}
/* Read the symbolic link into the supplied buffer and add a terminating nul. Return -1 if the /* Read the symbolic link into the supplied buffer and add a terminating nul. Return -1 if the
* buffer is too short to hold the link content and the nul. If readlink(2) returns an error, then * buffer is too short to hold the link content and the nul. If readlink(2) returns an error, then
* logs it and returns -1. Otherwise, returns the number of bytes read, including the terminating * logs it and returns -1. Otherwise, returns the number of bytes read, including the terminating

37
log.h
View File

@ -25,40 +25,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <sys/types.h> #include <sys/types.h>
#include <errno.h> #include <errno.h>
typedef unsigned int debugflags_t;
extern debugflags_t debug;
#define DEBUG_ALL (~0)
#define DEBUG_PACKETRX (1 << 0)
#define DEBUG_OVERLAYINTERFACES (1 << 1)
#define DEBUG_VERBOSE (1 << 2)
#define DEBUG_VERBOSE_IO (1 << 3)
#define DEBUG_PEERS (1 << 4)
#define DEBUG_DNARESPONSES (1 << 5)
#define DEBUG_DNAHELPER (1 << 6)
#define DEBUG_VOMP (1 << 7)
#define DEBUG_RHIZOME_RX (1 << 8)
#define DEBUG_PACKETFORMATS (1 << 9)
#define DEBUG_GATEWAY (1 << 10)
#define DEBUG_KEYRING (1 << 11)
#define DEBUG_IO (1 << 12)
#define DEBUG_OVERLAYFRAMES (1 << 13)
#define DEBUG_OVERLAYABBREVIATIONS (1 << 14)
#define DEBUG_OVERLAYROUTING (1 << 15)
#define DEBUG_SECURITY (1 << 16)
#define DEBUG_RHIZOME (1 << 17)
#define DEBUG_OVERLAYROUTEMONITOR (1 << 18)
#define DEBUG_QUEUES (1 << 19)
#define DEBUG_BROADCASTS (1 << 20)
#define DEBUG_RHIZOME_TX (1 << 21)
#define DEBUG_PACKETTX (1 << 22)
#define DEBUG_PACKETCONSTRUCTION (1 << 23)
#define DEBUG_MANIFESTS (1 << 24)
#define DEBUG_MDPREQUESTS (1 << 25)
#define DEBUG_TIMING (1 << 26)
#define DEBUG_RHIZOME_ADS (1 << 27)
#define LOG_LEVEL_SILENT (-1) #define LOG_LEVEL_SILENT (-1)
#define LOG_LEVEL_DEBUG (0) #define LOG_LEVEL_DEBUG (0)
#define LOG_LEVEL_INFO (1) #define LOG_LEVEL_INFO (1)
@ -122,10 +88,9 @@ void set_logging(FILE *f);
FILE *open_logging(); FILE *open_logging();
void close_logging(); void close_logging();
void logArgv(int level, struct __sourceloc whence, const char *label, int argc, const char *const *argv); void logArgv(int level, struct __sourceloc whence, const char *label, int argc, const char *const *argv);
void logString(int level, struct __sourceloc whence, const char *str); void logString(int level, struct __sourceloc whence, const char *str);
void logMessage(int level, struct __sourceloc whence, const char *fmt, ...); void logMessage(int level, struct __sourceloc whence, const char *fmt, ...);
void vlogMessage(int level, struct __sourceloc whence, const char *fmt, va_list); void vlogMessage(int level, struct __sourceloc whence, const char *fmt, va_list);
debugflags_t debugFlagMask(const char *flagname);
int logDump(int level, struct __sourceloc whence, char *name, const unsigned char *addr, size_t len); int logDump(int level, struct __sourceloc whence, char *name, const unsigned char *addr, size_t len);
ssize_t get_self_executable_path(char *buf, size_t len); ssize_t get_self_executable_path(char *buf, size_t len);
int log_backtrace(struct __sourceloc whence); int log_backtrace(struct __sourceloc whence);

17
lsif.c
View File

@ -27,6 +27,7 @@
*/ */
#include "serval.h" #include "serval.h"
#include "conf.h"
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
@ -72,7 +73,7 @@
*/ */
int scrapeProcNetRoute() int scrapeProcNetRoute()
{ {
if (debug & DEBUG_OVERLAYINTERFACES) DEBUG("called"); if (config.debug.overlayinterfaces) DEBUG("called");
FILE *f=fopen("/proc/net/route","r"); FILE *f=fopen("/proc/net/route","r");
if (!f) return WHY_perror("fopen(\"/proc/net/route\")"); if (!f) return WHY_perror("fopen(\"/proc/net/route\")");
@ -115,7 +116,7 @@ lsif(void) {
struct ifreq *ifr; struct ifreq *ifr;
struct in_addr addr, netmask; struct in_addr addr, netmask;
if (debug & DEBUG_OVERLAYINTERFACES) DEBUG("called"); if (config.debug.overlayinterfaces) DEBUG("called");
/* Get a socket handle. */ /* Get a socket handle. */
sck = socket(PF_INET, SOCK_DGRAM, 0); sck = socket(PF_INET, SOCK_DGRAM, 0);
@ -143,7 +144,7 @@ lsif(void) {
/* We're only interested in IPv4 addresses */ /* We're only interested in IPv4 addresses */
if (ifr->ifr_ifru.ifru_addr.sa_family != AF_INET) { if (ifr->ifr_ifru.ifru_addr.sa_family != AF_INET) {
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("Skipping non-AF_INET address on %s", ifr->ifr_name); if (config.debug.overlayinterfaces) DEBUGF("Skipping non-AF_INET address on %s", ifr->ifr_name);
continue; continue;
} }
@ -155,7 +156,7 @@ lsif(void) {
/* Not broadcast? Not interested.. */ /* Not broadcast? Not interested.. */
if ((ifr->ifr_ifru.ifru_flags & IFF_BROADCAST) == 0) { if ((ifr->ifr_ifru.ifru_flags & IFF_BROADCAST) == 0) {
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("Skipping non-broadcast address on %s", ifr->ifr_name); if (config.debug.overlayinterfaces) DEBUGF("Skipping non-broadcast address on %s", ifr->ifr_name);
continue; continue;
} }
@ -170,7 +171,7 @@ lsif(void) {
nInterfaces++; nInterfaces++;
} }
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("Examined %d interface addresses", nInterfaces); if (config.debug.overlayinterfaces) DEBUGF("Examined %d interface addresses", nInterfaces);
close(sck); close(sck);
return 0; return 0;
@ -185,7 +186,7 @@ doifaddrs(void) {
char *name; char *name;
struct in_addr addr, netmask; struct in_addr addr, netmask;
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("called"); if (config.debug.overlayinterfaces) DEBUGF("called");
if (getifaddrs(&ifaddr) == -1) if (getifaddrs(&ifaddr) == -1)
return WHY_perror("getifaddr()"); return WHY_perror("getifaddr()");
@ -196,13 +197,13 @@ doifaddrs(void) {
/* We're only interested in IPv4 addresses */ /* We're only interested in IPv4 addresses */
if (ifa->ifa_addr->sa_family != AF_INET) { if (ifa->ifa_addr->sa_family != AF_INET) {
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("Skipping non-AF_INET address on %s", ifa->ifa_name); if (config.debug.overlayinterfaces) DEBUGF("Skipping non-AF_INET address on %s", ifa->ifa_name);
continue; continue;
} }
/* Not broadcast? Not interested.. */ /* Not broadcast? Not interested.. */
if ((ifa->ifa_flags & IFF_BROADCAST) == 0) { if ((ifa->ifa_flags & IFF_BROADCAST) == 0) {
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("Skipping non-broadcast address on %s", ifa->ifa_name); if (config.debug.overlayinterfaces) DEBUGF("Skipping non-broadcast address on %s", ifa->ifa_name);
continue; continue;
} }

View File

@ -18,6 +18,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "str.h" #include "str.h"
#include "strbuf.h" #include "strbuf.h"
#include "overlay_buffer.h" #include "overlay_buffer.h"
@ -115,7 +116,7 @@ int overlay_mdp_client_init()
return WHY("Could not form MDP client socket name"); return WHY("Could not form MDP client socket name");
snprintf(overlay_mdp_client_socket_path,1024,fmt,getpid(),random_value); snprintf(overlay_mdp_client_socket_path,1024,fmt,getpid(),random_value);
overlay_mdp_client_socket_path_len=strlen(overlay_mdp_client_socket_path)+1; overlay_mdp_client_socket_path_len=strlen(overlay_mdp_client_socket_path)+1;
if(debug&DEBUG_IO) DEBUGF("MDP client socket name='%s'",overlay_mdp_client_socket_path); if(config.debug.io) DEBUGF("MDP client socket name='%s'",overlay_mdp_client_socket_path);
} }
if (overlay_mdp_client_socket_path_len > sizeof(name.sun_path) - 1) if (overlay_mdp_client_socket_path_len > sizeof(name.sun_path) - 1)
FATALF("MDP socket path too long (%d > %d)", overlay_mdp_client_socket_path_len, sizeof(name.sun_path) - 1); FATALF("MDP socket path too long (%d > %d)", overlay_mdp_client_socket_path_len, sizeof(name.sun_path) - 1);

View File

@ -112,7 +112,7 @@ int monitor_setup_sockets()
if(setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &send_buffer_size, sizeof send_buffer_size)==-1) if(setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &send_buffer_size, sizeof send_buffer_size)==-1)
WHYF_perror("setsockopt(%d, SOL_SOCKET, SO_RCVBUF, &%d, %d)", sock, send_buffer_size, sizeof send_buffer_size); WHYF_perror("setsockopt(%d, SOL_SOCKET, SO_RCVBUF, &%d, %d)", sock, send_buffer_size, sizeof send_buffer_size);
if (debug&(DEBUG_IO|DEBUG_VERBOSE_IO)) if (config.debug.io || config.debug.verbose_io)
DEBUGF("Monitor server socket bound to %s", alloca_toprint(-1, &name, len)); DEBUGF("Monitor server socket bound to %s", alloca_toprint(-1, &name, len));
named_socket.function=monitor_poll; named_socket.function=monitor_poll;

12
net.c
View File

@ -23,9 +23,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <time.h> #include <time.h>
#include "serval.h"
#include "conf.h"
#include "net.h" #include "net.h"
#include "str.h" #include "str.h"
#include "serval.h"
int _set_nonblock(int fd, struct __sourceloc __whence) int _set_nonblock(int fd, struct __sourceloc __whence)
{ {
@ -140,7 +142,7 @@ ssize_t recvwithttl(int sock,unsigned char *buffer, size_t bufferlen,int *ttl,
if (len == -1 && errno != EAGAIN && errno != EWOULDBLOCK) if (len == -1 && errno != EAGAIN && errno != EWOULDBLOCK)
return WHY_perror("recvmsg"); return WHY_perror("recvmsg");
if (0&&debug&DEBUG_PACKETRX) { if (0 && config.debug.packetrx) {
DEBUGF("recvmsg returned %lld (flags=%d, msg_controllen=%d)", (long long) len, msg.msg_flags, msg.msg_controllen); DEBUGF("recvmsg returned %lld (flags=%d, msg_controllen=%d)", (long long) len, msg.msg_flags, msg.msg_controllen);
dump("received data", buffer, len); dump("received data", buffer, len);
} }
@ -155,15 +157,15 @@ ssize_t recvwithttl(int sock,unsigned char *buffer, size_t bufferlen,int *ttl,
if ((cmsg->cmsg_level == IPPROTO_IP) && if ((cmsg->cmsg_level == IPPROTO_IP) &&
((cmsg->cmsg_type == IP_RECVTTL) ||(cmsg->cmsg_type == IP_TTL)) ((cmsg->cmsg_type == IP_RECVTTL) ||(cmsg->cmsg_type == IP_TTL))
&&(cmsg->cmsg_len) ){ &&(cmsg->cmsg_len) ){
if (debug&DEBUG_PACKETRX) if (config.debug.packetrx)
DEBUGF(" TTL (%p) data location resolves to %p", ttl,CMSG_DATA(cmsg)); DEBUGF(" TTL (%p) data location resolves to %p", ttl,CMSG_DATA(cmsg));
if (CMSG_DATA(cmsg)) { if (CMSG_DATA(cmsg)) {
*ttl = *(unsigned char *) CMSG_DATA(cmsg); *ttl = *(unsigned char *) CMSG_DATA(cmsg);
if (debug&DEBUG_PACKETRX) if (config.debug.packetrx)
DEBUGF(" TTL of packet is %d", *ttl); DEBUGF(" TTL of packet is %d", *ttl);
} }
} else { } else {
if (debug&DEBUG_PACKETRX) if (config.debug.packetrx)
DEBUGF("I didn't expect to see level=%02x, type=%02x", DEBUGF("I didn't expect to see level=%02x, type=%02x",
cmsg->cmsg_level,cmsg->cmsg_type); cmsg->cmsg_level,cmsg->cmsg_type);
} }

View File

@ -69,6 +69,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "rhizome.h" #include "rhizome.h"
#include "strbuf.h" #include "strbuf.h"
@ -147,7 +148,7 @@ schedule(&_sched_##X); }
SCHEDULE(overlay_route_tick, 100, 100); SCHEDULE(overlay_route_tick, 100, 100);
/* Show CPU usage stats periodically */ /* Show CPU usage stats periodically */
if (debug&DEBUG_TIMING){ if (config.debug.timing){
SCHEDULE(fd_periodicstats, 3000, 500); SCHEDULE(fd_periodicstats, 3000, 500);
} }

View File

@ -198,7 +198,7 @@ int set_reachable(struct subscriber *subscriber, int reachable){
subscriber->reachable=reachable; subscriber->reachable=reachable;
// These log messages are for use in tests. Changing them may break test scripts. // These log messages are for use in tests. Changing them may break test scripts.
if (debug&DEBUG_OVERLAYROUTING) { if (config.debug.overlayrouting) {
switch (reachable) { switch (reachable) {
case REACHABLE_NONE: case REACHABLE_NONE:
DEBUGF("NOT REACHABLE sid=%s", alloca_tohex_sid(subscriber->sid)); DEBUGF("NOT REACHABLE sid=%s", alloca_tohex_sid(subscriber->sid));
@ -340,12 +340,12 @@ int overlay_broadcast_drop_check(struct broadcast *addr)
bpi_index&=BPI_MASK; bpi_index&=BPI_MASK;
if (memcmp(bpilist[bpi_index].id, addr->id, BROADCAST_LEN)){ if (memcmp(bpilist[bpi_index].id, addr->id, BROADCAST_LEN)){
if (debug&DEBUG_BROADCASTS) if (config.debug.broadcasts)
DEBUGF("BPI %s is new", alloca_tohex(addr->id, BROADCAST_LEN)); DEBUGF("BPI %s is new", alloca_tohex(addr->id, BROADCAST_LEN));
bcopy(addr->id, bpilist[bpi_index].id, BROADCAST_LEN); bcopy(addr->id, bpilist[bpi_index].id, BROADCAST_LEN);
return 0; /* don't drop */ return 0; /* don't drop */
}else{ }else{
if (debug&DEBUG_BROADCASTS) if (config.debug.broadcasts)
DEBUGF("BPI %s is a duplicate", alloca_tohex(addr->id, BROADCAST_LEN)); DEBUGF("BPI %s is a duplicate", alloca_tohex(addr->id, BROADCAST_LEN));
return 1; /* drop frame because we have seen this BPI recently */ return 1; /* drop frame because we have seen this BPI recently */
} }

View File

@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "str.h" #include "str.h"
#include "overlay_address.h" #include "overlay_address.h"
#include "overlay_buffer.h" #include "overlay_buffer.h"
@ -203,7 +204,7 @@ int overlay_route_saw_advertisements(int i, struct overlay_frame *f, struct deco
/* Don't record routes to ourselves */ /* Don't record routes to ourselves */
if (subscriber->reachable==REACHABLE_SELF) { if (subscriber->reachable==REACHABLE_SELF) {
if (debug & DEBUG_OVERLAYROUTING) if (config.debug.overlayrouting)
DEBUGF("Ignore announcement about me (%s)", alloca_tohex_sid(subscriber->sid)); DEBUGF("Ignore announcement about me (%s)", alloca_tohex_sid(subscriber->sid));
continue; continue;
} }

View File

@ -17,8 +17,9 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "mem.h"
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "mem.h"
#include "overlay_buffer.h" #include "overlay_buffer.h"
/* /*
@ -141,7 +142,7 @@ int ob_unlimitsize(struct overlay_buffer *b)
int ob_makespace(struct overlay_buffer *b,int bytes) int ob_makespace(struct overlay_buffer *b,int bytes)
{ {
if (b->sizeLimit!=-1 && b->position+bytes>b->sizeLimit) { if (b->sizeLimit!=-1 && b->position+bytes>b->sizeLimit) {
if (debug&DEBUG_PACKETFORMATS) WHY("Asked to make space beyond size limit"); if (config.debug.packetformats) WHY("Asked to make space beyond size limit");
return -1; return -1;
} }

View File

@ -199,15 +199,15 @@ overlay_interface_read_any(struct sched_ent *alarm){
/* Drop the packet if we don't find a match */ /* Drop the packet if we don't find a match */
if (!interface){ if (!interface){
if (debug&DEBUG_OVERLAYINTERFACES) if (config.debug.overlayinterfaces)
DEBUGF("Could not find matching interface for packet received from %s", inet_ntoa(src)); DEBUGF("Could not find matching interface for packet received from %s", inet_ntoa(src));
return; return;
} }
/* We have a frame from this interface */ /* We have a frame from this interface */
if (debug&DEBUG_PACKETRX) if (config.debug.packetrx)
DEBUG_packet_visualise("Read from real interface", packet,plen); DEBUG_packet_visualise("Read from real interface", packet,plen);
if (debug&DEBUG_OVERLAYINTERFACES) if (config.debug.overlayinterfaces)
DEBUGF("Received %d bytes from %s on interface %s (ANY)",plen, DEBUGF("Received %d bytes from %s on interface %s (ANY)",plen,
inet_ntoa(src), inet_ntoa(src),
interface->name); interface->name);
@ -285,7 +285,7 @@ overlay_interface_init_socket(int interface_index)
return -1; return -1;
} }
if (debug & (DEBUG_PACKETRX | DEBUG_IO)){ if (config.debug.packetrx || config.debug.io) {
char srctxt[INET_ADDRSTRLEN]; char srctxt[INET_ADDRSTRLEN];
if (inet_ntop(AF_INET, (const void *)&interface->broadcast_address.sin_addr, srctxt, INET_ADDRSTRLEN)) if (inet_ntop(AF_INET, (const void *)&interface->broadcast_address.sin_addr, srctxt, INET_ADDRSTRLEN))
DEBUGF("Bound to %s:%d", srctxt, ntohs(interface->broadcast_address.sin_port)); DEBUGF("Bound to %s:%d", srctxt, ntohs(interface->broadcast_address.sin_port));
@ -474,9 +474,9 @@ static void overlay_interface_poll(struct sched_ent *alarm)
} }
/* We have a frame from this interface */ /* We have a frame from this interface */
if (debug&DEBUG_PACKETRX) if (config.debug.packetrx)
DEBUG_packet_visualise("Read from real interface", packet,plen); DEBUG_packet_visualise("Read from real interface", packet,plen);
if (debug&DEBUG_OVERLAYINTERFACES) { if (config.debug.overlayinterfaces) {
struct in_addr src = ((struct sockaddr_in *)&src_addr)->sin_addr; // avoid strict-alias warning on Solaris (gcc 4.4) struct in_addr src = ((struct sockaddr_in *)&src_addr)->sin_addr; // avoid strict-alias warning on Solaris (gcc 4.4)
DEBUGF("Received %d bytes from %s on interface %s",plen, DEBUGF("Received %d bytes from %s on interface %s",plen,
inet_ntoa(src), inet_ntoa(src),
@ -546,7 +546,7 @@ void overlay_dummy_poll(struct sched_ent *alarm)
return; return;
} }
if (debug&DEBUG_OVERLAYINTERFACES) if (config.debug.overlayinterfaces)
DEBUGF("Read interface %s (size=%lld) at offset=%d",interface->name, length, interface->recv_offset); DEBUGF("Read interface %s (size=%lld) at offset=%d",interface->name, length, interface->recv_offset);
ssize_t nread = read(alarm->poll.fd, &packet, sizeof packet); ssize_t nread = read(alarm->poll.fd, &packet, sizeof packet);
@ -558,7 +558,7 @@ void overlay_dummy_poll(struct sched_ent *alarm)
if (nread == sizeof packet) { if (nread == sizeof packet) {
interface->recv_offset += nread; interface->recv_offset += nread;
if (debug&DEBUG_PACKETRX) if (config.debug.packetrx)
DEBUG_packet_visualise("Read from dummy interface", packet.payload, packet.payload_length); DEBUG_packet_visualise("Read from dummy interface", packet.payload, packet.payload_length);
if (memcmp(&packet.dst_addr, &interface->address, sizeof(packet.dst_addr))==0 || if (memcmp(&packet.dst_addr, &interface->address, sizeof(packet.dst_addr))==0 ||
@ -601,7 +601,7 @@ overlay_broadcast_ensemble(int interface_number,
struct sockaddr_in *recipientaddr, struct sockaddr_in *recipientaddr,
unsigned char *bytes,int len) unsigned char *bytes,int len)
{ {
if (debug&DEBUG_PACKETTX) if (config.debug.packettx)
{ {
DEBUGF("Sending this packet via interface #%d",interface_number); DEBUGF("Sending this packet via interface #%d",interface_number);
DEBUG_packet_visualise(NULL,bytes,len); DEBUG_packet_visualise(NULL,bytes,len);
@ -634,7 +634,7 @@ overlay_broadcast_ensemble(int interface_number,
off_t fsize = lseek(interface->alarm.poll.fd, (off_t) 0, SEEK_END); off_t fsize = lseek(interface->alarm.poll.fd, (off_t) 0, SEEK_END);
if (fsize == -1) if (fsize == -1)
return WHY_perror("lseek"); return WHY_perror("lseek");
if (debug&DEBUG_OVERLAYINTERFACES) if (config.debug.overlayinterfaces)
DEBUGF("Write to interface %s at offset=%d", interface->name, fsize); DEBUGF("Write to interface %s at offset=%d", interface->name, fsize);
ssize_t nwrite = write(interface->alarm.poll.fd, &packet, sizeof(packet)); ssize_t nwrite = write(interface->alarm.poll.fd, &packet, sizeof(packet));
if (nwrite == -1) if (nwrite == -1)
@ -645,7 +645,7 @@ overlay_broadcast_ensemble(int interface_number,
} }
else else
{ {
if (debug&DEBUG_OVERLAYINTERFACES) if (config.debug.overlayinterfaces)
DEBUGF("Sending %d byte overlay frame on %s to %s",len,interface->name,inet_ntoa(recipientaddr->sin_addr)); DEBUGF("Sending %d byte overlay frame on %s to %s",len,interface->name,inet_ntoa(recipientaddr->sin_addr));
if(sendto(interface->alarm.poll.fd, if(sendto(interface->alarm.poll.fd,
bytes, len, 0, (struct sockaddr *)recipientaddr, sizeof(struct sockaddr_in)) != len){ bytes, len, 0, (struct sockaddr *)recipientaddr, sizeof(struct sockaddr_in)) != len){
@ -668,7 +668,7 @@ overlay_interface_register(char *name,
{ {
struct in_addr broadcast = {.s_addr = addr.s_addr | ~mask.s_addr}; struct in_addr broadcast = {.s_addr = addr.s_addr | ~mask.s_addr};
if (debug & DEBUG_OVERLAYINTERFACES) { if (config.debug.overlayinterfaces) {
// note, inet_ntop doesn't seem to behave on android // note, inet_ntop doesn't seem to behave on android
DEBUGF("%s address: %s", name, inet_ntoa(addr)); DEBUGF("%s address: %s", name, inet_ntoa(addr));
DEBUGF("%s broadcast address: %s", name, inet_ntoa(broadcast)); DEBUGF("%s broadcast address: %s", name, inet_ntoa(broadcast));
@ -691,12 +691,12 @@ overlay_interface_register(char *name,
} }
} }
if (ifconfig == NULL) { if (ifconfig == NULL) {
if (debug & DEBUG_OVERLAYINTERFACES) if (config.debug.overlayinterfaces)
DEBUGF("Interface %s does not match any rule", name); DEBUGF("Interface %s does not match any rule", name);
return 0; return 0;
} }
if (ifconfig->exclude) { if (ifconfig->exclude) {
if (debug & DEBUG_OVERLAYINTERFACES) if (config.debug.overlayinterfaces)
DEBUGF("Interface %s is explicitly excluded", name); DEBUGF("Interface %s is explicitly excluded", name);
return 0; return 0;
} }
@ -745,7 +745,7 @@ overlay_interface_register(char *name,
if (overlay_interface_init(name, addr, mask, broadcast, ifconfig)) if (overlay_interface_init(name, addr, mask, broadcast, ifconfig))
return WHYF("Could not initialise newly seen interface %s", name); return WHYF("Could not initialise newly seen interface %s", name);
else else
if (debug & DEBUG_OVERLAYINTERFACES) DEBUGF("Registered interface %s", name); if (config.debug.overlayinterfaces) DEBUGF("Registered interface %s", name);
return 0; return 0;
} }

View File

@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <sys/stat.h> #include <sys/stat.h>
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "str.h" #include "str.h"
#include "strbuf.h" #include "strbuf.h"
#include "overlay_buffer.h" #include "overlay_buffer.h"
@ -247,7 +248,7 @@ int overlay_mdp_process_bind_request(int sock, struct subscriber *subscriber, in
*/ */
free=random()%MDP_MAX_BINDINGS; free=random()%MDP_MAX_BINDINGS;
} }
if (debug & DEBUG_MDPREQUESTS) if (config.debug.mdprequests)
DEBUGF("Binding %s:%d", subscriber ? alloca_tohex_sid(subscriber->sid) : "NULL", port); DEBUGF("Binding %s:%d", subscriber ? alloca_tohex_sid(subscriber->sid) : "NULL", port);
/* Okay, record binding and report success */ /* Okay, record binding and report success */
mdp_bindings[free].port=port; mdp_bindings[free].port=port;
@ -415,7 +416,7 @@ static int overlay_saw_mdp_frame(struct overlay_frame *frame, overlay_mdp_frame
more prudent path. more prudent path.
*/ */
if (debug & DEBUG_MDPREQUESTS) if (config.debug.mdprequests)
DEBUGF("Received packet with listener (MDP ports: src=%s*:%d, dst=%d)", DEBUGF("Received packet with listener (MDP ports: src=%s*:%d, dst=%d)",
alloca_tohex(mdp->out.src.sid, 7), alloca_tohex(mdp->out.src.sid, 7),
mdp->out.src.port,mdp->out.dst.port); mdp->out.src.port,mdp->out.dst.port);
@ -810,7 +811,7 @@ static int search_subscribers(struct subscriber *subscriber, void *context){
} }
int overlay_mdp_address_list(overlay_mdp_addrlist *request, overlay_mdp_addrlist *response){ int overlay_mdp_address_list(overlay_mdp_addrlist *request, overlay_mdp_addrlist *response){
if (debug & DEBUG_MDPREQUESTS) if (config.debug.mdprequests)
DEBUGF("MDP_GETADDRS first_sid=%u mode=%d", DEBUGF("MDP_GETADDRS first_sid=%u mode=%d",
request->first_sid, request->first_sid,
request->mode request->mode
@ -829,7 +830,7 @@ int overlay_mdp_address_list(overlay_mdp_addrlist *request, overlay_mdp_addrlist
response->last_sid = response->first_sid + response->frame_sid_count - 1; response->last_sid = response->first_sid + response->frame_sid_count - 1;
if (debug & DEBUG_MDPREQUESTS) if (config.debug.mdprequests)
DEBUGF("reply MDP_ADDRLIST first_sid=%u last_sid=%u frame_sid_count=%u server_sid_count=%u", DEBUGF("reply MDP_ADDRLIST first_sid=%u last_sid=%u frame_sid_count=%u server_sid_count=%u",
response->first_sid, response->first_sid,
response->last_sid, response->last_sid,
@ -923,13 +924,13 @@ void overlay_mdp_poll(struct sched_ent *alarm)
switch (mdp_type) { switch (mdp_type) {
case MDP_GOODBYE: case MDP_GOODBYE:
if (debug & DEBUG_MDPREQUESTS) DEBUG("MDP_GOODBYE"); if (config.debug.mdprequests) DEBUG("MDP_GOODBYE");
overlay_mdp_releasebindings(recvaddr_un,recvaddrlen); overlay_mdp_releasebindings(recvaddr_un,recvaddrlen);
return; return;
/* Deprecated. We can replace with a more generic dump of the routing table */ /* Deprecated. We can replace with a more generic dump of the routing table */
case MDP_NODEINFO: case MDP_NODEINFO:
if (debug & DEBUG_MDPREQUESTS) DEBUG("MDP_NODEINFO"); if (config.debug.mdprequests) DEBUG("MDP_NODEINFO");
if (!overlay_route_node_info(&mdp->nodeinfo)) if (!overlay_route_node_info(&mdp->nodeinfo))
overlay_mdp_reply(mdp_named.poll.fd,recvaddr_un,recvaddrlen,mdp); overlay_mdp_reply(mdp_named.poll.fd,recvaddr_un,recvaddrlen,mdp);
@ -963,14 +964,14 @@ void overlay_mdp_poll(struct sched_ent *alarm)
break; break;
case MDP_TX: /* Send payload (and don't treat it as system privileged) */ case MDP_TX: /* Send payload (and don't treat it as system privileged) */
if (debug & DEBUG_MDPREQUESTS) DEBUG("MDP_TX"); if (config.debug.mdprequests) DEBUG("MDP_TX");
overlay_mdp_dispatch(mdp,1,(struct sockaddr_un*)recvaddr,recvaddrlen); overlay_mdp_dispatch(mdp,1,(struct sockaddr_un*)recvaddr,recvaddrlen);
return; return;
break; break;
case MDP_BIND: /* Bind to port */ case MDP_BIND: /* Bind to port */
{ {
if (debug & DEBUG_MDPREQUESTS) DEBUG("MDP_BIND"); if (config.debug.mdprequests) DEBUG("MDP_BIND");
struct subscriber *subscriber=NULL; struct subscriber *subscriber=NULL;
/* Make sure source address is either all zeros (listen on all), or a valid /* Make sure source address is either all zeros (listen on all), or a valid

View File

@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <sys/stat.h> #include <sys/stat.h>
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "str.h" #include "str.h"
#include "strbuf.h" #include "strbuf.h"
#include "overlay_buffer.h" #include "overlay_buffer.h"
@ -196,7 +197,7 @@ int overlay_mdp_service_dnalookup(overlay_mdp_frame *mdp)
bcopy(&mdp->out.payload[0],&did[0],pll); bcopy(&mdp->out.payload[0],&did[0],pll);
did[pll]=0; did[pll]=0;
if (debug & DEBUG_MDPREQUESTS) if (config.debug.mdprequests)
DEBUG("MDP_PORT_DNALOOKUP"); DEBUG("MDP_PORT_DNALOOKUP");
int results=0; int results=0;

View File

@ -175,7 +175,7 @@ static void parse_frame(struct overlay_buffer *buff){
frame.modifiers=ob_get(buff); frame.modifiers=ob_get(buff);
if (debug&DEBUG_OVERLAYINTERFACES) if (config.debug.overlayinterfaces)
DEBUGF("Received %d byte payload via olsr", buff->sizeLimit - buff->position); DEBUGF("Received %d byte payload via olsr", buff->sizeLimit - buff->position);
// the remaining bytes are an mdp payload, process it // the remaining bytes are an mdp payload, process it
@ -274,7 +274,7 @@ int olsr_send(struct overlay_frame *frame){
overlay_broadcast_append(b, &frame->broadcast_id); overlay_broadcast_append(b, &frame->broadcast_id);
ob_append_byte(b, frame->modifiers); ob_append_byte(b, frame->modifiers);
if (debug&DEBUG_OVERLAYINTERFACES) if (config.debug.overlayinterfaces)
DEBUGF("Sending %d byte payload via olsr", frame->payload->sizeLimit); DEBUGF("Sending %d byte payload via olsr", frame->payload->sizeLimit);
// send the packet // send the packet

View File

@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "str.h" #include "str.h"
#include "strbuf.h" #include "strbuf.h"
#include "overlay_buffer.h" #include "overlay_buffer.h"
@ -47,35 +48,35 @@ int process_incoming_frame(time_ms_t now, struct overlay_interface *interface, s
{ {
// route control frames // route control frames
case OF_TYPE_SELFANNOUNCE: case OF_TYPE_SELFANNOUNCE:
if (debug&DEBUG_OVERLAYFRAMES) if (config.debug.overlayframes)
DEBUG("Processing OF_TYPE_SELFANNOUNCE"); DEBUG("Processing OF_TYPE_SELFANNOUNCE");
overlay_route_saw_selfannounce(f,now); overlay_route_saw_selfannounce(f,now);
break; break;
case OF_TYPE_SELFANNOUNCE_ACK: case OF_TYPE_SELFANNOUNCE_ACK:
if (debug&DEBUG_OVERLAYFRAMES) if (config.debug.overlayframes)
DEBUG("Processing OF_TYPE_SELFANNOUNCE_ACK"); DEBUG("Processing OF_TYPE_SELFANNOUNCE_ACK");
overlay_route_saw_selfannounce_ack(f,now); overlay_route_saw_selfannounce_ack(f,now);
break; break;
case OF_TYPE_NODEANNOUNCE: case OF_TYPE_NODEANNOUNCE:
if (debug&DEBUG_OVERLAYFRAMES) if (config.debug.overlayframes)
DEBUG("Processing OF_TYPE_NODEANNOUNCE"); DEBUG("Processing OF_TYPE_NODEANNOUNCE");
overlay_route_saw_advertisements(id,f,context,now); overlay_route_saw_advertisements(id,f,context,now);
break; break;
// data frames // data frames
case OF_TYPE_RHIZOME_ADVERT: case OF_TYPE_RHIZOME_ADVERT:
if (debug&DEBUG_OVERLAYFRAMES) if (config.debug.overlayframes)
DEBUG("Processing OF_TYPE_RHIZOME_ADVERT"); DEBUG("Processing OF_TYPE_RHIZOME_ADVERT");
overlay_rhizome_saw_advertisements(id,f,now); overlay_rhizome_saw_advertisements(id,f,now);
break; break;
case OF_TYPE_DATA: case OF_TYPE_DATA:
case OF_TYPE_DATA_VOICE: case OF_TYPE_DATA_VOICE:
if (debug&DEBUG_OVERLAYFRAMES) if (config.debug.overlayframes)
DEBUG("Processing OF_TYPE_DATA"); DEBUG("Processing OF_TYPE_DATA");
overlay_saw_mdp_containing_frame(f,now); overlay_saw_mdp_containing_frame(f,now);
break; break;
case OF_TYPE_PLEASEEXPLAIN: case OF_TYPE_PLEASEEXPLAIN:
if (debug&DEBUG_OVERLAYFRAMES) if (config.debug.overlayframes)
DEBUG("Processing OF_TYPE_PLEASEEXPLAIN"); DEBUG("Processing OF_TYPE_PLEASEEXPLAIN");
process_explain(f); process_explain(f);
break; break;
@ -91,7 +92,7 @@ int overlay_forward_payload(struct overlay_frame *f){
if (f->ttl<=0) if (f->ttl<=0)
RETURN(0); RETURN(0);
if (debug&DEBUG_OVERLAYFRAMES) if (config.debug.overlayframes)
DEBUGF("Forwarding payload for %s, ttl=%d", DEBUGF("Forwarding payload for %s, ttl=%d",
(f->destination?alloca_tohex_sid(f->destination->sid):"broadcast"), (f->destination?alloca_tohex_sid(f->destination->sid):"broadcast"),
f->ttl); f->ttl);
@ -197,7 +198,7 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s
f.recvaddr = *((struct sockaddr_in *)recvaddr); f.recvaddr = *((struct sockaddr_in *)recvaddr);
if (debug&DEBUG_OVERLAYFRAMES) if (config.debug.overlayframes)
DEBUG("Received overlay packet"); DEBUG("Received overlay packet");
if (overlay_address_parse(&context, b, &context.sender)){ if (overlay_address_parse(&context, b, &context.sender)){
@ -271,7 +272,7 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s
} }
if (overlay_broadcast_drop_check(&f.broadcast_id)){ if (overlay_broadcast_drop_check(&f.broadcast_id)){
process=forward=0; process=forward=0;
if (debug&DEBUG_OVERLAYFRAMES) if (config.debug.overlayframes)
DEBUGF("Ignoring duplicate broadcast (%s)", alloca_tohex(f.broadcast_id.id, BROADCAST_LEN)); DEBUGF("Ignoring duplicate broadcast (%s)", alloca_tohex(f.broadcast_id.id, BROADCAST_LEN));
} }
} }
@ -339,12 +340,12 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s
// if we can't understand one of the addresses, skip processing the payload // if we can't understand one of the addresses, skip processing the payload
if (context.invalid_addresses){ if (context.invalid_addresses){
if (debug&DEBUG_OVERLAYFRAMES) if (config.debug.overlayframes)
DEBUG("Skipping payload due to unknown addresses"); DEBUG("Skipping payload due to unknown addresses");
goto next; goto next;
} }
if (debug&DEBUG_OVERLAYFRAMES){ if (config.debug.overlayframes){
DEBUGF("Received payload type %x, len %d", f.type, next_payload - b->position); DEBUGF("Received payload type %x, len %d", f.type, next_payload - b->position);
DEBUGF("Payload from %s", alloca_tohex_sid(f.source->sid)); DEBUGF("Payload from %s", alloca_tohex_sid(f.source->sid));
DEBUGF("Payload to %s", (f.destination?alloca_tohex_sid(f.destination->sid):"broadcast")); DEBUGF("Payload to %s", (f.destination?alloca_tohex_sid(f.destination->sid):"broadcast"));
@ -430,7 +431,7 @@ int overlay_add_selfannouncement(struct decode_context *context, int interface,s
return WHY("Could not add low sequence number to self-announcement"); return WHY("Could not add low sequence number to self-announcement");
if (ob_append_ui32(b, now)) if (ob_append_ui32(b, now))
return WHY("Could not add high sequence number to self-announcement"); return WHY("Could not add high sequence number to self-announcement");
if (debug&DEBUG_OVERLAYINTERFACES) if (config.debug.overlayinterfaces)
DEBUGF("interface #%d: last_tick_ms=%lld, now=%lld (delta=%lld)", DEBUGF("interface #%d: last_tick_ms=%lld, now=%lld (delta=%lld)",
interface, interface,
(long long)overlay_interfaces[interface].last_tick_ms, (long long)overlay_interfaces[interface].last_tick_ms,

View File

@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "str.h" #include "str.h"
#include "overlay_buffer.h" #include "overlay_buffer.h"
#include "overlay_packet.h" #include "overlay_packet.h"
@ -89,7 +90,7 @@ int overlay_frame_append_payload(struct decode_context *context, overlay_interfa
ob_checkpoint(b); ob_checkpoint(b);
if (debug&DEBUG_PACKETCONSTRUCTION){ if (config.debug.packetconstruction){
DEBUGF( "+++++\nFrame from %s to %s of type 0x%02x %s:", DEBUGF( "+++++\nFrame from %s to %s of type 0x%02x %s:",
alloca_tohex_sid(p->source->sid), alloca_tohex_sid(p->source->sid),
alloca_tohex_sid(p->destination->sid),p->type, alloca_tohex_sid(p->destination->sid),p->type,
@ -105,7 +106,7 @@ int overlay_frame_append_payload(struct decode_context *context, overlay_interfa
goto cleanup; goto cleanup;
int hdr_len=headers->position - (headers->var_length_offset +2); int hdr_len=headers->position - (headers->var_length_offset +2);
if (debug&DEBUG_PACKETCONSTRUCTION) if (config.debug.packetconstruction)
DEBUGF("Patching RFS for actual_len=%d\n",hdr_len + p->payload->position); DEBUGF("Patching RFS for actual_len=%d\n",hdr_len + p->payload->position);
ob_set_ui16(headers,headers->var_length_offset,hdr_len + p->payload->position); ob_set_ui16(headers,headers->var_length_offset,hdr_len + p->payload->position);
@ -113,7 +114,7 @@ int overlay_frame_append_payload(struct decode_context *context, overlay_interfa
/* Write payload format plus total length of header bits */ /* Write payload format plus total length of header bits */
if (ob_makespace(b,2+headers->position+p->payload->position)) { if (ob_makespace(b,2+headers->position+p->payload->position)) {
/* Not enough space free in output buffer */ /* Not enough space free in output buffer */
if (debug&DEBUG_PACKETFORMATS) if (config.debug.packetformats)
DEBUGF("Could not make enough space free in output buffer"); DEBUGF("Could not make enough space free in output buffer");
goto cleanup; goto cleanup;
} }

View File

@ -18,6 +18,7 @@
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "overlay_buffer.h" #include "overlay_buffer.h"
#include "overlay_packet.h" #include "overlay_packet.h"
#include "str.h" #include "str.h"
@ -186,7 +187,7 @@ int overlay_payload_enqueue(struct overlay_frame *p)
overlay_txqueue *queue = &overlay_tx[p->queue]; overlay_txqueue *queue = &overlay_tx[p->queue];
if (debug&DEBUG_PACKETTX) if (config.debug.packettx)
DEBUGF("Enqueuing packet for %s* (q[%d]length = %d)", DEBUGF("Enqueuing packet for %s* (q[%d]length = %d)",
p->destination?alloca_tohex(p->destination->sid, 7): alloca_tohex(p->broadcast_id.id,BROADCAST_LEN), p->destination?alloca_tohex(p->destination->sid, 7): alloca_tohex(p->broadcast_id.id,BROADCAST_LEN),
p->queue, queue->length); p->queue, queue->length);
@ -413,7 +414,7 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim
} }
} }
if (debug&DEBUG_OVERLAYFRAMES){ if (config.debug.overlayframes){
DEBUGF("Sending payload type %x len %d for %s via %s", frame->type, ob_position(frame->payload), DEBUGF("Sending payload type %x len %d for %s via %s", frame->type, ob_position(frame->payload),
frame->destination?alloca_tohex_sid(frame->destination->sid):"All", frame->destination?alloca_tohex_sid(frame->destination->sid):"All",
frame->next_hop?alloca_tohex_sid(frame->next_hop->sid):alloca_tohex(frame->broadcast_id.id, BROADCAST_LEN)); frame->next_hop?alloca_tohex_sid(frame->next_hop->sid):alloca_tohex(frame->broadcast_id.id, BROADCAST_LEN));
@ -496,7 +497,7 @@ overlay_fill_send_packet(struct outgoing_packet *packet, time_ms_t now) {
if (packet->add_advertisements) if (packet->add_advertisements)
overlay_rhizome_add_advertisements(&packet->context, packet->i,packet->buffer); overlay_rhizome_add_advertisements(&packet->context, packet->i,packet->buffer);
if (debug&DEBUG_PACKETCONSTRUCTION) if (config.debug.packetconstruction)
ob_dump(packet->buffer,"assembled packet"); ob_dump(packet->buffer,"assembled packet");
if (overlay_broadcast_ensemble(packet->i, &packet->dest, ob_ptr(packet->buffer), ob_position(packet->buffer))){ if (overlay_broadcast_ensemble(packet->i, &packet->dest, ob_ptr(packet->buffer), ob_position(packet->buffer))){
@ -540,7 +541,7 @@ overlay_tick_interface(int i, time_ms_t now) {
RETURN(0); RETURN(0);
} }
if (debug&DEBUG_OVERLAYINTERFACES) DEBUGF("Ticking interface #%d",i); if (config.debug.overlayinterfaces) DEBUGF("Ticking interface #%d",i);
// initialise the packet buffer // initialise the packet buffer
bzero(&packet, sizeof(struct outgoing_packet)); bzero(&packet, sizeof(struct outgoing_packet));

View File

@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "str.h" #include "str.h"
#include "strbuf.h" #include "strbuf.h"
#include "overlay_buffer.h" #include "overlay_buffer.h"
@ -374,7 +375,7 @@ int overlay_route_node_can_hear_me(struct subscriber *subscriber, int sender_int
the scanning of recent observations when re-calculating observation scores. */ the scanning of recent observations when re-calculating observation scores. */
while (neh->observations[obs_index].valid && neh->observations[obs_index].s2 >= s1 - 1) { while (neh->observations[obs_index].valid && neh->observations[obs_index].s2 >= s1 - 1) {
if (neh->observations[obs_index].sender_interface == sender_interface) { if (neh->observations[obs_index].sender_interface == sender_interface) {
if (debug&DEBUG_OVERLAYROUTING) if (config.debug.overlayrouting)
DEBUGF("merging observation into slot #%d s1=%u s2=%u", obs_index, neh->observations[obs_index].s1, neh->observations[obs_index].s2); DEBUGF("merging observation into slot #%d s1=%u s2=%u", obs_index, neh->observations[obs_index].s1, neh->observations[obs_index].s2);
s1 = neh->observations[obs_index].s1; s1 = neh->observations[obs_index].s1;
merge=1; merge=1;
@ -390,7 +391,7 @@ int overlay_route_node_can_hear_me(struct subscriber *subscriber, int sender_int
obs_index = 0; obs_index = 0;
} }
if (debug&DEBUG_OVERLAYROUTING) if (config.debug.overlayrouting)
DEBUGF("assign observation slot #%d: s1=%u s2=%u time_ms=%lld", obs_index, s1, s2, (long long)now); DEBUGF("assign observation slot #%d: s1=%u s2=%u time_ms=%lld", obs_index, s1, s2, (long long)now);
neh->observations[obs_index].s1=s1; neh->observations[obs_index].s1=s1;
neh->observations[obs_index].s2=s2; neh->observations[obs_index].s2=s2;
@ -407,7 +408,7 @@ int overlay_route_node_can_hear_me(struct subscriber *subscriber, int sender_int
if (overlay_route_recalc_neighbour_metrics(neh,now)) if (overlay_route_recalc_neighbour_metrics(neh,now))
return -1; return -1;
if (debug&DEBUG_OVERLAYROUTEMONITOR) overlay_route_dump(); if (config.debug.overlayroutemonitor) overlay_route_dump();
return 0; return 0;
} }
@ -430,7 +431,7 @@ int overlay_route_saw_selfannounce(struct overlay_frame *f, time_ms_t now)
s1=ob_get_ui32(f->payload); s1=ob_get_ui32(f->payload);
s2=ob_get_ui32(f->payload); s2=ob_get_ui32(f->payload);
sender_interface=ob_get(f->payload); sender_interface=ob_get(f->payload);
if (debug&DEBUG_OVERLAYROUTING) if (config.debug.overlayrouting)
DEBUGF("Received self-announcement for sequence range [%08x,%08x] from interface %d",s1,s2,sender_interface); DEBUGF("Received self-announcement for sequence range [%08x,%08x] from interface %d",s1,s2,sender_interface);
overlay_route_ack_selfannounce(f,s1,s2,sender_interface,n); overlay_route_ack_selfannounce(f,s1,s2,sender_interface,n);
@ -507,7 +508,7 @@ int overlay_route_recalc_node_metrics(overlay_node *n, time_ms_t now)
int diff=best_score - n->best_link_score; int diff=best_score - n->best_link_score;
if (diff>0) { if (diff>0) {
overlay_route_please_advertise(n); overlay_route_please_advertise(n);
if (debug&DEBUG_OVERLAYROUTEMONITOR) overlay_route_dump(); if (config.debug.overlayroutemonitor) overlay_route_dump();
} }
int old_best = n->best_link_score; int old_best = n->best_link_score;
@ -564,21 +565,21 @@ int overlay_route_recalc_neighbour_metrics(struct overlay_neighbour *n, time_ms_
if (!n->node) if (!n->node)
RETURN(WHY("Neighbour is not a node")); RETURN(WHY("Neighbour is not a node"));
if (debug&DEBUG_OVERLAYROUTING) if (config.debug.overlayrouting)
DEBUGF("Updating neighbour metrics for %s", alloca_tohex_sid(n->node->subscriber->sid)); DEBUGF("Updating neighbour metrics for %s", alloca_tohex_sid(n->node->subscriber->sid));
/* At most one update per half second */ /* At most one update per half second */
if (n->last_metric_update == 0) { if (n->last_metric_update == 0) {
if (debug&DEBUG_OVERLAYROUTING) if (config.debug.overlayrouting)
DEBUG("last update was never"); DEBUG("last update was never");
} else { } else {
time_ms_t ago = now - n->last_metric_update; time_ms_t ago = now - n->last_metric_update;
if (ago < 500) { if (ago < 500) {
if (debug&DEBUG_OVERLAYROUTING) if (config.debug.overlayrouting)
DEBUGF("last update was %lldms ago -- skipping", (long long)ago); DEBUGF("last update was %lldms ago -- skipping", (long long)ago);
RETURN (0); RETURN (0);
} }
if (debug&DEBUG_OVERLAYROUTING) if (config.debug.overlayrouting)
DEBUGF("last update was %lldms ago", (long long)ago); DEBUGF("last update was %lldms ago", (long long)ago);
} }
n->last_metric_update = now; n->last_metric_update = now;
@ -610,7 +611,7 @@ int overlay_route_recalc_neighbour_metrics(struct overlay_neighbour *n, time_ms_
/* Check the observation age, and ignore if too old */ /* Check the observation age, and ignore if too old */
time_ms_t obs_age = now - n->observations[i].time_ms; time_ms_t obs_age = now - n->observations[i].time_ms;
if (debug&DEBUG_OVERLAYROUTING) if (config.debug.overlayrouting)
DEBUGF("tallying obs: %lldms old, %ums long", obs_age,interval); DEBUGF("tallying obs: %lldms old, %ums long", obs_age,interval);
/* Ignore very large intervals (>1hour) as being likely to be erroneous. /* Ignore very large intervals (>1hour) as being likely to be erroneous.
@ -623,7 +624,7 @@ int overlay_route_recalc_neighbour_metrics(struct overlay_neighbour *n, time_ms_
if (interval>=3600000 || obs_age>20000) if (interval>=3600000 || obs_age>20000)
continue; continue;
if (debug&DEBUG_OVERLAYROUTING) if (config.debug.overlayrouting)
DEBUGF("adding %dms (interface %d '%s')", DEBUGF("adding %dms (interface %d '%s')",
interval,n->observations[i].sender_interface, interval,n->observations[i].sender_interface,
overlay_interfaces[n->observations[i].sender_interface].name); overlay_interfaces[n->observations[i].sender_interface].name);
@ -667,7 +668,7 @@ int overlay_route_recalc_neighbour_metrics(struct overlay_neighbour *n, time_ms_
scoreChanged=1; scoreChanged=1;
n->scores[i]=score; n->scores[i]=score;
} }
if ((debug&DEBUG_OVERLAYROUTING)&&score) if ((config.debug.overlayrouting)&&score)
DEBUGF("Neighbour score on interface #%d = %d (observations for %dms)",i,score,ms_observed_200sec[i]); DEBUGF("Neighbour score on interface #%d = %d (observations for %dms)",i,score,ms_observed_200sec[i]);
} }
if (scoreChanged) if (scoreChanged)
@ -700,7 +701,7 @@ int overlay_route_recalc_neighbour_metrics(struct overlay_neighbour *n, time_ms_
int overlay_route_saw_selfannounce_ack(struct overlay_frame *f,long long now) int overlay_route_saw_selfannounce_ack(struct overlay_frame *f,long long now)
{ {
IN(); IN();
if (debug&DEBUG_OVERLAYROUTING) if (config.debug.overlayrouting)
DEBUGF("processing selfannounce ack (payload length=%d)",f->payload->sizeLimit); DEBUGF("processing selfannounce ack (payload length=%d)",f->payload->sizeLimit);
if (f->payload->sizeLimit<9) if (f->payload->sizeLimit<9)
@ -724,14 +725,14 @@ int overlay_route_record_link(time_ms_t now, struct subscriber *to,
int gateways_en_route) int gateways_en_route)
{ {
IN(); IN();
if (debug & DEBUG_OVERLAYROUTING) if (config.debug.overlayrouting)
DEBUGF("to=%s, via=%s, sender_interface=%d, s1=%d, s2=%d score=%d gateways_en_route=%d", DEBUGF("to=%s, via=%s, sender_interface=%d, s1=%d, s2=%d score=%d gateways_en_route=%d",
alloca_tohex_sid(to->sid), alloca_tohex_sid(via->sid), sender_interface, s1, s2, alloca_tohex_sid(to->sid), alloca_tohex_sid(via->sid), sender_interface, s1, s2,
score, gateways_en_route score, gateways_en_route
); );
if (sender_interface>OVERLAY_MAX_INTERFACES || score == 0) { if (sender_interface>OVERLAY_MAX_INTERFACES || score == 0) {
if (debug & DEBUG_OVERLAYROUTING) if (config.debug.overlayrouting)
DEBUG("invalid report"); DEBUG("invalid report");
RETURN(0); RETURN(0);
} }
@ -758,10 +759,10 @@ int overlay_route_record_link(time_ms_t now, struct subscriber *to,
enough for now. */ enough for now. */
if (slot == -1) { if (slot == -1) {
slot = random() % OVERLAY_MAX_OBSERVATIONS; slot = random() % OVERLAY_MAX_OBSERVATIONS;
if (debug & DEBUG_OVERLAYROUTING) if (config.debug.overlayrouting)
DEBUGF("allocate observation slot=%d", slot); DEBUGF("allocate observation slot=%d", slot);
} else { } else {
if (debug & DEBUG_OVERLAYROUTING) if (config.debug.overlayrouting)
DEBUGF("overwrite observation slot=%d (sender=%s interface=%u observed_score=%u rx_time=%lld)", DEBUGF("overwrite observation slot=%d (sender=%s interface=%u observed_score=%u rx_time=%lld)",
slot, slot,
n->observations[slot].sender?alloca_tohex_sid(n->observations[slot].sender->sid):"[None]", n->observations[slot].sender?alloca_tohex_sid(n->observations[slot].sender->sid):"[None]",
@ -793,7 +794,7 @@ int overlay_route_record_link(time_ms_t now, struct subscriber *to,
overlay_route_recalc_node_metrics(n,now); overlay_route_recalc_node_metrics(n,now);
if (debug & DEBUG_OVERLAYROUTEMONITOR) if (config.debug.overlayroutemonitor)
overlay_route_dump(); overlay_route_dump();
RETURN(0); RETURN(0);

View File

@ -18,11 +18,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "str.h" #include "str.h"
int stowSid(unsigned char *packet, int ofs, const char *sid) int stowSid(unsigned char *packet, int ofs, const char *sid)
{ {
if (debug & DEBUG_PACKETFORMATS) if (config.debug.packetformats)
printf("stowing SID \"%s\"\n", sid); printf("stowing SID \"%s\"\n", sid);
if (strcasecmp(sid,"broadcast") == 0) if (strcasecmp(sid,"broadcast") == 0)
memset(packet + ofs, 0xff, SID_SIZE); memset(packet + ofs, 0xff, SID_SIZE);

View File

@ -67,7 +67,7 @@ int rhizome_fetch_delay_ms()
int rhizome_bundle_import_files(const char *manifest_path, const char *payload_path, int ttl) int rhizome_bundle_import_files(const char *manifest_path, const char *payload_path, int ttl)
{ {
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUGF("(manifest_path=%s, payload_path=%s, ttl=%d)", DEBUGF("(manifest_path=%s, payload_path=%s, ttl=%d)",
manifest_path ? alloca_str_toprint(manifest_path) : "NULL", manifest_path ? alloca_str_toprint(manifest_path) : "NULL",
payload_path ? alloca_str_toprint(payload_path) : "NULL", payload_path ? alloca_str_toprint(payload_path) : "NULL",
@ -107,7 +107,7 @@ int rhizome_bundle_import_files(const char *manifest_path, const char *payload_p
int rhizome_bundle_import(rhizome_manifest *m, int ttl) int rhizome_bundle_import(rhizome_manifest *m, int ttl)
{ {
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUGF("(m=%p, ttl=%d)", m, ttl); DEBUGF("(m=%p, ttl=%d)", m, ttl);
/* Add the manifest and its payload to the Rhizome database. */ /* Add the manifest and its payload to the Rhizome database. */
if (rhizome_manifest_check_file(m)) if (rhizome_manifest_check_file(m))
@ -148,7 +148,7 @@ int rhizome_manifest_check_sanity(rhizome_manifest *m_in)
} else { } else {
return WHY("Invalid service type"); return WHY("Invalid service type");
} }
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUGF("sender='%s'", sender ? sender : "(null)"); DEBUGF("sender='%s'", sender ? sender : "(null)");
/* passes all sanity checks */ /* passes all sanity checks */
@ -194,7 +194,7 @@ int rhizome_manifest_bind_id(rhizome_manifest *m_in)
if (!rhizome_secret2bk(m_in->cryptoSignPublic,rs,rs_len,bkbytes,m_in->cryptoSignSecret)) { if (!rhizome_secret2bk(m_in->cryptoSignPublic,rs,rs_len,bkbytes,m_in->cryptoSignSecret)) {
char bkhex[RHIZOME_BUNDLE_KEY_STRLEN + 1]; char bkhex[RHIZOME_BUNDLE_KEY_STRLEN + 1];
(void) tohex(bkhex, bkbytes, RHIZOME_BUNDLE_KEY_BYTES); (void) tohex(bkhex, bkbytes, RHIZOME_BUNDLE_KEY_BYTES);
if (debug&DEBUG_RHIZOME) DEBUGF("set BK=%s", bkhex); if (config.debug.rhizome) DEBUGF("set BK=%s", bkhex);
rhizome_manifest_set(m_in, "BK", bkhex); rhizome_manifest_set(m_in, "BK", bkhex);
} else { } else {
return WHY("Failed to set BK"); return WHY("Failed to set BK");
@ -221,7 +221,7 @@ int rhizome_manifest_bind_file(rhizome_manifest *m_in,const char *filename,int e
m_in->fileLength = stat.st_size; m_in->fileLength = stat.st_size;
} else } else
m_in->fileLength = 0; m_in->fileLength = 0;
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUGF("filename=%s, fileLength=%lld", filename, m_in->fileLength); DEBUGF("filename=%s, fileLength=%lld", filename, m_in->fileLength);
rhizome_manifest_set_ll(m_in,"filesize",m_in->fileLength); rhizome_manifest_set_ll(m_in,"filesize",m_in->fileLength);
@ -270,7 +270,7 @@ int rhizome_manifest_check_file(rhizome_manifest *m_in)
m_in->fileLength = stat.st_size; m_in->fileLength = stat.st_size;
} }
} }
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUGF("filename=%s, fileLength=%lld", m_in->dataFileName ? alloca_str_toprint(m_in->dataFileName) : "NULL", m_in->fileLength); DEBUGF("filename=%s, fileLength=%lld", m_in->dataFileName ? alloca_str_toprint(m_in->dataFileName) : "NULL", m_in->fileLength);
if (mfilesize != -1 && mfilesize != m_in->fileLength) { if (mfilesize != -1 && mfilesize != m_in->fileLength) {
WHYF("Manifest.filesize (%lld) != actual file size (%lld)", mfilesize, m_in->fileLength); WHYF("Manifest.filesize (%lld) != actual file size (%lld)", mfilesize, m_in->fileLength);
@ -306,7 +306,7 @@ int rhizome_manifest_check_file(rhizome_manifest *m_in)
(Debounce!) */ (Debounce!) */
int rhizome_manifest_check_duplicate(rhizome_manifest *m_in, rhizome_manifest **m_out) int rhizome_manifest_check_duplicate(rhizome_manifest *m_in, rhizome_manifest **m_out)
{ {
if (debug & DEBUG_RHIZOME) DEBUG("Checking for duplicate"); if (config.debug.rhizome) DEBUG("Checking for duplicate");
if (m_out) *m_out = NULL; if (m_out) *m_out = NULL;
rhizome_manifest *dupm = NULL; rhizome_manifest *dupm = NULL;
if (rhizome_find_duplicate(m_in, &dupm,0 /* version doesn't matter */) == -1) if (rhizome_find_duplicate(m_in, &dupm,0 /* version doesn't matter */) == -1)
@ -318,16 +318,16 @@ int rhizome_manifest_check_duplicate(rhizome_manifest *m_in, rhizome_manifest **
} }
else else
rhizome_manifest_free(dupm); rhizome_manifest_free(dupm);
if (debug & DEBUG_RHIZOME) DEBUG("Found a duplicate"); if (config.debug.rhizome) DEBUG("Found a duplicate");
return 2; return 2;
} }
if (debug & DEBUG_RHIZOME) DEBUG("No duplicate found"); if (config.debug.rhizome) DEBUG("No duplicate found");
return 0; return 0;
} }
int rhizome_add_manifest(rhizome_manifest *m_in,int ttl) int rhizome_add_manifest(rhizome_manifest *m_in,int ttl)
{ {
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUGF("rhizome_add_manifest(m_in=%p, ttl=%d)",m_in, ttl); DEBUGF("rhizome_add_manifest(m_in=%p, ttl=%d)",m_in, ttl);
if (m_in->finalised==0) if (m_in->finalised==0)
@ -363,10 +363,10 @@ int rhizome_add_manifest(rhizome_manifest *m_in,int ttl)
case -1: case -1:
return WHY("Select failed"); return WHY("Select failed");
case 0: case 0:
if (debug & DEBUG_RHIZOME) DEBUG("No existing manifest"); if (config.debug.rhizome) DEBUG("No existing manifest");
break; break;
case 1: case 1:
if (debug & DEBUG_RHIZOME) DEBUGF("Found existing version=%lld, new version=%lld", storedversion, m_in->version); if (config.debug.rhizome) DEBUGF("Found existing version=%lld, new version=%lld", storedversion, m_in->version);
if (m_in->version < storedversion) if (m_in->version < storedversion)
return WHY("Newer version exists"); return WHY("Newer version exists");
if (m_in->version == storedversion) if (m_in->version == storedversion)

View File

@ -265,7 +265,9 @@ __RHIZOME_INLINE int sqlite_code_busy(int code)
return code == SQLITE_BUSY || code == SQLITE_LOCKED; return code == SQLITE_BUSY || code == SQLITE_LOCKED;
} }
debugflags_t sqlite_set_debugmask(debugflags_t newmask); int (*sqlite_set_tracefunc(int (*newfunc)()))();
int is_debug_rhizome();
int is_debug_rhizome_ads();
sqlite3_stmt *_sqlite_prepare(struct __sourceloc __whence, sqlite_retry_state *retry, const char *sqlformat, ...); sqlite3_stmt *_sqlite_prepare(struct __sourceloc __whence, sqlite_retry_state *retry, const char *sqlformat, ...);
sqlite3_stmt *_sqlite_prepare_loglevel(struct __sourceloc __whence, int log_level, sqlite_retry_state *retry, strbuf stmt); sqlite3_stmt *_sqlite_prepare_loglevel(struct __sourceloc __whence, int log_level, sqlite_retry_state *retry, strbuf stmt);

View File

@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <stdlib.h> #include <stdlib.h>
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "rhizome.h" #include "rhizome.h"
#include "str.h" #include "str.h"
@ -38,7 +39,7 @@ int rhizome_manifest_verify(rhizome_manifest *m)
/* Read signature blocks from file. */ /* Read signature blocks from file. */
int ofs=end_of_text; int ofs=end_of_text;
while(ofs<m->manifest_all_bytes) { while(ofs<m->manifest_all_bytes) {
if (debug & DEBUG_RHIZOME) DEBUGF("ofs=0x%x, m->manifest_bytes=0x%x", ofs,m->manifest_all_bytes); if (config.debug.rhizome) DEBUGF("ofs=0x%x, m->manifest_bytes=0x%x", ofs,m->manifest_all_bytes);
if (rhizome_manifest_extract_signature(m,&ofs)) break; if (rhizome_manifest_extract_signature(m,&ofs)) break;
} }
@ -58,7 +59,7 @@ int rhizome_manifest_verify(rhizome_manifest *m)
WARN("Invalid manifest 'id' field"); WARN("Invalid manifest 'id' field");
m->errors++; m->errors++;
} else if (m->sig_count == 0 || memcmp(m->signatories[0], manifest_id, RHIZOME_MANIFEST_ID_BYTES) != 0) { } else if (m->sig_count == 0 || memcmp(m->signatories[0], manifest_id, RHIZOME_MANIFEST_ID_BYTES) != 0) {
if (debug&DEBUG_RHIZOME) { if (config.debug.rhizome) {
if (m->sig_count>0) { if (m->sig_count>0) {
DEBUGF("Manifest id variable does not match first signature block (signature key is %s)", DEBUGF("Manifest id variable does not match first signature block (signature key is %s)",
alloca_tohex(m->signatories[0], crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES) alloca_tohex(m->signatories[0], crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES)
@ -487,7 +488,7 @@ rhizome_manifest *_rhizome_new_manifest(struct __sourceloc __whence)
for (; manifest_first_free < MAX_RHIZOME_MANIFESTS && !manifest_free[manifest_first_free]; ++manifest_first_free) for (; manifest_first_free < MAX_RHIZOME_MANIFESTS && !manifest_free[manifest_first_free]; ++manifest_first_free)
; ;
if (debug & DEBUG_MANIFESTS) _log_manifest_trace(__whence, __FUNCTION__); if (config.debug.manifests) _log_manifest_trace(__whence, __FUNCTION__);
return m; return m;
} }
@ -536,7 +537,7 @@ void _rhizome_manifest_free(struct __sourceloc __whence, rhizome_manifest *m)
manifest_free_whence[mid]=__whence; manifest_free_whence[mid]=__whence;
if (mid<manifest_first_free) manifest_first_free=mid; if (mid<manifest_first_free) manifest_first_free=mid;
if (debug & DEBUG_MANIFESTS) _log_manifest_trace(__whence, __FUNCTION__); if (config.debug.manifests) _log_manifest_trace(__whence, __FUNCTION__);
return; return;
} }
@ -558,7 +559,7 @@ int rhizome_manifest_pack_variables(rhizome_manifest *m)
} }
m->manifestdata[ofs++]=0x00; m->manifestdata[ofs++]=0x00;
m->manifest_bytes=ofs; m->manifest_bytes=ofs;
if (debug&DEBUG_RHIZOME) DEBUG("Repacked variables in manifest."); if (config.debug.rhizome) DEBUG("Repacked variables in manifest.");
m->manifest_all_bytes=ofs; m->manifest_all_bytes=ofs;
/* Recalculate hash */ /* Recalculate hash */
@ -588,7 +589,7 @@ int rhizome_manifest_selfsign(rhizome_manifest *m)
int rhizome_write_manifest_file(rhizome_manifest *m, const char *filename) int rhizome_write_manifest_file(rhizome_manifest *m, const char *filename)
{ {
if (debug & DEBUG_RHIZOME) DEBUGF("write manifest (%d bytes) to %s", m->manifest_all_bytes, filename); if (config.debug.rhizome) DEBUGF("write manifest (%d bytes) to %s", m->manifest_all_bytes, filename);
if (!m) return WHY("Manifest is null."); if (!m) return WHY("Manifest is null.");
if (!m->finalised) return WHY("Manifest must be finalised before it can be written."); if (!m->finalised) return WHY("Manifest must be finalised before it can be written.");
FILE *f = fopen(filename, "w"); FILE *f = fopen(filename, "w");

View File

@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "str.h" #include "str.h"
#include "rhizome.h" #include "rhizome.h"
#include <stdlib.h> #include <stdlib.h>
@ -140,13 +141,13 @@ int rhizome_find_secret(const unsigned char *authorSid, int *rs_len, const unsig
{ {
int cn=0, in=0, kp=0; int cn=0, in=0, kp=0;
if (!keyring_find_sid(keyring,&cn,&in,&kp,authorSid)) { if (!keyring_find_sid(keyring,&cn,&in,&kp,authorSid)) {
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUGF("identity sid=%s is not in keyring", alloca_tohex_sid(authorSid)); DEBUGF("identity sid=%s is not in keyring", alloca_tohex_sid(authorSid));
return 2; return 2;
} }
kp = keyring_identity_find_keytype(keyring, cn, in, KEYTYPE_RHIZOME); kp = keyring_identity_find_keytype(keyring, cn, in, KEYTYPE_RHIZOME);
if (kp == -1) { if (kp == -1) {
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUGF("identity sid=%s has no Rhizome Secret", alloca_tohex_sid(authorSid)); DEBUGF("identity sid=%s has no Rhizome Secret", alloca_tohex_sid(authorSid));
return 3; return 3;
} }
@ -207,7 +208,7 @@ int rhizome_extract_privatekey(rhizome_manifest *m)
IN(); IN();
char *bk = rhizome_manifest_get(m, "BK", NULL, 0); char *bk = rhizome_manifest_get(m, "BK", NULL, 0);
if (!bk) { if (!bk) {
if (debug & DEBUG_RHIZOME) DEBUG("bundle contains no BK field"); if (config.debug.rhizome) DEBUG("bundle contains no BK field");
RETURN(1); RETURN(1);
} }
unsigned char bkBytes[RHIZOME_BUNDLE_KEY_BYTES]; unsigned char bkBytes[RHIZOME_BUNDLE_KEY_BYTES];
@ -229,7 +230,7 @@ int rhizome_extract_privatekey(rhizome_manifest *m)
} }
memset(m->cryptoSignSecret, 0, sizeof m->cryptoSignSecret); memset(m->cryptoSignSecret, 0, sizeof m->cryptoSignSecret);
m->haveSecret=0; m->haveSecret=0;
if (debug & DEBUG_RHIZOME) DEBUGF("result=%d", result); if (config.debug.rhizome) DEBUGF("result=%d", result);
RETURN(result); RETURN(result);
} }
@ -253,7 +254,7 @@ int rhizome_find_bundle_author(rhizome_manifest *m)
IN(); IN();
char *bk = rhizome_manifest_get(m, "BK", NULL, 0); char *bk = rhizome_manifest_get(m, "BK", NULL, 0);
if (!bk) { if (!bk) {
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUGF("missing BK field"); DEBUGF("missing BK field");
RETURN(4); RETURN(4);
} }
@ -263,7 +264,7 @@ int rhizome_find_bundle_author(rhizome_manifest *m)
int cn = 0, in = 0, kp = 0; int cn = 0, in = 0, kp = 0;
for (; keyring_next_identity(keyring, &cn, &in, &kp); ++kp) { for (; keyring_next_identity(keyring, &cn, &in, &kp); ++kp) {
const unsigned char *authorSid = keyring->contexts[cn]->identities[in]->keypairs[kp]->public_key; const unsigned char *authorSid = keyring->contexts[cn]->identities[in]->keypairs[kp]->public_key;
//if (debug & DEBUG_RHIZOME) DEBUGF("try author identity sid=%s", alloca_tohex(authorSid, SID_SIZE)); //if (config.debug.rhizome) DEBUGF("try author identity sid=%s", alloca_tohex(authorSid, SID_SIZE));
int rkp = keyring_identity_find_keytype(keyring, cn, in, KEYTYPE_RHIZOME); int rkp = keyring_identity_find_keytype(keyring, cn, in, KEYTYPE_RHIZOME);
if (rkp != -1) { if (rkp != -1) {
int rs_len = keyring->contexts[cn]->identities[in]->keypairs[rkp]->private_key_len; int rs_len = keyring->contexts[cn]->identities[in]->keypairs[rkp]->private_key_len;
@ -275,13 +276,13 @@ int rhizome_find_bundle_author(rhizome_manifest *m)
bkBytes,m->cryptoSignSecret)) { bkBytes,m->cryptoSignSecret)) {
memcpy(m->author, authorSid, sizeof m->author); memcpy(m->author, authorSid, sizeof m->author);
m->haveSecret=1; m->haveSecret=1;
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUGF("found bundle author sid=%s", alloca_tohex_sid(m->author)); DEBUGF("found bundle author sid=%s", alloca_tohex_sid(m->author));
RETURN(0); // bingo RETURN(0); // bingo
} }
} }
} }
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUG("bundle author not found"); DEBUG("bundle author not found");
RETURN(1); RETURN(1);
} }
@ -321,7 +322,7 @@ int rhizome_verify_bundle_privatekey(rhizome_manifest *m,
m->haveSecret=0; m->haveSecret=0;
RETURN(-1); RETURN(-1);
} }
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUGF("We have the private key for this bundle."); DEBUGF("We have the private key for this bundle.");
if (m&&sk==m->cryptoSignSecret&&pkin==m->cryptoSignPublic) { if (m&&sk==m->cryptoSignSecret&&pkin==m->cryptoSignPublic) {
DEBUGF("Set haveSecret=1 in manifest"); DEBUGF("Set haveSecret=1 in manifest");
@ -428,7 +429,7 @@ int rhizome_manifest_extract_signature(rhizome_manifest *m,int *ofs)
IN(); IN();
if (!m) if (!m)
RETURN(WHY("NULL pointer passed in as manifest")); RETURN(WHY("NULL pointer passed in as manifest"));
if (debug&DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUGF("m->manifest_all_bytes=%d m->manifest_bytes=%d *ofs=%d", m->manifest_all_bytes, m->manifest_bytes, *ofs); DEBUGF("m->manifest_all_bytes=%d m->manifest_bytes=%d *ofs=%d", m->manifest_all_bytes, m->manifest_bytes, *ofs);
if ((*ofs)>=m->manifest_all_bytes) { RETURN(0); } if ((*ofs)>=m->manifest_all_bytes) { RETURN(0); }
@ -474,7 +475,7 @@ int rhizome_manifest_extract_signature(rhizome_manifest *m,int *ofs)
bcopy(&m->manifestdata[(*ofs)+1+64],m->signatories[m->sig_count], bcopy(&m->manifestdata[(*ofs)+1+64],m->signatories[m->sig_count],
crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES); crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES);
m->sig_count++; m->sig_count++;
if (debug&DEBUG_RHIZOME) DEBUG("Signature passed."); if (config.debug.rhizome) DEBUG("Signature passed.");
} }
break; break;
default: default:

View File

@ -83,7 +83,7 @@ int form_rhizome_import_path(char * buf, size_t bufsiz, const char *fmt, ...)
int create_rhizome_datastore_dir() int create_rhizome_datastore_dir()
{ {
if (debug & DEBUG_RHIZOME) DEBUGF("mkdirs(%s, 0700)", rhizome_datastore_path()); if (config.debug.rhizome) DEBUGF("mkdirs(%s, 0700)", rhizome_datastore_path());
return mkdirs(rhizome_datastore_path(), 0700); return mkdirs(rhizome_datastore_path(), 0700);
} }
@ -92,7 +92,7 @@ int create_rhizome_import_dir()
char dirname[1024]; char dirname[1024];
if (!form_rhizome_import_path(dirname, sizeof dirname, NULL)) if (!form_rhizome_import_path(dirname, sizeof dirname, NULL))
return -1; return -1;
if (debug & DEBUG_RHIZOME) DEBUGF("mkdirs(%s, 0700)", dirname); if (config.debug.rhizome) DEBUGF("mkdirs(%s, 0700)", dirname);
return mkdirs(dirname, 0700); return mkdirs(dirname, 0700);
} }
@ -114,12 +114,22 @@ int rhizome_manifest_priority(sqlite_retry_state *retry, const char *id)
return (int) result; return (int) result;
} }
debugflags_t sqlite_trace_debug = DEBUG_RHIZOME; int is_debug_rhizome()
{
return config.debug.rhizome;
}
int is_debug_rhizome_ads()
{
return config.debug.rhizome_ads;
}
static int (*sqlite_trace_func)() = is_debug_rhizome;
const struct __sourceloc *sqlite_trace_whence = NULL; const struct __sourceloc *sqlite_trace_whence = NULL;
static void sqlite_trace_callback(void *context, const char *rendered_sql) static void sqlite_trace_callback(void *context, const char *rendered_sql)
{ {
if (debug & sqlite_trace_debug) if (sqlite_trace_func())
logMessage(LOG_LEVEL_DEBUG, sqlite_trace_whence ? *sqlite_trace_whence : __HERE__, "%s", rendered_sql); logMessage(LOG_LEVEL_DEBUG, sqlite_trace_whence ? *sqlite_trace_whence : __HERE__, "%s", rendered_sql);
} }
@ -139,11 +149,11 @@ static void sqlite_trace_callback(void *context, const char *rendered_sql)
* *
* @author Andrew Bettison <andrew@servalproject.com> * @author Andrew Bettison <andrew@servalproject.com>
*/ */
debugflags_t sqlite_set_debugmask(debugflags_t newmask) int (*sqlite_set_tracefunc(int (*newfunc)()))()
{ {
debugflags_t oldmask = sqlite_trace_debug; int (*oldfunc)() = sqlite_trace_func;
sqlite_trace_debug = newmask; sqlite_trace_func = newfunc;
return oldmask; return oldfunc;
} }
/* /*
@ -188,10 +198,10 @@ int rhizome_opendb()
RETURN(WHYF("SQLite could not open database %s: %s", dbpath, sqlite3_errmsg(rhizome_db))); RETURN(WHYF("SQLite could not open database %s: %s", dbpath, sqlite3_errmsg(rhizome_db)));
} }
sqlite3_trace(rhizome_db, sqlite_trace_callback, NULL); sqlite3_trace(rhizome_db, sqlite_trace_callback, NULL);
int loglevel = (debug & DEBUG_RHIZOME) ? LOG_LEVEL_DEBUG : LOG_LEVEL_SILENT; int loglevel = (config.debug.rhizome) ? LOG_LEVEL_DEBUG : LOG_LEVEL_SILENT;
/* Read Rhizome configuration */ /* Read Rhizome configuration */
if (debug&DEBUG_RHIZOME) { if (config.debug.rhizome) {
DEBUGF("Rhizome will use %lluB of storage for its database.", (unsigned long long) config.rhizome.database_size); DEBUGF("Rhizome will use %lluB of storage for its database.", (unsigned long long) config.rhizome.database_size);
} }
/* Create tables as required */ /* Create tables as required */
@ -658,7 +668,7 @@ int rhizome_drop_stored_file(const char *id,int maximum_priority)
WHYF("Cannot drop fileid=%s due to manifest priority, manifestId=%s", id, manifestId); WHYF("Cannot drop fileid=%s due to manifest priority, manifestId=%s", id, manifestId);
can_drop = 0; can_drop = 0;
} else { } else {
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUGF("removing stale manifests, groupmemberships"); DEBUGF("removing stale manifests, groupmemberships");
sqlite_exec_void_retry(&retry, "delete from manifests where id='%s';", manifestId); sqlite_exec_void_retry(&retry, "delete from manifests where id='%s';", manifestId);
sqlite_exec_void_retry(&retry, "delete from keypairs where public='%s';", manifestId); sqlite_exec_void_retry(&retry, "delete from keypairs where public='%s';", manifestId);
@ -905,20 +915,20 @@ int rhizome_list_manifests(const char *service, const char *sender_sid, const ch
long long blob_filesize = rhizome_manifest_get_ll(m, "filesize"); long long blob_filesize = rhizome_manifest_get_ll(m, "filesize");
int from_here = 0; int from_here = 0;
if (q_author) { if (q_author) {
if (debug & DEBUG_RHIZOME) DEBUGF("q_author=%s", alloca_str_toprint(q_author)); if (config.debug.rhizome) DEBUGF("q_author=%s", alloca_str_toprint(q_author));
unsigned char authorSid[SID_SIZE]; unsigned char authorSid[SID_SIZE];
stowSid(authorSid, 0, q_author); stowSid(authorSid, 0, q_author);
int cn = 0, in = 0, kp = 0; int cn = 0, in = 0, kp = 0;
from_here = keyring_find_sid(keyring, &cn, &in, &kp, authorSid); from_here = keyring_find_sid(keyring, &cn, &in, &kp, authorSid);
} }
if (!from_here && blob_sender) { if (!from_here && blob_sender) {
if (debug & DEBUG_RHIZOME) DEBUGF("blob_sender=%s", alloca_str_toprint(blob_sender)); if (config.debug.rhizome) DEBUGF("blob_sender=%s", alloca_str_toprint(blob_sender));
unsigned char senderSid[SID_SIZE]; unsigned char senderSid[SID_SIZE];
stowSid(senderSid, 0, blob_sender); stowSid(senderSid, 0, blob_sender);
int cn = 0, in = 0, kp = 0; int cn = 0, in = 0, kp = 0;
from_here = keyring_find_sid(keyring, &cn, &in, &kp, senderSid); from_here = keyring_find_sid(keyring, &cn, &in, &kp, senderSid);
} }
if (debug & DEBUG_RHIZOME) DEBUGF("manifest payload size = %lld", blob_filesize); if (config.debug.rhizome) DEBUGF("manifest payload size = %lld", blob_filesize);
cli_puts(blob_service ? blob_service : ""); cli_delim(":"); cli_puts(blob_service ? blob_service : ""); cli_delim(":");
cli_puts(q_manifestid); cli_delim(":"); cli_puts(q_manifestid); cli_delim(":");
cli_printf("%lld", blob_version); cli_delim(":"); cli_printf("%lld", blob_version); cli_delim(":");
@ -1238,7 +1248,7 @@ int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found,
if (m->fileLength != 0) { if (m->fileLength != 0) {
strncpy(filehash, m->fileHexHash, sizeof filehash); strncpy(filehash, m->fileHexHash, sizeof filehash);
str_toupper_inplace(filehash); str_toupper_inplace(filehash);
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUGF("filehash=\"%s\"", filehash); DEBUGF("filehash=\"%s\"", filehash);
sqlite3_bind_text(statement, field++, filehash, -1, SQLITE_STATIC); sqlite3_bind_text(statement, field++, filehash, -1, SQLITE_STATIC);
} }
@ -1247,7 +1257,7 @@ int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found,
size_t rows = 0; size_t rows = 0;
while (sqlite_step_retry(&retry, statement) == SQLITE_ROW) { while (sqlite_step_retry(&retry, statement) == SQLITE_ROW) {
++rows; ++rows;
if (debug & DEBUG_RHIZOME) DEBUGF("Row %d", rows); if (config.debug.rhizome) DEBUGF("Row %d", rows);
if (!( sqlite3_column_count(statement) == 4 if (!( sqlite3_column_count(statement) == 4
&& sqlite3_column_type(statement, 0) == SQLITE_TEXT && sqlite3_column_type(statement, 0) == SQLITE_TEXT
&& sqlite3_column_type(statement, 1) == SQLITE_BLOB && sqlite3_column_type(statement, 1) == SQLITE_BLOB
@ -1286,7 +1296,7 @@ int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found,
long long blob_version = rhizome_manifest_get_ll(blob_m, "version"); long long blob_version = rhizome_manifest_get_ll(blob_m, "version");
const char *blob_filehash = rhizome_manifest_get(blob_m, "filehash", NULL, 0); const char *blob_filehash = rhizome_manifest_get(blob_m, "filehash", NULL, 0);
long long blob_filesize = rhizome_manifest_get_ll(blob_m, "filesize"); long long blob_filesize = rhizome_manifest_get_ll(blob_m, "filesize");
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUGF("Consider manifest.service=%s manifest.id=%s manifest.version=%lld", blob_service, q_manifestid, blob_version); DEBUGF("Consider manifest.service=%s manifest.id=%s manifest.version=%lld", blob_service, q_manifestid, blob_version);
/* Perform consistency checks, because we're paranoid. */ /* Perform consistency checks, because we're paranoid. */
int inconsistent = 0; int inconsistent = 0;
@ -1330,7 +1340,7 @@ int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found,
if (strcasecmp(service, RHIZOME_SERVICE_FILE) == 0) { if (strcasecmp(service, RHIZOME_SERVICE_FILE) == 0) {
const char *blob_name = rhizome_manifest_get(blob_m, "name", NULL, 0); const char *blob_name = rhizome_manifest_get(blob_m, "name", NULL, 0);
if (blob_name && !strcmp(blob_name, name)) { if (blob_name && !strcmp(blob_name, name)) {
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
strbuf_sprintf(b, " name=\"%s\"", blob_name); strbuf_sprintf(b, " name=\"%s\"", blob_name);
ret = 1; ret = 1;
} }
@ -1338,7 +1348,7 @@ int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found,
const char *blob_sender = rhizome_manifest_get(blob_m, "sender", NULL, 0); const char *blob_sender = rhizome_manifest_get(blob_m, "sender", NULL, 0);
const char *blob_recipient = rhizome_manifest_get(blob_m, "recipient", NULL, 0); const char *blob_recipient = rhizome_manifest_get(blob_m, "recipient", NULL, 0);
if (blob_sender && !strcasecmp(blob_sender, sender) && blob_recipient && !strcasecmp(blob_recipient, recipient)) { if (blob_sender && !strcasecmp(blob_sender, sender) && blob_recipient && !strcasecmp(blob_recipient, recipient)) {
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
strbuf_sprintf(b, " sender=%s recipient=%s", blob_sender, blob_recipient); strbuf_sprintf(b, " sender=%s recipient=%s", blob_sender, blob_recipient);
ret = 1; ret = 1;
} }
@ -1346,7 +1356,7 @@ int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found,
if (ret == 1) { if (ret == 1) {
const char *q_author = (const char *) sqlite3_column_text(statement, 3); const char *q_author = (const char *) sqlite3_column_text(statement, 3);
if (q_author) { if (q_author) {
if (debug & DEBUG_RHIZOME) if (config.debug.rhizome)
strbuf_sprintf(b, " .author=%s", q_author); strbuf_sprintf(b, " .author=%s", q_author);
stowSid(blob_m->author, 0, q_author); stowSid(blob_m->author, 0, q_author);
} }

View File

@ -801,7 +801,7 @@ int rhizome_direct_get_bars(const unsigned char bid_low[RHIZOME_MANIFEST_ID_BYTE
int blob_bytes=sqlite3_blob_bytes(blob); int blob_bytes=sqlite3_blob_bytes(blob);
if (blob_bytes!=RHIZOME_BAR_BYTES) { if (blob_bytes!=RHIZOME_BAR_BYTES) {
if (debug&DEBUG_RHIZOME) if (config.debug.rhizome)
DEBUG("Found a BAR that is the wrong size - ignoring"); DEBUG("Found a BAR that is the wrong size - ignoring");
sqlite3_blob_close(blob); sqlite3_blob_close(blob);
blob=NULL; blob=NULL;

View File

@ -230,22 +230,22 @@ int rhizome_direct_form_received(rhizome_http_request *r)
const char *service = rhizome_manifest_get(m, "service", NULL, 0); const char *service = rhizome_manifest_get(m, "service", NULL, 0);
if (service == NULL) { if (service == NULL) {
rhizome_manifest_set(m, "service", (service = RHIZOME_SERVICE_FILE)); rhizome_manifest_set(m, "service", (service = RHIZOME_SERVICE_FILE));
if (debug & DEBUG_RHIZOME) DEBUGF("missing 'service', set default service=%s", service); if (config.debug.rhizome) DEBUGF("missing 'service', set default service=%s", service);
} else { } else {
if (debug & DEBUG_RHIZOME) DEBUGF("manifest contains service=%s", service); if (config.debug.rhizome) DEBUGF("manifest contains service=%s", service);
} }
if (rhizome_manifest_get(m, "date", NULL, 0) == NULL) { if (rhizome_manifest_get(m, "date", NULL, 0) == NULL) {
rhizome_manifest_set_ll(m, "date", (long long) gettime_ms()); rhizome_manifest_set_ll(m, "date", (long long) gettime_ms());
if (debug & DEBUG_RHIZOME) DEBUGF("missing 'date', set default date=%s", rhizome_manifest_get(m, "date", NULL, 0)); if (config.debug.rhizome) DEBUGF("missing 'date', set default date=%s", rhizome_manifest_get(m, "date", NULL, 0));
} }
const char *name = rhizome_manifest_get(m, "name", NULL, 0); const char *name = rhizome_manifest_get(m, "name", NULL, 0);
if (name == NULL) { if (name == NULL) {
name=r->data_file_name; name=r->data_file_name;
rhizome_manifest_set(m, "name", r->data_file_name); rhizome_manifest_set(m, "name", r->data_file_name);
if (debug & DEBUG_RHIZOME) DEBUGF("missing 'name', set name=\"%s\" from HTTP post field filename specification", name); if (config.debug.rhizome) DEBUGF("missing 'name', set name=\"%s\" from HTTP post field filename specification", name);
} else { } else {
if (debug & DEBUG_RHIZOME) DEBUGF("manifest contains name=\"%s\"", name); if (config.debug.rhizome) DEBUGF("manifest contains name=\"%s\"", name);
} }
const char *senderhex = rhizome_manifest_get(m, "sender", NULL, 0); const char *senderhex = rhizome_manifest_get(m, "sender", NULL, 0);
@ -610,12 +610,12 @@ int rhizome_direct_parse_http_request(rhizome_http_request *r)
} }
} }
if (content == NULL) { if (content == NULL) {
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUGF("Received malformed HTTP request %s", alloca_toprint(160, (const char *)r->request, r->request_length)); DEBUGF("Received malformed HTTP request %s", alloca_toprint(160, (const char *)r->request, r->request_length));
return rhizome_server_simple_http_response(r, 400, "<html><h1>Malformed request</h1></html>\r\n"); return rhizome_server_simple_http_response(r, 400, "<html><h1>Malformed request</h1></html>\r\n");
} }
INFOF("RHIZOME HTTP SERVER, %s %s %s", verb, alloca_toprint(-1, path, pathlen), proto); INFOF("RHIZOME HTTP SERVER, %s %s %s", verb, alloca_toprint(-1, path, pathlen), proto);
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUGF("headers %s", alloca_toprint(-1, headers, headerlen)); DEBUGF("headers %s", alloca_toprint(-1, headers, headerlen));
if (strcmp(verb, "GET") == 0 && strcmp(path, "/favicon.ico") == 0) { if (strcmp(verb, "GET") == 0 && strcmp(path, "/favicon.ico") == 0) {
r->request_type = RHIZOME_HTTP_REQUEST_FAVICON; r->request_type = RHIZOME_HTTP_REQUEST_FAVICON;
@ -702,7 +702,7 @@ static int receive_http_response(int sock, char *buffer, size_t buffer_len, stru
return WHYF_perror("read(%d, %p, %d)", sock, &buffer[len], buffer_len - len); return WHYF_perror("read(%d, %p, %d)", sock, &buffer[len], buffer_len - len);
len += count; len += count;
} while (len < buffer_len && count != 0 && !http_header_complete(buffer, len, len)); } while (len < buffer_len && count != 0 && !http_header_complete(buffer, len, len));
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Received HTTP response %s", alloca_toprint(-1, buffer, len)); DEBUGF("Received HTTP response %s", alloca_toprint(-1, buffer, len));
if (unpack_http_response(buffer, parts) == -1) if (unpack_http_response(buffer, parts) == -1)
return -1; return -1;
@ -711,7 +711,7 @@ static int receive_http_response(int sock, char *buffer, size_t buffer_len, stru
return -1; return -1;
} }
if (parts->content_length == -1) { if (parts->content_length == -1) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Invalid HTTP reply: missing Content-Length header"); DEBUGF("Invalid HTTP reply: missing Content-Length header");
return -1; return -1;
} }

View File

@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <arpa/inet.h> #include <arpa/inet.h>
#include <assert.h> #include <assert.h>
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "rhizome.h" #include "rhizome.h"
#include "str.h" #include "str.h"
#include "strbuf_helpers.h" #include "strbuf_helpers.h"
@ -182,7 +183,7 @@ static struct rhizome_fetch_candidate *rhizome_fetch_insert(struct rhizome_fetch
{ {
struct rhizome_fetch_candidate * const c = &q->candidate_queue[i]; struct rhizome_fetch_candidate * const c = &q->candidate_queue[i];
struct rhizome_fetch_candidate * e = &q->candidate_queue[q->candidate_queue_size - 1]; struct rhizome_fetch_candidate * e = &q->candidate_queue[q->candidate_queue_size - 1];
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("insert queue[%d] candidate[%d]", q - rhizome_fetch_queues, i); DEBUGF("insert queue[%d] candidate[%d]", q - rhizome_fetch_queues, i);
assert(i >= 0 && i < q->candidate_queue_size); assert(i >= 0 && i < q->candidate_queue_size);
assert(i == 0 || c[-1].manifest); assert(i == 0 || c[-1].manifest);
@ -208,7 +209,7 @@ static void rhizome_fetch_unqueue(struct rhizome_fetch_queue *q, int i)
{ {
assert(i >= 0 && i < q->candidate_queue_size); assert(i >= 0 && i < q->candidate_queue_size);
struct rhizome_fetch_candidate *c = &q->candidate_queue[i]; struct rhizome_fetch_candidate *c = &q->candidate_queue[i];
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("unqueue queue[%d] candidate[%d] manifest=%p", q - rhizome_fetch_queues, i, c->manifest); DEBUGF("unqueue queue[%d] candidate[%d] manifest=%p", q - rhizome_fetch_queues, i, c->manifest);
if (c->manifest) { if (c->manifest) {
rhizome_manifest_free(c->manifest); rhizome_manifest_free(c->manifest);
@ -496,7 +497,7 @@ static int rhizome_import_received_bundle(struct rhizome_manifest *m)
{ {
m->finalised = 1; m->finalised = 1;
m->manifest_bytes = m->manifest_all_bytes; // store the signatures too m->manifest_bytes = m->manifest_all_bytes; // store the signatures too
if (debug & DEBUG_RHIZOME_RX) { if (config.debug.rhizome_rx) {
DEBUGF("manifest len=%d has %d signatories. Associated file = %lld bytes", DEBUGF("manifest len=%d has %d signatories. Associated file = %lld bytes",
m->manifest_bytes, m->sig_count,(long long)m->fileLength); m->manifest_bytes, m->sig_count,(long long)m->fileLength);
dump("manifest", m->manifestdata, m->manifest_all_bytes); dump("manifest", m->manifestdata, m->manifest_all_bytes);
@ -555,7 +556,7 @@ static int schedule_fetch(struct rhizome_fetch_slot *slot)
if (connect(sock, (struct sockaddr*)&slot->peer_ipandport, if (connect(sock, (struct sockaddr*)&slot->peer_ipandport,
sizeof slot->peer_ipandport) == -1) { sizeof slot->peer_ipandport) == -1) {
if (errno == EINPROGRESS) { if (errno == EINPROGRESS) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("connect() returned EINPROGRESS"); DEBUGF("connect() returned EINPROGRESS");
} else { } else {
WHYF_perror("connect(%d, %s:%u)", sock, buf, WHYF_perror("connect(%d, %s:%u)", sock, buf,
@ -563,7 +564,7 @@ static int schedule_fetch(struct rhizome_fetch_slot *slot)
goto bail_http; goto bail_http;
} }
} }
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("RHIZOME HTTP REQUEST family=%u addr=%s sid=%s port=%u %s", DEBUGF("RHIZOME HTTP REQUEST family=%u addr=%s sid=%s port=%u %s",
slot->peer_ipandport.sin_family, slot->peer_ipandport.sin_family,
alloca_tohex_sid(slot->peer_sid), alloca_tohex_sid(slot->peer_sid),
@ -653,7 +654,7 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m, const struct
the cache slot number to implicitly store the first bits. the cache slot number to implicitly store the first bits.
*/ */
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Fetching bundle slot=%d bid=%s version=%lld size=%lld peerip=%s", DEBUGF("Fetching bundle slot=%d bid=%s version=%lld size=%lld peerip=%s",
slotno(slot), slotno(slot),
bid, bid,
@ -664,7 +665,7 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m, const struct
// If the payload is empty, no need to fetch, so import now. // If the payload is empty, no need to fetch, so import now.
if (m->fileLength == 0) { if (m->fileLength == 0) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF(" manifest fetch not started -- nil payload, so importing instead"); DEBUGF(" manifest fetch not started -- nil payload, so importing instead");
if (rhizome_import_received_bundle(m) == -1) if (rhizome_import_received_bundle(m) == -1)
return WHY("bundle import failed"); return WHY("bundle import failed");
@ -673,11 +674,11 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m, const struct
// If we already have this version or newer, do not fetch. // If we already have this version or newer, do not fetch.
if (rhizome_manifest_version_cache_lookup(m)) { if (rhizome_manifest_version_cache_lookup(m)) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUG(" fetch not started -- already have that version or newer"); DEBUG(" fetch not started -- already have that version or newer");
return SUPERSEDED; return SUPERSEDED;
} }
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF(" is new"); DEBUGF(" is new");
/* Don't fetch if already in progress. If a fetch of an older version is already in progress, /* Don't fetch if already in progress. If a fetch of an older version is already in progress,
@ -691,15 +692,15 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m, const struct
const rhizome_manifest *am = as->manifest; const rhizome_manifest *am = as->manifest;
if (as->state != RHIZOME_FETCH_FREE && memcmp(m->cryptoSignPublic, am->cryptoSignPublic, RHIZOME_MANIFEST_ID_BYTES) == 0) { if (as->state != RHIZOME_FETCH_FREE && memcmp(m->cryptoSignPublic, am->cryptoSignPublic, RHIZOME_MANIFEST_ID_BYTES) == 0) {
if (am->version < m->version) { if (am->version < m->version) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF(" fetch already in progress -- older version"); DEBUGF(" fetch already in progress -- older version");
return OLDERBUNDLE; return OLDERBUNDLE;
} else if (am->version > m->version) { } else if (am->version > m->version) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF(" fetch already in progress -- newer version"); DEBUGF(" fetch already in progress -- newer version");
return NEWERBUNDLE; return NEWERBUNDLE;
} else { } else {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF(" fetch already in progress -- same version"); DEBUGF(" fetch already in progress -- same version");
return SAMEBUNDLE; return SAMEBUNDLE;
} }
@ -714,7 +715,7 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m, const struct
if (sqlite_exec_int64(&gotfile, "SELECT COUNT(*) FROM FILES WHERE ID='%s' and datavalid=1;", m->fileHexHash) != 1) if (sqlite_exec_int64(&gotfile, "SELECT COUNT(*) FROM FILES WHERE ID='%s' and datavalid=1;", m->fileHexHash) != 1)
return WHY("select failed"); return WHY("select failed");
if (gotfile) { if (gotfile) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF(" fetch not started - payload already present, so importing instead"); DEBUGF(" fetch not started - payload already present, so importing instead");
if (rhizome_add_manifest(m, m->ttl-1) == -1) if (rhizome_add_manifest(m, m->ttl-1) == -1)
return WHY("add manifest failed"); return WHY("add manifest failed");
@ -726,7 +727,7 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m, const struct
struct rhizome_fetch_slot *s = &rhizome_fetch_queues[i].active; struct rhizome_fetch_slot *s = &rhizome_fetch_queues[i].active;
const rhizome_manifest *sm = s->manifest; const rhizome_manifest *sm = s->manifest;
if (s->state != RHIZOME_FETCH_FREE && strcasecmp(m->fileHexHash, sm->fileHexHash) == 0) { if (s->state != RHIZOME_FETCH_FREE && strcasecmp(m->fileHexHash, sm->fileHexHash) == 0) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF(" fetch already in progress, slot=%d filehash=%s", i, m->fileHexHash); DEBUGF(" fetch already in progress, slot=%d filehash=%s", i, m->fileHexHash);
return SAMEPAYLOAD; return SAMEPAYLOAD;
} }
@ -759,7 +760,7 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m, const struct
if (schedule_fetch(slot) == -1) { if (schedule_fetch(slot) == -1) {
return -1; return -1;
} }
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF(" started fetch into %s, slot=%d filehash=%s", slot->manifest->dataFileName, slotno(slot), m->fileHexHash); DEBUGF(" started fetch into %s, slot=%d filehash=%s", slot->manifest->dataFileName, slotno(slot), m->fileHexHash);
return STARTED; return STARTED;
} }
@ -879,17 +880,17 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sock
const char *bid = alloca_tohex_bid(m->cryptoSignPublic); const char *bid = alloca_tohex_bid(m->cryptoSignPublic);
int priority=100; /* normal priority */ int priority=100; /* normal priority */
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Considering import bid=%s version=%lld size=%lld priority=%d:", bid, m->version, m->fileLength, priority); DEBUGF("Considering import bid=%s version=%lld size=%lld priority=%d:", bid, m->version, m->fileLength, priority);
if (rhizome_manifest_version_cache_lookup(m)) { if (rhizome_manifest_version_cache_lookup(m)) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUG(" already have that version or newer"); DEBUG(" already have that version or newer");
rhizome_manifest_free(m); rhizome_manifest_free(m);
RETURN(-1); RETURN(-1);
} }
if (debug & DEBUG_RHIZOME_RX) { if (config.debug.rhizome_rx) {
long long stored_version; long long stored_version;
if (sqlite_exec_int64(&stored_version, "select version from manifests where id='%s'", bid) > 0) if (sqlite_exec_int64(&stored_version, "select version from manifests where id='%s'", bid) > 0)
DEBUGF(" is new (have version %lld)", stored_version); DEBUGF(" is new (have version %lld)", stored_version);
@ -970,7 +971,7 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sock
c->peer_ipandport = *peerip; c->peer_ipandport = *peerip;
bcopy(peersid,c->peer_sid,SID_SIZE); bcopy(peersid,c->peer_sid,SID_SIZE);
if (debug & DEBUG_RHIZOME_RX) { if (config.debug.rhizome_rx) {
DEBUG("Rhizome fetch queues:"); DEBUG("Rhizome fetch queues:");
int i, j; int i, j;
for (i = 0; i < NQUEUES; ++i) { for (i = 0; i < NQUEUES; ++i) {
@ -1002,7 +1003,7 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sock
static int rhizome_fetch_close(struct rhizome_fetch_slot *slot) static int rhizome_fetch_close(struct rhizome_fetch_slot *slot)
{ {
// if (debug & DEBUG_RHIZOME_RX) // if (config.debug.rhizome_rx)
DEBUGF("close Rhizome fetch slot=%d", slotno(slot)); DEBUGF("close Rhizome fetch slot=%d", slotno(slot));
assert(slot->state != RHIZOME_FETCH_FREE); assert(slot->state != RHIZOME_FETCH_FREE);
@ -1051,7 +1052,7 @@ static void rhizome_fetch_mdp_slot_callback(struct sched_ent *alarm)
rhizome_fetch_close(slot); rhizome_fetch_close(slot);
return; return;
} }
if (debug& DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Timeout waiting for blocks. Resending request for slot=0x%p", DEBUGF("Timeout waiting for blocks. Resending request for slot=0x%p",
slot); slot);
if (slot->bidP) if (slot->bidP)
@ -1217,7 +1218,7 @@ static int rhizome_fetch_switch_to_mdp(struct rhizome_fetch_slot *slot)
void rhizome_fetch_write(struct rhizome_fetch_slot *slot) void rhizome_fetch_write(struct rhizome_fetch_slot *slot)
{ {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("write_nonblock(%d, %s)", slot->alarm.poll.fd, alloca_toprint(-1, &slot->request[slot->request_ofs], slot->request_len-slot->request_ofs)); DEBUGF("write_nonblock(%d, %s)", slot->alarm.poll.fd, alloca_toprint(-1, &slot->request[slot->request_ofs], slot->request_len-slot->request_ofs));
int bytes = write_nonblock(slot->alarm.poll.fd, &slot->request[slot->request_ofs], slot->request_len-slot->request_ofs); int bytes = write_nonblock(slot->alarm.poll.fd, &slot->request[slot->request_ofs], slot->request_len-slot->request_ofs);
if (bytes == -1) { if (bytes == -1) {
@ -1259,7 +1260,7 @@ int rhizome_fetch_flush_blob_buffer(struct rhizome_fetch_slot *slot)
WHYF("sqlite3_blob_write(,,%d,%lld) failed, %s", WHYF("sqlite3_blob_write(,,%d,%lld) failed, %s",
slot->blob_buffer_bytes,slot->file_ofs-slot->blob_buffer_bytes, slot->blob_buffer_bytes,slot->file_ofs-slot->blob_buffer_bytes,
sqlite3_errmsg(rhizome_db)); sqlite3_errmsg(rhizome_db));
if (1||debug & DEBUG_RHIZOME_RX) if (1 || config.debug.rhizome_tx)
DEBUGF("Failed to write %d bytes to file @ offset %lld-%lld", DEBUGF("Failed to write %d bytes to file @ offset %lld-%lld",
slot->blob_buffer_bytes, slot->blob_buffer_bytes,
slot->file_ofs,slot->blob_buffer_bytes); slot->file_ofs,slot->blob_buffer_bytes);
@ -1290,7 +1291,7 @@ int rhizome_write_content(struct rhizome_fetch_slot *slot, char *buffer, int byt
if (bytes>0) if (bytes>0)
SHA512_Update(&slot->sha512_context,(unsigned char *)buffer,bytes); SHA512_Update(&slot->sha512_context,(unsigned char *)buffer,bytes);
if (debug & DEBUG_RHIZOME_RX) { if (config.debug.rhizome_rx) {
DEBUGF("slot->blob_buffer_bytes=%d, slot->file_ofs=%d", DEBUGF("slot->blob_buffer_bytes=%d, slot->file_ofs=%d",
slot->blob_buffer_bytes,slot->file_ofs); slot->blob_buffer_bytes,slot->file_ofs);
dump("buffer",buffer,bytes); dump("buffer",buffer,bytes);
@ -1327,7 +1328,7 @@ int rhizome_write_content(struct rhizome_fetch_slot *slot, char *buffer, int byt
slot->last_write_time=gettime_ms(); slot->last_write_time=gettime_ms();
if (slot->file_ofs>=slot->file_len) { if (slot->file_ofs>=slot->file_len) {
/* got all of file */ /* got all of file */
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Received all of file via rhizome -- now to import it"); DEBUGF("Received all of file via rhizome -- now to import it");
if (slot->manifest) { if (slot->manifest) {
// Were fetching payload, now we have it. // Were fetching payload, now we have it.
@ -1338,7 +1339,7 @@ int rhizome_write_content(struct rhizome_fetch_slot *slot, char *buffer, int byt
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT; sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
if (strcasecmp(hash_out,slot->manifest->fileHexHash)) { if (strcasecmp(hash_out,slot->manifest->fileHexHash)) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Hash mismatch -- dropping row from table."); DEBUGF("Hash mismatch -- dropping row from table.");
DEBUGF("Expected hash=%s, got %s", DEBUGF("Expected hash=%s, got %s",
slot->manifest->fileHexHash,hash_out); slot->manifest->fileHexHash,hash_out);
@ -1357,7 +1358,7 @@ int rhizome_write_content(struct rhizome_fetch_slot *slot, char *buffer, int byt
"UPDATE FILES SET datavalid=1 WHERE id='%s'", "UPDATE FILES SET datavalid=1 WHERE id='%s'",
slot->manifest->fileHexHash); slot->manifest->fileHexHash);
if (ret!=SQLITE_OK) if (ret!=SQLITE_OK)
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("error marking row valid: %s",sqlite3_errmsg(rhizome_db)); DEBUGF("error marking row valid: %s",sqlite3_errmsg(rhizome_db));
INFOF("Updated row status (took %lldms)",(long long)gettime_ms()-start); INFOF("Updated row status (took %lldms)",(long long)gettime_ms()-start);
} }
@ -1475,14 +1476,14 @@ void rhizome_fetch_poll(struct sched_ent *alarm)
schedule(&slot->alarm); schedule(&slot->alarm);
return; return;
} else { } else {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Empty read, closing connection: received %lld of %lld bytes", DEBUGF("Empty read, closing connection: received %lld of %lld bytes",
slot->file_ofs,slot->file_len); slot->file_ofs,slot->file_len);
rhizome_fetch_switch_to_mdp(slot); rhizome_fetch_switch_to_mdp(slot);
return; return;
} }
if (sigPipeFlag) { if (sigPipeFlag) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUG("Received SIGPIPE, closing connection"); DEBUG("Received SIGPIPE, closing connection");
rhizome_fetch_switch_to_mdp(slot); rhizome_fetch_switch_to_mdp(slot);
return; return;
@ -1502,25 +1503,25 @@ void rhizome_fetch_poll(struct sched_ent *alarm)
schedule(&slot->alarm); schedule(&slot->alarm);
slot->request_len += bytes; slot->request_len += bytes;
if (http_header_complete(slot->request, slot->request_len, bytes)) { if (http_header_complete(slot->request, slot->request_len, bytes)) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Got HTTP reply: %s", alloca_toprint(160, slot->request, slot->request_len)); DEBUGF("Got HTTP reply: %s", alloca_toprint(160, slot->request, slot->request_len));
/* We have all the reply headers, so parse them, taking care of any following bytes of /* We have all the reply headers, so parse them, taking care of any following bytes of
content. */ content. */
struct http_response_parts parts; struct http_response_parts parts;
if (unpack_http_response(slot->request, &parts) == -1) { if (unpack_http_response(slot->request, &parts) == -1) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Failed HTTP request: failed to unpack http response"); DEBUGF("Failed HTTP request: failed to unpack http response");
rhizome_fetch_switch_to_mdp(slot); rhizome_fetch_switch_to_mdp(slot);
return; return;
} }
if (parts.code != 200) { if (parts.code != 200) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Failed HTTP request: rhizome server returned %d != 200 OK", parts.code); DEBUGF("Failed HTTP request: rhizome server returned %d != 200 OK", parts.code);
rhizome_fetch_switch_to_mdp(slot); rhizome_fetch_switch_to_mdp(slot);
return; return;
} }
if (parts.content_length == -1) { if (parts.content_length == -1) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Invalid HTTP reply: missing Content-Length header"); DEBUGF("Invalid HTTP reply: missing Content-Length header");
rhizome_fetch_switch_to_mdp(slot); rhizome_fetch_switch_to_mdp(slot);
return; return;
@ -1554,7 +1555,7 @@ void rhizome_fetch_poll(struct sched_ent *alarm)
} }
if (alarm->poll.revents==0 || alarm->poll.revents & (POLLHUP | POLLERR)){ if (alarm->poll.revents==0 || alarm->poll.revents & (POLLHUP | POLLERR)){
// timeout or socket error, close the socket // timeout or socket error, close the socket
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Closing due to timeout or error %x (%x %x)", alarm->poll.revents, POLLHUP, POLLERR); DEBUGF("Closing due to timeout or error %x (%x %x)", alarm->poll.revents, POLLHUP, POLLERR);
if (slot->state!=RHIZOME_FETCH_FREE) if (slot->state!=RHIZOME_FETCH_FREE)
rhizome_fetch_close(slot); rhizome_fetch_close(slot);
@ -1582,12 +1583,12 @@ int unpack_http_response(char *response, struct http_response_parts *parts)
parts->content_start = NULL; parts->content_start = NULL;
char *p = NULL; char *p = NULL;
if (!str_startswith(response, "HTTP/1.0 ", (const char **)&p)) { if (!str_startswith(response, "HTTP/1.0 ", (const char **)&p)) {
if (debug&DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Malformed HTTP reply: missing HTTP/1.0 preamble"); DEBUGF("Malformed HTTP reply: missing HTTP/1.0 preamble");
return -1; return -1;
} }
if (!(isdigit(p[0]) && isdigit(p[1]) && isdigit(p[2]) && p[3] == ' ')) { if (!(isdigit(p[0]) && isdigit(p[1]) && isdigit(p[2]) && p[3] == ' ')) {
if (debug&DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Malformed HTTP reply: missing three-digit status code"); DEBUGF("Malformed HTTP reply: missing three-digit status code");
return -1; return -1;
} }
@ -1609,7 +1610,7 @@ int unpack_http_response(char *response, struct http_response_parts *parts)
while (isdigit(*p)) while (isdigit(*p))
parts->content_length = parts->content_length * 10 + *p++ - '0'; parts->content_length = parts->content_length * 10 + *p++ - '0';
if (p == nump || (*p != '\r' && *p != '\n')) { if (p == nump || (*p != '\r' && *p != '\n')) {
if (debug & DEBUG_RHIZOME_RX) if (config.debug.rhizome_rx)
DEBUGF("Invalid HTTP reply: malformed Content-Length header"); DEBUGF("Invalid HTTP reply: malformed Content-Length header");
return -1; return -1;
} }

View File

@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#endif #endif
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "str.h" #include "str.h"
#include "rhizome.h" #include "rhizome.h"
#define RHIZOME_SERVER_MAX_LIVE_REQUESTS 32 #define RHIZOME_SERVER_MAX_LIVE_REQUESTS 32
@ -97,7 +98,7 @@ int rhizome_http_server_start(int (*parse_func)(rhizome_http_request *),
if (now < rhizome_server_last_start_attempt + 5000) if (now < rhizome_server_last_start_attempt + 5000)
return 2; return 2;
rhizome_server_last_start_attempt = now; rhizome_server_last_start_attempt = now;
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUGF("Starting rhizome HTTP server"); DEBUGF("Starting rhizome HTTP server");
unsigned short port; unsigned short port;
@ -176,7 +177,7 @@ void rhizome_client_poll(struct sched_ent *alarm)
{ {
rhizome_http_request *r = (rhizome_http_request *)alarm; rhizome_http_request *r = (rhizome_http_request *)alarm;
if (alarm->poll.revents == 0){ if (alarm->poll.revents == 0){
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUG("Closing connection due to timeout"); DEBUG("Closing connection due to timeout");
rhizome_server_free_http_request(r); rhizome_server_free_http_request(r);
return; return;
@ -203,7 +204,7 @@ void rhizome_client_poll(struct sched_ent *alarm)
The idle timeout should drop the connections instead. The idle timeout should drop the connections instead.
*/ */
if (sigPipeFlag) { if (sigPipeFlag) {
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUG("Received SIGPIPE, closing connection"); DEBUG("Received SIGPIPE, closing connection");
rhizome_server_free_http_request(r); rhizome_server_free_http_request(r);
return; return;
@ -228,13 +229,13 @@ void rhizome_client_poll(struct sched_ent *alarm)
if (rhizome_http_parse_func!=NULL) rhizome_http_parse_func(r); if (rhizome_http_parse_func!=NULL) rhizome_http_parse_func(r);
} }
} else { } else {
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUG("Empty read, closing connection"); DEBUG("Empty read, closing connection");
rhizome_server_free_http_request(r); rhizome_server_free_http_request(r);
return; return;
} }
if (sigPipeFlag) { if (sigPipeFlag) {
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUG("Received SIGPIPE, closing connection"); DEBUG("Received SIGPIPE, closing connection");
rhizome_server_free_http_request(r); rhizome_server_free_http_request(r);
return; return;
@ -350,7 +351,7 @@ int rhizome_server_sql_query_http_response(rhizome_http_request *r,
/* Work out total response length */ /* Work out total response length */
long long response_bytes=256+r->source_count*r->source_record_size; long long response_bytes=256+r->source_count*r->source_record_size;
rhizome_server_http_response_header(r, 200, "servalproject.org/rhizome-list", response_bytes); rhizome_server_http_response_header(r, 200, "servalproject.org/rhizome-list", response_bytes);
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUGF("headers consumed %d bytes", r->buffer_length); DEBUGF("headers consumed %d bytes", r->buffer_length);
/* Clear and prepare response header */ /* Clear and prepare response header */
@ -359,7 +360,7 @@ int rhizome_server_sql_query_http_response(rhizome_http_request *r,
r->buffer[r->buffer_length]=0x01; /* type of response (list) */ r->buffer[r->buffer_length]=0x01; /* type of response (list) */
r->buffer[r->buffer_length+1]=0x01; /* version of response */ r->buffer[r->buffer_length+1]=0x01; /* version of response */
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUGF("Found %lld records",r->source_count); DEBUGF("Found %lld records",r->source_count);
/* Number of records we intend to return */ /* Number of records we intend to return */
r->buffer[r->buffer_length+4]=(r->source_count>>0)&0xff; r->buffer[r->buffer_length+4]=(r->source_count>>0)&0xff;
@ -390,7 +391,7 @@ int rhizome_server_sql_query_fill_buffer(rhizome_http_request *r, char *table, c
{ {
unsigned char blob_value[r->source_record_size*2+1]; unsigned char blob_value[r->source_record_size*2+1];
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUGF("populating with sql rows at offset %d",r->buffer_length); DEBUGF("populating with sql rows at offset %d",r->buffer_length);
if (r->source_index>=r->source_count) if (r->source_index>=r->source_count)
{ {
@ -400,7 +401,7 @@ int rhizome_server_sql_query_fill_buffer(rhizome_http_request *r, char *table, c
int record_count=(r->buffer_size-r->buffer_length)/r->source_record_size; int record_count=(r->buffer_size-r->buffer_length)/r->source_record_size;
if (record_count<1) { if (record_count<1) {
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUGF("r->buffer_size=%d, r->buffer_length=%d, r->source_record_size=%d", DEBUGF("r->buffer_size=%d, r->buffer_length=%d, r->source_record_size=%d",
r->buffer_size, r->buffer_length, r->source_record_size); r->buffer_size, r->buffer_length, r->source_record_size);
return WHY("Not enough space to fit any records"); return WHY("Not enough space to fit any records");
@ -410,7 +411,7 @@ int rhizome_server_sql_query_fill_buffer(rhizome_http_request *r, char *table, c
sqlite3_stmt *statement = sqlite_prepare(&retry, "%s LIMIT %lld,%d", r->source, r->source_index, record_count); sqlite3_stmt *statement = sqlite_prepare(&retry, "%s LIMIT %lld,%d", r->source, r->source_index, record_count);
if (!statement) if (!statement)
return -1; return -1;
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUG(sqlite3_sql(statement)); DEBUG(sqlite3_sql(statement));
while( r->buffer_length + r->source_record_size < r->buffer_size while( r->buffer_length + r->source_record_size < r->buffer_size
&& sqlite_step_retry(&retry, statement) == SQLITE_ROW && sqlite_step_retry(&retry, statement) == SQLITE_ROW
@ -426,7 +427,7 @@ int rhizome_server_sql_query_fill_buffer(rhizome_http_request *r, char *table, c
switch(column_type) { switch(column_type) {
case SQLITE_TEXT: value=sqlite3_column_text(statement, 0); break; case SQLITE_TEXT: value=sqlite3_column_text(statement, 0); break;
case SQLITE_BLOB: case SQLITE_BLOB:
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUGF("table='%s',col='%s',rowid=%lld", table, column, sqlite3_column_int64(statement,1)); DEBUGF("table='%s',col='%s',rowid=%lld", table, column, sqlite3_column_int64(statement,1));
int ret; int ret;
@ -594,7 +595,7 @@ int rhizome_server_parse_http_request(rhizome_http_request *r)
DEBUGF("Sending 404 not found for '%s'",path); DEBUGF("Sending 404 not found for '%s'",path);
} }
} else { } else {
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUGF("Received malformed HTTP request: %s", alloca_toprint(120, (const char *)r->request, r->request_length)); DEBUGF("Received malformed HTTP request: %s", alloca_toprint(120, (const char *)r->request, r->request_length));
rhizome_server_simple_http_response(r, 400, "<html><h1>Malformed request</h1></html>\r\n"); rhizome_server_simple_http_response(r, 400, "<html><h1>Malformed request</h1></html>\r\n");
} }
@ -656,7 +657,7 @@ int rhizome_server_set_response(rhizome_http_request *r, const struct http_respo
r->buffer_length = strbuf_len(b); r->buffer_length = strbuf_len(b);
r->buffer_offset = 0; r->buffer_offset = 0;
r->request_type |= RHIZOME_HTTP_REQUEST_FROMBUFFER; r->request_type |= RHIZOME_HTTP_REQUEST_FROMBUFFER;
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUGF("Sending HTTP response: %s", alloca_toprint(160, (const char *)r->buffer, r->buffer_length)); DEBUGF("Sending HTTP response: %s", alloca_toprint(160, (const char *)r->buffer, r->buffer_length));
return 0; return 0;
} }
@ -745,7 +746,7 @@ int rhizome_server_http_send_bytes(rhizome_http_request *r)
for(i=0;i<favicon_len;i++) for(i=0;i<favicon_len;i++)
r->buffer[i]=favicon_bytes[i]; r->buffer[i]=favicon_bytes[i];
r->buffer_length=i; r->buffer_length=i;
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUGF("favicon buffer_length=%d\n", r->buffer_length); DEBUGF("favicon buffer_length=%d\n", r->buffer_length);
r->request_type=RHIZOME_HTTP_REQUEST_FROMBUFFER; r->request_type=RHIZOME_HTTP_REQUEST_FROMBUFFER;
} }
@ -795,7 +796,7 @@ int rhizome_server_http_send_bytes(rhizome_http_request *r)
} }
} }
if (!r->request_type){ if (!r->request_type){
if (debug & DEBUG_RHIZOME_TX) if (config.debug.rhizome_tx)
DEBUG("Closing connection, done"); DEBUG("Closing connection, done");
return rhizome_server_free_http_request(r); return rhizome_server_free_http_request(r);
} }

View File

@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "serval.h" #include "serval.h"
#include "conf.h"
#include "rhizome.h" #include "rhizome.h"
#include <assert.h> #include <assert.h>
#include "overlay_buffer.h" #include "overlay_buffer.h"
@ -175,13 +176,13 @@ int overlay_rhizome_add_advertisements(struct decode_context *context, int inter
// TODO Group handling not completely thought out here yet. // TODO Group handling not completely thought out here yet.
debugflags_t oldmask = sqlite_set_debugmask(DEBUG_RHIZOME_ADS); int (*oldfunc)() = sqlite_set_tracefunc(is_debug_rhizome_ads);
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT; sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
/* Get number of bundles available if required */ /* Get number of bundles available if required */
long long tmp = 0; long long tmp = 0;
if (sqlite_exec_int64_retry(&retry, &tmp, "SELECT COUNT(BAR) FROM MANIFESTS;") != 1) { if (sqlite_exec_int64_retry(&retry, &tmp, "SELECT COUNT(BAR) FROM MANIFESTS;") != 1) {
sqlite_set_debugmask(oldmask); sqlite_set_tracefunc(oldfunc);
RETURN(WHY("Could not count BARs for advertisement")); RETURN(WHY("Could not count BARs for advertisement"));
} }
bundles_available = (int) tmp; bundles_available = (int) tmp;
@ -189,7 +190,7 @@ int overlay_rhizome_add_advertisements(struct decode_context *context, int inter
bundle_offset[0]=0; bundle_offset[0]=0;
if (bundles_available==-1||(bundle_offset[1]>=bundles_available)) if (bundles_available==-1||(bundle_offset[1]>=bundles_available))
bundle_offset[1]=0; bundle_offset[1]=0;
if (debug & DEBUG_RHIZOME_ADS) if (config.debug.rhizome_ads)
DEBUGF("%d bundles in database (%d %d), slots=%d.",bundles_available, DEBUGF("%d bundles in database (%d %d), slots=%d.",bundles_available,
bundle_offset[0],bundle_offset[1],slots); bundle_offset[0],bundle_offset[1],slots);
@ -233,7 +234,7 @@ int overlay_rhizome_add_advertisements(struct decode_context *context, int inter
break; break;
} }
if (!statement) { if (!statement) {
sqlite_set_debugmask(oldmask); sqlite_set_tracefunc(oldfunc);
WHY("Could not prepare sql statement for fetching BARs for advertisement"); WHY("Could not prepare sql statement for fetching BARs for advertisement");
goto stopStuffing; goto stopStuffing;
} }
@ -259,7 +260,7 @@ int overlay_rhizome_add_advertisements(struct decode_context *context, int inter
int blob_bytes=sqlite3_blob_bytes(blob); int blob_bytes=sqlite3_blob_bytes(blob);
if (pass&&(blob_bytes!=RHIZOME_BAR_BYTES)) { if (pass&&(blob_bytes!=RHIZOME_BAR_BYTES)) {
if (debug&DEBUG_RHIZOME_ADS) if (config.debug.rhizome_ads)
DEBUG("Found a BAR that is the wrong size - ignoring"); DEBUG("Found a BAR that is the wrong size - ignoring");
sqlite3_blob_close(blob); sqlite3_blob_close(blob);
blob=NULL; blob=NULL;
@ -328,7 +329,7 @@ int overlay_rhizome_add_advertisements(struct decode_context *context, int inter
ob_patch_rfs(e); ob_patch_rfs(e);
sqlite_set_debugmask(oldmask); sqlite_set_tracefunc(oldfunc);
RETURN(0); RETURN(0);
} }
@ -346,7 +347,7 @@ int overlay_rhizome_saw_advertisements(int i, struct overlay_frame *f, long long
rhizome_manifest *m=NULL; rhizome_manifest *m=NULL;
char httpaddrtxt[INET_ADDRSTRLEN]; char httpaddrtxt[INET_ADDRSTRLEN];
debugflags_t oldmask = sqlite_set_debugmask(DEBUG_RHIZOME_ADS); int (*oldfunc)() = sqlite_set_tracefunc(is_debug_rhizome_ads);
switch (ad_frame_type) { switch (ad_frame_type) {
case 3: case 3:
@ -382,14 +383,14 @@ int overlay_rhizome_saw_advertisements(int i, struct overlay_frame *f, long long
m = rhizome_new_manifest(); m = rhizome_new_manifest();
if (!m) { if (!m) {
WHY("Out of manifests"); WHY("Out of manifests");
sqlite_set_debugmask(oldmask); sqlite_set_tracefunc(oldfunc);
RETURN(0); RETURN(0);
} }
if (rhizome_read_manifest_file(m, (char *)data, manifest_length) == -1) { if (rhizome_read_manifest_file(m, (char *)data, manifest_length) == -1) {
WHY("Error importing manifest body"); WHY("Error importing manifest body");
rhizome_manifest_free(m); rhizome_manifest_free(m);
sqlite_set_debugmask(oldmask); sqlite_set_tracefunc(oldfunc);
RETURN(0); RETURN(0);
} }
@ -397,14 +398,14 @@ int overlay_rhizome_saw_advertisements(int i, struct overlay_frame *f, long long
if (rhizome_manifest_get(m, "id", manifest_id_prefix, sizeof manifest_id_prefix) == NULL) { if (rhizome_manifest_get(m, "id", manifest_id_prefix, sizeof manifest_id_prefix) == NULL) {
WHY("Manifest does not contain 'id' field"); WHY("Manifest does not contain 'id' field");
rhizome_manifest_free(m); rhizome_manifest_free(m);
sqlite_set_debugmask(oldmask); sqlite_set_tracefunc(oldfunc);
RETURN(0); RETURN(0);
} }
/* trim manifest ID to a prefix for ease of debugging /* trim manifest ID to a prefix for ease of debugging
(that is the only use of this */ (that is the only use of this */
manifest_id_prefix[8]=0; manifest_id_prefix[8]=0;
long long version = rhizome_manifest_get_ll(m, "version"); long long version = rhizome_manifest_get_ll(m, "version");
if (debug & DEBUG_RHIZOME_ADS) if (config.debug.rhizome_ads)
DEBUGF("manifest id=%s* version=%lld", manifest_id_prefix, version); DEBUGF("manifest id=%s* version=%lld", manifest_id_prefix, version);
/* Crude signature presence test */ /* Crude signature presence test */
@ -418,7 +419,7 @@ int overlay_rhizome_saw_advertisements(int i, struct overlay_frame *f, long long
offering the same manifest */ offering the same manifest */
WARN("Ignoring manifest announcment with no signature"); WARN("Ignoring manifest announcment with no signature");
rhizome_manifest_free(m); rhizome_manifest_free(m);
sqlite_set_debugmask(oldmask); sqlite_set_tracefunc(oldfunc);
RETURN(0); RETURN(0);
} }
@ -432,10 +433,10 @@ int overlay_rhizome_saw_advertisements(int i, struct overlay_frame *f, long long
/* Manifest is okay, so see if it is worth storing */ /* Manifest is okay, so see if it is worth storing */
if (rhizome_manifest_version_cache_lookup(m)) { if (rhizome_manifest_version_cache_lookup(m)) {
/* We already have this version or newer */ /* We already have this version or newer */
if (debug & DEBUG_RHIZOME_ADS) if (config.debug.rhizome_ads)
DEBUG("We already have that manifest or newer."); DEBUG("We already have that manifest or newer.");
} else { } else {
if (debug & DEBUG_RHIZOME_ADS) if (config.debug.rhizome_ads)
DEBUG("Not seen before."); DEBUG("Not seen before.");
rhizome_suggest_queue_manifest_import(m, &httpaddr,f->source->sid); rhizome_suggest_queue_manifest_import(m, &httpaddr,f->source->sid);
// the above function will free the manifest structure, make sure we don't free it again // the above function will free the manifest structure, make sure we don't free it again
@ -444,7 +445,7 @@ int overlay_rhizome_saw_advertisements(int i, struct overlay_frame *f, long long
} }
else else
{ {
if (debug & DEBUG_RHIZOME_ADS) if (config.debug.rhizome_ads)
DEBUG("Unverified manifest has errors - so not processing any further."); DEBUG("Unverified manifest has errors - so not processing any further.");
/* Don't waste any time on this manifest in future attempts for at least /* Don't waste any time on this manifest in future attempts for at least
a minute. */ a minute. */
@ -457,6 +458,6 @@ int overlay_rhizome_saw_advertisements(int i, struct overlay_frame *f, long long
} }
break; break;
} }
sqlite_set_debugmask(oldmask); sqlite_set_tracefunc(oldfunc);
RETURN(0); RETURN(0);
} }

View File

@ -648,7 +648,7 @@ start_servald_instances() {
eval DUMMY$instance_name="\$DUMMYNET" eval DUMMY$instance_name="\$DUMMYNET"
done done
# Now wait until they see each other. # Now wait until they see each other.
foreach "$@" \ foreach_instance "$@" \
wait_until --sleep=0.25 has_seen_instances "$@" wait_until --sleep=0.25 has_seen_instances "$@"
tfw_log "# dummynet file:" $(ls -l $DUMMYNET) tfw_log "# dummynet file:" $(ls -l $DUMMYNET)
pop_instance pop_instance

View File

@ -178,22 +178,6 @@ test_DebugFlags() {
assertStderrGrep --matches=0 '\<echo:argv\[' assertStderrGrep --matches=0 '\<echo:argv\['
} }
doc_DebugFlagAll="Debug config options override debug.all"
test_DebugFlagAll() {
executeOk_servald config set debug.all yes
executeOk_servald echo one two three
assertStderrGrep --matches=3 '\<echo:argv\['
executeOk_servald config set debug.verbose false
executeOk_servald echo one two three
assertStderrGrep --matches=0 '\<echo:argv\['
executeOk_servald config set debug.verbose true
executeOk_servald echo one two three
assertStderrGrep --matches=3 '\<echo:argv\['
executeOk_servald config set debug.all off
executeOk_servald echo one two three
assertStderrGrep --matches=3 '\<echo:argv\['
}
doc_InterfacesLegacyIncludeAll="Legacy 'interfaces' config option include all" doc_InterfacesLegacyIncludeAll="Legacy 'interfaces' config option include all"
test_InterfacesLegacyIncludeAll() { test_InterfacesLegacyIncludeAll() {
executeOk_servald config set interfaces '+' executeOk_servald config set interfaces '+'

View File

@ -44,7 +44,6 @@ setup() {
start_servald_instances +A +B start_servald_instances +A +B
wait_until --sleep=0.25 instances_reach_each_other +A +B wait_until --sleep=0.25 instances_reach_each_other +A +B
set_instance +A set_instance +A
executeOk_servald config set debug.all Yes
} }
finally() { finally() {
@ -63,11 +62,11 @@ set_server_vars() {
set log.show_time on \ set log.show_time on \
set mdp.iftype.wifi.tick_ms 100 \ set mdp.iftype.wifi.tick_ms 100 \
set rhizome.enable No \ set rhizome.enable No \
set debug.interfaces Yes \ set debug.overlayinterfaces Yes \
set debug.packetformats No \ set debug.packetformats No \
set debug.routing No \ set debug.overlayrouting No \
set debug.tx No \ set debug.packettx No \
set debug.rx No \ set debug.packetrx No \
set debug.mdprequests Yes \ set debug.mdprequests Yes \
set debug.keyring Yes set debug.keyring Yes
} }

View File

@ -40,8 +40,8 @@ configure_servald_server() {
set log.show_pid on \ set log.show_pid on \
set log.show_time on \ set log.show_time on \
set debug.rhizome on \ set debug.rhizome on \
set debug.rhizometx on \ set debug.rhizome_tx on \
set debug.rhizomerx on \ set debug.rhizome_rx on \
set server.respawn_on_crash off \ set server.respawn_on_crash off \
set mdp.iftype.wifi.tick_ms 500 set mdp.iftype.wifi.tick_ms 500
} }
@ -370,8 +370,8 @@ setup_sync() {
executeOk_servald config \ executeOk_servald config \
set log.show_time on \ set log.show_time on \
set debug.rhizome on \ set debug.rhizome on \
set debug.rhizometx on \ set debug.rhizome_tx on \
set debug.rhizomerx on \ set debug.rhizome_rx on \
set rhizome.direct.peer.0 "http://${addr_localhost}:${PORTA}" set rhizome.direct.peer.0 "http://${addr_localhost}:${PORTA}"
rhizome_add_file file2 rhizome_add_file file2
BID2=$BID BID2=$BID

View File

@ -39,9 +39,9 @@ configure_servald_server() {
executeOk_servald config \ executeOk_servald config \
set log.show_pid on \ set log.show_pid on \
set log.show_time on \ set log.show_time on \
set debug.rhizome on \ set debug.rhizome off \
set debug.rhizometx on \ set debug.rhizome_tx off \
set debug.rhizomerx on \ set debug.rhizome_rx off \
set server.respawn_on_crash off \ set server.respawn_on_crash off \
set mdp.iftype.wifi.tick_ms 500 set mdp.iftype.wifi.tick_ms 500
} }

29
vomp.c
View File

@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "serval.h" #include "serval.h"
#include "str.h" #include "str.h"
#include "conf.h"
#include "strbuf.h" #include "strbuf.h"
#include "strlcpy.h" #include "strlcpy.h"
#include "overlay_address.h" #include "overlay_address.h"
@ -342,7 +343,7 @@ static int vomp_generate_session_id()
if (urandombytes((unsigned char *)&session_id,sizeof(int))) if (urandombytes((unsigned char *)&session_id,sizeof(int)))
return WHY("Insufficient entropy"); return WHY("Insufficient entropy");
session_id&=VOMP_SESSION_MASK; session_id&=VOMP_SESSION_MASK;
if (debug & DEBUG_VOMP) DEBUGF("session=0x%08x",session_id); if (config.debug.vomp) DEBUGF("session=0x%08x",session_id);
int i; int i;
/* reject duplicate call session numbers */ /* reject duplicate call session numbers */
for(i=0;i<vomp_call_count;i++) for(i=0;i<vomp_call_count;i++)
@ -383,7 +384,7 @@ static struct vomp_call_state *vomp_create_call(struct subscriber *remote,
vomp_stats.name="vomp_process_tick"; vomp_stats.name="vomp_process_tick";
call->alarm.stats=&vomp_stats; call->alarm.stats=&vomp_stats;
schedule(&call->alarm); schedule(&call->alarm);
if (debug & DEBUG_VOMP) if (config.debug.vomp)
DEBUGF("Returning new call #%d",local_session); DEBUGF("Returning new call #%d",local_session);
return call; return call;
} }
@ -398,7 +399,7 @@ static struct vomp_call_state *vomp_find_or_create_call(struct subscriber *remot
int i; int i;
struct vomp_call_state *call; struct vomp_call_state *call;
if (debug & DEBUG_VOMP) if (config.debug.vomp)
DEBUGF("%d calls already in progress.",vomp_call_count); DEBUGF("%d calls already in progress.",vomp_call_count);
for(i=0;i<vomp_call_count;i++) for(i=0;i<vomp_call_count;i++)
{ {
@ -406,7 +407,7 @@ static struct vomp_call_state *vomp_find_or_create_call(struct subscriber *remot
/* do the fast comparison first, and only if that matches proceed to /* do the fast comparison first, and only if that matches proceed to
the slower SID comparisons */ the slower SID comparisons */
if (debug & DEBUG_VOMP) if (config.debug.vomp)
DEBUGF("asking for %06x:%06x, this call %06x:%06x", DEBUGF("asking for %06x:%06x, this call %06x:%06x",
sender_session,recvr_session, sender_session,recvr_session,
call->remote.session, call->remote.session,
@ -433,7 +434,7 @@ static struct vomp_call_state *vomp_find_or_create_call(struct subscriber *remot
if (!call->remote.session) if (!call->remote.session)
call->remote.session=sender_session; call->remote.session=sender_session;
if (debug & DEBUG_VOMP) { if (config.debug.vomp) {
DEBUGF("%06x:%06x matches call #%d %06x:%06x", DEBUGF("%06x:%06x matches call #%d %06x:%06x",
sender_session,recvr_session,i, sender_session,recvr_session,i,
call->remote.session, call->remote.session,
@ -507,7 +508,7 @@ static int vomp_send_status_remote(struct vomp_call_state *call)
*len+=didLen+1; *len+=didLen+1;
} }
if (debug & DEBUG_VOMP) if (config.debug.vomp)
DEBUGF("mdp frame with codec list is %d bytes", mdp.out.payload_length); DEBUGF("mdp frame with codec list is %d bytes", mdp.out.payload_length);
overlay_send_stun_request(directory_service, call->remote.subscriber); overlay_send_stun_request(directory_service, call->remote.subscriber);
@ -675,7 +676,7 @@ static int vomp_update(struct vomp_call_state *call)
if (call->last_sent_status==combined_status) if (call->last_sent_status==combined_status)
return 0; return 0;
if (debug & DEBUG_VOMP) if (config.debug.vomp)
DEBUGF("Call state changed to %d %d, sending updates",call->local.state, call->remote.state); DEBUGF("Call state changed to %d %d, sending updates",call->local.state, call->remote.state);
call->last_sent_status=combined_status; call->last_sent_status=combined_status;
@ -738,7 +739,7 @@ static int vomp_process_audio(struct vomp_call_state *call, overlay_mdp_frame *m
int vomp_ringing(struct vomp_call_state *call){ int vomp_ringing(struct vomp_call_state *call){
if (call){ if (call){
if ((!call->initiated_call) && call->local.state<VOMP_STATE_RINGINGIN && call->remote.state==VOMP_STATE_RINGINGOUT){ if ((!call->initiated_call) && call->local.state<VOMP_STATE_RINGINGIN && call->remote.state==VOMP_STATE_RINGINGOUT){
if (debug & DEBUG_VOMP) if (config.debug.vomp)
DEBUGF("RING RING!"); DEBUGF("RING RING!");
vomp_update_local_state(call, VOMP_STATE_RINGINGIN); vomp_update_local_state(call, VOMP_STATE_RINGINGIN);
vomp_update(call); vomp_update(call);
@ -750,7 +751,7 @@ int vomp_ringing(struct vomp_call_state *call){
static int vomp_call_destroy(struct vomp_call_state *call) static int vomp_call_destroy(struct vomp_call_state *call)
{ {
if (debug & DEBUG_VOMP) if (config.debug.vomp)
DEBUGF("Destroying call %06x:%06x [%s,%s]", call->local.session, call->remote.session, call->local.did,call->remote.did); DEBUGF("Destroying call %06x:%06x [%s,%s]", call->local.session, call->remote.session, call->local.did,call->remote.did);
/* now release the call structure */ /* now release the call structure */
@ -776,7 +777,7 @@ int vomp_dial(struct subscriber *local, struct subscriber *remote, const char *l
These need to be passed to the node being called to provide caller id, These need to be passed to the node being called to provide caller id,
and potentially handle call-routing, e.g., if it is a gateway. and potentially handle call-routing, e.g., if it is a gateway.
*/ */
if (debug & DEBUG_VOMP) if (config.debug.vomp)
DEBUG("Dialing"); DEBUG("Dialing");
if (vomp_call_count>=VOMP_MAX_CALLS) if (vomp_call_count>=VOMP_MAX_CALLS)
@ -808,7 +809,7 @@ int vomp_dial(struct subscriber *local, struct subscriber *remote, const char *l
int vomp_pickup(struct vomp_call_state *call) int vomp_pickup(struct vomp_call_state *call)
{ {
if (call){ if (call){
if (debug & DEBUG_VOMP) if (config.debug.vomp)
DEBUG("Picking up"); DEBUG("Picking up");
if (call->local.state<=VOMP_STATE_RINGINGIN && call->remote.state==VOMP_STATE_RINGINGOUT){ if (call->local.state<=VOMP_STATE_RINGINGIN && call->remote.state==VOMP_STATE_RINGINGOUT){
vomp_update_local_state(call, VOMP_STATE_INCALL); vomp_update_local_state(call, VOMP_STATE_INCALL);
@ -825,7 +826,7 @@ int vomp_pickup(struct vomp_call_state *call)
int vomp_hangup(struct vomp_call_state *call) int vomp_hangup(struct vomp_call_state *call)
{ {
if (call){ if (call){
if (debug & DEBUG_VOMP) if (config.debug.vomp)
DEBUG("Hanging up"); DEBUG("Hanging up");
vomp_update_local_state(call, VOMP_STATE_CALLENDED); vomp_update_local_state(call, VOMP_STATE_CALLENDED);
vomp_update(call); vomp_update(call);
@ -837,7 +838,7 @@ static int vomp_extract_remote_codec_list(struct vomp_call_state *call,overlay_m
{ {
int ofs=6; int ofs=6;
if (debug & DEBUG_VOMP) if (config.debug.vomp)
dump("codec list mdp frame", (unsigned char *)&mdp->in.payload[0],mdp->in.payload_length); dump("codec list mdp frame", (unsigned char *)&mdp->in.payload[0],mdp->in.payload_length);
for (;ofs<mdp->in.payload_length && mdp->in.payload[ofs];ofs++){ for (;ofs<mdp->in.payload_length && mdp->in.payload[ofs];ofs++){
@ -896,7 +897,7 @@ int vomp_mdp_received(overlay_mdp_frame *mdp)
if (!call) if (!call)
return WHY("Unable to find or create call"); return WHY("Unable to find or create call");
if (!recvr_session && (debug & DEBUG_VOMP)) if (!recvr_session && (config.debug.vomp))
DEBUG("recvr_session==0, created call"); DEBUG("recvr_session==0, created call");
// stale packet or forgery attempt? Should we just drop it? // stale packet or forgery attempt? Should we just drop it?