mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 05:53:02 +01:00
toxcore API update, add option to force TCP connection
This commit is contained in:
parent
3f6fd734d3
commit
edbdf2966a
43
src/toxic.c
43
src/toxic.c
@ -175,24 +175,28 @@ static void init_term(void)
|
|||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Tox *init_tox(int ipv4)
|
static Tox *init_tox(void)
|
||||||
{
|
{
|
||||||
/* Init core */
|
Tox_Options tox_opts;
|
||||||
int ipv6 = !ipv4;
|
tox_opts.ipv6enabled = !arg_opts.use_ipv4;
|
||||||
Tox *m = tox_new(ipv6);
|
tox_opts.udp_disabled = arg_opts.force_tcp;
|
||||||
|
tox_opts.proxy_enabled = 0;
|
||||||
|
|
||||||
/*
|
/* Init core */
|
||||||
* TOX_ENABLE_IPV6_DEFAULT is always 1.
|
Tox *m = tox_new(&tox_opts);
|
||||||
* Checking it is redundant, this *should* be doing ipv4 fallback
|
|
||||||
*/
|
if (tox_opts.ipv6enabled && m == NULL) {
|
||||||
if (ipv6 && m == NULL) {
|
fprintf(stderr, "IPv6 failed to initialize. Trying IPv4\n");
|
||||||
fprintf(stderr, "IPv6 didn't initialize, trying IPv4\n");
|
tox_opts.ipv6enabled = 0;
|
||||||
m = tox_new(0);
|
m = tox_new(&tox_opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ipv4)
|
if (!tox_opts.ipv6enabled)
|
||||||
fprintf(stderr, "Forcing IPv4 connection\n");
|
fprintf(stderr, "Forcing IPv4 connection\n");
|
||||||
|
|
||||||
|
if (tox_opts.udp_disabled)
|
||||||
|
fprintf(stderr, "UDP disabled\n");
|
||||||
|
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -508,12 +512,13 @@ static void print_usage(void)
|
|||||||
fprintf(stderr, "usage: toxic [OPTION] [FILE ...]\n");
|
fprintf(stderr, "usage: toxic [OPTION] [FILE ...]\n");
|
||||||
fprintf(stderr, " -4, --ipv4 Force IPv4 connection\n");
|
fprintf(stderr, " -4, --ipv4 Force IPv4 connection\n");
|
||||||
fprintf(stderr, " -c, --config Use specified config file\n");
|
fprintf(stderr, " -c, --config Use specified config file\n");
|
||||||
fprintf(stderr, " -d, --default_locale Use default locale\n");
|
fprintf(stderr, " -d, --default-locale Use default locale\n");
|
||||||
fprintf(stderr, " -f, --file Use specified data file\n");
|
fprintf(stderr, " -f, --file Use specified data file\n");
|
||||||
fprintf(stderr, " -h, --help Show this message and exit\n");
|
fprintf(stderr, " -h, --help Show this message and exit\n");
|
||||||
fprintf(stderr, " -n, --nodes Use specified DHTnodes file\n");
|
fprintf(stderr, " -n, --nodes Use specified DHTnodes file\n");
|
||||||
fprintf(stderr, " -o, --noconnect Do not connect to the DHT network\n");
|
fprintf(stderr, " -o, --noconnect Do not connect to the DHT network\n");
|
||||||
fprintf(stderr, " -r, --dnslist Use specified DNSservers file\n");
|
fprintf(stderr, " -r, --dnslist Use specified DNSservers file\n");
|
||||||
|
fprintf(stderr, " -t, --force-tcp Force the network to use TCP only\n");
|
||||||
fprintf(stderr, " -x, --nodata Ignore data file\n");
|
fprintf(stderr, " -x, --nodata Ignore data file\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,6 +529,7 @@ static void set_default_opts(void)
|
|||||||
arg_opts.default_locale = 0;
|
arg_opts.default_locale = 0;
|
||||||
arg_opts.use_custom_data = 0;
|
arg_opts.use_custom_data = 0;
|
||||||
arg_opts.no_connect = 0;
|
arg_opts.no_connect = 0;
|
||||||
|
arg_opts.force_tcp = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_args(int argc, char *argv[])
|
static void parse_args(int argc, char *argv[])
|
||||||
@ -534,15 +540,16 @@ static void parse_args(int argc, char *argv[])
|
|||||||
{"file", required_argument, 0, 'f'},
|
{"file", required_argument, 0, 'f'},
|
||||||
{"nodata", no_argument, 0, 'x'},
|
{"nodata", no_argument, 0, 'x'},
|
||||||
{"ipv4", no_argument, 0, '4'},
|
{"ipv4", no_argument, 0, '4'},
|
||||||
{"default_locale", no_argument, 0, 'd'},
|
{"default-locale", no_argument, 0, 'd'},
|
||||||
{"config", required_argument, 0, 'c'},
|
{"config", required_argument, 0, 'c'},
|
||||||
{"nodes", required_argument, 0, 'n'},
|
{"nodes", required_argument, 0, 'n'},
|
||||||
{"help", no_argument, 0, 'h'},
|
{"help", no_argument, 0, 'h'},
|
||||||
{"noconnect", no_argument, 0, 'o'},
|
{"noconnect", no_argument, 0, 'o'},
|
||||||
{"dnslist", required_argument, 0, 'r'},
|
{"dnslist", required_argument, 0, 'r'},
|
||||||
|
{"force-tcp", no_argument, 0, 't'},
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *opts_str = "4dhoxc:f:n:r:";
|
const char *opts_str = "4dhotxc:f:n:r:";
|
||||||
int opt, indexptr;
|
int opt, indexptr;
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv, opts_str, long_opts, &indexptr)) != -1) {
|
while ((opt = getopt_long(argc, argv, opts_str, long_opts, &indexptr)) != -1) {
|
||||||
@ -583,6 +590,10 @@ static void parse_args(int argc, char *argv[])
|
|||||||
snprintf(arg_opts.dns_path, sizeof(arg_opts.dns_path), "%s", optarg);
|
snprintf(arg_opts.dns_path, sizeof(arg_opts.dns_path), "%s", optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 't':
|
||||||
|
arg_opts.force_tcp = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'x':
|
case 'x':
|
||||||
arg_opts.ignore_data_file = 1;
|
arg_opts.ignore_data_file = 1;
|
||||||
break;
|
break;
|
||||||
@ -670,7 +681,7 @@ int main(int argc, char *argv[])
|
|||||||
char *p = arg_opts.config_path[0] ? arg_opts.config_path : NULL;
|
char *p = arg_opts.config_path[0] ? arg_opts.config_path : NULL;
|
||||||
int settings_err = settings_load(user_settings_, p);
|
int settings_err = settings_load(user_settings_, p);
|
||||||
|
|
||||||
Tox *m = init_tox(arg_opts.use_ipv4);
|
Tox *m = init_tox();
|
||||||
init_term();
|
init_term();
|
||||||
|
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
|
@ -74,6 +74,7 @@ struct _Winthread {
|
|||||||
struct arg_opts {
|
struct arg_opts {
|
||||||
int ignore_data_file;
|
int ignore_data_file;
|
||||||
int use_ipv4;
|
int use_ipv4;
|
||||||
|
int force_tcp;
|
||||||
int default_locale;
|
int default_locale;
|
||||||
int use_custom_data;
|
int use_custom_data;
|
||||||
int no_connect;
|
int no_connect;
|
||||||
|
Loading…
Reference in New Issue
Block a user