diff options
-rw-r--r-- | other/bootstrap_daemon/conf | 8 | ||||
-rw-r--r-- | other/bootstrap_daemon/tox_bootstrap_daemon.c | 62 | ||||
-rw-r--r-- | other/bootstrap_daemon/tox_bootstrap_daemon.sh | 2 |
3 files changed, 50 insertions, 22 deletions
diff --git a/other/bootstrap_daemon/conf b/other/bootstrap_daemon/conf index bbdf7652..c05beff1 100644 --- a/other/bootstrap_daemon/conf +++ b/other/bootstrap_daemon/conf | |||
@@ -6,13 +6,13 @@ port = 33445 | |||
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 | // The daemon should have permission to read/write to it. | 7 | // The daemon should have permission to read/write to it. |
8 | // Remember to replace the provided example with your own path. | 8 | // Remember to replace the provided example with your own path. |
9 | keys_file_path = "/home/tom/.tox_bootstrap_daemon/keys" | 9 | keys_file_path = "/home/tom/.tox_bootstrap_daemon/.tox_bootstrap_daemon.keys" |
10 | 10 | ||
11 | // The PID file written to by daemon. | 11 | // The PID file written to by daemon. |
12 | // Make sure that the user who runs the daemon has permissions to write to the | 12 | // Make sure that the user who runs the daemon has permissions to write to the |
13 | // PID file. | 13 | // PID file. |
14 | // Remember to replace the provided example with your own path. | 14 | // Remember to replace the provided example with your own path. |
15 | pid_file_path = "/home/tom/.tox_bootstrap_daemon/pid" | 15 | pid_file_path = "/home/tom/.tox_bootstrap_daemon/.tox_bootstrap_daemon.pid" |
16 | 16 | ||
17 | // Enable IPv6. | 17 | // Enable IPv6. |
18 | enable_ipv6 = false | 18 | enable_ipv6 = false |
@@ -22,9 +22,9 @@ enable_lan_discovery = true | |||
22 | 22 | ||
23 | enable_tcp_relay = true | 23 | enable_tcp_relay = true |
24 | 24 | ||
25 | // Tox uses 443 and 3389 ports by default, so it's highly recommended to keep | 25 | // Tox uses 443, 3389 and 33445 ports by default, so it's highly recommended to keep |
26 | // them. | 26 | // them. |
27 | tcp_relay_ports = [443, 3389] | 27 | tcp_relay_ports = [443, 3389, 33445] |
28 | 28 | ||
29 | // It's planned to use message of the day as a convenient method of checking | 29 | // It's planned to use message of the day as a convenient method of checking |
30 | // whether a node is up or not, though there are other methods of doing that. | 30 | // whether a node is up or not, though there are other methods of doing that. |
diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index 2c8f7014..ceb4fded 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c | |||
@@ -53,19 +53,21 @@ | |||
53 | 53 | ||
54 | 54 | ||
55 | #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 | 56 | #define DAEMON_VERSION_NUMBER 2014051800UL // 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) |
60 | 60 | ||
61 | #define DEFAULT_PID_FILE_PATH ".tox_bootstrap_daemon.pid" | 61 | #define DEFAULT_PID_FILE_PATH ".tox_bootstrap_daemon.pid" |
62 | #define DEFAULT_KEYS_FILE_PATH ".tox_bootstrap_daemon.keys" | 62 | #define DEFAULT_KEYS_FILE_PATH ".tox_bootstrap_daemon.keys" |
63 | #define DEFAULT_PORT 33445 | 63 | #define DEFAULT_PORT 33445 |
64 | #define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false | 64 | #define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false |
65 | #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 | 66 | #define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false |
67 | #define DEFAULT_ENABLE_MOTD 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_MOTD DAEMON_NAME | 68 | #define DEFAULT_TCP_RELAY_PORTS_COUNT 3 |
69 | #define DEFAULT_ENABLE_MOTD 1 // 1 - true, 0 - false | ||
70 | #define DEFAULT_MOTD DAEMON_NAME | ||
69 | 71 | ||
70 | #define MIN_ALLOWED_PORT 1 | 72 | #define MIN_ALLOWED_PORT 1 |
71 | #define MAX_ALLOWED_PORT 65535 | 73 | #define MAX_ALLOWED_PORT 65535 |
@@ -129,6 +131,33 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int | |||
129 | 131 | ||
130 | if (ports_array == NULL) { | 132 | if (ports_array == NULL) { |
131 | syslog(LOG_WARNING, "No '%s' setting in the configuration file.\n", NAME_TCP_RELAY_PORTS); | 133 | syslog(LOG_WARNING, "No '%s' setting in the configuration file.\n", NAME_TCP_RELAY_PORTS); |
134 | syslog(LOG_WARNING, "Using default '%s':\n", NAME_TCP_RELAY_PORTS); | ||
135 | |||
136 | uint16_t default_ports[DEFAULT_TCP_RELAY_PORTS_COUNT] = {DEFAULT_TCP_RELAY_PORTS}; | ||
137 | |||
138 | int i; | ||
139 | |||
140 | for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) { | ||
141 | syslog(LOG_WARNING, "Port #%d: %u\n", i, default_ports[i]); | ||
142 | } | ||
143 | |||
144 | // similar procedure to the one of reading config file below | ||
145 | *tcp_relay_ports = malloc(DEFAULT_TCP_RELAY_PORTS_COUNT * sizeof(uint16_t)); | ||
146 | |||
147 | for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) { | ||
148 | |||
149 | (*tcp_relay_ports)[*tcp_relay_port_count] = default_ports[i]; | ||
150 | if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT || (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) { | ||
151 | syslog(LOG_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); | ||
152 | continue; | ||
153 | } | ||
154 | |||
155 | (*tcp_relay_port_count) ++; | ||
156 | } | ||
157 | |||
158 | // the loop above skips invalid ports, so we adjust the allocated memory size | ||
159 | *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); | ||
160 | |||
132 | return; | 161 | return; |
133 | } | 162 | } |
134 | 163 | ||
@@ -164,8 +193,8 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int | |||
164 | } | 193 | } |
165 | 194 | ||
166 | (*tcp_relay_ports)[*tcp_relay_port_count] = config_setting_get_int(elem); | 195 | (*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) { | 196 | if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT || (*tcp_relay_ports)[*tcp_relay_port_count] > 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); | 197 | syslog(LOG_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); |
169 | continue; | 198 | continue; |
170 | } | 199 | } |
171 | 200 | ||
@@ -173,7 +202,7 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int | |||
173 | } | 202 | } |
174 | 203 | ||
175 | // the loop above skips invalid ports, so we adjust the allocated memory size | 204 | // 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)); | 205 | *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); |
177 | } | 206 | } |
178 | 207 | ||
179 | // Gets general config options | 208 | // Gets general config options |
@@ -485,8 +514,7 @@ int main(int argc, char *argv[]) | |||
485 | 514 | ||
486 | // Check if the PID file exists | 515 | // Check if the PID file exists |
487 | if (fopen(pid_file_path, "r")) { | 516 | if (fopen(pid_file_path, "r")) { |
488 | syslog(LOG_ERR, "Another instance of the daemon is already running, PID file %s exists. Exiting.\n", pid_file_path); | 517 | syslog(LOG_ERR, "Another instance of the daemon is already running, PID file %s exists.\n", pid_file_path); |
489 | return 1; | ||
490 | } | 518 | } |
491 | 519 | ||
492 | IP ip; | 520 | IP ip; |
@@ -555,10 +583,10 @@ int main(int argc, char *argv[]) | |||
555 | print_public_key(dht->self_public_key); | 583 | print_public_key(dht->self_public_key); |
556 | 584 | ||
557 | // Write the PID file | 585 | // Write the PID file |
558 | FILE *pidf = fopen(pid_file_path, "w"); | 586 | FILE *pidf = fopen(pid_file_path, "a+"); |
559 | 587 | ||
560 | if (pidf == NULL) { | 588 | if (pidf == NULL) { |
561 | syslog(LOG_ERR, "Can't open the PID file for writing: %s. Exiting.\n", pid_file_path); | 589 | syslog(LOG_ERR, "Couldn't open the PID file for writing: %s. Exiting.\n", pid_file_path); |
562 | return 1; | 590 | return 1; |
563 | } | 591 | } |
564 | 592 | ||
@@ -575,7 +603,7 @@ int main(int argc, char *argv[]) | |||
575 | } | 603 | } |
576 | 604 | ||
577 | if (pid > 0) { | 605 | if (pid > 0) { |
578 | fprintf(pidf, "%d\n", pid); | 606 | fprintf(pidf, "%d ", pid); |
579 | fclose(pidf); | 607 | fclose(pidf); |
580 | syslog(LOG_DEBUG, "Forked successfully: PID: %d.\n", pid); | 608 | syslog(LOG_DEBUG, "Forked successfully: PID: %d.\n", pid); |
581 | return 0; | 609 | return 0; |
diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.sh b/other/bootstrap_daemon/tox_bootstrap_daemon.sh index e083ea0b..787498ec 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.sh +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.sh | |||
@@ -18,7 +18,7 @@ USER=tom | |||
18 | CFG=/home/$USER/.$NAME/conf | 18 | CFG=/home/$USER/.$NAME/conf |
19 | DAEMON=/home/$USER/.$NAME/$NAME | 19 | DAEMON=/home/$USER/.$NAME/$NAME |
20 | DAEMON_ARGS="$CFG" | 20 | DAEMON_ARGS="$CFG" |
21 | PIDFILE=/home/$USER/.$NAME/pid | 21 | PIDFILE=/home/$USER/.$NAME/."$NAME".pid |
22 | SCRIPTNAME=/etc/init.d/$NAME | 22 | SCRIPTNAME=/etc/init.d/$NAME |
23 | 23 | ||
24 | # Exit if the package is not installed | 24 | # Exit if the package is not installed |