diff options
Diffstat (limited to 'other/bootstrap_daemon/tox_bootstrap_daemon.c')
-rw-r--r-- | other/bootstrap_daemon/tox_bootstrap_daemon.c | 236 |
1 files changed, 208 insertions, 28 deletions
diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index abad7760..6853358a 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c | |||
@@ -21,28 +21,39 @@ | |||
21 | * | 21 | * |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <sys/types.h> | 24 | // system provided |
25 | #include <arpa/inet.h> | ||
26 | #include <syslog.h> | ||
25 | #include <sys/stat.h> | 27 | #include <sys/stat.h> |
28 | #include <sys/types.h> | ||
26 | #include <unistd.h> | 29 | #include <unistd.h> |
27 | #include <syslog.h> | ||
28 | 30 | ||
31 | // C | ||
29 | #include <stdio.h> | 32 | #include <stdio.h> |
30 | #include <stdlib.h> | 33 | #include <stdlib.h> |
31 | #include <libconfig.h> | ||
32 | #include <arpa/inet.h> | ||
33 | #include <string.h> | 34 | #include <string.h> |
34 | 35 | ||
36 | // 3rd party | ||
37 | #include <libconfig.h> | ||
38 | |||
39 | // ./configure | ||
35 | #ifdef HAVE_CONFIG_H | 40 | #ifdef HAVE_CONFIG_H |
36 | #include "config.h" | 41 | #include "config.h" |
37 | #endif | 42 | #endif |
38 | 43 | ||
39 | #include "../../toxcore/onion_announce.h" | 44 | // toxcore |
40 | #include "../../toxcore/LAN_discovery.h" | 45 | #include "../../toxcore/LAN_discovery.h" |
46 | #include "../../toxcore/onion_announce.h" | ||
47 | #include "../../toxcore/TCP_server.h" | ||
41 | #include "../../toxcore/util.h" | 48 | #include "../../toxcore/util.h" |
42 | 49 | ||
50 | // misc | ||
51 | #include "../bootstrap_node_packets.c" | ||
43 | #include "../../testing/misc_tools.c" | 52 | #include "../../testing/misc_tools.c" |
44 | 53 | ||
54 | |||
45 | #define DAEMON_NAME "tox_bootstrap_daemon" | 55 | #define DAEMON_NAME "tox_bootstrap_daemon" |
56 | #define DAEMON_VERSION_NUMBER 2014051700UL // yyyymmmddvv format: yyyy year, mm month, dd day, vv version change count for that day | ||
46 | 57 | ||
47 | #define SLEEP_TIME_MILLISECONDS 30 | 58 | #define SLEEP_TIME_MILLISECONDS 30 |
48 | #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) | 59 | #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) |
@@ -52,6 +63,12 @@ | |||
52 | #define DEFAULT_PORT 33445 | 63 | #define DEFAULT_PORT 33445 |
53 | #define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false | 64 | #define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false |
54 | #define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false | 65 | #define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false |
66 | #define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false | ||
67 | #define DEFAULT_ENABLE_MOTD 1 // 1 - true, 0 - false | ||
68 | #define DEFAULT_MOTD DAEMON_NAME | ||
69 | |||
70 | #define MIN_ALLOWED_PORT 1 | ||
71 | #define MAX_ALLOWED_PORT 65535 | ||
55 | 72 | ||
56 | 73 | ||
57 | // Uses the already existing key or creates one if it didn't exist | 74 | // Uses the already existing key or creates one if it didn't exist |
@@ -96,15 +113,81 @@ int manage_keys(DHT *dht, char *keys_file_path) | |||
96 | return 1; | 113 | return 1; |
97 | } | 114 | } |
98 | 115 | ||
116 | // Parses tcp relay ports from `cfg` and puts them into `tcp_relay_ports` array | ||
117 | // | ||
118 | // Supposed to be called from get_general_config only | ||
119 | // | ||
120 | // Important: iff `tcp_relay_port_count` > 0, then you are responsible for freeing `tcp_relay_ports` | ||
121 | |||
122 | void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int *tcp_relay_port_count) | ||
123 | { | ||
124 | const char *NAME_TCP_RELAY_PORTS = "tcp_relay_ports"; | ||
125 | |||
126 | *tcp_relay_port_count = 0; | ||
127 | |||
128 | config_setting_t *ports_array = config_lookup(cfg, NAME_TCP_RELAY_PORTS); | ||
129 | |||
130 | if (ports_array == NULL) { | ||
131 | syslog(LOG_WARNING, "No '%s' setting in the configuration file.\n", NAME_TCP_RELAY_PORTS); | ||
132 | return; | ||
133 | } | ||
134 | |||
135 | if (config_setting_is_array(ports_array) == CONFIG_FALSE) { | ||
136 | syslog(LOG_WARNING, "'%s' setting should be an array. Array syntax: 'setting = [value1, value2, ...]'.\n", NAME_TCP_RELAY_PORTS); | ||
137 | return; | ||
138 | } | ||
139 | |||
140 | int config_port_count = config_setting_length(ports_array); | ||
141 | if (config_port_count == 0) { | ||
142 | syslog(LOG_WARNING, "'%s' is empty.\n", NAME_TCP_RELAY_PORTS); | ||
143 | return; | ||
144 | } | ||
145 | |||
146 | *tcp_relay_ports = malloc(config_port_count * sizeof(uint16_t)); | ||
147 | |||
148 | config_setting_t *elem; | ||
149 | int i; | ||
150 | |||
151 | for (i = 0; i < config_port_count; i ++) { | ||
152 | |||
153 | elem = config_setting_get_elem(ports_array, i); | ||
154 | |||
155 | if (elem == NULL) { | ||
156 | // it's NULL if `ports_array` is not an array (we have that check ealier) or if `i` is out of range, which should not be | ||
157 | syslog(LOG_WARNING, "Port #%d: Something went wrong while parsing the port. Stopping reading ports.\n", i); | ||
158 | break; | ||
159 | } | ||
160 | |||
161 | if (config_setting_is_number(elem) == CONFIG_FALSE) { | ||
162 | syslog(LOG_WARNING, "Port #%d: Not a number. Skipping.\n", i); | ||
163 | continue; | ||
164 | } | ||
165 | |||
166 | (*tcp_relay_ports)[*tcp_relay_port_count] = config_setting_get_int(elem); | ||
167 | if ((*tcp_relay_ports)[i] < MIN_ALLOWED_PORT || (*tcp_relay_ports)[i] > MAX_ALLOWED_PORT) { | ||
168 | syslog(LOG_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, (*tcp_relay_ports)[i], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); | ||
169 | continue; | ||
170 | } | ||
171 | |||
172 | (*tcp_relay_port_count) ++; | ||
173 | } | ||
174 | |||
175 | // the loop above skips invalid ports, so we adjust the allocated memory size | ||
176 | *tcp_relay_ports = realloc(*tcp_relay_ports, *tcp_relay_port_count * sizeof(uint16_t)); | ||
177 | } | ||
178 | |||
99 | // Gets general config options | 179 | // Gets general config options |
100 | // | 180 | // |
101 | // Important: you are responsible for freeing `pid_file_path` and `keys_file_path` | 181 | // Important: you are responsible for freeing `pid_file_path` and `keys_file_path` |
182 | // also, iff `tcp_relay_ports_count` > 0, then you are responsible for freeing `tcp_relay_ports` | ||
183 | // and also `motd` iff `enable_motd` is set | ||
102 | // | 184 | // |
103 | // returns 1 on success | 185 | // returns 1 on success |
104 | // 0 on failure, doesn't modify any data pointed by arguments | 186 | // 0 on failure, doesn't modify any data pointed by arguments |
105 | 187 | ||
106 | int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6, | 188 | int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6, |
107 | int *enable_lan_discovery) | 189 | int *enable_lan_discovery, int *enable_tcp_relay, uint16_t **tcp_relay_ports, int *tcp_relay_port_count, |
190 | int *enable_motd, char **motd) | ||
108 | { | 191 | { |
109 | config_t cfg; | 192 | config_t cfg; |
110 | 193 | ||
@@ -113,6 +196,9 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi | |||
113 | const char *NAME_KEYS_FILE_PATH = "keys_file_path"; | 196 | const char *NAME_KEYS_FILE_PATH = "keys_file_path"; |
114 | const char *NAME_ENABLE_IPV6 = "enable_ipv6"; | 197 | const char *NAME_ENABLE_IPV6 = "enable_ipv6"; |
115 | const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery"; | 198 | const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery"; |
199 | const char *NAME_ENABLE_TCP_RELAY = "enable_tcp_relay"; | ||
200 | const char *NAME_ENABLE_MOTD = "enable_motd"; | ||
201 | const char *NAME_MOTD = "motd"; | ||
116 | 202 | ||
117 | config_init(&cfg); | 203 | config_init(&cfg); |
118 | 204 | ||
@@ -169,6 +255,44 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi | |||
169 | *enable_lan_discovery = DEFAULT_ENABLE_LAN_DISCOVERY; | 255 | *enable_lan_discovery = DEFAULT_ENABLE_LAN_DISCOVERY; |
170 | } | 256 | } |
171 | 257 | ||
258 | // Get TCP relay option | ||
259 | if (config_lookup_bool(&cfg, NAME_ENABLE_TCP_RELAY, enable_tcp_relay) == CONFIG_FALSE) { | ||
260 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_TCP_RELAY); | ||
261 | syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_TCP_RELAY, | ||
262 | DEFAULT_ENABLE_TCP_RELAY ? "true" : "false"); | ||
263 | *enable_tcp_relay = DEFAULT_ENABLE_TCP_RELAY; | ||
264 | } | ||
265 | |||
266 | if (*enable_tcp_relay) { | ||
267 | parse_tcp_relay_ports_config(&cfg, tcp_relay_ports, tcp_relay_port_count); | ||
268 | } else { | ||
269 | *tcp_relay_port_count = 0; | ||
270 | } | ||
271 | |||
272 | // Get MOTD option | ||
273 | if (config_lookup_bool(&cfg, NAME_ENABLE_MOTD, enable_motd) == CONFIG_FALSE) { | ||
274 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_MOTD); | ||
275 | syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_MOTD, | ||
276 | DEFAULT_ENABLE_MOTD ? "true" : "false"); | ||
277 | *enable_motd = DEFAULT_ENABLE_MOTD; | ||
278 | } | ||
279 | |||
280 | if (*enable_motd) { | ||
281 | // Get MOTD | ||
282 | const char *tmp_motd; | ||
283 | |||
284 | if (config_lookup_string(&cfg, NAME_MOTD, &tmp_motd) == CONFIG_FALSE) { | ||
285 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_MOTD); | ||
286 | syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_MOTD, DEFAULT_MOTD); | ||
287 | tmp_motd = DEFAULT_MOTD; | ||
288 | } | ||
289 | size_t tmp_motd_length = strlen(tmp_motd) + 1; | ||
290 | size_t motd_length = tmp_motd_length > MAX_MOTD_LENGTH ? MAX_MOTD_LENGTH : tmp_motd_length; | ||
291 | *motd = malloc(motd_length); | ||
292 | strncpy(*motd, tmp_motd, motd_length); | ||
293 | (*motd)[MAX_MOTD_LENGTH - 1] = '\0'; | ||
294 | } | ||
295 | |||
172 | config_destroy(&cfg); | 296 | config_destroy(&cfg); |
173 | 297 | ||
174 | syslog(LOG_DEBUG, "Successfully read:\n"); | 298 | syslog(LOG_DEBUG, "Successfully read:\n"); |
@@ -178,6 +302,25 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi | |||
178 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false"); | 302 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false"); |
179 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false"); | 303 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false"); |
180 | 304 | ||
305 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false"); | ||
306 | // show info about tcp ports only if tcp relay is enabled | ||
307 | if (*enable_tcp_relay) { | ||
308 | if (*tcp_relay_port_count == 0) { | ||
309 | syslog(LOG_DEBUG, "No TCP ports could be read.\n"); | ||
310 | } else { | ||
311 | syslog(LOG_DEBUG, "Read %d TCP ports:\n", *tcp_relay_port_count); | ||
312 | int i; | ||
313 | for (i = 0; i < *tcp_relay_port_count; i ++) { | ||
314 | syslog(LOG_DEBUG, "Port #%d: %u\n", i, (*tcp_relay_ports)[i]); | ||
315 | } | ||
316 | } | ||
317 | } | ||
318 | |||
319 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_MOTD, *enable_motd ? "true" : "false"); | ||
320 | if (*enable_motd) { | ||
321 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_MOTD, *motd); | ||
322 | } | ||
323 | |||
181 | return 1; | 324 | return 1; |
182 | } | 325 | } |
183 | 326 | ||
@@ -252,15 +395,14 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
252 | } | 395 | } |
253 | 396 | ||
254 | // Process settings | 397 | // Process settings |
255 | if (strlen(bs_public_key) != 64) { | 398 | if (strlen(bs_public_key) != crypto_box_PUBLICKEYBYTES*2) { |
256 | syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %s. Skipping the node.\n", i, NAME_PUBLIC_KEY, | 399 | syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %s. Skipping the node.\n", i, NAME_PUBLIC_KEY, |
257 | bs_public_key); | 400 | bs_public_key); |
258 | goto next; | 401 | goto next; |
259 | } | 402 | } |
260 | 403 | ||
261 | // not (1 <= port <= 65535) | 404 | if (bs_port < MIN_ALLOWED_PORT || bs_port > MAX_ALLOWED_PORT) { |
262 | if (bs_port < 1 || bs_port > 65535) { | 405 | syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %d, should be in [%d, %d]. Skipping the node.\n", i, NAME_PORT, bs_port, MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); |
263 | syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %d. Skipping the node.\n", i, NAME_PORT, bs_port); | ||
264 | goto next; | 406 | goto next; |
265 | } | 407 | } |
266 | 408 | ||
@@ -277,9 +419,9 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
277 | syslog(LOG_DEBUG, "Successfully added bootstrap node #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key); | 419 | syslog(LOG_DEBUG, "Successfully added bootstrap node #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key); |
278 | 420 | ||
279 | next: | 421 | next: |
280 | // config_setting_lookup_string() allocates string inside and doesn't allow us to free it | 422 | // config_setting_lookup_string() allocates string inside and doesn't allow us to free it direcly |
281 | // so in order to reuse `bs_public_key` and `bs_address` we have to remove the element | 423 | // though it's freed when the element is removed, so we free it right away in order to keep memory |
282 | // which will cause libconfig to free allocated strings | 424 | // consumption minimal |
283 | config_setting_remove_elem(node_list, 0); | 425 | config_setting_remove_elem(node_list, 0); |
284 | i++; | 426 | i++; |
285 | } | 427 | } |
@@ -293,17 +435,13 @@ next: | |||
293 | 435 | ||
294 | void print_public_key(uint8_t *public_key) | 436 | void print_public_key(uint8_t *public_key) |
295 | { | 437 | { |
296 | char buffer[64 + 1]; | 438 | char buffer[2*crypto_box_PUBLICKEYBYTES + 1]; |
297 | int index = 0; | 439 | int index = 0; |
298 | 440 | ||
299 | int i; | 441 | int i; |
300 | 442 | ||
301 | for (i = 0; i < 32; i++) { | 443 | for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) { |
302 | if (public_key[i] < 16) { | 444 | index += sprintf(buffer + index, "%02hhX", public_key[i]); |
303 | index += sprintf(buffer + index, "0"); | ||
304 | } | ||
305 | |||
306 | index += sprintf(buffer + index, "%hhX", public_key[i]); | ||
307 | } | 445 | } |
308 | 446 | ||
309 | syslog(LOG_INFO, "Public Key: %s\n", buffer); | 447 | syslog(LOG_INFO, "Public Key: %s\n", buffer); |
@@ -315,6 +453,8 @@ int main(int argc, char *argv[]) | |||
315 | { | 453 | { |
316 | openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON); | 454 | openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON); |
317 | 455 | ||
456 | syslog(LOG_INFO, "Running \"%s\" version %lu.\n", DAEMON_NAME, DAEMON_VERSION_NUMBER); | ||
457 | |||
318 | if (argc < 2) { | 458 | if (argc < 2) { |
319 | syslog(LOG_ERR, "Please specify a path to a configuration file as the first argument. Exiting.\n"); | 459 | syslog(LOG_ERR, "Please specify a path to a configuration file as the first argument. Exiting.\n"); |
320 | return 1; | 460 | return 1; |
@@ -325,17 +465,21 @@ int main(int argc, char *argv[]) | |||
325 | int port; | 465 | int port; |
326 | int enable_ipv6; | 466 | int enable_ipv6; |
327 | int enable_lan_discovery; | 467 | int enable_lan_discovery; |
468 | int enable_tcp_relay; | ||
469 | uint16_t *tcp_relay_ports; | ||
470 | int tcp_relay_port_count; | ||
471 | int enable_motd; | ||
472 | char *motd; | ||
328 | 473 | ||
329 | if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_lan_discovery)) { | 474 | if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_lan_discovery, &enable_tcp_relay, &tcp_relay_ports, &tcp_relay_port_count, &enable_motd, &motd)) { |
330 | syslog(LOG_DEBUG, "General config read successfully\n"); | 475 | syslog(LOG_DEBUG, "General config read successfully\n"); |
331 | } else { | 476 | } else { |
332 | syslog(LOG_ERR, "Couldn't read config file: %s. Exiting.\n", cfg_file_path); | 477 | syslog(LOG_ERR, "Couldn't read config file: %s. Exiting.\n", cfg_file_path); |
333 | return 1; | 478 | return 1; |
334 | } | 479 | } |
335 | 480 | ||
336 | // not (1 <= port <= 65535) | 481 | if (port < MIN_ALLOWED_PORT || port > MAX_ALLOWED_PORT) { |
337 | if (port < 1 || port > 65535) { | 482 | syslog(LOG_ERR, "Invalid port: %d, should be in [%d, %d]. Exiting.\n", port, MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); |
338 | syslog(LOG_ERR, "Invalid port: %d, must be 1 <= port <= 65535. Exiting.\n", port); | ||
339 | return 1; | 483 | return 1; |
340 | } | 484 | } |
341 | 485 | ||
@@ -363,19 +507,46 @@ int main(int argc, char *argv[]) | |||
363 | return 1; | 507 | return 1; |
364 | } | 508 | } |
365 | 509 | ||
366 | if (enable_lan_discovery) { | 510 | if (enable_motd) { |
367 | LANdiscovery_init(dht); | 511 | if (bootstrap_set_callbacks(dht->net, DAEMON_VERSION_NUMBER, (uint8_t*)motd, strlen(motd) + 1) == 0) { |
512 | syslog(LOG_DEBUG, "Set MOTD successfully.\n"); | ||
513 | } else { | ||
514 | syslog(LOG_ERR, "Couldn't set MOTD: %s. Exiting.\n", motd); | ||
515 | return 1; | ||
516 | } | ||
517 | free(motd); | ||
368 | } | 518 | } |
369 | 519 | ||
370 | if (manage_keys(dht, keys_file_path)) { | 520 | if (manage_keys(dht, keys_file_path)) { |
371 | syslog(LOG_DEBUG, "Keys are managed successfully\n"); | 521 | syslog(LOG_DEBUG, "Keys are managed successfully.\n"); |
372 | } else { | 522 | } else { |
373 | syslog(LOG_ERR, "Couldn't read/write: %s. Exiting.\n", keys_file_path); | 523 | syslog(LOG_ERR, "Couldn't read/write: %s. Exiting.\n", keys_file_path); |
374 | return 1; | 524 | return 1; |
375 | } | 525 | } |
376 | 526 | ||
527 | TCP_Server *tcp_server = NULL; | ||
528 | |||
529 | if (enable_tcp_relay) { | ||
530 | if (tcp_relay_port_count == 0) { | ||
531 | syslog(LOG_ERR, "No TCP relay ports read. Exiting.\n"); | ||
532 | return 1; | ||
533 | } | ||
534 | |||
535 | tcp_server = new_TCP_server(enable_ipv6, tcp_relay_port_count, tcp_relay_ports, dht->self_public_key, dht->self_secret_key, onion); | ||
536 | |||
537 | // tcp_relay_port_count != 0 at this point | ||
538 | free(tcp_relay_ports); | ||
539 | |||
540 | if (tcp_server != NULL) { | ||
541 | syslog(LOG_DEBUG, "Initialized Tox TCP server successfully.\n"); | ||
542 | } else { | ||
543 | syslog(LOG_ERR, "Couldn't initialize Tox TCP server. Exiting.\n"); | ||
544 | return 1; | ||
545 | } | ||
546 | } | ||
547 | |||
377 | if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6)) { | 548 | if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6)) { |
378 | syslog(LOG_DEBUG, "List of bootstrap nodes read successfully\n"); | 549 | syslog(LOG_DEBUG, "List of bootstrap nodes read successfully.\n"); |
379 | } else { | 550 | } else { |
380 | syslog(LOG_ERR, "Couldn't read list of bootstrap nodes in %s. Exiting.\n", cfg_file_path); | 551 | syslog(LOG_ERR, "Couldn't read list of bootstrap nodes in %s. Exiting.\n", cfg_file_path); |
381 | return 1; | 552 | return 1; |
@@ -435,6 +606,11 @@ int main(int argc, char *argv[]) | |||
435 | 606 | ||
436 | int waiting_for_dht_connection = 1; | 607 | int waiting_for_dht_connection = 1; |
437 | 608 | ||
609 | if (enable_lan_discovery) { | ||
610 | LANdiscovery_init(dht); | ||
611 | syslog(LOG_DEBUG, "Initialized LAN discovery.\n"); | ||
612 | } | ||
613 | |||
438 | while (1) { | 614 | while (1) { |
439 | do_DHT(dht); | 615 | do_DHT(dht); |
440 | 616 | ||
@@ -443,6 +619,10 @@ int main(int argc, char *argv[]) | |||
443 | last_LANdiscovery = unix_time(); | 619 | last_LANdiscovery = unix_time(); |
444 | } | 620 | } |
445 | 621 | ||
622 | if (enable_tcp_relay) { | ||
623 | do_TCP_server(tcp_server); | ||
624 | } | ||
625 | |||
446 | networking_poll(dht->net); | 626 | networking_poll(dht->net); |
447 | 627 | ||
448 | if (waiting_for_dht_connection && DHT_isconnected(dht)) { | 628 | if (waiting_for_dht_connection && DHT_isconnected(dht)) { |