From da76da6c95fedf6014b69ed475cce074ad0afda9 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Fri, 1 Jan 2016 00:55:09 -0500 Subject: Remove dependency on files from testing directory Also remove unneeded includes and refactor sleep define. --- other/bootstrap_daemon/src/config.c | 32 ++++++++++++++++++++++++----- other/bootstrap_daemon/src/tox-bootstrapd.c | 17 ++------------- 2 files changed, 29 insertions(+), 20 deletions(-) (limited to 'other/bootstrap_daemon/src') diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c index 270d399f..ee9fbdd2 100644 --- a/other/bootstrap_daemon/src/config.c +++ b/other/bootstrap_daemon/src/config.c @@ -26,16 +26,13 @@ #include "config_defaults.h" #include "log.h" -// C -//#include +#include +#include #include -// 3rd party #include -// toxcore #include "../../bootstrap_node_packets.h" -//#include "../../testing/misc_tools.c" // Parses tcp relay ports from `cfg` and puts them into `tcp_relay_ports` array // @@ -296,6 +293,31 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k return 1; } +// Converts a hex string with even number of characters into binary +// +// You are responsible for freeing the return value! +// +// Returns binary on success, +// NULL on failure + +uint8_t *hex_string_to_bin(char *hex_string) +{ + if (strlen(hex_string) % 2 != 0) { + return NULL; + } + + size_t len = strlen(hex_string) / 2; + uint8_t *ret = malloc(len); + + char *pos = hex_string; + size_t i; + for (i = 0; i < len; ++i, pos += 2) { + sscanf(pos, "%2hhx", &ret[i]); + } + + return ret; +} + int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) { const char *NAME_BOOTSTRAP_NODES = "bootstrap_nodes"; diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 8ffef009..45b7add0 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -22,11 +22,6 @@ */ // system provided -#include -#include -#include -#include -#include #include // C @@ -34,11 +29,6 @@ #include #include -// ./configure -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - // toxcore #include "../../toxcore/LAN_discovery.h" #include "../../toxcore/onion_announce.h" @@ -47,16 +37,13 @@ // misc #include "../bootstrap_node_packets.h" -#include "../../testing/misc_tools.c" #include "command_line_arguments.h" #include "config.h" #include "global.h" #include "log.h" - -#define SLEEP_TIME_MILLISECONDS 30 -#define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) +#define SLEEP_MILLISECONDS(MS) usleep(1000*MS) // Uses the already existing key or creates one if it didn't exist // @@ -346,7 +333,7 @@ int main(int argc, char *argv[]) waiting_for_dht_connection = 0; } - sleep; + SLEEP_MILLISECONDS(30); } return 1; -- cgit v1.2.3