summaryrefslogtreecommitdiff
path: root/other/bootstrap_daemon/tox-bootstrapd.c
diff options
context:
space:
mode:
authorMaxim Biro <nurupo.contributions@gmail.com>2014-10-12 23:21:59 -0400
committerMaxim Biro <nurupo.contributions@gmail.com>2014-10-12 23:22:25 -0400
commit1200e69a3fb1619a19b78bf52e815095dfb705d4 (patch)
tree1e93f70d79a4078e230b46ab38ca4312c6203aef /other/bootstrap_daemon/tox-bootstrapd.c
parent3d239822502cd3a0d8fe5e66d540f23257c60a52 (diff)
Added IPv4 fallback, made IPv6 and IPv4 fallback enabled by default
Diffstat (limited to 'other/bootstrap_daemon/tox-bootstrapd.c')
-rw-r--r--other/bootstrap_daemon/tox-bootstrapd.c42
1 files changed, 36 insertions, 6 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
235int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6, 236int 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");