summaryrefslogtreecommitdiff
path: root/other
diff options
context:
space:
mode:
Diffstat (limited to 'other')
-rw-r--r--other/bootstrap_serverdaemon/conf35
-rw-r--r--other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c61
2 files changed, 37 insertions, 59 deletions
diff --git a/other/bootstrap_serverdaemon/conf b/other/bootstrap_serverdaemon/conf
index 70dbdb14..136db0f5 100644
--- a/other/bootstrap_serverdaemon/conf
+++ b/other/bootstrap_serverdaemon/conf
@@ -1,33 +1,34 @@
1// ProjectTox bootstrap server configuration file 1// ProjectTox dht bootstrap server daemon configuration file.
2 2
3// listening port 3// Listening port.
4port = 33445 4port = 33445
5 5
6// The key file is like a password, so keep it where no one can read it 6// The 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 8// Remember to replace the provided example with your own path.
9// your own path
10keys_file_path = "/home/tom/.tox_dht_bootstrap_server_daemon/keys" 9keys_file_path = "/home/tom/.tox_dht_bootstrap_server_daemon/keys"
11 10
12// The PID file written to by daemon, 11// The PID file written to by daemon.
13// make sure that the user who runs the server 12// Make sure that the user who runs the daemon has permissions to write to the
14// does have permissions to write to it 13// PID file.
15// Remember to replace the provided example with 14// Remember to replace the provided example with your own path.
16// your own path
17pid_file_path = "/home/tom/.tox_dht_bootstrap_server_daemon/pid" 15pid_file_path = "/home/tom/.tox_dht_bootstrap_server_daemon/pid"
18 16
17// Enable IPv6.
19enable_ipv6 = false 18enable_ipv6 = false
20 19
21// Automatically bootstrap with nodes on local network 20// Automatically bootstrap with nodes on local area network.
22enable_lan_discovery = true 21enable_lan_discovery = true
23 22
24// Any number of nodes the daemon will bootstrap itself from 23// Any number of servers the daemon will bootstrap itself from.
25// Remember to replace the provided example with 24// Remember to replace the provided example with your own server list.
26// your own server list 25// You may leave the list empty or remove "bootstrap_servers" complitely,
26// in both cases this will be interpreted as if you don't want to bootstrap
27// from anyone.
27bootstrap_servers = ( 28bootstrap_servers = (
28 { // Server 1 29 { // Server 1
29 // any ipv4 or ipv6, depending if `enable_ipv6` is set or not 30 // Any ipv4 or ipv6, depending if `enable_ipv6` is set or not, and also
30 // also any US-ASCII domain name 31 // any US-ASCII domain name.
31 address = "198.46.136.167" 32 address = "198.46.136.167"
32 port = 33445 33 port = 33445
33 public_key = "728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854" 34 public_key = "728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854"
diff --git a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c b/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c
index 1a68393f..a6cffb54 100644
--- a/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c
+++ b/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c
@@ -186,8 +186,8 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi
186 186
187// Bootstraps servers listed in the config file 187// Bootstraps servers listed in the config file
188// 188//
189// returns 1 on success 189// returns 1 on success, some or no bootstrap servers were added
190// 0 on failure, either no or only some servers were bootstrapped 190// 0 on failure, a error accured while parsing config file
191 191
192int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) 192int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6)
193{ 193{
@@ -210,9 +210,15 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6)
210 config_setting_t *server_list = config_lookup(&cfg, NAME_BOOTSTRAP_SERVERS); 210 config_setting_t *server_list = config_lookup(&cfg, NAME_BOOTSTRAP_SERVERS);
211 211
212 if (server_list == NULL) { 212 if (server_list == NULL) {
213 syslog(LOG_ERR, "No '%s' setting in configuration file.\n", NAME_BOOTSTRAP_SERVERS); 213 syslog(LOG_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n", NAME_BOOTSTRAP_SERVERS);
214 config_destroy(&cfg); 214 config_destroy(&cfg);
215 return 0; 215 return 1;
216 }
217
218 if (config_setting_length(server_list) == 0) {
219 syslog(LOG_WARNING, "No bootstrap servers found. Skipping bootstrapping.\n");
220 config_destroy(&cfg);
221 return 1;
216 } 222 }
217 223
218 int bs_port; 224 int bs_port;
@@ -232,7 +238,7 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6)
232 return 0; 238 return 0;
233 } 239 }
234 240
235 // Proceed only if all parts are present 241 // Check that all settings are present
236 if (config_setting_lookup_string(server, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE) { 242 if (config_setting_lookup_string(server, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE) {
237 syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PUBLIC_KEY); 243 syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PUBLIC_KEY);
238 goto next; 244 goto next;
@@ -248,6 +254,7 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6)
248 goto next; 254 goto next;
249 } 255 }
250 256
257 // Process settings
251 if (strlen(bs_public_key) != 64) { 258 if (strlen(bs_public_key) != 64) {
252 syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_PUBLIC_KEY, bs_public_key); 259 syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_PUBLIC_KEY, bs_public_key);
253 goto next; 260 goto next;
@@ -282,36 +289,6 @@ next:
282 return 1; 289 return 1;
283} 290}
284 291
285// Checks if we are connected to the DHT
286//
287// returns 1 on success
288// 0 on failure
289
290int try_connect(DHT *dht, int port, int enable_lan_discovery)
291{
292 uint16_t htons_port = htons(port);
293
294 int i;
295
296 for (i = 0; i < 100; i ++) {
297 do_DHT(dht);
298
299 if (enable_lan_discovery) {
300 send_LANdiscovery(htons_port, dht);
301 }
302
303 networking_poll(dht->c->lossless_udp->net);
304
305 if (DHT_isconnected(dht)) {
306 return 1;
307 }
308
309 sleep;
310 }
311
312 return 0;
313}
314
315// Prints public key 292// Prints public key
316 293
317void print_public_key(uint8_t *public_key) 294void print_public_key(uint8_t *public_key)
@@ -404,13 +381,6 @@ int main(int argc, char *argv[])
404 return 1; 381 return 1;
405 } 382 }
406 383
407 if (try_connect(dht, port, enable_lan_discovery)) {
408 syslog(LOG_INFO, "Successfully connected to DHT\n");
409 } else {
410 syslog(LOG_ERR, "Couldn't connect to the DHT. Check settings and network connections. Exiting.\n");
411 return 1;
412 }
413
414 print_public_key(dht->c->self_public_key); 384 print_public_key(dht->c->self_public_key);
415 385
416 // Write the PID file 386 // Write the PID file
@@ -463,6 +433,8 @@ int main(int argc, char *argv[])
463 uint64_t last_LANdiscovery = 0; 433 uint64_t last_LANdiscovery = 0;
464 uint16_t htons_port = htons(port); 434 uint16_t htons_port = htons(port);
465 435
436 int waiting_for_dht_connection = 1;
437
466 while (1) { 438 while (1) {
467 do_DHT(dht); 439 do_DHT(dht);
468 440
@@ -473,6 +445,11 @@ int main(int argc, char *argv[])
473 445
474 networking_poll(dht->net); 446 networking_poll(dht->net);
475 447
448 if (waiting_for_dht_connection && DHT_isconnected(dht)) {
449 syslog(LOG_DEBUG, "Connected to other bootstrap server successfully.\n");
450 waiting_for_dht_connection = 0;
451 }
452
476 sleep; 453 sleep;
477 } 454 }
478 455