Squashed 'external/toxcore/c-toxcore/' changes from 67badf694..82460b212
82460b212 feat: add ngc events 24b54722a fix: Ensure we have allocators available for the error paths. 48dbcfebc cleanup: Remove redundant `-DSODIUM_EXPORT` from definitions. 0cef46ee9 cleanup: Fix a few more clang-tidy warnings. 0c5b918e9 cleanup: Fix a few more clang-tidy warnings. 4d3c97f49 cleanup: Enforce stricter identifier naming using clang-tidy. a549807df refactor: Add `mem` module to allow tests to override allocators. 6133fb153 chore: Add devcontainer setup for codespaces. 620e07ecd chore: Set a timeout for tests started using Conan c0ec33b16 chore: Migrate Windows CI from Appveyor to Azure DevOps 8ed47f3ef fix incorrect documentation a1e245841 docs: Fix doxygen config and remove some redundant comments. b0f633185 chore: Fix the Android CI job 7469a529b fix: Add missing `#include <array>`. 2b1a6b0d2 add missing ngc constants getter declarations and definitions 2e02d5637 chore: Add missing module dependencies. REVERT: 67badf694 feat: add ngc events git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: 82460b2124216af1ac9d63060de310a682a2fd15
This commit is contained in:
@ -29,7 +29,7 @@
|
||||
*/
|
||||
static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int *tcp_relay_port_count)
|
||||
{
|
||||
const char *NAME_TCP_RELAY_PORTS = "tcp_relay_ports";
|
||||
const char *const NAME_TCP_RELAY_PORTS = "tcp_relay_ports";
|
||||
|
||||
*tcp_relay_port_count = 0;
|
||||
|
||||
@ -129,15 +129,15 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
|
||||
{
|
||||
config_t cfg;
|
||||
|
||||
const char *NAME_PORT = "port";
|
||||
const char *NAME_PID_FILE_PATH = "pid_file_path";
|
||||
const char *NAME_KEYS_FILE_PATH = "keys_file_path";
|
||||
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_TCP_RELAY = "enable_tcp_relay";
|
||||
const char *NAME_ENABLE_MOTD = "enable_motd";
|
||||
const char *NAME_MOTD = "motd";
|
||||
const char *const NAME_PORT = "port";
|
||||
const char *const NAME_PID_FILE_PATH = "pid_file_path";
|
||||
const char *const NAME_KEYS_FILE_PATH = "keys_file_path";
|
||||
const char *const NAME_ENABLE_IPV6 = "enable_ipv6";
|
||||
const char *const NAME_ENABLE_IPV4_FALLBACK = "enable_ipv4_fallback";
|
||||
const char *const NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery";
|
||||
const char *const NAME_ENABLE_TCP_RELAY = "enable_tcp_relay";
|
||||
const char *const NAME_ENABLE_MOTD = "enable_motd";
|
||||
const char *const NAME_MOTD = "motd";
|
||||
|
||||
config_init(&cfg);
|
||||
|
||||
@ -307,11 +307,11 @@ static uint8_t *bootstrap_hex_string_to_bin(const char *hex_string)
|
||||
|
||||
int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
|
||||
{
|
||||
const char *NAME_BOOTSTRAP_NODES = "bootstrap_nodes";
|
||||
const char *const NAME_BOOTSTRAP_NODES = "bootstrap_nodes";
|
||||
|
||||
const char *NAME_PUBLIC_KEY = "public_key";
|
||||
const char *NAME_PORT = "port";
|
||||
const char *NAME_ADDRESS = "address";
|
||||
const char *const NAME_PUBLIC_KEY = "public_key";
|
||||
const char *const NAME_PORT = "port";
|
||||
const char *const NAME_ADDRESS = "address";
|
||||
|
||||
config_t cfg;
|
||||
|
||||
|
@ -61,10 +61,9 @@ static int manage_keys(DHT *dht, char *keys_file_path)
|
||||
{
|
||||
enum { KEYS_SIZE = CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE };
|
||||
uint8_t keys[KEYS_SIZE];
|
||||
FILE *keys_file;
|
||||
|
||||
// Check if file exits, proceed to open and load keys
|
||||
keys_file = fopen(keys_file_path, "rb");
|
||||
FILE *keys_file = fopen(keys_file_path, "rb");
|
||||
|
||||
if (keys_file != nullptr) {
|
||||
const size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file);
|
||||
@ -120,9 +119,9 @@ static void print_public_key(const uint8_t *public_key)
|
||||
static void daemonize(LOG_BACKEND log_backend, char *pid_file_path)
|
||||
{
|
||||
// Check if the PID file exists
|
||||
FILE *pid_file;
|
||||
FILE *pid_file = fopen(pid_file_path, "r");
|
||||
|
||||
if ((pid_file = fopen(pid_file_path, "r"))) {
|
||||
if (pid_file != nullptr) {
|
||||
log_write(LOG_LEVEL_WARNING, "Another instance of the daemon is already running, PID file %s exists.\n", pid_file_path);
|
||||
fclose(pid_file);
|
||||
}
|
||||
@ -175,38 +174,29 @@ static void daemonize(LOG_BACKEND log_backend, char *pid_file_path)
|
||||
|
||||
// Logs toxcore logger message using our logger facility
|
||||
|
||||
static LOG_LEVEL logger_level_to_log_level(Logger_Level level)
|
||||
{
|
||||
switch (level) {
|
||||
case LOGGER_LEVEL_TRACE:
|
||||
case LOGGER_LEVEL_DEBUG:
|
||||
case LOGGER_LEVEL_INFO:
|
||||
return LOG_LEVEL_INFO;
|
||||
|
||||
case LOGGER_LEVEL_WARNING:
|
||||
return LOG_LEVEL_WARNING;
|
||||
|
||||
case LOGGER_LEVEL_ERROR:
|
||||
return LOG_LEVEL_ERROR;
|
||||
|
||||
default:
|
||||
return LOG_LEVEL_INFO;
|
||||
}
|
||||
}
|
||||
|
||||
static void toxcore_logger_callback(void *context, Logger_Level level, const char *file, int line,
|
||||
const char *func, const char *message, void *userdata)
|
||||
{
|
||||
LOG_LEVEL log_level;
|
||||
|
||||
switch (level) {
|
||||
case LOGGER_LEVEL_TRACE:
|
||||
log_level = LOG_LEVEL_INFO;
|
||||
break;
|
||||
|
||||
case LOGGER_LEVEL_DEBUG:
|
||||
log_level = LOG_LEVEL_INFO;
|
||||
break;
|
||||
|
||||
case LOGGER_LEVEL_INFO:
|
||||
log_level = LOG_LEVEL_INFO;
|
||||
break;
|
||||
|
||||
case LOGGER_LEVEL_WARNING:
|
||||
log_level = LOG_LEVEL_WARNING;
|
||||
break;
|
||||
|
||||
case LOGGER_LEVEL_ERROR:
|
||||
log_level = LOG_LEVEL_ERROR;
|
||||
break;
|
||||
|
||||
default:
|
||||
log_level = LOG_LEVEL_INFO;
|
||||
break;
|
||||
}
|
||||
|
||||
log_write(log_level, "%s:%d(%s) %s\n", file, line, func, message);
|
||||
log_write(logger_level_to_log_level(level), "%s:%d(%s) %s\n", file, line, func, message);
|
||||
}
|
||||
|
||||
static volatile sig_atomic_t caught_signal = 0;
|
||||
@ -220,11 +210,10 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
umask(077);
|
||||
char *cfg_file_path = nullptr;
|
||||
LOG_BACKEND log_backend;
|
||||
bool run_in_foreground;
|
||||
bool run_in_foreground = false;
|
||||
|
||||
// choose backend for printing command line argument parsing output based on whether the daemon is being run from a terminal
|
||||
log_backend = isatty(STDOUT_FILENO) ? LOG_BACKEND_STDOUT : LOG_BACKEND_SYSLOG;
|
||||
LOG_BACKEND log_backend = isatty(STDOUT_FILENO) ? LOG_BACKEND_STDOUT : LOG_BACKEND_SYSLOG;
|
||||
|
||||
log_open(log_backend);
|
||||
handle_command_line_arguments(argc, argv, &cfg_file_path, &log_backend, &run_in_foreground);
|
||||
@ -236,14 +225,14 @@ int main(int argc, char *argv[])
|
||||
|
||||
char *pid_file_path = nullptr;
|
||||
char *keys_file_path = nullptr;
|
||||
int start_port;
|
||||
int enable_ipv6;
|
||||
int enable_ipv4_fallback;
|
||||
int enable_lan_discovery;
|
||||
int enable_tcp_relay;
|
||||
int start_port = 0;
|
||||
int enable_ipv6 = 0;
|
||||
int enable_ipv4_fallback = 0;
|
||||
int enable_lan_discovery = 0;
|
||||
int enable_tcp_relay = 0;
|
||||
uint16_t *tcp_relay_ports = nullptr;
|
||||
int tcp_relay_port_count;
|
||||
int enable_motd;
|
||||
int tcp_relay_port_count = 0;
|
||||
int enable_motd = 0;
|
||||
char *motd = nullptr;
|
||||
|
||||
if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &start_port, &enable_ipv6, &enable_ipv4_fallback,
|
||||
@ -275,20 +264,22 @@ int main(int argc, char *argv[])
|
||||
|
||||
Logger *logger = logger_new();
|
||||
|
||||
if (MIN_LOGGER_LEVEL == LOGGER_LEVEL_TRACE || MIN_LOGGER_LEVEL == LOGGER_LEVEL_DEBUG) {
|
||||
if (MIN_LOGGER_LEVEL <= LOGGER_LEVEL_DEBUG) {
|
||||
logger_callback_log(logger, toxcore_logger_callback, nullptr, nullptr);
|
||||
}
|
||||
|
||||
const uint16_t end_port = start_port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM);
|
||||
const Memory *mem = system_memory();
|
||||
const Random *rng = system_random();
|
||||
const Network *ns = system_network();
|
||||
Networking_Core *net = new_networking_ex(logger, ns, &ip, start_port, end_port, nullptr);
|
||||
Networking_Core *net = new_networking_ex(logger, mem, ns, &ip, start_port, end_port, nullptr);
|
||||
|
||||
if (net == nullptr) {
|
||||
if (enable_ipv6 && enable_ipv4_fallback) {
|
||||
log_write(LOG_LEVEL_WARNING, "Couldn't initialize IPv6 networking. Falling back to using IPv4.\n");
|
||||
enable_ipv6 = 0;
|
||||
ip_init(&ip, enable_ipv6);
|
||||
net = new_networking_ex(logger, ns, &ip, start_port, end_port, nullptr);
|
||||
net = new_networking_ex(logger, mem, ns, &ip, start_port, end_port, nullptr);
|
||||
|
||||
if (net == nullptr) {
|
||||
log_write(LOG_LEVEL_ERROR, "Couldn't fallback to IPv4. Exiting.\n");
|
||||
@ -308,7 +299,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
Mono_Time *const mono_time = mono_time_new(nullptr, nullptr);
|
||||
Mono_Time *const mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
|
||||
if (mono_time == nullptr) {
|
||||
log_write(LOG_LEVEL_ERROR, "Couldn't initialize monotonic timer. Exiting.\n");
|
||||
@ -322,12 +313,11 @@ int main(int argc, char *argv[])
|
||||
|
||||
mono_time_update(mono_time);
|
||||
|
||||
const Random *rng = system_random();
|
||||
DHT *const dht = new_dht(logger, rng, ns, mono_time, net, true, enable_lan_discovery);
|
||||
DHT *const dht = new_dht(logger, mem, rng, ns, mono_time, net, true, enable_lan_discovery);
|
||||
|
||||
if (dht == nullptr) {
|
||||
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox DHT instance. Exiting.\n");
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
kill_networking(net);
|
||||
logger_kill(logger);
|
||||
free(motd);
|
||||
@ -341,7 +331,7 @@ int main(int argc, char *argv[])
|
||||
if (forwarding == nullptr) {
|
||||
log_write(LOG_LEVEL_ERROR, "Couldn't initialize forwarding. Exiting.\n");
|
||||
kill_dht(dht);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
kill_networking(net);
|
||||
logger_kill(logger);
|
||||
free(motd);
|
||||
@ -350,13 +340,13 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
Announcements *announce = new_announcements(logger, rng, mono_time, forwarding);
|
||||
Announcements *announce = new_announcements(logger, mem, rng, mono_time, forwarding);
|
||||
|
||||
if (announce == nullptr) {
|
||||
log_write(LOG_LEVEL_ERROR, "Couldn't initialize DHT announcements. Exiting.\n");
|
||||
kill_forwarding(forwarding);
|
||||
kill_dht(dht);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
kill_networking(net);
|
||||
logger_kill(logger);
|
||||
free(motd);
|
||||
@ -372,7 +362,7 @@ int main(int argc, char *argv[])
|
||||
kill_announcements(announce);
|
||||
kill_forwarding(forwarding);
|
||||
kill_dht(dht);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
kill_networking(net);
|
||||
logger_kill(logger);
|
||||
free(motd);
|
||||
@ -381,14 +371,14 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
Onion *onion = new_onion(logger, mono_time, rng, dht);
|
||||
Onion *onion = new_onion(logger, mem, mono_time, rng, dht);
|
||||
|
||||
if (!onion) {
|
||||
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion. Exiting.\n");
|
||||
kill_announcements(announce);
|
||||
kill_forwarding(forwarding);
|
||||
kill_dht(dht);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
kill_networking(net);
|
||||
logger_kill(logger);
|
||||
free(motd);
|
||||
@ -397,7 +387,7 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
Onion_Announce *onion_a = new_onion_announce(logger, rng, mono_time, dht);
|
||||
Onion_Announce *onion_a = new_onion_announce(logger, mem, rng, mono_time, dht);
|
||||
|
||||
if (!onion_a) {
|
||||
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion Announce. Exiting.\n");
|
||||
@ -406,7 +396,7 @@ int main(int argc, char *argv[])
|
||||
kill_announcements(announce);
|
||||
kill_forwarding(forwarding);
|
||||
kill_dht(dht);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
kill_networking(net);
|
||||
logger_kill(logger);
|
||||
free(motd);
|
||||
@ -429,7 +419,7 @@ int main(int argc, char *argv[])
|
||||
kill_announcements(announce);
|
||||
kill_forwarding(forwarding);
|
||||
kill_dht(dht);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
kill_networking(net);
|
||||
logger_kill(logger);
|
||||
free(motd);
|
||||
@ -450,7 +440,7 @@ int main(int argc, char *argv[])
|
||||
kill_announcements(announce);
|
||||
kill_forwarding(forwarding);
|
||||
kill_dht(dht);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
kill_networking(net);
|
||||
logger_kill(logger);
|
||||
free(tcp_relay_ports);
|
||||
@ -469,14 +459,15 @@ int main(int argc, char *argv[])
|
||||
kill_forwarding(forwarding);
|
||||
kill_onion(onion);
|
||||
kill_dht(dht);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
kill_networking(net);
|
||||
logger_kill(logger);
|
||||
free(tcp_relay_ports);
|
||||
return 1;
|
||||
}
|
||||
|
||||
tcp_server = new_TCP_server(logger, rng, ns, enable_ipv6, tcp_relay_port_count, tcp_relay_ports,
|
||||
tcp_server = new_tcp_server(logger, mem, rng, ns, enable_ipv6,
|
||||
tcp_relay_port_count, tcp_relay_ports,
|
||||
dht_get_self_secret_key(dht), onion, forwarding);
|
||||
|
||||
free(tcp_relay_ports);
|
||||
@ -515,7 +506,7 @@ int main(int argc, char *argv[])
|
||||
kill_announcements(announce);
|
||||
kill_forwarding(forwarding);
|
||||
kill_dht(dht);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
kill_networking(net);
|
||||
logger_kill(logger);
|
||||
return 1;
|
||||
@ -526,14 +517,14 @@ int main(int argc, char *argv[])
|
||||
log_write(LOG_LEVEL_INFO, "List of bootstrap nodes read successfully.\n");
|
||||
} else {
|
||||
log_write(LOG_LEVEL_ERROR, "Couldn't read list of bootstrap nodes in %s. Exiting.\n", cfg_file_path);
|
||||
kill_TCP_server(tcp_server);
|
||||
kill_tcp_server(tcp_server);
|
||||
kill_onion_announce(onion_a);
|
||||
kill_gca(group_announce);
|
||||
kill_onion(onion);
|
||||
kill_announcements(announce);
|
||||
kill_forwarding(forwarding);
|
||||
kill_dht(dht);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
kill_networking(net);
|
||||
logger_kill(logger);
|
||||
return 1;
|
||||
@ -541,7 +532,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
print_public_key(dht_get_self_public_key(dht));
|
||||
|
||||
uint64_t last_LANdiscovery = 0;
|
||||
uint64_t last_lan_discovery = 0;
|
||||
const uint16_t net_htons_port = net_htons(start_port);
|
||||
|
||||
int waiting_for_dht_connection = 1;
|
||||
@ -576,13 +567,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
do_dht(dht);
|
||||
|
||||
if (enable_lan_discovery && mono_time_is_timeout(mono_time, last_LANdiscovery, LAN_DISCOVERY_INTERVAL)) {
|
||||
if (enable_lan_discovery && mono_time_is_timeout(mono_time, last_lan_discovery, LAN_DISCOVERY_INTERVAL)) {
|
||||
lan_discovery_send(dht_get_net(dht), broadcast, dht_get_self_public_key(dht), net_htons_port);
|
||||
last_LANdiscovery = mono_time_get(mono_time);
|
||||
last_lan_discovery = mono_time_get(mono_time);
|
||||
}
|
||||
|
||||
if (enable_tcp_relay) {
|
||||
do_TCP_server(tcp_server, mono_time);
|
||||
do_tcp_server(tcp_server, mono_time);
|
||||
}
|
||||
|
||||
networking_poll(dht_get_net(dht), nullptr);
|
||||
@ -609,14 +600,14 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
lan_discovery_kill(broadcast);
|
||||
kill_TCP_server(tcp_server);
|
||||
kill_tcp_server(tcp_server);
|
||||
kill_onion_announce(onion_a);
|
||||
kill_gca(group_announce);
|
||||
kill_onion(onion);
|
||||
kill_announcements(announce);
|
||||
kill_forwarding(forwarding);
|
||||
kill_dht(dht);
|
||||
mono_time_free(mono_time);
|
||||
mono_time_free(mem, mono_time);
|
||||
kill_networking(net);
|
||||
logger_kill(logger);
|
||||
|
||||
|
Reference in New Issue
Block a user