summaryrefslogtreecommitdiff
path: root/other/bootstrap_daemon/src/config.c
diff options
context:
space:
mode:
authorMaxim Biro <nurupo.contributions@gmail.com>2016-01-01 00:55:09 -0500
committerMaxim Biro <nurupo.contributions@gmail.com>2016-01-01 00:55:09 -0500
commitda76da6c95fedf6014b69ed475cce074ad0afda9 (patch)
tree6df3ca30e72982a5166b526be192ee745a9161ef /other/bootstrap_daemon/src/config.c
parent7d86caf51fd2f127a7f12c90293981650f6aae3c (diff)
Remove dependency on files from testing directory
Also remove unneeded includes and refactor sleep define.
Diffstat (limited to 'other/bootstrap_daemon/src/config.c')
-rw-r--r--other/bootstrap_daemon/src/config.c32
1 files changed, 27 insertions, 5 deletions
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 @@
26#include "config_defaults.h" 26#include "config_defaults.h"
27#include "log.h" 27#include "log.h"
28 28
29// C 29#include <stdlib.h>
30//#include <stdlib.h> 30#include <string.h>
31#include <string.h> 31#include <string.h>
32 32
33// 3rd party
34#include <libconfig.h> 33#include <libconfig.h>
35 34
36// toxcore
37#include "../../bootstrap_node_packets.h" 35#include "../../bootstrap_node_packets.h"
38//#include "../../testing/misc_tools.c"
39 36
40// Parses tcp relay ports from `cfg` and puts them into `tcp_relay_ports` array 37// Parses tcp relay ports from `cfg` and puts them into `tcp_relay_ports` array
41// 38//
@@ -296,6 +293,31 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
296 return 1; 293 return 1;
297} 294}
298 295
296// Converts a hex string with even number of characters into binary
297//
298// You are responsible for freeing the return value!
299//
300// Returns binary on success,
301// NULL on failure
302
303uint8_t *hex_string_to_bin(char *hex_string)
304{
305 if (strlen(hex_string) % 2 != 0) {
306 return NULL;
307 }
308
309 size_t len = strlen(hex_string) / 2;
310 uint8_t *ret = malloc(len);
311
312 char *pos = hex_string;
313 size_t i;
314 for (i = 0; i < len; ++i, pos += 2) {
315 sscanf(pos, "%2hhx", &ret[i]);
316 }
317
318 return ret;
319}
320
299int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) 321int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
300{ 322{
301 const char *NAME_BOOTSTRAP_NODES = "bootstrap_nodes"; 323 const char *NAME_BOOTSTRAP_NODES = "bootstrap_nodes";