mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-26 23:53:28 +01:00
allow connections through proxies
This commit is contained in:
parent
edbdf2966a
commit
72010dd2e1
36
src/toxic.c
36
src/toxic.c
@ -180,7 +180,12 @@ static Tox *init_tox(void)
|
|||||||
Tox_Options tox_opts;
|
Tox_Options tox_opts;
|
||||||
tox_opts.ipv6enabled = !arg_opts.use_ipv4;
|
tox_opts.ipv6enabled = !arg_opts.use_ipv4;
|
||||||
tox_opts.udp_disabled = arg_opts.force_tcp;
|
tox_opts.udp_disabled = arg_opts.force_tcp;
|
||||||
tox_opts.proxy_enabled = 0;
|
tox_opts.proxy_enabled = arg_opts.use_proxy;
|
||||||
|
|
||||||
|
if (tox_opts.proxy_enabled) {
|
||||||
|
tox_opts.proxy_port = arg_opts.proxy_port;
|
||||||
|
snprintf(tox_opts.proxy_address, sizeof(tox_opts.proxy_address), "%s", arg_opts.proxy_address);
|
||||||
|
}
|
||||||
|
|
||||||
/* Init core */
|
/* Init core */
|
||||||
Tox *m = tox_new(&tox_opts);
|
Tox *m = tox_new(&tox_opts);
|
||||||
@ -197,6 +202,9 @@ static Tox *init_tox(void)
|
|||||||
if (tox_opts.udp_disabled)
|
if (tox_opts.udp_disabled)
|
||||||
fprintf(stderr, "UDP disabled\n");
|
fprintf(stderr, "UDP disabled\n");
|
||||||
|
|
||||||
|
if (tox_opts.proxy_enabled && m == NULL)
|
||||||
|
exit_toxic_err("Proxy failed to connect", FATALERR_PROXY);
|
||||||
|
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -517,8 +525,9 @@ static void print_usage(void)
|
|||||||
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, " -p, --proxy Use proxy: Requires [IP] [port]\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, " -t, --force-tcp Force TCP connection (use this with proxies)\n");
|
||||||
fprintf(stderr, " -x, --nodata Ignore data file\n");
|
fprintf(stderr, " -x, --nodata Ignore data file\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -530,6 +539,7 @@ static void set_default_opts(void)
|
|||||||
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;
|
arg_opts.force_tcp = 0;
|
||||||
|
arg_opts.use_proxy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_args(int argc, char *argv[])
|
static void parse_args(int argc, char *argv[])
|
||||||
@ -547,9 +557,10 @@ static void parse_args(int argc, char *argv[])
|
|||||||
{"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'},
|
{"force-tcp", no_argument, 0, 't'},
|
||||||
|
{"proxy", required_argument, 0, 'p'},
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *opts_str = "4dhotxc:f:n:r:";
|
const char *opts_str = "4dhotxc:f:n:r:p:";
|
||||||
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) {
|
||||||
@ -586,6 +597,12 @@ static void parse_args(int argc, char *argv[])
|
|||||||
arg_opts.no_connect = 1;
|
arg_opts.no_connect = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'p':
|
||||||
|
arg_opts.use_proxy = 1;
|
||||||
|
snprintf(arg_opts.proxy_address, sizeof(arg_opts.proxy_address), "%s", optarg);
|
||||||
|
arg_opts.proxy_port = (uint16_t) atoi(argv[optind++]);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
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;
|
||||||
@ -726,14 +743,19 @@ int main(int argc, char *argv[])
|
|||||||
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
|
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings_err == -1) {
|
if (settings_err == -1)
|
||||||
msg = "Failed to load user settings";
|
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to load user settings");
|
||||||
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
|
|
||||||
|
if (arg_opts.use_proxy && !arg_opts.force_tcp) {
|
||||||
|
msg = "WARNING: Using a proxy without disabling UDP may leak your real IP address.";
|
||||||
|
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
|
||||||
|
msg = "Use the -t option to disable UDP";
|
||||||
|
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Redirect stderr to /dev/null
|
/* Redirect stderr to /dev/null
|
||||||
NOTE: Might not be best solution. Comment out for debugging. */
|
NOTE: Might not be best solution. Comment out for debugging. */
|
||||||
freopen("/dev/null", "w", stderr);
|
//freopen("/dev/null", "w", stderr);
|
||||||
|
|
||||||
uint64_t last_save = (uint64_t) time(NULL);
|
uint64_t last_save = (uint64_t) time(NULL);
|
||||||
uint64_t looptimer = last_save;
|
uint64_t looptimer = last_save;
|
||||||
|
@ -78,6 +78,7 @@ typedef enum _FATAL_ERRS {
|
|||||||
FATALERR_NETWORKINIT = -8, /* Tox network failed to init */
|
FATALERR_NETWORKINIT = -8, /* Tox network failed to init */
|
||||||
FATALERR_INFLOOP = -9, /* infinite loop detected */
|
FATALERR_INFLOOP = -9, /* infinite loop detected */
|
||||||
FATALERR_WININIT = -10, /* window init failed */
|
FATALERR_WININIT = -10, /* window init failed */
|
||||||
|
FATALERR_PROXY = -11, /* Tox network failed to iti using a proxy */
|
||||||
} FATAL_ERRS;
|
} FATAL_ERRS;
|
||||||
|
|
||||||
/* Fixes text color problem on some terminals.
|
/* Fixes text color problem on some terminals.
|
||||||
|
@ -78,9 +78,14 @@ struct arg_opts {
|
|||||||
int default_locale;
|
int default_locale;
|
||||||
int use_custom_data;
|
int use_custom_data;
|
||||||
int no_connect;
|
int no_connect;
|
||||||
|
|
||||||
char dns_path[MAX_STR_SIZE];
|
char dns_path[MAX_STR_SIZE];
|
||||||
char config_path[MAX_STR_SIZE];
|
char config_path[MAX_STR_SIZE];
|
||||||
char nodes_path[MAX_STR_SIZE];
|
char nodes_path[MAX_STR_SIZE];
|
||||||
|
|
||||||
|
int use_proxy;
|
||||||
|
char proxy_address[256];
|
||||||
|
uint16_t proxy_port;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct ToxWindow ToxWindow;
|
typedef struct ToxWindow ToxWindow;
|
||||||
|
Loading…
Reference in New Issue
Block a user