summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--other/bootstrap_daemon/tox_bootstrap_daemon.c29
-rw-r--r--other/bootstrap_daemon/tox_bootstrap_daemon.sh4
2 files changed, 15 insertions, 18 deletions
diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c
index dce181a4..410a3453 100644
--- a/other/bootstrap_daemon/tox_bootstrap_daemon.c
+++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c
@@ -50,6 +50,7 @@
50// misc 50// misc
51#include "../../testing/misc_tools.c" 51#include "../../testing/misc_tools.c"
52 52
53
53#define DAEMON_NAME "tox_bootstrap_daemon" 54#define DAEMON_NAME "tox_bootstrap_daemon"
54 55
55#define SLEEP_TIME_MILLISECONDS 30 56#define SLEEP_TIME_MILLISECONDS 30
@@ -60,7 +61,7 @@
60#define DEFAULT_PORT 33445 61#define DEFAULT_PORT 33445
61#define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false 62#define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false
62#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false 63#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false
63#define DEFAULT_ENABLE_TCP_RELAY 1 64#define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false
64 65
65#define MIN_ALLOWED_PORT 1 66#define MIN_ALLOWED_PORT 1
66#define MAX_ALLOWED_PORT 65535 67#define MAX_ALLOWED_PORT 65535
@@ -356,7 +357,7 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6)
356 } 357 }
357 358
358 // Process settings 359 // Process settings
359 if (strlen(bs_public_key) != 64) { 360 if (strlen(bs_public_key) != crypto_box_PUBLICKEYBYTES*2) {
360 syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %s. Skipping the node.\n", i, NAME_PUBLIC_KEY, 361 syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %s. Skipping the node.\n", i, NAME_PUBLIC_KEY,
361 bs_public_key); 362 bs_public_key);
362 goto next; 363 goto next;
@@ -380,9 +381,9 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6)
380 syslog(LOG_DEBUG, "Successfully added bootstrap node #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key); 381 syslog(LOG_DEBUG, "Successfully added bootstrap node #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key);
381 382
382next: 383next:
383 // config_setting_lookup_string() allocates string inside and doesn't allow us to free it 384 // config_setting_lookup_string() allocates string inside and doesn't allow us to free it direcly
384 // so in order to reuse `bs_public_key` and `bs_address` we have to remove the element 385 // though it's freed when the element is removed, so we free it right away in order to keep memory
385 // which will cause libconfig to free allocated strings 386 // consumption minimal
386 config_setting_remove_elem(node_list, 0); 387 config_setting_remove_elem(node_list, 0);
387 i++; 388 i++;
388 } 389 }
@@ -396,17 +397,13 @@ next:
396 397
397void print_public_key(uint8_t *public_key) 398void print_public_key(uint8_t *public_key)
398{ 399{
399 char buffer[64 + 1]; 400 char buffer[2*crypto_box_PUBLICKEYBYTES + 1];
400 int index = 0; 401 int index = 0;
401 402
402 int i; 403 int i;
403 404
404 for (i = 0; i < 32; i++) { 405 for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) {
405 if (public_key[i] < 16) { 406 index += sprintf(buffer + index, "%02hhX", public_key[i]);
406 index += sprintf(buffer + index, "0");
407 }
408
409 index += sprintf(buffer + index, "%hhX", public_key[i]);
410 } 407 }
411 408
412 syslog(LOG_INFO, "Public Key: %s\n", buffer); 409 syslog(LOG_INFO, "Public Key: %s\n", buffer);
@@ -468,10 +465,6 @@ int main(int argc, char *argv[])
468 return 1; 465 return 1;
469 } 466 }
470 467
471 if (enable_lan_discovery) {
472 LANdiscovery_init(dht);
473 }
474
475 if (manage_keys(dht, keys_file_path)) { 468 if (manage_keys(dht, keys_file_path)) {
476 syslog(LOG_DEBUG, "Keys are managed successfully\n"); 469 syslog(LOG_DEBUG, "Keys are managed successfully\n");
477 } else { 470 } else {
@@ -559,6 +552,10 @@ int main(int argc, char *argv[])
559 552
560 int waiting_for_dht_connection = 1; 553 int waiting_for_dht_connection = 1;
561 554
555 if (enable_lan_discovery) {
556 LANdiscovery_init(dht);
557 }
558
562 while (1) { 559 while (1) {
563 do_DHT(dht); 560 do_DHT(dht);
564 561
diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.sh b/other/bootstrap_daemon/tox_bootstrap_daemon.sh
index 83d9a119..e083ea0b 100644
--- a/other/bootstrap_daemon/tox_bootstrap_daemon.sh
+++ b/other/bootstrap_daemon/tox_bootstrap_daemon.sh
@@ -11,12 +11,12 @@
11 11
12# PATH should only include /usr/* if it runs after the mountnfs.sh script 12# PATH should only include /usr/* if it runs after the mountnfs.sh script
13PATH=/sbin:/usr/sbin:/bin:/usr/bin 13PATH=/sbin:/usr/sbin:/bin:/usr/bin
14DESC="Tox DHT bootstrap server daemon" 14DESC="Tox DHT bootstrap daemon"
15NAME=tox_bootstrap_daemon 15NAME=tox_bootstrap_daemon
16# You may want to change USER if you are using it anywhere else 16# You may want to change USER if you are using it anywhere else
17USER=tom 17USER=tom
18CFG=/home/$USER/.$NAME/conf 18CFG=/home/$USER/.$NAME/conf
19DAEMON=/home/$USER/$NAME 19DAEMON=/home/$USER/.$NAME/$NAME
20DAEMON_ARGS="$CFG" 20DAEMON_ARGS="$CFG"
21PIDFILE=/home/$USER/.$NAME/pid 21PIDFILE=/home/$USER/.$NAME/pid
22SCRIPTNAME=/etc/init.d/$NAME 22SCRIPTNAME=/etc/init.d/$NAME