mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge pull request #703 from nurupo/dht_bootstrap_daemon
Improved DHT bootstrap daemon
This commit is contained in:
commit
7df9c0eb4b
@ -1,17 +1,17 @@
|
||||
if BUILD_DHT_BOOTSTRAP_DAEMON
|
||||
|
||||
noinst_PROGRAMS += tox_dht_bootstrap_server_daemon
|
||||
noinst_PROGRAMS += tox_bootstrap_daemon
|
||||
|
||||
tox_dht_bootstrap_server_daemon_SOURCES = \
|
||||
../other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.c
|
||||
tox_bootstrap_daemon_SOURCES = \
|
||||
../other/bootstrap_serverdaemon/tox_bootstrap_daemon.c
|
||||
|
||||
tox_dht_bootstrap_server_daemon_CFLAGS = \
|
||||
tox_bootstrap_daemon_CFLAGS = \
|
||||
-I$(top_srcdir)/other/bootstrap_serverdaemon \
|
||||
$(LIBSODIUM_CFLAGS) \
|
||||
$(NACL_CFLAGS) \
|
||||
$(LIBCONFIG_CFLAGS)
|
||||
|
||||
tox_dht_bootstrap_server_daemon_LDADD = \
|
||||
tox_bootstrap_daemon_LDADD = \
|
||||
$(LIBSODIUM_LDFLAGS) \
|
||||
$(NACL_LDFLAGS) \
|
||||
libtoxcore.la \
|
||||
@ -23,5 +23,5 @@ endif
|
||||
|
||||
EXTRA_DIST += \
|
||||
$(top_srcdir)/other/bootstrap_serverdaemon/conf \
|
||||
$(top_srcdir)/other/bootstrap_serverdaemon/tox_dht_bootstrap_server_daemon.sh
|
||||
$(top_srcdir)/other/bootstrap_serverdaemon/tox_bootstrap_daemon.sh
|
||||
|
@ -2,44 +2,44 @@
|
||||
|
||||
The following commands are to be executed as root:
|
||||
|
||||
1. In `tox_dht_bootstrap_server_daemon.sh` file change:
|
||||
1. In `tox_bootstrap_daemon.sh` file change:
|
||||
- `CFG` to where your config file (`conf`) will be; read rights required
|
||||
- `DAEMON` to point to the executable
|
||||
- `PIDFILE` to point to a pid file daemon would have rights to create
|
||||
|
||||
2. Go over everything in `conf`. Make sure `pid_file_path` matches `PIDFILE` from `tox_dht_bootstrap_server_daemon.sh`
|
||||
2. Go over everything in `conf`. Make sure `pid_file_path` matches `PIDFILE` from `tox_bootstrap_daemon.sh`
|
||||
|
||||
3. Execute:
|
||||
```
|
||||
mv tox_dht_bootstrap_server_daemon.sh /etc/init.d/tox_dht_bootstrap_server_daemon
|
||||
mv tox_bootstrap_daemon.sh /etc/init.d/tox_bootstrap_daemon
|
||||
```
|
||||
*(note that we removed `.sh` ending)*
|
||||
|
||||
4. Give the right permissions to this file:
|
||||
```
|
||||
chmod 755 /etc/init.d/tox_dht_bootstrap_server_daemon
|
||||
chmod 755 /etc/init.d/tox_bootstrap_daemon
|
||||
```
|
||||
|
||||
5. Execute:
|
||||
```
|
||||
update-rc.d tox_dht_bootstrap_server_daemon defaults
|
||||
update-rc.d tox_bootstrap_daemon defaults
|
||||
```
|
||||
|
||||
6. Start the service:
|
||||
```
|
||||
service tox_dht_bootstrap_server_daemon start
|
||||
service tox_bootstrap_daemon start
|
||||
```
|
||||
|
||||
7. Verify that the service is running:
|
||||
```
|
||||
service tox_dht_bootstrap_server_daemon status
|
||||
service tox_bootstrap_daemon status
|
||||
```
|
||||
|
||||
--
|
||||
|
||||
You can see daemon's log with
|
||||
```
|
||||
grep "tox_dht_bootstrap_server_daemon" /var/log/syslog
|
||||
grep "tox_bootstrap_daemon" /var/log/syslog
|
||||
```
|
||||
|
||||
**Note that system log is where you find your public key**
|
||||
@ -50,12 +50,12 @@ grep "tox_dht_bootstrap_server_daemon" /var/log/syslog
|
||||
|
||||
1. Check the log for errors with
|
||||
```
|
||||
grep "tox_dht_bootstrap_server_daemon" /var/log/syslog
|
||||
grep "tox_bootstrap_daemon" /var/log/syslog
|
||||
```
|
||||
|
||||
2. Check that paths in the beginning of `/etc/init.d/tox_dht_bootstrap_server_daemon` are valid
|
||||
2. Check that paths in the beginning of `/etc/init.d/tox_bootstrap_daemon` are valid
|
||||
|
||||
3. Make sure that `PIDFILE` from `/etc/init.d/tox_dht_bootstrap_server_daemon` matches with the `pid_file_path` from `conf`
|
||||
3. Make sure that `PIDFILE` from `/etc/init.d/tox_bootstrap_daemon` matches with the `pid_file_path` from `conf`
|
||||
|
||||
4. Make sure you have write permission to keys and pid files
|
||||
|
||||
|
@ -1,33 +1,34 @@
|
||||
// ProjectTox bootstrap server configuration file
|
||||
// ProjectTox dht bootstrap server daemon configuration file.
|
||||
|
||||
// listening port
|
||||
// Listening port.
|
||||
port = 33445
|
||||
|
||||
// The key file is like a password, so keep it where no one can read it
|
||||
// The daemon should have permission to read/write to it
|
||||
// Remember to replace the provided example with
|
||||
// your own path
|
||||
keys_file_path = "/home/tom/.tox_dht_bootstrap_server_daemon/keys"
|
||||
// The key file is like a password, so keep it where no one can read it.
|
||||
// The daemon should have permission to read/write to it.
|
||||
// Remember to replace the provided example with your own path.
|
||||
keys_file_path = "/home/tom/.tox_bootstrap_daemon/keys"
|
||||
|
||||
// The PID file written to by daemon,
|
||||
// make sure that the user who runs the server
|
||||
// does have permissions to write to it
|
||||
// Remember to replace the provided example with
|
||||
// your own path
|
||||
pid_file_path = "/home/tom/.tox_dht_bootstrap_server_daemon/pid"
|
||||
// The PID file written to by daemon.
|
||||
// Make sure that the user who runs the daemon has permissions to write to the
|
||||
// PID file.
|
||||
// Remember to replace the provided example with your own path.
|
||||
pid_file_path = "/home/tom/.tox_bootstrap_daemon/pid"
|
||||
|
||||
// Enable IPv6.
|
||||
enable_ipv6 = false
|
||||
|
||||
// Automatically bootstrap with nodes on local network
|
||||
// Automatically bootstrap with nodes on local area network.
|
||||
enable_lan_discovery = true
|
||||
|
||||
// Any number of nodes the daemon will bootstrap itself from
|
||||
// Remember to replace the provided example with
|
||||
// your own server list
|
||||
// Any number of servers the daemon will bootstrap itself from.
|
||||
// Remember to replace the provided example with your own server list.
|
||||
// You may leave the list empty or remove "bootstrap_servers" complitely,
|
||||
// in both cases this will be interpreted as if you don't want to bootstrap
|
||||
// from anyone.
|
||||
bootstrap_servers = (
|
||||
{ // Server 1
|
||||
// any ipv4 or ipv6, depending if `enable_ipv6` is set or not
|
||||
// also any US-ASCII domain name
|
||||
// Any ipv4 or ipv6, depending if `enable_ipv6` is set or not, and also
|
||||
// any US-ASCII domain name.
|
||||
address = "198.46.136.167"
|
||||
port = 33445
|
||||
public_key = "728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854"
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* tox_dht_bootstrap_server_daemon
|
||||
/* tox_bootstrap_daemon.c
|
||||
*
|
||||
* A simple DHT bootstrap server for tox - daemon edition.
|
||||
* Tox DHT bootstrap server daemon.
|
||||
*
|
||||
* Copyright (C) 2014 Tox project All Rights Reserved.
|
||||
*
|
||||
@ -42,13 +42,13 @@
|
||||
|
||||
#include "../../testing/misc_tools.c"
|
||||
|
||||
#define DAEMON_NAME "tox_dht_bootstrap_server_daemon"
|
||||
#define DAEMON_NAME "tox_bootstrap_daemon"
|
||||
|
||||
#define SLEEP_TIME_MILLISECONDS 30
|
||||
#define sleep usleep(1000*SLEEP_TIME_MILLISECONDS)
|
||||
|
||||
#define DEFAULT_PID_FILE_PATH ".tox_dht_bootstrap_server_daemon.pid"
|
||||
#define DEFAULT_KEYS_FILE_PATH ".tox_dht_bootstrap_server_daemon.keys"
|
||||
#define DEFAULT_PID_FILE_PATH ".tox_bootstrap_daemon.pid"
|
||||
#define DEFAULT_KEYS_FILE_PATH ".tox_bootstrap_daemon.keys"
|
||||
#define DEFAULT_PORT 33445
|
||||
#define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false
|
||||
#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false
|
||||
@ -186,8 +186,8 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi
|
||||
|
||||
// Bootstraps servers listed in the config file
|
||||
//
|
||||
// returns 1 on success
|
||||
// 0 on failure, either no or only some servers were bootstrapped
|
||||
// returns 1 on success, some or no bootstrap servers were added
|
||||
// 0 on failure, a error accured while parsing config file
|
||||
|
||||
int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6)
|
||||
{
|
||||
@ -210,9 +210,15 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6)
|
||||
config_setting_t *server_list = config_lookup(&cfg, NAME_BOOTSTRAP_SERVERS);
|
||||
|
||||
if (server_list == NULL) {
|
||||
syslog(LOG_ERR, "No '%s' setting in configuration file.\n", NAME_BOOTSTRAP_SERVERS);
|
||||
syslog(LOG_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n", NAME_BOOTSTRAP_SERVERS);
|
||||
config_destroy(&cfg);
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (config_setting_length(server_list) == 0) {
|
||||
syslog(LOG_WARNING, "No bootstrap servers found. Skipping bootstrapping.\n");
|
||||
config_destroy(&cfg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int bs_port;
|
||||
@ -232,21 +238,31 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Proceed only if all parts are present
|
||||
if (config_setting_lookup_string(server, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE ||
|
||||
config_setting_lookup_int (server, NAME_PORT, &bs_port) == CONFIG_FALSE ||
|
||||
config_setting_lookup_string(server, NAME_ADDRESS, &bs_address) == CONFIG_FALSE ) {
|
||||
// Check that all settings are present
|
||||
if (config_setting_lookup_string(server, NAME_PUBLIC_KEY, &bs_public_key) == CONFIG_FALSE) {
|
||||
syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PUBLIC_KEY);
|
||||
goto next;
|
||||
}
|
||||
|
||||
if (config_setting_lookup_int(server, NAME_PORT, &bs_port) == CONFIG_FALSE) {
|
||||
syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_PORT);
|
||||
goto next;
|
||||
}
|
||||
|
||||
if (config_setting_lookup_string(server, NAME_ADDRESS, &bs_address) == CONFIG_FALSE) {
|
||||
syslog(LOG_WARNING, "Bootstrap server #%d: Couldn't find '%s' setting. Skipping the server.\n", i, NAME_ADDRESS);
|
||||
goto next;
|
||||
}
|
||||
|
||||
// Process settings
|
||||
if (strlen(bs_public_key) != 64) {
|
||||
syslog(LOG_WARNING, "bootstrap_server #%d: Invalid '%s': %s.\n", i, NAME_PUBLIC_KEY, bs_public_key);
|
||||
syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_PUBLIC_KEY, bs_public_key);
|
||||
goto next;
|
||||
}
|
||||
|
||||
// not (1 <= port <= 65535)
|
||||
if (bs_port < 1 || bs_port > 65535) {
|
||||
syslog(LOG_WARNING, "bootstrap_server #%d: Invalid '%s': %d.\n", i, NAME_PORT, bs_port);
|
||||
syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %d. Skipping the server.\n", i, NAME_PORT, bs_port);
|
||||
goto next;
|
||||
}
|
||||
|
||||
@ -254,11 +270,11 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6)
|
||||
hex_string_to_bin((char *)bs_public_key));
|
||||
|
||||
if (!address_resolved) {
|
||||
syslog(LOG_WARNING, "bootstrap_server #%d: Invalid '%s': %s.\n", i, NAME_ADDRESS, bs_address);
|
||||
syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_ADDRESS, bs_address);
|
||||
goto next;
|
||||
}
|
||||
|
||||
syslog(LOG_DEBUG, "Successfully connected to %s:%d %s\n", bs_address, bs_port, bs_public_key);
|
||||
syslog(LOG_DEBUG, "Successfully added bootstrap server #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key);
|
||||
|
||||
next:
|
||||
// config_setting_lookup_string() allocates string inside and doesn't allow us to free it
|
||||
@ -273,36 +289,6 @@ next:
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Checks if we are connected to the DHT
|
||||
//
|
||||
// returns 1 on success
|
||||
// 0 on failure
|
||||
|
||||
int try_connect(DHT *dht, int port, int enable_lan_discovery)
|
||||
{
|
||||
uint16_t htons_port = htons(port);
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 100; i ++) {
|
||||
do_DHT(dht);
|
||||
|
||||
if (enable_lan_discovery) {
|
||||
send_LANdiscovery(htons_port, dht);
|
||||
}
|
||||
|
||||
networking_poll(dht->c->lossless_udp->net);
|
||||
|
||||
if (DHT_isconnected(dht)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
sleep;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Prints public key
|
||||
|
||||
void print_public_key(uint8_t *public_key)
|
||||
@ -330,7 +316,7 @@ int main(int argc, char *argv[])
|
||||
openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON);
|
||||
|
||||
if (argc < 2) {
|
||||
syslog(LOG_ERR, "Please specify a configuration file. Exiting.\n");
|
||||
syslog(LOG_ERR, "Please specify a path to a configuration file as the first argument. Exiting.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -395,13 +381,6 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (try_connect(dht, port, enable_lan_discovery)) {
|
||||
syslog(LOG_INFO, "Successfully connected to DHT\n");
|
||||
} else {
|
||||
syslog(LOG_ERR, "Couldn't connect to the DHT. Check settings and network connections. Exiting.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
print_public_key(dht->c->self_public_key);
|
||||
|
||||
// Write the PID file
|
||||
@ -454,6 +433,8 @@ int main(int argc, char *argv[])
|
||||
uint64_t last_LANdiscovery = 0;
|
||||
uint16_t htons_port = htons(port);
|
||||
|
||||
int waiting_for_dht_connection = 1;
|
||||
|
||||
while (1) {
|
||||
do_DHT(dht);
|
||||
|
||||
@ -464,6 +445,11 @@ int main(int argc, char *argv[])
|
||||
|
||||
networking_poll(dht->net);
|
||||
|
||||
if (waiting_for_dht_connection && DHT_isconnected(dht)) {
|
||||
syslog(LOG_DEBUG, "Connected to other bootstrap server successfully.\n");
|
||||
waiting_for_dht_connection = 0;
|
||||
}
|
||||
|
||||
sleep;
|
||||
}
|
||||
|
@ -1,18 +1,19 @@
|
||||
#! /bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: tox_dht_bootstrap_server_daemon
|
||||
# Provides: tox_bootstrap_daemon
|
||||
# Required-Start: $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Starts the Tox bootstrapping server
|
||||
# Description: Starts the Tox bootstrapping server
|
||||
# Short-Description: Starts the Tox DHT bootstrapping server daemon
|
||||
# Description: Starts the Tox DHT bootstrapping server daemon
|
||||
### END INIT INFO
|
||||
|
||||
# PATH should only include /usr/* if it runs after the mountnfs.sh script
|
||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
||||
DESC="ProjectTox bootstrap server daemon"
|
||||
NAME=tox_dht_bootstrap_server_daemon
|
||||
DESC="Tox DHT bootstrap server daemon"
|
||||
NAME=tox_bootstrap_daemon
|
||||
# You may want to change USER if you are using it anywhere else
|
||||
USER=tom
|
||||
CFG=/home/$USER/.$NAME/conf
|
||||
DAEMON=/home/$USER/$NAME
|
Loading…
x
Reference in New Issue
Block a user