From: Guus Sliepen Date: Mon, 21 Apr 2014 21:41:12 +0000 (+0200) Subject: Move debug_level to mesh. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=8eab1de5c6b24e90c865fd204887e313e99e32c6;p=meshlink Move debug_level to mesh. --- diff --git a/src/logger.c b/src/logger.c index eb630890..e6303c66 100644 --- a/src/logger.c +++ b/src/logger.c @@ -20,11 +20,11 @@ #include "system.h" #include "logger.h" - -debug_t debug_level = DEBUG_NOTHING; +#include "meshlink_internal.h" +#include "sptps.h" void logger(int level, int priority, const char *format, ...) { - if(level > debug_level) + if(level > mesh->debug_level) return; va_list ap; @@ -41,7 +41,7 @@ void logger(int level, int priority, const char *format, ...) { } // TODO: make sure this gets used somewhere -static void sptps_logger(struct sptps *s, int s_errno, const char *format, va_list ap) { +static void sptps_logger(sptps_t *s, int s_errno, const char *format, va_list ap) { char message[1024] = ""; int len = vsnprintf(message, sizeof message, format, ap); if(len > 0 && len < sizeof message && message[len - 1] == '\n') diff --git a/src/logger.h b/src/logger.h index 89d65616..b882612f 100644 --- a/src/logger.h +++ b/src/logger.h @@ -63,7 +63,6 @@ enum { #endif #endif -extern debug_t debug_level; extern void logger(int, int, const char *, ...) __attribute__ ((__format__(printf, 3, 4))); #endif /* __TINC_LOGGER_H__ */ diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index 57c2a8f6..4be2f739 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -24,6 +24,7 @@ #include "event.h" #include "hash.h" +#include "logger.h" #include "meshlink.h" #include "sockaddr.h" @@ -89,6 +90,8 @@ struct meshlink_handle { hash_t *node_udp_cache; struct connection_t *everyone; struct ecdsa *invitation_key; + + debug_t debug_level; }; /// A handle for a MeshLink node. diff --git a/src/net_packet.c b/src/net_packet.c index d231c231..9420bdf5 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -649,7 +649,7 @@ void handle_incoming_vpn_data(void *data, int flags) { n = try_harder(&from, &pkt); if(n) update_node_udp(n, &from); - else if(debug_level >= DEBUG_PROTOCOL) { + else if(mesh->debug_level >= DEBUG_PROTOCOL) { hostname = sockaddr2hostname(&from); logger(DEBUG_PROTOCOL, LOG_WARNING, "Received UDP packet from unknown source %s", hostname); free(hostname); diff --git a/src/net_setup.c b/src/net_setup.c index decaaaa4..7bee9d93 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -249,7 +249,7 @@ static bool add_listen_address(char *address, bool bindto) { io_add(&mesh->listen_socket[mesh->listen_sockets].tcp, handle_new_meta_connection, &mesh->listen_socket[mesh->listen_sockets], tcp_fd, IO_READ); io_add(&mesh->listen_socket[mesh->listen_sockets].udp, handle_incoming_vpn_data, &mesh->listen_socket[mesh->listen_sockets], udp_fd, IO_READ); - if(debug_level >= DEBUG_CONNECTIONS) { + if(mesh->debug_level >= DEBUG_CONNECTIONS) { char *hostname = sockaddr2hostname((sockaddr_t *) aip->ai_addr); logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Listening on %s", hostname); free(hostname); diff --git a/src/sptps_speed.c b/src/sptps_speed.c index e88c81fc..50db8b10 100644 --- a/src/sptps_speed.c +++ b/src/sptps_speed.c @@ -29,6 +29,7 @@ // Symbols necessary to link with logger.o bool send_request(void *c, const char *msg, ...) { return false; } +void *mesh; bool send_meta(void *c, const char *msg , int len) { return false; } char *logfilename = NULL; struct timeval now; diff --git a/src/sptps_test.c b/src/sptps_test.c index 63a48459..e9cab253 100644 --- a/src/sptps_test.c +++ b/src/sptps_test.c @@ -34,6 +34,7 @@ // Symbols necessary to link with logger.o bool send_request(void *c, const char *msg, ...) { return false; } +void *mesh; bool send_meta(void *c, const char *msg , int len) { return false; } char *logfilename = NULL; struct timeval now; diff --git a/src/tincd.c b/src/tincd.c index 32447056..7d580cf2 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -112,9 +112,9 @@ static bool parse_options(int argc, char **argv) { if(!optarg && optind < argc && *argv[optind] != '-') optarg = argv[optind++]; if(optarg) - debug_level = atoi(optarg); + mesh->debug_level = atoi(optarg); else - debug_level++; + mesh->debug_level++; break; case 1: /* show help */