mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Added IPv4 fallback, made IPv6 and IPv4 fallback enabled by default
This commit is contained in:
parent
3d23982250
commit
1200e69a3f
|
@ -53,7 +53,7 @@
|
||||||
|
|
||||||
|
|
||||||
#define DAEMON_NAME "tox-bootstrapd"
|
#define DAEMON_NAME "tox-bootstrapd"
|
||||||
#define DAEMON_VERSION_NUMBER 2014101000UL // yyyymmmddvv format: yyyy year, mm month, dd day, vv version change count for that day
|
#define DAEMON_VERSION_NUMBER 2014101200UL // yyyymmmddvv format: yyyy year, mm month, dd day, vv version change count for that day
|
||||||
|
|
||||||
#define SLEEP_TIME_MILLISECONDS 30
|
#define SLEEP_TIME_MILLISECONDS 30
|
||||||
#define sleep usleep(1000*SLEEP_TIME_MILLISECONDS)
|
#define sleep usleep(1000*SLEEP_TIME_MILLISECONDS)
|
||||||
|
@ -62,6 +62,7 @@
|
||||||
#define DEFAULT_KEYS_FILE_PATH "tox-bootstrapd.keys"
|
#define DEFAULT_KEYS_FILE_PATH "tox-bootstrapd.keys"
|
||||||
#define DEFAULT_PORT 33445
|
#define DEFAULT_PORT 33445
|
||||||
#define DEFAULT_ENABLE_IPV6 1 // 1 - true, 0 - false
|
#define DEFAULT_ENABLE_IPV6 1 // 1 - true, 0 - false
|
||||||
|
#define DEFAULT_ENABLE_IPV4_FALLBACK 1 // 1 - true, 0 - false
|
||||||
#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false
|
#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false
|
||||||
#define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false
|
#define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false
|
||||||
#define DEFAULT_TCP_RELAY_PORTS 443, 3389, 33445 // comma-separated list of ports. make sure to adjust DEFAULT_TCP_RELAY_PORTS_COUNT accordingly
|
#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
|
||||||
// 0 on failure, doesn't modify any data pointed by arguments
|
// 0 on failure, doesn't modify any data pointed by arguments
|
||||||
|
|
||||||
int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6,
|
int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6,
|
||||||
int *enable_lan_discovery, int *enable_tcp_relay, uint16_t **tcp_relay_ports, int *tcp_relay_port_count,
|
int *enable_ipv4_fallback, int *enable_lan_discovery, int *enable_tcp_relay, uint16_t **tcp_relay_ports,
|
||||||
int *enable_motd, char **motd)
|
int *tcp_relay_port_count, int *enable_motd, char **motd)
|
||||||
{
|
{
|
||||||
config_t cfg;
|
config_t cfg;
|
||||||
|
|
||||||
|
@ -242,6 +243,7 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi
|
||||||
const char *NAME_PID_FILE_PATH = "pid_file_path";
|
const char *NAME_PID_FILE_PATH = "pid_file_path";
|
||||||
const char *NAME_KEYS_FILE_PATH = "keys_file_path";
|
const char *NAME_KEYS_FILE_PATH = "keys_file_path";
|
||||||
const char *NAME_ENABLE_IPV6 = "enable_ipv6";
|
const char *NAME_ENABLE_IPV6 = "enable_ipv6";
|
||||||
|
const char *NAME_ENABLE_IPV4_FALLBACK = "enable_ipv4_fallback";
|
||||||
const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery";
|
const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery";
|
||||||
const char *NAME_ENABLE_TCP_RELAY = "enable_tcp_relay";
|
const char *NAME_ENABLE_TCP_RELAY = "enable_tcp_relay";
|
||||||
const char *NAME_ENABLE_MOTD = "enable_motd";
|
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
|
||||||
*enable_ipv6 = DEFAULT_ENABLE_IPV6;
|
*enable_ipv6 = DEFAULT_ENABLE_IPV6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get IPv4 fallback option
|
||||||
|
if (config_lookup_bool(&cfg, NAME_ENABLE_IPV4_FALLBACK, enable_ipv4_fallback) == CONFIG_FALSE) {
|
||||||
|
syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_IPV4_FALLBACK);
|
||||||
|
syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, DEFAULT_ENABLE_IPV4_FALLBACK ? "true" : "false");
|
||||||
|
*enable_ipv4_fallback = DEFAULT_ENABLE_IPV4_FALLBACK;
|
||||||
|
}
|
||||||
|
|
||||||
// Get LAN discovery option
|
// Get LAN discovery option
|
||||||
if (config_lookup_bool(&cfg, NAME_ENABLE_LAN_DISCOVERY, enable_lan_discovery) == CONFIG_FALSE) {
|
if (config_lookup_bool(&cfg, NAME_ENABLE_LAN_DISCOVERY, enable_lan_discovery) == CONFIG_FALSE) {
|
||||||
syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_LAN_DISCOVERY);
|
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
|
||||||
syslog(LOG_DEBUG, "'%s': %s\n", NAME_KEYS_FILE_PATH, *keys_file_path);
|
syslog(LOG_DEBUG, "'%s': %s\n", NAME_KEYS_FILE_PATH, *keys_file_path);
|
||||||
syslog(LOG_DEBUG, "'%s': %d\n", NAME_PORT, *port);
|
syslog(LOG_DEBUG, "'%s': %d\n", NAME_PORT, *port);
|
||||||
syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false");
|
syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false");
|
||||||
|
syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV4_FALLBACK, *enable_ipv4_fallback ? "true" : "false");
|
||||||
syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false");
|
syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false");
|
||||||
|
|
||||||
syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false");
|
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[])
|
||||||
char *pid_file_path, *keys_file_path;
|
char *pid_file_path, *keys_file_path;
|
||||||
int port;
|
int port;
|
||||||
int enable_ipv6;
|
int enable_ipv6;
|
||||||
|
int enable_ipv4_fallback;
|
||||||
int enable_lan_discovery;
|
int enable_lan_discovery;
|
||||||
int enable_tcp_relay;
|
int enable_tcp_relay;
|
||||||
uint16_t *tcp_relay_ports;
|
uint16_t *tcp_relay_ports;
|
||||||
|
@ -523,8 +534,8 @@ int main(int argc, char *argv[])
|
||||||
int enable_motd;
|
int enable_motd;
|
||||||
char *motd;
|
char *motd;
|
||||||
|
|
||||||
if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_lan_discovery,
|
if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_ipv4_fallback,
|
||||||
&enable_tcp_relay, &tcp_relay_ports, &tcp_relay_port_count, &enable_motd, &motd)) {
|
&enable_lan_discovery, &enable_tcp_relay, &tcp_relay_ports, &tcp_relay_port_count, &enable_motd, &motd)) {
|
||||||
syslog(LOG_DEBUG, "General config read successfully\n");
|
syslog(LOG_DEBUG, "General config read successfully\n");
|
||||||
} else {
|
} else {
|
||||||
syslog(LOG_ERR, "Couldn't read config file: %s. Exiting.\n", cfg_file_path);
|
syslog(LOG_ERR, "Couldn't read config file: %s. Exiting.\n", cfg_file_path);
|
||||||
|
@ -547,7 +558,26 @@ int main(int argc, char *argv[])
|
||||||
IP ip;
|
IP ip;
|
||||||
ip_init(&ip, enable_ipv6);
|
ip_init(&ip, enable_ipv6);
|
||||||
|
|
||||||
DHT *dht = new_DHT(new_networking(ip, port));
|
Networking_Core *net = new_networking(ip, port);
|
||||||
|
|
||||||
|
if (net == NULL) {
|
||||||
|
if (enable_ipv6 && enable_ipv4_fallback) {
|
||||||
|
syslog(LOG_DEBUG, "Couldn't initialize IPv6 networking. Falling back to using IPv4.\n");
|
||||||
|
enable_ipv6 = 0;
|
||||||
|
ip_init(&ip, enable_ipv6);
|
||||||
|
net = new_networking(ip, port);
|
||||||
|
if (net == NULL) {
|
||||||
|
syslog(LOG_DEBUG, "Couldn't fallback to IPv4. Exiting.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
syslog(LOG_DEBUG, "Couldn't initialize networking. Exiting.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DHT *dht = new_DHT(net);
|
||||||
|
|
||||||
if (dht == NULL) {
|
if (dht == NULL) {
|
||||||
syslog(LOG_ERR, "Couldn't initialize Tox DHT instance. Exiting.\n");
|
syslog(LOG_ERR, "Couldn't initialize Tox DHT instance. Exiting.\n");
|
||||||
|
|
|
@ -1,46 +1,51 @@
|
||||||
// Tox DHT bootstrap daemon configuration file.
|
// Tox DHT bootstrap daemon configuration file.
|
||||||
|
|
||||||
// Listening port.
|
// Listening port (UDP).
|
||||||
port = 33445
|
port = 33445
|
||||||
|
|
||||||
// A key file is like a password, so keep it where no one can read it.
|
// A key file is like a password, so keep it where no one can read it.
|
||||||
// If there is no key file, a new one will be generated.
|
// If there is no key file, a new one will be generated.
|
||||||
// The daemon should have permission to read/write to it.
|
// The daemon should have permission to read/write it.
|
||||||
keys_file_path = "/var/lib/tox-bootstrapd/keys"
|
keys_file_path = "/var/lib/tox-bootstrapd/keys"
|
||||||
|
|
||||||
// The PID file written to by daemon.
|
// The PID file written to by the daemon.
|
||||||
// Make sure that the user who runs the daemon has permissions to write to the
|
// Make sure that the user that daemon runs as has permissions to write to the
|
||||||
// PID file.
|
// PID file.
|
||||||
pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"
|
pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"
|
||||||
|
|
||||||
// Enable IPv6.
|
// Enable IPv6.
|
||||||
enable_ipv6 = false
|
enable_ipv6 = true
|
||||||
|
|
||||||
|
// Fallback to IPv4 in case IPv6 fails.
|
||||||
|
enable_ipv4_fallback = true
|
||||||
|
|
||||||
// Automatically bootstrap with nodes on local area network.
|
// Automatically bootstrap with nodes on local area network.
|
||||||
enable_lan_discovery = true
|
enable_lan_discovery = true
|
||||||
|
|
||||||
enable_tcp_relay = true
|
enable_tcp_relay = true
|
||||||
|
|
||||||
// Tox uses 443, 3389 and 33445 ports by default, so it's highly recommended to keep
|
// Tox uses 443, 3389 and 33445 ports by default, so it's highly encouraged to keep
|
||||||
// them.
|
// them.
|
||||||
tcp_relay_ports = [443, 3389, 33445]
|
tcp_relay_ports = [443, 3389, 33445]
|
||||||
|
|
||||||
// It's planned to use message of the day as a convenient method of checking
|
// Reply to MOTD (Message Of The Day) requests.
|
||||||
// whether a node is up or not, though there are other methods of doing that.
|
|
||||||
enable_motd = true
|
enable_motd = true
|
||||||
|
|
||||||
|
// Just a message that is sent when someone requests MOTD.
|
||||||
|
// Put anything you want, but note that it will be trimmed to fit into 255 bytes.
|
||||||
motd = "tox-bootstrapd"
|
motd = "tox-bootstrapd"
|
||||||
|
|
||||||
// Any number of nodes the daemon will bootstrap itself off.
|
// Any number of nodes the daemon will bootstrap itself off.
|
||||||
|
//
|
||||||
// Remember to replace the provided example with your own node list.
|
// Remember to replace the provided example with your own node list.
|
||||||
// There is a maintained list of bootstrap nodes on Tox's wiki, if you need it
|
// There is a maintained list of bootstrap nodes on Tox's wiki, if you need it
|
||||||
// (http://wiki.tox.im/Nodes).
|
// (http://wiki.tox.im/Nodes).
|
||||||
|
//
|
||||||
// You may leave the list empty or remove "bootstrap_nodes" completely,
|
// You may leave the list empty or remove "bootstrap_nodes" completely,
|
||||||
// in both cases this will be interpreted as if you don't want to bootstrap
|
// in both cases this will be interpreted as if you don't want to bootstrap
|
||||||
// from anyone.
|
// from anyone.
|
||||||
// address = any ipv4 or Any ipv4 or ipv6, depending on whether `enable_ipv6`
|
//
|
||||||
// is set or not, and also any US-ASCII domain name.
|
// address = any ipv4 or ipv6 address and also any US-ASCII domain name.
|
||||||
|
|
||||||
bootstrap_nodes = (
|
bootstrap_nodes = (
|
||||||
{
|
{
|
||||||
// NikolaiToryzin - US
|
// NikolaiToryzin - US
|
||||||
|
|
Loading…
Reference in New Issue
Block a user