Move if(config.debug.xxx) tests into DEBUGF()

Original DEBUG() and DEBUGF() macros renamed to _DEBUG() and _DEBUGF()
New DEBUG() and DEBUGF() macros, first argument is flagname
New DEBUGF2(foo, bar, ...) macro does if(config.debug.foo||config.debug.bar) test
Replace almost all config.debug.xxx references to IF_DEBUG(xxx)
This commit is contained in:
Andrew Bettison 2015-07-06 17:49:49 +09:30
parent abb2a39330
commit 7d9a5faa4e
62 changed files with 1222 additions and 1783 deletions

View File

@ -25,8 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
void _exit(int status);
void exit(int status)
{
if (config.debug.verbose)
DEBUGF("Calling _exit(%d)", status);
DEBUGF(verbose, "Calling _exit(%d)", status);
fflush(stdout);
_exit(status);
}
}

10
cli.c
View File

@ -138,7 +138,7 @@ int cli_parse(const int argc, const char *const *args, const struct cli_schema *
int arg = 0;
unsigned opt = 0;
while ((pattern = commands[cmd].words[opt])) {
//DEBUGF("cmd=%d opt=%d pattern='%s' args[arg=%d]='%s'", cmd, opt, pattern, arg, arg < argc ? args[arg] : "");
//DEBUGF(cli, "cmd=%d opt=%d pattern='%s' args[arg=%d]='%s'", cmd, opt, pattern, arg, arg < argc ? args[arg] : "");
unsigned patlen = strlen(pattern);
if (cmdpa.varargi != -1)
return WHYF("Internal error: commands[%d].word[%d]=\"%s\" - more words not allowed after \"...\"", cmd, opt, commands[cmd].words[opt]);
@ -279,7 +279,7 @@ int cli_parse(const int argc, const char *const *args, const struct cli_schema *
++opt;
}
}
//DEBUGF("cmd=%d opt=%d args[arg=%d]='%s'", cmd, opt, arg, arg < argc ? args[arg] : "");
//DEBUGF(cli, "cmd=%d opt=%d args[arg=%d]='%s'", cmd, opt, arg, arg < argc ? args[arg] : "");
if (!pattern && arg == argc) {
/* A match! We got through the command definition with no internal errors and all literal
args matched and we have a proper number of args. If we have multiple matches, then note
@ -309,9 +309,9 @@ int cli_parse(const int argc, const char *const *args, const struct cli_schema *
return 0;
}
void _debug_cli_parsed(struct __sourceloc __whence, const struct cli_parsed *parsed)
void _debug_cli_parsed(struct __sourceloc __whence, const char *tag, const struct cli_parsed *parsed)
{
DEBUG_argv("command", parsed->argc, parsed->args);
_DEBUG_argv(tag, parsed->argc, parsed->args);
strbuf b = strbuf_alloca(1024);
unsigned i;
for (i = 0; i < parsed->labelc; ++i) {
@ -320,7 +320,7 @@ void _debug_cli_parsed(struct __sourceloc __whence, const struct cli_parsed *par
}
if (parsed->varargi >= 0)
strbuf_sprintf(b, " varargi=%d", parsed->varargi);
DEBUGF("parsed%s", strbuf_str(b));
_DEBUGF(tag, "parsed%s", strbuf_str(b));
}
int cli_invoke(const struct cli_parsed *parsed, struct cli_context *context)

4
cli.h
View File

@ -72,9 +72,9 @@ struct cli_parsed {
int varargi; // -1 means no var args
};
void _debug_cli_parsed(struct __sourceloc __whence, const struct cli_parsed *parsed);
void _debug_cli_parsed(struct __sourceloc __whence, const char *tag, const struct cli_parsed *parsed);
#define DEBUG_cli_parsed(parsed) _debug_cli_parsed(__WHENCE__, parsed)
#define DEBUG_cli_parsed(TAG,parsed) _debug_cli_parsed(__WHENCE__, "{" #TAG "}", parsed)
int cli_usage(const struct cli_schema *commands, const struct cli_schema *end_commands, XPRINTF xpf);
int cli_usage_args(const int argc, const char *const *args, const struct cli_schema *commands, const struct cli_schema *end_commands, XPRINTF xpf);

View File

@ -266,7 +266,7 @@ int parseCommandLine(struct cli_context *context, const char *argv0, int argc, c
OUT();
if (config.debug.timing)
if (IF_DEBUG(timing))
fd_showstats();
return result;
}
@ -528,14 +528,12 @@ DEFINE_CMD(app_echo,CLIFLAG_PERMISSIVE_CONFIG,
"echo","[-e]","[--]","...");
static int app_echo(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
int escapes = !cli_arg(parsed, "-e", NULL, NULL, NULL);
unsigned i;
for (i = parsed->varargi; i < parsed->argc; ++i) {
const char *arg = parsed->args[i];
if (config.debug.verbose)
DEBUGF("echo:argv[%d]=\"%s\"", i, arg);
DEBUGF(verbose, "echo:argv[%d]=\"%s\"", i, arg);
if (escapes) {
unsigned char buf[strlen(arg)];
size_t len = strn_fromprint(buf, sizeof buf, arg, 0, '\0', NULL);
@ -552,8 +550,7 @@ DEFINE_CMD(app_log,CLIFLAG_PERMISSIVE_CONFIG,
"log","error|warn|hint|info|debug","<message>");
static int app_log(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
assert(parsed->argc == 3);
const char *lvl = parsed->args[1];
const char *msg = parsed->args[2];

18
conf.c
View File

@ -48,15 +48,12 @@ static const char *conffile_path()
static int reload(const char *path, int *resultp)
{
if (config.debug.config)
DEBUGF(" file path=%s", alloca_str_toprint(path));
DEBUGF(config, " file path=%s", alloca_str_toprint(path));
struct file_meta meta;
if (get_file_meta(path, &meta) == -1)
return -1;
if (config.debug.config) {
DEBUGF(" file meta=%s", alloca_file_meta(&meta));
DEBUGF("conffile_meta=%s", alloca_file_meta(&conffile_meta));
}
DEBUGF(config, " file meta=%s", alloca_file_meta(&meta));
DEBUGF(config, "conffile_meta=%s", alloca_file_meta(&conffile_meta));
if (cmp_file_meta(&meta, &conffile_meta) == 0)
return 0;
if (conffile_meta.mtime.tv_sec != -1)
@ -93,12 +90,10 @@ static int reload(const char *path, int *resultp)
free(buf);
return -1;
}
if (config.debug.config)
DEBUGF("config file %s successfully read %ld bytes", path, (long) meta.size);
DEBUGF(config, "config file %s successfully read %ld bytes", path, (long) meta.size);
}
conffile_meta = meta;
if (config.debug.config)
DEBUGF("set conffile_meta=%s", alloca_file_meta(&conffile_meta));
DEBUGF(config, "set conffile_meta=%s", alloca_file_meta(&conffile_meta));
struct cf_om_node *new_root = NULL;
*resultp = cf_om_parse(path, buf, meta.size, &new_root);
free(buf);
@ -157,8 +152,7 @@ int cf_om_save()
else
INFOF("wrote %s", path);
conffile_meta = newmeta;
if (config.debug.config)
DEBUGF("set conffile_meta=%s", alloca_file_meta(&conffile_meta));
DEBUGF(config, "set conffile_meta=%s", alloca_file_meta(&conffile_meta));
}
return 0;
}

2
conf.h
View File

@ -702,6 +702,8 @@ int cf_fmt_encapsulation(const char **, const short *encapp);
extern int cf_limbo;
extern __thread struct config_main config;
#define IF_DEBUG(flagname) (config.debug.flagname)
int cf_init(void);
int cf_load(void);
int cf_load_strict(void);

View File

@ -31,8 +31,7 @@ DEFINE_CMD(app_config_schema, CLIFLAG_PERMISSIVE_CONFIG,
"config", "schema");
static int app_config_schema(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
struct cf_om_node *root = NULL;
if (cf_sch_config_main(&root) == -1) {
cf_om_free_node(&root);
@ -53,8 +52,7 @@ DEFINE_CMD(app_config_dump, CLIFLAG_PERMISSIVE_CONFIG,
"config","dump","[--full]");
static int app_config_dump(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
int full = 0 == cli_arg(parsed, "--full", NULL, NULL, NULL);
if (create_serval_instance_dir() == -1)
return -1;
@ -120,8 +118,7 @@ DEFINE_CMD(app_config_set, CLIFLAG_PERMISSIVE_CONFIG,
"config","sync","...");
static int app_config_set(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
if (create_serval_instance_dir() == -1)
return -1;
// <kludge>
@ -207,8 +204,7 @@ DEFINE_CMD(app_config_get, CLIFLAG_PERMISSIVE_CONFIG,
"config","get","[<variable>]");
static int app_config_get(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
const char *var;
if (cli_arg(parsed, "variable", &var, is_configvarpattern, NULL) == -1)
return -1;
@ -241,8 +237,7 @@ DEFINE_CMD(app_config_paths, CLIFLAG_PERMISSIVE_CONFIG,
"config", "paths");
static int app_config_paths(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
if (cf_om_reload() == -1)
return -1;
char path[1024];

View File

@ -132,9 +132,9 @@ static int cf_om_make_child(struct cf_om_node **const parentp, const char *const
c = strncmp(key, child->key, keylen);
if (c == 0 && child->key[keylen])
c = -1;
//DEBUGF(" m=%u n=%u i=%u child->key=%s c=%d", m, n, i, alloca_str_toprint(child->key), c);
//DEBUGF(config, " m=%u n=%u i=%u child->key=%s c=%d", m, n, i, alloca_str_toprint(child->key), c);
if (c == 0) {
//DEBUGF(" found i=%u", i);
//DEBUGF(config, " found i=%u", i);
return i;
}
if (c > 0)
@ -159,7 +159,7 @@ static int cf_om_make_child(struct cf_om_node **const parentp, const char *const
for (j = (*parentp)->nodc - 1; j > i; --j)
(*parentp)->nodv[j] = (*parentp)->nodv[j-1];
(*parentp)->nodv[i] = child;
//DEBUGF(" insert i=%u", i);
//DEBUGF(config, " insert i=%u", i);
return i;
}
@ -237,7 +237,7 @@ int cf_om_parse(const char *source, const char *buf, size_t len, struct cf_om_no
nextline = lend + 1;
if (lend > line && lend[-1] == '\r')
--lend;
//DEBUGF("lineno=%u %s", lineno, alloca_toprint(-1, line, lend - line));
//DEBUGF(config, "lineno=%u %s", lineno, alloca_toprint(-1, line, lend - line));
if (line[0] == '#')
continue; // skip comment lines
const char *p;
@ -293,7 +293,7 @@ int cf_om_parse(const char *source, const char *buf, size_t len, struct cf_om_no
void cf_om_free_node(struct cf_om_node **nodep)
{
if (*nodep) {
//DEBUGF("%s text=%s nodc=%d", (*nodep)->fullkey, alloca_str_toprint((*nodep)->text), (*nodep)->nodc);
//DEBUGF(config, "%s text=%s nodc=%d", (*nodep)->fullkey, alloca_str_toprint((*nodep)->text), (*nodep)->nodc);
while ((*nodep)->nodc)
cf_om_free_node(&(*nodep)->nodv[--(*nodep)->nodc]);
if ((*nodep)->fullkey) {
@ -312,9 +312,9 @@ void cf_om_free_node(struct cf_om_node **nodep)
void cf_om_dump_node(const struct cf_om_node *node, int indent)
{
if (node == NULL)
DEBUGF("%*sNULL", indent * 3, "");
_DEBUGF("%*sNULL", indent * 3, "");
else {
DEBUGF("%*s%s:%u fullkey=%s key=%s text=%s", indent * 3, "",
_DEBUGF("%*s%s:%u fullkey=%s key=%s text=%s", indent * 3, "",
node->source ? node->source : "NULL",
node->line_number,
alloca_str_toprint(node->fullkey),
@ -330,15 +330,15 @@ void cf_om_dump_node(const struct cf_om_node *node, int indent)
int cf_om_match(const char *pattern, const struct cf_om_node *node)
{
if (node == NULL) {
//DEBUGF("pattern='%s' node=NULL", pattern);
//DEBUGF(config, "pattern='%s' node=NULL", pattern);
return 0;
}
if (node->fullkey == NULL) {
//DEBUGF("pattern='%s' node->fullkey=NULL", pattern);
//DEBUGF(config, "pattern='%s' node->fullkey=NULL", pattern);
return 0;
}
/*
DEBUGF("pattern='%s' node->fullkey=%s node->nodc=%d node->text=%s",
DEBUGF(config, "pattern='%s' node->fullkey=%s node->nodc=%d node->text=%s",
pattern,
alloca_str_toprint(node->fullkey),
node->nodc,
@ -353,7 +353,7 @@ int cf_om_match(const char *pattern, const struct cf_om_node *node)
const char *const fullkeyend = node->fullkey + strlen(node->fullkey);
const char *keyend = NULL;
const char *patend = pat;
//DEBUGF(" pat=%s key=%s", alloca_str_toprint(pat), alloca_str_toprint(key));
//DEBUGF(config, " pat=%s key=%s", alloca_str_toprint(pat), alloca_str_toprint(key));
while (pat < pattern_end && key <= fullkeyend && (keyend = cf_find_keyend(key, fullkeyend)) && (patend = cf_find_keypattern_end(pat, pattern_end))) {
if (pat[0] == '*') {
if (pat[1] == '*')
@ -370,9 +370,9 @@ int cf_om_match(const char *pattern, const struct cf_om_node *node)
++pat;
if (*key)
++key;
//DEBUGF(" pat=%s key=%s", alloca_str_toprint(pat), alloca_str_toprint(key));
//DEBUGF(config, " pat=%s key=%s", alloca_str_toprint(pat), alloca_str_toprint(key));
}
//DEBUGF(" patend=%s keyend=%s", alloca_str_toprint(patend), alloca_str_toprint(keyend));
//DEBUGF(config, " patend=%s keyend=%s", alloca_str_toprint(patend), alloca_str_toprint(keyend));
return patend == NULL ? -1 : keyend && keyend == fullkeyend && pat == pattern_end;
}

View File

@ -910,7 +910,7 @@ int cf_cmp_pattern_list(const struct pattern_list *a, const struct pattern_list
*/
static int cf_opt_network_interface_legacy(struct config_network_interface *nifp, const char *text)
{
//DEBUGF("%s text=%s", __FUNCTION__, alloca_str_toprint(text));
//DEBUGF(config, "%s text=%s", __FUNCTION__, alloca_str_toprint(text));
struct config_network_interface nif;
cf_dfl_config_network_interface(&nif);
if (text[0] != '+' && text[0] != '-')

View File

@ -261,6 +261,7 @@ ATOM(bool_t, rhizome_tx, 0, boolean,, "")
ATOM(bool_t, rhizome_rx, 0, boolean,, "")
ATOM(bool_t, rhizome_ads, 0, boolean,, "")
ATOM(bool_t, rhizome_mdp_rx, 0, boolean,, "")
ATOM(bool_t, rhizome_direct, 0, boolean,, "")
ATOM(bool_t, subscriber, 0, boolean,, "")
ATOM(bool_t, meshms, 0, boolean,, "")
ATOM(bool_t, vomp, 0, boolean,, "")

View File

@ -101,7 +101,7 @@ static void directory_update(struct sched_ent *alarm){
alarm->deadline = alarm->alarm + 10000;
schedule(alarm);
}else
DEBUGF("Directory service is not reachable");
INFOF("Directory service is not reachable");
}
}

View File

@ -146,8 +146,7 @@ static void
dna_helper_close_pipes()
{
if (dna_helper_stdin != -1) {
if (config.debug.dnahelper)
DEBUGF("DNAHELPER closing stdin pipe fd=%d", dna_helper_stdin);
DEBUGF(dnahelper, "DNAHELPER closing stdin pipe fd=%d", dna_helper_stdin);
close(dna_helper_stdin);
dna_helper_stdin = -1;
}
@ -156,8 +155,7 @@ dna_helper_close_pipes()
sched_requests.poll.fd = -1;
}
if (dna_helper_stdout != -1) {
if (config.debug.dnahelper)
DEBUGF("DNAHELPER closing stdout pipe fd=%d", dna_helper_stdout);
DEBUGF(dnahelper, "DNAHELPER closing stdout pipe fd=%d", dna_helper_stdout);
close(dna_helper_stdout);
dna_helper_stdout = -1;
}
@ -166,8 +164,7 @@ dna_helper_close_pipes()
sched_replies.poll.fd = -1;
}
if (dna_helper_stderr != -1) {
if (config.debug.dnahelper)
DEBUGF("DNAHELPER closing stderr pipe fd=%d", dna_helper_stderr);
DEBUGF(dnahelper, "DNAHELPER closing stderr pipe fd=%d", dna_helper_stderr);
close(dna_helper_stderr);
dna_helper_stderr = -1;
}
@ -293,8 +290,7 @@ dna_helper_kill()
awaiting_reply = 0;
}
if (dna_helper_pid > 0) {
if (config.debug.dnahelper)
DEBUGF("DNAHELPER sending SIGTERM to pid=%d", dna_helper_pid);
DEBUGF(dnahelper, "DNAHELPER sending SIGTERM to pid=%d", dna_helper_pid);
if (kill(dna_helper_pid, SIGTERM) == -1)
WHYF_perror("kill(%d, SIGTERM)", dna_helper_pid);
// The process is wait()ed for in dna_helper_monitor() so that we do not block here.
@ -307,8 +303,8 @@ static int
dna_helper_harvest(int blocking)
{
if (dna_helper_pid > 0) {
if (blocking && (config.debug.dnahelper))
DEBUGF("DNAHELPER waiting for pid=%d to die", dna_helper_pid);
if (blocking)
DEBUGF(dnahelper, "DNAHELPER waiting for pid=%d to die", dna_helper_pid);
int status;
pid_t pid = waitpid(dna_helper_pid, &status, blocking ? 0 : WNOHANG);
if (pid == dna_helper_pid) {
@ -332,8 +328,7 @@ dna_helper_harvest(int blocking)
int dna_helper_shutdown()
{
if (config.debug.dnahelper)
DEBUG("DNAHELPER shutting down");
DEBUG(dnahelper, "DNAHELPER shutting down");
dna_helper_close_pipes();
switch (dna_helper_kill()) {
case -1:
@ -347,19 +342,16 @@ int dna_helper_shutdown()
static void monitor_requests(struct sched_ent *alarm)
{
if (config.debug.dnahelper) {
DEBUGF("sched_requests.poll.fd=%d .revents=%s",
sched_requests.poll.fd,
strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_requests.poll.revents))
);
}
DEBUGF(dnahelper, "sched_requests.poll.fd=%d .revents=%s",
sched_requests.poll.fd,
strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_requests.poll.revents))
);
assert(alarm == &sched_requests);
// On Linux, poll(2) returns ERR when the remote reader dies. On Mac OS X, poll(2) returns NVAL,
// which is documented to mean the file descriptor is not open, but testing revealed that in this
// case it is still open. See issue #5.
if (sched_requests.poll.revents & (POLLHUP | POLLERR | POLLNVAL)) {
if (config.debug.dnahelper)
DEBUGF("DNAHELPER closing stdin fd=%d", dna_helper_stdin);
DEBUGF(dnahelper, "DNAHELPER closing stdin fd=%d", dna_helper_stdin);
close(dna_helper_stdin);
dna_helper_stdin = -1;
unwatch(&sched_requests);
@ -381,8 +373,7 @@ static void monitor_requests(struct sched_ent *alarm)
INFO("DNAHELPER got SIGPIPE on write -- stopping process");
dna_helper_kill();
} else if (written > 0) {
if (config.debug.dnahelper)
DEBUGF("DNAHELPER wrote request %s", alloca_toprint(-1, request_bufptr, written));
DEBUGF(dnahelper, "DNAHELPER wrote request %s", alloca_toprint(-1, request_bufptr, written));
request_bufptr += written;
}
}
@ -417,8 +408,7 @@ void handle_reply_line(const char *bufp, size_t len)
{
if (!dna_helper_started) {
if (len == 8 && strncmp(bufp, "STARTED\n", 8) == 0) {
if (config.debug.dnahelper)
DEBUGF("DNAHELPER got STARTED ACK");
DEBUGF(dnahelper, "DNAHELPER got STARTED ACK");
dna_helper_started = 1;
// Start sending request if there is one pending.
if (request_bufptr) {
@ -431,8 +421,7 @@ void handle_reply_line(const char *bufp, size_t len)
}
} else if (awaiting_reply) {
if (len == 5 && strncmp(bufp, "DONE\n", 5) == 0) {
if (config.debug.dnahelper)
DEBUG("DNAHELPER reply DONE");
DEBUG(dnahelper, "DNAHELPER reply DONE");
unschedule(&sched_timeout);
awaiting_reply = 0;
} else {
@ -462,8 +451,7 @@ void handle_reply_line(const char *bufp, size_t len)
else if (*replyend != '\n')
WHYF("DNAHELPER reply %s contains spurious trailing chars -- ignored", alloca_toprint(-1, bufp, len));
else {
if (config.debug.dnahelper)
DEBUGF("DNAHELPER reply %s", alloca_toprint(-1, bufp, len));
DEBUGF(dnahelper, "DNAHELPER reply %s", alloca_toprint(-1, bufp, len));
overlay_mdp_dnalookup_reply(request_source, request_port, my_subscriber, uri, did, name);
}
}
@ -474,12 +462,10 @@ void handle_reply_line(const char *bufp, size_t len)
static void monitor_replies(struct sched_ent *alarm)
{
if (config.debug.dnahelper) {
DEBUGF("sched_replies.poll.fd=%d .revents=%s",
DEBUGF(dnahelper, "sched_replies.poll.fd=%d .revents=%s",
sched_replies.poll.fd,
strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_replies.poll.revents))
);
}
assert(alarm == &sched_replies);
if (sched_replies.poll.revents & POLLIN) {
size_t remaining = reply_buffer + sizeof reply_buffer - reply_bufend;
@ -492,8 +478,7 @@ static void monitor_replies(struct sched_ent *alarm)
while (nread > 0 && (nl = srv_strnstr(readp, nread, "\n"))) {
size_t len = nl - bufp + 1;
if (discarding_until_nl) {
if (config.debug.dnahelper)
DEBUGF("Discarding %s", alloca_toprint(-1, bufp, len));
DEBUGF(dnahelper, "Discarding %s", alloca_toprint(-1, bufp, len));
discarding_until_nl = 0;
} else {
handle_reply_line(bufp, len);
@ -507,16 +492,14 @@ static void monitor_replies(struct sched_ent *alarm)
reply_bufend = reply_buffer + len;
} else if (reply_bufend >= reply_buffer + sizeof reply_buffer) {
WHY("DNAHELPER reply buffer overrun");
if (config.debug.dnahelper)
DEBUGF("Discarding %s", alloca_toprint(-1, reply_buffer, sizeof reply_buffer));
DEBUGF(dnahelper, "Discarding %s", alloca_toprint(-1, reply_buffer, sizeof reply_buffer));
reply_bufend = reply_buffer;
discarding_until_nl = 1;
}
}
}
if (sched_replies.poll.revents & (POLLHUP | POLLERR | POLLNVAL)) {
if (config.debug.dnahelper)
DEBUGF("DNAHELPER closing stdout fd=%d", dna_helper_stdout);
DEBUGF(dnahelper, "DNAHELPER closing stdout fd=%d", dna_helper_stdout);
close(dna_helper_stdout);
dna_helper_stdout = -1;
unwatch(&sched_replies);
@ -527,12 +510,10 @@ static void monitor_replies(struct sched_ent *alarm)
static void monitor_errors(struct sched_ent *alarm)
{
if (config.debug.dnahelper) {
DEBUGF("sched_errors.poll.fd=%d .revents=%s",
DEBUGF(dnahelper, "sched_errors.poll.fd=%d .revents=%s",
sched_errors.poll.fd,
strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_errors.poll.revents))
);
}
assert(alarm == &sched_errors);
if (sched_errors.poll.revents & POLLIN) {
char buffer[1024];
@ -541,8 +522,7 @@ static void monitor_errors(struct sched_ent *alarm)
WHYF("DNAHELPER stderr %s", alloca_toprint(-1, buffer, nread));
}
if (sched_errors.poll.revents & (POLLHUP | POLLERR | POLLNVAL)) {
if (config.debug.dnahelper)
DEBUGF("DNAHELPER closing stderr fd=%d", dna_helper_stderr);
DEBUGF(dnahelper, "DNAHELPER closing stderr fd=%d", dna_helper_stderr);
close(dna_helper_stderr);
dna_helper_stderr = -1;
unwatch(&sched_errors);
@ -561,8 +541,7 @@ static void harvester(struct sched_ent *alarm)
schedule(&sched_harvester);
} else {
const int delay_ms = 500;
if (config.debug.dnahelper)
DEBUGF("DNAHELPER process died, pausing %d ms before restart", delay_ms);
DEBUGF(dnahelper, "DNAHELPER process died, pausing %d ms before restart", delay_ms);
dna_helper_pid = 0; // Will be set to -1 after delay
sched_restart.function = restart_delayer;
sched_restart.alarm = gettime_ms() + delay_ms;
@ -575,8 +554,7 @@ static void restart_delayer(struct sched_ent *alarm)
{
assert(alarm == &sched_restart);
if (dna_helper_pid == 0) {
if (config.debug.dnahelper)
DEBUG("DNAHELPER re-enable restart");
DEBUG(dnahelper, "DNAHELPER re-enable restart");
dna_helper_pid = -1;
}
}
@ -593,8 +571,7 @@ static void reply_timeout(struct sched_ent *alarm)
int
dna_helper_enqueue(struct subscriber *source, mdp_port_t source_port, const char *did)
{
if (config.debug.dnahelper)
DEBUGF("DNAHELPER request did=%s sid=%s", did, alloca_tohex_sid_t(source->sid));
DEBUGF(dnahelper, "DNAHELPER request did=%s sid=%s", did, alloca_tohex_sid_t(source->sid));
if (dna_helper_pid == 0)
return 0;
// Only try to restart a DNA helper process if the previous one is well and truly gone.

View File

@ -72,22 +72,22 @@ void list_alarms()
time_ms_t now = gettime_ms();
struct sched_ent *alarm;
DEBUG("Run now;");
_DEBUG("Run now;");
for (alarm = run_now; alarm; alarm=alarm->_next_run)
DEBUGF("%p %s deadline in %"PRId64"ms", alarm->function, alloca_alarm_name(alarm), alarm->run_before - now);
_DEBUGF("%p %s deadline in %"PRId64"ms", alarm->function, alloca_alarm_name(alarm), alarm->run_before - now);
DEBUG("Run soon;");
_DEBUG("Run soon;");
for (alarm = run_soon; alarm; alarm=alarm->_next_run)
DEBUGF("%p %s run in %"PRId64"ms", alarm->function, alloca_alarm_name(alarm), alarm->run_after - now);
_DEBUGF("%p %s run in %"PRId64"ms", alarm->function, alloca_alarm_name(alarm), alarm->run_after - now);
DEBUG("Wake at;");
_DEBUG("Wake at;");
for (alarm = wake_list; alarm; alarm = alarm->_next_wake)
DEBUGF("%p %s wake in %"PRId64"ms", alarm->function, alloca_alarm_name(alarm), alarm->wake_at - now);
_DEBUGF("%p %s wake in %"PRId64"ms", alarm->function, alloca_alarm_name(alarm), alarm->wake_at - now);
DEBUG("File handles;");
_DEBUG("File handles;");
int i;
for (i = 0; i < fdcount; ++i)
DEBUGF("%s watching #%d for %x", alloca_alarm_name(fd_callbacks[i]), fds[i].fd, fds[i].events);
_DEBUGF("%s watching #%d for %x", alloca_alarm_name(fd_callbacks[i]), fds[i].fd, fds[i].events);
}
static void insert_run_now(struct sched_ent *alarm)
@ -173,8 +173,7 @@ static void move_run_list(){
run_soon = run_soon->_next_run;
remove_wake_list(alarm);
insert_run_now(alarm);
if (config.debug.io)
DEBUGF("Moved %s from run_soon to run_now", alloca_alarm_name(alarm));
DEBUGF(io, "Moved %s from run_soon to run_now", alloca_alarm_name(alarm));
}
}
@ -189,9 +188,9 @@ void _schedule(struct __sourceloc __whence, struct sched_ent *alarm)
if (alarm->run_after == TIME_MS_NEVER_WILL || alarm->run_after==0)
alarm->run_after = alarm->wake_at;
if (config.debug.io){
if (IF_DEBUG(io)){
time_ms_t now = gettime_ms();
DEBUGF("schedule(alarm=%s) run_after=%.3f wake_at=%.3f run_before=%.3f",
DEBUGF(io, "schedule(alarm=%s) run_after=%.3f wake_at=%.3f run_before=%.3f",
alloca_alarm_name(alarm),
(double)(alarm->run_after - now) / 1000,
(double)(alarm->wake_at - now) / 1000,
@ -225,8 +224,7 @@ void _unschedule(struct __sourceloc __whence, struct sched_ent *alarm)
if (!is_scheduled(alarm))
return;
if (config.debug.io)
DEBUGF("unschedule(alarm=%s)", alloca_alarm_name(alarm));
DEBUGF(io, "unschedule(alarm=%s)", alloca_alarm_name(alarm));
remove_run_list(alarm, &run_now);
remove_run_list(alarm, &run_soon);
@ -238,8 +236,7 @@ void _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
int _watch(struct __sourceloc __whence, struct sched_ent *alarm)
{
if (config.debug.io)
DEBUGF("watch(alarm=%s)", alloca_alarm_name(alarm));
DEBUGF(io, "watch(alarm=%s)", alloca_alarm_name(alarm));
if (!alarm->stats)
WARN("watch() called without supplying an alarm name");
@ -250,11 +247,9 @@ int _watch(struct __sourceloc __whence, struct sched_ent *alarm)
if (alarm->_poll_index>=0 && fd_callbacks[alarm->_poll_index]==alarm){
// updating event flags
if (config.debug.io)
DEBUGF("Updating watch %s, #%d for %s", alloca_alarm_name(alarm), alarm->poll.fd, alloca_poll_events(alarm->poll.events));
DEBUGF(io, "Updating watch %s, #%d for %s", alloca_alarm_name(alarm), alarm->poll.fd, alloca_poll_events(alarm->poll.events));
}else{
if (config.debug.io)
DEBUGF("Adding watch %s, #%d for %s", alloca_alarm_name(alarm), alarm->poll.fd, alloca_poll_events(alarm->poll.events));
DEBUGF(io, "Adding watch %s, #%d for %s", alloca_alarm_name(alarm), alarm->poll.fd, alloca_poll_events(alarm->poll.events));
if (fdcount>=MAX_WATCHED_FDS)
return WHY("Too many file handles to watch");
fd_callbacks[fdcount]=alarm;
@ -276,8 +271,7 @@ int is_watching(struct sched_ent *alarm)
// stop watching a file handle
int _unwatch(struct __sourceloc __whence, struct sched_ent *alarm)
{
if (config.debug.io)
DEBUGF("unwatch(alarm=%s)", alloca_alarm_name(alarm));
DEBUGF(io, "unwatch(alarm=%s)", alloca_alarm_name(alarm));
int index = alarm->_poll_index;
if (index <0 || fds[index].fd!=alarm->poll.fd)
@ -293,8 +287,7 @@ int _unwatch(struct __sourceloc __whence, struct sched_ent *alarm)
fds[fdcount].fd=-1;
fd_callbacks[fdcount]=NULL;
alarm->_poll_index=-1;
if (config.debug.io)
DEBUGF("%s stopped watching #%d for %s", alloca_alarm_name(alarm), alarm->poll.fd, alloca_poll_events(alarm->poll.events));
DEBUGF(io, "%s stopped watching #%d for %s", alloca_alarm_name(alarm), alarm->poll.fd, alloca_poll_events(alarm->poll.events));
return 0;
}
@ -306,8 +299,7 @@ static void call_alarm(struct sched_ent *alarm, int revents)
struct call_stats call_stats;
call_stats.totals = alarm->stats;
if (config.debug.io)
DEBUGF("Calling alarm/callback %p %s", alarm, alloca_alarm_name(alarm));
DEBUGF(io, "Calling alarm/callback %p %s", alarm, alloca_alarm_name(alarm));
if (call_stats.totals)
fd_func_enter(__HERE__, &call_stats);
@ -320,8 +312,7 @@ static void call_alarm(struct sched_ent *alarm, int revents)
if (call_stats.totals)
fd_func_exit(__HERE__, &call_stats);
if (config.debug.io)
DEBUGF("Alarm %p returned",alarm);
DEBUGF(io, "Alarm %p returned",alarm);
OUT();
}
@ -382,8 +373,7 @@ int fd_poll2(time_ms_t (*waiting)(time_ms_t, time_ms_t, time_ms_t), void (*wokeu
wait = wait_until - now;
if (fdcount){
if (config.debug.io)
DEBUGF("Calling poll with %dms wait", wait);
DEBUGF(io, "Calling poll with %dms wait", wait);
fd_func_enter(__HERE__, &call_stats);
r = poll(fds, fdcount, wait);
@ -392,7 +382,7 @@ int fd_poll2(time_ms_t (*waiting)(time_ms_t, time_ms_t, time_ms_t), void (*wokeu
if (r==-1 && errno!=EINTR)
WHY_perror("poll");
if (config.debug.io) {
if (IF_DEBUG(io)) {
strbuf b = strbuf_alloca(1024);
int i;
for (i = 0; i < fdcount; ++i) {
@ -403,7 +393,7 @@ int fd_poll2(time_ms_t (*waiting)(time_ms_t, time_ms_t, time_ms_t), void (*wokeu
strbuf_puts(b, "->");
strbuf_append_poll_events(b, fds[i].revents);
}
DEBUGF("poll(fds=(%s), fdcount=%d, ms=%d) -> %d", strbuf_str(b), fdcount, wait, r);
DEBUGF(io, "poll(fds=(%s), fdcount=%d, ms=%d) -> %d", strbuf_str(b), fdcount, wait, r);
}
}else if(wait>0){

View File

@ -74,20 +74,16 @@ static struct profile_total http_server_stats = {
.name = "http_server_poll",
};
#define DEBUG_DUMP_PARSED(r) do { \
if (config.debug.http_server) \
DEBUGF("%s %s HTTP/%u.%u", r->verb ? r->verb : "NULL", alloca_str_toprint(r->path), r->version_major, r->version_minor);\
} while (0)
#define DEBUG_DUMP_PARSED(r) \
DEBUGF(http_server, "%s %s HTTP/%u.%u", r->verb ? r->verb : "NULL", alloca_str_toprint(r->path), r->version_major, r->version_minor)
#define DEBUG_DUMP_PARSER(r) do { \
if (config.debug.http_server) \
DEBUGF("parsed %d %s cursor %d %s end %d remain %"PRIhttp_size_t, \
(int)(r->parsed - r->received), alloca_toprint(-1, r->parsed, r->cursor - r->parsed), \
(int)(r->cursor - r->received), alloca_toprint(50, r->cursor, r->end - r->cursor), \
(int)(r->end - r->received), \
r->request_content_remaining \
); \
} while (0)
#define DEBUG_DUMP_PARSER(r) \
DEBUGF(http_server, "parsed %d %s cursor %d %s end %d remain %"PRIhttp_size_t, \
(int)(r->parsed - r->received), alloca_toprint(-1, r->parsed, r->cursor - r->parsed), \
(int)(r->cursor - r->received), alloca_toprint(50, r->cursor, r->end - r->cursor), \
(int)(r->end - r->received), \
r->request_content_remaining \
)
static void http_server_poll(struct sched_ent *);
static void http_request_set_idle_timeout(struct http_request *r);
@ -137,7 +133,7 @@ void http_request_free_response_buffer(struct http_request *r)
{
if (r->response_free_buffer) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Free response buffer of %zu bytes", r->response_buffer_size);
_DEBUGF("Free response buffer of %zu bytes", r->response_buffer_size);
r->response_free_buffer(r->response_buffer);
r->response_free_buffer = NULL;
}
@ -157,7 +153,7 @@ int http_request_set_response_bufsize(struct http_request *r, size_t bufsiz)
r->response_buffer = (char *) r->reserved;
r->response_buffer_size = rbufsiz;
if (r->debug_flag && *r->debug_flag)
DEBUGF("Static response buffer %zu bytes", r->response_buffer_size);
_DEBUGF("Static response buffer %zu bytes", r->response_buffer_size);
return 0;
}
if (bufsiz != r->response_buffer_size) {
@ -167,7 +163,7 @@ int http_request_set_response_bufsize(struct http_request *r, size_t bufsiz)
r->response_free_buffer = free;
r->response_buffer_size = bufsiz;
if (r->debug_flag && *r->debug_flag)
DEBUGF("Allocated response buffer %zu bytes", r->response_buffer_size);
_DEBUGF("Allocated response buffer %zu bytes", r->response_buffer_size);
}
assert(r->response_buffer_size >= bufsiz);
assert(r->response_buffer != NULL);
@ -651,7 +647,7 @@ static int _parse_content_type(struct http_request *r, struct mime_content_type
struct substring param;
if (_skip_token(r, &param) && _skip_literal(r, "=") && _parse_token_or_quoted_string(r, NULL, 0)) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Skipping HTTP Content-Type parameter: %s", alloca_substring_toprint(param));
_DEBUGF("Skipping HTTP Content-Type parameter: %s", alloca_substring_toprint(param));
continue;
}
WARNF("Malformed HTTP Content-Type: %s", alloca_toprint(50, r->cursor, r->end - r->cursor));
@ -695,23 +691,23 @@ static int _parse_authorization(struct http_request *r, struct http_client_autho
return 1;
}
if (r->debug_flag && *r->debug_flag)
DEBUGF("Malformed HTTP header: Authorization: %s", alloca_toprint(50, start, header_bytes));
_DEBUGF("Malformed HTTP header: Authorization: %s", alloca_toprint(50, start, header_bytes));
return 0;
}
if (_skip_literal(r, "Digest") && _skip_space(r)) {
if (r->debug_flag && *r->debug_flag)
DEBUG("Ignoring unsupported HTTP Authorization scheme: Digest");
_DEBUG("Ignoring unsupported HTTP Authorization scheme: Digest");
r->cursor += header_bytes;
return 1;
}
struct substring scheme;
if (_skip_token(r, &scheme) && _skip_space(r)) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Unrecognised HTTP Authorization scheme: %s", alloca_toprint(-1, scheme.start, scheme.end - scheme.start));
_DEBUGF("Unrecognised HTTP Authorization scheme: %s", alloca_toprint(-1, scheme.start, scheme.end - scheme.start));
return 0;
}
if (r->debug_flag && *r->debug_flag)
DEBUGF("Malformed HTTP Authorization header: %s", alloca_toprint(50, r->parsed, r->end - r->parsed));
_DEBUGF("Malformed HTTP Authorization header: %s", alloca_toprint(50, r->parsed, r->end - r->parsed));
return 0;
}
@ -773,7 +769,7 @@ static int http_request_parse_verb(struct http_request *r)
}
if (r->verb == NULL) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Malformed HTTP request, invalid verb: %s", alloca_toprint(20, r->cursor, r->end - r->cursor));
_DEBUGF("Malformed HTTP request, invalid verb: %s", alloca_toprint(20, r->cursor, r->end - r->cursor));
return 400;
}
_commit(r);
@ -798,7 +794,7 @@ static int http_request_parse_path(struct http_request *r)
if (_run_out(r))
return 100; // read more and try again
if (r->debug_flag && *r->debug_flag)
DEBUGF("Malformed HTTP %s request at path: %s", r->verb, alloca_toprint(20, r->parsed, r->end - r->parsed));
_DEBUGF("Malformed HTTP %s request at path: %s", r->verb, alloca_toprint(20, r->parsed, r->end - r->parsed));
return 400;
}
_commit(r);
@ -834,7 +830,7 @@ static int http_request_parse_http_version(struct http_request *r)
if (_run_out(r))
return 100; // read more and try again
if (r->debug_flag && *r->debug_flag)
DEBUGF("Malformed HTTP %s request at version: %s", r->verb, alloca_toprint(20, r->parsed, r->end - r->parsed));
_DEBUGF("Malformed HTTP %s request at version: %s", r->verb, alloca_toprint(20, r->parsed, r->end - r->parsed));
return 400;
}
_commit(r);
@ -859,7 +855,7 @@ static int http_request_start_parsing_headers(struct http_request *r)
assert(r->version_major != 0);
if (r->version_major != 1) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Unsupported HTTP version: %u.%u", r->version_major, r->version_minor);
_DEBUGF("Unsupported HTTP version: %u.%u", r->version_major, r->version_minor);
return 400;
}
r->parser = http_request_parse_header;
@ -904,7 +900,7 @@ static int http_request_parse_header(struct http_request *r)
if (_skip_literal_nocase(r, "Content-Length:")) {
if (r->request_header.content_length != CONTENT_LENGTH_UNKNOWN) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Skipping duplicate HTTP header Content-Length: %s", alloca_toprint(50, sol, r->end - sol));
_DEBUGF("Skipping duplicate HTTP header Content-Length: %s", alloca_toprint(50, sol, r->end - sol));
r->cursor = nextline;
_commit(r);
return 0;
@ -916,7 +912,7 @@ static int http_request_parse_header(struct http_request *r)
_commit(r);
r->request_header.content_length = length;
if (r->debug_flag && *r->debug_flag)
DEBUGF("Parsed HTTP request Content-Length: %"PRIhttp_size_t, r->request_header.content_length);
_DEBUGF("Parsed HTTP request Content-Length: %"PRIhttp_size_t, r->request_header.content_length);
return 0;
}
goto malformed;
@ -925,7 +921,7 @@ static int http_request_parse_header(struct http_request *r)
if (_skip_literal_nocase(r, "Content-Type:")) {
if (r->request_header.content_type.type[0]) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Skipping duplicate HTTP header Content-Type: %s", alloca_toprint(50, sol, r->end - sol));
_DEBUGF("Skipping duplicate HTTP header Content-Type: %s", alloca_toprint(50, sol, r->end - sol));
r->cursor = nextline;
_commit(r);
return 0;
@ -938,7 +934,7 @@ static int http_request_parse_header(struct http_request *r)
r->cursor = nextline;
_commit(r);
if (r->debug_flag && *r->debug_flag)
DEBUGF("Parsed HTTP request Content-type: %s", alloca_mime_content_type(&r->request_header.content_type));
_DEBUGF("Parsed HTTP request Content-type: %s", alloca_mime_content_type(&r->request_header.content_type));
return 0;
}
goto malformed;
@ -947,7 +943,7 @@ static int http_request_parse_header(struct http_request *r)
if (_skip_literal_nocase(r, "Range:")) {
if (r->request_header.content_range_count) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Skipping duplicate HTTP header Range: %s", alloca_toprint(50, sol, r->end - sol));
_DEBUGF("Skipping duplicate HTTP header Range: %s", alloca_toprint(50, sol, r->end - sol));
r->cursor = nextline;
_commit(r);
return 0;
@ -963,14 +959,14 @@ static int http_request_parse_header(struct http_request *r)
_commit(r);
if (n > NELS(r->request_header.content_ranges)) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("HTTP request Range header overflow (%u ranges in set, can only handle %zu): %s",
_DEBUGF("HTTP request Range header overflow (%u ranges in set, can only handle %zu): %s",
n, NELS(r->request_header.content_ranges), alloca_toprint(-1, sol, eol - sol));
// In this case ignore the Range: header -- respond with the entire resource.
r->request_header.content_range_count = 0;
} else {
r->request_header.content_range_count = n;
if (r->debug_flag && *r->debug_flag)
DEBUGF("Parsed HTTP request Range: bytes=%s", alloca_http_ranges(r->request_header.content_ranges));
_DEBUGF("Parsed HTTP request Range: bytes=%s", alloca_http_ranges(r->request_header.content_ranges));
}
return 0;
}
@ -980,7 +976,7 @@ static int http_request_parse_header(struct http_request *r)
if (_skip_literal_nocase(r, "Authorization:")) {
if (r->request_header.authorization.scheme != NOAUTH) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Skipping duplicate HTTP header Authorization: %s", alloca_toprint(50, sol, r->end - sol));
_DEBUGF("Skipping duplicate HTTP header Authorization: %s", alloca_toprint(50, sol, r->end - sol));
r->cursor = nextline;
_commit(r);
return 0;
@ -1003,7 +999,7 @@ static int http_request_parse_header(struct http_request *r)
if (_skip_literal_nocase(r, "Origin:")) {
if (r->request_header.origin) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Skipping duplicate HTTP header Origin: %s", alloca_toprint(50, sol, r->end - sol));
_DEBUGF("Skipping duplicate HTTP header Origin: %s", alloca_toprint(50, sol, r->end - sol));
r->cursor = nextline;
_commit(r);
return 0;
@ -1022,13 +1018,13 @@ static int http_request_parse_header(struct http_request *r)
}
_rewind(r);
if (r->debug_flag && *r->debug_flag)
DEBUGF("Skipped HTTP request header: %s", alloca_toprint(-1, sol, eol - sol));
_DEBUGF("Skipped HTTP request header: %s", alloca_toprint(-1, sol, eol - sol));
r->cursor = nextline;
_commit(r);
return 0;
malformed:
if (r->debug_flag && *r->debug_flag)
DEBUGF("Malformed HTTP request header: %s", alloca_toprint(-1, sol, eol - sol));
_DEBUGF("Malformed HTTP request header: %s", alloca_toprint(-1, sol, eol - sol));
return 400;
}
@ -1050,12 +1046,12 @@ static int http_request_start_body(struct http_request *r)
// TODO: Implement HEAD requests (only send response header, not body)
if (r->request_header.content_length != 0 && r->request_header.content_length != CONTENT_LENGTH_UNKNOWN) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Malformed HTTP %s request: non-zero Content-Length not allowed", r->verb);
_DEBUGF("Malformed HTTP %s request: non-zero Content-Length not allowed", r->verb);
return 400;
}
if (r->request_header.content_type.type[0]) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Malformed HTTP %s request: Content-Type not allowed", r->verb);
_DEBUGF("Malformed HTTP %s request: Content-Type not allowed", r->verb);
return 400;
}
r->parser = NULL;
@ -1063,7 +1059,7 @@ static int http_request_start_body(struct http_request *r)
else if (r->verb == HTTP_VERB_POST) {
if (r->request_header.content_length == CONTENT_LENGTH_UNKNOWN) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Malformed HTTP %s request: missing Content-Length header", r->verb);
_DEBUGF("Malformed HTTP %s request: missing Content-Length header", r->verb);
return 411;
}
if (r->request_header.content_length == 0) {
@ -1071,7 +1067,7 @@ static int http_request_start_body(struct http_request *r)
} else {
if (r->request_header.content_type.type[0] == '\0') {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Malformed HTTP %s request: missing Content-Type header", r->verb);
_DEBUGF("Malformed HTTP %s request: missing Content-Type header", r->verb);
return 400;
}
if ( strcmp(r->request_header.content_type.type, "multipart") == 0
@ -1081,7 +1077,7 @@ static int http_request_start_body(struct http_request *r)
|| r->request_header.content_type.multipart_boundary[0] == '\0'
) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Malformed HTTP %s request: Content-Type %s/%s missing boundary parameter",
_DEBUGF("Malformed HTTP %s request: Content-Type %s/%s missing boundary parameter",
r->verb, r->request_header.content_type.type, r->request_header.content_type.subtype);
return 400;
}
@ -1089,7 +1085,7 @@ static int http_request_start_body(struct http_request *r)
r->form_data_state = START;
} else {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Unsupported HTTP %s request: Content-Type %s not supported",
_DEBUGF("Unsupported HTTP %s request: Content-Type %s not supported",
r->verb, alloca_mime_content_type(&r->request_header.content_type));
return 415;
}
@ -1097,7 +1093,7 @@ static int http_request_start_body(struct http_request *r)
}
else {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Unsupported HTTP %s request", r->verb);
_DEBUGF("Unsupported HTTP %s request", r->verb);
r->parser = NULL;
return 501;
}
@ -1115,9 +1111,9 @@ static int http_request_reject_content(struct http_request *r)
{
if (r->debug_flag && *r->debug_flag) {
if (r->request_header.content_length != CONTENT_LENGTH_UNKNOWN)
DEBUGF("Malformed HTTP %s request (Content-Length %"PRIhttp_size_t"): spurious content", r->verb, r->request_header.content_length);
_DEBUGF("Malformed HTTP %s request (Content-Length %"PRIhttp_size_t"): spurious content", r->verb, r->request_header.content_length);
else
DEBUGF("Malformed HTTP %s request: spurious content", r->verb);
_DEBUGF("Malformed HTTP %s request: spurious content", r->verb);
}
return 400;
}
@ -1195,7 +1191,7 @@ static int _parse_content_disposition(struct http_request *r, struct mime_conten
struct substring param;
if (_skip_token(r, &param) && _skip_literal(r, "=") && _parse_token_or_quoted_string(r, NULL, 0)) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Skipping HTTP Content-Disposition parameter: %s", alloca_substring_toprint(param));
_DEBUGF("Skipping HTTP Content-Disposition parameter: %s", alloca_substring_toprint(param));
continue;
}
malformed:
@ -1217,7 +1213,7 @@ malformed:
#define _INVOKE_HANDLER_VOID(FUNC) do { \
if (r->form_data.FUNC) { \
if (r->debug_flag && *r->debug_flag) \
DEBUGF(#FUNC "()"); \
_DEBUGF(#FUNC "()"); \
int result = r->form_data.FUNC(r); \
_HANDLER_RESULT(result); \
} \
@ -1225,7 +1221,7 @@ malformed:
#define _INVOKE_HANDLER_BUF_LEN(FUNC, START, END) do { \
if (r->form_data.FUNC && (START) != (END)) { \
if (r->debug_flag && *r->debug_flag) \
DEBUGF(#FUNC "(%s length=%zu)", alloca_toprint(50, (START), (END) - (START)), (END) - (START)); \
_DEBUGF(#FUNC "(%s length=%zu)", alloca_toprint(50, (START), (END) - (START)), (END) - (START)); \
int result = r->form_data.FUNC(r, (START), (END) - (START)); \
_HANDLER_RESULT(result); \
} \
@ -1279,15 +1275,13 @@ static int http_request_parse_body_form_data(struct http_request *r)
int at_start = 0;
switch (r->form_data_state) {
case START:
if (config.debug.http_server)
DEBUGF("START");
DEBUGF(http_server, "START");
// The logic here allows for a missing initial CRLF before the first boundary line.
at_start = 1;
r->form_data_state = PREAMBLE;
// fall through
case PREAMBLE: {
if (config.debug.http_server)
DEBUGF("PREAMBLE");
DEBUGF(http_server, "PREAMBLE");
char *start = r->parsed;
while (at_start || _skip_to_crlf(r)) {
char *end_preamble = r->cursor;
@ -1307,7 +1301,7 @@ static int http_request_parse_body_form_data(struct http_request *r)
}
if (_end_of_content(r)) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Malformed HTTP %s form data: missing first boundary", r->verb);
_DEBUGF("Malformed HTTP %s form data: missing first boundary", r->verb);
return 400;
}
_rewind_optional_cr(r);
@ -1317,8 +1311,7 @@ static int http_request_parse_body_form_data(struct http_request *r)
}
return 100; // need more data
case HEADER: {
if (config.debug.http_server)
DEBUGF("HEADER");
DEBUGF(http_server, "HEADER");
// If not at a CRLF, then we are skipping through an over-long header that didn't
// fit into the buffer. Just discard bytes up to the next CRLF.
if (!_skip_crlf(r)) {
@ -1326,7 +1319,7 @@ static int http_request_parse_body_form_data(struct http_request *r)
_rewind_optional_cr(r); // don't skip a CR at end of buffer (it might be part of a half-received CRLF)
assert(r->cursor > r->parsed);
if (r->debug_flag && *r->debug_flag)
DEBUGF("skipping %zu header bytes", r->cursor - r->parsed);
_DEBUGF("skipping %zu header bytes", r->cursor - r->parsed);
_commit(r);
return 0;
}
@ -1336,7 +1329,7 @@ static int http_request_parse_body_form_data(struct http_request *r)
_commit(r);
if (r->form_data.handle_mime_part_header) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("handle_mime_part_header(Content-Length: %"PRIhttp_size_t", Content-Type: %s, Content-Disposition: %s)",
_DEBUGF("handle_mime_part_header(Content-Length: %"PRIhttp_size_t", Content-Type: %s, Content-Disposition: %s)",
r->part_header.content_length,
alloca_mime_content_type(&r->part_header.content_type),
alloca_mime_content_disposition(&r->part_header.content_disposition)
@ -1372,7 +1365,7 @@ static int http_request_parse_body_form_data(struct http_request *r)
if (strcmp(labelstr, "content-length") == 0) {
if (r->part_header.content_length != CONTENT_LENGTH_UNKNOWN) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Skipping duplicate HTTP multipart header %s", alloca_toprint(50, sol, r->end - sol));
_DEBUGF("Skipping duplicate HTTP multipart header %s", alloca_toprint(50, sol, r->end - sol));
return 400;
}
http_size_t length;
@ -1381,42 +1374,42 @@ static int http_request_parse_body_form_data(struct http_request *r)
_commit(r);
r->part_header.content_length = length;
if (r->debug_flag && *r->debug_flag)
DEBUGF("Parsed HTTP multipart header Content-Length: %"PRIhttp_size_t, r->part_header.content_length);
_DEBUGF("Parsed HTTP multipart header Content-Length: %"PRIhttp_size_t, r->part_header.content_length);
return 0;
}
}
else if (strcmp(labelstr, "content-type") == 0) {
if (r->part_header.content_type.type[0]) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Skipping duplicate HTTP multipart header %s", alloca_toprint(50, sol, r->end - sol));
_DEBUGF("Skipping duplicate HTTP multipart header %s", alloca_toprint(50, sol, r->end - sol));
return 400;
}
if (_parse_content_type(r, &r->part_header.content_type) && _skip_optional_space(r) && _skip_crlf(r)) {
_rewind_crlf(r);
_commit(r);
if (r->debug_flag && *r->debug_flag)
DEBUGF("Parsed HTTP multipart header Content-Type: %s", alloca_mime_content_type(&r->part_header.content_type));
_DEBUGF("Parsed HTTP multipart header Content-Type: %s", alloca_mime_content_type(&r->part_header.content_type));
return 0;
}
}
else if (strcmp(labelstr, "content-disposition") == 0) {
if (r->part_header.content_disposition.type[0]) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Skipping duplicate HTTP multipart header %s", alloca_toprint(50, sol, r->end - sol));
_DEBUGF("Skipping duplicate HTTP multipart header %s", alloca_toprint(50, sol, r->end - sol));
return 400;
}
if (_parse_content_disposition(r, &r->part_header.content_disposition) && _skip_optional_space(r) && _skip_crlf(r)) {
_rewind_crlf(r);
_commit(r);
if (r->debug_flag && *r->debug_flag)
DEBUGF("Parsed HTTP multipart header Content-Disposition: %s", alloca_mime_content_disposition(&r->part_header.content_disposition));
_DEBUGF("Parsed HTTP multipart header Content-Disposition: %s", alloca_mime_content_disposition(&r->part_header.content_disposition));
return 0;
}
}
else if (_skip_to_crlf(r)) {
_commit(r);
if (r->debug_flag && *r->debug_flag)
DEBUGF("Skip HTTP multipart header: %s", alloca_toprint(50, sol, r->parsed - sol));
_DEBUGF("Skip HTTP multipart header: %s", alloca_toprint(50, sol, r->parsed - sol));
return 0;
}
}
@ -1428,20 +1421,19 @@ static int http_request_parse_body_form_data(struct http_request *r)
r->cursor = r->end;
_rewind_optional_cr(r);
if (r->debug_flag && *r->debug_flag)
DEBUGF("skipping %zu header bytes", r->cursor - r->parsed);
_DEBUGF("skipping %zu header bytes", r->cursor - r->parsed);
_commit(r);
return 0;
}
if (_run_out(r))
return 100; // read more and try again
if (r->debug_flag && *r->debug_flag)
DEBUGF("Malformed HTTP %s form data part: invalid header %s", r->verb, alloca_toprint(50, sol, r->end - sol));
_DEBUGF("Malformed HTTP %s form data part: invalid header %s", r->verb, alloca_toprint(50, sol, r->end - sol));
DEBUG_DUMP_PARSER(r);
}
return 400;
case BODY:
if (config.debug.http_server)
DEBUGF("BODY");
DEBUGF(http_server, "BODY");
char *start = r->parsed;
while (_skip_to_crlf(r)) {
int b;
@ -1460,7 +1452,7 @@ static int http_request_parse_body_form_data(struct http_request *r)
}
if (_end_of_content(r)) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Malformed HTTP %s form data part: missing end boundary", r->verb);
_DEBUGF("Malformed HTTP %s form data part: missing end boundary", r->verb);
return 400;
}
_rewind_optional_cr(r);
@ -1471,8 +1463,7 @@ static int http_request_parse_body_form_data(struct http_request *r)
_INVOKE_HANDLER_BUF_LEN(handle_mime_body, start, r->parsed);
return 100; // need more data
case EPILOGUE:
if (config.debug.http_server)
DEBUGF("EPILOGUE");
DEBUGF(http_server, "EPILOGUE");
r->cursor = r->end;
assert(r->cursor >= r->parsed);
_INVOKE_HANDLER_BUF_LEN(handle_mime_epilogue, r->parsed, r->cursor);
@ -1493,13 +1484,13 @@ static ssize_t http_request_read(struct http_request *r, char *buf, size_t len)
ssize_t bytes = read_nonblock(r->alarm.poll.fd, buf, len);
if (bytes == -1) {
if (r->debug_flag && *r->debug_flag)
DEBUG("HTTP socket read error, closing connection");
_DEBUG("HTTP socket read error, closing connection");
http_request_finalise(r);
return -1;
}
if (sigPipeFlag) {
if (r->debug_flag && *r->debug_flag)
DEBUG("Received SIGPIPE on HTTP socket read, closing connection");
_DEBUG("Received SIGPIPE on HTTP socket read, closing connection");
http_request_finalise(r);
return -1;
}
@ -1535,7 +1526,7 @@ static void http_request_receive(struct http_request *r)
// If there is no more buffer space, fail the request.
if (room == 0) {
if (r->debug_flag && *r->debug_flag)
DEBUG("Buffer size reached, reporting overflow");
_DEBUG("Buffer size reached, reporting overflow");
http_request_simple_response(r, 431, NULL);
RETURNVOID;
}
@ -1570,7 +1561,7 @@ static void http_request_receive(struct http_request *r)
result = r->handle_content_end(r);
else {
if (r->debug_flag && *r->debug_flag)
DEBUG("Internal failure parsing HTTP request: no end-of-content function set");
_DEBUG("Internal failure parsing HTTP request: no end-of-content function set");
result = 500;
}
} else {
@ -1578,7 +1569,7 @@ static void http_request_receive(struct http_request *r)
const char *oldparsed = r->parsed;
if (r->parser == NULL) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("No HTTP parser function set -- skipping %zu bytes", (size_t)(r->end - r->cursor));
_DEBUGF("No HTTP parser function set -- skipping %zu bytes", (size_t)(r->end - r->cursor));
_skip_all(r);
_commit(r);
result = 0;
@ -1592,7 +1583,7 @@ static void http_request_receive(struct http_request *r)
RETURNVOID; // needs more data; poll again
if (result == 0 && r->parsed == oldparsed && r->parser == oldparser) {
if (r->debug_flag && *r->debug_flag)
DEBUG("Internal failure parsing HTTP request: parser function did not advance");
_DEBUG("Internal failure parsing HTTP request: parser function did not advance");
DEBUG_DUMP_PARSER(r);
result = 500;
}
@ -1602,14 +1593,14 @@ static void http_request_receive(struct http_request *r)
r->response.result_code = result;
} else if (result) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Internal failure parsing HTTP request: invalid result=%d", result);
_DEBUGF("Internal failure parsing HTTP request: invalid result=%d", result);
r->response.result_code = 500;
}
if (r->response.result_code)
break;
if (result == -1) {
if (r->debug_flag && *r->debug_flag)
DEBUG("Unrecoverable error parsing HTTP request, closing connection");
_DEBUG("Unrecoverable error parsing HTTP request, closing connection");
http_request_finalise(r);
RETURNVOID;
}
@ -1644,7 +1635,7 @@ static void http_request_send_response(struct http_request *r)
uint64_t remaining = CONTENT_LENGTH_UNKNOWN;
size_t unsent = r->response_buffer_length - r->response_buffer_sent;
if (r->debug_flag && *r->debug_flag)
DEBUGF("HTTP response buffer contains %zu bytes unsent", unsent);
_DEBUGF("HTTP response buffer contains %zu bytes unsent", unsent);
if (r->response_length != CONTENT_LENGTH_UNKNOWN) {
remaining = r->response_length - r->response_sent;
assert(unsent <= remaining);
@ -1707,7 +1698,7 @@ static void http_request_send_response(struct http_request *r)
RETURNVOID;
}
if (r->debug_flag && *r->debug_flag)
DEBUGF("Generated HTTP %zu bytes of content, need %zu bytes of buffer (ret=%d)", result.generated, result.need, ret);
_DEBUGF("Generated HTTP %zu bytes of content, need %zu bytes of buffer (ret=%d)", result.generated, result.need, ret);
if (r->phase != PAUSE && ret == 0)
r->response.content_generator = NULL; // ensure we never invoke again
continue;
@ -1729,13 +1720,13 @@ static void http_request_send_response(struct http_request *r)
ssize_t written = write_nonblock(r->alarm.poll.fd, r->response_buffer + r->response_buffer_sent, unsent);
if (written == -1) {
if (r->debug_flag && *r->debug_flag)
DEBUG("HTTP socket write error, closing connection");
_DEBUG("HTTP socket write error, closing connection");
http_request_finalise(r);
RETURNVOID;
}
if (sigPipeFlag) {
if (r->debug_flag && *r->debug_flag)
DEBUG("Received SIGPIPE on HTTP socket write, closing connection");
_DEBUG("Received SIGPIPE on HTTP socket write, closing connection");
http_request_finalise(r);
RETURNVOID;
}
@ -1745,9 +1736,9 @@ static void http_request_send_response(struct http_request *r)
r->response_sent += (size_t) written;
assert(r->response_sent <= r->response_length);
if (r->debug_flag && *r->debug_flag) {
DEBUGF("Wrote %zu bytes to HTTP socket, total %"PRIhttp_size_t", remaining=%"PRIhttp_size_t,
_DEBUGF("Wrote %zu bytes to HTTP socket, total %"PRIhttp_size_t", remaining=%"PRIhttp_size_t,
(size_t) written, r->response_sent, r->response_length - r->response_sent);
DEBUGF("%s", alloca_toprint(-1, r->response_buffer + r->response_buffer_sent, unsent));
_DEBUGF("%s", alloca_toprint(-1, r->response_buffer + r->response_buffer_sent, unsent));
}
r->response_buffer_sent += (size_t) written;
assert(r->response_buffer_sent <= r->response_buffer_length);
@ -1759,7 +1750,7 @@ static void http_request_send_response(struct http_request *r)
RETURNVOID;
}
if (r->debug_flag && *r->debug_flag)
DEBUG("Done, closing connection");
_DEBUG("Done, closing connection");
http_request_finalise(r);
OUT();
}
@ -1782,7 +1773,7 @@ static void _http_request_start_transmitting(struct http_request *r)
void http_request_pause_response(struct http_request *r, time_ms_t until)
{
if (r->debug_flag && *r->debug_flag)
DEBUGF("Pausing response for %.3f sec", (double)(until - gettime_ms()) / 1000.0);
_DEBUGF("Pausing response for %.3f sec", (double)(until - gettime_ms()) / 1000.0);
assert(r->phase == TRANSMIT);
r->phase = PAUSE;
r->alarm.alarm = until;
@ -1800,7 +1791,7 @@ void http_request_resume_response(struct http_request *r)
{
if (r->phase == PAUSE) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Resuming paused response for %.3f sec early", (double)(r->alarm.alarm - gettime_ms()) / 1000.0);
_DEBUGF("Resuming paused response for %.3f sec early", (double)(r->alarm.alarm - gettime_ms()) / 1000.0);
_http_request_start_transmitting(r);
}
}
@ -1816,13 +1807,13 @@ static void http_server_poll(struct sched_ent *alarm)
http_request_resume_response(r);
} else {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Timeout, closing connection");
_DEBUGF("Timeout, closing connection");
http_request_finalise(r);
}
}
else if (alarm->poll.revents & (POLLHUP | POLLERR)) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("Poll error (%s), closing connection", alloca_poll_events(alarm->poll.revents));
_DEBUGF("Poll error (%s), closing connection", alloca_poll_events(alarm->poll.revents));
http_request_finalise(r);
}
else if (alarm->poll.revents & POLLIN) {
@ -2182,7 +2173,7 @@ static void http_request_start_response(struct http_request *r)
r->response_buffer_need = 0;
r->response_sent = 0;
if (r->debug_flag && *r->debug_flag)
DEBUGF("Sending HTTP response: %s", alloca_toprint(160, (const char *)r->response_buffer, r->response_buffer_length));
_DEBUGF("Sending HTTP response: %s", alloca_toprint(160, (const char *)r->response_buffer, r->response_buffer_length));
_http_request_start_transmitting(r);
OUT();
}
@ -2258,7 +2249,7 @@ int generate_http_content_from_strbuf_chunks(
while ((ret = chunker(r, b)) != -1) {
if (strbuf_overrun(b)) {
if (r->debug_flag && *r->debug_flag)
DEBUGF("overrun by %zu bytes", strbuf_count(b) - strbuf_len(b));
_DEBUGF("overrun by %zu bytes", strbuf_count(b) - strbuf_len(b));
result->need = strbuf_count(b) + 1 - result->generated;
break;
}

View File

@ -185,7 +185,7 @@ struct http_request {
// requests.
unsigned int uuid;
// These can be set up to point to config flags, to allow debug to be
// enabled indpendently for different instances HTTP server instances
// enabled independently for different instances HTTP server instances
// that use this code.
bool_t *debug_flag;
bool_t *disable_tx_flag;

37
httpd.c
View File

@ -157,8 +157,7 @@ int httpd_server_start(uint16_t port_low, uint16_t port_high)
if (now < httpd_server_last_start_attempt + 5000)
return 2;
httpd_server_last_start_attempt = now;
if (config.debug.httpd)
DEBUGF("Starting HTTP server");
DEBUGF(httpd, "Starting HTTP server");
uint16_t port;
for (port = port_low; port <= port_high; ++port) {
@ -241,8 +240,7 @@ unsigned int current_httpd_request_count = 0;
static void httpd_server_finalise_http_request(struct http_request *hr)
{
httpd_request *r = (httpd_request *) hr;
if (config.debug.httpd)
DEBUGF("current_httpd_request_count=%u current_httpd_requests=%p r=%p r->next=%p r->prev=%p", current_httpd_request_count, current_httpd_requests, r, r->next, r->prev);
DEBUGF(httpd, "current_httpd_request_count=%u current_httpd_requests=%p r=%p r->next=%p r->prev=%p", current_httpd_request_count, current_httpd_requests, r, r->next, r->prev);
if (r->next) {
assert(current_httpd_request_count >= 2);
assert(r->next->prev == r);
@ -430,10 +428,9 @@ int accumulate_text(httpd_request *r, const char *partname, char *textbuf, size_
if (len) {
size_t newlen = *textlenp + len;
if (newlen > textsiz) {
if (config.debug.httpd)
DEBUGF("Form part \"%s\" too long, %zu bytes overflows maximum %zu by %zu",
partname, newlen, textsiz, (size_t)(newlen - textsiz)
);
DEBUGF(httpd, "Form part \"%s\" too long, %zu bytes overflows maximum %zu by %zu",
partname, newlen, textsiz, (size_t)(newlen - textsiz)
);
strbuf msg = strbuf_alloca(100);
strbuf_sprintf(msg, "Overflow in \"%s\" form part", partname);
http_request_simple_response(&r->http, 403, strbuf_str(msg));
@ -460,10 +457,9 @@ int form_buf_malloc_accumulate(httpd_request *r, const char *partname, struct fo
return 0;
size_t newlen = f->length + len;
if (newlen > f->size_limit) {
if (config.debug.httpd)
DEBUGF("form part \"%s\" overflow, %zu bytes exceeds limit %zu by %zu",
partname, newlen, f->size_limit, (size_t)(newlen - f->size_limit)
);
DEBUGF(httpd, "form part \"%s\" overflow, %zu bytes exceeds limit %zu by %zu",
partname, newlen, f->size_limit, (size_t)(newlen - f->size_limit)
);
strbuf msg = strbuf_alloca(100);
strbuf_sprintf(msg, "Overflow in \"%s\" form part", partname);
http_request_simple_response(&r->http, 403, strbuf_str(msg));
@ -494,12 +490,11 @@ void form_buf_malloc_release(struct form_buf_malloc *f)
int http_response_content_type(httpd_request *r, const char *what, const struct mime_content_type *ct)
{
if (config.debug.httpd)
DEBUGF("%s Content-Type: %s/%s%s%s%s%s", what, ct->type, ct->subtype,
ct->charset[0] ? "; charset=" : "",
ct->charset,
ct->multipart_boundary[0] ? "; boundary=" : "",
ct->multipart_boundary
DEBUGF(httpd, "%s Content-Type: %s/%s%s%s%s%s", what, ct->type, ct->subtype,
ct->charset[0] ? "; charset=" : "",
ct->charset,
ct->multipart_boundary[0] ? "; boundary=" : "",
ct->multipart_boundary
);
strbuf msg = strbuf_alloca(200);
strbuf_sprintf(msg, "%s Content-Type:", what);
@ -517,8 +512,7 @@ int http_response_content_type(httpd_request *r, const char *what, const struct
int http_response_content_disposition(httpd_request *r, const char *what, const char *type)
{
if (config.debug.httpd)
DEBUGF("%s Content-Disposition: %s %s", what, type);
DEBUGF(httpd, "%s Content-Disposition: %s %s", what, type);
strbuf msg = strbuf_alloca(100);
strbuf_sprintf(msg, "%s Content-Disposition: %s", what, type);
http_request_simple_response(&r->http, 403, strbuf_str(msg));
@ -527,8 +521,7 @@ int http_response_content_disposition(httpd_request *r, const char *what, const
int http_response_form_part(httpd_request *r, const char *what, const char *partname, const char *text, size_t textlen)
{
if (config.debug.httpd)
DEBUGF("%s \"%s\" form part %s", what, partname, text ? alloca_toprint(-1, text, textlen) : "");
DEBUGF(httpd, "%s \"%s\" form part %s", what, partname, text ? alloca_toprint(-1, text, textlen) : "");
strbuf msg = strbuf_alloca(100);
strbuf_sprintf(msg, "%s \"%s\" form part", what, partname);
http_request_simple_response(&r->http, 403, strbuf_str(msg));

122
keyring.c
View File

@ -47,14 +47,12 @@ static int keyring_identity_mac(const keyring_identity *id, unsigned char *pkrsa
static int _keyring_open(keyring_file *k, const char *path, const char *mode)
{
if (config.debug.keyring)
DEBUGF("opening %s in \"%s\" mode", alloca_str_toprint(path), mode);
DEBUGF(keyring, "opening %s in \"%s\" mode", alloca_str_toprint(path), mode);
k->file = fopen(path, mode);
if (!k->file) {
if (errno != EPERM && errno != ENOENT)
return WHYF_perror("fopen(%s, \"%s\")", alloca_str_toprint(path), mode);
if (config.debug.keyring)
DEBUGF("cannot open %s in \"%s\" mode", alloca_str_toprint(path), mode);
DEBUGF(keyring, "cannot open %s in \"%s\" mode", alloca_str_toprint(path), mode);
}
return 0;
}
@ -366,8 +364,7 @@ static int keyring_munge_block(
unsigned char *KeyRingSalt, int KeyRingSaltLen,
const char *KeyRingPin, const char *PKRPin)
{
if (config.debug.keyring)
DEBUGF("KeyRingPin=%s PKRPin=%s", alloca_str_toprint(KeyRingPin), alloca_str_toprint(PKRPin));
DEBUGF(keyring, "KeyRingPin=%s PKRPin=%s", alloca_str_toprint(KeyRingPin), alloca_str_toprint(PKRPin));
int exit_code=1;
unsigned char hashKey[crypto_hash_sha512_BYTES];
unsigned char hashNonce[crypto_hash_sha512_BYTES];
@ -899,8 +896,7 @@ static int keyring_pack_identity(const keyring_identity *id, unsigned char packe
if (packer == NULL) {
WARNF("no packer function for key type 0x%02x(%s), omitted from keyring file", ktype, kts);
} else {
if (config.debug.keyring)
DEBUGF("pack key type = 0x%02x(%s)", ktype, kts);
DEBUGF(keyring, "pack key type = 0x%02x(%s)", ktype, kts);
// First byte is the key type code.
rotbuf_putc(&rbuf, ktype);
// The next two bytes are the key pair length, for forward compatibility: so older software can
@ -1058,8 +1054,7 @@ static keyring_identity *keyring_unpack_identity(unsigned char *slot, const char
break;
}
if (keypair_len > rotbuf_remain(&rbuf)) {
if (config.debug.keyring)
DEBUGF("invalid keypair length %zu", keypair_len);
DEBUGF(keyring, "invalid keypair length %zu", keypair_len);
keyring_free_identity(id);
return NULL;
}
@ -1072,12 +1067,10 @@ static keyring_identity *keyring_unpack_identity(unsigned char *slot, const char
}
struct rotbuf rbstart = rbuf;
if (ktype < NELS(keytypes) && kt->unpacker) {
if (config.debug.keyring)
DEBUGF("unpack key type = 0x%02x(%s) at offset %u", ktype, keytype_str(ktype, "unknown"), (int)rotbuf_position(&rbo));
DEBUGF(keyring, "unpack key type = 0x%02x(%s) at offset %u", ktype, keytype_str(ktype, "unknown"), (int)rotbuf_position(&rbo));
if (kt->unpacker(kp, &rbuf, keypair_len) != 0) {
// If there is an error, it is probably an empty slot.
if (config.debug.keyring)
DEBUGF("key type 0x%02x does not unpack", ktype);
DEBUGF(keyring, "key type 0x%02x does not unpack", ktype);
keyring_free_keypair(kp);
keyring_free_identity(id);
return NULL;
@ -1087,15 +1080,13 @@ static keyring_identity *keyring_unpack_identity(unsigned char *slot, const char
if (unpacked != keypair_len) {
// If the number of bytes unpacked does not match the keypair length, it is probably an
// empty slot.
if (config.debug.keyring)
DEBUGF("key type 0x%02x unpacked wrong length (unpacked %u, expecting %u)", ktype, (int)unpacked, (int)keypair_len);
DEBUGF(keyring, "key type 0x%02x unpacked wrong length (unpacked %u, expecting %u)", ktype, (int)unpacked, (int)keypair_len);
keyring_free_keypair(kp);
keyring_free_identity(id);
return NULL;
}
} else {
if (config.debug.keyring)
DEBUGF("unsupported key type 0x%02x at offset %u, reading %u bytes as private key", ktype, (unsigned)rotbuf_position(&rbo), (unsigned)kp->private_key_len);
DEBUGF(keyring, "unsupported key type 0x%02x at offset %u, reading %u bytes as private key", ktype, (unsigned)rotbuf_position(&rbo), (unsigned)kp->private_key_len);
assert(kp->public_key_len == 0);
assert(kp->public_key == NULL);
rotbuf_getbuf(&rbuf, kp->private_key, kp->private_key_len);
@ -1107,13 +1098,11 @@ static keyring_identity *keyring_unpack_identity(unsigned char *slot, const char
}
// If the buffer offset overshot, we got an invalid keypair code and length combination.
if (rbuf.wrap > 1) {
if (config.debug.keyring)
DEBUGF("slot overrun by %u bytes", rbuf.wrap - 1);
DEBUGF(keyring, "slot overrun by %u bytes", rbuf.wrap - 1);
keyring_free_identity(id);
return NULL;
}
if (config.debug.keyring)
DEBUGF("unpacked key pairs");
DEBUGF(keyring, "unpacked key pairs");
return id;
}
@ -1151,8 +1140,7 @@ static int keyring_identity_mac(const keyring_identity *id, unsigned char *pkrsa
*/
static int keyring_decrypt_pkr(keyring_file *k, const char *pin, int slot_number)
{
if (config.debug.keyring)
DEBUGF("k=%p, pin=%s slot_number=%d", k, alloca_str_toprint(pin), slot_number);
DEBUGF(keyring, "k=%p, pin=%s slot_number=%d", k, alloca_str_toprint(pin), slot_number);
unsigned char slot[KEYRING_PAGE_SIZE];
keyring_identity *id=NULL;
@ -1167,8 +1155,7 @@ static int keyring_decrypt_pkr(keyring_file *k, const char *pin, int slot_number
goto kdp_safeexit;
}
/* 3. Unpack contents of slot into a new identity in the provided context. */
if (config.debug.keyring)
DEBUGF("unpack slot %u", slot_number);
DEBUGF(keyring, "unpack slot %u", slot_number);
if (((id = keyring_unpack_identity(slot, pin)) == NULL) || !id->keypairs)
goto kdp_safeexit; // Not a valid slot
id->slot = slot_number;
@ -1210,8 +1197,7 @@ static int keyring_decrypt_pkr(keyring_file *k, const char *pin, int slot_number
int keyring_enter_pin(keyring_file *k, const char *pin)
{
IN();
if (config.debug.keyring)
DEBUGF("k=%p, pin=%s", k, alloca_str_toprint(pin));
DEBUGF(keyring, "k=%p, pin=%s", k, alloca_str_toprint(pin));
if (!k) RETURN(-1);
if (!pin) pin="";
@ -1312,8 +1298,7 @@ static int keyring_commit_identity(keyring_file *k, keyring_identity *id)
*/
keyring_identity *keyring_create_identity(keyring_file *k, const char *pin)
{
if (config.debug.keyring)
DEBUGF("k=%p", k);
DEBUGF(keyring, "k=%p", k);
/* Check obvious abort conditions early */
if (!k) { WHY("keyring is NULL"); return NULL; }
if (!k->bam) { WHY("keyring lacks BAM (not to be confused with KAPOW)"); return NULL; }
@ -1362,8 +1347,7 @@ keyring_identity *keyring_create_identity(keyring_file *k, const char *pin)
int keyring_commit(keyring_file *k)
{
if (config.debug.keyring)
DEBUGF("k=%p", k);
DEBUGF(keyring, "k=%p", k);
if (!k)
return WHY("keyring was NULL");
unsigned errorCount = 0;
@ -1404,8 +1388,7 @@ int keyring_commit(keyring_file *k)
/* Store */
off_t file_offset = KEYRING_PAGE_SIZE * it.identity->slot;
if (file_offset == 0) {
if (config.debug.keyring)
DEBUGF("ID id=%p has slot=0", it.identity);
DEBUGF(keyring, "ID id=%p has slot=0", it.identity);
} else if (fseeko(k->file, file_offset, SEEK_SET) == -1) {
WHYF_perror("fseeko(%d, %ld, SEEK_SET)", fileno(k->file), (long)file_offset);
errorCount++;
@ -1433,8 +1416,7 @@ int keyring_set_did(keyring_identity *id, const char *did, const char *name)
keypair *kp = id->keypairs;
while(kp){
if (kp->type==KEYTYPE_DID){
if (config.debug.keyring)
DEBUG("Identity already contains DID");
DEBUG(keyring, "Identity already contains DID");
break;
}
kp=kp->next;
@ -1445,8 +1427,7 @@ int keyring_set_did(keyring_identity *id, const char *did, const char *name)
if ((kp = keyring_alloc_keypair(KEYTYPE_DID, 0)) == NULL)
return -1;
keyring_identity_add_keypair(id, kp);
if (config.debug.keyring)
DEBUG("Created DID record for identity");
DEBUG(keyring, "Created DID record for identity");
}
/* Store DID unpacked for ease of searching */
@ -1461,9 +1442,9 @@ int keyring_set_did(keyring_identity *id, const char *did, const char *name)
bcopy(name,&kp->public_key[0],len);
bzero(&kp->public_key[len],64-len);
if (config.debug.keyring){
dump("storing did",&kp->private_key[0],32);
dump("storing name",&kp->public_key[0],64);
if (IF_DEBUG(keyring)) {
dump("{keyring} storing did",&kp->private_key[0],32);
dump("{keyring} storing name",&kp->public_key[0],64);
}
return 0;
}
@ -1508,8 +1489,7 @@ int keyring_set_public_tag(keyring_identity *id, const char *name, const unsigne
keyring_unpack_tag(kp->public_key, kp->public_key_len,
&tag_name, &tag_value, &tag_length)==0 &&
strcmp(tag_name, name)==0) {
if (config.debug.keyring)
DEBUG("Found existing public tag");
DEBUG(keyring, "Found existing public tag");
break;
}
kp = kp->next;
@ -1517,8 +1497,7 @@ int keyring_set_public_tag(keyring_identity *id, const char *name, const unsigne
/* allocate if needed */
if (!kp){
if (config.debug.keyring)
DEBUGF("Creating new public tag");
DEBUGF(keyring, "Creating new public tag");
if ((kp = keyring_alloc_keypair(KEYTYPE_PUBLIC_TAG, 0)) == NULL)
return -1;
keyring_identity_add_keypair(id, kp);
@ -1535,8 +1514,8 @@ int keyring_set_public_tag(keyring_identity *id, const char *name, const unsigne
if (keyring_pack_tag(kp->public_key, &kp->public_key_len, name, value, length))
return -1;
if (config.debug.keyring)
dump("New tag", kp->public_key, kp->public_key_len);
if (IF_DEBUG(keyring))
dump("{keyring} New tag", kp->public_key, kp->public_key_len);
return 0;
}
@ -1587,8 +1566,7 @@ struct keypair *keyring_find_sas_private(keyring_file *k, keyring_identity *iden
kp->verified=1;
}
if (config.debug.keyring)
DEBUGF("Found SAS entry");
DEBUGF(keyring, "Found SAS entry");
RETURN(kp);
OUT();
@ -1597,14 +1575,12 @@ struct keypair *keyring_find_sas_private(keyring_file *k, keyring_identity *iden
static int keyring_store_sas(struct internal_mdp_header *header, struct overlay_buffer *payload)
{
if (header->source->sas_valid){
if (config.debug.keyring)
DEBUGF("Ignoring SID:SAS mapping for %s, already have one", alloca_tohex_sid_t(header->source->sid));
DEBUGF(keyring, "Ignoring SID:SAS mapping for %s, already have one", alloca_tohex_sid_t(header->source->sid));
return 0;
}
size_t len = ob_remaining(payload);
if (config.debug.keyring)
DEBUGF("Received SID:SAS mapping, %zd bytes", len);
DEBUGF(keyring, "Received SID:SAS mapping, %zd bytes", len);
#define SIG_BYTES crypto_sign_edwards25519sha512batch_BYTES
@ -1640,11 +1616,10 @@ static int keyring_store_sas(struct internal_mdp_header *header, struct overlay_
header->source->sas_valid=1;
header->source->sas_last_request=-1;
if (config.debug.keyring)
DEBUGF("Stored SID:SAS mapping, SID=%s to SAS=%s",
alloca_tohex_sid_t(header->source->sid),
alloca_tohex_sas(header->source->sas_public)
);
DEBUGF(keyring, "Stored SID:SAS mapping, SID=%s to SAS=%s",
alloca_tohex_sid_t(header->source->sid),
alloca_tohex_sas(header->source->sas_public)
);
return 0;
}
@ -1687,12 +1662,11 @@ static int keyring_respond_sas(keyring_file *k, struct internal_mdp_header *head
slen-=SID_SIZE;
ob_append_space(response_payload, slen);
if (config.debug.keyring)
DEBUGF("Sending SID:SAS mapping, %zd bytes, %s:%"PRImdp_port_t" -> %s:%"PRImdp_port_t,
ob_position(response_payload),
alloca_tohex_sid_t(header->destination->sid), header->destination_port,
alloca_tohex_sid_t(header->source->sid), header->source_port
);
DEBUGF(keyring, "Sending SID:SAS mapping, %zd bytes, %s:%"PRImdp_port_t" -> %s:%"PRImdp_port_t,
ob_position(response_payload),
alloca_tohex_sid_t(header->destination->sid), header->destination_port,
alloca_tohex_sid_t(header->source->sid), header->source_port
);
ob_flip(response_payload);
int ret = overlay_send_frame(&response, response_payload);
@ -1729,8 +1703,7 @@ int keyring_send_unlock(struct subscriber *subscriber)
ob_append_space(response, len - ob_position(response));
if (config.debug.keyring)
DEBUGF("Sending Unlock request for sid %s", alloca_tohex_sid_t(subscriber->sid));
DEBUGF(keyring, "Sending Unlock request for sid %s", alloca_tohex_sid_t(subscriber->sid));
ob_flip(response);
int ret = overlay_send_frame(&header, response);
ob_free(response);
@ -1758,8 +1731,7 @@ static int keyring_send_challenge(struct subscriber *source, struct subscriber *
ob_append_byte(payload, UNLOCK_CHALLENGE);
ob_append_bytes(payload, source->identity->challenge, sizeof source->identity->challenge);
if (config.debug.keyring)
DEBUGF("Sending Unlock challenge for sid %s", alloca_tohex_sid_t(source->sid));
DEBUGF(keyring, "Sending Unlock challenge for sid %s", alloca_tohex_sid_t(source->sid));
ob_flip(payload);
int ret = overlay_send_frame(&header, payload);
@ -1793,8 +1765,7 @@ static int keyring_respond_challenge(struct subscriber *subscriber, struct overl
return -1;
ob_append_space(response, len - ob_position(response));
if (config.debug.keyring)
DEBUGF("Responding to Unlock challenge for sid %s", alloca_tohex_sid_t(subscriber->sid));
DEBUGF(keyring, "Responding to Unlock challenge for sid %s", alloca_tohex_sid_t(subscriber->sid));
ob_flip(response);
int ret = overlay_send_frame(&header, response);
ob_free(response);
@ -1856,16 +1827,14 @@ int keyring_send_sas_request(struct subscriber *subscriber){
time_ms_t now = gettime_ms();
if (now < subscriber->sas_last_request + 100){
if (config.debug.keyring)
INFO("Too soon to ask for SAS mapping again");
DEBUG(keyring, "Too soon to ask for SAS mapping again");
return 0;
}
if (!my_subscriber)
return WHY("couldn't request SAS (I don't know who I am)");
if (config.debug.keyring)
DEBUGF("Requesting SAS mapping for SID=%s", alloca_tohex_sid_t(subscriber->sid));
DEBUGF(keyring, "Requesting SAS mapping for SID=%s", alloca_tohex_sid_t(subscriber->sid));
/* request mapping (send request auth-crypted). */
struct internal_mdp_header header;
@ -1880,8 +1849,7 @@ int keyring_send_sas_request(struct subscriber *subscriber){
struct overlay_buffer *payload = ob_new();
ob_append_byte(payload, KEYTYPE_CRYPTOSIGN);
if (config.debug.keyring)
DEBUGF("Sending SAS resolution request");
DEBUGF(keyring, "Sending SAS resolution request");
subscriber->sas_last_request=now;
ob_flip(payload);
int ret = overlay_send_frame(&header, payload);
@ -2164,7 +2132,7 @@ int keyring_load_from_dump(keyring_file *k, unsigned entry_pinc, const char **en
const char *ktypestr = &line[i];
line[j] = '\0';
const char *content = &line[j + 1];
//DEBUGF("n=%d i=%u ktypestr=%s j=%u content=%s", n, i, alloca_str_toprint(ktypestr), j, alloca_str_toprint(content));
//DEBUGF(keyring, "n=%d i=%u ktypestr=%s j=%u content=%s", n, i, alloca_str_toprint(ktypestr), j, alloca_str_toprint(content));
keypair *kp = keyring_alloc_keypair(ktype, 0);
if (kp == NULL)
return -1;

View File

@ -32,8 +32,7 @@ DEFINE_CMD(app_keyring_create, 0,
"keyring","create");
static int app_keyring_create(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
keyring_file *k = keyring_create_instance();
if (!k)
return -1;
@ -46,8 +45,7 @@ DEFINE_CMD(app_keyring_dump, 0,
"keyring","dump" KEYRING_PIN_OPTIONS,"[--secret]","[<file>]");
static int app_keyring_dump(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
const char *path;
if (cli_arg(parsed, "file", &path, cli_path_regular, NULL) == -1)
return -1;
@ -76,8 +74,7 @@ DEFINE_CMD(app_keyring_load, 0,
"keyring","load" KEYRING_PIN_OPTIONS,"<file>","[<entry-pin>]...");
static int app_keyring_load(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
const char *path;
if (cli_arg(parsed, "file", &path, cli_path_regular, NULL) == -1)
return -1;
@ -119,8 +116,7 @@ DEFINE_CMD(app_keyring_list, 0,
"keyring","list" KEYRING_PIN_OPTIONS);
static int app_keyring_list(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
keyring_file *k = keyring_open_instance_cli(parsed);
if (!k)
return -1;
@ -233,8 +229,7 @@ DEFINE_CMD(app_keyring_add, 0,
"keyring","add" KEYRING_PIN_OPTIONS,"[<pin>]");
static int app_keyring_add(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
const char *pin;
cli_arg(parsed, "pin", &pin, NULL, "");
keyring_file *k = keyring_open_instance_cli(parsed);
@ -269,8 +264,7 @@ DEFINE_CMD(app_keyring_set_did, 0,
"keyring", "set","did" KEYRING_PIN_OPTIONS,"<sid>","<did>","<name>");
static int app_keyring_set_did(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
const char *sidhex, *did, *name;
if (cli_arg(parsed, "sid", &sidhex, str_is_subscriber_id, "") == -1 ||

28
log.h
View File

@ -79,6 +79,8 @@ __SERVAL_LOG_INLINE void logMessage(int level, struct __sourceloc whence, const
#define NOWHENCE(LOGSTMT) do { const struct __sourceloc __whence = __NOWHENCE__; LOGSTMT; } while (0)
#define BACKTRACE logBacktrace(LOG_LEVEL_FATAL, __WHENCE__)
#define FATALF(F,...) do { LOGF(LOG_LEVEL_FATAL, F, ##__VA_ARGS__); abort(); exit(-1); } while (1)
#define FATAL(X) FATALF("%s", (X))
#define FATALF_perror(F,...) FATALF(F ": %s [errno=%d]", ##__VA_ARGS__, strerror(errno), errno)
@ -104,17 +106,27 @@ __SERVAL_LOG_INLINE void logMessage(int level, struct __sourceloc whence, const
#define INFOF(F,...) LOGF(LOG_LEVEL_INFO, F, ##__VA_ARGS__)
#define INFO(X) INFOF("%s", (X))
#define DEBUGF(F,...) LOGF(LOG_LEVEL_DEBUG, F, ##__VA_ARGS__)
#define DEBUG(X) DEBUGF("%s", (X))
#define DEBUGF_perror(F,...) LOGF_perror(LOG_LEVEL_DEBUG, F, ##__VA_ARGS__)
#define DEBUG_perror(X) DEBUGF_perror("%s", (X))
#define D (DEBUG("D"), 1)
#define T (config.debug.trace ? DEBUG("T") : 1)
#define DEBUG_argv(X,ARGC,ARGV) logArgv(LOG_LEVEL_DEBUG, __WHENCE__, (X), (ARGC), (ARGV))
#define _DEBUGF(F,...) LOGF(LOG_LEVEL_DEBUG, F, ##__VA_ARGS__)
#define _DEBUG(X) _DEBUGF("%s", (X))
#define _DEBUGF_perror(F,...) LOGF_perror(LOG_LEVEL_DEBUG, F, ##__VA_ARGS__)
#define _DEBUG_perror(X) _DEBUGF_perror("%s", (X))
#define _DEBUG_argv(X,ARGC,ARGV) logArgv(LOG_LEVEL_DEBUG, __WHENCE__, (X), (ARGC), (ARGV))
#define _DEBUGF_TAG(TAG,F,...) _DEBUGF("{%s} " F, (TAG), ##__VA_ARGS__)
#define _DEBUGF_TAG_perror(TAG,F,...) _DEBUGF_perror("{%s} " F, (TAG), ##__VA_ARGS__)
#define _DEBUGF_TAG_argv(TAG,X,ARGC,ARGV) _DEBUGF_argv("{" TAG "} " X, (ARGC), (ARGV))
#define DEBUGF(FLAG,F,...) do { if (IF_DEBUG(FLAG)) _DEBUGF_TAG(#FLAG, F, ##__VA_ARGS__); } while (0)
#define DEBUGF2(FLAG1,FLAG2,F,...) do { if (IF_DEBUG(FLAG1) || IF_DEBUG(FLAG2)) _DEBUGF_TAG((IF_DEBUG(FLAG1) ? #FLAG1 : #FLAG2), F, ##__VA_ARGS__); } while (0)
#define DEBUG(FLAG,X) DEBUGF(FLAG, "%s", (X))
#define DEBUGF_perror(FLAG,F,...) do { if (IF_DEBUG(FLAG)) _DEBUGF_TAG_perror(#FLAG, F, ##__VA_ARGS__); } while (0)
#define DEBUG_perror(FLAG,X) DEBUGF_perror(FLAG, "%s", (X))
#define DEBUG_argv(FLAG,X,ARGC,ARGV) do { if (IF_DEBUG(FLAG)) _DEBUG_TAG_argv(#FLAG, X, (ARGC), (ARGV)); } while (0)
#define dump(X,A,N) logDump(LOG_LEVEL_DEBUG, __WHENCE__, (X), (const unsigned char *)(A), (size_t)(N))
#define BACKTRACE logBacktrace(LOG_LEVEL_FATAL, __WHENCE__)
#define D (DEBUG("D"), 1)
#define T (IF_DEBUG(trace) ? (DEBUG("T"), 1) : 1)
// Utility functions, defined in terms of above primitives.
void logArgv(int level, struct __sourceloc whence, const char *label, int argc, const char *const *argv);

16
lsif.c
View File

@ -80,7 +80,7 @@
*/
int scrapeProcNetRoute()
{
if (config.debug.overlayinterfaces) DEBUG("called");
DEBUG(overlayinterfaces, "called");
FILE *f=fopen("/proc/net/route","r");
if (!f)
@ -146,7 +146,7 @@ lsif(void) {
bzero(&addr, sizeof(addr));
bzero(&broadcast, sizeof(broadcast));
if (config.debug.overlayinterfaces) DEBUG("called");
DEBUG(overlayinterfaces, "called");
/* Get a socket handle. */
sck = socket(PF_INET, SOCK_DGRAM, 0);
@ -176,7 +176,7 @@ lsif(void) {
/* We're only interested in IPv4 addresses */
if (ifr->ifr_ifru.ifru_addr.sa_family != AF_INET) {
if (config.debug.overlayinterfaces) DEBUGF("Skipping non-AF_INET address on %s", ifr->ifr_name);
DEBUGF(overlayinterfaces, "Skipping non-AF_INET address on %s", ifr->ifr_name);
continue;
}
@ -189,7 +189,7 @@ lsif(void) {
/* Not broadcast? Not interested.. */
if ((ifr->ifr_ifru.ifru_flags & IFF_BROADCAST) == 0) {
if (config.debug.overlayinterfaces) DEBUGF("Skipping non-broadcast address on %s", ifr->ifr_name);
DEBUGF(overlayinterfaces, "Skipping non-broadcast address on %s", ifr->ifr_name);
continue;
}
@ -211,7 +211,7 @@ lsif(void) {
nInterfaces++;
}
if (config.debug.overlayinterfaces) DEBUGF("Examined %u interface addresses", nInterfaces);
DEBUGF(overlayinterfaces, "Examined %u interface addresses", nInterfaces);
close(sck);
return 0;
@ -229,7 +229,7 @@ doifaddrs(void) {
bzero(&addr, sizeof(addr));
bzero(&broadcast, sizeof(broadcast));
if (config.debug.overlayinterfaces) DEBUGF("called");
DEBUGF(overlayinterfaces, "called");
if (getifaddrs(&ifaddr) == -1)
return WHY_perror("getifaddr()");
@ -243,13 +243,13 @@ doifaddrs(void) {
/* We're only interested in IPv4 addresses */
if (ifa->ifa_addr->sa_family != AF_INET) {
if (config.debug.overlayinterfaces) DEBUGF("Skipping non-AF_INET address on %s", ifa->ifa_name);
DEBUGF(overlayinterfaces, "Skipping non-AF_INET address on %s", ifa->ifa_name);
continue;
}
/* Not broadcast? Not interested.. */
if ((ifa->ifa_flags & IFF_BROADCAST) == 0) {
if (config.debug.overlayinterfaces) DEBUGF("Skipping non-broadcast address on %s", ifa->ifa_name);
DEBUGF(overlayinterfaces, "Skipping non-broadcast address on %s", ifa->ifa_name);
continue;
}

View File

@ -395,12 +395,12 @@ int overlay_mdp_getmyaddr(int mdp_sockfd, unsigned index, sid_t *sidp)
int result=overlay_mdp_send(mdp_sockfd,&a,MDP_AWAITREPLY,5000);
if (result) {
if (a.packetTypeAndFlags == MDP_ERROR)
DEBUGF("MDP Server error #%d: '%s'", a.error.error, a.error.message);
WARNF("MDP Server error #%d: '%s'", a.error.error, a.error.message);
return WHY("Failed to get local address list");
}
if ((a.packetTypeAndFlags&MDP_TYPE_MASK)!=MDP_ADDRLIST)
return WHY("MDP Server returned something other than an address list");
if (0) DEBUGF("local addr 0 = %s",alloca_tohex_sid_t(a.addrlist.sids[0]));
if (0) WARNF("local addr 0 = %s",alloca_tohex_sid_t(a.addrlist.sids[0]));
*sidp = a.addrlist.sids[0];
return 0;
}

View File

@ -104,13 +104,13 @@ int allow_inbound_packet(const struct internal_mdp_header *header)
)
|| (rule->flags & (RULE_INBOUND | RULE_OUTBOUND)) == 0
) {
if ((rule->flags & RULE_DROP) && config.debug.mdp_filter)
DEBUGF("DROP inbound packet source=%s:%"PRImdp_port_t" destination=%s:%"PRImdp_port_t,
header->source ? alloca_tohex_sid_t(header->source->sid) : "null",
header->source_port,
header->destination ? alloca_tohex_sid_t(header->destination->sid) : "null",
header->destination_port
);
if (rule->flags & RULE_DROP)
DEBUGF(mdp_filter, "DROP inbound packet source=%s:%"PRImdp_port_t" destination=%s:%"PRImdp_port_t,
header->source ? alloca_tohex_sid_t(header->source->sid) : "null",
header->source_port,
header->destination ? alloca_tohex_sid_t(header->destination->sid) : "null",
header->destination_port
);
return rule->flags & RULE_DROP ? 0 : 1;
}
return 1; // allow by default
@ -128,13 +128,13 @@ int allow_outbound_packet(const struct internal_mdp_header *header)
)
|| (rule->flags & (RULE_INBOUND | RULE_OUTBOUND)) == 0
) {
if ((rule->flags & RULE_DROP) && config.debug.mdp_filter)
DEBUGF("DROP outbound packet source=%s:%"PRImdp_port_t" destination=%s:%"PRImdp_port_t,
header->source ? alloca_tohex_sid_t(header->source->sid) : "null",
header->source_port,
header->destination ? alloca_tohex_sid_t(header->destination->sid) : "null",
header->destination_port
);
if (rule->flags & RULE_DROP)
DEBUGF(mdp_filter, "DROP outbound packet source=%s:%"PRImdp_port_t" destination=%s:%"PRImdp_port_t,
header->source ? alloca_tohex_sid_t(header->source->sid) : "null",
header->source_port,
header->destination ? alloca_tohex_sid_t(header->destination->sid) : "null",
header->destination_port
);
return rule->flags & RULE_DROP ? 0 : 1;
}
return 1; // allow by default
@ -208,8 +208,7 @@ static inline size_t available(ConstCursor c)
static inline size_t _preload(struct __sourceloc __whence, Cursor c, size_t n)
{
#ifdef DEBUG_MDP_FILTER_PARSING
if (config.debug.mdp_filter)
DEBUGF("preload(cursor=%s, n=%zu)", alloca_cursor_state(c), n);
DEBUGF(mdp_filter, "preload(cursor=%s, n=%zu)", alloca_cursor_state(c), n);
#endif
assert(c->current >= c->buffer);
assert(c->current <= c->end);
@ -276,8 +275,7 @@ static inline const char *preloaded(ConstCursor c)
static inline char _skip(struct __sourceloc __whence, Cursor c, const char *text)
{
#ifdef DEBUG_MDP_FILTER_PARSING
if (config.debug.mdp_filter)
DEBUGF("skip(cursor=%s, text=%s)", alloca_cursor_state(c), alloca_str_toprint(text));
DEBUGF(mdp_filter, "skip(cursor=%s, text=%s)", alloca_cursor_state(c), alloca_str_toprint(text));
#endif
size_t textlen = strlen(text);
preload(c, textlen);
@ -290,8 +288,7 @@ static inline char _skip(struct __sourceloc __whence, Cursor c, const char *text
static inline void _next(struct __sourceloc UNUSED(__whence), Cursor c)
{
#ifdef DEBUG_MDP_FILTER_PARSING
if (config.debug.mdp_filter)
DEBUGF("next(cursor=%s)", alloca_cursor_state(c));
DEBUGF(mdp_filter, "next(cursor=%s)", alloca_cursor_state(c));
#endif
assert(c->current >= c->buffer);
assert(c->current < c->end);
@ -302,8 +299,7 @@ static inline void _next(struct __sourceloc UNUSED(__whence), Cursor c)
static inline void _advance_to(struct __sourceloc UNUSED(__whence), Cursor c, const char *pos)
{
#ifdef DEBUG_MDP_FILTER_PARSING
if (config.debug.mdp_filter)
DEBUGF("advance_to(cursor=%s, pos=%d)", alloca_cursor_state(c), (int)(pos - c->buffer));
DEBUGF(mdp_filter, "advance_to(cursor=%s, pos=%d)", alloca_cursor_state(c), (int)(pos - c->buffer));
#endif
assert(pos >= c->current);
assert(pos <= c->end);
@ -314,8 +310,7 @@ static inline void _advance_to(struct __sourceloc UNUSED(__whence), Cursor c, co
static inline Pin _pin(struct __sourceloc UNUSED(__whence), Cursor c)
{
#ifdef DEBUG_MDP_FILTER_PARSING
if (config.debug.mdp_filter)
DEBUGF("pin(cursor=%s)", alloca_cursor_state(c));
DEBUGF(mdp_filter, "pin(cursor=%s)", alloca_cursor_state(c));
#endif
assert(c->current >= c->buffer);
assert(c->current < c->end);
@ -331,8 +326,7 @@ static inline Pin _pin(struct __sourceloc UNUSED(__whence), Cursor c)
static inline void _retreat(struct __sourceloc UNUSED(__whence), Cursor c, Pin p)
{
#ifdef DEBUG_MDP_FILTER_PARSING
if (config.debug.mdp_filter)
DEBUGF("retreat(cursor=%s, p=%zu)", alloca_cursor_state(c), p);
DEBUGF(mdp_filter, "retreat(cursor=%s, p=%zu)", alloca_cursor_state(c), p);
#endif
assert(c->current >= c->buffer);
assert(c->current <= c->end);
@ -351,8 +345,7 @@ static inline void _retreat(struct __sourceloc UNUSED(__whence), Cursor c, Pin p
static inline void _unpin(struct __sourceloc UNUSED(__whence), Cursor c, Pin p)
{
#ifdef DEBUG_MDP_FILTER_PARSING
if (config.debug.mdp_filter)
DEBUGF("unpin(cursor=%s, p=%zu)", alloca_cursor_state(c), p);
DEBUGF(mdp_filter, "unpin(cursor=%s, p=%zu)", alloca_cursor_state(c), p);
#endif
assert(c->current >= c->buffer);
assert(c->current <= c->end);
@ -586,8 +579,7 @@ static void clear_mdp_packet_rules()
{
free_rule_list(packet_rules);
packet_rules = NULL;
if (config.debug.mdp_filter)
DEBUG("cleared packet filter rules");
DEBUG(mdp_filter, "cleared packet filter rules");
}
/* Replace the current packet filter rules with the given new list of rules.
@ -598,11 +590,11 @@ static void set_mdp_packet_rules(struct packet_rule *rules)
{
clear_mdp_packet_rules();
packet_rules = rules;
if (config.debug.mdp_filter && packet_rules) {
DEBUG("set new packet filter rules:");
if (IF_DEBUG(mdp_filter) && packet_rules) {
DEBUG(mdp_filter, "set new packet filter rules:");
const struct packet_rule *rule;
for (rule = packet_rules; rule; rule = rule->next)
DEBUGF(" %s", alloca_packet_rule(rule));
DEBUGF(mdp_filter, " %s", alloca_packet_rule(rule));
}
}
@ -622,15 +614,12 @@ int reload_mdp_packet_rules()
char rules_path[1024];
if (!FORMF_SERVAL_ETC_PATH(rules_path, "%s", config.mdp.filter_rules_path))
return -1;
if (config.debug.mdp_filter)
DEBUGF(" file path=%s", alloca_str_toprint(rules_path));
DEBUGF(mdp_filter, " file path=%s", alloca_str_toprint(rules_path));
struct file_meta meta;
if (get_file_meta(rules_path, &meta) == -1)
return -1;
if (config.debug.mdp_filter) {
DEBUGF(" file meta=%s", alloca_file_meta(&meta));
DEBUGF("packet_rules_meta=%s", alloca_file_meta(&packet_rules_meta));
}
DEBUGF(mdp_filter, " file meta=%s", alloca_file_meta(&meta));
DEBUGF(mdp_filter, "packet_rules_meta=%s", alloca_file_meta(&packet_rules_meta));
if (cmp_file_meta(&meta, &packet_rules_meta) == 0)
return 0; // no change since last load
if (packet_rules_meta.mtime.tv_sec != -1 && serverMode)

View File

@ -41,10 +41,9 @@ ssize_t recvwithttl(int sock,unsigned char *buffer, size_t bufferlen,int *ttl, s
return WHYF_perror("recvmsg(%d,%p,0)", sock, &msg);
#if 0
if (config.debug.packetrx) {
DEBUGF("recvmsg returned %d (flags=%d, msg_controllen=%d)", (int) len, msg.msg_flags, (int)msg.msg_controllen);
DEBUGF(packetrx, "recvmsg returned %d (flags=%d, msg_controllen=%d)", (int) len, msg.msg_flags, (int)msg.msg_controllen);
if (IF_DEBUG(packetrx))
dump("received data", buffer, len);
}
#endif
if (len > 0) {
@ -54,17 +53,13 @@ ssize_t recvwithttl(int sock,unsigned char *buffer, size_t bufferlen,int *ttl, s
&& ((cmsg->cmsg_type == IP_RECVTTL) || (cmsg->cmsg_type == IP_TTL))
&& cmsg->cmsg_len
) {
if (config.debug.packetrx)
DEBUGF(" TTL (%p) data location resolves to %p", ttl,CMSG_DATA(cmsg));
DEBUGF(packetrx, " TTL (%p) data location resolves to %p", ttl,CMSG_DATA(cmsg));
if (CMSG_DATA(cmsg)) {
*ttl = *(unsigned char *) CMSG_DATA(cmsg);
if (config.debug.packetrx)
DEBUGF(" TTL of packet is %d", *ttl);
DEBUGF(packetrx, " TTL of packet is %d", *ttl);
}
} else {
if (config.debug.packetrx)
DEBUGF("I didn't expect to see level=%02x, type=%02x",
cmsg->cmsg_level,cmsg->cmsg_type);
DEBUGF(packetrx, "I didn't expect to see level=%02x, type=%02x", cmsg->cmsg_level,cmsg->cmsg_type);
}
}
}

6
mem.c
View File

@ -71,19 +71,19 @@ char *_str_edup(struct __sourceloc __whence, const char *str)
void *_serval_debug_malloc(unsigned int bytes, struct __sourceloc __whence)
{
void *r=malloc(bytes+SDM_GUARD_AFTER);
DEBUGF("malloc(%d) -> %p", bytes, r);
_DEBUGF("malloc(%d) -> %p", bytes, r);
return r;
}
void *_serval_debug_calloc(unsigned int bytes, unsigned int count, struct __sourceloc __whence)
{
void *r=calloc((bytes*count)+SDM_GUARD_AFTER,1);
DEBUGF("calloc(%d,%d) -> %p", bytes, count, r);
_DEBUGF("calloc(%d,%d) -> %p", bytes, count, r);
return r;
}
void _serval_debug_free(void *p, struct __sourceloc __whence)
{
free(p);
DEBUGF("free(%p)", p);
_DEBUGF("free(%p)", p);
}

139
meshms.c
View File

@ -71,15 +71,11 @@ static enum meshms_status get_my_conversation_bundle(const sid_t *my_sidp, rhizo
rhizome_manifest_set_name(m, "");
if (rhizome_fill_manifest(m, NULL, my_sidp) != NULL)
return WHY("Invalid conversation manifest");
if (config.debug.meshms) {
char secret[RHIZOME_BUNDLE_KEY_STRLEN + 1];
rhizome_bytes_to_hex_upper(m->cryptoSignSecret, secret, RHIZOME_BUNDLE_KEY_BYTES);
// The 'meshms' automated test depends on this message; do not alter.
DEBUGF("MESHMS CONVERSATION BUNDLE bid=%s secret=%s",
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic),
secret
// The 'meshms' automated test depends on this message; do not alter.
DEBUGF(meshms, "MESHMS CONVERSATION BUNDLE bid=%s secret=%s",
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic),
alloca_tohex(m->cryptoSignSecret, RHIZOME_BUNDLE_KEY_BYTES)
);
}
} else {
if (strcmp(m->service, RHIZOME_SERVICE_FILE) != 0) {
WARNF("Invalid conversations manifest, service=%s but should be %s", m->service, RHIZOME_SERVICE_FILE);
@ -125,11 +121,10 @@ static enum meshms_status get_database_conversations(const sid_t *my_sid, const
);
if (!statement)
return MESHMS_STATUS_ERROR;
if (config.debug.meshms) {
const char *my_sid_hex = alloca_tohex_sid_t(*my_sid);
const char *their_sid_hex = alloca_tohex_sid_t(*(their_sid ? their_sid : my_sid));
DEBUGF("Looking for conversations for %s, %s", my_sid_hex, their_sid_hex);
}
DEBUGF(meshms, "Looking for conversations for %s, %s",
alloca_tohex_sid_t(*my_sid),
alloca_tohex_sid_t(*(their_sid ? their_sid : my_sid))
);
int r;
while ((r=sqlite_step_retry(&retry, statement)) == SQLITE_ROW) {
const char *id_hex = (const char *)sqlite3_column_text(statement, 0);
@ -138,8 +133,7 @@ static enum meshms_status get_database_conversations(const sid_t *my_sid, const
int64_t tail = sqlite3_column_int64(statement, 3);
const char *sender = (const char *)sqlite3_column_text(statement, 4);
const char *recipient = (const char *)sqlite3_column_text(statement, 5);
if (config.debug.meshms)
DEBUGF("found id %s, sender %s, recipient %s", id_hex, sender, recipient);
DEBUGF(meshms, "found id %s, sender %s, recipient %s", id_hex, sender, recipient);
rhizome_bid_t bid;
if (str_to_rhizome_bid_t(&bid, id_hex) == -1) {
WHYF("invalid Bundle ID hex: %s -- skipping", alloca_str_toprint(id_hex));
@ -196,10 +190,10 @@ static enum meshms_status find_or_create_conv(const sid_t *my_sid, const sid_t *
static int create_ply(const sid_t *my_sid, struct meshms_conversations *conv, rhizome_manifest *m)
{
if (config.debug.meshms)
DEBUGF("Creating ply for my_sid=%s them=%s",
alloca_tohex_sid_t(conv->them),
alloca_tohex_sid_t(*my_sid));
DEBUGF(meshms, "Creating ply for my_sid=%s them=%s",
alloca_tohex_sid_t(conv->them),
alloca_tohex_sid_t(*my_sid)
);
rhizome_manifest_set_service(m, RHIZOME_SERVICE_MESHMS2);
rhizome_manifest_set_sender(m, my_sid);
rhizome_manifest_set_recipient(m, &conv->them);
@ -232,8 +226,7 @@ static size_t append_timestamp(uint8_t *buffer)
static enum meshms_status ply_read_open(struct meshms_ply_read *ply, const rhizome_bid_t *bid, rhizome_manifest *m)
{
if (config.debug.meshms)
DEBUGF("Opening ply %s", alloca_tohex_rhizome_bid_t(*bid));
DEBUGF(meshms, "Opening ply %s", alloca_tohex_rhizome_bid_t(*bid));
switch (rhizome_retrieve_manifest(bid, m)) {
case RHIZOME_BUNDLE_STATUS_SAME:
break;
@ -245,8 +238,7 @@ static enum meshms_status ply_read_open(struct meshms_ply_read *ply, const rhizo
return MESHMS_STATUS_ERROR;
}
enum rhizome_payload_status pstatus = rhizome_open_decrypt_read(m, &ply->read);
if (config.debug.meshms)
DEBUGF("pstatus=%d", pstatus);
DEBUGF(meshms, "pstatus=%d", pstatus);
if (pstatus == RHIZOME_PAYLOAD_STATUS_NEW) {
WARNF("Payload was not found for manifest %s, %"PRIu64, alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version);
return MESHMS_STATUS_PROTOCOL_FAULT;
@ -279,8 +271,7 @@ static enum meshms_status ply_read_prev(struct meshms_ply_read *ply)
ply->record_end_offset = ply->read.offset;
unsigned char footer[2];
if (ply->read.offset <= sizeof footer) {
if (config.debug.meshms)
DEBUG("EOF");
DEBUG(meshms, "EOF");
return MESHMS_STATUS_OK;
}
ply->read.offset -= sizeof footer;
@ -297,12 +288,10 @@ static enum meshms_status ply_read_prev(struct meshms_ply_read *ply)
ply->record_length=read_uint16(footer);
ply->type = ply->record_length & 0xF;
ply->record_length = ply->record_length>>4;
if (config.debug.meshms)
DEBUGF("Found record %d, length %d @%"PRId64, ply->type, ply->record_length, ply->record_end_offset);
DEBUGF(meshms, "Found record %d, length %d @%"PRId64, ply->type, ply->record_length, ply->record_end_offset);
// need to allow for advancing the tail and cutting a message in half.
if (ply->record_length + sizeof footer > ply->read.offset){
if (config.debug.meshms)
DEBUGF("EOF");
DEBUGF(meshms, "EOF");
return MESHMS_STATUS_OK;
}
ply->read.offset -= ply->record_length + sizeof(footer);
@ -371,8 +360,7 @@ static enum meshms_status append_meshms_buffer(const sid_t *my_sid, struct meshm
goto end;
enum rhizome_bundle_status bstatus = rhizome_manifest_finalise(m, &mout, 1);
if (config.debug.meshms)
DEBUGF("bstatus=%d", bstatus);
DEBUGF(meshms, "bstatus=%d", bstatus);
switch (bstatus) {
case RHIZOME_BUNDLE_STATUS_ERROR:
// error has already been logged
@ -415,8 +403,7 @@ end:
// return MESHMS_STATUS_UPDATED if the conversation index needs to be saved.
static enum meshms_status update_conversation(const sid_t *my_sid, struct meshms_conversations *conv)
{
if (config.debug.meshms)
DEBUG("Checking if conversation needs to be acked");
DEBUG(meshms, "Checking if conversation needs to be acked");
// Nothing to be done if they have never sent us anything
if (!conv->found_their_ply)
@ -430,8 +417,7 @@ static enum meshms_status update_conversation(const sid_t *my_sid, struct meshms
struct meshms_ply_read ply;
bzero(&ply, sizeof(ply));
enum meshms_status status = MESHMS_STATUS_ERROR;
if (config.debug.meshms)
DEBUG("Locating their last message");
DEBUG(meshms, "Locating their last message");
if (meshms_failed(status = ply_read_open(&ply, &conv->their_ply.bundle_id, m_theirs)))
goto end;
if (meshms_failed(status = ply_find_prev(&ply, MESHMS_BLOCK_TYPE_MESSAGE)))
@ -443,16 +429,14 @@ static enum meshms_status update_conversation(const sid_t *my_sid, struct meshms
}
conv->their_last_message = ply.record_end_offset;
if (config.debug.meshms)
DEBUGF("Found last message @%"PRId64, conv->their_last_message);
DEBUGF(meshms, "Found last message @%"PRId64, conv->their_last_message);
ply_read_close(&ply);
// find our previous ack
uint64_t previous_ack = 0;
if (conv->found_my_ply){
if (config.debug.meshms)
DEBUG("Locating our previous ack");
DEBUG(meshms, "Locating our previous ack");
m_ours = rhizome_new_manifest();
if (!m_ours) {
@ -468,12 +452,10 @@ static enum meshms_status update_conversation(const sid_t *my_sid, struct meshms
previous_ack=0;
status = MESHMS_STATUS_OK;
}
if (config.debug.meshms)
DEBUGF("Previous ack is %"PRId64, previous_ack);
DEBUGF(meshms, "Previous ack is %"PRId64, previous_ack);
ply_read_close(&ply);
}else{
if (config.debug.meshms)
DEBUGF("No outgoing ply");
DEBUGF(meshms, "No outgoing ply");
status = MESHMS_STATUS_PROTOCOL_FAULT;
}
if (previous_ack >= conv->their_last_message){
@ -483,8 +465,7 @@ static enum meshms_status update_conversation(const sid_t *my_sid, struct meshms
}
// append an ack for their message
if (config.debug.meshms)
DEBUGF("Creating ACK for %"PRId64" - %"PRId64, previous_ack, conv->their_last_message);
DEBUGF(meshms, "Creating ACK for %"PRId64" - %"PRId64, previous_ack, conv->their_last_message);
unsigned char buffer[30];
int ofs=0;
ofs+=pack_uint(&buffer[ofs], conv->their_last_message);
@ -493,8 +474,7 @@ static enum meshms_status update_conversation(const sid_t *my_sid, struct meshms
ofs+=append_footer(buffer+ofs, MESHMS_BLOCK_TYPE_ACK, ofs);
ofs+=append_timestamp(buffer+ofs);
status = append_meshms_buffer(my_sid, conv, buffer, ofs);
if (config.debug.meshms)
DEBUGF("status=%d", status);
DEBUGF(meshms, "status=%d", status);
end:
ply_read_close(&ply);
if (m_ours)
@ -520,8 +500,7 @@ static enum meshms_status update_conversations(const sid_t *my_sid, struct meshm
return status;
if (status == MESHMS_STATUS_UPDATED){
rstatus = MESHMS_STATUS_UPDATED;
if (config.debug.meshms)
DEBUGF("Bumping conversation from %s", alloca_tohex_sid_t(n->them));
DEBUGF(meshms, "Bumping conversation from %s", alloca_tohex_sid_t(n->them));
// bump to head of list
*ptr = n->_next;
n->_next = *conv;
@ -574,8 +553,7 @@ static enum meshms_status read_known_conversations(rhizome_manifest *m, const si
}
if (r != sizeof sid.binary)
break;
if (config.debug.meshms)
DEBUGF("Reading existing conversation for %s", alloca_tohex_sid_t(sid));
DEBUGF(meshms, "Reading existing conversation for %s", alloca_tohex_sid_t(sid));
// unpack the stored details first so we know where the next record is
unsigned char details[12*3];
@ -645,13 +623,13 @@ static ssize_t write_conversation(struct rhizome_write *write, struct meshms_con
len+=measure_packed_uint(conv->read_offset);
len+=measure_packed_uint(conv->their_size);
}
if (config.debug.meshms)
DEBUGF("len %s, %"PRId64", %"PRId64", %"PRId64" = %zu",
alloca_tohex_sid_t(conv->them),
conv->their_last_message,
conv->read_offset,
conv->their_size,
len);
DEBUGF(meshms, "len %s, %"PRId64", %"PRId64", %"PRId64" = %zu",
alloca_tohex_sid_t(conv->them),
conv->their_last_message,
conv->read_offset,
conv->their_size,
len
);
return len;
}
@ -759,8 +737,7 @@ enum meshms_status meshms_conversations_list(const sid_t *my_sid, const sid_t *t
status = write_known_conversations(m, *conv);
end:
rhizome_manifest_free(m);
if (config.debug.meshms)
DEBUGF("status=%d", status);
DEBUGF(meshms, "status=%d", status);
return status;
}
@ -785,10 +762,9 @@ void meshms_conversation_iterator_advance(struct meshms_conversation_iterator *i
enum meshms_status meshms_message_iterator_open(struct meshms_message_iterator *iter, const sid_t *me, const sid_t *them)
{
if (config.debug.meshms)
DEBUGF("iter=%p me=%s them=%s", iter,
me ? alloca_tohex_sid_t(*me) : "NULL",
them ? alloca_tohex_sid_t(*them) : "NULL"
DEBUGF(meshms, "iter=%p me=%s them=%s", iter,
me ? alloca_tohex_sid_t(*me) : "NULL",
them ? alloca_tohex_sid_t(*them) : "NULL"
);
enum meshms_status status;
bzero(iter, sizeof *iter);
@ -821,15 +797,13 @@ enum meshms_status meshms_message_iterator_open(struct meshms_message_iterator *
iter->latest_ack_my_offset = 0;
else
iter->latest_ack_offset = iter->_their_reader.record_end_offset;
if (config.debug.meshms)
DEBUGF("Found their last ack @%"PRId64, iter->latest_ack_my_offset);
DEBUGF(meshms, "Found their last ack @%"PRId64, iter->latest_ack_my_offset);
}
// Re-seek to end of their ply.
iter->_their_reader.read.offset = iter->_their_reader.read.length;
}
} else {
if (config.debug.meshms)
DEBUGF("Did not find sender's ply; no messages in thread");
DEBUGF(meshms, "Did not find sender's ply; no messages in thread");
}
iter->_in_ack = 0;
return MESHMS_STATUS_OK;
@ -847,8 +821,7 @@ int meshms_message_iterator_is_open(const struct meshms_message_iterator *iter)
void meshms_message_iterator_close(struct meshms_message_iterator *iter)
{
if (config.debug.meshms)
DEBUGF("iter=%p", iter);
DEBUGF(meshms, "iter=%p", iter);
if (iter->_my_manifest) {
ply_read_close(&iter->_my_reader);
rhizome_manifest_free(iter->_my_manifest);
@ -874,8 +847,7 @@ enum meshms_status meshms_message_iterator_prev(struct meshms_message_iterator *
enum meshms_status status = MESHMS_STATUS_UPDATED;
while (status == MESHMS_STATUS_UPDATED) {
if (iter->_in_ack) {
if (config.debug.meshms)
DEBUGF("Reading other log from %"PRId64", to %"PRId64, iter->_their_reader.read.offset, iter->_end_range);
DEBUGF(meshms, "Reading other log from %"PRId64", to %"PRId64, iter->_their_reader.read.offset, iter->_end_range);
if (meshms_failed(status = ply_read_prev(&iter->_their_reader)))
break;
iter->which_ply = THEIR_PLY;
@ -910,8 +882,7 @@ enum meshms_status meshms_message_iterator_prev(struct meshms_message_iterator *
status = MESHMS_STATUS_UPDATED;
}
else if ((status = ply_read_prev(&iter->_my_reader)) == MESHMS_STATUS_UPDATED) {
if (config.debug.meshms)
DEBUGF("Offset %"PRId64", type %d, read_offset %"PRId64, iter->_my_reader.read.offset, iter->_my_reader.type, iter->read_offset);
DEBUGF(meshms, "Offset %"PRId64", type %d, read_offset %"PRId64, iter->_my_reader.read.offset, iter->_my_reader.type, iter->read_offset);
iter->which_ply = MY_PLY;
switch (iter->_my_reader.type) {
case MESHMS_BLOCK_TYPE_TIME:
@ -920,7 +891,7 @@ enum meshms_status meshms_message_iterator_prev(struct meshms_message_iterator *
return MESHMS_STATUS_PROTOCOL_FAULT;
}
iter->timestamp = read_uint32(iter->_my_reader.record);
DEBUGF("Parsed timestamp %ds old", gettime() - iter->timestamp);
DEBUGF(meshms, "Parsed timestamp %ds old", gettime() - iter->timestamp);
break;
case MESHMS_BLOCK_TYPE_ACK:
// Read the received messages up to the ack'ed offset
@ -984,11 +955,10 @@ enum meshms_status meshms_send_message(const sid_t *sender, const sid_t *recipie
enum meshms_status meshms_mark_read(const sid_t *sender, const sid_t *recipient, uint64_t offset)
{
if (config.debug.meshms)
DEBUGF("sender=%s recipient=%s offset=%"PRIu64,
alloca_tohex_sid_t(*sender),
recipient ? alloca_tohex_sid_t(*recipient) : "NULL",
offset
DEBUGF(meshms, "sender=%s recipient=%s offset=%"PRIu64,
alloca_tohex_sid_t(*sender),
recipient ? alloca_tohex_sid_t(*recipient) : "NULL",
offset
);
enum meshms_status status = MESHMS_STATUS_ERROR;
struct meshms_conversations *conv = NULL;
@ -1010,8 +980,7 @@ enum meshms_status meshms_mark_read(const sid_t *sender, const sid_t *recipient,
if (status == MESHMS_STATUS_UPDATED)
changed = 1;
changed += mark_read(conv, recipient, offset);
if (config.debug.meshms)
DEBUGF("changed=%u", changed);
DEBUGF(meshms, "changed=%u", changed);
if (changed) {
if (meshms_failed(status = write_known_conversations(m, conv)))
goto end;
@ -1228,9 +1197,9 @@ static unsigned mark_read(struct meshms_conversations *conv, const sid_t *their_
if (new_offset > conv->their_last_message)
new_offset = conv->their_last_message;
if (new_offset > conv->read_offset) {
if (config.debug.meshms)
DEBUGF("Moving read marker for %s, from %"PRId64" to %"PRId64,
alloca_tohex_sid_t(conv->them), conv->read_offset, new_offset);
DEBUGF(meshms, "Moving read marker for %s, from %"PRId64" to %"PRId64,
alloca_tohex_sid_t(conv->them), conv->read_offset, new_offset
);
conv->read_offset = new_offset;
ret++;
}

View File

@ -591,8 +591,7 @@ static int send_mime_part_end(struct http_request *hr)
if (r->u.sendmsg.message.length == 0)
return http_response_form_part(r, "Invalid (empty)", PART_MESSAGE, NULL, 0);
r->u.sendmsg.received_message = 1;
if (config.debug.httpd)
DEBUGF("received %s = %s", PART_MESSAGE, alloca_toprint(-1, r->u.sendmsg.message.buffer, r->u.sendmsg.message.length));
DEBUGF(httpd, "received %s = %s", PART_MESSAGE, alloca_toprint(-1, r->u.sendmsg.message.buffer, r->u.sendmsg.message.length));
} else
FATALF("current_part = %s", alloca_str_toprint(r->u.sendmsg.current_part));
r->u.sendmsg.current_part = NULL;

View File

@ -72,8 +72,7 @@ int monitor_client_open(struct monitor_state **res)
struct socket_address addr;
if (make_local_sockaddr(&addr, "monitor.socket") == -1)
return -1;
if (config.debug.monitor)
DEBUGF("Attempting to connect to %s", alloca_socket_address(&addr));
DEBUGF(monitor, "Attempting to connect to %s", alloca_socket_address(&addr));
if (socket_connect(fd, &addr) == -1) {
close(fd);
return -1;
@ -86,8 +85,7 @@ int monitor_client_open(struct monitor_state **res)
int monitor_client_close(int fd, struct monitor_state *res){
free(res);
close(fd);
if (config.debug.monitor)
DEBUGF("Closed fd %d", fd);
DEBUGF(monitor, "Closed fd %d", fd);
return 0;
}
@ -104,8 +102,8 @@ int monitor_client_writeline(int fd,char *fmt, ...)
n=vsnprintf(msg, sizeof(msg), fmt, ap);
va_end(ap);
if (config.debug.monitor)
dump("Writing to monitor", msg, n);
if (IF_DEBUG(monitor))
dump("{monitor} Writing to monitor", msg, n);
return write(fd,msg,n);
}
@ -128,8 +126,8 @@ int monitor_client_writeline_and_data(int fd,unsigned char *data,int bytes,char
bcopy(data,out+n,bytes);
n+=bytes;
if (config.debug.monitor)
dump("Writing to monitor", out, n);
if (IF_DEBUG(monitor))
dump("{monitor} Writing to monitor", out, n);
return write(fd,out,n);
}
@ -164,8 +162,8 @@ int monitor_client_read(int fd, struct monitor_state *res, struct monitor_comman
return -1;
}
if (config.debug.monitor)
dump("Read from monitor", res->buffer + oldOffset, bytesRead);
if (IF_DEBUG(monitor))
dump("{monitor} Read from monitor", res->buffer + oldOffset, bytesRead);
res->bufferBytes+=bytesRead;

View File

@ -484,7 +484,7 @@ static int monitor_lookup_match(const struct cli_parsed *parsed, struct cli_cont
char uri[256];
snprintf(uri, sizeof(uri), "sid://%s/external/%s", alloca_tohex_sid_t(my_subscriber->sid), ext);
DEBUGF("Sending response to %s for %s", sid, uri);
DEBUGF(monitor, "Sending response to %s for %s", sid, uri);
overlay_mdp_dnalookup_reply(destination, dest_port, my_subscriber, uri, ext, name);
return 0;
}

View File

@ -205,18 +205,20 @@ unsigned msp_socket_count()
void msp_debug()
{
time_ms_t now = gettime_ms();
struct msp_sock *p=root;
DEBUGF("Msp sockets;");
while(p){
DEBUGF("State %d, from %s:%d to %s:%d, next %"PRId64"ms, ack %"PRId64"ms timeout %"PRId64"ms",
p->state,
alloca_tohex_sid_t(p->header.local.sid), p->header.local.port,
alloca_tohex_sid_t(p->header.remote.sid), p->header.remote.port,
(p->next_action - now),
(p->next_ack - now),
(p->timeout - now));
p=p->_next;
if (IF_DEBUG(msp)) {
time_ms_t now = gettime_ms();
struct msp_sock *p=root;
DEBUGF(msp, "Msp sockets;");
while(p){
DEBUGF(msp, "State %d, from %s:%d to %s:%d, next %"PRId64"ms, ack %"PRId64"ms timeout %"PRId64"ms",
p->state,
alloca_tohex_sid_t(p->header.local.sid), p->header.local.port,
alloca_tohex_sid_t(p->header.remote.sid), p->header.remote.port,
(p->next_action - now),
(p->next_ack - now),
(p->timeout - now));
p=p->_next;
}
}
}
@ -264,8 +266,7 @@ static void free_acked_packets(struct msp_window *window, uint16_t seq)
window->rtt = rtt;
if (window->base_rtt > rtt)
window->base_rtt = rtt;
if (config.debug.msp)
DEBUGF("ACK %x, RTT %u-%u, base %u", seq, rtt, rtt_max, window->base_rtt);
DEBUGF(msp, "ACK %x, RTT %u-%u, base %u", seq, rtt, rtt_max, window->base_rtt);
}
if (!p)
window->_tail = NULL;
@ -323,8 +324,7 @@ void msp_stop(MSP_SOCKET handle)
// we don't have a matching socket, reply with STOP flag to force breaking the connection
// TODO global rate limit?
mdp_send(sock->mdp_sock, &sock->header, &response, 1);
if (config.debug.msp)
DEBUGF("Sending STOP packet");
DEBUGF(msp, "Sending STOP packet");
}
}
@ -403,8 +403,7 @@ static int add_packet(struct msp_window *window, uint16_t seq, uint8_t flags, co
}else{
if (window->_tail->seq == seq){
// ignore duplicate packets
if (config.debug.msp)
DEBUGF("Ignore duplicate packet %02x", seq);
DEBUGF(msp, "Ignore duplicate packet %02x", seq);
return 0;
}else if (compare_wrapped_uint16(window->_tail->seq, seq)<0){
if (compare_wrapped_uint16(window->_head->seq, seq)>0){
@ -418,8 +417,7 @@ static int add_packet(struct msp_window *window, uint16_t seq, uint8_t flags, co
insert_pos = &(*insert_pos)->_next;
if ((*insert_pos)->seq == seq){
// ignore duplicate packets
if (config.debug.msp)
DEBUGF("Ignore duplicate packet %02x", seq);
DEBUGF(msp, "Ignore duplicate packet %02x", seq);
return 0;
}
}
@ -450,8 +448,7 @@ static int add_packet(struct msp_window *window, uint16_t seq, uint8_t flags, co
bcopy(payload, p, len);
}
window->packet_count++;
if (config.debug.msp)
DEBUGF("Add packet %02x", seq);
DEBUGF(msp, "Add packet %02x", seq);
return 1;
}
@ -509,8 +506,7 @@ static int msp_send_packet(struct msp_sock *sock, struct msp_packet *packet)
msp_close_all(sock->mdp_sock);
return -1;
}
if (config.debug.msp)
DEBUGF("Sent packet flags %02x seq %02x len %zd (acked %02x)", msp_header[0], packet->seq, packet->len, sock->rx.next_seq -1);
DEBUGF(msp, "Sent packet flags %02x seq %02x len %zd (acked %02x)", msp_header[0], packet->seq, packet->len, sock->rx.next_seq -1);
sock->tx.last_activity = packet->sent = gettime_ms();
sock->next_ack = packet->sent + RETRANSMIT_TIME;
return 0;
@ -558,8 +554,7 @@ static int send_ack(struct msp_sock *sock)
msp_close_all(sock->mdp_sock);
return -1;
}
if (config.debug.msp)
DEBUGF("Sent packet flags %02x (acked %02x)", msp_header[0], sock->rx.next_seq -1);
DEBUGF(msp, "Sent packet flags %02x (acked %02x)", msp_header[0], sock->rx.next_seq -1);
sock->previous_ack = sock->rx.next_seq -1;
sock->tx.last_activity = gettime_ms();
sock->next_ack = sock->tx.last_activity + RETRANSMIT_TIME;
@ -755,8 +750,7 @@ static void msp_release(struct msp_sock *sock){
header.remote.sid = SID_ANY;
header.remote.port = MDP_LISTEN;
header.flags = MDP_FLAG_CLOSE;
if (config.debug.msp)
DEBUGF("Releasing mdp port binding %d", header.local.port);
DEBUGF(msp, "Releasing mdp port binding %d", header.local.port);
mdp_send(sock->mdp_sock, &header, NULL, 0);
sock->header.local.port=0;
sock->header.local.sid=SID_ANY;
@ -811,8 +805,7 @@ static int process_packet(int mdp_sock, struct mdp_header *header, const uint8_t
// process bind response from the daemon
s->header.local = header->local;
s->header.flags &= ~MDP_FLAG_BIND;
if (config.debug.msp)
DEBUGF("Bound to %s:%d", alloca_tohex_sid_t(header->local.sid), header->local.port);
DEBUGF(msp, "Bound to %s:%d", alloca_tohex_sid_t(header->local.sid), header->local.port);
if (s->state & MSP_STATE_LISTENING)
s->next_action = s->timeout = TIME_MS_NEVER_WILL;
else
@ -842,8 +835,7 @@ static int process_packet(int mdp_sock, struct mdp_header *header, const uint8_t
// ignore any stop packet if we have no matching connection
if (!sock && flags & FLAG_STOP){
if (config.debug.msp)
DEBUGF("Ignoring STOP packet, no matching connection");
DEBUGF(msp, "Ignoring STOP packet, no matching connection");
return 0;
}
@ -865,8 +857,7 @@ static int process_packet(int mdp_sock, struct mdp_header *header, const uint8_t
// TODO global rate limit?
// Note that we might recieve a queued packet after sending a MDP_FLAG_CLOSE, so this might trigger an error
mdp_send(mdp_sock, header, &response, 1);
if (config.debug.msp)
DEBUGF("Replying to unexpected packet with STOP packet");
DEBUGF(msp, "Replying to unexpected packet with STOP packet");
return 0;
}
}
@ -876,8 +867,7 @@ static int process_packet(int mdp_sock, struct mdp_header *header, const uint8_t
sock->state |= MSP_STATE_RECEIVED_PACKET;
if (flags & FLAG_STOP){
if (config.debug.msp)
DEBUGF("Closing socket due to STOP packet");
DEBUGF(msp, "Closing socket due to STOP packet");
msp_stop(sock_to_handle(sock));
return 0;
}

View File

@ -216,8 +216,7 @@ static void remote_shutdown(struct connection *conn)
WARNF_perror("shutdown(%d)", conn->alarm_out.poll.fd);
}
msp_get_remote(conn->sock, &remote);
if (config.debug.msp)
DEBUGF(" - Connection with %s:%d remote shutdown", alloca_tohex_sid_t(remote.sid), remote.port);
DEBUGF(msp, " - Connection with %s:%d remote shutdown", alloca_tohex_sid_t(remote.sid), remote.port);
}
static void local_shutdown(struct connection *conn)
@ -225,8 +224,7 @@ static void local_shutdown(struct connection *conn)
struct mdp_sockaddr remote;
msp_get_remote(conn->sock, &remote);
msp_shutdown(conn->sock);
if (config.debug.msp)
DEBUGF(" - Connection with %s:%d local shutdown", alloca_tohex_sid_t(remote.sid), remote.port);
DEBUGF(msp, " - Connection with %s:%d local shutdown", alloca_tohex_sid_t(remote.sid), remote.port);
}
static size_t msp_handler(MSP_SOCKET sock, msp_state_t state, const uint8_t *payload, size_t len, void *context)
@ -270,8 +268,7 @@ static size_t msp_handler(MSP_SOCKET sock, msp_state_t state, const uint8_t *pay
if (state & MSP_STATE_CLOSED){
struct mdp_sockaddr remote;
msp_get_remote(sock, &remote);
if (config.debug.msp)
DEBUGF(" - Connection with %s:%d closed %s",
DEBUGF(msp, " - Connection with %s:%d closed %s",
alloca_tohex_sid_t(remote.sid), remote.port,
(state & MSP_STATE_STOPPED) ? "suddenly":"gracefully");
@ -316,8 +313,7 @@ static size_t msp_listener(MSP_SOCKET sock, msp_state_t state, const uint8_t *pa
struct mdp_sockaddr remote;
msp_get_remote(sock, &remote);
if (config.debug.msp)
DEBUGF(" - New connection from %s:%d", alloca_tohex_sid_t(remote.sid), remote.port);
DEBUGF(msp, " - New connection from %s:%d", alloca_tohex_sid_t(remote.sid), remote.port);
int fd_in = STDIN_FILENO;
int fd_out = STDOUT_FILENO;
@ -518,8 +514,7 @@ static void listen_poll(struct sched_ent *alarm)
WHYF_perror("accept(%d)", alarm->poll.fd);
return;
}
if (config.debug.msp)
DEBUGF("- Incoming TCP connection from %s", alloca_socket_address(&addr));
DEBUGF(msp, "- Incoming TCP connection from %s", alloca_socket_address(&addr));
watch(&mdp_sock);
MSP_SOCKET sock = msp_socket(mdp_sock.poll.fd, 0);
if (msp_socket_is_null(sock))
@ -642,8 +637,7 @@ static int app_msp_connection(const struct cli_parsed *parsed, struct cli_contex
if (socket_listen(listen_alarm.poll.fd, 0)==-1)
goto end;
watch(&listen_alarm);
if (config.debug.msp)
DEBUGF("- Forwarding from %s to %s:%d", alloca_socket_address(&ip_addr), alloca_tohex_sid_t(addr.sid), addr.port);
DEBUGF(msp, "- Forwarding from %s to %s:%d", alloca_socket_address(&ip_addr), alloca_tohex_sid_t(addr.sid), addr.port);
}else{
watch(&mdp_sock);
sock = msp_socket(mdp_sock.poll.fd, 0);
@ -653,8 +647,7 @@ static int app_msp_connection(const struct cli_parsed *parsed, struct cli_contex
goto end;
msp_set_handler(sock, msp_handler, conn);
msp_connect(sock, &addr);
if (config.debug.msp)
DEBUGF("- Connecting to %s:%d", alloca_tohex_sid_t(addr.sid), addr.port);
DEBUGF(msp, "- Connecting to %s:%d", alloca_tohex_sid_t(addr.sid), addr.port);
}
}else{
watch(&mdp_sock);
@ -668,12 +661,10 @@ static int app_msp_connection(const struct cli_parsed *parsed, struct cli_contex
listener=sock;
if (local_port_string){
if (config.debug.msp)
DEBUGF("- Forwarding from port %d to %s", addr.port, alloca_socket_address(&ip_addr));
DEBUGF(msp, "- Forwarding from port %d to %s", addr.port, alloca_socket_address(&ip_addr));
}else{
once = 1;
if (config.debug.msp)
DEBUGF(" - Listening on port %d", addr.port);
DEBUGF(msp, " - Listening on port %d", addr.port);
}
}

View File

@ -39,8 +39,7 @@ DEFINE_CMD(app_mdp_ping, 0,
static int app_mdp_ping(const struct cli_parsed *parsed, struct cli_context *context)
{
int mdp_sockfd;
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
const char *sidhex, *count, *opt_timeout, *opt_interval;
int opt_wait_for_duplicates = 0 == cli_arg(parsed, "--wait-for-duplicates", NULL, NULL, NULL);
if ( cli_arg(parsed, "--timeout", &opt_timeout, cli_interval_ms, "1") == -1
@ -128,8 +127,7 @@ static int app_mdp_ping(const struct cli_parsed *parsed, struct cli_context *con
write_uint64(&payload[4], now);
int r = mdp_send(mdp_sockfd, &mdp_header, payload, sizeof(payload));
if (r != -1) {
if (config.debug.mdprequests)
DEBUGF("ping seq=%lu", (unsigned long)(sequence_number - firstSeq) + 1);
DEBUGF(mdprequests, "ping seq=%lu", (unsigned long)(sequence_number - firstSeq) + 1);
unsigned i = (unsigned long)(sequence_number - firstSeq) % NELS(stats);
assert(i == tx_count % NELS(stats));
struct packet_stat *stat = &stats[i];
@ -170,13 +168,11 @@ static int app_mdp_ping(const struct cli_parsed *parsed, struct cli_context *con
// received port binding confirmation
mdp_header.local = mdp_recv_header.local;
mdp_header.flags &= ~MDP_FLAG_BIND;
if (config.debug.mdprequests)
DEBUGF("bound to %s:%d", alloca_tohex_sid_t(mdp_header.local.sid), mdp_header.local.port);
DEBUGF(mdprequests, "bound to %s:%d", alloca_tohex_sid_t(mdp_header.local.sid), mdp_header.local.port);
continue;
}
if ((size_t)len < sizeof(recv_payload)){
if (config.debug.mdprequests)
DEBUGF("ignoring short pong");
DEBUGF(mdprequests, "ignoring short pong");
continue;
}
uint32_t rxseq = read_uint32(&recv_payload[0]);
@ -187,8 +183,7 @@ static int app_mdp_ping(const struct cli_parsed *parsed, struct cli_context *con
struct packet_stat *stat = &stats[(unsigned long)(rxseq - firstSeq) % NELS(stats)];
if (stat->sequence != rxseq || stat->tx_time != txtime) {
if (config.debug.mdprequests)
DEBUGF("ignoring spurious pong");
DEBUGF(mdprequests, "ignoring spurious pong");
++rx_igncount;
stat = NULL; // old or corrupted reply (either sequence or txtime is wrong)
} else if (stat->pong_count++ == 0) {
@ -350,8 +345,7 @@ DEFINE_CMD(app_id_self, 0,
static int app_id_self(const struct cli_parsed *parsed, struct cli_context *context)
{
int mdp_sockfd;
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
/* List my own identities */
overlay_mdp_frame a;
bzero(&a, sizeof(overlay_mdp_frame));
@ -413,8 +407,7 @@ DEFINE_CMD(app_count_peers, 0,
static int app_count_peers(const struct cli_parsed *parsed, struct cli_context *context)
{
int mdp_sockfd;
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
if ((mdp_sockfd = overlay_mdp_client_socket()) < 0)
return WHY("Cannot create MDP socket");
@ -441,8 +434,7 @@ DEFINE_CMD(app_route_print, 0,
static int app_route_print(const struct cli_parsed *parsed, struct cli_context *context)
{
int mdp_sockfd;
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
if ((mdp_sockfd = overlay_mdp_client_socket()) < 0)
return WHY("Cannot create MDP socket");
@ -513,8 +505,7 @@ DEFINE_CMD(app_network_scan, 0,
static int app_network_scan(const struct cli_parsed *parsed, struct cli_context *context)
{
int mdp_sockfd;
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
overlay_mdp_frame mdp;
bzero(&mdp,sizeof(mdp));
@ -585,8 +576,7 @@ DEFINE_CMD(app_dna_lookup, 0,
static int app_dna_lookup(const struct cli_parsed *parsed, struct cli_context *context)
{
int mdp_sockfd;
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
/* Create the instance directory if it does not yet exist */
if (create_serval_instance_dir() == -1)
@ -715,8 +705,7 @@ DEFINE_CMD(app_reverse_lookup, 0,
static int app_reverse_lookup(const struct cli_parsed *parsed, struct cli_context *context)
{
int mdp_sockfd;
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
const char *sidhex, *delay;
if (cli_arg(parsed, "sid", &sidhex, str_is_subscriber_id, "") == -1)
return -1;

View File

@ -110,8 +110,7 @@ void free_subscribers()
struct subscriber *_find_subscriber(struct __sourceloc __whence, const unsigned char *sidp, int len, int create)
{
IN();
if (config.debug.subscriber)
DEBUGF("find_subscriber(sid=%s, create=%d)", alloca_tohex(sidp, len), create);
DEBUGF(subscriber, "find_subscriber(sid=%s, create=%d)", alloca_tohex(sidp, len), create);
struct tree_node *ptr = &root;
int pos=0;
if (len!=SID_SIZE)
@ -127,10 +126,9 @@ struct subscriber *_find_subscriber(struct __sourceloc __whence, const unsigned
ptr->subscribers[nibble] = ret;
ret->sid = *(const sid_t *)sidp;
ret->abbreviate_len = pos;
if (config.debug.subscriber)
DEBUGF("set node[%.*s].subscribers[%c]=%p (sid=%s, abbrev_len=%d)",
pos - 1, alloca_tohex(sidp, len), hexdigit_upper[nibble],
ret, alloca_tohex_sid_t(ret->sid), ret->abbreviate_len
DEBUGF(subscriber, "set node[%.*s].subscribers[%c]=%p (sid=%s, abbrev_len=%d)",
pos - 1, alloca_tohex(sidp, len), hexdigit_upper[nibble],
ret, alloca_tohex_sid_t(ret->sid), ret->abbreviate_len
);
}
goto done;
@ -150,25 +148,22 @@ struct subscriber *_find_subscriber(struct __sourceloc __whence, const unsigned
ret = NULL;
goto done;
}
if (config.debug.subscriber)
DEBUGF("create node[%.*s]", pos, alloca_tohex(sidp, len));
DEBUGF(subscriber, "create node[%.*s]", pos, alloca_tohex(sidp, len));
ptr->tree_nodes[nibble] = new;
ptr->is_tree |= (1<<nibble);
ptr = new;
nibble = get_nibble(ret->sid.binary, pos);
ptr->subscribers[nibble] = ret;
ret->abbreviate_len = pos + 1;
if (config.debug.subscriber)
DEBUGF("set node[%.*s].subscribers[%c]=%p(sid=%s, abbrev_len=%d)",
pos, alloca_tohex(sidp, len), hexdigit_upper[nibble],
ret, alloca_tohex_sid_t(ret->sid), ret->abbreviate_len
);
DEBUGF(subscriber, "set node[%.*s].subscribers[%c]=%p(sid=%s, abbrev_len=%d)",
pos, alloca_tohex(sidp, len), hexdigit_upper[nibble],
ret, alloca_tohex_sid_t(ret->sid), ret->abbreviate_len
);
// then go around the loop again to compare the next nibble against the sid until we find an empty slot.
}
} while(pos < len*2);
done:
if (config.debug.subscriber)
DEBUGF("find_subscriber() return %p", ret);
DEBUGF(subscriber, "find_subscriber() return %p", ret);
RETURN(ret);
}
@ -239,13 +234,11 @@ int overlay_broadcast_drop_check(struct broadcast *addr)
bpi_index&=BPI_MASK;
if (memcmp(bpilist[bpi_index].id, addr->id, BROADCAST_LEN)){
if (config.debug.broadcasts)
DEBUGF("BPI %s is new", alloca_tohex(addr->id, BROADCAST_LEN));
DEBUGF(broadcasts, "BPI %s is new", alloca_tohex(addr->id, BROADCAST_LEN));
bcopy(addr->id, bpilist[bpi_index].id, BROADCAST_LEN);
return 0; /* don't drop */
}else{
if (config.debug.broadcasts)
DEBUGF("BPI %s is a duplicate", alloca_tohex(addr->id, BROADCAST_LEN));
DEBUGF(broadcasts, "BPI %s is a duplicate", alloca_tohex(addr->id, BROADCAST_LEN));
return 1; /* drop frame because we have seen this BPI recently */
}
}
@ -313,8 +306,7 @@ static int add_explain_response(struct subscriber *subscriber, void *context)
// the header of this packet must include our full sid.
if (subscriber->reachable==REACHABLE_SELF){
if (subscriber==my_subscriber){
if (config.debug.subscriber)
DEBUGF("Explaining SELF sid=%s", alloca_tohex_sid_t(subscriber->sid));
DEBUGF(subscriber, "Explaining SELF sid=%s", alloca_tohex_sid_t(subscriber->sid));
response->please_explain->source_full=1;
return 0;
}
@ -322,8 +314,7 @@ static int add_explain_response(struct subscriber *subscriber, void *context)
}
// add the whole subscriber id to the payload, stop if we run out of space
if (config.debug.subscriber)
DEBUGF("Explaining sid=%s", alloca_tohex_sid_t(subscriber->sid));
DEBUGF(subscriber, "Explaining sid=%s", alloca_tohex_sid_t(subscriber->sid));
ob_checkpoint(response->please_explain->payload);
ob_append_byte(response->please_explain->payload, SID_SIZE);
ob_append_bytes(response->please_explain->payload, subscriber->sid.binary, SID_SIZE);
@ -532,7 +523,6 @@ int process_explain(struct overlay_frame *frame)
}
if (context.please_explain)
send_please_explain(&context, frame->destination, frame->source);
else if (config.debug.subscriber)
DEBUG("No explain responses");
DEBUG(subscriber, "No explain responses");
return 0;
}

View File

@ -34,8 +34,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
struct overlay_buffer *_ob_new(struct __sourceloc __whence)
{
struct overlay_buffer *ret = emalloc_zero(sizeof(struct overlay_buffer));
if (config.debug.overlaybuffer)
DEBUGF("ob_new() return %p", ret);
DEBUGF(overlaybuffer, "ob_new() return %p", ret);
if (ret == NULL)
return NULL;
ob_unlimitsize(ret);
@ -47,8 +46,7 @@ struct overlay_buffer *_ob_new(struct __sourceloc __whence)
struct overlay_buffer *_ob_static(struct __sourceloc __whence, unsigned char *bytes, size_t size)
{
struct overlay_buffer *ret = emalloc_zero(sizeof(struct overlay_buffer));
if (config.debug.overlaybuffer)
DEBUGF("ob_static(bytes=%p, size=%zu) return %p", bytes, size, ret);
DEBUGF(overlaybuffer, "ob_static(bytes=%p, size=%zu) return %p", bytes, size, ret);
if (ret == NULL)
return NULL;
ret->bytes = bytes;
@ -68,8 +66,7 @@ struct overlay_buffer *_ob_slice(struct __sourceloc __whence, struct overlay_buf
return NULL;
}
struct overlay_buffer *ret = emalloc_zero(sizeof(struct overlay_buffer));
if (config.debug.overlaybuffer)
DEBUGF("ob_slice(b=%p, offset=%zu, length=%zu) return %p", b, offset, length, ret);
DEBUGF(overlaybuffer, "ob_slice(b=%p, offset=%zu, length=%zu) return %p", b, offset, length, ret);
if (ret == NULL)
return NULL;
ret->bytes = b->bytes + offset;
@ -82,8 +79,7 @@ struct overlay_buffer *_ob_slice(struct __sourceloc __whence, struct overlay_buf
struct overlay_buffer *_ob_dup(struct __sourceloc __whence, struct overlay_buffer *b)
{
struct overlay_buffer *ret = emalloc_zero(sizeof(struct overlay_buffer));
if (config.debug.overlaybuffer)
DEBUGF("ob_dup(b=%p) return %p", b, ret);
DEBUGF(overlaybuffer, "ob_dup(b=%p) return %p", b, ret);
if (ret == NULL)
return NULL;
ret->sizeLimit = b->sizeLimit;
@ -107,8 +103,7 @@ struct overlay_buffer *_ob_dup(struct __sourceloc __whence, struct overlay_buffe
void _ob_free(struct __sourceloc __whence, struct overlay_buffer *b)
{
assert(b != NULL);
if (config.debug.overlaybuffer)
DEBUGF("ob_free(b=%p)", b);
DEBUGF(overlaybuffer, "ob_free(b=%p)", b);
if (b->allocated)
free(b->allocated);
free(b);
@ -118,8 +113,7 @@ int _ob_checkpoint(struct __sourceloc __whence, struct overlay_buffer *b)
{
assert(b != NULL);
b->checkpointLength = b->position;
if (config.debug.overlaybuffer)
DEBUGF("ob_checkpoint(b=%p) checkpointLength=%zu", b, b->checkpointLength);
DEBUGF(overlaybuffer, "ob_checkpoint(b=%p) checkpointLength=%zu", b, b->checkpointLength);
return 0;
}
@ -127,8 +121,7 @@ int _ob_rewind(struct __sourceloc __whence, struct overlay_buffer *b)
{
assert(b != NULL);
b->position = b->checkpointLength;
if (config.debug.overlaybuffer)
DEBUGF("ob_rewind(b=%p) position=%zu", b, b->position);
DEBUGF(overlaybuffer, "ob_rewind(b=%p) position=%zu", b, b->position);
return 0;
}
@ -141,22 +134,19 @@ void _ob_limitsize(struct __sourceloc __whence, struct overlay_buffer *b, size_t
if (b->bytes && b->allocated == NULL)
assert(bytes <= b->allocSize);
b->sizeLimit = bytes;
if (config.debug.overlaybuffer)
DEBUGF("ob_limitsize(b=%p, bytes=%zu) sizeLimit=%zu", b, bytes, b->sizeLimit);
DEBUGF(overlaybuffer, "ob_limitsize(b=%p, bytes=%zu) sizeLimit=%zu", b, bytes, b->sizeLimit);
}
void _ob_unlimitsize(struct __sourceloc __whence, struct overlay_buffer *b)
{
assert(b != NULL);
b->sizeLimit = SIZE_MAX;
if (config.debug.overlaybuffer)
DEBUGF("ob_unlimitsize(b=%p) sizeLimit=%zu", b, b->sizeLimit);
DEBUGF(overlaybuffer, "ob_unlimitsize(b=%p) sizeLimit=%zu", b, b->sizeLimit);
}
void _ob_flip(struct __sourceloc __whence, struct overlay_buffer *b)
{
if (config.debug.overlaybuffer)
DEBUGF("ob_flip(b=%p) checkpointLength=0 position=0", b);
DEBUGF(overlaybuffer, "ob_flip(b=%p) checkpointLength=0 position=0", b);
b->checkpointLength = 0;
ob_limitsize(b, b->position);
b->position = 0;
@ -164,8 +154,7 @@ void _ob_flip(struct __sourceloc __whence, struct overlay_buffer *b)
void _ob_clear(struct __sourceloc __whence, struct overlay_buffer *b)
{
if (config.debug.overlaybuffer)
DEBUGF("ob_flip(b=%p) checkpointLength=0 position=0", b);
DEBUGF(overlaybuffer, "ob_flip(b=%p) checkpointLength=0 position=0", b);
b->checkpointLength = 0;
b->position = 0;
ob_unlimitsize(b);
@ -176,24 +165,21 @@ void _ob_clear(struct __sourceloc __whence, struct overlay_buffer *b)
ssize_t _ob_makespace(struct __sourceloc __whence, struct overlay_buffer *b, size_t bytes)
{
assert(b != NULL);
if (config.debug.overlaybuffer)
DEBUGF("ob_makespace(b=%p, bytes=%zd) b->bytes=%p b->position=%zu b->allocSize=%zu",
b, bytes, b->bytes, b->position, b->allocSize);
DEBUGF(overlaybuffer, "ob_makespace(b=%p, bytes=%zd) b->bytes=%p b->position=%zu b->allocSize=%zu",
b, bytes, b->bytes, b->position, b->allocSize);
assert(b->position <= b->sizeLimit);
assert(b->position <= b->allocSize);
if (b->position)
assert(b->bytes != NULL);
if (b->position + bytes > b->sizeLimit) {
if (config.debug.overlaybuffer)
DEBUGF("ob_makespace(): asked for space to %zu, beyond size limit of %zu", b->position + bytes, b->sizeLimit);
DEBUGF(overlaybuffer, "ob_makespace(): asked for space to %zu, beyond size limit of %zu", b->position + bytes, b->sizeLimit);
return 0;
}
if (b->position + bytes <= b->allocSize)
return 1;
// Don't realloc a static buffer.
if (b->bytes && b->allocated == NULL) {
if (config.debug.overlaybuffer)
DEBUGF("ob_makespace(): asked for space to %zu, beyond static buffer size of %zu", b->position + bytes, b->allocSize);
DEBUGF(overlaybuffer, "ob_makespace(): asked for space to %zu, beyond static buffer size of %zu", b->position + bytes, b->allocSize);
return 0;
}
size_t newSize = b->position + bytes;
@ -203,8 +189,7 @@ ssize_t _ob_makespace(struct __sourceloc __whence, struct overlay_buffer *b, siz
newSize+=1024-(newSize&1023);
if (newSize>65536 && (newSize&65535))
newSize+=65536-(newSize&65535);
if (config.debug.overlaybuffer)
DEBUGF("realloc(b->bytes=%p, newSize=%zu)", b->bytes, newSize);
DEBUGF(overlaybuffer, "realloc(b->bytes=%p, newSize=%zu)", b->bytes, newSize);
/* XXX OSX realloc() seems to be able to corrupt things if the heap is not happy when calling realloc(), making debugging memory corruption much harder.
So will do a three-stage malloc,bcopy,free to see if we can tease bugs out that way. */
/*
@ -254,11 +239,9 @@ void _ob_append_byte(struct __sourceloc __whence, struct overlay_buffer *b, unsi
const int bytes = 1;
if (ob_makespace(b, bytes)) {
b->bytes[b->position] = byte;
if (config.debug.overlaybuffer)
DEBUGF("ob_append_byte(b=%p, byte=0x%02x) %p[%zd]=%02x position=%zu", b, byte, b->bytes, b->position, byte, b->position + bytes);
DEBUGF(overlaybuffer, "ob_append_byte(b=%p, byte=0x%02x) %p[%zd]=%02x position=%zu", b, byte, b->bytes, b->position, byte, b->position + bytes);
} else {
if (config.debug.overlaybuffer)
DEBUGF("ob_append_byte(b=%p, byte=0x%02x) OVERRUN position=%zu", b, byte, b->position + bytes);
DEBUGF(overlaybuffer, "ob_append_byte(b=%p, byte=0x%02x) OVERRUN position=%zu", b, byte, b->position + bytes);
}
b->position += bytes;
}
@ -268,8 +251,7 @@ unsigned char *_ob_append_space(struct __sourceloc __whence, struct overlay_buff
assert(count > 0);
unsigned char *r = ob_makespace(b, count) ? &b->bytes[b->position] : NULL;
b->position += count;
if (config.debug.overlaybuffer)
DEBUGF("ob_append_space(b=%p, count=%zu) position=%zu return %p", b, count, b->position, r);
DEBUGF(overlaybuffer, "ob_append_space(b=%p, count=%zu) position=%zu return %p", b, count, b->position, r);
return r;
}
@ -279,14 +261,12 @@ void _ob_append_bytes(struct __sourceloc __whence, struct overlay_buffer *b, con
unsigned char *r = ob_makespace(b, count) ? &b->bytes[b->position] : NULL;
if (r) {
bcopy(bytes, r, count);
if (config.debug.overlaybuffer)
DEBUGF("ob_append_bytes(b=%p, bytes=%p, count=%zu) position=%zu return %p", b, bytes, count, b->position + count, r);
DEBUGF(overlaybuffer, "ob_append_bytes(b=%p, bytes=%p, count=%zu) position=%zu return %p", b, bytes, count, b->position + count, r);
} else {
if (config.debug.overlaybuffer)
DEBUGF("ob_append_bytes(b=%p, bytes=%p, count=%zu) OVERRUN position=%zu return NULL", b, bytes, count, b->position + count);
DEBUGF(overlaybuffer, "ob_append_bytes(b=%p, bytes=%p, count=%zu) OVERRUN position=%zu return NULL", b, bytes, count, b->position + count);
}
if (config.debug.overlaybuffer)
dump("ob_append_bytes", bytes, count);
if (IF_DEBUG(overlaybuffer))
dump("{overlaybuffer} ob_append_bytes", bytes, count);
b->position += count;
}
@ -301,11 +281,9 @@ void _ob_append_ui16(struct __sourceloc __whence, struct overlay_buffer *b, uint
if (ob_makespace(b, bytes)) {
b->bytes[b->position] = (v >> 8) & 0xFF;
b->bytes[b->position+1] = v & 0xFF;
if (config.debug.overlaybuffer)
DEBUGF("ob_append_ui16(b=%p, v=%u) %p[%zd]=%s position=%zu", b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
DEBUGF(overlaybuffer, "ob_append_ui16(b=%p, v=%u) %p[%zd]=%s position=%zu", b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
} else {
if (config.debug.overlaybuffer)
DEBUGF("ob_append_ui16(b=%p, v=%u) OVERRUN position=%zu", b, v, b->position + bytes);
DEBUGF(overlaybuffer, "ob_append_ui16(b=%p, v=%u) OVERRUN position=%zu", b, v, b->position + bytes);
}
b->position += bytes;
}
@ -316,11 +294,9 @@ void _ob_append_ui16_rv(struct __sourceloc __whence, struct overlay_buffer *b, u
if (ob_makespace(b, bytes)) {
b->bytes[b->position] = v & 0xFF;
b->bytes[b->position+1] = (v >> 8) & 0xFF;
if (config.debug.overlaybuffer)
DEBUGF("ob_append_ui16(b=%p, v=%u) %p[%zd]=%s position=%zu", b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
DEBUGF(overlaybuffer, "ob_append_ui16(b=%p, v=%u) %p[%zd]=%s position=%zu", b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
} else {
if (config.debug.overlaybuffer)
DEBUGF("ob_append_ui16(b=%p, v=%u) OVERRUN position=%zu", b, v, b->position + bytes);
DEBUGF(overlaybuffer, "ob_append_ui16(b=%p, v=%u) OVERRUN position=%zu", b, v, b->position + bytes);
}
b->position += bytes;
}
@ -333,12 +309,10 @@ void _ob_append_ui32(struct __sourceloc __whence, struct overlay_buffer *b, uint
b->bytes[b->position+1] = (v >> 16) & 0xFF;
b->bytes[b->position+2] = (v >> 8) & 0xFF;
b->bytes[b->position+3] = v & 0xFF;
if (config.debug.overlaybuffer)
DEBUGF("ob_append_ui32(b=%p, v=%"PRIu32") %p[%zd]=%s position=%zu",
b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
DEBUGF(overlaybuffer, "ob_append_ui32(b=%p, v=%"PRIu32") %p[%zd]=%s position=%zu",
b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
} else {
if (config.debug.overlaybuffer)
DEBUGF("ob_append_ui32(b=%p, v=%"PRIu32") OVERRUN position=%zu", b, v, b->position + bytes);
DEBUGF(overlaybuffer, "ob_append_ui32(b=%p, v=%"PRIu32") OVERRUN position=%zu", b, v, b->position + bytes);
}
b->position += bytes;
}
@ -351,12 +325,10 @@ void _ob_append_ui32_rv(struct __sourceloc __whence, struct overlay_buffer *b, u
b->bytes[b->position+1] = (v >> 8) & 0xFF;
b->bytes[b->position+2] = (v >> 16) & 0xFF;
b->bytes[b->position+3] = (v >> 24) & 0xFF;
if (config.debug.overlaybuffer)
DEBUGF("ob_append_ui32(b=%p, v=%"PRIu32") %p[%zd]=%s position=%zu",
b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
DEBUGF(overlaybuffer, "ob_append_ui32(b=%p, v=%"PRIu32") %p[%zd]=%s position=%zu",
b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
} else {
if (config.debug.overlaybuffer)
DEBUGF("ob_append_ui32(b=%p, v=%"PRIu32") OVERRUN position=%zu", b, v, b->position + bytes);
DEBUGF(overlaybuffer, "ob_append_ui32(b=%p, v=%"PRIu32") OVERRUN position=%zu", b, v, b->position + bytes);
}
b->position += bytes;
}
@ -373,12 +345,10 @@ void _ob_append_ui64(struct __sourceloc __whence, struct overlay_buffer *b, uint
b->bytes[b->position+5] = (v >> 16) & 0xFF;
b->bytes[b->position+6] = (v >> 8) & 0xFF;
b->bytes[b->position+7] = v & 0xFF;
if (config.debug.overlaybuffer)
DEBUGF("ob_append_ui64(b=%p, v=%"PRIu64") %p[%zd]=%s position=%zu",
b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
DEBUGF(overlaybuffer, "ob_append_ui64(b=%p, v=%"PRIu64") %p[%zd]=%s position=%zu",
b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
} else {
if (config.debug.overlaybuffer)
DEBUGF("ob_append_ui64(b=%p, v=%"PRIu64") OVERRUN position=%zu", b, v, b->position + bytes);
DEBUGF(overlaybuffer, "ob_append_ui64(b=%p, v=%"PRIu64") OVERRUN position=%zu", b, v, b->position + bytes);
}
b->position += bytes;
}
@ -395,12 +365,10 @@ void _ob_append_ui64_rv(struct __sourceloc __whence, struct overlay_buffer *b, u
b->bytes[b->position+5] = (v >> 40) & 0xFF;
b->bytes[b->position+6] = (v >> 48) & 0xFF;
b->bytes[b->position+7] = (v >> 56) & 0xFF;
if (config.debug.overlaybuffer)
DEBUGF("ob_append_ui64(b=%p, v=%"PRIu64") %p[%zd]=%s position=%zu",
b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
DEBUGF(overlaybuffer, "ob_append_ui64(b=%p, v=%"PRIu64") %p[%zd]=%s position=%zu",
b, v, b->bytes, b->position, alloca_tohex(&b->bytes[b->position], bytes), b->position + bytes);
} else {
if (config.debug.overlaybuffer)
DEBUGF("ob_append_ui64(b=%p, v=%"PRIu64") OVERRUN position=%zu", b, v, b->position + bytes);
DEBUGF(overlaybuffer, "ob_append_ui64(b=%p, v=%"PRIu64") OVERRUN position=%zu", b, v, b->position + bytes);
}
b->position += bytes;
}
@ -639,8 +607,7 @@ void _ob_set_ui16(struct __sourceloc __whence, struct overlay_buffer *b, size_t
assert(offset + bytes <= b->allocSize);
b->bytes[offset] = (v >> 8) & 0xFF;
b->bytes[offset+1] = v & 0xFF;
if (config.debug.overlaybuffer)
DEBUGF("ob_set_ui16(b=%p, offset=%zd, v=%u) %p[%zd]=%s", b, offset, v, b->bytes, offset, alloca_tohex(&b->bytes[offset], bytes));
DEBUGF(overlaybuffer, "ob_set_ui16(b=%p, offset=%zd, v=%u) %p[%zd]=%s", b, offset, v, b->bytes, offset, alloca_tohex(&b->bytes[offset], bytes));
}
void _ob_set(struct __sourceloc __whence, struct overlay_buffer *b, size_t offset, unsigned char byte)
@ -650,8 +617,7 @@ void _ob_set(struct __sourceloc __whence, struct overlay_buffer *b, size_t offse
assert(offset + bytes <= b->sizeLimit);
assert(offset + bytes <= b->allocSize);
b->bytes[offset] = byte;
if (config.debug.overlaybuffer)
DEBUGF("ob_set(b=%p, offset=%zd, byte=0x%02x) %p[%zd]=%s", b, offset, byte, b->bytes, offset, alloca_tohex(&b->bytes[offset], bytes));
DEBUGF(overlaybuffer, "ob_set(b=%p, offset=%zd, byte=0x%02x) %p[%zd]=%s", b, offset, byte, b->bytes, offset, alloca_tohex(&b->bytes[offset], bytes));
}
@ -676,8 +642,7 @@ size_t ob_remaining(struct overlay_buffer *b)
int _ob_overrun(struct __sourceloc __whence, struct overlay_buffer *b)
{
int ret = b->position > (b->sizeLimit != SIZE_MAX && b->sizeLimit < b->allocSize ? b->sizeLimit : b->allocSize);
if (config.debug.overlaybuffer)
DEBUGF("ob_overrun(b=%p) return %d", b, ret);
DEBUGF(overlaybuffer, "ob_overrun(b=%p) return %d", b, ret);
return ret;
}
@ -700,8 +665,8 @@ int asprintable(int c)
int ob_dump(struct overlay_buffer *b, char *desc)
{
DEBUGF("overlay_buffer '%s' at %p (%p) : checkpoint=%zu, position=%zu, limit=%zu, size=%zu",
desc, b, b->bytes, b->checkpointLength, b->position, b->sizeLimit, b->allocSize);
_DEBUGF("overlay_buffer '%s' at %p (%p) : checkpoint=%zu, position=%zu, limit=%zu, size=%zu",
desc, b, b->bytes, b->checkpointLength, b->position, b->sizeLimit, b->allocSize);
if (b->bytes) {
if (b->sizeLimit != SIZE_MAX && b->sizeLimit > 0) {
assert(b->position <= b->sizeLimit);

View File

@ -234,33 +234,30 @@ overlay_interface * overlay_interface_find(struct in_addr addr, int return_defau
if (overlay_interfaces[i].address.addr.sa_family == AF_INET
&& (overlay_interfaces[i].netmask.s_addr & addr.s_addr) == (overlay_interfaces[i].netmask.s_addr & overlay_interfaces[i].address.inet.sin_addr.s_addr)){
if (config.debug.overlayinterfaces) {
DEBUGF("Found interface #%d for in_addr=0x%08x, interface mask=0x%08x, interface addr=0x%08x\n",
i,
addr.s_addr,
overlay_interfaces[i].netmask.s_addr,
overlay_interfaces[i].address.inet.sin_addr.s_addr);
}
DEBUGF(overlayinterfaces, "Found interface #%d for in_addr=0x%08x, interface mask=0x%08x, interface addr=0x%08x\n",
i,
addr.s_addr,
overlay_interfaces[i].netmask.s_addr,
overlay_interfaces[i].address.inet.sin_addr.s_addr
);
return &overlay_interfaces[i];
} else {
if (config.debug.overlayinterfaces) {
DEBUGF("in_addr=0x%08x is not from interface #%d (interface mask=0x%08x, interface addr=0x%08x)\n",
addr.s_addr,i,
overlay_interfaces[i].netmask.s_addr,
overlay_interfaces[i].address.inet.sin_addr.s_addr);
}
DEBUGF(overlayinterfaces, "in_addr=0x%08x is not from interface #%d (interface mask=0x%08x, interface addr=0x%08x)\n",
addr.s_addr,i,
overlay_interfaces[i].netmask.s_addr,
overlay_interfaces[i].address.inet.sin_addr.s_addr
);
}
// check if this is a default interface
if (return_default && overlay_interfaces[i].ifconfig.default_route) {
ret=&overlay_interfaces[i];
if (config.debug.overlayinterfaces) {
DEBUGF("in_addr=0x%08x is being deemed to default-route interface #%d (interface mask=0x%08x, interface addr=0x%08x)\n",
addr.s_addr,i,
overlay_interfaces[i].netmask.s_addr,
overlay_interfaces[i].address.inet.sin_addr.s_addr);
}
DEBUGF(overlayinterfaces, "in_addr=0x%08x is being deemed to default-route interface #%d (interface mask=0x%08x, interface addr=0x%08x)\n",
addr.s_addr,i,
overlay_interfaces[i].netmask.s_addr,
overlay_interfaces[i].address.inet.sin_addr.s_addr
);
}
}
@ -354,8 +351,7 @@ overlay_interface_read_any(struct sched_ent *alarm)
/* Drop the packet if we don't find a match */
if (!interface){
if (config.debug.overlayinterfaces)
DEBUGF("Could not find matching interface for packet received from %s", inet_ntoa(recvaddr.inet.sin_addr));
DEBUGF(overlayinterfaces, "Could not find matching interface for packet received from %s", inet_ntoa(recvaddr.inet.sin_addr));
return;
}
packetOkOverlay(interface, packet, plen, &recvaddr);
@ -448,8 +444,7 @@ overlay_interface_init_socket(overlay_interface *interface)
return WHYF("Failed to bind interface %s", interface->name);
}
if (config.debug.packetrx || config.debug.io)
DEBUGF("Bound to %s", alloca_socket_address(&interface->address));
DEBUGF2(packetrx, io, "Bound to %s", alloca_socket_address(&interface->address));
interface->alarm.poll.events=POLLIN;
watch(&interface->alarm);
@ -751,21 +746,19 @@ static void interface_read_file(struct overlay_interface *interface)
}
if (nread == sizeof packet) {
if (config.debug.overlayinterfaces)
DEBUGF("Read from interface %s (filesize=%"PRId64") at offset=%"PRId64": src_addr=%s dst_addr=%s pid=%d length=%d",
interface->name, (int64_t)length, (int64_t)interface->recv_offset,
alloca_socket_address(&packet.src_addr),
alloca_socket_address(&packet.dst_addr),
packet.pid,
packet.payload_length
DEBUGF(overlayinterfaces, "Read from interface %s (filesize=%"PRId64") at offset=%"PRId64": src_addr=%s dst_addr=%s pid=%d length=%d",
interface->name, (int64_t)length, (int64_t)interface->recv_offset,
alloca_socket_address(&packet.src_addr),
alloca_socket_address(&packet.dst_addr),
packet.pid,
packet.payload_length
);
interface->recv_offset += nread;
if (should_drop(interface, &packet.dst_addr) || (packet.pid == getpid() && !interface->local_echo)){
if (config.debug.packetrx)
DEBUGF("Ignoring packet from pid=%d src_addr=%s dst_addr=%s",
packet.pid,
alloca_socket_address(&packet.src_addr),
alloca_socket_address(&packet.dst_addr)
DEBUGF(overlayinterfaces, "Ignoring packet from pid=%d src_addr=%s dst_addr=%s",
packet.pid,
alloca_socket_address(&packet.src_addr),
alloca_socket_address(&packet.dst_addr)
);
}else{
packetOkOverlay(interface, packet.payload, packet.payload_length, &packet.src_addr);
@ -946,8 +939,8 @@ int overlay_broadcast_ensemble(struct network_destination *destination, struct o
struct overlay_interface *interface = destination->interface;
destination->last_tx = gettime_ms();
if (config.debug.packettx){
DEBUGF("Sending this packet via interface %s (len=%zu)",interface->name, len);
if (IF_DEBUG(packettx)) {
DEBUGF(packettx, "Sending this packet via interface %s (len=%zu)",interface->name, len);
DEBUG_packet_visualise(NULL, bytes, len);
}
@ -956,10 +949,11 @@ int overlay_broadcast_ensemble(struct network_destination *destination, struct o
return WHYF("Cannot send to interface %s as it is down", interface->name);
}
if (config.debug.overlayinterfaces || interface->ifconfig.debug)
DEBUGF("Sending %zu byte overlay frame on %s to %s [%s]",
(size_t)len, interface->name, alloca_socket_address(&destination->address),
alloca_tohex(bytes, len>64?64:len));
if (IF_DEBUG(overlayinterfaces) || interface->ifconfig.debug)
_DEBUGF_TAG("overlayinterfaces", "Sending %zu byte overlay frame on %s to %s [%s]",
(size_t)len, interface->name, alloca_socket_address(&destination->address),
alloca_tohex(bytes, len>64?64:len)
);
interface->tx_count++;
@ -985,14 +979,14 @@ int overlay_broadcast_ensemble(struct network_destination *destination, struct o
/* This lseek() is unneccessary because the dummy file is opened in O_APPEND mode. It's
only purpose is to find out the offset to print in the DEBUG statement. It is vulnerable
to a race condition with other processes appending to the same file. */
if (config.debug.overlayinterfaces) {
if (IF_DEBUG(overlayinterfaces)) {
off_t fsize = lseek(interface->alarm.poll.fd, (off_t) 0, SEEK_END);
if (fsize == -1) {
/* Don't complain if the seek fails because we are writing to a pipe or device that does
not support seeking. */
if (errno != ESPIPE)
return WHY_perror("lseek");
DEBUGF("Write to interface %s at offset unknown: src_addr=%s dst_addr=%s pid=%d length=%d",
DEBUGF(overlayinterfaces, "Write to interface %s at offset unknown: src_addr=%s dst_addr=%s pid=%d length=%d",
interface->name,
alloca_socket_address(&packet.src_addr),
alloca_socket_address(&packet.dst_addr),
@ -1000,7 +994,7 @@ int overlay_broadcast_ensemble(struct network_destination *destination, struct o
packet.payload_length
);
} else
DEBUGF("Write to interface %s at offset=%"PRId64": src_addr=%s dst_addr=%s pid=%d length=%d",
DEBUGF(overlayinterfaces, "Write to interface %s at offset=%"PRId64": src_addr=%s dst_addr=%s pid=%d length=%d",
interface->name, (int64_t)fsize,
alloca_socket_address(&packet.src_addr),
alloca_socket_address(&packet.dst_addr),
@ -1085,13 +1079,11 @@ overlay_interface_register(char *name,
}
}
if (ifconfig == NULL) {
if (config.debug.overlayinterfaces)
DEBUGF("Interface %s does not match any rule", name);
DEBUGF(overlayinterfaces, "Interface %s does not match any rule", name);
return 0;
}
if (ifconfig->exclude) {
if (config.debug.overlayinterfaces)
DEBUGF("Interface %s is explicitly excluded", name);
DEBUGF(overlayinterfaces, "Interface %s is explicitly excluded", name);
return 0;
}
@ -1100,12 +1092,10 @@ overlay_interface_register(char *name,
if (broadcast->addr.sa_family==AF_INET)
broadcast->inet.sin_port = htons(ifconfig->port);
if (config.debug.overlayinterfaces) {
// note, inet_ntop doesn't seem to behave on android
DEBUGF("%s address: %s", name, alloca_socket_address(addr));
DEBUGF("%s netmask: %s", name, alloca_socket_address(netmask));
DEBUGF("%s broadcast address: %s", name, alloca_socket_address(broadcast));
}
// note, inet_ntop doesn't seem to behave on android
DEBUGF(overlayinterfaces, "%s address: %s", name, alloca_socket_address(addr));
DEBUGF(overlayinterfaces, "%s netmask: %s", name, alloca_socket_address(netmask));
DEBUGF(overlayinterfaces, "%s broadcast address: %s", name, alloca_socket_address(broadcast));
struct overlay_interface *interface = overlay_interface_find_name_addr(name, addr);
if (interface){
@ -1118,9 +1108,8 @@ overlay_interface_register(char *name,
/* New interface, so register it */
if (overlay_interface_init(name, addr, netmask, broadcast, ifconfig))
return WHYF("Could not initialise newly seen interface %s", name);
else if (config.debug.overlayinterfaces)
DEBUGF("Registered interface %s", name);
DEBUGF(overlayinterfaces, "Registered interface %s", name);
return 0;
}
@ -1205,8 +1194,8 @@ void overlay_interface_discover(struct sched_ent *alarm)
broadcast.local.sun_path[len--]='\0';
broadcast.addrlen = sizeof addr.local.sun_family + len + 2;
DEBUGF("Attempting to bind local socket w. addr %s, broadcast %s",
alloca_socket_address(&addr), alloca_socket_address(&broadcast));
INFOF("Attempting to bind local socket w. addr %s, broadcast %s",
alloca_socket_address(&addr), alloca_socket_address(&broadcast));
overlay_interface_init(ifconfig->file, &addr, &netmask, &broadcast, ifconfig);
break;
}

View File

@ -48,20 +48,19 @@ int set_reachable(struct subscriber *subscriber,
subscriber->next_hop = next_hop;
// These log messages are for use in tests. Changing them may break test scripts.
if (config.debug.overlayrouting || config.debug.linkstate) {
if (IF_DEBUG(overlayrouting) || IF_DEBUG(linkstate)) {
switch (reachable) {
case REACHABLE_NONE:
DEBUGF("NOT REACHABLE sid=%s", alloca_tohex_sid_t(subscriber->sid));
_DEBUGF("NOT REACHABLE sid=%s", alloca_tohex_sid_t(subscriber->sid));
break;
case REACHABLE_INDIRECT:
DEBUGF("REACHABLE INDIRECTLY sid=%s, via %s",
alloca_tohex_sid_t(subscriber->sid), alloca_tohex_sid_t(next_hop->sid));
_DEBUGF("REACHABLE INDIRECTLY sid=%s, via %s", alloca_tohex_sid_t(subscriber->sid), alloca_tohex_sid_t(next_hop->sid));
break;
case REACHABLE_UNICAST:
DEBUGF("REACHABLE VIA UNICAST sid=%s, on %s ", alloca_tohex_sid_t(subscriber->sid), destination->interface->name);
_DEBUGF("REACHABLE VIA UNICAST sid=%s, on %s ", alloca_tohex_sid_t(subscriber->sid), destination->interface->name);
break;
case REACHABLE_BROADCAST:
DEBUGF("REACHABLE VIA BROADCAST sid=%s, on %s ", alloca_tohex_sid_t(subscriber->sid), destination->interface->name);
_DEBUGF("REACHABLE VIA BROADCAST sid=%s, on %s ", alloca_tohex_sid_t(subscriber->sid), destination->interface->name);
break;
}
}
@ -95,8 +94,7 @@ int resolve_name(const char *name, struct in_addr *addr){
if (addresses->ai_addr->sa_family==AF_INET){
*addr = ((struct sockaddr_in *)addresses->ai_addr)->sin_addr;
if (config.debug.overlayrouting)
DEBUGF("Resolved %s into %s", name, inet_ntoa(*addr));
DEBUGF(overlayrouting, "Resolved %s into %s", name, inet_ntoa(*addr));
}else
ret=WHY("Ignoring non IPv4 address");
@ -137,8 +135,7 @@ int load_subscriber_address(struct subscriber *subscriber)
return 1;
}
}
if (config.debug.overlayrouting)
DEBUGF("Loaded address %s for %s", alloca_socket_address(&addr), alloca_tohex_sid_t(subscriber->sid));
DEBUGF(overlayrouting, "Loaded address %s for %s", alloca_socket_address(&addr), alloca_tohex_sid_t(subscriber->sid));
struct network_destination *destination = create_unicast_destination(&addr, interface);
if (!destination)
return -1;
@ -156,8 +153,7 @@ overlay_mdp_service_probe(struct internal_mdp_header *header, struct overlay_buf
WARN("Probe packets should be returned from remote echo port");
RETURN(-1);
}
if (config.debug.overlayrouting)
DEBUGF("Received probe response from %s", alloca_tohex_sid_t(header->source->sid));
DEBUGF(overlayrouting, "Received probe response from %s", alloca_tohex_sid_t(header->source->sid));
if (header->source->reachable == REACHABLE_SELF)
RETURN(0);
@ -208,11 +204,11 @@ int overlay_send_probe(struct subscriber *peer, struct network_destination *dest
op_free(frame);
return -1;
}
if (config.debug.overlayrouting)
DEBUGF("Queued probe packet on interface %s to %s for %s",
DEBUGF(overlayrouting, "Queued probe packet on interface %s to %s for %s",
destination->interface->name,
alloca_socket_address(&destination->address),
peer?alloca_tohex_sid_t(peer->sid):"ANY");
peer?alloca_tohex_sid_t(peer->sid):"ANY"
);
return 0;
}
@ -226,18 +222,15 @@ static void overlay_append_unicast_address(struct subscriber *subscriber, struct
overlay_address_append(NULL, buff, subscriber);
ob_append_ui32(buff, subscriber->destination->address.inet.sin_addr.s_addr);
ob_append_ui16(buff, subscriber->destination->address.inet.sin_port);
if (config.debug.overlayrouting)
DEBUGF("Added STUN info for %s", alloca_tohex_sid_t(subscriber->sid));
DEBUGF(overlayrouting, "Added STUN info for %s", alloca_tohex_sid_t(subscriber->sid));
}else{
if (config.debug.overlayrouting)
DEBUGF("Unable to give address of %s, %d", alloca_tohex_sid_t(subscriber->sid),subscriber->reachable);
DEBUGF(overlayrouting, "Unable to give address of %s, %d", alloca_tohex_sid_t(subscriber->sid),subscriber->reachable);
}
}
int overlay_mdp_service_stun_req(struct internal_mdp_header *header, struct overlay_buffer *payload)
{
if (config.debug.overlayrouting)
DEBUGF("Processing STUN request from %s", alloca_tohex_sid_t(header->source->sid));
DEBUGF(overlayrouting, "Processing STUN request from %s", alloca_tohex_sid_t(header->source->sid));
struct internal_mdp_header reply;
bzero(&reply, sizeof reply);
@ -254,8 +247,7 @@ int overlay_mdp_service_stun_req(struct internal_mdp_header *header, struct over
if (overlay_address_parse(NULL, payload, &subscriber))
break;
if (!subscriber){
if (config.debug.overlayrouting)
DEBUGF("Unknown subscriber");
DEBUGF(overlayrouting, "Unknown subscriber");
continue;
}
overlay_append_unicast_address(subscriber, replypayload);
@ -266,8 +258,7 @@ int overlay_mdp_service_stun_req(struct internal_mdp_header *header, struct over
ob_rewind(replypayload);
if (ob_position(replypayload)){
if (config.debug.overlayrouting)
DEBUGF("Sending reply");
DEBUGF(overlayrouting, "Sending reply");
ob_flip(replypayload);
overlay_send_frame(&reply, replypayload);
}
@ -277,8 +268,7 @@ int overlay_mdp_service_stun_req(struct internal_mdp_header *header, struct over
int overlay_mdp_service_stun(struct internal_mdp_header *header, struct overlay_buffer *payload)
{
if (config.debug.overlayrouting)
DEBUGF("Processing STUN info from %s", alloca_tohex_sid_t(header->source->sid));
DEBUGF(overlayrouting, "Processing STUN info from %s", alloca_tohex_sid_t(header->source->sid));
while(ob_remaining(payload)>0){
struct subscriber *subscriber=NULL;
@ -352,8 +342,7 @@ int overlay_send_stun_request(struct subscriber *server, struct subscriber *requ
}
ob_flip(payload);
if (config.debug.overlayrouting)
DEBUGF("Sending STUN response to %s for my private addresses", alloca_tohex_sid_t(request->sid));
DEBUGF(overlayrouting, "Sending STUN response to %s for my private addresses", alloca_tohex_sid_t(request->sid));
overlay_send_frame(&header, payload);
ob_free(payload);
}
@ -373,8 +362,7 @@ int overlay_send_stun_request(struct subscriber *server, struct subscriber *requ
overlay_address_append(NULL, payload, request);
if (!ob_overrun(payload)) {
if (config.debug.overlayrouting)
DEBUGF("Sending STUN request to %s", alloca_tohex_sid_t(server->sid));
DEBUGF(overlayrouting, "Sending STUN request to %s", alloca_tohex_sid_t(server->sid));
ob_flip(payload);
overlay_send_frame(&header, payload);

View File

@ -312,8 +312,7 @@ static int overlay_mdp_releasebindings(struct socket_address *client)
static int overlay_mdp_process_bind_request(struct subscriber *subscriber, mdp_port_t port,
int flags, struct socket_address *client)
{
if (config.debug.mdprequests)
DEBUGF("Bind request %s:%"PRImdp_port_t, subscriber ? alloca_tohex_sid_t(subscriber->sid) : "NULL", port);
DEBUGF(mdprequests, "Bind request %s:%"PRImdp_port_t, subscriber ? alloca_tohex_sid_t(subscriber->sid) : "NULL", port);
if (port == 0){
return WHYF("Port %d cannot be bound", port);
@ -595,8 +594,7 @@ static int overlay_saw_mdp_frame(
more prudent path.
*/
if (config.debug.mdprequests)
DEBUGF("Received packet (MDP ports: src=%s*:%"PRImdp_port_t", dst=%"PRImdp_port_t")",
DEBUGF(mdprequests, "Received packet (MDP ports: src=%s*:%"PRImdp_port_t", dst=%"PRImdp_port_t")",
alloca_tohex_sid_t_trunc(header->source->sid, 14),
header->source_port, header->destination_port);
@ -631,8 +629,7 @@ static int overlay_saw_mdp_frame(
if (len < 0)
RETURN(WHY("unsupported MDP packet type"));
struct socket_address *client = &mdp_bindings[match].client;
if (config.debug.mdprequests)
DEBUGF("Forwarding packet to client %s", alloca_socket_address(client));
DEBUGF(mdprequests, "Forwarding packet to client %s", alloca_socket_address(client));
ssize_t r = sendto(mdp_sock.poll.fd, &mdp, len, 0, &client->addr, client->addrlen);
if (r == -1){
WHYF_perror("sendto(fd=%d,len=%zu,addr=%s)", mdp_sock.poll.fd, (size_t)len, alloca_socket_address(client));
@ -662,8 +659,7 @@ static int overlay_saw_mdp_frame(
client_header.ttl=header->ttl;
client_header.flags=header->crypt_flags;
if (config.debug.mdprequests)
DEBUGF("Forwarding packet to client v2 %s", alloca_socket_address(client));
DEBUGF(mdprequests, "Forwarding packet to client v2 %s", alloca_socket_address(client));
size_t len = ob_remaining(payload);
const uint8_t *ptr = ob_get_bytes_ptr(payload, len);
@ -685,12 +681,11 @@ static int overlay_saw_mdp_frame(
int overlay_mdp_dnalookup_reply(struct subscriber *dest, mdp_port_t dest_port,
struct subscriber *resolved_sid, const char *uri, const char *did, const char *name)
{
if (config.debug.mdprequests)
DEBUGF("MDP_PORT_DNALOOKUP resolved_sid=%s uri=%s did=%s name=%s",
alloca_tohex_sid_t(resolved_sid->sid),
alloca_str_toprint(uri),
alloca_str_toprint(did),
alloca_str_toprint(name)
DEBUGF(mdprequests, "MDP_PORT_DNALOOKUP resolved_sid=%s uri=%s did=%s name=%s",
alloca_tohex_sid_t(resolved_sid->sid),
alloca_str_toprint(uri),
alloca_str_toprint(did),
alloca_str_toprint(name)
);
struct internal_mdp_header header;
@ -835,8 +830,8 @@ static struct overlay_buffer * encrypt_payload(
}
#if 0
if (config.debug.crypto) {
DEBUG("authcrypted mdp frame");
if (IF_DEBUG(crypto)) {
DEBUG(crypto, "authcrypted mdp frame");
dump("nm",k,crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES);
dump("plain text",plain,sizeof(plain));
dump("nonce",nonce,nb);
@ -850,7 +845,7 @@ static struct overlay_buffer * encrypt_payload(
bcopy(&cipher_text[cz],&cipher_text[0],cipher_len-cz);
ret->position-=cz;
#if 0
if (config.debug.crypto)
if (IF_DEBUG(crypto))
dump("frame", &ret->bytes[0], ret->position);
#endif
@ -867,8 +862,7 @@ int _overlay_send_frame(struct __sourceloc whence, struct internal_mdp_header *h
ob_rewind(payload);
if (header->destination) {
/* Is local, and is not broadcast, so shouldn't get sent out on the wire. */
if (config.debug.mdprequests)
DEBUGF("Local packet, not transmitting");
DEBUGF(mdprequests, "Local packet, not transmitting");
return 0;
}
}
@ -887,10 +881,9 @@ int _overlay_send_frame(struct __sourceloc whence, struct internal_mdp_header *h
if (!header->source)
return WHYF("No source specified");
if (config.debug.mdprequests)
DEBUGF("Attempting to queue mdp packet from %s:%d to %s:%d",
alloca_tohex_sid_t(header->source->sid), header->source_port,
header->destination?alloca_tohex_sid_t(header->destination->sid):"broadcast", header->destination_port);
DEBUGF(mdprequests, "Attempting to queue mdp packet from %s:%d to %s:%d",
alloca_tohex_sid_t(header->source->sid), header->source_port,
header->destination?alloca_tohex_sid_t(header->destination->sid):"broadcast", header->destination_port);
/* Prepare the overlay frame for dispatch */
struct overlay_frame *frame = emalloc_zero(sizeof(struct overlay_frame));
@ -924,18 +917,15 @@ int _overlay_send_frame(struct __sourceloc whence, struct internal_mdp_header *h
}
if (ob_overrun(plaintext)) {
if (config.debug.mdprequests)
DEBUGF("Frame overrun: position=%zu allocSize=%zu sizeLimit=%zu",
plaintext->position, plaintext->allocSize, plaintext->sizeLimit);
DEBUGF(mdprequests, "Frame overrun: position=%zu allocSize=%zu sizeLimit=%zu",
plaintext->position, plaintext->allocSize, plaintext->sizeLimit);
op_free(frame);
ob_free(plaintext);
return -1;
}
if (config.debug.mdprequests) {
DEBUGF("Send frame %zu bytes", ob_position(plaintext));
if (config.debug.verbose)
dump("Frame plaintext", ob_ptr(plaintext), ob_position(plaintext));
}
DEBUGF(mdprequests, "Send frame %zu bytes", ob_position(plaintext));
if (IF_DEBUG(mdprequests) && IF_DEBUG(verbose))
dump("Frame plaintext", ob_ptr(plaintext), ob_position(plaintext));
/* Work out the disposition of the frame-> For now we are only worried
about the crypto matters, and not compression that may be applied
@ -957,7 +947,7 @@ int _overlay_send_frame(struct __sourceloc whence, struct internal_mdp_header *h
return -1;
}
#if 0
if (config.debug.crypto)
if (IF_DEBUG(crypto))
dump("Frame signed ciphertext", ob_ptr(frame->payload), ob_position(frame->payload));
#endif
break;
@ -972,7 +962,7 @@ int _overlay_send_frame(struct __sourceloc whence, struct internal_mdp_header *h
return -1;
}
#if 0
if (config.debug.crypto)
if (IF_DEBUG(crypto))
dump("Frame signed plaintext", ob_ptr(frame->payload), ob_position(frame->payload));
#endif
break;
@ -1008,16 +998,13 @@ int _overlay_send_frame(struct __sourceloc whence, struct internal_mdp_header *h
static int overlay_mdp_dispatch(overlay_mdp_frame *mdp, struct socket_address *client)
{
IN();
unsigned __d = 0;
if (config.debug.mdprequests) {
__d = fd_depth();
DEBUGF("[%u] src=%s*:%"PRImdp_port_t", dst=%s*:%"PRImdp_port_t", recv=%s",
unsigned __d = IF_DEBUG(mdprequests) ? fd_depth() : 0;
DEBUGF(mdprequests, "[%u] src=%s*:%"PRImdp_port_t", dst=%s*:%"PRImdp_port_t", recv=%s",
__d,
alloca_tohex_sid_t_trunc(mdp->out.src.sid, 14), mdp->out.src.port,
alloca_tohex_sid_t_trunc(mdp->out.dst.sid, 14), mdp->out.dst.port,
client ? alloca_socket_address(client) : "NULL"
);
}
if (mdp->out.payload_length > sizeof(mdp->out.payload))
FATAL("Payload length is past the end of the buffer");
@ -1059,8 +1046,7 @@ static int overlay_mdp_dispatch(overlay_mdp_frame *mdp, struct socket_address *c
/* Work out if destination is broadcast or not */
if (is_sid_t_broadcast(mdp->out.dst.sid)){
if (config.debug.mdprequests)
DEBUGF("[%u] Broadcast packet", __d);
DEBUGF(mdprequests, "[%u] Broadcast packet", __d);
/* broadcast packets cannot be encrypted, so complain if MDP_NOCRYPT
flag is not set. Also, MDP_NOSIGN must also be applied, until
NaCl cryptobox keys can be used for signing. */
@ -1077,8 +1063,7 @@ static int overlay_mdp_dispatch(overlay_mdp_frame *mdp, struct socket_address *c
RETURN(overlay_mdp_reply_error(mdp_sock.poll.fd, client, 9, "TTL out of range"));
}
if (config.debug.mdprequests)
DEBUGF("[%u] destination->sid=%s", __d, header.destination ? alloca_tohex_sid_t(header.destination->sid) : "NULL");
DEBUGF(mdprequests, "[%u] destination->sid=%s", __d, header.destination ? alloca_tohex_sid_t(header.destination->sid) : "NULL");
if (mdp->packetTypeAndFlags&MDP_NOCRYPT)
header.crypt_flags |= MDP_FLAG_NO_CRYPT;
@ -1121,8 +1106,7 @@ static int search_subscribers(struct subscriber *subscriber, void *context){
static int overlay_mdp_address_list(struct overlay_mdp_addrlist *request, struct overlay_mdp_addrlist *response)
{
if (config.debug.mdprequests)
DEBUGF("MDP_GETADDRS first_sid=%u mode=%d", request->first_sid, request->mode);
DEBUGF(mdprequests, "MDP_GETADDRS first_sid=%u mode=%d", request->first_sid, request->mode);
/* Prepare reply packet */
response->mode = request->mode;
@ -1134,13 +1118,12 @@ static int overlay_mdp_address_list(struct overlay_mdp_addrlist *request, struct
response->last_sid = response->first_sid + response->frame_sid_count - 1;
if (config.debug.mdprequests)
DEBUGF("reply MDP_ADDRLIST first_sid=%u last_sid=%u frame_sid_count=%u server_sid_count=%u",
response->first_sid,
response->last_sid,
response->frame_sid_count,
response->server_sid_count
);
DEBUGF(mdprequests, "reply MDP_ADDRLIST first_sid=%u last_sid=%u frame_sid_count=%u server_sid_count=%u",
response->first_sid,
response->last_sid,
response->frame_sid_count,
response->server_sid_count
);
return 0;
}
@ -1211,7 +1194,7 @@ static void overlay_mdp_scan(struct sched_ent *alarm)
time_ms_t now = gettime_ms();
RESCHEDULE(alarm, now+500, now+500, TIME_MS_NEVER_WILL);
}else{
DEBUG("Scan completed");
DEBUG(mdprequests, "Scan completed");
state->interface=NULL;
state->current=0;
state->last=0;
@ -1320,18 +1303,15 @@ static int mdp_search_identities(struct socket_address *client, struct mdp_heade
while(1){
if (value_len){
if (config.debug.mdprequests)
DEBUGF("Looking for next %s tag & value", tag);
DEBUGF(mdprequests, "Looking for next %s tag & value", tag);
if (!keyring_find_public_tag_value(&it, tag, value, value_len))
break;
}else if(tag){
if (config.debug.mdprequests)
DEBUGF("Looking for next %s tag", tag);
DEBUGF(mdprequests, "Looking for next %s tag", tag);
if (!keyring_find_public_tag(&it, tag, NULL, NULL))
break;
}else{
if (config.debug.mdprequests)
DEBUGF("Looking for next identity");
DEBUGF(mdprequests, "Looking for next identity");
if (!keyring_next_identity(&it))
break;
}
@ -1464,11 +1444,10 @@ static void mdp_process_packet(struct socket_address *client, struct mdp_header
for(i=0;i<MDP_MAX_BINDINGS;i++) {
if (mdp_bindings[i].port!=0
&& cmp_sockaddr(&mdp_bindings[i].client, client)==0){
if (config.debug.mdprequests)
DEBUGF("Unbind MDP %s:%d from %s",
mdp_bindings[i].subscriber?alloca_tohex_sid_t(mdp_bindings[i].subscriber->sid):"All",
mdp_bindings[i].port,
alloca_socket_address(client));
DEBUGF(mdprequests, "Unbind MDP %s:%d from %s",
mdp_bindings[i].subscriber?alloca_tohex_sid_t(mdp_bindings[i].subscriber->sid):"All",
mdp_bindings[i].port,
alloca_socket_address(client));
mdp_bindings[i].port=0;
}
}
@ -1548,11 +1527,10 @@ static void mdp_process_packet(struct socket_address *client, struct mdp_header
return;
}
if (config.debug.mdprequests)
DEBUGF("Bind MDP %s:%d to %s",
alloca_tohex_sid_t(header->local.sid),
header->local.port,
alloca_socket_address(client));
DEBUGF(mdprequests, "Bind MDP %s:%d to %s",
alloca_tohex_sid_t(header->local.sid),
header->local.port,
alloca_socket_address(client));
// claim binding
binding = free_slot;
@ -1582,25 +1560,21 @@ static void mdp_process_packet(struct socket_address *client, struct mdp_header
}
break;
case MDP_IDENTITY:
if (config.debug.mdprequests)
DEBUGF("Processing MDP_IDENTITY from %s", alloca_socket_address(client));
DEBUGF(mdprequests, "Processing MDP_IDENTITY from %s", alloca_socket_address(client));
mdp_process_identity_request(client, header, payload);
break;
// seach unlocked identities
case MDP_SEARCH_IDS:
if (config.debug.mdprequests)
DEBUGF("Processing MDP_SEARCH_IDS from %s", alloca_socket_address(client));
DEBUGF(mdprequests, "Processing MDP_SEARCH_IDS from %s", alloca_socket_address(client));
mdp_search_identities(client, header, payload);
break;
case MDP_SYNC_CONFIG:
if (config.debug.mdprequests)
DEBUGF("Processing MDP_SYNC_CONFIG from %s", alloca_socket_address(client));
DEBUGF(mdprequests, "Processing MDP_SYNC_CONFIG from %s", alloca_socket_address(client));
server_config_reload(NULL);
mdp_reply_ok(client, header);
break;
case MDP_INTERFACE:
if (config.debug.mdprequests)
DEBUGF("Processing MDP_INTERFACE from %s", alloca_socket_address(client));
DEBUGF(mdprequests, "Processing MDP_INTERFACE from %s", alloca_socket_address(client));
mdp_interface_packet(client, header, payload);
break;
default:
@ -1642,11 +1616,10 @@ static void mdp_process_packet(struct socket_address *client, struct mdp_header
&& !binding->internal
&& header->flags & MDP_FLAG_CLOSE
&& cmp_sockaddr(&binding->client, client)==0){
if (config.debug.mdprequests)
DEBUGF("Unbind MDP %s:%d from %s",
binding->subscriber?alloca_tohex_sid_t(binding->subscriber->sid):"All",
binding->port,
alloca_socket_address(client));
DEBUGF(mdprequests, "Unbind MDP %s:%d from %s",
binding->subscriber?alloca_tohex_sid_t(binding->subscriber->sid):"All",
binding->port,
alloca_socket_address(client));
binding->port=0;
binding=NULL;
}
@ -1767,14 +1740,12 @@ static void overlay_mdp_poll(struct sched_ent *alarm)
switch (mdp_type) {
case MDP_GOODBYE:
if (config.debug.mdprequests)
DEBUGF("MDP_GOODBYE from %s", alloca_socket_address(&client));
DEBUGF(mdprequests, "MDP_GOODBYE from %s", alloca_socket_address(&client));
overlay_mdp_releasebindings(&client);
return;
case MDP_ROUTING_TABLE:
if (config.debug.mdprequests)
DEBUGF("MDP_ROUTING_TABLE from %s", alloca_socket_address(&client));
DEBUGF(mdprequests, "MDP_ROUTING_TABLE from %s", alloca_socket_address(&client));
{
struct routing_state state={
.client = &client,
@ -1786,8 +1757,7 @@ static void overlay_mdp_poll(struct sched_ent *alarm)
return;
case MDP_GETADDRS:
if (config.debug.mdprequests)
DEBUGF("MDP_GETADDRS from %s", alloca_socket_address(&client));
DEBUGF(mdprequests, "MDP_GETADDRS from %s", alloca_socket_address(&client));
{
overlay_mdp_frame mdpreply;
bzero(&mdpreply, sizeof(overlay_mdp_frame));
@ -1803,8 +1773,7 @@ static void overlay_mdp_poll(struct sched_ent *alarm)
break;
case MDP_TX: /* Send payload (and don't treat it as system privileged) */
if (config.debug.mdprequests)
DEBUGF("MDP_TX from %s", alloca_socket_address(&client));
DEBUGF(mdprequests, "MDP_TX from %s", alloca_socket_address(&client));
// Dont allow mdp clients to send very high priority payloads
if (mdp->out.queue<=OQ_MESH_MANAGEMENT)
@ -1814,8 +1783,7 @@ static void overlay_mdp_poll(struct sched_ent *alarm)
break;
case MDP_BIND: /* Bind to port */
if (config.debug.mdprequests)
DEBUGF("MDP_BIND from %s", alloca_socket_address(&client));
DEBUGF(mdprequests, "MDP_BIND from %s", alloca_socket_address(&client));
{
struct subscriber *subscriber=NULL;
/* Make sure source address is either all zeros (listen on all), or a valid
@ -1842,8 +1810,7 @@ static void overlay_mdp_poll(struct sched_ent *alarm)
break;
case MDP_SCAN:
if (config.debug.mdprequests)
DEBUGF("MDP_SCAN from %s", alloca_socket_address(&client));
DEBUGF(mdprequests, "MDP_SCAN from %s", alloca_socket_address(&client));
{
struct overlay_mdp_scan *scan = (struct overlay_mdp_scan *)&mdp->raw;
time_ms_t start=gettime_ms();

View File

@ -40,8 +40,7 @@ int rhizome_mdp_send_block(struct subscriber *dest, const rhizome_bid_t *bid, ui
if (blockLength<=0 || blockLength>1024)
RETURN(WHYF("Invalid block length %d", blockLength));
if (config.debug.rhizome_tx)
DEBUGF("Requested blocks for bid=%s, ver=%"PRIu64" @%"PRIx64" bitmap %x", alloca_tohex_rhizome_bid_t(*bid), version, fileOffset, bitmap);
DEBUGF(rhizome_tx, "Requested blocks for bid=%s, ver=%"PRIu64" @%"PRIx64" bitmap %x", alloca_tohex_rhizome_bid_t(*bid), version, fileOffset, bitmap);
struct internal_mdp_header header;
bzero(&header, sizeof header);
@ -134,8 +133,7 @@ int overlay_mdp_service_rhizomeresponse(struct internal_mdp_header *UNUSED(heade
int type=ob_get(payload);
if (config.debug.rhizome_mdp_rx)
DEBUGF("Received Rhizome over MDP block, type=%02x",type);
DEBUGF(rhizome_mdp_rx, "Received Rhizome over MDP block, type=%02x",type);
switch (type) {
case 'B': /* data block */
@ -149,9 +147,8 @@ int overlay_mdp_service_rhizomeresponse(struct internal_mdp_header *UNUSED(heade
size_t count = ob_remaining(payload);
unsigned char *bytes=ob_current_ptr(payload);
if (config.debug.rhizome_mdp_rx)
DEBUGF("bidprefix=%02x%02x%02x%02x*, offset=%"PRId64", count=%zu",
bidprefix[0],bidprefix[1],bidprefix[2],bidprefix[3],offset,count);
DEBUGF(rhizome_mdp_rx, "bidprefix=%02x%02x%02x%02x*, offset=%"PRId64", count=%zu",
bidprefix[0],bidprefix[1],bidprefix[2],bidprefix[3],offset,count);
/* Now see if there is a slot that matches. If so, then
see if the bytes are in the window, and write them.
@ -188,8 +185,7 @@ int overlay_mdp_service_dnalookup(struct internal_mdp_header *header, struct ove
ob_get_bytes(payload, (unsigned char *)did, pll);
did[pll]=0;
if (config.debug.mdprequests)
DEBUG("MDP_PORT_DNALOOKUP");
DEBUG(mdprequests, "MDP_PORT_DNALOOKUP");
int results=0;
while(keyring_find_did(&it, did))

View File

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

View File

@ -100,8 +100,8 @@ int process_incoming_frame(time_ms_t now, struct overlay_interface *UNUSED(inter
process_explain(f);
break;
default:
if (config.debug.verbose && config.debug.overlayframes)
DEBUGF("Overlay type f->type=0x%x not supported", f->type);
if (IF_DEBUG(verbose))
DEBUGF(overlayframes, "Overlay type f->type=0x%x not supported", f->type);
}
RETURN(0);
OUT();
@ -111,13 +111,13 @@ int process_incoming_frame(time_ms_t now, struct overlay_interface *UNUSED(inter
int overlay_forward_payload(struct overlay_frame *f){
IN();
if (f->ttl == 0){
if (config.debug.verbose && config.debug.overlayframes)
DEBUGF("NOT FORWARDING, due to ttl=0");
if (IF_DEBUG(verbose))
DEBUGF(overlayframes, "NOT FORWARDING, due to ttl=0");
RETURN(0);
}
if (config.debug.verbose && config.debug.overlayframes)
DEBUGF("Forwarding payload for %s, ttl=%u",
if (IF_DEBUG(verbose))
DEBUGF(overlayframes, "Forwarding payload for %s, ttl=%u",
(f->destination?alloca_tohex_sid_t(f->destination->sid):"broadcast"),
(unsigned)f->ttl);
@ -164,8 +164,8 @@ int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *f
RETURN(WHY("Unable to parse payload source"));
if (!frame->source || frame->source->reachable==REACHABLE_SELF){
process=forward=0;
if (config.debug.verbose && config.debug.overlayframes)
DEBUGF("Ignoring my packet (or unparsable source)");
if (IF_DEBUG(verbose))
DEBUGF(overlayframes, "Ignoring my packet (or unparsable source)");
}
}
@ -175,13 +175,13 @@ int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *f
RETURN(WHY("Unable to read broadcast address"));
if (overlay_broadcast_drop_check(&frame->broadcast_id)){
process=forward=0;
if (config.debug.verbose && config.debug.overlayframes)
DEBUGF("Ignoring duplicate broadcast (%s)", alloca_tohex(frame->broadcast_id.id, BROADCAST_LEN));
if (IF_DEBUG(verbose))
DEBUGF(overlayframes, "Ignoring duplicate broadcast (%s)", alloca_tohex(frame->broadcast_id.id, BROADCAST_LEN));
}
if (link_state_should_forward_broadcast(context->sender)==0){
forward=0;
if (config.debug.verbose && config.debug.overlayframes)
DEBUGF("Not forwarding broadcast (%s), as we aren't a relay in the senders routing table", alloca_tohex(frame->broadcast_id.id, BROADCAST_LEN));
if (IF_DEBUG(verbose))
DEBUGF(overlayframes, "Not forwarding broadcast (%s), as we aren't a relay in the senders routing table", alloca_tohex(frame->broadcast_id.id, BROADCAST_LEN));
}
}
frame->destination=NULL;
@ -192,8 +192,8 @@ int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *f
if (!frame->destination || frame->destination->reachable!=REACHABLE_SELF){
process=0;
if (config.debug.verbose && config.debug.overlayframes)
DEBUGF("Don't process packet not addressed to me");
if (IF_DEBUG(verbose))
DEBUGF(overlayframes, "Don't process packet not addressed to me");
}
if (!(flags & PAYLOAD_FLAG_ONE_HOP)){
@ -203,8 +203,8 @@ int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *f
if (!(*nexthop) || (*nexthop)->reachable!=REACHABLE_SELF){
forward=0;
if (config.debug.verbose && config.debug.overlayframes)
DEBUGF("Don't forward packet not addressed to me");
if (IF_DEBUG(verbose))
DEBUGF(overlayframes, "Don't forward packet not addressed to me");
}
}
}
@ -222,8 +222,8 @@ int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *f
--frame->ttl;
if (frame->ttl == 0) {
forward = 0;
if (config.debug.verbose && config.debug.overlayframes)
DEBUGF("NOT FORWARDING, due to ttl=0");
if (IF_DEBUG(verbose))
DEBUGF(overlayframes, "NOT FORWARDING, due to ttl=0");
}
if (flags & PAYLOAD_FLAG_LEGACY_TYPE){
@ -239,8 +239,8 @@ int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *f
if (seq == -1)
RETURN(WHY("Unable to read packet seq"));
if (link_received_duplicate(context->sender, seq)){
if (config.debug.verbose && config.debug.overlayframes)
DEBUG("Don't process or forward duplicate payloads");
if (IF_DEBUG(verbose))
DEBUG(overlayframes, "Don't process or forward duplicate payloads");
forward=process=0;
}
}
@ -249,8 +249,8 @@ int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *f
// if we can't understand one of the addresses, skip processing the payload
if ((forward||process)&&context->invalid_addresses){
if (config.debug.verbose && config.debug.overlayframes)
DEBUG("Don't process or forward with invalid addresses");
if (IF_DEBUG(verbose))
DEBUG(overlayframes, "Don't process or forward with invalid addresses");
forward=process=0;
}
RETURN(forward|process);
@ -294,8 +294,8 @@ int parseEnvelopeHeader(struct decode_context *context, struct overlay_interface
if (context->sender){
if (context->sender->reachable==REACHABLE_SELF){
if (config.debug.verbose && config.debug.overlayframes)
DEBUG("Completely ignore packets I sent");
if (IF_DEBUG(verbose))
DEBUG(overlayframes, "Completely ignore packets I sent");
RETURN(1);
}
@ -307,8 +307,7 @@ int parseEnvelopeHeader(struct decode_context *context, struct overlay_interface
context->point_to_point_device = context->interface->other_device = context->sender;
}
if (config.debug.overlayframes)
DEBUGF("Received %s packet seq %d from %s on %s %s",
DEBUGF(overlayframes, "Received %s packet seq %d from %s on %s %s",
packet_flags & PACKET_UNICAST?"unicast":"broadcast",
sender_seq, alloca_tohex_sid_t(context->sender->sid),
interface->name, alloca_socket_address(addr));
@ -375,8 +374,8 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s
the source having received the frame from elsewhere.
*/
if (config.debug.packetrx || interface->ifconfig.debug) {
DEBUGF("Received on %s, len %d", interface->name, (int)len);
if (IF_DEBUG(packetrx) || interface->ifconfig.debug) {
_DEBUGF("Received on %s, len %d", interface->name, (int)len);
DEBUG_packet_visualise("Received packet",packet,len);
}
@ -423,8 +422,7 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s
payload_len = ob_get_ui16(b);
if (payload_len > ob_remaining(b)){
unsigned char *current = ob_ptr(b)+ob_position(b);
if (config.debug.overlayframes)
if (IF_DEBUG(overlayframes))
dump("Payload Header", header_start, current - header_start);
ret = WHYF("Invalid payload length (%zd)", payload_len);
goto end;
@ -434,14 +432,14 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s
int next_payload = ob_position(b) + payload_len;
if (config.debug.overlayframes){
DEBUGF("Received payload type %x, len %zd", f.type, payload_len);
DEBUGF("Payload from %s", f.source?alloca_tohex_sid_t(f.source->sid):"NULL");
DEBUGF("Payload to %s", (f.destination?alloca_tohex_sid_t(f.destination->sid):"broadcast"));
if (IF_DEBUG(overlayframes)) {
DEBUGF(overlayframes, "Received payload type %x, len %zd", f.type, payload_len);
DEBUGF(overlayframes, "Payload from %s", f.source?alloca_tohex_sid_t(f.source->sid):"NULL");
DEBUGF(overlayframes, "Payload to %s", (f.destination?alloca_tohex_sid_t(f.destination->sid):"broadcast"));
if (!is_all_matching(f.broadcast_id.id, BROADCAST_LEN, 0))
DEBUGF("Broadcast id %s", alloca_tohex(f.broadcast_id.id, BROADCAST_LEN));
DEBUGF(overlayframes, "Broadcast id %s", alloca_tohex(f.broadcast_id.id, BROADCAST_LEN));
if (nexthop)
DEBUGF("Next hop %s", alloca_tohex_sid_t(nexthop->sid));
DEBUGF(overlayframes, "Next hop %s", alloca_tohex_sid_t(nexthop->sid));
}
if (header_valid!=0){

View File

@ -90,11 +90,11 @@ int overlay_packetradio_setup_port(overlay_interface *interface)
if (tcsetattr(interface->alarm.poll.fd, TCSANOW, &t))
WHY_perror("Failed to set terminal parameters");
if (config.debug.packetradio) {
if (IF_DEBUG(packetradio)) {
tcgetattr(interface->alarm.poll.fd, &t);
int in_speed=cfgetispeed(&t);
int out_speed=cfgetospeed(&t);
DEBUGF("uart speed reported as %d/%d",in_speed,out_speed);
DEBUGF(packetradio, "uart speed reported as %d/%d",in_speed,out_speed);
}
set_nonblock(interface->alarm.poll.fd);

View File

@ -132,7 +132,7 @@ overlay_queue_dump(overlay_txqueue *q)
}
f=f->prev;
}
DEBUG(strbuf_str(b));
_DEBUG(strbuf_str(b));
return 0;
}
#endif
@ -173,9 +173,9 @@ int _overlay_payload_enqueue(struct __sourceloc __whence, struct overlay_frame *
if (p->packet_version<=0)
p->packet_version=1;
if (config.debug.verbose && config.debug.overlayframes)
DEBUGF("Enqueue packet to %s",
p->destination?alloca_tohex_sid_t_trunc(p->destination->sid, 14): "broadcast");
if (IF_DEBUG(verbose))
DEBUGF(overlayframes, "Enqueue packet to %s",
p->destination?alloca_tohex_sid_t_trunc(p->destination->sid, 14): "broadcast");
if (p->destination_count==0){
if (!p->destination){
@ -186,8 +186,7 @@ int _overlay_payload_enqueue(struct __sourceloc __whence, struct overlay_frame *
// just drop it now
if (p->destination_count == 0){
if (config.debug.mdprequests)
DEBUGF("Not transmitting, as we have nowhere to send it");
DEBUGF(mdprequests, "Not transmitting, as we have nowhere to send it");
// free the packet and return success.
op_free(p);
return 0;
@ -204,10 +203,10 @@ int _overlay_payload_enqueue(struct __sourceloc __whence, struct overlay_frame *
int i=0;
for (i=0;i<p->destination_count;i++){
p->destinations[i].sent_sequence=-1;
if (config.debug.verbose && config.debug.overlayframes)
DEBUGF("Sending %s on interface %s",
p->destinations[i].destination->unicast?"unicast":"broadcast",
p->destinations[i].destination->interface->name);
if (IF_DEBUG(verbose))
DEBUGF(overlayframes, "Sending %s on interface %s",
p->destinations[i].destination->unicast?"unicast":"broadcast",
p->destinations[i].destination->interface->name);
}
struct overlay_frame *l=queue->last;
@ -252,11 +251,11 @@ overlay_init_packet(struct outgoing_packet *packet, int packet_version,
return -1;
}
packet->header_length = ob_position(packet->buffer);
if (config.debug.overlayframes)
DEBUGF("Creating %d packet for interface %s, seq %d, %s",
packet_version,
destination->interface->name, destination->sequence_number,
alloca_socket_address(&destination->address));
DEBUGF(overlayframes, "Creating %d packet for interface %s, seq %d, %s",
packet_version,
destination->interface->name, destination->sequence_number,
alloca_socket_address(&destination->address)
);
return 0;
}
@ -278,10 +277,10 @@ int overlay_queue_schedule_next(time_ms_t next_allowed_packet){
}
void frame_remove_destination(struct overlay_frame *frame, int i){
if (config.debug.overlayframes)
DEBUGF("Remove %s destination on interface %s",
frame->destinations[i].destination->unicast?"unicast":"broadcast",
frame->destinations[i].destination->interface->name);
DEBUGF(overlayframes, "Remove %s destination on interface %s",
frame->destinations[i].destination->unicast?"unicast":"broadcast",
frame->destinations[i].destination->interface->name
);
release_destination_ref(frame->destinations[i].destination);
frame->destination_count --;
if (i<frame->destination_count)
@ -295,10 +294,10 @@ void frame_add_destination(struct overlay_frame *frame, struct subscriber *next_
frame->destinations[i].destination=add_destination_ref(dest);
frame->destinations[i].next_hop = next_hop;
frame->destinations[i].sent_sequence=-1;
if (config.debug.overlayframes)
DEBUGF("Add %s destination on interface %s",
frame->destinations[i].destination->unicast?"unicast":"broadcast",
frame->destinations[i].destination->interface->name);
DEBUGF(overlayframes, "Add %s destination on interface %s",
frame->destinations[i].destination->unicast?"unicast":"broadcast",
frame->destinations[i].destination->interface->name
);
}
// update the alarm time and return 1 if changed
@ -354,10 +353,10 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim
// TODO stop when the packet is nearly full?
while(frame){
if (queue->latencyTarget!=0 && frame->enqueued_at + queue->latencyTarget < now){
if (config.debug.overlayframes)
DEBUGF("Dropping frame type %x (length %zu) for %s due to expiry timeout",
frame->type, frame->payload->checkpointLength,
frame->destination?alloca_tohex_sid_t(frame->destination->sid):"All");
DEBUGF(overlayframes, "Dropping frame type %x (length %zu) for %s due to expiry timeout",
frame->type, frame->payload->checkpointLength,
frame->destination?alloca_tohex_sid_t(frame->destination->sid):"All"
);
frame = overlay_queue_remove(queue, frame);
continue;
}
@ -383,9 +382,8 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim
if(frame->mdp_sequence != -1 && ((mdp_sequence - frame->mdp_sequence)&0xFFFF) >= 64){
// too late, we've sent too many packets for the next hop to correctly de-duplicate
if (config.debug.overlayframes)
DEBUGF("Retransmition of frame %p mdp seq %d, is too late to be de-duplicated",
frame, frame->mdp_sequence);
DEBUGF(overlayframes, "Retransmition of frame %p mdp seq %d, is too late to be de-duplicated",
frame, frame->mdp_sequence);
frame = overlay_queue_remove(queue, frame);
continue;
}
@ -500,19 +498,18 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim
dest->transmit_time = now;
if (debug)
strbuf_sprintf(debug, "%d(%s), ", frame->mdp_sequence, frame->whence.function);
if (config.debug.overlayframes)
DEBUGF("Appended payload %p, %d type %x len %zd for %s via %s",
frame, frame->mdp_sequence,
frame->type, ob_position(frame->payload),
frame->destination?alloca_tohex_sid_t(frame->destination->sid):"All",
dest->next_hop?alloca_tohex_sid_t(dest->next_hop->sid):alloca_tohex(frame->broadcast_id.id, BROADCAST_LEN));
DEBUGF(overlayframes, "Appended payload %p, %d type %x len %zd for %s via %s",
frame, frame->mdp_sequence,
frame->type, ob_position(frame->payload),
frame->destination?alloca_tohex_sid_t(frame->destination->sid):"All",
dest->next_hop?alloca_tohex_sid_t(dest->next_hop->sid):alloca_tohex(frame->broadcast_id.id, BROADCAST_LEN)
);
}
// dont retransmit if we aren't sending sequence numbers, or we've been asked not to
if (!will_retransmit){
if (config.debug.overlayframes)
DEBUGF("Not waiting for retransmission (%d, %d, %d)", frame->packet_version, frame->resend, packet->seq);
DEBUGF(overlayframes, "Not waiting for retransmission (%d, %d, %d)", frame->packet_version, frame->resend, packet->seq);
frame_remove_destination(frame, destination_index);
if (frame->destination_count==0){
frame = overlay_queue_remove(queue, frame);
@ -548,7 +545,7 @@ overlay_fill_send_packet(struct outgoing_packet *packet, time_ms_t now, strbuf d
if(packet->buffer){
if (debug){
strbuf_sprintf(debug, "]");
DEBUGF("%s", strbuf_str(debug));
_DEBUGF("%s", strbuf_str(debug));
}
overlay_broadcast_ensemble(packet->destination, packet->buffer);
@ -566,7 +563,7 @@ static void overlay_send_packet(struct sched_ent *UNUSED(alarm))
struct outgoing_packet packet;
bzero(&packet, sizeof(struct outgoing_packet));
packet.seq=-1;
strbuf debug = config.debug.packets_sent?strbuf_alloca(256):NULL;
strbuf debug = IF_DEBUG(packets_sent) ? strbuf_alloca(256) : NULL;
overlay_fill_send_packet(&packet, gettime_ms(), debug);
}
@ -576,7 +573,7 @@ int overlay_send_tick_packet(struct network_destination *destination)
bzero(&packet, sizeof(struct outgoing_packet));
if (overlay_init_packet(&packet, 0, destination) != -1){
strbuf debug = NULL;
if (config.debug.packets_sent){
if (IF_DEBUG(packets_sent)) {
debug = strbuf_alloca(256);
strbuf_sprintf(debug, "building packet %s %s %d [",
packet.destination->interface->name,
@ -618,9 +615,8 @@ int overlay_queue_ack(struct subscriber *neighbour, struct network_destination *
if (!rtt || this_rtt < rtt)
rtt = this_rtt;
if (config.debug.ack)
DEBUGF("DROPPED DUE TO ACK: Packet %p to %s sent by seq %d, acked with seq %d",
frame, alloca_tohex_sid_t(neighbour->sid), frame_seq, ack_seq);
DEBUGF(ack, "DROPPED DUE TO ACK: Packet %p to %s sent by seq %d, acked with seq %d",
frame, alloca_tohex_sid_t(neighbour->sid), frame_seq, ack_seq);
// drop packets that don't need to be retransmitted
if (frame->destination || frame->destination_count<=1){
@ -631,8 +627,7 @@ int overlay_queue_ack(struct subscriber *neighbour, struct network_destination *
}else if (seq_delta < 128 && frame->destination && frame->delay_until>now){
// retransmit asap
if (config.debug.ack)
DEBUGF("RE-TX DUE TO NACK: Requeue packet %p to %s sent by seq %d due to ack of seq %d", frame, alloca_tohex_sid_t(neighbour->sid), frame_seq, ack_seq);
DEBUGF(ack, "RE-TX DUE TO NACK: Requeue packet %p to %s sent by seq %d due to ack of seq %d", frame, alloca_tohex_sid_t(neighbour->sid), frame_seq, ack_seq);
frame->delay_until = now;
overlay_calc_queue_time(frame);
}
@ -649,8 +644,7 @@ int overlay_queue_ack(struct subscriber *neighbour, struct network_destination *
int delay = rtt * 2 + 40;
if (delay < destination->resend_delay){
destination->resend_delay = delay;
if (config.debug.linkstate)
DEBUGF("Adjusting resend delay to %d", destination->resend_delay);
DEBUGF(linkstate, "Adjusting resend delay to %d", destination->resend_delay);
}
}
if (!destination->max_rtt || rtt > destination->max_rtt)

View File

@ -183,7 +183,7 @@ int fd_showstats()
}
// Report any functions that take too much time
if (!config.debug.timing)
if (!IF_DEBUG(timing))
{
stats = stats_head;
while(stats!=NULL){
@ -240,10 +240,8 @@ unsigned fd_depth()
int fd_func_enter(struct __sourceloc __whence, struct call_stats *this_call)
{
if (config.debug.profiling)
DEBUGF("%s called from %s() %s:%d",
__FUNCTION__,__whence.function,__whence.file,__whence.line);
DEBUGF(profiling, "%s called from %s() %s:%d",
__FUNCTION__,__whence.function,__whence.file,__whence.line);
this_call->enter_time=gettime_ms();
this_call->child_time=0;
this_call->prev = current_call;
@ -257,10 +255,8 @@ int fd_func_exit(struct __sourceloc __whence, struct call_stats *this_call)
// probably points to somewhere on the stack (see the IN() macro) that has since been overwritten,
// so no sense in trying to print its contents in a diagnostic message; that would just cause
// a SEGV.
if (config.debug.profiling)
DEBUGF("%s called from %s() %s:%d",
__FUNCTION__,__whence.function,__whence.file,__whence.line);
DEBUGF(profiling, "%s called from %s() %s:%d",
__FUNCTION__,__whence.function,__whence.file,__whence.line);
if (current_call != this_call)
FATAL("performance timing stack trace corrupted");

View File

@ -262,8 +262,7 @@ static int build_heartbeat(struct radio_link_state *link_state)
link_state->txbuffer[15]=0x05;
golay_encode(&link_state->txbuffer[14]);
link_state->tx_bytes = count + RADIO_CRC_LENGTH + RADIO_HEADER_LENGTH;
if (config.debug.radio_link)
DEBUGF("Produced heartbeat");
DEBUGF(radio_link, "Produced heartbeat");
return 0;
}
@ -359,11 +358,10 @@ static int parse_heartbeat(struct radio_link_state *state, const unsigned char *
state->next_tx_allowed = gettime_ms();
if (free_bytes>720)
state->next_heartbeat=gettime_ms()+1000;
if (config.debug.packetradio)
INFOF("Link budget = %+ddB, remote link budget = %+ddB, buffer space = %d%% (approx %d)",
state->radio_rssi,
state->remote_rssi,
free_space, free_bytes);
DEBUGF(packetradio, "Link budget = %+ddB, remote link budget = %+ddB, buffer space = %d%% (approx %d)",
state->radio_rssi,
state->remote_rssi,
free_space, free_bytes);
return 1;
}
return 0;
@ -379,8 +377,7 @@ static int radio_link_parse(struct overlay_interface *interface, struct radio_li
int errs=0;
int tail = golay_decode(&errs, &payload[14]);
if (tail == 0x555){
if (config.debug.radio_link)
DEBUGF("Decoded remote heartbeat request");
DEBUGF(radio_link, "Decoded remote heartbeat request");
return 1;
}
return 0;
@ -390,27 +387,24 @@ static int radio_link_parse(struct overlay_interface *interface, struct radio_li
int errors=decode_rs_8(&payload[4], NULL, 0, FEC_MAX_BYTES - data_bytes);
if (errors==-1){
if (config.debug.radio_link)
DEBUGF("Reed-Solomon error correction failed");
DEBUGF(radio_link, "Reed-Solomon error correction failed");
return 0;
}
*backtrack=errors;
data_bytes -= 2;
int seq=payload[4]&0x3f;
if (config.debug.radio_link){
DEBUGF("Received RS protected message, len: %zd, errors: %d, seq: %d, flags:%s%s",
data_bytes,
errors,
seq,
payload[4]&0x40?" start":"",
payload[4]&0x80?" end":"");
}
DEBUGF(radio_link, "Received RS protected message, len: %zd, errors: %d, seq: %d, flags:%s%s",
data_bytes,
errors,
seq,
payload[4]&0x40?" start":"",
payload[4]&0x80?" end":""
);
if (seq != ((state->seq+1)&0x3f)){
// reject partial packet if we missed a sequence number
if (config.debug.radio_link)
DEBUGF("Rejecting packet, sequence jumped from %d to %d", state->seq, seq);
DEBUGF(radio_link, "Rejecting packet, sequence jumped from %d to %d", state->seq, seq);
state->packet_length=sizeof(state->dst)+1;
}
@ -421,8 +415,7 @@ static int radio_link_parse(struct overlay_interface *interface, struct radio_li
state->seq=payload[4]&0x3f;
if (state->packet_length + data_bytes > sizeof(state->dst)){
if (config.debug.radio_link)
DEBUG("Fragmented packet is too long or a previous piece was missed - discarding");
DEBUG(radio_link, "Fragmented packet is too long or a previous piece was missed - discarding");
state->packet_length=sizeof(state->dst)+1;
return 1;
}
@ -431,8 +424,7 @@ static int radio_link_parse(struct overlay_interface *interface, struct radio_li
state->packet_length+=data_bytes;
if (payload[4]&0x80) {
if (config.debug.radio_link)
DEBUGF("PDU Complete (length=%zd)",state->packet_length);
DEBUGF(radio_link, "PDU Complete (length=%zd)",state->packet_length);
packetOkOverlay(interface, state->dst, state->packet_length, NULL);
state->packet_length=sizeof(state->dst)+1;
@ -453,8 +445,8 @@ static int decode_length(struct radio_link_state *state, unsigned char *p)
if (length!=17 && (length <= FEC_LENGTH || length > LINK_MTU))
return -1;
if (config.debug.radio_link && (errs || state->payload_length!=*p))
DEBUGF("Decoded length %u to %zu with %d errs", *p, length, errs);
if (errs || state->payload_length!=*p)
DEBUGF(radio_link, "Decoded length %u to %zu with %d errs", *p, length, errs);
state->payload_length=length;
return 0;
@ -468,8 +460,7 @@ int radio_link_decode(struct overlay_interface *interface, uint8_t c)
if (state->payload_start + state->payload_offset >= sizeof state->payload){
// drop one byte if we run out of space
if (config.debug.radio_link)
DEBUGF("Dropped %02x, buffer full", state->payload[0]);
DEBUGF(radio_link, "Dropped %02x, buffer full", state->payload[0]);
bcopy(state->payload+1, state->payload, sizeof(state->payload) -1);
state->payload_start--;
}
@ -523,8 +514,8 @@ int radio_link_decode(struct overlay_interface *interface, uint8_t c)
// Since we know we've synced with the remote party,
// and there's nothing we can do about any earlier data
// throw away everything before the end of this packet
if (state->payload_start && config.debug.radio_link)
dump("Skipped", state->payload, state->payload_start);
if (state->payload_start && IF_DEBUG(radio_link))
dump("{radio_link} Skipped", state->payload, state->payload_start);
// If the packet is truncated by less than 16 bytes, RS protection should be enough to recover the packet,
// but we may need to examine the last few bytes to find the start of the next packet.

View File

@ -168,19 +168,18 @@ enum rhizome_add_file_result rhizome_manifest_add_file(int appending,
// because these will be calculated by the journal append logic.
if (appending) {
if (m->version)
DEBUG(cause = "Cannot set 'version' field in journal append");
DEBUG(rhizome, cause = "Cannot set 'version' field in journal append");
else if (m->filesize != RHIZOME_SIZE_UNSET)
DEBUG(cause = "Cannot set 'filesize' field in journal append");
DEBUG(rhizome, cause = "Cannot set 'filesize' field in journal append");
else if (m->has_filehash)
DEBUG(cause = "Cannot set 'filehash' field in journal append");
DEBUG(rhizome, cause = "Cannot set 'filehash' field in journal append");
if (cause) {
result = RHIZOME_ADD_FILE_INVALID_FOR_JOURNAL;
goto error;
}
}
if (bid) {
if (config.debug.rhizome)
DEBUGF("Reading manifest from database: id=%s", alloca_tohex_rhizome_bid_t(*bid));
DEBUGF(rhizome, "Reading manifest from database: id=%s", alloca_tohex_rhizome_bid_t(*bid));
if ((existing_manifest = rhizome_new_manifest()) == NULL) {
WHY(cause = "Manifest struct could not be allocated");
goto error;
@ -260,8 +259,7 @@ enum rhizome_add_file_result rhizome_manifest_add_file(int appending,
status_ok = 1;
break;
case RHIZOME_MANIFEST_SYNTAX_ERROR:
if (config.debug.rhizome)
DEBUGF("Manifest syntax error: %s=%s", label, alloca_toprint(-1, asg->value, asg->valuelen));
DEBUGF(rhizome, "Manifest syntax error: %s=%s", label, alloca_toprint(-1, asg->value, asg->valuelen));
if (reason)
strbuf_sprintf(reason, "Manifest syntax error: %s=%s", label, alloca_toprint(-1, asg->value, asg->valuelen));
result = RHIZOME_ADD_FILE_INVALID;
@ -270,22 +268,19 @@ enum rhizome_add_file_result rhizome_manifest_add_file(int appending,
// We already deleted the field, so if this happens, its a nasty bug
FATALF("Duplicate field should not occur: %s=%s", label, alloca_toprint(-1, asg->value, asg->valuelen));
case RHIZOME_MANIFEST_INVALID:
if (config.debug.rhizome)
DEBUGF("Manifest invalid field: %s=%s", label, alloca_toprint(-1, asg->value, asg->valuelen));
DEBUGF(rhizome, "Manifest invalid field: %s=%s", label, alloca_toprint(-1, asg->value, asg->valuelen));
if (reason)
strbuf_sprintf(reason, "Manifest invalid field: %s=%s", label, alloca_toprint(-1, asg->value, asg->valuelen));
result = RHIZOME_ADD_FILE_INVALID;
goto error;
case RHIZOME_MANIFEST_MALFORMED:
if (config.debug.rhizome)
DEBUGF("Manifest malformed field: %s=%s", label, alloca_toprint(-1, asg->value, asg->valuelen));
DEBUGF(rhizome, "Manifest malformed field: %s=%s", label, alloca_toprint(-1, asg->value, asg->valuelen));
if (reason)
strbuf_sprintf(reason, "Manifest malformed field: %s=%s", label, alloca_toprint(-1, asg->value, asg->valuelen));
result = RHIZOME_ADD_FILE_INVALID;
goto error;
case RHIZOME_MANIFEST_OVERFLOW:
if (config.debug.rhizome)
DEBUGF("Too many fields in manifest at: %s=%s", label, alloca_toprint(-1, asg->value, asg->valuelen));
DEBUGF(rhizome, "Too many fields in manifest at: %s=%s", label, alloca_toprint(-1, asg->value, asg->valuelen));
if (reason)
strbuf_sprintf(reason, "Too many fields in manifest at: %s=%s", label, alloca_toprint(-1, asg->value, asg->valuelen));
result = RHIZOME_ADD_FILE_INVALID;
@ -298,15 +293,13 @@ enum rhizome_add_file_result rhizome_manifest_add_file(int appending,
}
if (appending && !new_manifest->is_journal) {
cause = "Cannot append to a non-journal";
if (config.debug.rhizome)
DEBUG(cause);
DEBUG(rhizome, cause);
result = RHIZOME_ADD_FILE_REQUIRES_JOURNAL;
goto error;
}
if (!appending && new_manifest->is_journal) {
cause = "Cannot add a journal bundle (use append instead)";
if (config.debug.rhizome)
DEBUG(cause);
DEBUG(rhizome, cause);
result = RHIZOME_ADD_FILE_INVALID_FOR_JOURNAL;
goto error;
}
@ -348,10 +341,9 @@ error:
*/
enum rhizome_bundle_status rhizome_bundle_import_files(rhizome_manifest *m, rhizome_manifest **mout, const char *manifest_path, const char *filepath)
{
if (config.debug.rhizome)
DEBUGF("(manifest_path=%s, filepath=%s)",
manifest_path ? alloca_str_toprint(manifest_path) : "NULL",
filepath ? alloca_str_toprint(filepath) : "NULL");
DEBUGF(rhizome, "(manifest_path=%s, filepath=%s)",
manifest_path ? alloca_str_toprint(manifest_path) : "NULL",
filepath ? alloca_str_toprint(filepath) : "NULL");
size_t buffer_len = 0;
int ret = 0;
@ -543,16 +535,14 @@ enum rhizome_bundle_status rhizome_manifest_check_stored(rhizome_manifest *m, rh
what = "newer than";
result = RHIZOME_BUNDLE_STATUS_NEW;
}
if (config.debug.rhizome)
DEBUGF("Bundle %s:%"PRIu64" is %s stored version %"PRIu64, alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version, what, stored_m->version);
DEBUGF(rhizome, "Bundle %s:%"PRIu64" is %s stored version %"PRIu64, alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version, what, stored_m->version);
if (mout)
*mout = stored_m;
else
rhizome_manifest_free(stored_m);
}else{
rhizome_manifest_free(stored_m);
if (config.debug.rhizome)
DEBUGF("No stored manifest with id=%s", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic));
DEBUGF(rhizome, "No stored manifest with id=%s", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic));
if (mout)
*mout = m;
}
@ -584,12 +574,10 @@ enum rhizome_bundle_status rhizome_manifest_check_stored(rhizome_manifest *m, rh
*/
enum rhizome_bundle_status rhizome_add_manifest(rhizome_manifest *m, rhizome_manifest **mout)
{
if (config.debug.rhizome) {
if (mout == NULL)
DEBUGF("rhizome_add_manifest(m=manifest[%d](%p), mout=NULL)", m->manifest_record_number, m);
else
DEBUGF("rhizome_add_manifest(m=manifest[%d](%p), *mout=manifest[%d](%p))", m->manifest_record_number, m, *mout ? (*mout)->manifest_record_number : -1, *mout);
}
if (mout == NULL)
DEBUGF(rhizome, "rhizome_add_manifest(m=manifest[%d](%p), mout=NULL)", m->manifest_record_number, m);
else
DEBUGF(rhizome, "rhizome_add_manifest(m=manifest[%d](%p), *mout=manifest[%d](%p))", m->manifest_record_number, m, *mout ? (*mout)->manifest_record_number : -1, *mout);
if (!m->finalised && !rhizome_manifest_validate(m))
return RHIZOME_BUNDLE_STATUS_INVALID;
assert(m->finalised);

View File

@ -57,8 +57,7 @@ static uint64_t rhizome_manifest_get_ui64(rhizome_manifest *m, const char *var)
*/
static int _rhizome_manifest_del(struct __sourceloc __whence, rhizome_manifest *m, const char *var)
{
if (config.debug.rhizome_manifest)
DEBUGF("DEL manifest[%d].%s", m->manifest_record_number, var);
DEBUGF(rhizome_manifest, "DEL manifest[%d].%s", m->manifest_record_number, var);
int ret = 0;
unsigned i;
for (i = 0; i < m->var_count; ++i)
@ -82,8 +81,7 @@ static int _rhizome_manifest_del(struct __sourceloc __whence, rhizome_manifest *
static const char *_rhizome_manifest_set(struct __sourceloc __whence, rhizome_manifest *m, const char *var, const char *value)
{
if (config.debug.rhizome_manifest)
DEBUGF("SET manifest[%d].%s = %s", m->manifest_record_number, var, alloca_str_toprint(value));
DEBUGF(rhizome_manifest, "SET manifest[%d].%s = %s", m->manifest_record_number, var, alloca_str_toprint(value));
unsigned i;
for(i=0;i<m->var_count;i++)
if (strcmp(m->vars[i],var) == 0) {
@ -375,15 +373,13 @@ void _rhizome_manifest_set_crypt(struct __sourceloc __whence, rhizome_manifest *
void _rhizome_manifest_set_rowid(struct __sourceloc __whence, rhizome_manifest *m, uint64_t rowid)
{
if (config.debug.rhizome_manifest)
DEBUGF("SET manifest[%d].rowid = %"PRIu64, m->manifest_record_number, rowid);
DEBUGF(rhizome_manifest, "SET manifest[%d].rowid = %"PRIu64, m->manifest_record_number, rowid);
m->rowid = rowid;
}
void _rhizome_manifest_set_inserttime(struct __sourceloc __whence, rhizome_manifest *m, time_ms_t time)
{
if (config.debug.rhizome_manifest)
DEBUGF("SET manifest[%d].inserttime = %"PRItime_ms_t, m->manifest_record_number, time);
DEBUGF(rhizome_manifest, "SET manifest[%d].inserttime = %"PRItime_ms_t, m->manifest_record_number, time);
m->inserttime = time;
}
@ -391,8 +387,7 @@ void _rhizome_manifest_set_author(struct __sourceloc __whence, rhizome_manifest
{
if (sidp) {
if (m->authorship == ANONYMOUS || cmp_sid_t(&m->author, sidp) != 0) {
if (config.debug.rhizome_manifest)
DEBUGF("SET manifest[%d] author = %s", m->manifest_record_number, alloca_tohex_sid_t(*sidp));
DEBUGF(rhizome_manifest, "SET manifest[%d] author = %s", m->manifest_record_number, alloca_tohex_sid_t(*sidp));
m->author = *sidp;
m->authorship = AUTHOR_NOT_CHECKED;
}
@ -403,8 +398,7 @@ void _rhizome_manifest_set_author(struct __sourceloc __whence, rhizome_manifest
void _rhizome_manifest_del_author(struct __sourceloc __whence, rhizome_manifest *m)
{
if (m->authorship != ANONYMOUS) {
if (config.debug.rhizome_manifest)
DEBUGF("DEL manifest[%d] author", m->manifest_record_number);
DEBUGF(rhizome_manifest, "DEL manifest[%d] author", m->manifest_record_number);
m->author = SID_ANY;
m->authorship = ANONYMOUS;
}
@ -443,16 +437,14 @@ int rhizome_manifest_verify(rhizome_manifest *m)
// Make sure the first signatory's public key is the bundle ID
assert(m->has_id);
if (m->sig_count == 0) {
if (config.debug.rhizome)
DEBUG("Manifest has no signature blocks, but should have self-signature block");
DEBUG(rhizome_manifest, "Manifest has no signature blocks, but should have self-signature block");
m->selfSigned = 0;
return 0;
}
if (memcmp(m->signatories[0], m->cryptoSignPublic.binary, sizeof m->cryptoSignPublic.binary) != 0) {
if (config.debug.rhizome)
DEBUGF("Manifest id does not match first signature block (signature key is %s)",
alloca_tohex(m->signatories[0], crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES)
);
DEBUGF(rhizome_manifest, "Manifest id does not match first signature block (signature key is %s)",
alloca_tohex(m->signatories[0], crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES)
);
m->selfSigned = 0;
return 0;
}
@ -616,8 +608,7 @@ int rhizome_manifest_parse(rhizome_manifest *m)
while (p < end && *p && *p != '=' && *p != '\n')
++p;
if (p == end || *p != '=') {
if (config.debug.rhizome_manifest)
DEBUGF("Invalid manifest line %u: %s", line_number, alloca_toprint(-1, plabel, p - plabel + 1));
DEBUGF(rhizome_manifest, "Invalid manifest line %u: %s", line_number, alloca_toprint(-1, plabel, p - plabel + 1));
break;
}
assert(p < end);
@ -626,8 +617,7 @@ int rhizome_manifest_parse(rhizome_manifest *m)
while (p < end && *p && *p != '\n')
++p;
if (p >= end || *p != '\n') {
if (config.debug.rhizome_manifest)
DEBUGF("Missing manifest newline at line %u: %s", line_number, alloca_toprint(-1, plabel, p - plabel));
DEBUGF(rhizome_manifest, "Missing manifest newline at line %u: %s", line_number, alloca_toprint(-1, plabel, p - plabel));
break;
}
const char *const eol = (p > pvalue && p[-1] == '\r') ? p - 1 : p;
@ -984,8 +974,7 @@ int _rhizome_manifest_overwrite(struct __sourceloc __whence, rhizome_manifest *m
for (i = 0; i < NELS(rhizome_manifest_fields); ++i) {
struct rhizome_manifest_field_descriptor *desc = &rhizome_manifest_fields[i];
if (desc->test(srcm)) {
if (config.debug.rhizome_manifest)
DEBUGF("COPY manifest[%d].%s to:", srcm->manifest_record_number, desc->label);
DEBUGF(rhizome_manifest, "COPY manifest[%d].%s to:", srcm->manifest_record_number, desc->label);
desc->copy(__whence, m, srcm);
}
}
@ -1056,15 +1045,13 @@ rhizome_manifest_parse_field(rhizome_manifest *m, const char *field_label, size_
{
// Syntax check on field label.
if (!rhizome_manifest_field_label_is_valid(field_label, field_label_len)) {
if (config.debug.rhizome_manifest)
DEBUGF("Invalid manifest field name: %s", alloca_toprint(100, field_label, field_label_len));
DEBUGF(rhizome_manifest, "Invalid manifest field name: %s", alloca_toprint(100, field_label, field_label_len));
return RHIZOME_MANIFEST_SYNTAX_ERROR;
}
const char *label = alloca_strndup(field_label, field_label_len);
// Sanity and syntax check on field value.
if (!rhizome_manifest_field_value_is_valid(field_value, field_value_len)) {
if (config.debug.rhizome_manifest)
DEBUGF("Invalid manifest field value: %s=%s", label, alloca_toprint(100, field_value, field_value_len));
DEBUGF(rhizome_manifest, "Invalid manifest field value: %s=%s", label, alloca_toprint(100, field_value, field_value_len));
return RHIZOME_MANIFEST_SYNTAX_ERROR;
}
const char *value = alloca_strndup(field_value, field_value_len);
@ -1072,24 +1059,20 @@ rhizome_manifest_parse_field(rhizome_manifest *m, const char *field_label, size_
enum rhizome_manifest_parse_status status = RHIZOME_MANIFEST_OK;
assert(m->var_count <= NELS(m->vars));
if (desc ? desc->test(m) : rhizome_manifest_get(m, label) != NULL) {
if (config.debug.rhizome_manifest)
DEBUGF("Duplicate field at %s=%s", label, alloca_toprint(100, field_value, field_value_len));
DEBUGF(rhizome_manifest, "Duplicate field at %s=%s", label, alloca_toprint(100, field_value, field_value_len));
status = RHIZOME_MANIFEST_DUPLICATE_FIELD;
} else if (m->var_count == NELS(m->vars)) {
if (config.debug.rhizome_manifest)
DEBUGF("Manifest field limit reached at %s=%s", label, alloca_toprint(100, field_value, field_value_len));
DEBUGF(rhizome_manifest, "Manifest field limit reached at %s=%s", label, alloca_toprint(100, field_value, field_value_len));
status = RHIZOME_MANIFEST_OVERFLOW;
} else if (desc) {
if (!desc->parse(m, value)) {
if (config.debug.rhizome_manifest)
DEBUGF("Manifest field parse failed at %s=%s", label, alloca_toprint(100, field_value, field_value_len));
DEBUGF(rhizome_manifest, "Manifest field parse failed at %s=%s", label, alloca_toprint(100, field_value, field_value_len));
status = desc->core ? RHIZOME_MANIFEST_INVALID : RHIZOME_MANIFEST_MALFORMED;
}
} else if (rhizome_manifest_set(m, label, value) == NULL)
status = RHIZOME_MANIFEST_ERROR;
if (status != RHIZOME_MANIFEST_OK) {
if (config.debug.rhizome_manifest)
DEBUGF("SKIP manifest[%d].%s = %s (status=%d)", m->manifest_record_number, label, alloca_str_toprint(value), status);
DEBUGF(rhizome_manifest, "SKIP manifest[%d].%s = %s (status=%d)", m->manifest_record_number, label, alloca_str_toprint(value), status);
}
return status;
}
@ -1101,8 +1084,7 @@ rhizome_manifest_parse_field(rhizome_manifest *m, const char *field_label, size_
int rhizome_manifest_remove_field(rhizome_manifest *m, const char *field_label, size_t field_label_len)
{
if (!rhizome_manifest_field_label_is_valid(field_label, field_label_len)) {
if (config.debug.rhizome_manifest)
DEBUGF("Invalid manifest field name: %s", alloca_toprint(100, field_label, field_label_len));
DEBUGF(rhizome_manifest, "Invalid manifest field name: %s", alloca_toprint(100, field_label, field_label_len));
return 0;
}
const char *label = alloca_strndup(field_label, field_label_len);
@ -1155,8 +1137,8 @@ const char *rhizome_manifest_validate_reason(rhizome_manifest *m)
reason = "Spurious 'filehash' field";
else if (m->filesize != 0 && !m->has_filehash)
reason = "Missing 'filehash' field";
if (reason && config.debug.rhizome_manifest)
DEBUG(reason);
if (reason)
DEBUG(rhizome_manifest, reason);
if (m->service == NULL)
m->malformed = "Missing 'service' field";
else if (strcmp(m->service, RHIZOME_SERVICE_FILE) == 0) {
@ -1174,8 +1156,8 @@ const char *rhizome_manifest_validate_reason(rhizome_manifest *m)
m->malformed = "Manifest invalid 'service' field";
else if (!m->has_date)
m->malformed = "Missing 'date' field";
if (m->malformed && config.debug.rhizome_manifest)
DEBUG(m->malformed);
if (m->malformed)
DEBUG(rhizome_manifest, m->malformed);
m->finalised = (reason == NULL);
return reason;
}
@ -1292,8 +1274,7 @@ rhizome_manifest *_rhizome_new_manifest(struct __sourceloc __whence)
for (; manifest_first_free < MAX_RHIZOME_MANIFESTS && !manifest_free[manifest_first_free]; ++manifest_first_free)
;
if (config.debug.rhizome_manifest)
DEBUGF("NEW manifest[%d], count_free=%u", m->manifest_record_number, _count_free_manifests());
DEBUGF(rhizome_manifest, "NEW manifest[%d], count_free=%u", m->manifest_record_number, _count_free_manifests());
// Set global defaults for a manifest (which are not zero)
rhizome_manifest_clear(m);
@ -1332,8 +1313,7 @@ void _rhizome_manifest_free(struct __sourceloc __whence, rhizome_manifest *m)
manifest_free_whence[mid]=__whence;
if (mid<manifest_first_free) manifest_first_free=mid;
if (config.debug.rhizome_manifest)
DEBUGF("FREE manifest[%d], count_free=%u", m->manifest_record_number, _count_free_manifests());
DEBUGF(rhizome_manifest, "FREE manifest[%d], count_free=%u", m->manifest_record_number, _count_free_manifests());
return;
}
@ -1354,8 +1334,7 @@ static int rhizome_manifest_pack_variables(rhizome_manifest *m)
if (strbuf_overrun(sb))
return WHYF("Manifest overflow: body of %zu bytes exceeds limit of %zu", strbuf_count(sb) + 1, sizeof m->manifestdata);
m->manifest_body_bytes = strbuf_len(sb) + 1;
if (config.debug.rhizome)
DEBUGF("Repacked variables into manifest: %zu bytes", m->manifest_body_bytes);
DEBUGF(rhizome, "Repacked variables into manifest: %zu bytes", m->manifest_body_bytes);
m->manifest_all_bytes = m->manifest_body_bytes;
m->selfSigned = 0;
return 0;
@ -1392,8 +1371,7 @@ int rhizome_manifest_selfsign(rhizome_manifest *m)
int rhizome_write_manifest_file(rhizome_manifest *m, const char *path, char append)
{
if (config.debug.rhizome)
DEBUGF("write manifest (%zd bytes) to %s", m->manifest_all_bytes, path);
DEBUGF(rhizome, "write manifest (%zd bytes) to %s", m->manifest_all_bytes, path);
assert(m->finalised);
int fd = open(path, O_WRONLY | O_CREAT | (append ? O_APPEND : 0), 0666);
if (fd == -1)
@ -1528,13 +1506,11 @@ const char * rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, co
// If the Bundle Id is already known, then derive the bundle secret from BK if known.
// If there is no Bundle Id, then create a new bundle Id and secret from scratch.
if (m->has_id) {
if (config.debug.rhizome)
DEBUGF("discover secret for bundle bid=%s", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic));
DEBUGF(rhizome, "discover secret for bundle bid=%s", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic));
rhizome_authenticate_author(m);
break;
}
if (config.debug.rhizome)
DEBUG("creating new bundle");
DEBUG(rhizome, "creating new bundle");
if (rhizome_manifest_createid(m) == -1) {
WHY(reason = "Could not bind manifest to an ID");
return reason;
@ -1544,8 +1520,7 @@ const char * rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, co
valid_haveSecret = 1;
assert(m->has_id);
if (m->authorship != ANONYMOUS) {
if (config.debug.rhizome)
DEBUGF("set BK field for bid=%s", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic));
DEBUGF(rhizome, "set BK field for bid=%s", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic));
rhizome_manifest_add_bundle_key(m); // set the BK field
}
break;
@ -1553,8 +1528,7 @@ const char * rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, co
valid_haveSecret = 1;
// If modifying an existing bundle, try to discover the bundle secret key and the author.
assert(m->has_id);
if (config.debug.rhizome)
DEBUGF("modifying existing bundle bid=%s", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic));
DEBUGF(rhizome, "modifying existing bundle bid=%s", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic));
rhizome_authenticate_author(m);
// TODO assert that new version > old version?
}
@ -1567,27 +1541,24 @@ const char * rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, co
WHYF(reason = "Missing 'service' field");
return reason;
}
if (config.debug.rhizome)
DEBUGF("manifest contains service=%s", m->service);
DEBUGF(rhizome, "manifest contains service=%s", m->service);
/* Fill in 'date' field to current time unless already set.
*/
if (!m->has_date) {
rhizome_manifest_set_date(m, (int64_t) gettime_ms());
if (config.debug.rhizome)
DEBUGF("missing 'date', set default date=%"PRItime_ms_t, m->date);
DEBUGF(rhizome, "missing 'date', set default date=%"PRItime_ms_t, m->date);
}
/* Fill in 'name' field if service=file.
*/
if (strcasecmp(RHIZOME_SERVICE_FILE, m->service) == 0) {
if (m->name) {
if (config.debug.rhizome)
DEBUGF("manifest already contains name=%s", alloca_str_toprint(m->name));
DEBUGF(rhizome, "manifest already contains name=%s", alloca_str_toprint(m->name));
} else if (filepath)
rhizome_manifest_set_name_from_path(m, filepath);
else if (config.debug.rhizome)
DEBUGF("manifest missing 'name'");
else
DEBUGF(rhizome, "manifest missing 'name'");
}
/* Fill in 'crypt' field. Anything sent from one person to another should be considered private
@ -1598,8 +1569,7 @@ const char * rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, co
&& m->has_recipient
&& !is_sid_t_broadcast(m->recipient)
) {
if (config.debug.rhizome)
DEBUGF("Implicitly adding payload encryption due to presense of sender & recipient fields");
DEBUGF(rhizome, "Implicitly adding payload encryption due to presense of sender & recipient fields");
rhizome_manifest_set_crypt(m, PAYLOAD_ENCRYPTED);
}
@ -1618,24 +1588,20 @@ int rhizome_lookup_author(rhizome_manifest *m)
switch (m->authorship) {
case AUTHOR_NOT_CHECKED:
if (config.debug.rhizome)
DEBUGF("manifest[%d] lookup author=%s", m->manifest_record_number, alloca_tohex_sid_t(m->author));
DEBUGF(rhizome, "manifest[%d] lookup author=%s", m->manifest_record_number, alloca_tohex_sid_t(m->author));
keyring_iterator_start(keyring, &it);
if (keyring_find_sid(&it, &m->author)) {
if (config.debug.rhizome)
DEBUGF("found author");
DEBUGF(rhizome, "found author");
m->authorship = AUTHOR_LOCAL;
RETURN(1);
}
// fall through
case ANONYMOUS:
if (m->has_sender) {
if (config.debug.rhizome)
DEBUGF("manifest[%d] lookup sender=%s", m->manifest_record_number, alloca_tohex_sid_t(m->sender));
DEBUGF(rhizome, "manifest[%d] lookup sender=%s", m->manifest_record_number, alloca_tohex_sid_t(m->sender));
keyring_iterator_start(keyring, &it);
if (keyring_find_sid(&it, &m->sender)) {
if (config.debug.rhizome)
DEBUGF("found sender");
DEBUGF(rhizome, "found sender");
rhizome_manifest_set_author(m, &m->sender);
m->authorship = AUTHOR_LOCAL;
RETURN(1);

View File

@ -88,8 +88,7 @@ DEFINE_CMD(app_rhizome_hash_file, 0,
"rhizome","hash","file","<filepath>");
static int app_rhizome_hash_file(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
/* compute hash of file. We do this without a manifest, so it will necessarily
return the hash of the file unencrypted. */
const char *filepath;
@ -110,8 +109,7 @@ DEFINE_CMD(app_rhizome_add_file, 0,
"rhizome", "journal", "append" KEYRING_PIN_OPTIONS, "<author_sid>", "<bundleid>", "<filepath>", "[<bsk>]");
static int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
const char *filepath, *manifestpath, *bundleIdHex, *authorSidHex, *bsktext;
int force_new = 0 == cli_arg(parsed, "--force-new", NULL, NULL, NULL);
@ -196,8 +194,7 @@ static int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_cont
goto finish;
}
if (manifestpath && *manifestpath && access(manifestpath, R_OK) == 0) {
if (config.debug.rhizome)
DEBUGF("reading manifest from %s", manifestpath);
DEBUGF(rhizome, "reading manifest from %s", manifestpath);
if (rhizome_read_manifest_from_file(m, manifestpath) || m->malformed) {
ret = WHY("Manifest file could not be loaded -- not added to rhizome");
goto finish;
@ -251,18 +248,15 @@ static int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_cont
enum rhizome_payload_status pstatus;
if (appending) {
pstatus = rhizome_append_journal_file(m, 0, filepath);
if (config.debug.rhizome)
DEBUGF("rhizome_append_journal_file() returned %d %s", pstatus, rhizome_payload_status_message(pstatus));
DEBUGF(rhizome, "rhizome_append_journal_file() returned %d %s", pstatus, rhizome_payload_status_message(pstatus));
} else {
pstatus = rhizome_stat_payload_file(m, filepath);
if (config.debug.rhizome)
DEBUGF("rhizome_stat_payload_file() returned %d %s", pstatus, rhizome_payload_status_message(pstatus));
DEBUGF(rhizome, "rhizome_stat_payload_file() returned %d %s", pstatus, rhizome_payload_status_message(pstatus));
assert(m->filesize != RHIZOME_SIZE_UNSET);
if (pstatus == RHIZOME_PAYLOAD_STATUS_NEW) {
assert(m->filesize > 0);
pstatus = rhizome_store_payload_file(m, filepath);
if (config.debug.rhizome)
DEBUGF("rhizome_store_payload_file() returned %d %s", pstatus, rhizome_payload_status_message(pstatus));
DEBUGF(rhizome, "rhizome_store_payload_file() returned %d %s", pstatus, rhizome_payload_status_message(pstatus));
}
}
enum rhizome_bundle_status status = RHIZOME_BUNDLE_STATUS_ERROR;
@ -355,8 +349,7 @@ DEFINE_CMD(app_rhizome_import_bundle, 0,
"rhizome","import","bundle","<filepath>","<manifestpath>");
static int app_rhizome_import_bundle(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
const char *filepath, *manifestpath;
cli_arg(parsed, "filepath", &filepath, NULL, "");
cli_arg(parsed, "manifestpath", &manifestpath, NULL, "");
@ -394,8 +387,7 @@ DEFINE_CMD(app_rhizome_append_manifest, 0,
"rhizome", "append", "manifest", "<filepath>", "<manifestpath>");
static int app_rhizome_append_manifest(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
const char *manifestpath, *filepath;
if ( cli_arg(parsed, "manifestpath", &manifestpath, NULL, "") == -1
|| cli_arg(parsed, "filepath", &filepath, NULL, "") == -1)
@ -423,8 +415,7 @@ DEFINE_CMD(app_rhizome_delete, 0,
"rhizome","delete","|file","<fileid>");
static int app_rhizome_delete(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
const char *manifestid, *fileid;
if (cli_arg(parsed, "manifestid", &manifestid, cli_bid, NULL) == -1)
return -1;
@ -485,8 +476,7 @@ DEFINE_CMD(app_rhizome_clean, 0,
"rhizome","clean","[verify]");
static int app_rhizome_clean(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
int verify = cli_arg(parsed, "verify", NULL, NULL, NULL) == 0;
/* Ensure the Rhizome database exists and is open */
@ -529,8 +519,7 @@ DEFINE_CMD(app_rhizome_extract, 0,
"<manifestid>","[<filepath>]","[<bsk>]");
static int app_rhizome_extract(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
const char *manifestpath, *filepath, *manifestid, *bsktext;
if ( cli_arg(parsed, "manifestid", &manifestid, cli_bid, "") == -1
|| cli_arg(parsed, "manifestpath", &manifestpath, NULL, "") == -1
@ -647,8 +636,7 @@ DEFINE_CMD(app_rhizome_export_file, 0,
"rhizome","export","file","<fileid>","[<filepath>]");
static int app_rhizome_export_file(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
const char *fileid, *filepath;
if ( cli_arg(parsed, "filepath", &filepath, NULL, "") == -1
|| cli_arg(parsed, "fileid", &fileid, cli_fileid, NULL) == -1)
@ -691,8 +679,7 @@ DEFINE_CMD(app_rhizome_list, 0,
"[<service>]","[<name>]","[<sender_sid>]","[<recipient_sid>]","[<offset>]","[<limit>]");
static int app_rhizome_list(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
const char *service = NULL, *name = NULL, *sender_hex = NULL, *recipient_hex = NULL, *offset_ascii = NULL, *limit_ascii = NULL;
cli_arg(parsed, "service", &service, NULL, "");
cli_arg(parsed, "name", &name, NULL, "");

View File

@ -217,8 +217,7 @@ enum rhizome_secret_disposition find_rhizome_secret(const sid_t *authorSidp, siz
keyring_iterator_start(keyring, &it);
if (!keyring_find_sid(&it, authorSidp)) {
if (config.debug.rhizome)
DEBUGF("identity sid=%s is not in keyring", alloca_tohex_sid_t(*authorSidp));
DEBUGF(rhizome, "identity sid=%s is not in keyring", alloca_tohex_sid_t(*authorSidp));
RETURN(IDENTITY_NOT_FOUND);
}
keypair *kp=keyring_identity_keytype(it.identity, KEYTYPE_RHIZOME);
@ -244,58 +243,48 @@ enum rhizome_secret_disposition find_rhizome_secret(const sid_t *authorSidp, siz
void rhizome_authenticate_author(rhizome_manifest *m)
{
IN();
if (config.debug.rhizome)
DEBUGF("authenticate author for bid=%s", m->has_id ? alloca_tohex_rhizome_bid_t(m->cryptoSignPublic) : "(none)");
DEBUGF(rhizome, "authenticate author for bid=%s", m->has_id ? alloca_tohex_rhizome_bid_t(m->cryptoSignPublic) : "(none)");
if (!m->has_bundle_key) {
if (config.debug.rhizome)
DEBUG(" no BK field");
DEBUG(rhizome, " no BK field");
RETURNVOID;
}
switch (m->authorship) {
case ANONYMOUS:
if (config.debug.rhizome)
DEBUGF(" manifest[%d] author unknown", m->manifest_record_number);
DEBUGF(rhizome, " manifest[%d] author unknown", m->manifest_record_number);
rhizome_find_bundle_author_and_secret(m);
break;
case AUTHOR_NOT_CHECKED:
case AUTHOR_LOCAL: {
if (config.debug.rhizome)
DEBUGF(" manifest[%d] authenticate author=%s", m->manifest_record_number, alloca_tohex_sid_t(m->author));
DEBUGF(rhizome, " manifest[%d] authenticate author=%s", m->manifest_record_number, alloca_tohex_sid_t(m->author));
size_t rs_len;
const unsigned char *rs;
enum rhizome_secret_disposition d = find_rhizome_secret(&m->author, &rs_len, &rs);
switch (d) {
case FOUND_RHIZOME_SECRET:
if (config.debug.rhizome)
DEBUGF(" author has Rhizome secret");
DEBUGF(rhizome, " author has Rhizome secret");
switch (rhizome_bk2secret(&m->cryptoSignPublic, rs, rs_len, m->bundle_key.binary, m->cryptoSignSecret)) {
case 0:
if (config.debug.rhizome)
DEBUGF(" is authentic");
DEBUGF(rhizome, " is authentic");
m->authorship = AUTHOR_AUTHENTIC;
if (!m->haveSecret)
m->haveSecret = EXISTING_BUNDLE_ID;
break;
case -1:
if (config.debug.rhizome)
DEBUGF(" error");
DEBUGF(rhizome, " error");
m->authorship = AUTHENTICATION_ERROR;
break;
default:
if (config.debug.rhizome)
DEBUGF(" author is impostor");
DEBUGF(rhizome, " author is impostor");
m->authorship = AUTHOR_IMPOSTOR;
break;
}
break;
case IDENTITY_NOT_FOUND:
if (config.debug.rhizome)
DEBUGF(" author not found");
DEBUGF(rhizome, " author not found");
m->authorship = AUTHOR_UNKNOWN;
break;
case IDENTITY_HAS_NO_RHIZOME_SECRET:
if (config.debug.rhizome)
DEBUGF(" author has no Rhizome secret");
DEBUGF(rhizome, " author has no Rhizome secret");
m->authorship = AUTHENTICATION_ERROR;
break;
default:
@ -329,16 +318,14 @@ void rhizome_authenticate_author(rhizome_manifest *m)
int rhizome_apply_bundle_secret(rhizome_manifest *m, const rhizome_bk_t *bsk)
{
IN();
if (config.debug.rhizome)
DEBUGF("manifest[%d] bsk=%s", m->manifest_record_number, bsk ? alloca_tohex_rhizome_bk_t(*bsk) : "NULL");
DEBUGF(rhizome, "manifest[%d] bsk=%s", m->manifest_record_number, bsk ? alloca_tohex_rhizome_bk_t(*bsk) : "NULL");
assert(m->haveSecret == SECRET_UNKNOWN);
assert(is_all_matching(m->cryptoSignSecret, sizeof m->cryptoSignSecret, 0));
assert(m->has_id);
assert(bsk != NULL);
assert(!rhizome_is_bk_none(bsk));
if (rhizome_verify_bundle_privatekey(bsk->binary, m->cryptoSignPublic.binary)) {
if (config.debug.rhizome)
DEBUG("bundle secret verifies ok");
DEBUG(rhizome, "bundle secret verifies ok");
bcopy(bsk->binary, m->cryptoSignSecret, sizeof bsk->binary);
bcopy(m->cryptoSignPublic.binary, m->cryptoSignSecret + sizeof bsk->binary, sizeof m->cryptoSignPublic.binary);
m->haveSecret = EXISTING_BUNDLE_ID;
@ -375,17 +362,14 @@ int rhizome_apply_bundle_secret(rhizome_manifest *m, const rhizome_bk_t *bsk)
void rhizome_find_bundle_author_and_secret(rhizome_manifest *m)
{
IN();
if (config.debug.rhizome)
DEBUGF("Finding author and secret for bid=%s", m->has_id ? alloca_tohex_rhizome_bid_t(m->cryptoSignPublic) : "(none)");
DEBUGF(rhizome, "Finding author and secret for bid=%s", m->has_id ? alloca_tohex_rhizome_bid_t(m->cryptoSignPublic) : "(none)");
if (m->authorship != ANONYMOUS) {
if (config.debug.rhizome)
DEBUGF(" bundle is anonymous");
DEBUGF(rhizome, " bundle is anonymous");
RETURNVOID;
}
assert(is_sid_t_any(m->author));
if (!m->has_bundle_key) {
if (config.debug.rhizome)
DEBUGF(" bundle has no BK field");
DEBUGF(rhizome, " bundle has no BK field");
RETURNVOID;
}
keyring_iterator it;
@ -411,8 +395,7 @@ void rhizome_find_bundle_author_and_secret(rhizome_manifest *m)
keypair *kp_sid = keyring_identity_keytype(it.identity, KEYTYPE_CRYPTOBOX);
if (kp_sid) {
const sid_t *authorSidp = (const sid_t *) kp_sid->public_key;
if (config.debug.rhizome)
DEBUGF(" found bundle author sid=%s", alloca_tohex_sid_t(*authorSidp));
DEBUGF(rhizome, " found bundle author sid=%s", alloca_tohex_sid_t(*authorSidp));
rhizome_manifest_set_author(m, authorSidp);
m->authorship = AUTHOR_AUTHENTIC;
// if this bundle is already in the database, update the author.
@ -427,8 +410,7 @@ void rhizome_find_bundle_author_and_secret(rhizome_manifest *m)
}
}
assert(m->authorship == ANONYMOUS);
if (config.debug.rhizome)
DEBUG(" bundle author not found");
DEBUG(rhizome, " bundle author not found");
OUT();
}
@ -535,8 +517,7 @@ static int rhizome_manifest_lookup_signature_validity(const unsigned char *hash,
int rhizome_manifest_extract_signature(rhizome_manifest *m, unsigned *ofs)
{
IN();
if (config.debug.rhizome_manifest)
DEBUGF("*ofs=%u m->manifest_all_bytes=%zu", *ofs, m->manifest_all_bytes);
DEBUGF(rhizome_manifest, "*ofs=%u m->manifest_all_bytes=%zu", *ofs, m->manifest_all_bytes);
assert((*ofs) < m->manifest_all_bytes);
const unsigned char *sig = m->manifestdata + *ofs;
uint8_t sigType = m->manifestdata[*ofs];
@ -568,8 +549,7 @@ int rhizome_manifest_extract_signature(rhizome_manifest *m, unsigned *ofs)
RETURN(-1);
bcopy(sig + 1 + 64, m->signatories[m->sig_count], crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES);
m->sig_count++;
if (config.debug.rhizome)
DEBUG("Signature verified");
DEBUG(rhizome, "Signature verified");
RETURN(0);
}
}
@ -653,17 +633,15 @@ int rhizome_derive_payload_key(rhizome_manifest *m)
return 0;
}
nm_bytes = keyring_get_nm_bytes(&m->recipient, &m->sender);
if (config.debug.rhizome)
DEBUGF("derived payload key from recipient=%s* to sender=%s*",
alloca_tohex_sid_t_trunc(m->recipient, 7),
alloca_tohex_sid_t_trunc(m->sender, 7)
DEBUGF(rhizome, "derived payload key from recipient=%s* to sender=%s*",
alloca_tohex_sid_t_trunc(m->recipient, 7),
alloca_tohex_sid_t_trunc(m->sender, 7)
);
}else{
nm_bytes = keyring_get_nm_bytes(&m->sender, &m->recipient);
if (config.debug.rhizome)
DEBUGF("derived payload key from sender=%s* to recipient=%s*",
alloca_tohex_sid_t_trunc(m->sender, 7),
alloca_tohex_sid_t_trunc(m->recipient, 7)
DEBUGF(rhizome, "derived payload key from sender=%s* to recipient=%s*",
alloca_tohex_sid_t_trunc(m->sender, 7),
alloca_tohex_sid_t_trunc(m->recipient, 7)
);
}
assert(nm_bytes != NULL);
@ -674,15 +652,13 @@ int rhizome_derive_payload_key(rhizome_manifest *m)
WHY("Cannot derive payload key because bundle secret is unknown");
return 0;
}
if (config.debug.rhizome)
DEBUGF("derived payload key from bundle secret bsk=%s", alloca_tohex(m->cryptoSignSecret, sizeof m->cryptoSignSecret));
DEBUGF(rhizome, "derived payload key from bundle secret bsk=%s", alloca_tohex(m->cryptoSignSecret, sizeof m->cryptoSignSecret));
unsigned char raw_key[9+crypto_sign_edwards25519sha512batch_SECRETKEYBYTES]="sasquatch";
bcopy(m->cryptoSignSecret, &raw_key[9], crypto_sign_edwards25519sha512batch_SECRETKEYBYTES);
crypto_hash_sha512(hash, raw_key, sizeof(raw_key));
}
bcopy(hash, m->payloadKey, RHIZOME_CRYPT_KEY_BYTES);
if (config.debug.rhizome_manifest)
DEBUGF("SET manifest[%d].payloadKey = %s", m->manifest_record_number, alloca_tohex(m->payloadKey, sizeof m->payloadKey));
DEBUGF(rhizome_manifest, "SET manifest[%d].payloadKey = %s", m->manifest_record_number, alloca_tohex(m->payloadKey, sizeof m->payloadKey));
// journal bundles must always have the same nonce, regardless of version.
// otherwise, generate nonce from version#bundle id#version;
@ -691,12 +667,10 @@ int rhizome_derive_payload_key(rhizome_manifest *m)
write_uint64(&raw_nonce[0], nonce_version);
bcopy(m->cryptoSignPublic.binary, &raw_nonce[8], sizeof m->cryptoSignPublic.binary);
write_uint64(&raw_nonce[8 + sizeof m->cryptoSignPublic.binary], nonce_version);
if (config.debug.rhizome)
DEBUGF("derived payload nonce from bid=%s version=%"PRIu64, alloca_tohex_sid_t(m->cryptoSignPublic), nonce_version);
DEBUGF(rhizome, "derived payload nonce from bid=%s version=%"PRIu64, alloca_tohex_sid_t(m->cryptoSignPublic), nonce_version);
crypto_hash_sha512(hash, raw_nonce, sizeof(raw_nonce));
bcopy(hash, m->payloadNonce, sizeof(m->payloadNonce));
if (config.debug.rhizome_manifest)
DEBUGF("SET manifest[%d].payloadNonce = %s", m->manifest_record_number, alloca_tohex(m->payloadNonce, sizeof m->payloadNonce));
DEBUGF(rhizome_manifest, "SET manifest[%d].payloadNonce = %s", m->manifest_record_number, alloca_tohex(m->payloadNonce, sizeof m->payloadNonce));
return 1;
}

View File

@ -39,8 +39,7 @@ static int create_rhizome_store_dir()
if (!formf_rhizome_store_path(rdpath, sizeof rdpath, "%s", config.rhizome.datastore_path))
return -1;
INFOF("Rhizome datastore path = %s", alloca_str_toprint(rdpath));
if (config.debug.rhizome)
DEBUGF("mkdirs(%s, 0700)", alloca_str_toprint(rdpath));
DEBUGF(rhizome, "mkdirs(%s, 0700)", alloca_str_toprint(rdpath));
return emkdirs_info(rdpath, 0700);
}
@ -50,12 +49,12 @@ static time_ms_t rhizomeRetryLimit = -1;
int is_debug_rhizome()
{
return config.debug.rhizome;
return IF_DEBUG(rhizome);
}
int is_debug_rhizome_ads()
{
return config.debug.rhizome_ads;
return IF_DEBUG(rhizome_ads);
}
static int (*sqlite_trace_func)() = is_debug_rhizome;
@ -142,8 +141,7 @@ void verify_bundles()
ret = rhizome_store_manifest(m);
}
if (ret) {
if (config.debug.rhizome)
DEBUGF("Removing invalid manifest entry @%lld", rowid);
DEBUGF(rhizome, "Removing invalid manifest entry @%lld", rowid);
sqlite_exec_void_retry(&retry, "DELETE FROM MANIFESTS WHERE ROWID = ?;", INT64, rowid, END);
}
rhizome_manifest_free(m);
@ -218,14 +216,13 @@ int rhizome_opendb()
}
sqlite3_trace(rhizome_db, sqlite_trace_callback, NULL);
sqlite3_profile(rhizome_db, sqlite_profile_callback, NULL);
int loglevel = (config.debug.rhizome) ? LOG_LEVEL_DEBUG : LOG_LEVEL_SILENT;
int loglevel = IF_DEBUG(rhizome) ? LOG_LEVEL_DEBUG : LOG_LEVEL_SILENT;
const char *env = getenv("SERVALD_RHIZOME_DB_RETRY_LIMIT_MS");
rhizomeRetryLimit = env ? atoi(env) : -1;
/* Read Rhizome configuration */
if (config.debug.rhizome)
DEBUGF("Rhizome will use %"PRIu64"B of storage for its database.", (uint64_t) config.rhizome.database_size);
DEBUGF(rhizome, "Rhizome will use %"PRIu64"B of storage for its database.", (uint64_t) config.rhizome.database_size);
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
@ -331,16 +328,14 @@ int rhizome_opendb()
RETURN(WHY("Cannot generate new UUID for Rhizome database"));
if (sqlite_exec_void_retry(&retry, "UPDATE IDENTITY SET uuid = ? LIMIT 1;", SERVAL_UUID_T, &rhizome_db_uuid, END) == -1)
RETURN(WHY("Failed to update new UUID in Rhizome database"));
if (config.debug.rhizome)
DEBUGF("Updated Rhizome database UUID to %s", alloca_uuid_str(rhizome_db_uuid));
DEBUGF(rhizome, "Updated Rhizome database UUID to %s", alloca_uuid_str(rhizome_db_uuid));
}
} else if (r == 0) {
if (uuid_generate_random(&rhizome_db_uuid) == -1)
RETURN(WHY("Cannot generate UUID for Rhizome database"));
if (sqlite_exec_void_retry(&retry, "INSERT INTO IDENTITY (uuid) VALUES (?);", SERVAL_UUID_T, &rhizome_db_uuid, END) == -1)
RETURN(WHY("Failed to insert UUID into Rhizome database"));
if (config.debug.rhizome)
DEBUGF("Set Rhizome database UUID to %s", alloca_uuid_str(rhizome_db_uuid));
DEBUGF(rhizome, "Set Rhizome database UUID to %s", alloca_uuid_str(rhizome_db_uuid));
}
// We can't delete a file that is being transferred in another process at this very moment...
@ -538,7 +533,7 @@ int _sqlite_vbind(struct __sourceloc __whence, int log_level, sqlite_retry_state
LOGF(log_level, "at bind arg %u, illegal index=%d: %s", argnum, index, sqlite3_sql(statement));
return -1;
}
if (config.debug.rhizome)
if (IF_DEBUG(rhizome))
strbuf_sprintf((ext = strbuf_alloca(35)), "|INDEX(%d)", index);
} else if ((typ & 0xffff0000) == NAMED) {
typ &= 0xffff;
@ -549,7 +544,7 @@ int _sqlite_vbind(struct __sourceloc __whence, int log_level, sqlite_retry_state
LOGF(log_level, "at bind arg %u, no parameter named %s in query: %s", argnum, alloca_str_toprint(name), sqlite3_sql(statement));
return -1;
}
if (config.debug.rhizome) {
if (IF_DEBUG(rhizome)) {
ext = strbuf_alloca(30 + toprint_str_len(name, "\"\""));
strbuf_puts(ext, "|NAMED(");
strbuf_toprint_quoted(ext, "\"\"", name);
@ -557,15 +552,14 @@ int _sqlite_vbind(struct __sourceloc __whence, int log_level, sqlite_retry_state
}
} else if ((typ & 0xffff0000) == 0) {
index = ++index_counter;
if (config.debug.rhizome)
if (IF_DEBUG(rhizome))
ext = strbuf_alloca(10);
} else {
FATALF("at bind arg %u, unsupported bind code typ=0x%08x: %s", argnum, typ, sqlite3_sql(statement));
return -1;
}
#define BIND_DEBUG(TYP,FUNC,ARGFMT,...) \
if (config.debug.rhizome_sql_bind) \
DEBUGF("%s%s %s(%d," ARGFMT ") %s", #TYP, strbuf_str(ext), #FUNC, index, ##__VA_ARGS__, sqlite3_sql(statement))
DEBUGF(rhizome_sql_bind, "%s%s %s(%d," ARGFMT ") %s", #TYP, strbuf_str(ext), #FUNC, index, ##__VA_ARGS__, sqlite3_sql(statement))
#define BIND_RETRY(FUNC, ...) \
do { \
switch (FUNC(statement, index, ##__VA_ARGS__)) { \
@ -597,7 +591,7 @@ int _sqlite_vbind(struct __sourceloc __whence, int log_level, sqlite_retry_state
BIND_RETRY(sqlite3_bind_null);
break;
default:
if ((typ & NUL) && config.debug.rhizome)
if ((typ & NUL) && IF_DEBUG(rhizome))
strbuf_puts(ext, "|NUL");
switch (typ & ~NUL) {
case INT: {
@ -918,7 +912,7 @@ int _sqlite_exec(struct __sourceloc __whence, int log_level, sqlite_retry_state
++rowcount;
sqlite3_finalize(statement);
if (sqlite_trace_func())
DEBUGF("rowcount=%d changes=%d", rowcount, sqlite3_changes(rhizome_db));
_DEBUGF("rowcount=%d changes=%d", rowcount, sqlite3_changes(rhizome_db));
return sqlite_code_ok(stepcode) ? rowcount : -1;
}
@ -997,7 +991,7 @@ static int _sqlite_vexec_uint64(struct __sourceloc __whence, sqlite_retry_state
if (!sqlite_code_ok(stepcode) || ret == -1)
return -1;
if (sqlite_trace_func())
DEBUGF("rowcount=%d changes=%d result=%"PRIu64, rowcount, sqlite3_changes(rhizome_db), *result);
_DEBUGF("rowcount=%d changes=%d result=%"PRIu64, rowcount, sqlite3_changes(rhizome_db), *result);
return rowcount;
}
@ -1197,7 +1191,7 @@ void rhizome_vacuum_db(sqlite_retry_state *retry){
int rhizome_cleanup(struct rhizome_cleanup_report *report)
{
IN();
if (config.debug.rhizome && report == NULL)
if (IF_DEBUG(rhizome) && report == NULL)
report = alloca(sizeof *report);
if (report)
bzero(report, sizeof *report);
@ -1251,13 +1245,13 @@ int rhizome_cleanup(struct rhizome_cleanup_report *report)
rhizome_vacuum_db(&retry);
if (config.debug.rhizome && report)
DEBUGF("report deleted_stale_incoming_files=%u deleted_orphan_files=%u deleted_orphan_fileblobs=%u deleted_orphan_manifests=%u",
report->deleted_stale_incoming_files,
report->deleted_orphan_files,
report->deleted_orphan_fileblobs,
report->deleted_orphan_manifests
);
if (report)
DEBUGF(rhizome, "report deleted_stale_incoming_files=%u deleted_orphan_files=%u deleted_orphan_fileblobs=%u deleted_orphan_manifests=%u",
report->deleted_stale_incoming_files,
report->deleted_orphan_files,
report->deleted_orphan_fileblobs,
report->deleted_orphan_manifests
);
RETURN(0);
OUT();
}
@ -1375,11 +1369,10 @@ rollback:
static void trigger_rhizome_bundle_added_debug(rhizome_manifest *m)
{
if (config.debug.rhizome)
DEBUGF("TRIGGER rhizome_bundle_added service=%s bid=%s version=%"PRIu64,
m->service ? m->service : "NULL",
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic),
m->version
DEBUGF(rhizome, "TRIGGER rhizome_bundle_added service=%s bid=%s version=%"PRIu64,
m->service ? m->service : "NULL",
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic),
m->version
);
}
@ -1392,16 +1385,15 @@ DEFINE_TRIGGER(rhizome_bundle_added, trigger_rhizome_bundle_added_debug)
*/
int rhizome_list_open(struct rhizome_list_cursor *c)
{
if (config.debug.rhizome)
DEBUGF("c=%p c->service=%s c->name=%s c->sender=%s c->recipient=%s c->rowid_since=%"PRIu64" c->_rowid_last=%"PRIu64,
c,
alloca_str_toprint(c->service),
alloca_str_toprint(c->name),
c->is_sender_set ? alloca_tohex_sid_t(c->sender) : "UNSET",
c->is_recipient_set ? alloca_tohex_sid_t(c->recipient) : "UNSET",
c->rowid_since,
c->_rowid_last
);
DEBUGF(rhizome, "c=%p c->service=%s c->name=%s c->sender=%s c->recipient=%s c->rowid_since=%"PRIu64" c->_rowid_last=%"PRIu64,
c,
alloca_str_toprint(c->service),
alloca_str_toprint(c->name),
c->is_sender_set ? alloca_tohex_sid_t(c->sender) : "UNSET",
c->is_recipient_set ? alloca_tohex_sid_t(c->recipient) : "UNSET",
c->rowid_since,
c->_rowid_last
);
IN();
strbuf b = strbuf_alloca(1024);
strbuf_sprintf(b, "SELECT id, manifest, version, inserttime, author, rowid FROM manifests WHERE 1=1");
@ -1459,16 +1451,15 @@ failure:
*/
int rhizome_list_next(struct rhizome_list_cursor *c)
{
if (config.debug.rhizome)
DEBUGF("c=%p c->service=%s c->name=%s c->sender=%s c->recipient=%s c->rowid_since=%"PRIu64" c->_rowid_last=%"PRIu64,
c,
alloca_str_toprint(c->service),
alloca_str_toprint(c->name),
c->is_sender_set ? alloca_tohex_sid_t(c->sender) : "UNSET",
c->is_recipient_set ? alloca_tohex_sid_t(c->recipient) : "UNSET",
c->rowid_since,
c->_rowid_last
);
DEBUGF(rhizome, "c=%p c->service=%s c->name=%s c->sender=%s c->recipient=%s c->rowid_since=%"PRIu64" c->_rowid_last=%"PRIu64,
c,
alloca_str_toprint(c->service),
alloca_str_toprint(c->name),
c->is_sender_set ? alloca_tohex_sid_t(c->sender) : "UNSET",
c->is_recipient_set ? alloca_tohex_sid_t(c->recipient) : "UNSET",
c->rowid_since,
c->_rowid_last
);
IN();
if (c->_statement == NULL && rhizome_list_open(c) == -1)
RETURN(-1);
@ -1550,9 +1541,8 @@ int rhizome_list_next(struct rhizome_list_cursor *c)
void rhizome_list_commit(struct rhizome_list_cursor *c)
{
if (config.debug.rhizome)
DEBUGF("c=%p c->rowid_since=%"PRIu64" c->_rowid_current=%"PRIu64" c->_rowid_last=%"PRIu64,
c, c->rowid_since, c->_rowid_current, c->_rowid_last);
DEBUGF(rhizome, "c=%p c->rowid_since=%"PRIu64" c->_rowid_current=%"PRIu64" c->_rowid_last=%"PRIu64,
c, c->rowid_since, c->_rowid_current, c->_rowid_last);
assert(c->_rowid_current != 0);
if (c->_rowid_last == 0 || (c->rowid_since ? c->_rowid_current > c->_rowid_last : c->_rowid_current < c->_rowid_last))
c->_rowid_last = c->_rowid_current;
@ -1560,8 +1550,7 @@ void rhizome_list_commit(struct rhizome_list_cursor *c)
void rhizome_list_release(struct rhizome_list_cursor *c)
{
if (config.debug.rhizome)
DEBUGF("c=%p", c);
DEBUGF(rhizome, "c=%p", c);
if (c->manifest) {
rhizome_manifest_free(c->manifest);
c->_rowid_current = 0;
@ -1622,8 +1611,7 @@ enum rhizome_bundle_status rhizome_find_duplicate(const rhizome_manifest *m, rhi
int r=0;
while ((r=sqlite_step_retry(&retry, statement)) == SQLITE_ROW) {
++rows;
if (config.debug.rhizome)
DEBUGF("Row %d", rows);
DEBUGF(rhizome, "Row %d", rows);
rhizome_manifest *blob_m = rhizome_new_manifest();
if (blob_m == NULL) {
ret = WHY("Out of manifests");
@ -1657,8 +1645,7 @@ enum rhizome_bundle_status rhizome_find_duplicate(const rhizome_manifest *m, rhi
if (m->authorship != AUTHOR_AUTHENTIC)
goto next;
*found = blob_m;
if (config.debug.rhizome)
DEBUGF("Found duplicate payload, %s", q_manifestid);
DEBUGF(rhizome, "Found duplicate payload, %s", q_manifestid);
ret = RHIZOME_BUNDLE_STATUS_DUPLICATE;
break;
next:
@ -1716,8 +1703,7 @@ static enum rhizome_bundle_status unpack_manifest_row(sqlite_retry_state *retry,
*/
enum rhizome_bundle_status rhizome_retrieve_manifest(const rhizome_bid_t *bidp, rhizome_manifest *m)
{
if (config.debug.rhizome)
DEBUGF("retrieve manifest bid=%s", bidp ? alloca_tohex_rhizome_bid_t(*bidp) : "<NULL>");
DEBUGF(rhizome, "retrieve manifest bid=%s", bidp ? alloca_tohex_rhizome_bid_t(*bidp) : "<NULL>");
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
sqlite3_stmt *statement = sqlite_prepare_bind(&retry,
"SELECT id, manifest, version, inserttime, author, rowid FROM manifests WHERE id = ?",

View File

@ -142,7 +142,7 @@ rhizome_direct_sync_request
if (rd_sync_handle_count>=RHIZOME_DIRECT_MAX_SYNC_HANDLES)
{
DEBUGF("Too many Rhizome Direct synchronisation policies.");
WARN("Too many Rhizome Direct synchronisation policies.");
return NULL;
}
@ -191,26 +191,26 @@ int rhizome_direct_continue_sync_request(rhizome_direct_sync_request *r)
if (r->cursor->size_high>=r->cursor->limit_size_high)
{
DEBUG("Out of bins");
DEBUG(rhizome_direct, "Out of bins");
if (cmp_rhizome_bid_t(&r->cursor->bid_low, &r->cursor->limit_bid_high) >= 0) {
DEBUG("out of BIDs");
DEBUG(rhizome_direct, "out of BIDs");
/* Sync has finished.
The transport may have initiated one or more transfers, so
we cannot declare the sync complete until we know the transport
has finished transferring. */
if (!r->bundle_transfers_in_progress) {
/* seems that all is done */
DEBUG("All done");
DEBUG(rhizome_direct, "All done");
return rhizome_direct_conclude_sync_request(r);
} else
DEBUG("Stuck on in-progress transfers");
DEBUG(rhizome_direct, "Stuck on in-progress transfers");
} else
DEBUGF("bid_low<limit_bid_high");
DEBUGF(rhizome_direct, "bid_low<limit_bid_high");
}
int count=rhizome_direct_bundle_iterator_fill(r->cursor,-1);
DEBUGF("Got %d BARs",count);
DEBUGF(rhizome_direct, "Got %d BARs",count);
r->dispatch_function(r);
@ -229,22 +229,22 @@ int rhizome_direct_conclude_sync_request(rhizome_direct_sync_request *r)
*/
if (r->interval==0) {
DEBUG("concluding one-shot");
DEBUG(rhizome_direct, "concluding one-shot");
int i;
for(i=0;i<rd_sync_handle_count;i++)
if (r==rd_sync_handles[i])
{
DEBUG("Found it");
DEBUG(rhizome_direct, "Found it");
rhizome_direct_bundle_iterator_free(&r->cursor);
free(r);
if (i!=rd_sync_handle_count-1)
rd_sync_handles[i]=rd_sync_handles[rd_sync_handle_count-1];
rd_sync_handle_count--;
DEBUGF("handle count=%d",rd_sync_handle_count);
DEBUGF(rhizome_direct, "handle count=%d",rd_sync_handle_count);
return 0;
}
DEBUGF("Couldn't find sync request handle in list.");
DEBUGF(rhizome_direct, "Couldn't find sync request handle in list.");
return -1;
}
@ -282,17 +282,17 @@ rhizome_direct_bundle_cursor *rhizome_direct_get_fill_response(unsigned char *bu
assert(c!=NULL);
if (rhizome_direct_bundle_iterator_unpickle_range(c,buffer,10))
{
DEBUGF("Couldn't unpickle range");
DEBUGF(rhizome_direct, "Couldn't unpickle range");
rhizome_direct_bundle_iterator_free(&c);
return NULL;
}
DEBUGF("unpickled size_high=%"PRId64", limit_size_high=%"PRId64,
DEBUGF(rhizome_direct, "unpickled size_high=%"PRId64", limit_size_high=%"PRId64,
c->size_high,c->limit_size_high);
DEBUGF("c->buffer_size=%zu",c->buffer_size);
DEBUGF(rhizome_direct, "c->buffer_size=%zu",c->buffer_size);
/* Get our list of BARs for the same cursor range */
int us_count=rhizome_direct_bundle_iterator_fill(c,-1);
DEBUGF("Found %d manifests in that range",us_count);
DEBUGF(rhizome_direct, "Found %d manifests in that range",us_count);
/* Transfer to a temporary buffer, so that we can overwrite
the cursor's buffer with the response data. */
@ -305,21 +305,21 @@ rhizome_direct_bundle_cursor *rhizome_direct_get_fill_response(unsigned char *bu
smaller than the 32 bytes used by BARs, therefore the response will never be
bigger than the request, and so we don't need to worry about overflows. */
int them=0,us=0;
DEBUGF("themcount=%d, uscount=%d",them_count,us_count);
DEBUGF(rhizome_direct, "themcount=%d, uscount=%d",them_count,us_count);
while(them<them_count||us<us_count)
{
DEBUGF("them=%d, us=%d",them,us);
DEBUGF(rhizome_direct, "them=%d, us=%d",them,us);
const rhizome_bar_t *their_bar = (const rhizome_bar_t *)&buffer[10+them*RHIZOME_BAR_BYTES];
const rhizome_bar_t *our_bar = (const rhizome_bar_t *)&usbuffer[10+us*RHIZOME_BAR_BYTES];
int relation=0;
if (them<them_count&&us<us_count) {
relation=memcmp(their_bar->binary,our_bar->binary,RHIZOME_BAR_COMPARE_BYTES);
DEBUGF("relation = %d",relation);
DEBUGF(rhizome_direct, "relation = %d",relation);
}
else if (us==us_count) relation=-1; /* they have a bundle we don't have */
else if (them==them_count) relation=+1; /* we have a bundle they don't have */
else {
DEBUGF("This should never happen.");
DEBUGF(rhizome_direct, "This should never happen.");
break;
}
int who=0;
@ -333,7 +333,7 @@ rhizome_direct_bundle_cursor *rhizome_direct_get_fill_response(unsigned char *bu
RHIZOME_BAR_PREFIX_BYTES);
c->buffer_used+=1+RHIZOME_BAR_PREFIX_BYTES;
who=-1;
DEBUGF("They have previously unseen bundle %016"PRIx64"*",
DEBUGF(rhizome_direct, "They have previously unseen bundle %016"PRIx64"*",
rhizome_bar_bidprefix_ll(their_bar));
} else if (relation>0) {
/* We have a bundle that they don't have any version of
@ -345,7 +345,7 @@ rhizome_direct_bundle_cursor *rhizome_direct_get_fill_response(unsigned char *bu
RHIZOME_BAR_PREFIX_BYTES);
c->buffer_used+=1+RHIZOME_BAR_PREFIX_BYTES;
who=+1;
DEBUGF("We have previously unseen bundle %016"PRIx64"*",
DEBUGF(rhizome_direct, "We have previously unseen bundle %016"PRIx64"*",
rhizome_bar_bidprefix_ll(our_bar));
} else {
/* We each have a version of this bundle, so see whose is newer */
@ -358,7 +358,7 @@ rhizome_direct_bundle_cursor *rhizome_direct_get_fill_response(unsigned char *bu
&c->buffer[c->buffer_offset_bytes+c->buffer_used+1],
RHIZOME_BAR_PREFIX_BYTES);
c->buffer_used+=1+RHIZOME_BAR_PREFIX_BYTES;
DEBUGF("They have newer version of bundle %016"PRIx64"* (%"PRIu64" versus %"PRIu64")",
DEBUGF(rhizome_direct, "They have newer version of bundle %016"PRIx64"* (%"PRIu64" versus %"PRIu64")",
rhizome_bar_bidprefix_ll(their_bar),
them_version,
us_version);
@ -369,12 +369,12 @@ rhizome_direct_bundle_cursor *rhizome_direct_get_fill_response(unsigned char *bu
&c->buffer[c->buffer_offset_bytes+c->buffer_used+1],
RHIZOME_BAR_PREFIX_BYTES);
c->buffer_used+=1+RHIZOME_BAR_PREFIX_BYTES;
DEBUGF("We have newer version of bundle %016"PRIx64"* (%"PRIu64" versus %"PRIu64")",
DEBUGF(rhizome_direct, "We have newer version of bundle %016"PRIx64"* (%"PRIu64" versus %"PRIu64")",
rhizome_bar_bidprefix_ll(our_bar),
us_version,
them_version);
} else {
DEBUGF("We both have the same version of %016"PRIx64"*",
DEBUGF(rhizome_direct, "We both have the same version of %016"PRIx64"*",
rhizome_bar_bidprefix_ll(their_bar));
}
}
@ -452,7 +452,7 @@ rhizome_manifest *rhizome_direct_get_manifest(unsigned char *bid_prefix, size_t
goto error;
}
DEBUGF("Read manifest");
DEBUGF(rhizome_direct, "Read manifest");
sqlite3_blob_close(blob);
sqlite3_finalize(statement);
return m;
@ -464,7 +464,7 @@ rhizome_manifest *rhizome_direct_get_manifest(unsigned char *bid_prefix, size_t
}
else
{
DEBUGF("no matching manifests");
DEBUGF(rhizome_direct, "no matching manifests");
sqlite3_finalize(statement);
return NULL;
}
@ -493,7 +493,7 @@ static int rhizome_sync_with_peers(int mode, int peer_count, const struct config
if (strbuf_overrun(h))
return WHYF("Rhizome Direct host name too long: %s", alloca_str_toprint(peer->host));
state->port = peer->port;
DEBUGF("Rhizome direct peer is %s://%s:%d", peer->protocol, state->host, state->port);
DEBUGF(rhizome_direct, "Rhizome direct peer is %s://%s:%d", peer->protocol, state->host, state->port);
rhizome_direct_sync_request *s = rhizome_direct_new_sync_request(rhizome_direct_http_dispatch, 65536, 0, mode, state);
rhizome_direct_start_sync_request(s);
if (rd_sync_handle_count > 0)
@ -508,15 +508,14 @@ DEFINE_CMD(app_rhizome_direct_sync, 0,
"rhizome","direct","push|pull|sync","[<url>]");
static int app_rhizome_direct_sync(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
/* Attempt to connect with a remote Rhizome Direct instance,
and negotiate which BARs to synchronise. */
const char *modeName = (parsed->argc >= 3 ? parsed->args[2] : "sync");
int mode=3; /* two-way sync */
if (!strcasecmp(modeName,"push")) mode=1; /* push only */
if (!strcasecmp(modeName,"pull")) mode=2; /* pull only */
DEBUGF("sync direction = %d",mode);
DEBUGF(rhizome_direct, "sync direction = %d",mode);
rhizome_opendb();
if (parsed->args[3]) {
struct config_rhizome_peer peer;
@ -530,7 +529,7 @@ static int app_rhizome_direct_sync(const struct cli_parsed *parsed, struct cli_c
return WHYF("Invalid peer URI %s -- %s", alloca_str_toprint(parsed->args[3]), strbuf_str(b));
}
} else if (config.rhizome.direct.peer.ac == 0) {
DEBUG("No rhizome direct peers were configured or supplied");
DEBUG(rhizome_direct, "No rhizome direct peers were configured or supplied");
return -1;
} else {
const struct config_rhizome_peer *peers[config.rhizome.direct.peer.ac];
@ -597,7 +596,7 @@ int rhizome_direct_bundle_iterator_pickle_range(rhizome_direct_bundle_cursor *r,
pickled[0]=ltwov;
for(v=0;v<4;v++) pickled[1+v]=r->start_bid_low.binary[v];
v=r->size_high;
DEBUGF("pickling size_high=%"PRId64,r->size_high);
DEBUGF(rhizome_direct, "pickling size_high=%"PRId64,r->size_high);
ltwov=0;
while(v>1) { ltwov++; v=v>>1; }
pickled[1+4]=ltwov;
@ -612,7 +611,7 @@ int rhizome_direct_bundle_iterator_unpickle_range(rhizome_direct_bundle_cursor *
{
assert(r);
if (pickle_buffer_size!=10) {
DEBUGF("pickled rhizome direct cursor ranges should be 10 bytes.");
DEBUGF(rhizome_direct, "pickled rhizome direct cursor ranges should be 10 bytes.");
return -1;
}
@ -657,7 +656,7 @@ int rhizome_direct_bundle_iterator_fill(rhizome_direct_bundle_cursor *c,int max_
if (max_bars==-1)
max_bars=(c->buffer_size-c->buffer_offset_bytes)/RHIZOME_BAR_BYTES;
DEBUGF("Iterating cursor size high %"PRId64"..%"PRId64", max_bars=%d",
DEBUGF(rhizome_direct, "Iterating cursor size high %"PRId64"..%"PRId64", max_bars=%d",
c->size_high,c->limit_size_high,max_bars);
while (bundles_stuffed<max_bars&&c->size_high<=c->limit_size_high)
@ -688,7 +687,7 @@ int rhizome_direct_bundle_iterator_fill(rhizome_direct_bundle_cursor *c,int max_
c->size_low=c->size_high+1;
c->size_high*=2;
if (c->size_high<=1024) c->size_low=0;
DEBUGF("size=%"PRId64"..%"PRId64,c->size_low,c->size_high);
DEBUGF(rhizome_direct, "size=%"PRId64"..%"PRId64,c->size_low,c->size_high);
/* Record that we covered to the end of that size bin */
c->bid_high = RHIZOME_BID_MAX;
if (c->size_high>c->limit_size_high)
@ -774,7 +773,7 @@ int rhizome_direct_get_bars(const rhizome_bid_t *bidp_low,
int ret;
int64_t filesize = sqlite3_column_int64(statement, 3);
if (filesize<size_low||filesize>size_high) {
DEBUGF("WEIRDNESS ALERT: filesize=%"PRId64", but query was: %s", filesize, sqlite3_sql(statement));
DEBUGF(rhizome_direct, "WEIRDNESS ALERT: filesize=%"PRId64", but query was: %s", filesize, sqlite3_sql(statement));
break;
}
int64_t rowid = sqlite3_column_int64(statement, 1);
@ -789,8 +788,7 @@ int rhizome_direct_get_bars(const rhizome_bid_t *bidp_low,
int blob_bytes=sqlite3_blob_bytes(blob);
if (blob_bytes!=RHIZOME_BAR_BYTES) {
if (config.debug.rhizome)
DEBUG("Found a BAR that is the wrong size - ignoring");
DEBUG(rhizome_direct, "Found a BAR that is the wrong size - ignoring");
sqlite3_blob_close(blob);
blob=NULL;
continue;

View File

@ -78,11 +78,10 @@ static int rhizome_direct_import_end(struct http_request *hr)
http_request_simple_response(&r->http, 500, "Internal Error: Buffer overrun");
return 0;
}
if (config.debug.rhizome)
DEBUGF("Call rhizome_bundle_import_files(%s, %s)",
alloca_str_toprint(manifest_path),
alloca_str_toprint(payload_path)
);
DEBUGF(rhizome, "Call rhizome_bundle_import_files(%s, %s)",
alloca_str_toprint(manifest_path),
alloca_str_toprint(payload_path)
);
enum rhizome_bundle_status status = 0;
rhizome_manifest *m = rhizome_new_manifest();
if (!m)
@ -144,8 +143,7 @@ int rhizome_direct_enquiry_end(struct http_request *hr)
http_request_simple_response(&r->http, 500, "Internal Error: Buffer overrun");
return 0;
}
if (config.debug.rhizome)
DEBUGF("Call rhizome_direct_fill_response(%s)", alloca_str_toprint(data_path));
DEBUGF(rhizome, "Call rhizome_direct_fill_response(%s)", alloca_str_toprint(data_path));
/* Read data buffer in, pass to rhizome direct for comparison with local
rhizome database, and send back responses. */
int fd = open(data_path, O_RDONLY);
@ -204,8 +202,7 @@ static int rhizome_direct_addfile_end(struct http_request *hr)
http_request_simple_response(&r->http, 500, "Internal Error: Buffer overrun");
return 0;
}
if (config.debug.rhizome)
DEBUGF("Call rhizome_store_payload_file(%s)", alloca_str_toprint(payload_path));
DEBUGF(rhizome, "Call rhizome_store_payload_file(%s)", alloca_str_toprint(payload_path));
char manifestTemplate[1024];
manifestTemplate[0] = '\0';
if (config.rhizome.api.addfile.manifest_template_file[0]) {
@ -219,8 +216,7 @@ static int rhizome_direct_addfile_end(struct http_request *hr)
http_request_simple_response(&r->http, 500, "Internal Error: Cannot read template");
return 0;
}
if (config.debug.rhizome)
DEBUGF("Using manifest template %s", alloca_str_toprint(manifestTemplate));
DEBUGF(rhizome, "Using manifest template %s", alloca_str_toprint(manifestTemplate));
}
rhizome_manifest *m = rhizome_new_manifest();
if (!m) {
@ -277,8 +273,7 @@ static int rhizome_direct_addfile_end(struct http_request *hr)
http_request_simple_response(&r->http, 500, "Internal Error: Could not finalise manifest");
return 0;
}
if (config.debug.rhizome)
DEBUGF("Import sans-manifest appeared to succeed");
DEBUGF(rhizome, "Import sans-manifest appeared to succeed");
/* Respond with the manifest that was added. */
http_request_response_static(&r->http, 200, CONTENT_TYPE_TEXT, (const char *)m->manifestdata, m->manifest_all_bytes);
/* clean up after ourselves */
@ -446,8 +441,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], (int)(buffer_len - len));
len += (size_t)count;
} while (len < buffer_len && count != 0 && !is_http_header_complete(buffer, len, len));
if (config.debug.rhizome_rx)
DEBUGF("Received HTTP response %s", alloca_toprint(-1, buffer, len));
DEBUGF(rhizome_rx, "Received HTTP response %s", alloca_toprint(-1, buffer, len));
if (unpack_http_response(buffer, parts) == -1)
return -1;
if (parts->code != 200 && parts->code != 201) {
@ -455,12 +449,10 @@ static int receive_http_response(int sock, char *buffer, size_t buffer_len, stru
return -1;
}
if (parts->content_length == HTTP_RESPONSE_CONTENT_LENGTH_UNSET) {
if (config.debug.rhizome_rx)
DEBUGF("Invalid HTTP reply: missing Content-Length header");
DEBUGF(rhizome_rx, "Invalid HTTP reply: missing Content-Length header");
return -1;
}
if (config.debug.rhizome_rx)
DEBUGF("content_length=%"PRIu64, parts->content_length);
DEBUGF(rhizome_rx, "content_length=%"PRIu64, parts->content_length);
return len - (parts->content_start - buffer);
}
@ -476,8 +468,7 @@ static int fill_buffer(int sock, unsigned char *buffer, int len, int buffer_size
void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
{
if (config.debug.rhizome_tx)
DEBUGF("Dispatch size_high=%"PRId64,r->cursor->size_high);
DEBUGF(rhizome_tx, "Dispatch size_high=%"PRId64,r->cursor->size_high);
rhizome_direct_transport_state_http *state = r->transport_specific_state;
int sock=socket(AF_INET, SOCK_STREAM, 0);
@ -489,8 +480,7 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
struct hostent *hostent;
hostent = gethostbyname(state->host);
if (!hostent) {
if (config.debug.rhizome_tx)
DEBUGF("could not resolve hostname");
DEBUGF(rhizome_tx, "could not resolve hostname");
goto end;
}
@ -544,8 +534,7 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
int len = strbuf_len(request);
int sent=0;
while(sent<len) {
if (config.debug.rhizome_tx)
DEBUGF("write(%d, %s, %d)", sock, alloca_toprint(-1, &buffer[sent], len-sent), len-sent);
DEBUGF(rhizome_tx, "write(%d, %s, %d)", sock, alloca_toprint(-1, &buffer[sent], len-sent), len-sent);
int count=write(sock,&buffer[sent],len-sent);
if (count == -1) {
if (errno==EPIPE) goto rx;
@ -575,8 +564,7 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
len = strbuf_len(request);
sent=0;
while(sent<len) {
if (config.debug.rhizome_tx)
DEBUGF("write(%d, %s, %d)", sock, alloca_toprint(-1, &buffer[sent], len-sent), len-sent);
DEBUGF(rhizome_tx, "write(%d, %s, %d)", sock, alloca_toprint(-1, &buffer[sent], len-sent), len-sent);
int count=write(sock,&buffer[sent],len-sent);
if (count == -1) {
if (errno==EPIPE) goto rx;
@ -636,8 +624,7 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
Then as noted above, we can use that to pull the file down using
existing routines.
*/
if (config.debug.rhizome_tx)
DEBUGF("Fetching manifest %s* @ 0x%x",alloca_tohex(&actionlist[i], 1+RHIZOME_BAR_PREFIX_BYTES),i);
DEBUGF(rhizome_tx, "Fetching manifest %s* @ 0x%x",alloca_tohex(&actionlist[i], 1+RHIZOME_BAR_PREFIX_BYTES),i);
if (!rhizome_fetch_request_manifest_by_prefix(&addr, NULL, &actionlist[i+1], RHIZOME_BAR_PREFIX_BYTES))
{
/* Fetching the manifest, and then using it to see if we want to
@ -659,12 +646,10 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
}
/* Get filehash and size from manifest if present */
if (config.debug.rhizome_tx) {
DEBUGF("bundle id = %s", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic));
DEBUGF("bundle filehash = %s", alloca_tohex_rhizome_filehash_t(m->filehash));
DEBUGF("file size = %"PRId64, m->filesize);
DEBUGF("version = %"PRIu64, m->version);
}
DEBUGF(rhizome_tx, "bundle id = %s", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic));
DEBUGF(rhizome_tx, "bundle filehash = %s", alloca_tohex_rhizome_filehash_t(m->filehash));
DEBUGF(rhizome_tx, "file size = %"PRId64, m->filesize);
DEBUGF(rhizome_tx, "version = %"PRIu64, m->version);
/* We now have everything we need to compose the POST request and send it.
*/
@ -682,8 +667,7 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
"Content-Type: application/octet-stream\r\n"
"\r\n";
/* Work out what the content length should be */
if (config.debug.rhizome_tx)
DEBUGF("manifest_all_bytes=%zu, manifest_body_bytes=%zu", m->manifest_all_bytes, m->manifest_body_bytes);
DEBUGF(rhizome_tx, "manifest_all_bytes=%zu, manifest_body_bytes=%zu", m->manifest_all_bytes, m->manifest_body_bytes);
assert(m->filesize != RHIZOME_SIZE_UNSET);
size_t content_length =
strlen(template2) - 2 /* minus 2 for the "%s" that gets replaced */
@ -702,13 +686,11 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
sock=socket(AF_INET, SOCK_STREAM, 0);
if (sock==-1) {
if (config.debug.rhizome_tx)
DEBUGF("could not open socket");
DEBUGF(rhizome_tx, "could not open socket");
goto closeit;
}
if (connect(sock,&addr.addr,addr.addrlen) == -1) {
if (config.debug.rhizome_tx)
DEBUGF("Could not connect to remote");
DEBUGF(rhizome_tx, "Could not connect to remote");
goto closeit;
}
@ -809,14 +791,11 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
rhizome_direct_bundle_cursor *c=rhizome_direct_bundle_iterator(10);
assert(c!=NULL);
if (rhizome_direct_bundle_iterator_unpickle_range(c,(unsigned char *)&p[0],10)) {
if (config.debug.rhizome_tx)
DEBUGF("Couldn't unpickle range. This should never happen. Assuming near and far cursor ranges match.");
DEBUGF(rhizome_tx, "Couldn't unpickle range. This should never happen. Assuming near and far cursor ranges match.");
}
else {
if (config.debug.rhizome_tx) {
DEBUGF("unpickled size_high=%"PRId64", limit_size_high=%"PRId64, c->size_high, c->limit_size_high);
DEBUGF("c->buffer_size=%d",c->buffer_size);
}
DEBUGF(rhizome_tx, "unpickled size_high=%"PRId64", limit_size_high=%"PRId64, c->size_high, c->limit_size_high);
DEBUGF(rhizome_tx, "c->buffer_size=%d",c->buffer_size);
r->cursor->size_low=c->limit_size_high;
/* Set tail of BID to all high, as we assume the far end has returned all
BIDs with the specified prefix. */

View File

@ -155,7 +155,7 @@ static const char * fetch_state(int state)
DEFINE_ALARM(rhizome_fetch_status);
void rhizome_fetch_status(struct sched_ent *alarm)
{
if (!config.debug.rhizome)
if (!IF_DEBUG(rhizome))
return;
unsigned i;
@ -173,11 +173,12 @@ void rhizome_fetch_status(struct sched_ent *alarm)
}
// if (candidates == 0 && q->active.state==RHIZOME_FETCH_FREE)
// continue;
DEBUGF("Fetch slot %d, candidates %u of %u %"PRIu64" bytes, %s %"PRIu64" of %"PRIu64,
i, candidates, q->candidate_queue_size, candidate_size,
fetch_state(q->active.state),
q->active.state==RHIZOME_FETCH_FREE?0:q->active.write_state.file_offset,
q->active.manifest?q->active.manifest->filesize:0);
DEBUGF(rhizome_rx, "Fetch slot %d, candidates %u of %u %"PRIu64" bytes, %s %"PRIu64" of %"PRIu64,
i, candidates, q->candidate_queue_size, candidate_size,
fetch_state(q->active.state),
q->active.state==RHIZOME_FETCH_FREE?0:q->active.write_state.file_offset,
q->active.manifest?q->active.manifest->filesize:0
);
}
rhizome_sync_status();
time_ms_t now = gettime_ms();
@ -318,8 +319,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 * e = &q->candidate_queue[q->candidate_queue_size - 1];
if (config.debug.rhizome_rx)
DEBUGF("insert queue[%d] candidate[%u]", (int)(q - rhizome_fetch_queues), i);
DEBUGF(rhizome_rx, "insert queue[%d] candidate[%u]", (int)(q - rhizome_fetch_queues), i);
assert(i < q->candidate_queue_size);
assert(i == 0 || c[-1].manifest);
if (e->manifest) // queue is full
@ -344,8 +344,7 @@ static void rhizome_fetch_unqueue(struct rhizome_fetch_queue *q, unsigned i)
{
assert(i < q->candidate_queue_size);
struct rhizome_fetch_candidate *c = &q->candidate_queue[i];
if (config.debug.rhizome_rx)
DEBUGF("unqueue queue[%d] candidate[%d] manifest=%p", (int)(q - rhizome_fetch_queues), i, c->manifest);
DEBUGF(rhizome_rx, "unqueue queue[%d] candidate[%d] manifest=%p", (int)(q - rhizome_fetch_queues), i, c->manifest);
if (c->manifest) {
rhizome_manifest_free(c->manifest);
c->manifest = NULL;
@ -468,11 +467,10 @@ static int rhizome_import_received_bundle(struct rhizome_manifest *m)
{
if (!rhizome_manifest_validate(m))
return 0;
if (config.debug.rhizome_rx) {
DEBUGF("manifest len=%zu has %u signatories. Associated filesize=%"PRIu64" bytes",
m->manifest_all_bytes, m->sig_count, m->filesize);
DEBUGF(rhizome_rx, "manifest len=%zu has %u signatories. Associated filesize=%"PRIu64" bytes",
m->manifest_all_bytes, m->sig_count, m->filesize);
if (IF_DEBUG(rhizome_rx))
dump("manifest", m->manifestdata, m->manifest_all_bytes);
}
enum rhizome_bundle_status status = rhizome_add_manifest(m, NULL);
switch (status) {
case RHIZOME_BUNDLE_STATUS_NEW:
@ -596,19 +594,17 @@ status_ok:
goto bail_http;
if (connect(sock, &slot->addr.addr, slot->addr.addrlen) == -1) {
if (errno == EINPROGRESS) {
if (config.debug.rhizome_rx)
DEBUGF("connect() returned EINPROGRESS");
DEBUGF(rhizome_rx, "connect() returned EINPROGRESS");
} else {
WHYF_perror("connect(%d, %s)", sock, alloca_socket_address(&slot->addr));
goto bail_http;
}
}
if (config.debug.rhizome_rx)
DEBUGF("RHIZOME HTTP REQUEST addr=%s sid=%s %s",
alloca_socket_address(&slot->addr),
slot->peer?alloca_tohex_sid_t(slot->peer->sid):"unknown",
alloca_str_toprint(slot->request)
);
DEBUGF(rhizome_rx, "RHIZOME HTTP REQUEST addr=%s sid=%s %s",
alloca_socket_address(&slot->addr),
slot->peer?alloca_tohex_sid_t(slot->peer->sid):"unknown",
alloca_str_toprint(slot->request)
);
slot->alarm.poll.fd = sock;
/* Watch for activity on the socket */
slot->alarm.poll.events = POLLIN|POLLOUT;
@ -691,19 +687,17 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m,
the cache slot number to implicitly store the first bits.
*/
if (config.debug.rhizome_rx)
DEBUGF("Fetching bundle slot=%d bid=%s version=%"PRIu64" size=%"PRIu64" addr=%s",
slotno(slot),
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic),
m->version,
m->filesize,
alloca_socket_address(addr)
);
DEBUGF(rhizome_rx, "Fetching bundle slot=%d bid=%s version=%"PRIu64" size=%"PRIu64" addr=%s",
slotno(slot),
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic),
m->version,
m->filesize,
alloca_socket_address(addr)
);
// If the payload is empty, no need to fetch, so import now.
if (m->filesize == 0) {
if (config.debug.rhizome_rx)
DEBUGF(" manifest fetch not started -- nil payload, so importing instead");
DEBUGF(rhizome_rx, " manifest fetch not started -- nil payload, so importing instead");
if (rhizome_import_received_bundle(m) == -1)
RETURN(WHY("bundle import failed"));
RETURN(IMPORTED);
@ -719,16 +713,13 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m,
if (as){
const rhizome_manifest *am = as->manifest;
if (am->version < m->version) {
if (config.debug.rhizome_rx)
DEBUGF(" fetch already in progress -- older version");
DEBUGF(rhizome_rx, " fetch already in progress -- older version");
RETURN(OLDERBUNDLE);
} else if (am->version > m->version) {
if (config.debug.rhizome_rx)
DEBUGF(" fetch already in progress -- newer version");
DEBUGF(rhizome_rx, " fetch already in progress -- newer version");
RETURN(NEWERBUNDLE);
} else {
if (config.debug.rhizome_rx)
DEBUGF(" fetch already in progress -- same version");
DEBUGF(rhizome_rx, " fetch already in progress -- same version");
RETURN(SAMEBUNDLE);
}
}
@ -738,20 +729,17 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m,
struct rhizome_fetch_slot *as = &rhizome_fetch_queues[i].active;
const rhizome_manifest *am = as->manifest;
if (as->state != RHIZOME_FETCH_FREE && cmp_rhizome_filehash_t(&m->filehash, &am->filehash) == 0) {
if (config.debug.rhizome_rx)
DEBUGF(" fetch already in progress, slot=%d filehash=%s", i, alloca_tohex_rhizome_filehash_t(m->filehash));
DEBUGF(rhizome_rx, " fetch already in progress, slot=%d filehash=%s", i, alloca_tohex_rhizome_filehash_t(m->filehash));
RETURN(SAMEPAYLOAD);
}
}
// If we already have this version or newer, do not fetch.
if (!rhizome_is_manifest_interesting(m)) {
if (config.debug.rhizome_rx)
DEBUG(" fetch not started -- already have that version or newer");
DEBUG(rhizome_rx, " fetch not started -- already have that version or newer");
RETURN(SUPERSEDED);
}
if (config.debug.rhizome_rx)
DEBUGF(" is new");
DEBUGF(rhizome_rx, " is new");
/* Prepare for fetching */
slot->addr = *addr;
@ -761,8 +749,7 @@ rhizome_fetch(struct rhizome_fetch_slot *slot, rhizome_manifest *m,
enum rhizome_start_fetch_result result = schedule_fetch(slot);
// If the payload is already available, no need to fetch, so import now.
if (result == IMPORTED) {
if (config.debug.rhizome_rx)
DEBUGF(" fetch not started - payload already present, so importing instead");
DEBUGF(rhizome_rx, " fetch not started - payload already present, so importing instead");
if (rhizome_add_manifest(m, NULL) == -1)
RETURN(WHY("add manifest failed"));
}
@ -894,13 +881,11 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sock
RETURN(0);
}
if (config.debug.rhizome_rx)
DEBUGF("Considering import bid=%s version=%"PRIu64" size=%"PRIu64,
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version, m->filesize);
DEBUGF(rhizome_rx, "Considering import bid=%s version=%"PRIu64" size=%"PRIu64,
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version, m->filesize);
if (!rhizome_is_manifest_interesting(m)) {
if (config.debug.rhizome_rx)
DEBUG(" already stored that version or newer");
DEBUG(rhizome_rx, " already stored that version or newer");
rhizome_manifest_free(m);
RETURN(-1);
}
@ -979,8 +964,7 @@ int rhizome_suggest_queue_manifest_import(rhizome_manifest *m, const struct sock
static void rhizome_fetch_close(struct rhizome_fetch_slot *slot)
{
if (config.debug.rhizome_rx)
DEBUGF("close Rhizome fetch slot=%d", slotno(slot));
DEBUGF(rhizome_rx, "close Rhizome fetch slot=%d", slotno(slot));
assert(slot->state != RHIZOME_FETCH_FREE);
/* close socket and stop watching it */
@ -1018,7 +1002,7 @@ static void rhizome_fetch_mdp_slot_callback(struct sched_ent *alarm)
time_ms_t now = gettime_ms();
if (now - slot->last_write_time > slot->mdpIdleTimeout) {
DEBUGF("MDP connection timed out: last RX %"PRId64"ms ago (read %"PRId64" of %"PRId64" bytes)",
DEBUGF(rhizome_rx, "MDP connection timed out: last RX %"PRId64"ms ago (read %"PRId64" of %"PRId64" bytes)",
now-slot->last_write_time,
slot->write_state.file_offset,
slot->write_state.file_length);
@ -1026,10 +1010,9 @@ static void rhizome_fetch_mdp_slot_callback(struct sched_ent *alarm)
OUT();
return;
}
if (config.debug.rhizome_rx)
DEBUGF("Timeout: Resending request for slot=0x%p (%"PRIu64" of %"PRIu64" received)",
slot, slot->write_state.file_offset,
slot->write_state.file_length);
DEBUGF(rhizome_rx, "Timeout: Resending request for slot=0x%p (%"PRIu64" of %"PRIu64" received)",
slot, slot->write_state.file_offset,
slot->write_state.file_length);
rhizome_fetch_mdp_requestblocks(slot);
OUT();
}
@ -1094,12 +1077,11 @@ static int rhizome_fetch_mdp_requestblocks(struct rhizome_fetch_slot *slot)
ob_append_ui32_rv(payload, bitmap);
ob_append_ui16_rv(payload, slot->mdpRXBlockLength);
if (config.debug.rhizome_tx)
DEBUGF("src sid=%s, dst sid=%s, mdpRXWindowStart=0x%"PRIx64", slot->bidVersion=0x%"PRIx64,
alloca_tohex_sid_t(header.source->sid),
alloca_tohex_sid_t(header.destination->sid),
slot->write_state.file_offset,
slot->bidVersion);
DEBUGF(rhizome_tx, "src sid=%s, dst sid=%s, mdpRXWindowStart=0x%"PRIx64", slot->bidVersion=0x%"PRIx64,
alloca_tohex_sid_t(header.source->sid),
alloca_tohex_sid_t(header.destination->sid),
slot->write_state.file_offset,
slot->bidVersion);
ob_flip(payload);
overlay_send_frame(&header, payload);
@ -1136,8 +1118,7 @@ static int pipe_journal(struct rhizome_fetch_slot *slot){
// of course there might not be any overlap
if (start < slot->previous->filesize && length>0){
if (config.debug.rhizome)
DEBUGF("Copying %"PRId64" bytes from previous journal", length);
DEBUGF(rhizome, "Copying %"PRId64" bytes from previous journal", length);
rhizome_journal_pipe(&slot->write_state, &slot->previous->filehash, start, length);
}
@ -1164,14 +1145,13 @@ static enum rhizome_start_fetch_result rhizome_fetch_switch_to_mdp(struct rhizom
RETURN(-1);
}
if (!my_subscriber) {
DEBUGF("I don't have an identity, so we cannot fall back to MDP");
WARN("I don't have an identity, so we cannot fall back to MDP");
rhizome_fetch_close(slot);
RETURN(-1);
}
if (config.debug.rhizome_rx)
DEBUGF("Trying to switch to MDP for Rhizome fetch: slot=0x%p (%"PRIu64" bytes)",
slot, slot->write_state.file_length);
DEBUGF(rhizome_rx, "Trying to switch to MDP for Rhizome fetch: slot=0x%p (%"PRIu64" bytes)",
slot, slot->write_state.file_length);
/* close socket and stop watching it */
if (slot->alarm.poll.fd>=0) {
@ -1223,8 +1203,7 @@ static enum rhizome_start_fetch_result rhizome_fetch_switch_to_mdp(struct rhizom
void rhizome_fetch_write(struct rhizome_fetch_slot *slot)
{
IN();
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(rhizome_rx, "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);
if (bytes == -1) {
WHY("Got error while sending HTTP request.");
@ -1261,8 +1240,7 @@ static int rhizome_write_complete(struct rhizome_fetch_slot *slot)
RETURN(0);
// Were fetching payload, now we have it.
if (config.debug.rhizome_rx)
DEBUGF("Received all of file via rhizome -- now to import it");
DEBUGF(rhizome_rx, "Received all of file via rhizome -- now to import it");
enum rhizome_payload_status status = rhizome_finish_write(&slot->write_state);
if (status != RHIZOME_PAYLOAD_STATUS_EMPTY && status != RHIZOME_PAYLOAD_STATUS_NEW) {
@ -1286,8 +1264,7 @@ static int rhizome_write_complete(struct rhizome_fetch_slot *slot)
}
} else {
/* This was to fetch the manifest, so now fetch the file if needed */
if (config.debug.rhizome_rx)
DEBUGF("Received a manifest in response to supplying a manifest prefix.");
DEBUGF(rhizome_rx, "Received a manifest in response to supplying a manifest prefix.");
/* Read the manifest and add it to suggestion queue, then immediately
call schedule queued items. */
rhizome_manifest *m = rhizome_new_manifest();
@ -1297,26 +1274,25 @@ static int rhizome_write_complete(struct rhizome_fetch_slot *slot)
if ( rhizome_manifest_parse(m) == -1
|| !rhizome_manifest_validate(m)
) {
DEBUGF("Couldn't read manifest");
DEBUGF(rhizome_rx, "Couldn't read manifest");
rhizome_manifest_free(m);
} else {
if (config.debug.rhizome_rx){
DEBUGF("All looks good for importing manifest id=%s, addr=%s, sid=%s",
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic),
alloca_socket_address(&slot->addr),
slot->peer?alloca_tohex_sid_t(slot->peer->sid):"unknown");
}
DEBUGF(rhizome_rx, "All looks good for importing manifest id=%s, addr=%s, sid=%s",
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic),
alloca_socket_address(&slot->addr),
slot->peer?alloca_tohex_sid_t(slot->peer->sid):"unknown"
);
rhizome_suggest_queue_manifest_import(m, &slot->addr, slot->peer);
}
}
}
if (config.debug.rhizome_rx) {
if (IF_DEBUG(rhizome_rx)) {
time_ms_t now = gettime_ms();
time_ms_t interval = now - slot->start_time;
if (interval <= 0)
interval = 1;
DEBUGF("Closing rhizome fetch slot = 0x%p. Received %"PRIu64" bytes in %"PRIu64"ms (%"PRIu64"KB/sec).",
DEBUGF(rhizome_rx, "Closing rhizome fetch slot = 0x%p. Received %"PRIu64" bytes in %"PRIu64"ms (%"PRIu64"KB/sec).",
slot, slot->write_state.file_offset,
(uint64_t)interval,
slot->write_state.file_offset / (uint64_t)interval
@ -1377,17 +1353,14 @@ int rhizome_received_content(const unsigned char *bidprefix,
struct rhizome_fetch_slot *slot=fetch_search_slot(bidprefix, 16);
if (slot && slot->bidVersion == version && slot->state == RHIZOME_FETCH_RXFILEMDP){
if (config.debug.rhizome)
DEBUGF("Rhizome over MDP receiving %zu bytes.", count);
DEBUGF(rhizome, "Rhizome over MDP receiving %zu bytes.", count);
if (rhizome_random_write(&slot->write_state, offset, bytes, count)){
if (config.debug.rhizome)
DEBUGF("Write failed!");
DEBUGF(rhizome, "Write failed!");
RETURN (-1);
}
if (rhizome_write_complete(slot)){
if (config.debug.rhizome)
DEBUGF("Complete failed!");
DEBUGF(rhizome, "Complete failed!");
RETURN(-1);
}
@ -1469,17 +1442,15 @@ void rhizome_fetch_poll(struct sched_ent *alarm)
return;
} else {
if (errno!=EAGAIN) {
if (config.debug.rhizome_rx)
DEBUGF("Empty read, closing connection: received %"PRIu64" of %"PRIu64" bytes",
slot->write_state.file_offset,
slot->write_state.file_length);
DEBUGF(rhizome_rx, "Empty read, closing connection: received %"PRIu64" of %"PRIu64" bytes",
slot->write_state.file_offset,
slot->write_state.file_length);
rhizome_fetch_switch_to_mdp(slot);
}
return;
}
if (sigPipeFlag) {
if (config.debug.rhizome_rx)
DEBUG("Received SIGPIPE, closing connection");
DEBUG(rhizome_rx, "Received SIGPIPE, closing connection");
rhizome_fetch_switch_to_mdp(slot);
return;
}
@ -1498,26 +1469,22 @@ void rhizome_fetch_poll(struct sched_ent *alarm)
schedule(&slot->alarm);
slot->request_len += bytes;
if (is_http_header_complete(slot->request, slot->request_len, bytes)) {
if (config.debug.rhizome_rx)
DEBUGF("Got HTTP reply: %s", alloca_toprint(160, slot->request, slot->request_len));
DEBUGF(rhizome_rx, "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
content. */
struct http_response_parts parts;
if (unpack_http_response(slot->request, &parts) == -1) {
if (config.debug.rhizome_rx)
DEBUGF("Failed HTTP request: failed to unpack http response");
DEBUGF(rhizome_rx, "Failed HTTP request: failed to unpack http response");
rhizome_fetch_switch_to_mdp(slot);
return;
}
if (parts.code != 200 && parts.code != 206) {
if (config.debug.rhizome_rx)
DEBUGF("Failed HTTP request: rhizome server returned %03u", parts.code);
DEBUGF(rhizome_rx, "Failed HTTP request: rhizome server returned %03u", parts.code);
rhizome_fetch_switch_to_mdp(slot);
return;
}
if (parts.content_length == HTTP_RESPONSE_CONTENT_LENGTH_UNSET) {
if (config.debug.rhizome_rx)
DEBUGF("Invalid HTTP reply: missing Content-Length header");
DEBUGF(rhizome_rx, "Invalid HTTP reply: missing Content-Length header");
rhizome_fetch_switch_to_mdp(slot);
return;
}
@ -1566,8 +1533,7 @@ void rhizome_fetch_poll(struct sched_ent *alarm)
default:
// timeout or socket error, close the socket
if (config.debug.rhizome_rx)
DEBUGF("Closing due to timeout or error %x (%x %x)", alarm->poll.revents, POLLHUP, POLLERR);
DEBUGF(rhizome_rx, "Closing due to timeout or error %x (%x %x)", alarm->poll.revents, POLLHUP, POLLERR);
if (slot->state!=RHIZOME_FETCH_FREE&&slot->state!=RHIZOME_FETCH_RXFILEMDP)
rhizome_fetch_switch_to_mdp(slot);
}
@ -1597,13 +1563,11 @@ int unpack_http_response(char *response, struct http_response_parts *parts)
parts->content_start = NULL;
char *p = NULL;
if (!str_startswith(response, "HTTP/1.0 ", (const char **)&p)) {
if (config.debug.rhizome_rx)
DEBUGF("Malformed HTTP reply: missing HTTP/1.0 preamble");
DEBUGF(rhizome_rx, "Malformed HTTP reply: missing HTTP/1.0 preamble");
RETURN(-1);
}
if (!(isdigit(p[0]) && isdigit(p[1]) && isdigit(p[2]) && p[3] == ' ')) {
if (config.debug.rhizome_rx)
DEBUGF("Malformed HTTP reply: missing three-digit status code");
DEBUGF(rhizome_rx, "Malformed HTTP reply: missing three-digit status code");
RETURN(-1);
}
parts->code = (p[0]-'0') * 100 + (p[1]-'0') * 10 + p[2]-'0';
@ -1621,8 +1585,7 @@ int unpack_http_response(char *response, struct http_response_parts *parts)
while (isdigit(*p))
parts->range_start = parts->range_start * 10 + *p++ - '0';
if (p == nump) {
if (config.debug.rhizome_rx)
DEBUGF("Invalid HTTP reply: malformed Content-Range header");
DEBUGF(rhizome_rx, "Invalid HTTP reply: malformed Content-Range header");
RETURN(-1);
}
}
@ -1634,8 +1597,7 @@ int unpack_http_response(char *response, struct http_response_parts *parts)
while (isdigit(*p))
parts->content_length = parts->content_length * 10 + *p++ - '0';
if (p == nump || (*p != '\r' && *p != '\n')) {
if (config.debug.rhizome_rx)
DEBUGF("Invalid HTTP reply: malformed Content-Length header");
DEBUGF(rhizome_rx, "Invalid HTTP reply: malformed Content-Length header");
RETURN(-1);
}
}

View File

@ -163,9 +163,8 @@ int rhizome_advertise_manifest(struct subscriber *dest, rhizome_manifest *m){
ob_append_byte(frame->payload, 0xFF);
if (overlay_payload_enqueue(frame) == -1)
goto error;
if (config.debug.rhizome_ads)
DEBUGF("Advertising manifest %s %"PRIu64" to %s",
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version, dest?alloca_tohex_sid_t(dest->sid):"broadcast");
DEBUGF(rhizome_ads, "Advertising manifest %s %"PRIu64" to %s",
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version, dest?alloca_tohex_sid_t(dest->sid):"broadcast");
return 0;
error:
op_free(frame);
@ -226,27 +225,23 @@ int overlay_rhizome_saw_advertisements(struct decode_context *context, struct ov
// Briefly inspect the manifest to see if it looks interesting.
struct rhizome_manifest_summary summ;
if (!rhizome_manifest_inspect((char *)data, manifest_length, &summ)) {
if (config.debug.rhizome_ads)
DEBUG("Ignoring manifest that looks malformed");
DEBUG(rhizome_ads, "Ignoring manifest that looks malformed");
goto next;
}
if (config.debug.rhizome_ads)
DEBUGF("manifest id=%s version=%"PRIu64, alloca_tohex_rhizome_bid_t(summ.bid), summ.version);
DEBUGF(rhizome_ads, "manifest id=%s version=%"PRIu64, alloca_tohex_rhizome_bid_t(summ.bid), summ.version);
// If it looks like there is no signature at all, ignore the announcement but don't brown-list
// the manifest ID, so that we will still process other offers of the same manifest with
// signatures.
if (summ.body_len == manifest_length) {
if (config.debug.rhizome_ads)
DEBUG("Ignoring manifest announcment with no signature");
DEBUG(rhizome_ads, "Ignoring manifest announcment with no signature");
goto next;
}
if (rhizome_ignore_manifest_check(summ.bid.binary, sizeof summ.bid.binary)){
/* Ignoring manifest that has caused us problems recently */
if (config.debug.rhizome_ads)
DEBUGF("Ignoring manifest with errors bid=%s", alloca_tohex_rhizome_bid_t(summ.bid));
DEBUGF(rhizome_ads, "Ignoring manifest with errors bid=%s", alloca_tohex_rhizome_bid_t(summ.bid));
goto next;
}
@ -350,8 +345,7 @@ next:
payload = ob_new();
}
if (config.debug.rhizome)
DEBUGF("Requesting manifest for BAR %s", alloca_tohex_rhizome_bar_t(bars[index]));
DEBUGF(rhizome, "Requesting manifest for BAR %s", alloca_tohex_rhizome_bar_t(bars[index]));
ob_append_bytes(payload, bars[index]->binary, RHIZOME_BAR_BYTES);
}
}

View File

@ -591,35 +591,30 @@ static int insert_mime_part_end(struct http_request *hr)
)
return http_response_form_part(r, "Invalid", PART_AUTHOR, r->u.insert.author_hex, r->u.insert.author_hex_len);
r->u.insert.received_author = 1;
if (config.debug.rhizome)
DEBUGF("received %s = %s", PART_AUTHOR, alloca_tohex_sid_t(r->u.insert.author));
DEBUGF(rhizome, "received %s = %s", PART_AUTHOR, alloca_tohex_sid_t(r->u.insert.author));
}
else if (r->u.insert.current_part == PART_SECRET) {
if (strn_to_rhizome_bsk_t(&r->u.insert.bundle_secret, r->u.insert.secret_text, r->u.insert.secret_text_len) == -1)
return http_response_form_part(r, "Invalid", PART_SECRET, r->u.insert.secret_text, r->u.insert.secret_text_len);
r->u.insert.received_secret = 1;
if (config.debug.rhizome)
DEBUGF("received %s = %s", PART_SECRET, alloca_tohex_rhizome_bk_t(r->u.insert.bundle_secret));
DEBUGF(rhizome, "received %s = %s", PART_SECRET, alloca_tohex_rhizome_bk_t(r->u.insert.bundle_secret));
}
else if (r->u.insert.current_part == PART_BUNDLEID) {
if (strn_to_rhizome_bid_t(&r->bid, r->u.insert.bid_text, r->u.insert.bid_text_len) == -1)
return http_response_form_part(r, "Invalid", PART_BUNDLEID, r->u.insert.secret_text, r->u.insert.secret_text_len);
r->u.insert.received_bundleid = 1;
if (config.debug.rhizome)
DEBUGF("received %s = %s", PART_BUNDLEID, alloca_tohex_rhizome_bid_t(r->bid));
DEBUGF(rhizome, "received %s = %s", PART_BUNDLEID, alloca_tohex_rhizome_bid_t(r->bid));
}
else if (r->u.insert.current_part == PART_MANIFEST) {
r->u.insert.received_manifest = 1;
if (config.debug.rhizome)
DEBUGF("received %s = %s", PART_MANIFEST, alloca_toprint(-1, r->u.insert.manifest.buffer, r->u.insert.manifest.length));
DEBUGF(rhizome, "received %s = %s", PART_MANIFEST, alloca_toprint(-1, r->u.insert.manifest.buffer, r->u.insert.manifest.length));
int result = insert_make_manifest(r);
if (result)
return result;
}
else if (r->u.insert.current_part == PART_PAYLOAD) {
r->u.insert.received_payload = 1;
if (config.debug.rhizome)
DEBUGF("received %s, %zd bytes", PART_PAYLOAD, r->u.insert.payload_size);
DEBUGF(rhizome, "received %s, %zd bytes", PART_PAYLOAD, r->u.insert.payload_size);
r->payload_status = rhizome_finish_write(&r->u.insert.write);
} else
FATALF("current_part = %s", alloca_str_toprint(r->u.insert.current_part));
@ -636,8 +631,7 @@ static int restful_rhizome_insert_end(struct http_request *hr)
return http_response_form_part(r, "Missing", PART_PAYLOAD, NULL, 0);
// Fill in the missing manifest fields and ensure payload and manifest are consistent.
assert(r->manifest != NULL);
if (config.debug.rhizome)
DEBUGF("r->payload_status=%d %s", r->payload_status, rhizome_payload_status_message(r->payload_status));
DEBUGF(rhizome, "r->payload_status=%d %s", r->payload_status, rhizome_payload_status_message(r->payload_status));
assert(r->u.insert.write.file_length != RHIZOME_SIZE_UNSET);
if (r->u.insert.appending) {
// For journal appends, the user cannot supply a 'filesize' field. This will have been caught
@ -645,8 +639,7 @@ static int restful_rhizome_insert_end(struct http_request *hr)
// size should be the sum of 'filesize' and the appended portion.
assert(r->manifest->is_journal);
assert(r->manifest->filesize != RHIZOME_SIZE_UNSET);
if (config.debug.rhizome)
DEBUGF("file_length=%"PRIu64" filesize=%"PRIu64" payload_size=%"PRIu64,
DEBUGF(rhizome, "file_length=%"PRIu64" filesize=%"PRIu64" payload_size=%"PRIu64,
r->u.insert.write.file_length,
r->manifest->filesize,
r->u.insert.payload_size);
@ -715,8 +708,7 @@ static int restful_rhizome_insert_end(struct http_request *hr)
rhizome_manifest *mout = NULL;
r->bundle_status = rhizome_manifest_finalise(r->manifest, &mout, !r->u.insert.force_new);
int result = 500;
if (config.debug.rhizome)
DEBUGF("r->bundle_status=%d", r->bundle_status);
DEBUGF(rhizome, "r->bundle_status=%d", r->bundle_status);
switch (r->bundle_status) {
case RHIZOME_BUNDLE_STATUS_NEW:
if (mout && mout != r->manifest)

View File

@ -80,8 +80,7 @@ static uint64_t rhizome_create_fileblob(sqlite_retry_state *retry, uint64_t id,
return 0;
}
uint64_t rowid = sqlite3_last_insert_rowid(rhizome_db);
if (config.debug.rhizome_store)
DEBUGF("Inserted fileblob rowid=%"PRId64" for id='%"PRIu64"'", rowid, id);
DEBUGF(rhizome_store, "Inserted fileblob rowid=%"PRId64" for id='%"PRIu64"'", rowid, id);
return rowid;
}
@ -96,8 +95,7 @@ static int rhizome_delete_external(const char *id)
return WHYF_perror("unlink(%s)", alloca_str_toprint(blob_path));
return 1;
}
if (config.debug.rhizome_store)
DEBUGF("Deleted blob file %s", blob_path);
DEBUGF(rhizome_store, "Deleted blob file %s", blob_path);
return 0;
}
@ -230,9 +228,8 @@ static enum rhizome_payload_status store_make_space(uint64_t bytes, struct rhizo
const uint64_t limit = store_space_limit(db_used);
if (bytes && bytes >= limit){
if (config.debug.rhizome)
DEBUGF("Not enough space for %"PRIu64". Used; %"PRIu64" = %"PRIu64" + %"PRIu64" * (%"PRIu64" - %"PRIu64"), Limit; %"PRIu64,
bytes, db_used, external_bytes, db_page_size, db_page_count, db_free_page_count, limit);
DEBUGF(rhizome, "Not enough space for %"PRIu64". Used; %"PRIu64" = %"PRIu64" + %"PRIu64" * (%"PRIu64" - %"PRIu64"), Limit; %"PRIu64,
bytes, db_used, external_bytes, db_page_size, db_page_count, db_free_page_count, limit);
return RHIZOME_PAYLOAD_STATUS_TOO_BIG;
}
@ -262,9 +259,8 @@ static enum rhizome_payload_status store_make_space(uint64_t bytes, struct rhizo
time_ms_t cost_existing = inserttime - length;
if (config.debug.rhizome)
DEBUGF("Considering dropping file %s, size %"PRId64" cost %"PRId64" vs %"PRId64" to add %"PRId64" new bytes",
id, length, cost, cost_existing, bytes);
DEBUGF(rhizome, "Considering dropping file %s, size %"PRId64" cost %"PRId64" vs %"PRId64" to add %"PRId64" new bytes",
id, length, cost, cost_existing, bytes);
// don't allow the new file, we've got more important things to store
if (bytes && cost < cost_existing)
break;
@ -294,9 +290,8 @@ static enum rhizome_payload_status store_make_space(uint64_t bytes, struct rhizo
return RHIZOME_PAYLOAD_STATUS_NEW;
if (sqlite_code_ok(r)){
if (config.debug.rhizome)
DEBUGF("Not enough space for %"PRIu64". Used; %"PRIu64" = %"PRIu64" + %"PRIu64" * (%"PRIu64" - %"PRIu64"), Limit; %"PRIu64,
bytes, db_used, external_bytes, db_page_size, db_page_count, db_free_page_count, limit);
DEBUGF(rhizome, "Not enough space for %"PRIu64". Used; %"PRIu64" = %"PRIu64" + %"PRIu64" * (%"PRIu64" - %"PRIu64"), Limit; %"PRIu64,
bytes, db_used, external_bytes, db_page_size, db_page_count, db_free_page_count, limit);
return RHIZOME_PAYLOAD_STATUS_EVICTED;
}
@ -310,8 +305,7 @@ int rhizome_store_cleanup(struct rhizome_cleanup_report *report)
enum rhizome_payload_status rhizome_open_write(struct rhizome_write *write, const rhizome_filehash_t *expectedHashp, uint64_t file_length)
{
if (config.debug.rhizome_store)
DEBUGF("file_length=%"PRIu64, file_length);
DEBUGF(rhizome_store, "file_length=%"PRIu64, file_length);
if (file_length == 0)
return RHIZOME_PAYLOAD_STATUS_EMPTY;
@ -372,8 +366,7 @@ static int prepare_data(struct rhizome_write *write_state, uint8_t *buffer, size
SHA512_Update(&write_state->sha512_context, buffer, data_size);
write_state->file_offset+=data_size;
if (config.debug.rhizome_store)
DEBUGF("Processed %"PRIu64" of %"PRIu64, write_state->file_offset, write_state->file_length);
DEBUGF(rhizome_store, "Processed %"PRIu64" of %"PRIu64, write_state->file_offset, write_state->file_length);
return 0;
}
@ -390,14 +383,12 @@ static int write_get_lock(struct rhizome_write *write_state)
char blob_path[1024];
if (!FORMF_RHIZOME_STORE_PATH(blob_path, "%s/%"PRIu64, RHIZOME_BLOB_SUBDIR, write_state->temp_id))
return -1;
if (config.debug.rhizome_store)
DEBUGF("Attempting to put blob for id='%"PRIu64"' in %s", write_state->temp_id, blob_path);
DEBUGF(rhizome_store, "Attempting to put blob for id='%"PRIu64"' in %s", write_state->temp_id, blob_path);
if ((write_state->blob_fd = open(blob_path, O_CREAT | O_TRUNC | O_RDWR, 0664)) == -1) {
WHYF("Failed to create payload file, id='%"PRIu64"'", write_state->temp_id);
return -1;
}
if (config.debug.rhizome_store)
DEBUGF("Writing to new blob file %s (fd=%d)", blob_path, write_state->blob_fd);
DEBUGF(rhizome_store, "Writing to new blob file %s (fd=%d)", blob_path, write_state->blob_fd);
}else{
// use an explicit transaction so we can delay I/O failures until COMMIT so they can be retried.
if (sqlite_exec_void_retry(&retry, "BEGIN TRANSACTION;", END) == -1)
@ -420,8 +411,7 @@ fail:
// write data to disk
static int write_data(struct rhizome_write *write_state, uint64_t file_offset, uint8_t *buffer, size_t data_size)
{
if (config.debug.rhizome_store)
DEBUGF("write_state->file_length=%"PRIu64" file_offset=%"PRIu64, write_state->file_length, file_offset);
DEBUGF(rhizome_store, "write_state->file_length=%"PRIu64" file_offset=%"PRIu64, write_state->file_length, file_offset);
if (data_size<=0)
return 0;
@ -438,8 +428,7 @@ static int write_data(struct rhizome_write *write_state, uint64_t file_offset, u
ssize_t r = write(write_state->blob_fd, buffer + ofs, (size_t)(data_size - ofs));
if (r == -1)
return WHY_perror("write");
if (config.debug.rhizome_store)
DEBUGF("Wrote %zd bytes to fd %d", (size_t)r, write_state->blob_fd);
DEBUGF(rhizome_store, "Wrote %zd bytes to fd %d", (size_t)r, write_state->blob_fd);
ofs += (size_t)r;
}
}else{
@ -452,8 +441,7 @@ static int write_data(struct rhizome_write *write_state, uint64_t file_offset, u
write_state->written_offset = file_offset + data_size;
if (config.debug.rhizome_store)
DEBUGF("Wrote %"PRIu64" of %"PRIu64, file_offset + data_size, write_state->file_length);
DEBUGF(rhizome_store, "Wrote %"PRIu64" of %"PRIu64, file_offset + data_size, write_state->file_length);
return 0;
}
@ -475,8 +463,7 @@ static int write_release_lock(struct rhizome_write *write_state)
// Though there is an upper bound on the amount of cached data
int rhizome_random_write(struct rhizome_write *write_state, uint64_t offset, uint8_t *buffer, size_t data_size)
{
if (config.debug.rhizome_store)
DEBUGF("write_state->file_length=%"PRIu64" offset=%"PRIu64, write_state->file_length, offset);
DEBUGF(rhizome_store, "write_state->file_length=%"PRIu64" offset=%"PRIu64, write_state->file_length, offset);
if ( write_state->file_length != RHIZOME_SIZE_UNSET
&& offset >= write_state->file_length)
return 0;
@ -497,10 +484,9 @@ int rhizome_random_write(struct rhizome_write *write_state, uint64_t offset, uin
write_state->file_length > config.rhizome.max_blob_size ||
write_state->file_offset > config.rhizome.max_blob_size) {
should_write = 1;
if (config.debug.rhizome_store)
DEBUGF("Attempting to write (fd=%d, blob=%p, buffer=%p, len=%"PRId64", offset=%"PRId64")",
write_state->blob_fd, write_state->sql_blob, buffer,
write_state->file_length, write_state->file_offset);
DEBUGF(rhizome_store, "Attempting to write (fd=%d, blob=%p, buffer=%p, len=%"PRId64", offset=%"PRId64")",
write_state->blob_fd, write_state->sql_blob, buffer,
write_state->file_length, write_state->file_offset);
} else {
// cache up to RHIZOME_BUFFER_MAXIMUM_SIZE or file length before attempting to write everything in one go.
// (Not perfect if the range overlaps)
@ -587,8 +573,7 @@ int rhizome_random_write(struct rhizome_write *write_state, uint64_t offset, uin
if (size<=0)
break;
if (config.debug.rhizome_store)
DEBUGF("Caching block @%"PRId64", %zu", offset, size);
DEBUGF(rhizome_store, "Caching block @%"PRId64", %zu", offset, size);
struct rhizome_write_buffer *i = emalloc(size + sizeof(struct rhizome_write_buffer));
if (!i){
ret=-1;
@ -661,8 +646,7 @@ int rhizome_write_file(struct rhizome_write *write, const char *filename)
void rhizome_fail_write(struct rhizome_write *write)
{
if (write->blob_fd != -1){
if (config.debug.rhizome_store)
DEBUGF("Closing and removing fd %d", write->blob_fd);
DEBUGF(rhizome_store, "Closing and removing fd %d", write->blob_fd);
close(write->blob_fd);
write->blob_fd=-1;
char blob_path[1024];
@ -684,15 +668,13 @@ void rhizome_fail_write(struct rhizome_write *write)
enum rhizome_payload_status rhizome_finish_write(struct rhizome_write *write)
{
if (config.debug.rhizome_store)
DEBUGF("blob_fd=%d file_offset=%"PRIu64"", write->blob_fd, write->file_offset);
DEBUGF(rhizome_store, "blob_fd=%d file_offset=%"PRIu64"", write->blob_fd, write->file_offset);
enum rhizome_payload_status status = RHIZOME_PAYLOAD_STATUS_NEW;
// Once the whole file has been processed, we should finally know its length
if (write->file_length == RHIZOME_SIZE_UNSET) {
if (config.debug.rhizome_store)
DEBUGF("Wrote %"PRIu64" bytes, set file_length", write->file_offset);
DEBUGF(rhizome_store, "Wrote %"PRIu64" bytes, set file_length", write->file_offset);
write->file_length = write->file_offset;
if (write->file_length == 0)
status = RHIZOME_PAYLOAD_STATUS_EMPTY;
@ -725,8 +707,7 @@ enum rhizome_payload_status rhizome_finish_write(struct rhizome_write *write)
if (write->file_length == 0) {
// whoops, no payload, don't store anything
if (config.debug.rhizome_store)
DEBUGF("Ignoring empty write");
DEBUGF(rhizome_store, "Ignoring empty write");
goto failure;
}
@ -756,8 +737,7 @@ enum rhizome_payload_status rhizome_finish_write(struct rhizome_write *write)
if (write->blob_fd != -1) {
external = 1;
if (write->file_length <= config.rhizome.max_blob_size) {
if (config.debug.rhizome_store)
DEBUGF("Copying %zu bytes from external file %s into blob, id=%"PRIu64, (size_t)write->file_offset, blob_path, write->temp_id);
DEBUGF(rhizome_store, "Copying %zu bytes from external file %s into blob, id=%"PRIu64, (size_t)write->file_offset, blob_path, write->temp_id);
int ret = 0;
if (lseek(write->blob_fd, 0, SEEK_SET) == (off_t) -1)
ret = WHYF_perror("lseek(%d,0,SEEK_SET)", write->blob_fd);
@ -771,8 +751,7 @@ enum rhizome_payload_status rhizome_finish_write(struct rhizome_write *write)
WARNF_perror("unlink(%s)", alloca_str_toprint(blob_path));
}
}
if (config.debug.rhizome_store)
DEBUGF("Closing fd=%d", write->blob_fd);
DEBUGF(rhizome_store, "Closing fd=%d", write->blob_fd);
close(write->blob_fd);
write->blob_fd = -1;
}
@ -793,8 +772,7 @@ enum rhizome_payload_status rhizome_finish_write(struct rhizome_write *write)
if (unlink(blob_path) == -1)
WARNF_perror("unlink(%s)", alloca_str_toprint(blob_path));
}
if (config.debug.rhizome_store)
DEBUGF("Payload id=%s already present, removed id='%"PRIu64"'", alloca_tohex_rhizome_filehash_t(write->id), write->temp_id);
DEBUGF(rhizome_store, "Payload id=%s already present, removed id='%"PRIu64"'", alloca_tohex_rhizome_filehash_t(write->id), write->temp_id);
status = RHIZOME_PAYLOAD_STATUS_STORED;
}else{
if (sqlite_exec_void_retry(&retry, "BEGIN TRANSACTION;", END) == -1)
@ -822,8 +800,7 @@ enum rhizome_payload_status rhizome_finish_write(struct rhizome_write *write)
WHYF_perror("rename(%s, %s)", blob_path, dest_path);
goto dbfailure;
}
if (config.debug.rhizome_store)
DEBUGF("Renamed %s to %s", blob_path, dest_path);
DEBUGF(rhizome_store, "Renamed %s to %s", blob_path, dest_path);
}else{
if (sqlite_exec_void_retry(
&retry,
@ -837,8 +814,7 @@ enum rhizome_payload_status rhizome_finish_write(struct rhizome_write *write)
}
if (sqlite_exec_void_retry(&retry, "COMMIT;", END) == -1)
goto dbfailure;
if (config.debug.rhizome_store)
DEBUGF("Stored file %s", alloca_tohex_rhizome_filehash_t(write->id));
DEBUGF(rhizome_store, "Stored file %s", alloca_tohex_rhizome_filehash_t(write->id));
}
write->blob_rowid = 0;
return status;
@ -930,9 +906,8 @@ enum rhizome_payload_status rhizome_stat_payload_file(rhizome_manifest *m, const
if (m->filesize == RHIZOME_SIZE_UNSET)
rhizome_manifest_set_filesize(m, size);
else if (size != m->filesize) {
if (config.debug.rhizome_store)
DEBUGF("payload file %s (size=%"PRIu64") does not match manifest[%d].filesize=%"PRIu64,
alloca_str_toprint(filepath), size, m->manifest_record_number, m->filesize);
DEBUGF(rhizome_store, "payload file %s (size=%"PRIu64") does not match manifest[%d].filesize=%"PRIu64,
alloca_str_toprint(filepath), size, m->manifest_record_number, m->filesize);
return RHIZOME_PAYLOAD_STATUS_WRONG_SIZE;
}
return size ? RHIZOME_PAYLOAD_STATUS_NEW : RHIZOME_PAYLOAD_STATUS_EMPTY;
@ -948,9 +923,8 @@ static enum rhizome_payload_status rhizome_write_derive_key(rhizome_manifest *m,
if (!rhizome_derive_payload_key(m))
return RHIZOME_PAYLOAD_STATUS_CRYPTO_FAIL;
if (config.debug.rhizome_store)
DEBUGF("Encrypting payload contents for bid=%s, version=%"PRIu64,
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version);
DEBUGF(rhizome_store, "Encrypting payload contents for bid=%s, version=%"PRIu64,
alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version);
write->crypt=1;
if (m->is_journal && m->tail > 0)
@ -1034,8 +1008,7 @@ enum rhizome_payload_status rhizome_open_read(struct rhizome_read *read, const r
read->blob_fd = open(blob_path, O_RDONLY);
if (read->blob_fd == -1) {
if (errno == ENOENT) {
if (config.debug.rhizome_store)
DEBUGF("Stored file does not exist: %s", blob_path);
DEBUGF(rhizome_store, "Stored file does not exist: %s", blob_path);
// make sure we remove an orphan file row
rhizome_delete_file(&read->id);
return RHIZOME_PAYLOAD_STATUS_NEW;
@ -1052,8 +1025,7 @@ enum rhizome_payload_status rhizome_open_read(struct rhizome_read *read, const r
WHYF("Length mismatch");
return RHIZOME_PAYLOAD_STATUS_ERROR;
}
if (config.debug.rhizome_store)
DEBUGF("Opened stored file %s as fd %d, len %"PRIx64, blob_path, read->blob_fd, read->length);
DEBUGF(rhizome_store, "Opened stored file %s as fd %d, len %"PRIx64, blob_path, read->blob_fd, read->length);
}
SHA512_Init(&read->sha512_context);
return RHIZOME_PAYLOAD_STATUS_STORED;
@ -1070,8 +1042,7 @@ static ssize_t rhizome_read_retry(sqlite_retry_state *retry, struct rhizome_read
ssize_t rd = read(read_state->blob_fd, buffer, bufsz);
if (rd == -1)
RETURN(WHYF_perror("read(%d,%p,%zu)", read_state->blob_fd, buffer, bufsz));
if (config.debug.rhizome_store)
DEBUGF("Read %zu bytes from fd=%d @%"PRIx64, (size_t) rd, read_state->blob_fd, read_state->offset);
DEBUGF(rhizome_store, "Read %zu bytes from fd=%d @%"PRIx64, (size_t) rd, read_state->blob_fd, read_state->offset);
RETURN(rd);
}
if (read_state->blob_rowid == 0)
@ -1150,8 +1121,7 @@ ssize_t rhizome_read(struct rhizome_read *read_state, unsigned char *buffer, siz
}
}
read_state->offset += bytes_read;
if (config.debug.rhizome_store)
DEBUGF("read %zu bytes, read_state->offset=%"PRIu64, bytes_read, read_state->offset);
DEBUGF(rhizome_store, "read %zu bytes, read_state->offset=%"PRIu64, bytes_read, read_state->offset);
RETURN(bytes_read);
OUT();
}
@ -1162,7 +1132,7 @@ ssize_t rhizome_read_buffered(struct rhizome_read *read, struct rhizome_read_buf
size_t bytes_copied=0;
while (len>0){
//DEBUGF("len=%zu read->length=%"PRIu64" read->offset=%"PRIu64" buffer->offset=%"PRIu64"", len, read->length, read->offset, buffer->offset);
//DEBUGF(rhizome_store, "len=%zu read->length=%"PRIu64" read->offset=%"PRIu64" buffer->offset=%"PRIu64"", len, read->length, read->offset, buffer->offset);
// make sure we only attempt to read data that actually exists
if (read->length != RHIZOME_SIZE_UNSET && read->offset + len > read->length)
len = read->length - read->offset;
@ -1221,8 +1191,7 @@ ssize_t rhizome_read_buffered(struct rhizome_read *read, struct rhizome_read_buf
void rhizome_read_close(struct rhizome_read *read)
{
if (read->blob_fd != -1) {
if (config.debug.rhizome_store)
DEBUGF("Closing store fd %d", read->blob_fd);
DEBUGF(rhizome_store, "Closing store fd %d", read->blob_fd);
close(read->blob_fd);
read->blob_fd = -1;
}
@ -1352,9 +1321,8 @@ ssize_t rhizome_read_cached(const rhizome_bid_t *bidp, uint64_t version, time_ms
if (!entry){
rhizome_filehash_t filehash;
if (rhizome_database_filehash_from_id(bidp, version, &filehash) != 0){
if (config.debug.rhizome_store)
DEBUGF("Payload not found for bundle bid=%s version=%"PRIu64,
alloca_tohex_rhizome_bid_t(*bidp), version);
DEBUGF(rhizome_store, "Payload not found for bundle bid=%s version=%"PRIu64,
alloca_tohex_rhizome_bid_t(*bidp), version);
return -1;
}
entry = emalloc_zero(sizeof(struct cache_entry));
@ -1442,8 +1410,7 @@ static enum rhizome_payload_status read_derive_key(rhizome_manifest *m, struct r
WHY("Unable to decrypt bundle, valid key not found");
return RHIZOME_PAYLOAD_STATUS_CRYPTO_FAIL;
}
if (config.debug.rhizome_store)
DEBUGF("Decrypting payload contents for bid=%s version=%"PRIu64, alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version);
DEBUGF(rhizome_store, "Decrypting payload contents for bid=%s version=%"PRIu64, alloca_tohex_rhizome_bid_t(m->cryptoSignPublic), m->version);
if (m->is_journal && m->tail > 0)
read_state->tail = m->tail;
bcopy(m->payloadKey, read_state->key, sizeof(read_state->key));
@ -1587,13 +1554,11 @@ enum rhizome_payload_status rhizome_write_open_journal(struct rhizome_write *wri
if (advance_by > 0)
rhizome_manifest_set_tail(m, m->tail + advance_by);
enum rhizome_payload_status status = rhizome_open_write(write, NULL, new_filesize);
if (config.debug.rhizome)
DEBUGF("rhizome_open_write() returned %d %s", status, rhizome_payload_status_message(status));
DEBUGF(rhizome, "rhizome_open_write() returned %d %s", status, rhizome_payload_status_message(status));
if (status == RHIZOME_PAYLOAD_STATUS_NEW && copy_length > 0) {
// we don't need to bother decrypting the existing journal payload
enum rhizome_payload_status rstatus = rhizome_journal_pipe(write, &m->filehash, advance_by, copy_length);
if (config.debug.rhizome)
DEBUGF("rhizome_journal_pipe() returned %d %s", rstatus, rhizome_payload_status_message(rstatus));
DEBUGF(rhizome, "rhizome_journal_pipe() returned %d %s", rstatus, rhizome_payload_status_message(rstatus));
int rstatus_valid = 0;
switch (rstatus) {
case RHIZOME_PAYLOAD_STATUS_EMPTY:
@ -1618,8 +1583,7 @@ enum rhizome_payload_status rhizome_write_open_journal(struct rhizome_write *wri
}
if (status == RHIZOME_PAYLOAD_STATUS_NEW) {
status = rhizome_write_derive_key(m, write);
if (config.debug.rhizome)
DEBUGF("rhizome_write_derive_key() returned %d %s", status, rhizome_payload_status_message(status));
DEBUGF(rhizome, "rhizome_write_derive_key() returned %d %s", status, rhizome_payload_status_message(status));
}
if (status != RHIZOME_PAYLOAD_STATUS_NEW) {
rhizome_fail_write(write);
@ -1630,8 +1594,7 @@ enum rhizome_payload_status rhizome_write_open_journal(struct rhizome_write *wri
// Call to finish any payload store operation
enum rhizome_payload_status rhizome_finish_store(struct rhizome_write *write, rhizome_manifest *m, enum rhizome_payload_status status)
{
if (config.debug.rhizome)
DEBUGF("write=%p m=manifest[%d], status=%d %s", write, m->manifest_record_number, status, rhizome_payload_status_message_nonnull(status));
DEBUGF(rhizome, "write=%p m=manifest[%d], status=%d %s", write, m->manifest_record_number, status, rhizome_payload_status_message_nonnull(status));
switch (status) {
case RHIZOME_PAYLOAD_STATUS_NEW:
break;
@ -1669,8 +1632,7 @@ enum rhizome_payload_status rhizome_finish_store(struct rhizome_write *write, rh
if (m->is_journal || m->filesize == RHIZOME_SIZE_UNSET)
rhizome_manifest_set_filesize(m, write->file_length);
else if (m->filesize != write->file_length) {
if (config.debug.rhizome)
DEBUGF("m->filesize=%"PRIu64", write->file_length=%"PRIu64, m->filesize, write->file_length);
DEBUGF(rhizome, "m->filesize=%"PRIu64", write->file_length=%"PRIu64, m->filesize, write->file_length);
return RHIZOME_PAYLOAD_STATUS_WRONG_SIZE;
}
if (m->is_journal)
@ -1679,8 +1641,7 @@ enum rhizome_payload_status rhizome_finish_store(struct rhizome_write *write, rh
if (m->is_journal || !m->has_filehash)
rhizome_manifest_set_filehash(m, &write->id);
else if (cmp_rhizome_filehash_t(&write->id, &m->filehash) != 0) {
if (config.debug.rhizome)
DEBUGF("m->filehash=%s, write->id=%s", alloca_tohex_rhizome_filehash_t(m->filehash), alloca_tohex_rhizome_filehash_t(write->id));
DEBUGF(rhizome, "m->filehash=%s, write->id=%s", alloca_tohex_rhizome_filehash_t(m->filehash), alloca_tohex_rhizome_filehash_t(write->id));
return RHIZOME_PAYLOAD_STATUS_WRONG_HASH;
}
} else if (m->is_journal)

View File

@ -82,7 +82,7 @@ static int sync_status(struct subscriber *subscriber, void *UNUSED(context))
if (!subscriber->sync_state)
return 0;
struct rhizome_sync *state=subscriber->sync_state;
DEBUGF("%s seen %u BARs [%"PRId64" to %"PRId64" of %"PRId64"], %d interesting, %d skipped",
DEBUGF(rhizome_sync, "%s seen %u BARs [%"PRId64" to %"PRId64" of %"PRId64"], %d interesting, %d skipped",
alloca_tohex_sid_t(subscriber->sid),
state->bars_seen,
state->sync_start,
@ -114,8 +114,7 @@ static void rhizome_sync_request(struct subscriber *subscriber, uint64_t token,
ob_append_byte(b, forwards);
ob_append_packed_ui64(b, token);
if (config.debug.rhizome_sync)
DEBUGF("Sending request to %s for BARs from %"PRIu64" %s", alloca_tohex_sid_t(subscriber->sid), token, forwards?"forwards":"backwards");
DEBUGF(rhizome_sync, "Sending request to %s for BARs from %"PRIu64" %s", alloca_tohex_sid_t(subscriber->sid), token, forwards?"forwards":"backwards");
ob_flip(b);
overlay_send_frame(&header, b);
@ -164,8 +163,7 @@ static void rhizome_sync_send_requests(struct subscriber *subscriber, struct rhi
if (ob_remaining(payload)<RHIZOME_BAR_BYTES)
break;
if (config.debug.rhizome_sync)
DEBUGF("Requesting manifest for BAR %s", alloca_tohex_rhizome_bar_t(&state->bars[i].bar));
DEBUGF(rhizome_sync, "Requesting manifest for BAR %s", alloca_tohex_rhizome_bar_t(&state->bars[i].bar));
ob_append_bytes(payload, state->bars[i].bar.binary, RHIZOME_BAR_BYTES);
@ -173,8 +171,7 @@ static void rhizome_sync_send_requests(struct subscriber *subscriber, struct rhi
state->bars[i].next_request = now+5000;
if (!state->bars[i].tries){
// remove this BAR and shift the last BAR down to this position if required.
if (config.debug.rhizome_sync)
DEBUGF("Giving up on fetching BAR %s", alloca_tohex_rhizome_bar_t(&state->bars[i].bar));
DEBUGF(rhizome_sync, "Giving up on fetching BAR %s", alloca_tohex_rhizome_bar_t(&state->bars[i].bar));
state->bar_count --;
if (i<state->bar_count)
state->bars[i] = state->bars[state->bar_count];
@ -210,8 +207,7 @@ static void rhizome_sync_send_requests(struct subscriber *subscriber, struct rhi
}else if(!state->sync_complete){
state->sync_complete = 1;
state->completed = gettime_ms();
if (config.debug.rhizome_sync)
DEBUGF("BAR sync with %s complete", alloca_tohex_sid_t(subscriber->sid));
DEBUGF(rhizome_sync, "BAR sync with %s complete", alloca_tohex_sid_t(subscriber->sid));
}
state->next_request = now+5000;
}
@ -234,8 +230,7 @@ static int sync_bundle_inserted(struct subscriber *subscriber, void *context)
uint64_t this_version = rhizome_bar_version(this_bar);
if (memcmp(this_id, id, RHIZOME_BAR_PREFIX_BYTES)==0 && version >= this_version){
// remove this BAR and shift the last BAR down to this position if required.
if (config.debug.rhizome_sync)
DEBUGF("Removing BAR %s from queue", alloca_tohex_rhizome_bar_t(this_bar));
DEBUGF(rhizome_sync, "Removing BAR %s from queue", alloca_tohex_rhizome_bar_t(this_bar));
state->bar_count --;
if (i<state->bar_count)
state->bars[i] = state->bars[state->bar_count];
@ -268,8 +263,7 @@ static int sync_cache_bar(struct rhizome_sync *state, const rhizome_bar_t *bar,
return -1;
}
if (config.debug.rhizome_sync)
DEBUGF("Remembering BAR %s", alloca_tohex_rhizome_bar_t(bar));
DEBUGF(rhizome_sync, "Remembering BAR %s", alloca_tohex_rhizome_bar_t(bar));
state->bars[state->bar_count].bar = *bar;
state->bars[state->bar_count].next_request = gettime_ms();
@ -351,8 +345,7 @@ static void sync_process_bar_list(struct subscriber *subscriber, struct rhizome_
if (bar_count>0 && state->sync_end == 0 && bar_tokens[0]>=bar_tokens[bar_count -1]){
// make sure we start syncing from the end
if (config.debug.rhizome_sync)
DEBUGF("Starting BAR sync with %s", alloca_tohex_sid_t(subscriber->sid));
DEBUGF(rhizome_sync, "Starting BAR sync with %s", alloca_tohex_sid_t(subscriber->sid));
state->sync_start = state->sync_end = state->highest_seen;
mid_point=0;
}
@ -380,8 +373,7 @@ static void sync_process_bar_list(struct subscriber *subscriber, struct rhizome_
if (r==1)
added=1;
}
if (config.debug.rhizome_sync)
DEBUGF("Synced %"PRIu64" - %"PRIu64" with %s", state->sync_start, state->sync_end, alloca_tohex_sid_t(subscriber->sid));
DEBUGF(rhizome_sync, "Synced %"PRIu64" - %"PRIu64" with %s", state->sync_start, state->sync_end, alloca_tohex_sid_t(subscriber->sid));
if (added)
state->next_request = gettime_ms();
}
@ -500,8 +492,7 @@ static void sync_send_response(struct subscriber *dest, int forwards, uint64_t t
sqlite3_finalize(statement);
if (count){
if (config.debug.rhizome_sync)
DEBUGF("Sending %d BARs from %"PRIu64" to %"PRIu64, count, token, last);
DEBUGF(rhizome_sync, "Sending %d BARs from %"PRIu64" to %"PRIu64, count, token, last);
ob_flip(b);
overlay_send_frame(&header, b);
}

View File

@ -289,8 +289,7 @@ static struct neighbour *get_neighbour(struct subscriber *subscriber, char creat
n->rtt = 120;
n->next_neighbour_update = gettime_ms() + 10;
neighbours = n;
if (config.debug.linkstate)
DEBUGF("LINK STATE; new neighbour %s", alloca_tohex_sid_t(n->subscriber->sid));
DEBUGF(linkstate, "LINK STATE; new neighbour %s", alloca_tohex_sid_t(n->subscriber->sid));
}
return n;
}
@ -372,12 +371,12 @@ static void update_path_score(struct neighbour *neighbour, struct link *link){
if (link->drop_rate>2)
drop_rate += link->drop_rate;
if (config.debug.verbose && config.debug.linkstate && hop_count != link->hop_count)
DEBUGF("LINK STATE; path score to %s via %s version %d = %d",
alloca_tohex_sid_t(link->receiver->sid),
alloca_tohex_sid_t(neighbour->subscriber->sid),
neighbour->path_version,
hop_count);
if (hop_count != link->hop_count && IF_DEBUG(verbose))
DEBUGF(linkstate, "LINK STATE; path score to %s via %s version %d = %d",
alloca_tohex_sid_t(link->receiver->sid),
alloca_tohex_sid_t(neighbour->subscriber->sid),
neighbour->path_version,
hop_count);
link->hop_count = hop_count;
link->path_version = neighbour->path_version;
@ -462,8 +461,7 @@ next:
subscriber->reachable=REACHABLE_SELF;
changed = 1;
best_link = NULL;
if (config.debug.overlayrouting || config.debug.linkstate)
DEBUGF("REACHABLE via self %s", alloca_tohex_sid_t(subscriber->sid));
DEBUGF2(overlayrouting, linkstate, "REACHABLE via self %s", alloca_tohex_sid_t(subscriber->sid));
}
if (changed){
@ -582,8 +580,8 @@ static int append_link(struct subscriber *subscriber, void *context)
static void free_neighbour(struct neighbour **neighbour_ptr){
struct neighbour *n = *neighbour_ptr;
if (config.debug.linkstate && config.debug.verbose)
DEBUGF("LINK STATE; all links from neighbour %s have died", alloca_tohex_sid_t(n->subscriber->sid));
if (IF_DEBUG(verbose))
DEBUGF(linkstate, "LINK STATE; all links from neighbour %s have died", alloca_tohex_sid_t(n->subscriber->sid));
struct link_in *link = n->links;
while(link){
@ -617,10 +615,9 @@ static void clean_neighbours(time_ms_t now)
while(*list){
struct link_in *link = *list;
if (link->interface->state!=INTERFACE_STATE_UP || link->link_timeout < now){
if (config.debug.linkstate)
DEBUGF("LINK STATE; link expired from neighbour %s on interface %s",
alloca_tohex_sid_t(n->subscriber->sid),
link->interface->name);
DEBUGF(linkstate, "LINK STATE; link expired from neighbour %s on interface %s",
alloca_tohex_sid_t(n->subscriber->sid),
link->interface->name);
*list=link->_next;
free(link);
}else{
@ -797,16 +794,14 @@ static int neighbour_find_best_link(struct neighbour *n)
if (n->best_link != best_link){
n->best_link = best_link;
n->next_neighbour_update = gettime_ms()+20;
if (config.debug.linkstate){
if (best_link){
DEBUGF("LINK STATE; best link from neighbour %s is %s on interface %s",
alloca_tohex_sid_t(n->subscriber->sid),
best_link->unicast?"unicast":"broadcast",
best_link->interface->name);
}else{
DEBUGF("LINK STATE; no best link from neighbour %s",
alloca_tohex_sid_t(n->subscriber->sid));
}
if (best_link) {
DEBUGF(linkstate, "LINK STATE; best link from neighbour %s is %s on interface %s",
alloca_tohex_sid_t(n->subscriber->sid),
best_link->unicast?"unicast":"broadcast",
best_link->interface->name);
} else {
DEBUGF(linkstate, "LINK STATE; no best link from neighbour %s",
alloca_tohex_sid_t(n->subscriber->sid));
}
}
@ -821,10 +816,10 @@ static int neighbour_link_sent(struct overlay_frame *frame, struct network_desti
if (!neighbour)
return 0;
neighbour->last_update_seq = sequence;
if ((config.debug.linkstate && config.debug.verbose)||config.debug.ack)
DEBUGF("LINK STATE; ack sent to neighbour %s via %s, in seq %d",
alloca_tohex_sid_t(subscriber->sid),
alloca_socket_address(&destination->address), sequence);
if (IF_DEBUG(verbose) || IF_DEBUG(ack))
DEBUGF2(linkstate, ack, "LINK STATE; ack sent to neighbour %s via %s, in seq %d",
alloca_tohex_sid_t(subscriber->sid),
alloca_socket_address(&destination->address), sequence);
return 0;
}
@ -859,8 +854,8 @@ static int send_neighbour_link(struct neighbour *n)
frame->destination = n->subscriber;
}else{
// not an immediate neighbour yet? send this packet to all probable destinations.
if ((config.debug.linkstate && config.debug.verbose)|| config.debug.ack)
DEBUGF("Sending link state ack to all possibilities");
if (IF_DEBUG(verbose) || IF_DEBUG(ack))
DEBUGF2(linkstate, ack, "Sending link state ack to all possibilities");
struct link_out *out = n->out_links;
while(out){
if (out->timeout >= now)
@ -878,8 +873,7 @@ static int send_neighbour_link(struct neighbour *n)
else
flags|=FLAG_BROADCAST;
if (config.debug.ack)
DEBUGF("LINK STATE; Sending ack to %s for seq %d", alloca_tohex_sid_t(n->subscriber->sid), n->best_link->ack_sequence);
DEBUGF(ack, "LINK STATE; Sending ack to %s for seq %d", alloca_tohex_sid_t(n->subscriber->sid), n->best_link->ack_sequence);
append_link_state(frame->payload, flags, n->subscriber, my_subscriber, n->best_link->neighbour_interface, 1,
n->best_link->ack_sequence, n->best_link->ack_mask, -1);
@ -890,8 +884,7 @@ static int send_neighbour_link(struct neighbour *n)
n->last_update = now;
}
n->next_neighbour_update = n->last_update + n->best_link->interface->destination->ifconfig.tick_ms;
if (config.debug.ack)
DEBUGF("Next update for %s in %"PRId64"ms", alloca_tohex_sid_t(n->subscriber->sid), n->next_neighbour_update - gettime_ms());
DEBUGF(ack, "Next update for %s in %"PRId64"ms", alloca_tohex_sid_t(n->subscriber->sid), n->next_neighbour_update - gettime_ms());
OUT();
return 0;
}
@ -1024,12 +1017,11 @@ struct link_in * get_neighbour_link(struct neighbour *neighbour, struct overlay_
link->ack_sequence = -1;
link->ack_mask = 0;
link->_next = neighbour->links;
if (config.debug.linkstate)
DEBUGF("LINK STATE; new possible %s link from neighbour %s on interface %s/%d",
unicast?"unicast":"broadcast",
alloca_tohex_sid_t(neighbour->subscriber->sid),
interface->name,
sender_interface);
DEBUGF(linkstate, "LINK STATE; new possible %s link from neighbour %s on interface %s/%d",
unicast?"unicast":"broadcast",
alloca_tohex_sid_t(neighbour->subscriber->sid),
interface->name,
sender_interface);
neighbour->links = link;
return link;
}
@ -1145,8 +1137,7 @@ int link_state_ack_soon(struct subscriber *subscriber)
time_ms_t update_time = now + subscriber->destination->resend_delay/3;
if (neighbour->next_neighbour_update > update_time){
neighbour->next_neighbour_update = update_time;
if (config.debug.ack)
DEBUGF("Asking for next ACK Real Soon Now");
DEBUGF(ack, "Asking for next ACK Real Soon Now");
}
update_alarm(__WHENCE__, neighbour->next_neighbour_update);
}
@ -1179,7 +1170,7 @@ int link_received_duplicate(struct subscriber *subscriber, int payload_seq)
int offset = (payload_seq - neighbour->mdp_ack_sequence - 1)&0xFF;
if (offset>=64){
neighbour->mdp_ack_mask = 0;
DEBUGF("Jump in neighbour mdp seq (%d -> %d)",neighbour->mdp_ack_sequence,payload_seq);
DEBUGF(ack, "Jump in neighbour mdp seq (%d -> %d)",neighbour->mdp_ack_sequence,payload_seq);
}else{
neighbour->mdp_ack_mask = (neighbour->mdp_ack_mask << 1) | 1;
neighbour->mdp_ack_mask = neighbour->mdp_ack_mask << offset;
@ -1213,11 +1204,10 @@ static struct link_out *create_out_link(struct neighbour *neighbour, overlay_int
ret->_next=neighbour->out_links;
neighbour->out_links=ret;
ret->destination=dest;
if (config.debug.linkstate)
DEBUGF("LINK STATE; Create possible %s link_out for neighbour %s on interface %s",
unicast?"unicast":"broadcast",
alloca_tohex_sid_t(neighbour->subscriber->sid),
interface->name);
DEBUGF(linkstate, "LINK STATE; Create possible %s link_out for neighbour %s on interface %s",
unicast?"unicast":"broadcast",
alloca_tohex_sid_t(neighbour->subscriber->sid),
interface->name);
time_ms_t now = gettime_ms();
ret->timeout = now + ret->destination->ifconfig.reachable_timeout_ms;
update_alarm(__WHENCE__, now + 5);
@ -1261,9 +1251,9 @@ int link_received_packet(struct decode_context *context, int sender_seq, char un
if (link->ack_sequence != -1){
int offset = (link->ack_sequence - 1 - sender_seq)&0xFF;
if (offset < 64){
if (config.debug.verbose && config.debug.linkstate)
DEBUGF("LINK STATE; late seq %d from %s on %s",
sender_seq, alloca_tohex_sid_t(context->sender->sid), context->interface->name);
if (IF_DEBUG(verbose))
DEBUGF(linkstate, "LINK STATE; late seq %d from %s on %s",
sender_seq, alloca_tohex_sid_t(context->sender->sid), context->interface->name);
link->ack_mask |= (1ull<<offset);
}else{
link->ack_mask = (link->ack_mask << 1) | 1;
@ -1272,9 +1262,9 @@ int link_received_packet(struct decode_context *context, int sender_seq, char un
if (link->ack_sequence == sender_seq)
break;
// missed a packet? send a link state soon
if ((config.debug.verbose && config.debug.linkstate)||config.debug.ack)
DEBUGF("LINK STATE; missed seq %d from %s on %s",
link->ack_sequence, alloca_tohex_sid_t(context->sender->sid), context->interface->name);
if (IF_DEBUG(verbose) || IF_DEBUG(ack))
DEBUGF2(linkstate, ack, "LINK STATE; missed seq %d from %s on %s",
link->ack_sequence, alloca_tohex_sid_t(context->sender->sid), context->interface->name);
link->ack_mask = link->ack_mask << 1;
link->ack_counter --;
@ -1380,15 +1370,15 @@ int link_receive(struct internal_mdp_header *header, struct overlay_buffer *payl
if (context.invalid_addresses)
continue;
if ((config.debug.verbose && config.debug.linkstate)||config.debug.ack)
DEBUGF("LINK STATE; record - %d, %s, %s, %d, %d, %x, %d",
flags,
receiver?alloca_tohex_sid_t(receiver->sid):"NULL",
transmitter?alloca_tohex_sid_t(transmitter->sid):"NULL",
interface_id,
ack_seq,
ack_mask,
drop_rate);
if (IF_DEBUG(verbose) || IF_DEBUG(ack))
DEBUGF2(linkstate, ack, "LINK STATE; record - %d, %s, %s, %d, %d, %x, %d",
flags,
receiver?alloca_tohex_sid_t(receiver->sid):"NULL",
transmitter?alloca_tohex_sid_t(transmitter->sid):"NULL",
interface_id,
ack_seq,
ack_mask,
drop_rate);
if (transmitter && transmitter!=my_subscriber && transmitter->reachable==REACHABLE_SELF){
// Our neighbour is talking about a path *from* a secondary SID of ours? Impossible.
@ -1501,9 +1491,8 @@ int link_receive(struct internal_mdp_header *header, struct overlay_buffer *payl
neighbour->last_update_seq = -1;
}else if(seq_delta < 128){
// send another ack soon
if (config.debug.ack)
DEBUGF("LINK STATE; neighbour %s missed ack %d, queue another",
alloca_tohex_sid_t(header->source->sid), neighbour->last_update_seq);
DEBUGF(ack, "LINK STATE; neighbour %s missed ack %d, queue another",
alloca_tohex_sid_t(header->source->sid), neighbour->last_update_seq);
neighbour->next_neighbour_update=now+10;
update_alarm(__WHENCE__, neighbour->next_neighbour_update);
}
@ -1573,8 +1562,7 @@ int link_state_legacy_ack(struct overlay_frame *frame, time_ms_t now)
if (!neighbour->legacy_protocol){
changed = 1;
if (config.debug.linkstate)
DEBUGF("LINK STATE; new legacy neighbour %s", alloca_tohex_sid_t(frame->source->sid));
DEBUGF(linkstate, "LINK STATE; new legacy neighbour %s", alloca_tohex_sid_t(frame->source->sid));
}
if (neighbour->link_in_timeout < now)
changed = 1;

View File

@ -515,12 +515,11 @@ void server_watchdog(struct sched_ent *alarm)
break;
default:
/* Child, report grandchild's PID. */
if (config.debug.watchdog)
LOGF(LOG_LEVEL_DEBUG, "STARTED WATCHDOG pid=%u executable=%s argv=[%s]",
watchdog_pid,
alloca_str_toprint(config.server.watchdog.executable),
strbuf_str(argv_sb)
);
DEBUGF(watchdog, "STARTED WATCHDOG pid=%u executable=%s argv=[%s]",
watchdog_pid,
alloca_str_toprint(config.server.watchdog.executable),
strbuf_str(argv_sb)
);
do { _exit(0); } while (1);
break;
}
@ -587,7 +586,7 @@ void cf_on_config_change()
if (config.rhizome.enable){
rhizome_opendb();
RESCHEDULE(&ALARM_STRUCT(rhizome_clean_db), now + 30*60*1000, TIME_MS_NEVER_WILL, TIME_MS_NEVER_WILL);
if (config.debug.rhizome)
if (IF_DEBUG(rhizome))
RESCHEDULE(&ALARM_STRUCT(rhizome_fetch_status), now + 3000, TIME_MS_NEVER_WILL, TIME_MS_NEVER_WILL);
}else if(rhizome_db){
rhizome_close_db();
@ -682,8 +681,7 @@ DEFINE_CMD(app_server_start, 0,
static int app_server_start(const struct cli_parsed *parsed, struct cli_context *context)
{
IN();
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
/* Process optional arguments */
int cpid=-1;
const char *execpath;
@ -741,8 +739,7 @@ static int app_server_start(const struct cli_parsed *parsed, struct cli_context
_exit() is used on non-Android systems, then source code coverage does not get reported,
because it relies on an atexit() callback to write the accumulated counters into .gcda
files. */
if (config.debug.verbose)
DEBUG("Child Process");
DEBUG(verbose, "Child Process");
// Ensure that all stdio streams are flushed before forking, so that if a child calls
// exit(), it will not result in any buffered output being written twice to the file
// descriptor.
@ -758,8 +755,7 @@ static int app_server_start(const struct cli_parsed *parsed, struct cli_context
start a new process session so that if we are being started by an adb shell session
on an Android device, then we don't receive a SIGHUP when the adb shell process ends.
*/
if (config.debug.verbose)
DEBUG("Grand-Child Process, reopening log");
DEBUG(verbose, "Grand-Child Process, reopening log");
close_log_file();
disable_log_stderr();
int fd;
@ -783,8 +779,7 @@ static int app_server_start(const struct cli_parsed *parsed, struct cli_context
if (execpath) {
/* Need the cast on Solaris because it defines NULL as 0L and gcc doesn't see it as a
sentinal. */
if (config.debug.verbose)
DEBUGF("Calling execl %s start foreground", execpath);
DEBUGF(verbose, "Calling execl %s start foreground", execpath);
execl(execpath, "servald", "start", "foreground", (void *)NULL);
WHYF_perror("execl(%s, \"servald\", \"start\", \"foreground\")", alloca_str_toprint(execpath));
exit(-1);
@ -854,8 +849,7 @@ DEFINE_CMD(app_server_stop,CLIFLAG_PERMISSIVE_CONFIG,
"stop");
static int app_server_stop(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
int pid, tries, running;
time_ms_t timeout;
const char *ipath = instance_path();
@ -908,8 +902,7 @@ DEFINE_CMD(app_server_status,CLIFLAG_PERMISSIVE_CONFIG,
"status");
static int app_server_status(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
int pid = server_pid();
const char *ipath = instance_path();
if (ipath) {

View File

@ -152,7 +152,7 @@ static void recv_packet(int fd, struct network *network, struct peer *destinatio
peer=peer->_next;
}
if (!peer) {
DEBUGF("New peer %s", alloca_socket_address(&addr));
DEBUGF(verbose, "New peer %s", alloca_socket_address(&addr));
struct socket_address unicast_addr;
unicast_addr.local.sun_family=AF_UNIX;
strbuf d = strbuf_local(unicast_addr.local.sun_path, sizeof unicast_addr.local.sun_path);
@ -382,8 +382,7 @@ static void crash_handler(int signal)
{
LOGF(LOG_LEVEL_FATAL, "Caught signal %s", alloca_signal_name(signal));
dump_stack(LOG_LEVEL_FATAL);
// TODO Move logBackTrace to log utils?
// BACKTRACE;
BACKTRACE;
// Now die of the same signal, so that our exit status reflects the cause.
INFOF("Re-sending signal %d to self", signal);
kill(getpid(), signal);
@ -506,11 +505,11 @@ static int console_up(const struct cli_parsed *parsed, struct cli_context *UNUSE
n->up = 1;
INFOF("Network %s is now up", n->name);
DEBUGF("Minimum latency %dms", (int)n->latency);
DEBUGF("Will drop %d%% of packets", n->drop_packets);
DEBUGF("Will %s broadcast packets", n->drop_broadcast?"drop":"allow");
DEBUGF("Will %s unicast packets", n->drop_unicast?"drop":"allow");
DEBUGF("Allowing a maximum of %d packets every %"PRId64"ms",
DEBUGF(verbose, "Minimum latency %dms", (int)n->latency);
DEBUGF(verbose, "Will drop %d%% of packets", n->drop_packets);
DEBUGF(verbose, "Will %s broadcast packets", n->drop_broadcast?"drop":"allow");
DEBUGF(verbose, "Will %s unicast packets", n->drop_unicast?"drop":"allow");
DEBUGF(verbose, "Allowing a maximum of %d packets every %"PRId64"ms",
n->limit.burst_size,
n->limit.burst_length);
}
@ -596,12 +595,12 @@ int main()
{
struct network *n = networks;
while(n) {
DEBUGF("Closing network %s, TX %d RX %d", n->name, n->tx_count, n->rx_count);
DEBUGF(verbose, "Closing network %s, TX %d RX %d", n->name, n->tx_count, n->rx_count);
unwatch(&n->alarm);
socket_unlink_close(n->alarm.poll.fd);
struct peer *p = n->peer_list;
while(p) {
DEBUGF("Closing peer proxy socket, TX %d RX %d", p->tx_count, p->rx_count);
DEBUGF(verbose, "Closing peer proxy socket, TX %d RX %d", p->tx_count, p->rx_count);
unwatch(&p->alarm);
socket_unlink_close(p->alarm.poll.fd);
struct peer *f = p;

View File

@ -187,8 +187,7 @@ int _esocket(struct __sourceloc __whence, int domain, int type, int protocol)
int fd;
if ((fd = socket(domain, type, protocol)) == -1)
return WHYF_perror("socket(%s, %s, 0)", alloca_socket_domain(domain), alloca_socket_type(type));
if (config.debug.io || config.debug.verbose_io)
DEBUGF("socket(%s, %s, 0) -> %d", alloca_socket_domain(domain), alloca_socket_type(type), fd);
DEBUGF2(io, verbose_io, "socket(%s, %s, 0) -> %d", alloca_socket_domain(domain), alloca_socket_type(type), fd);
return fd;
}
@ -196,8 +195,7 @@ int _socket_connect(struct __sourceloc __whence, int sock, const struct socket_a
{
if (connect(sock, &addr->addr, addr->addrlen) == -1)
return WHYF_perror("connect(%d,%s,%lu)", sock, alloca_socket_address(addr), (unsigned long)addr->addrlen);
if (config.debug.io || config.debug.verbose_io)
DEBUGF("connect(%d, %s, %lu)", sock, alloca_socket_address(addr), (unsigned long)addr->addrlen);
DEBUGF2(io, verbose_io, "connect(%d, %s, %lu)", sock, alloca_socket_address(addr), (unsigned long)addr->addrlen);
return 0;
}
@ -216,13 +214,11 @@ int _socket_bind(struct __sourceloc __whence, int sock, const struct socket_addr
// remove a previous socket
if (unlink(addr->local.sun_path) == -1 && errno != ENOENT)
WARNF_perror("unlink(%s)", alloca_str_toprint(addr->local.sun_path));
if (config.debug.io || config.debug.verbose_io)
DEBUGF("unlink(%s)", alloca_str_toprint(addr->local.sun_path));
DEBUGF2(io, verbose_io, "unlink(%s)", alloca_str_toprint(addr->local.sun_path));
}
if (bind(sock, &addr->addr, addr->addrlen) == -1)
return WHYF_perror("bind(%d,%s,%lu)", sock, alloca_socket_address(addr), (unsigned long)addr->addrlen);
if (config.debug.io || config.debug.verbose_io)
DEBUGF("bind(%d, %s, %lu)", sock, alloca_socket_address(addr), (unsigned long)addr->addrlen);
DEBUGF2(io, verbose_io, "bind(%d, %s, %lu)", sock, alloca_socket_address(addr), (unsigned long)addr->addrlen);
return 0;
}
@ -230,8 +226,7 @@ int _socket_listen(struct __sourceloc __whence, int sock, int backlog)
{
if (listen(sock, backlog) == -1)
return WHYF_perror("listen(%d,%d)", sock, backlog);
if (config.debug.io || config.debug.verbose_io)
DEBUGF("listen(%d, %d)", sock, backlog);
DEBUGF2(io, verbose_io, "listen(%d, %d)", sock, backlog);
return 0;
}
@ -241,8 +236,7 @@ int _socket_set_reuseaddr(struct __sourceloc __whence, int sock, int reuseP)
WARNF_perror("setsockopt(%d,SOL_SOCKET,SO_REUSEADDR,&%d,%u)", sock, reuseP, (unsigned)sizeof reuseP);
return -1;
}
if (config.debug.io || config.debug.verbose_io)
DEBUGF("setsockopt(%d, SOL_SOCKET, SO_REUSEADDR, &%d, %u)", sock, reuseP, (unsigned)sizeof reuseP);
DEBUGF2(io, verbose_io, "setsockopt(%d, SOL_SOCKET, SO_REUSEADDR, &%d, %u)", sock, reuseP, (unsigned)sizeof reuseP);
return 0;
}
@ -252,8 +246,7 @@ int _socket_set_rcvbufsize(struct __sourceloc __whence, int sock, unsigned buffe
WARNF_perror("setsockopt(%d,SOL_SOCKET,SO_RCVBUF,&%u,%u)", sock, buffer_size, (unsigned)sizeof buffer_size);
return -1;
}
if (config.debug.io || config.debug.verbose_io)
DEBUGF("setsockopt(%d, SOL_SOCKET, SO_RCVBUF, &%u, %u)", sock, buffer_size, (unsigned)sizeof buffer_size);
DEBUGF2(io, verbose_io, "setsockopt(%d, SOL_SOCKET, SO_RCVBUF, &%u, %u)", sock, buffer_size, (unsigned)sizeof buffer_size);
return 0;
}

View File

@ -60,8 +60,7 @@ DEFINE_CMD(app_crypt_test, 0,
"test","crypt");
static int app_crypt_test(const struct cli_parsed *parsed, struct cli_context *context)
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
unsigned char nonce[crypto_box_curve25519xsalsa20poly1305_NONCEBYTES];
unsigned char k[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES];
@ -294,7 +293,7 @@ static int app_config_test(const struct cli_parsed *UNUSED(parsed), struct cli_c
struct cf_om_node *root = NULL;
int ret = cf_om_parse(filename, buf, st.st_size, &root);
close(fd);
DEBUGF("ret = %s", strbuf_str(strbuf_cf_flags(strbuf_alloca(128), ret)));
DEBUGF(verbose, "ret = %s", strbuf_str(strbuf_cf_flags(strbuf_alloca(128), ret)));
//cf_dump_node(root, 0);
struct config_main config;
memset(&config, 0, sizeof config);
@ -302,45 +301,45 @@ static int app_config_test(const struct cli_parsed *UNUSED(parsed), struct cli_c
int result = root ? cf_opt_config_main(&config, root) : CFEMPTY;
cf_om_free_node(&root);
free(buf);
DEBUGF("result = %s", strbuf_str(strbuf_cf_flags(strbuf_alloca(128), result)));
DEBUGF("config.log.file.path = %s", alloca_str_toprint(config.log.file.path));
DEBUGF("config.log.file.show_pid = %d", config.log.file.show_pid);
DEBUGF("config.log.file.show_time = %d", config.log.file.show_time);
DEBUGF("config.server.chdir = %s", alloca_str_toprint(config.server.chdir));
DEBUGF("config.debug.verbose = %d", config.debug.verbose);
DEBUGF("config.directory.service = %s", alloca_tohex_sid_t(config.directory.service));
DEBUGF("config.rhizome.api.addfile.allow_host = %s", inet_ntoa(config.rhizome.api.addfile.allow_host));
DEBUGF(verbose, "result = %s", strbuf_str(strbuf_cf_flags(strbuf_alloca(128), result)));
DEBUGF(verbose, "config.log.file.path = %s", alloca_str_toprint(config.log.file.path));
DEBUGF(verbose, "config.log.file.show_pid = %d", config.log.file.show_pid);
DEBUGF(verbose, "config.log.file.show_time = %d", config.log.file.show_time);
DEBUGF(verbose, "config.server.chdir = %s", alloca_str_toprint(config.server.chdir));
DEBUGF(verbose, "config.debug.verbose = %d", config.debug.verbose);
DEBUGF(verbose, "config.directory.service = %s", alloca_tohex_sid_t(config.directory.service));
DEBUGF(verbose, "config.rhizome.api.addfile.allow_host = %s", inet_ntoa(config.rhizome.api.addfile.allow_host));
unsigned j;
for (j = 0; j < config.dna.helper.argv.ac; ++j) {
DEBUGF("config.dna.helper.argv.%u=%s", config.dna.helper.argv.av[j].key, config.dna.helper.argv.av[j].value);
DEBUGF(verbose, "config.dna.helper.argv.%u=%s", config.dna.helper.argv.av[j].key, config.dna.helper.argv.av[j].value);
}
for (j = 0; j < config.rhizome.direct.peer.ac; ++j) {
DEBUGF("config.rhizome.direct.peer.%s", config.rhizome.direct.peer.av[j].key);
DEBUGF(" .protocol = %s", alloca_str_toprint(config.rhizome.direct.peer.av[j].value.protocol));
DEBUGF(" .host = %s", alloca_str_toprint(config.rhizome.direct.peer.av[j].value.host));
DEBUGF(" .port = %u", config.rhizome.direct.peer.av[j].value.port);
DEBUGF(verbose, "config.rhizome.direct.peer.%s", config.rhizome.direct.peer.av[j].key);
DEBUGF(verbose, " .protocol = %s", alloca_str_toprint(config.rhizome.direct.peer.av[j].value.protocol));
DEBUGF(verbose, " .host = %s", alloca_str_toprint(config.rhizome.direct.peer.av[j].value.host));
DEBUGF(verbose, " .port = %u", config.rhizome.direct.peer.av[j].value.port);
}
for (j = 0; j < config.interfaces.ac; ++j) {
DEBUGF("config.interfaces.%u", config.interfaces.av[j].key);
DEBUGF(" .exclude = %d", config.interfaces.av[j].value.exclude);
DEBUGF(" .match = [");
DEBUGF(verbose, "config.interfaces.%u", config.interfaces.av[j].key);
DEBUGF(verbose, " .exclude = %d", config.interfaces.av[j].value.exclude);
DEBUGF(verbose, " .match = [");
unsigned k;
for (k = 0; k < config.interfaces.av[j].value.match.patc; ++k)
DEBUGF(" %s", alloca_str_toprint(config.interfaces.av[j].value.match.patv[k]));
DEBUGF(" ]");
DEBUGF(" .type = %d", config.interfaces.av[j].value.type);
DEBUGF(" .port = %u", config.interfaces.av[j].value.port);
DEBUGF(" .broadcast.drop = %d", (int) config.interfaces.av[j].value.broadcast.drop);
DEBUGF(" .unicast.drop = %d", (int) config.interfaces.av[j].value.unicast.drop);
DEBUGF(" .drop_packets = %u", (unsigned) config.interfaces.av[j].value.drop_packets);
DEBUGF(verbose, " %s", alloca_str_toprint(config.interfaces.av[j].value.match.patv[k]));
DEBUGF(verbose, " ]");
DEBUGF(verbose, " .type = %d", config.interfaces.av[j].value.type);
DEBUGF(verbose, " .port = %u", config.interfaces.av[j].value.port);
DEBUGF(verbose, " .broadcast.drop = %d", (int) config.interfaces.av[j].value.broadcast.drop);
DEBUGF(verbose, " .unicast.drop = %d", (int) config.interfaces.av[j].value.unicast.drop);
DEBUGF(verbose, " .drop_packets = %u", (unsigned) config.interfaces.av[j].value.drop_packets);
}
for (j = 0; j < config.hosts.ac; ++j) {
char sidhex[SID_STRLEN + 1];
tohex(sidhex, SID_STRLEN, config.hosts.av[j].key.binary);
DEBUGF("config.hosts.%s", sidhex);
DEBUGF(" .interface = %s", alloca_str_toprint(config.hosts.av[j].value.interface));
DEBUGF(" .address = %s", inet_ntoa(config.hosts.av[j].value.address));
DEBUGF(" .port = %u", config.hosts.av[j].value.port);
DEBUGF(verbose, "config.hosts.%s", sidhex);
DEBUGF(verbose, " .interface = %s", alloca_str_toprint(config.hosts.av[j].value.interface));
DEBUGF(verbose, " .address = %s", inet_ntoa(config.hosts.av[j].value.address));
DEBUGF(verbose, " .port = %u", config.hosts.av[j].value.port);
}
return 0;
}

69
vomp.c
View File

@ -349,7 +349,7 @@ static int vomp_generate_session_id()
if (urandombytes((unsigned char *)&session_id, sizeof session_id))
return WHY("Insufficient entropy");
session_id&=VOMP_SESSION_MASK;
if (config.debug.vomp) DEBUGF("session=0x%08x",session_id);
DEBUGF(vomp, "session=0x%08x",session_id);
unsigned i;
/* reject duplicate call session numbers */
for(i=0;i<vomp_call_count;i++)
@ -391,8 +391,7 @@ static struct vomp_call_state *vomp_create_call(struct subscriber *remote,
vomp_stats.name="vomp_process_tick";
call->alarm.stats=&vomp_stats;
schedule(&call->alarm);
if (config.debug.vomp)
DEBUGF("Returning new call #%d",local_session);
DEBUGF(vomp, "Returning new call #%d",local_session);
return call;
}
@ -404,8 +403,7 @@ static struct vomp_call_state *vomp_find_or_create_call(struct subscriber *remot
int recvr_state)
{
struct vomp_call_state *call;
if (config.debug.vomp)
DEBUGF("%u calls already in progress.",vomp_call_count);
DEBUGF(vomp, "%u calls already in progress.",vomp_call_count);
unsigned i;
for(i=0;i<vomp_call_count;i++)
{
@ -413,11 +411,10 @@ 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
the slower SID comparisons */
if (config.debug.vomp)
DEBUGF("asking for %06x:%06x, this call %06x:%06x",
sender_session,recvr_session,
call->remote.session,
call->local.session);
DEBUGF(vomp, "asking for %06x:%06x, this call %06x:%06x",
sender_session,recvr_session,
call->remote.session,
call->local.session);
int checked=0;
if (call->remote.session&&sender_session) {
@ -440,12 +437,10 @@ static struct vomp_call_state *vomp_find_or_create_call(struct subscriber *remot
if (!call->remote.session)
call->remote.session=sender_session;
if (config.debug.vomp) {
DEBUGF("%06x:%06x matches call #%d %06x:%06x",
sender_session,recvr_session,i,
call->remote.session,
call->local.session);
}
DEBUGF(vomp, "%06x:%06x matches call #%d %06x:%06x",
sender_session,recvr_session,i,
call->remote.session,
call->local.session);
return call;
}
@ -513,20 +508,18 @@ static int vomp_send_status_remote(struct vomp_call_state *call)
/* Include src and dst phone numbers */
if (call->initiated_call){
if (config.debug.vomp)
DEBUGF("Sending phone numbers %s, %s",call->local.did,call->remote.did);
DEBUGF(vomp, "Sending phone numbers %s, %s",call->local.did,call->remote.did);
ob_append_str(payload, call->local.did);
ob_append_str(payload, call->remote.did);
}
if (config.debug.vomp)
DEBUGF("mdp frame with codec list is %zd bytes", ob_position(payload));
DEBUGF(vomp, "mdp frame with codec list is %zd bytes", ob_position(payload));
}
call->local.sequence++;
ob_flip(payload);
if (config.debug.vomp)
if (IF_DEBUG(vomp))
ob_dump(payload, "payload");
overlay_send_frame(&header, payload);
ob_free(payload);
@ -565,7 +558,7 @@ int vomp_received_audio(struct vomp_call_state *call, int audio_codec, int time,
ob_append_bytes(payload, audio, audio_length);
ob_flip(payload);
if (config.debug.vomp)
if (IF_DEBUG(vomp))
ob_dump(payload, "payload");
overlay_send_frame(&header, payload);
ob_free(payload);
@ -591,7 +584,7 @@ static int monitor_call_status(struct vomp_call_state *call)
static int monitor_send_audio(struct vomp_call_state *call, int audio_codec, int time, int sequence,
const unsigned char *audio, int audio_length, int delay)
{
if (0) DEBUGF("Tell call monitor about audio for call %06x:%06x",
if (0) DEBUGF(vomp, "Tell call monitor about audio for call %06x:%06x",
call->local.session,call->remote.session);
char msg[1024 + MAX_AUDIO_BYTES];
/* All commands followed by binary data start with *len:, so that
@ -688,8 +681,7 @@ static int vomp_update(struct vomp_call_state *call)
if (call->last_sent_status==combined_status)
return 0;
if (config.debug.vomp)
DEBUGF("Call state changed to %d %d, sending updates",call->local.state, call->remote.state);
DEBUGF(vomp, "Call state changed to %d %d, sending updates",call->local.state, call->remote.state);
call->last_sent_status=combined_status;
@ -757,8 +749,7 @@ static int vomp_process_audio(struct vomp_call_state *call, struct overlay_buffe
int vomp_ringing(struct vomp_call_state *call){
if (call){
if ((!call->initiated_call) && call->local.state<VOMP_STATE_RINGINGIN && call->remote.state==VOMP_STATE_RINGINGOUT){
if (config.debug.vomp)
DEBUGF("RING RING!");
DEBUGF(vomp, "RING RING!");
vomp_update_local_state(call, VOMP_STATE_RINGINGIN);
vomp_update(call);
}else
@ -769,8 +760,7 @@ int vomp_ringing(struct vomp_call_state *call){
static int vomp_call_destroy(struct vomp_call_state *call)
{
if (config.debug.vomp)
DEBUGF("Destroying call %06x:%06x [%s,%s]", call->local.session, call->remote.session, call->local.did,call->remote.did);
DEBUGF(vomp, "Destroying call %06x:%06x [%s,%s]", call->local.session, call->remote.session, call->local.did,call->remote.did);
/* now release the call structure */
unsigned i = (call - vomp_call_states);
@ -796,8 +786,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,
and potentially handle call-routing, e.g., if it is a gateway.
*/
if (config.debug.vomp)
DEBUGF("Dialing %s:%s", alloca_tohex_sid_t(remote->sid), remote_did);
DEBUGF(vomp, "Dialing %s:%s", alloca_tohex_sid_t(remote->sid), remote_did);
if (vomp_call_count>=VOMP_MAX_CALLS)
return WHY("All call slots in use");
@ -828,8 +817,7 @@ int vomp_dial(struct subscriber *local, struct subscriber *remote, const char *l
int vomp_pickup(struct vomp_call_state *call)
{
if (call){
if (config.debug.vomp)
DEBUG("Picking up");
DEBUG(vomp, "Picking up");
if (call->local.state<=VOMP_STATE_RINGINGIN && call->remote.state==VOMP_STATE_RINGINGOUT){
vomp_update_local_state(call, VOMP_STATE_INCALL);
call->create_time=gettime_ms();
@ -845,8 +833,7 @@ int vomp_pickup(struct vomp_call_state *call)
int vomp_hangup(struct vomp_call_state *call)
{
if (call){
if (config.debug.vomp)
DEBUG("Hanging up");
DEBUG(vomp, "Hanging up");
vomp_update_local_state(call, VOMP_STATE_CALLENDED);
vomp_update(call);
}
@ -855,7 +842,7 @@ int vomp_hangup(struct vomp_call_state *call)
static int vomp_extract_remote_codec_list(struct vomp_call_state *call, struct overlay_buffer *payload)
{
if (config.debug.vomp)
if (IF_DEBUG(vomp))
ob_dump(payload, "codec list mdp frame");
while(ob_remaining(payload)>0){
@ -914,8 +901,8 @@ int vomp_mdp_received(struct internal_mdp_header *header, struct overlay_buffer
if (!call)
return WHY("Unable to find or create call");
if (!recvr_session && (config.debug.vomp))
DEBUG("recvr_session==0, created call");
if (!recvr_session)
DEBUG(vomp, "recvr_session==0, created call");
// stale packet or forgery attempt? Should we just drop it?
if (sender_state < call->remote.state)
@ -993,8 +980,7 @@ int vomp_mdp_received(struct internal_mdp_header *header, struct overlay_buffer
if (call->initiated_call){
// hey, quit it, we were trying to call you.
if (config.debug.vomp)
DEBUGF("Rejecting call, invalid state transition");
DEBUGF(vomp, "Rejecting call, invalid state transition");
call->rejection_reason=VOMP_REJECT_BUSY;
recvr_state=VOMP_STATE_CALLENDED;
}else{
@ -1013,8 +999,7 @@ int vomp_mdp_received(struct internal_mdp_header *header, struct overlay_buffer
if (call->initiated_call){
recvr_state=VOMP_STATE_RINGINGOUT;
}else{
if (config.debug.vomp)
DEBUGF("Rejecting call, invalid state transition");
DEBUGF(vomp, "Rejecting call, invalid state transition");
recvr_state=VOMP_STATE_CALLENDED;
}
break;

View File

@ -387,8 +387,7 @@ DEFINE_CMD(app_vomp_console, 0,
"console");
static int app_vomp_console(const struct cli_parsed *parsed, struct cli_context *UNUSED(context))
{
if (config.debug.verbose)
DEBUG_cli_parsed(parsed);
DEBUG_cli_parsed(verbose, parsed);
monitor_alarm.poll.fd = monitor_client_open(&monitor_state);
if (monitor_alarm.poll.fd==-1)