diff options
author | Maxim Biro <nurupo.contributions@gmail.com> | 2014-10-12 23:21:59 -0400 |
---|---|---|
committer | Maxim Biro <nurupo.contributions@gmail.com> | 2014-10-12 23:22:25 -0400 |
commit | 1200e69a3fb1619a19b78bf52e815095dfb705d4 (patch) | |
tree | 1e93f70d79a4078e230b46ab38ca4312c6203aef | |
parent | 3d239822502cd3a0d8fe5e66d540f23257c60a52 (diff) |
Added IPv4 fallback, made IPv6 and IPv4 fallback enabled by default
-rw-r--r-- | other/bootstrap_daemon/tox-bootstrapd.c | 42 | ||||
-rw-r--r-- | other/bootstrap_daemon/tox-bootstrapd.conf | 27 |
2 files changed, 52 insertions, 17 deletions
diff --git a/other/bootstrap_daemon/tox-bootstrapd.c b/other/bootstrap_daemon/tox-bootstrapd.c index 1b69014c..4cc1426e 100644 --- a/other/bootstrap_daemon/tox-bootstrapd.c +++ b/other/bootstrap_daemon/tox-bootstrapd.c | |||
@@ -53,7 +53,7 @@ | |||
53 | 53 | ||
54 | 54 | ||
55 | #define DAEMON_NAME "tox-bootstrapd" | 55 | #define DAEMON_NAME "tox-bootstrapd" |
56 | #define DAEMON_VERSION_NUMBER 2014101000UL // yyyymmmddvv format: yyyy year, mm month, dd day, vv version change count for that day | 56 | #define DAEMON_VERSION_NUMBER 2014101200UL // yyyymmmddvv format: yyyy year, mm month, dd day, vv version change count for that day |
57 | 57 | ||
58 | #define SLEEP_TIME_MILLISECONDS 30 | 58 | #define SLEEP_TIME_MILLISECONDS 30 |
59 | #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) | 59 | #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) |
@@ -62,6 +62,7 @@ | |||
62 | #define DEFAULT_KEYS_FILE_PATH "tox-bootstrapd.keys" | 62 | #define DEFAULT_KEYS_FILE_PATH "tox-bootstrapd.keys" |
63 | #define DEFAULT_PORT 33445 | 63 | #define DEFAULT_PORT 33445 |
64 | #define DEFAULT_ENABLE_IPV6 1 // 1 - true, 0 - false | 64 | #define DEFAULT_ENABLE_IPV6 1 // 1 - true, 0 - false |
65 | #define DEFAULT_ENABLE_IPV4_FALLBACK 1 // 1 - true, 0 - false | ||
65 | #define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false | 66 | #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_TCP_RELAY 1 // 1 - true, 0 - false |
67 | #define DEFAULT_TCP_RELAY_PORTS 443, 3389, 33445 // comma-separated list of ports. make sure to adjust DEFAULT_TCP_RELAY_PORTS_COUNT accordingly | 68 | #define DEFAULT_TCP_RELAY_PORTS 443, 3389, 33445 // comma-separated list of ports. make sure to adjust DEFAULT_TCP_RELAY_PORTS_COUNT accordingly |
@@ -233,8 +234,8 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int | |||
233 | // 0 on failure, doesn't modify any data pointed by arguments | 234 | // 0 on failure, doesn't modify any data pointed by arguments |
234 | 235 | ||
235 | int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6, | 236 | int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6, |
236 | int *enable_lan_discovery, int *enable_tcp_relay, uint16_t **tcp_relay_ports, int *tcp_relay_port_count, | 237 | int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay, uint16_t **tcp_relay_ports, |
237 | int *enable_motd, char **motd) | 238 | int *tcp_relay_port_count, int *enable_motd, char **motd) |
238 | { | 239 | { |
239 | config_t cfg; | 240 | config_t cfg; |
240 | 241 | ||
@@ -242,6 +243,7 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi | |||
242 | const char *NAME_PID_FILE_PATH = "pid_file_path"; | 243 | const char *NAME_PID_FILE_PATH = "pid_file_path"; |
243 | const char *NAME_KEYS_FILE_PATH = "keys_file_path"; | 244 | const char *NAME_KEYS_FILE_PATH = "keys_file_path"; |
244 | const char *NAME_ENABLE_IPV6 = "enable_ipv6"; | 245 | const char *NAME_ENABLE_IPV6 = "enable_ipv6"; |
246 | const char *NAME_ENABLE_IPV4_FALLBACK = "enable_ipv4_fallback"; | ||
245 | const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery"; | 247 | const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery"; |
246 | const char *NAME_ENABLE_TCP_RELAY = "enable_tcp_relay"; | 248 | const char *NAME_ENABLE_TCP_RELAY = "enable_tcp_relay"; |
247 | const char *NAME_ENABLE_MOTD = "enable_motd"; | 249 | const char *NAME_ENABLE_MOTD = "enable_motd"; |
@@ -294,6 +296,13 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi | |||
294 | *enable_ipv6 = DEFAULT_ENABLE_IPV6; | 296 | *enable_ipv6 = DEFAULT_ENABLE_IPV6; |
295 | } | 297 | } |
296 | 298 | ||
299 | // Get IPv4 fallback option | ||
300 | if (config_lookup_bool(&cfg, NAME_ENABLE_IPV4_FALLBACK, enable_ipv4_fallback) == CONFIG_FALSE) { | ||
301 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_IPV4_FALLBACK); | ||
302 | syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, DEFAULT_ENABLE_IPV4_FALLBACK ? "true" : "false"); | ||
303 | *enable_ipv4_fallback = DEFAULT_ENABLE_IPV4_FALLBACK; | ||
304 | } | ||
305 | |||
297 | // Get LAN discovery option | 306 | // Get LAN discovery option |
298 | if (config_lookup_bool(&cfg, NAME_ENABLE_LAN_DISCOVERY, enable_lan_discovery) == CONFIG_FALSE) { | 307 | if (config_lookup_bool(&cfg, NAME_ENABLE_LAN_DISCOVERY, enable_lan_discovery) == CONFIG_FALSE) { |
299 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_LAN_DISCOVERY); | 308 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_LAN_DISCOVERY); |
@@ -348,6 +357,7 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi | |||
348 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_KEYS_FILE_PATH, *keys_file_path); | 357 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_KEYS_FILE_PATH, *keys_file_path); |
349 | syslog(LOG_DEBUG, "'%s': %d\n", NAME_PORT, *port); | 358 | syslog(LOG_DEBUG, "'%s': %d\n", NAME_PORT, *port); |
350 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false"); | 359 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false"); |
360 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, *enable_ipv4_fallback ? "true" : "false"); | ||
351 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false"); | 361 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false"); |
352 | 362 | ||
353 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false"); | 363 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false"); |
@@ -516,6 +526,7 @@ int main(int argc, char *argv[]) | |||
516 | char *pid_file_path, *keys_file_path; | 526 | char *pid_file_path, *keys_file_path; |
517 | int port; | 527 | int port; |
518 | int enable_ipv6; | 528 | int enable_ipv6; |
529 | int enable_ipv4_fallback; | ||
519 | int enable_lan_discovery; | 530 | int enable_lan_discovery; |
520 | int enable_tcp_relay; | 531 | int enable_tcp_relay; |
521 | uint16_t *tcp_relay_ports; | 532 | uint16_t *tcp_relay_ports; |
@@ -523,8 +534,8 @@ int main(int argc, char *argv[]) | |||
523 | int enable_motd; | 534 | int enable_motd; |
524 | char *motd; | 535 | char *motd; |
525 | 536 | ||
526 | if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_lan_discovery, | 537 | if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_ipv4_fallback, |
527 | &enable_tcp_relay, &tcp_relay_ports, &tcp_relay_port_count, &enable_motd, &motd)) { | 538 | &enable_lan_discovery, &enable_tcp_relay, &tcp_relay_ports, &tcp_relay_port_count, &enable_motd, &motd)) { |
528 | syslog(LOG_DEBUG, "General config read successfully\n"); | 539 | syslog(LOG_DEBUG, "General config read successfully\n"); |
529 | } else { | 540 | } else { |
530 | syslog(LOG_ERR, "Couldn't read config file: %s. Exiting.\n", cfg_file_path); | 541 | syslog(LOG_ERR, "Couldn't read config file: %s. Exiting.\n", cfg_file_path); |
@@ -547,7 +558,26 @@ int main(int argc, char *argv[]) | |||
547 | IP ip; | 558 | IP ip; |
548 | ip_init(&ip, enable_ipv6); | 559 | ip_init(&ip, enable_ipv6); |
549 | 560 | ||
550 | DHT *dht = new_DHT(new_networking(ip, port)); | 561 | Networking_Core *net = new_networking(ip, port); |
562 | |||
563 | if (net == NULL) { | ||
564 | if (enable_ipv6 && enable_ipv4_fallback) { | ||
565 | syslog(LOG_DEBUG, "Couldn't initialize IPv6 networking. Falling back to using IPv4.\n"); | ||
566 | enable_ipv6 = 0; | ||
567 | ip_init(&ip, enable_ipv6); | ||
568 | net = new_networking(ip, port); | ||
569 | if (net == NULL) { | ||
570 | syslog(LOG_DEBUG, "Couldn't fallback to IPv4. Exiting.\n"); | ||
571 | return 1; | ||
572 | } | ||
573 | } else { | ||
574 | syslog(LOG_DEBUG, "Couldn't initialize networking. Exiting.\n"); | ||
575 | return 1; | ||
576 | } | ||
577 | } | ||
578 | |||
579 | |||
580 | DHT *dht = new_DHT(net); | ||
551 | 581 | ||
552 | if (dht == NULL) { | 582 | if (dht == NULL) { |
553 | syslog(LOG_ERR, "Couldn't initialize Tox DHT instance. Exiting.\n"); | 583 | syslog(LOG_ERR, "Couldn't initialize Tox DHT instance. Exiting.\n"); |
diff --git a/other/bootstrap_daemon/tox-bootstrapd.conf b/other/bootstrap_daemon/tox-bootstrapd.conf index 710de2aa..4547d83d 100644 --- a/other/bootstrap_daemon/tox-bootstrapd.conf +++ b/other/bootstrap_daemon/tox-bootstrapd.conf | |||
@@ -1,46 +1,51 @@ | |||
1 | // Tox DHT bootstrap daemon configuration file. | 1 | // Tox DHT bootstrap daemon configuration file. |
2 | 2 | ||
3 | // Listening port. | 3 | // Listening port (UDP). |
4 | port = 33445 | 4 | port = 33445 |
5 | 5 | ||
6 | // A key file is like a password, so keep it where no one can read it. | 6 | // A key file is like a password, so keep it where no one can read it. |
7 | // If there is no key file, a new one will be generated. | 7 | // If there is no key file, a new one will be generated. |
8 | // The daemon should have permission to read/write to it. | 8 | // The daemon should have permission to read/write it. |
9 | keys_file_path = "/var/lib/tox-bootstrapd/keys" | 9 | keys_file_path = "/var/lib/tox-bootstrapd/keys" |
10 | 10 | ||
11 | // The PID file written to by daemon. | 11 | // The PID file written to by the daemon. |
12 | // Make sure that the user who runs the daemon has permissions to write to the | 12 | // Make sure that the user that daemon runs as has permissions to write to the |
13 | // PID file. | 13 | // PID file. |
14 | pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid" | 14 | pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid" |
15 | 15 | ||
16 | // Enable IPv6. | 16 | // Enable IPv6. |
17 | enable_ipv6 = false | 17 | enable_ipv6 = true |
18 | |||
19 | // Fallback to IPv4 in case IPv6 fails. | ||
20 | enable_ipv4_fallback = true | ||
18 | 21 | ||
19 | // Automatically bootstrap with nodes on local area network. | 22 | // Automatically bootstrap with nodes on local area network. |
20 | enable_lan_discovery = true | 23 | enable_lan_discovery = true |
21 | 24 | ||
22 | enable_tcp_relay = true | 25 | enable_tcp_relay = true |
23 | 26 | ||
24 | // Tox uses 443, 3389 and 33445 ports by default, so it's highly recommended to keep | 27 | // Tox uses 443, 3389 and 33445 ports by default, so it's highly encouraged to keep |
25 | // them. | 28 | // them. |
26 | tcp_relay_ports = [443, 3389, 33445] | 29 | tcp_relay_ports = [443, 3389, 33445] |
27 | 30 | ||
28 | // It's planned to use message of the day as a convenient method of checking | 31 | // Reply to MOTD (Message Of The Day) requests. |
29 | // whether a node is up or not, though there are other methods of doing that. | ||
30 | enable_motd = true | 32 | enable_motd = true |
31 | 33 | ||
34 | // Just a message that is sent when someone requests MOTD. | ||
35 | // Put anything you want, but note that it will be trimmed to fit into 255 bytes. | ||
32 | motd = "tox-bootstrapd" | 36 | motd = "tox-bootstrapd" |
33 | 37 | ||
34 | // Any number of nodes the daemon will bootstrap itself off. | 38 | // Any number of nodes the daemon will bootstrap itself off. |
39 | // | ||
35 | // Remember to replace the provided example with your own node list. | 40 | // Remember to replace the provided example with your own node list. |
36 | // There is a maintained list of bootstrap nodes on Tox's wiki, if you need it | 41 | // There is a maintained list of bootstrap nodes on Tox's wiki, if you need it |
37 | // (http://wiki.tox.im/Nodes). | 42 | // (http://wiki.tox.im/Nodes). |
43 | // | ||
38 | // You may leave the list empty or remove "bootstrap_nodes" completely, | 44 | // You may leave the list empty or remove "bootstrap_nodes" completely, |
39 | // in both cases this will be interpreted as if you don't want to bootstrap | 45 | // in both cases this will be interpreted as if you don't want to bootstrap |
40 | // from anyone. | 46 | // from anyone. |
41 | // address = any ipv4 or Any ipv4 or ipv6, depending on whether `enable_ipv6` | 47 | // |
42 | // is set or not, and also any US-ASCII domain name. | 48 | // address = any ipv4 or ipv6 address and also any US-ASCII domain name. |
43 | |||
44 | bootstrap_nodes = ( | 49 | bootstrap_nodes = ( |
45 | { | 50 | { |
46 | // NikolaiToryzin - US | 51 | // NikolaiToryzin - US |