mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-14 17:23:03 +01:00
Add setting to control DHT nodeslist update frequency
Also rename a few things and semi-fix man page format issues
This commit is contained in:
parent
4f6c603543
commit
151f5f0c51
@ -82,7 +82,8 @@ Show help message
|
||||
.RS 4
|
||||
Use specified
|
||||
\fInodes\-file\fR
|
||||
for DHT bootstrap nodes, instead of the default
|
||||
for DHT bootstrap nodes instead of
|
||||
\fI~/\&.config/tox/DHTnodes\&.json\fR
|
||||
.RE
|
||||
.PP
|
||||
\-o, \-\-noconnect
|
||||
@ -124,7 +125,8 @@ Unencrypt a data file\&. A warning will appear if this option is used with a dat
|
||||
~/\&.config/tox/DHTnodes\&.json
|
||||
.RS 4
|
||||
Default location for list of DHT bootstrap nodes (list obtained from
|
||||
https://nodes\&.tox\&.chat)\&. This list is automatically updated every 30 days\&.
|
||||
https://nodes\&.tox\&.chat)\&. This list is automatically updated\&. See
|
||||
\fBtoxic\&.conf\fR(5) for details on controlling the update frequency\&.
|
||||
.RE
|
||||
.PP
|
||||
~/\&.config/tox/toxic_profile\&.tox
|
||||
|
@ -41,7 +41,7 @@ OPTIONS
|
||||
Show help message
|
||||
|
||||
-n, --nodes nodes-file::
|
||||
Use specified 'nodes-file' for DHT bootstrap nodes, instead of the default
|
||||
Use specified 'nodes-file' for DHT bootstrap nodes instead of '~/.config/tox/DHTnodes.json'
|
||||
|
||||
-o, --noconnect::
|
||||
Do not connect to the DHT network
|
||||
@ -69,7 +69,7 @@ FILES
|
||||
-----
|
||||
~/.config/tox/DHTnodes.json::
|
||||
Default location for list of DHT bootstrap nodes (list obtained from https://nodes.tox.chat).
|
||||
This list is automatically updated every 30 days.
|
||||
This list is automatically updated. See *toxic.conf*(5) for details on controlling the update frequency.
|
||||
|
||||
~/.config/tox/toxic_profile.tox::
|
||||
Savestate which contains your personal info (nickname, Tox ID, contacts,
|
||||
|
@ -2,12 +2,12 @@
|
||||
.\" Title: toxic.conf
|
||||
.\" Author: [see the "AUTHORS" section]
|
||||
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
|
||||
.\" Date: 2016-02-28
|
||||
.\" Date: 2016-07-21
|
||||
.\" Manual: Toxic Manual
|
||||
.\" Source: toxic __VERSION__
|
||||
.\" Language: English
|
||||
.\"
|
||||
.TH "TOXIC\&.CONF" "5" "2016\-02\-28" "toxic __VERSION__" "Toxic Manual"
|
||||
.TH "TOXIC\&.CONF" "5" "2016\-07\-21" "toxic __VERSION__" "Toxic Manual"
|
||||
.\" -----------------------------------------------------------------
|
||||
.\" * Define some portability stuff
|
||||
.\" -----------------------------------------------------------------
|
||||
@ -118,6 +118,11 @@ Show welcome message on startup\&. true or false
|
||||
Enable friend connection change notifications\&. true or false
|
||||
.RE
|
||||
.PP
|
||||
\fBnodelist_update_freq\fR
|
||||
.RS 4
|
||||
How often in days to update the DHT nodes list\&. (0 to disable updates)
|
||||
.RE
|
||||
.PP
|
||||
\fBhistory_size\fR
|
||||
.RS 4
|
||||
Maximum lines for chat window history\&. Integer value\&. (for example: 700)
|
||||
@ -151,11 +156,19 @@ Set user status when attaching and detaching from GNU screen or tmux\&. true or
|
||||
\fBmplex_away_note\fR
|
||||
.RS 4
|
||||
Status message to set when status is set to away due to screen/tmux detach\&. When attaching, the status message is set back to the original value\&.
|
||||
.RE
|
||||
.PP
|
||||
.sp
|
||||
.if n \{\
|
||||
.RS 4
|
||||
.\}
|
||||
.nf
|
||||
The following options control whether to output a terminal bell on certain events\&.
|
||||
.br
|
||||
Some terminals mark the window as urgent when a bell is received\&. Urgent windows are usually highlighted in the taskbar and some window managers even provide shortcuts to jump to the next urgent window\&. These options don't affect the "alerts" option\&.
|
||||
Some terminals mark the window as urgent when a bell is received\&. Urgent windows are usually highlighted in the taskbar and some window managers even provide shortcuts to jump to the next urgent window\&.
|
||||
These options don\*(Aqt affect the "alerts" option\&.
|
||||
.fi
|
||||
.if n \{\
|
||||
.RE
|
||||
.\}
|
||||
.RE
|
||||
.PP
|
||||
\fBbell_on_message\fR
|
||||
.RS 4
|
||||
|
@ -75,6 +75,9 @@ OPTIONS
|
||||
*show_connection_msg*;;
|
||||
Enable friend connection change notifications. true or false
|
||||
|
||||
*nodelist_update_freq*;;
|
||||
How often in days to update the DHT nodes list. (0 to disable updates)
|
||||
|
||||
*history_size*;;
|
||||
Maximum lines for chat window history. Integer value. (for example: 700)
|
||||
|
||||
@ -104,16 +107,16 @@ OPTIONS
|
||||
Some terminals mark the window as urgent when a bell is received. Urgent windows are usually highlighted in the taskbar and some window managers even provide shortcuts to jump to the next urgent window.
|
||||
These options don't affect the "alerts" option.
|
||||
|
||||
*bell_on_message*
|
||||
*bell_on_message*;;
|
||||
Enable/Disable the terminal bell when receiving a message. true or false
|
||||
|
||||
*bell_on_filetrans*
|
||||
*bell_on_filetrans*;;
|
||||
Enable/Disable the terminal bell when receiving a filetransfer. true or false
|
||||
|
||||
*bell_on_filetrans_accept*
|
||||
*bell_on_filetrans_accept*;;
|
||||
Enable/Disable the terminal bell when a filetransfer was accepted. true or false
|
||||
|
||||
*bell_on_invite*
|
||||
*bell_on_invite*;;
|
||||
Enable/Disable the terminal bell when receiving a group/call invite. true or false
|
||||
|
||||
|
||||
|
@ -29,7 +29,7 @@ ui = {
|
||||
// 24 or 12 hour time
|
||||
time_format=24;
|
||||
|
||||
// timestamp format string according to date/strftime format. Overrides time_format setting
|
||||
// Timestamp format string according to date/strftime format. Overrides time_format setting
|
||||
timestamp_format="%H:%M:%S";
|
||||
|
||||
// true to show you when others are typing a message in 1-on-1 chats
|
||||
@ -44,6 +44,9 @@ ui = {
|
||||
// true to show friend connection change messages on the home screen
|
||||
show_connection_msg=true;
|
||||
|
||||
// How often in days to update the DHT nodes list. (0 to disable updates)
|
||||
nodeslist_update_freq=30;
|
||||
|
||||
// maximum lines for chat window history
|
||||
history_size=700;
|
||||
|
||||
@ -101,8 +104,7 @@ sounds = {
|
||||
};
|
||||
|
||||
// Currently supported: Ctrl modified keys, Tab, PAGEUP and PAGEDOWN (case insensitive)
|
||||
// Note: All printable keys register as input
|
||||
// Note2: Ctrl+M does not work
|
||||
// Note: Ctrl+M does not work
|
||||
keys = {
|
||||
next_tab="Ctrl+P";
|
||||
prev_tab="Ctrl+O";
|
||||
|
@ -33,9 +33,10 @@
|
||||
#include "misc_tools.h"
|
||||
#include "configdir.h"
|
||||
#include "curl_util.h"
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
extern struct arg_opts arg_opts;
|
||||
extern struct user_settings *user_settings;
|
||||
|
||||
/* URL that we get the JSON encoded nodes list from. */
|
||||
#define NODES_LIST_URL "https://nodes.tox.chat/json"
|
||||
@ -48,9 +49,6 @@ extern struct arg_opts arg_opts;
|
||||
/* Number of nodes to bootstrap to per try */
|
||||
#define NUM_BOOTSTRAP_NODES 5
|
||||
|
||||
/* How often we should update the nodeslist file. */
|
||||
#define NODELIST_UPDATE_TIMEOUT (60*24*30)
|
||||
|
||||
#define IPv4_MAX_SIZE 64
|
||||
#define PORT_MAX_SIZE 5
|
||||
|
||||
@ -72,12 +70,12 @@ extern struct arg_opts arg_opts;
|
||||
#define NODELEN (MAX_NODE_LINE - TOX_PUBLIC_KEY_SIZE - 7)
|
||||
#define MAX_NODELIST_SIZE (1024 * MAXNODES)
|
||||
|
||||
static struct toxNodes {
|
||||
static struct DHT_Nodes {
|
||||
size_t lines;
|
||||
char nodes[MAXNODES][NODELEN];
|
||||
uint16_t ports[MAXNODES];
|
||||
char keys[MAXNODES][TOX_PUBLIC_KEY_SIZE];
|
||||
} toxNodes;
|
||||
} Nodes;
|
||||
|
||||
|
||||
/* Return true if nodeslist pointed to by fp needs to be updated.
|
||||
@ -86,6 +84,10 @@ static struct toxNodes {
|
||||
*/
|
||||
static bool nodeslist_needs_update(const char *nodes_path)
|
||||
{
|
||||
if (user_settings->nodeslist_update_freq <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FILE *fp = fopen(nodes_path, "r+");
|
||||
|
||||
if (fp == NULL) {
|
||||
@ -111,7 +113,7 @@ static bool nodeslist_needs_update(const char *nodes_path)
|
||||
last_scan_val += LAST_SCAN_JSON_VALUE_LEN;
|
||||
long long int last_scan = strtoll(last_scan_val, NULL, 10);
|
||||
|
||||
if (timed_out(last_scan, NODELIST_UPDATE_TIMEOUT)) {
|
||||
if (timed_out(last_scan, user_settings->nodeslist_update_freq * 24 * 60 * 60)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -123,7 +125,7 @@ static bool nodeslist_needs_update(const char *nodes_path)
|
||||
* Return 0 on success.
|
||||
* Return -1 on failure.
|
||||
*/
|
||||
static int curl_fetch_nodes_JSON(struct Recv_Data *recv_data)
|
||||
static int curl_fetch_nodes_JSON(struct Recv_Curl_Data *recv_data)
|
||||
{
|
||||
CURL *c_handle = curl_easy_init();
|
||||
|
||||
@ -137,7 +139,7 @@ static int curl_fetch_nodes_JSON(struct Recv_Data *recv_data)
|
||||
|
||||
curl_easy_setopt(c_handle, CURLOPT_HTTPHEADER, headers);
|
||||
curl_easy_setopt(c_handle, CURLOPT_URL, NODES_LIST_URL);
|
||||
curl_easy_setopt(c_handle, CURLOPT_WRITEFUNCTION, write_lookup_data);
|
||||
curl_easy_setopt(c_handle, CURLOPT_WRITEFUNCTION, curl_cb_write_data);
|
||||
curl_easy_setopt(c_handle, CURLOPT_WRITEDATA, recv_data);
|
||||
curl_easy_setopt(c_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
|
||||
curl_easy_setopt(c_handle, CURLOPT_HTTPGET, 1L);
|
||||
@ -202,8 +204,8 @@ static int update_DHT_nodeslist(const char *nodes_path)
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct Recv_Data recv_data;
|
||||
memset(&recv_data, 0, sizeof(struct Recv_Data));
|
||||
struct Recv_Curl_Data recv_data;
|
||||
memset(&recv_data, 0, sizeof(struct Recv_Curl_Data));
|
||||
|
||||
if (curl_fetch_nodes_JSON(&recv_data) == -1) {
|
||||
fclose(fp);
|
||||
@ -276,7 +278,7 @@ int load_DHT_nodeslist(void)
|
||||
|
||||
const char *line_start = line;
|
||||
|
||||
while ((line_start = strstr(line_start + 1, IPV4_JSON_VALUE)) && toxNodes.lines < MAXNODES) {
|
||||
while ((line_start = strstr(line_start + 1, IPV4_JSON_VALUE)) && Nodes.lines < MAXNODES) {
|
||||
/* Extract IPv4 address */
|
||||
const char *ip_start = strstr(line_start, IPV4_JSON_VALUE);
|
||||
|
||||
@ -338,19 +340,19 @@ int load_DHT_nodeslist(void)
|
||||
key_string[TOX_PUBLIC_KEY_SIZE * 2] = 0;
|
||||
|
||||
/* Add entry to nodes list */
|
||||
snprintf(toxNodes.nodes[toxNodes.lines], sizeof(toxNodes.nodes[toxNodes.lines]), "%s", ipv4_string);
|
||||
toxNodes.ports[toxNodes.lines] = port;
|
||||
snprintf(Nodes.nodes[Nodes.lines], sizeof(Nodes.nodes[Nodes.lines]), "%s", ipv4_string);
|
||||
Nodes.ports[Nodes.lines] = port;
|
||||
|
||||
if (hex_string_to_bin(key_string, key_len, toxNodes.keys[toxNodes.lines], TOX_PUBLIC_KEY_SIZE) == -1)
|
||||
if (hex_string_to_bin(key_string, key_len, Nodes.keys[Nodes.lines], TOX_PUBLIC_KEY_SIZE) == -1)
|
||||
continue;
|
||||
|
||||
toxNodes.lines++;
|
||||
Nodes.lines++;
|
||||
}
|
||||
|
||||
/* If nodeslist does not contain any valid entries we set the last_scan value
|
||||
* to 0 so that it will fetch a new list the next time this function is called.
|
||||
*/
|
||||
if (toxNodes.lines == 0) {
|
||||
if (Nodes.lines == 0) {
|
||||
const char *s = "{\"last_scan\":0}";
|
||||
rewind(fp);
|
||||
fwrite(s, strlen(s), 1, fp); // Not much we can do if it fails
|
||||
@ -365,26 +367,26 @@ int load_DHT_nodeslist(void)
|
||||
/* Connects to NUM_BOOTSTRAP_NODES random DHT nodes listed in the DHTnodes file. */
|
||||
static void DHT_bootstrap(Tox *m)
|
||||
{
|
||||
if (toxNodes.lines == 0) {
|
||||
if (Nodes.lines == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < NUM_BOOTSTRAP_NODES; ++i) {
|
||||
size_t node = rand() % toxNodes.lines;
|
||||
size_t node = rand() % Nodes.lines;
|
||||
|
||||
TOX_ERR_BOOTSTRAP err;
|
||||
tox_bootstrap(m, toxNodes.nodes[node], toxNodes.ports[node], (uint8_t *) toxNodes.keys[node], &err);
|
||||
tox_bootstrap(m, Nodes.nodes[node], Nodes.ports[node], (uint8_t *) Nodes.keys[node], &err);
|
||||
|
||||
if (err != TOX_ERR_BOOTSTRAP_OK) {
|
||||
fprintf(stderr, "Failed to bootstrap %s:%d\n", toxNodes.nodes[node], toxNodes.ports[node]);
|
||||
fprintf(stderr, "Failed to bootstrap %s:%d\n", Nodes.nodes[node], Nodes.ports[node]);
|
||||
}
|
||||
|
||||
tox_add_tcp_relay(m, toxNodes.nodes[node], toxNodes.ports[node], (uint8_t *) toxNodes.keys[node], &err);
|
||||
tox_add_tcp_relay(m, Nodes.nodes[node], Nodes.ports[node], (uint8_t *) Nodes.keys[node], &err);
|
||||
|
||||
if (err != TOX_ERR_BOOTSTRAP_OK) {
|
||||
fprintf(stderr, "Failed to add TCP relay %s:%d\n", toxNodes.nodes[node], toxNodes.ports[node]);
|
||||
fprintf(stderr, "Failed to add TCP relay %s:%d\n", Nodes.nodes[node], Nodes.ports[node]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,9 +74,9 @@ int set_curl_proxy(CURL *c_handle, const char *proxy_address, uint16_t port, uin
|
||||
* Returns number of bytes received from http request on success (don't change this).
|
||||
* Returns 0 if data exceeds buffer size.
|
||||
*/
|
||||
size_t write_lookup_data(void *data, size_t size, size_t nmemb, void *user_pointer)
|
||||
size_t curl_cb_write_data(void *data, size_t size, size_t nmemb, void *user_pointer)
|
||||
{
|
||||
struct Recv_Data *recv_data = (struct Recv_Data *) user_pointer;
|
||||
struct Recv_Curl_Data *recv_data = (struct Recv_Curl_Data *) user_pointer;
|
||||
|
||||
size_t length = size * nmemb;
|
||||
size_t total_size = length + recv_data->length;
|
||||
|
@ -27,7 +27,7 @@
|
||||
#define MAX_RECV_CURL_DATA_SIZE 32767
|
||||
|
||||
/* Holds data received from curl lookup */
|
||||
struct Recv_Data {
|
||||
struct Recv_Curl_Data {
|
||||
char data[MAX_RECV_CURL_DATA_SIZE + 1]; /* Data received from curl write data callback */
|
||||
size_t length; /* Total number of bytes written to data buffer (doesn't include null) */
|
||||
};
|
||||
@ -47,4 +47,4 @@ int set_curl_proxy(CURL *c_handle, const char *proxy_address, uint16_t port, uin
|
||||
*
|
||||
* Returns size of bytes written to the data buffer.
|
||||
*/
|
||||
size_t write_lookup_data(void *data, size_t size, size_t nmemb, void *user_pointer);
|
||||
size_t curl_cb_write_data(void *data, size_t size, size_t nmemb, void *user_pointer);
|
||||
|
@ -192,7 +192,7 @@ static bool get_domain_match(char *pubkey, char *out_domain, size_t out_domain_s
|
||||
* Returns -1 on failure.
|
||||
*/
|
||||
#define ID_PREFIX "\"tox_id\": \""
|
||||
static int process_response(struct Recv_Data *recv_data)
|
||||
static int process_response(struct Recv_Curl_Data *recv_data)
|
||||
{
|
||||
size_t prefix_size = strlen(ID_PREFIX);
|
||||
|
||||
@ -248,8 +248,8 @@ void *lookup_thread_func(void *data)
|
||||
kill_lookup_thread();
|
||||
}
|
||||
|
||||
struct Recv_Data recv_data;
|
||||
memset(&recv_data, 0, sizeof(struct Recv_Data));
|
||||
struct Recv_Curl_Data recv_data;
|
||||
memset(&recv_data, 0, sizeof(struct Recv_Curl_Data));
|
||||
|
||||
char post_data[MAX_STR_SIZE];
|
||||
snprintf(post_data, sizeof(post_data), "{\"action\": 3, \"name\": \"%s\"}", name);
|
||||
@ -261,7 +261,7 @@ void *lookup_thread_func(void *data)
|
||||
|
||||
curl_easy_setopt(c_handle, CURLOPT_HTTPHEADER, headers);
|
||||
curl_easy_setopt(c_handle, CURLOPT_URL, real_domain);
|
||||
curl_easy_setopt(c_handle, CURLOPT_WRITEFUNCTION, write_lookup_data);
|
||||
curl_easy_setopt(c_handle, CURLOPT_WRITEFUNCTION, curl_cb_write_data);
|
||||
curl_easy_setopt(c_handle, CURLOPT_WRITEDATA, &recv_data);
|
||||
curl_easy_setopt(c_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
|
||||
curl_easy_setopt(c_handle, CURLOPT_POSTFIELDS, post_data);
|
||||
|
@ -62,6 +62,7 @@ static struct ui_strings {
|
||||
const char* show_typing_other;
|
||||
const char* show_welcome_msg;
|
||||
const char* show_connection_msg;
|
||||
const char* nodeslist_update_freq;
|
||||
|
||||
const char* line_join;
|
||||
const char* line_quit;
|
||||
@ -88,6 +89,7 @@ static struct ui_strings {
|
||||
"show_typing_other",
|
||||
"show_welcome_msg",
|
||||
"show_connection_msg",
|
||||
"nodeslist_update_freq",
|
||||
"line_join",
|
||||
"line_quit",
|
||||
"line_alert",
|
||||
@ -114,6 +116,7 @@ static void ui_defaults(struct user_settings* settings)
|
||||
settings->show_typing_other = SHOW_TYPING_ON;
|
||||
settings->show_welcome_msg = SHOW_WELCOME_MSG_ON;
|
||||
settings->show_connection_msg = SHOW_CONNECTION_MSG_ON;
|
||||
settings->nodeslist_update_freq = 30;
|
||||
|
||||
snprintf(settings->line_join, LINE_HINT_MAX + 1, "%s", LINE_JOIN);
|
||||
snprintf(settings->line_quit, LINE_HINT_MAX + 1, "%s", LINE_QUIT);
|
||||
@ -347,12 +350,14 @@ int settings_load(struct user_settings *s, const char *patharg)
|
||||
|
||||
config_setting_lookup_bool(setting, ui_strings.autolog, &s->autolog);
|
||||
config_setting_lookup_bool(setting, ui_strings.native_colors, &s->colour_theme);
|
||||
config_setting_lookup_int(setting, ui_strings.history_size, &s->history_size);
|
||||
config_setting_lookup_bool(setting, ui_strings.show_typing_self, &s->show_typing_self);
|
||||
config_setting_lookup_bool(setting, ui_strings.show_typing_other, &s->show_typing_other);
|
||||
config_setting_lookup_bool(setting, ui_strings.show_welcome_msg, &s->show_welcome_msg);
|
||||
config_setting_lookup_bool(setting, ui_strings.show_connection_msg, &s->show_connection_msg);
|
||||
|
||||
config_setting_lookup_int(setting, ui_strings.history_size, &s->history_size);
|
||||
config_setting_lookup_int(setting, ui_strings.nodeslist_update_freq, &s->nodeslist_update_freq);
|
||||
|
||||
if ( config_setting_lookup_string(setting, ui_strings.line_join, &str) ) {
|
||||
snprintf(s->line_join, sizeof(s->line_join), "%s", str);
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ struct user_settings {
|
||||
int show_typing_other; /* boolean */
|
||||
int show_welcome_msg; /* boolean */
|
||||
int show_connection_msg; /* boolean */
|
||||
int nodeslist_update_freq; /* int (<= 0 to disable updates) */
|
||||
|
||||
char line_join[LINE_HINT_MAX + 1];
|
||||
char line_quit[LINE_HINT_MAX + 1];
|
||||
|
Loading…
Reference in New Issue
Block a user