mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Added disabling of UDP and basic SOCKS5 proxy support to public API.
tox_new() now takes a Tox_Options struct as argument. If a NULL pointer is passed to that struct, defaults are used.
This commit is contained in:
parent
f0b2cd7ad2
commit
ef78169842
|
@ -124,9 +124,9 @@ void write_file(Tox *m, int friendnumber, uint8_t filenumber, const uint8_t *dat
|
||||||
START_TEST(test_few_clients)
|
START_TEST(test_few_clients)
|
||||||
{
|
{
|
||||||
long long unsigned int con_time, cur_time = time(NULL);
|
long long unsigned int con_time, cur_time = time(NULL);
|
||||||
Tox *tox1 = tox_new(TOX_ENABLE_IPV6_DEFAULT);
|
Tox *tox1 = tox_new(0);
|
||||||
Tox *tox2 = tox_new(TOX_ENABLE_IPV6_DEFAULT);
|
Tox *tox2 = tox_new(0);
|
||||||
Tox *tox3 = tox_new(TOX_ENABLE_IPV6_DEFAULT);
|
Tox *tox3 = tox_new(0);
|
||||||
ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances");
|
ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances");
|
||||||
uint32_t to_compare = 974536;
|
uint32_t to_compare = 974536;
|
||||||
tox_callback_friend_request(tox2, accept_friend_request, &to_compare);
|
tox_callback_friend_request(tox2, accept_friend_request, &to_compare);
|
||||||
|
@ -302,7 +302,7 @@ START_TEST(test_many_clients)
|
||||||
uint32_t to_comp = 974536;
|
uint32_t to_comp = 974536;
|
||||||
|
|
||||||
for (i = 0; i < NUM_TOXES; ++i) {
|
for (i = 0; i < NUM_TOXES; ++i) {
|
||||||
toxes[i] = tox_new(TOX_ENABLE_IPV6_DEFAULT);
|
toxes[i] = tox_new(0);
|
||||||
ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
|
ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
|
||||||
tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp);
|
tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1225,7 +1225,7 @@ int main(int argc, char *argv[])
|
||||||
if (!strcmp(argv[argc - 2], "-f"))
|
if (!strcmp(argv[argc - 2], "-f"))
|
||||||
filename = argv[argc - 1];
|
filename = argv[argc - 1];
|
||||||
|
|
||||||
m = tox_new(ipv6enabled);
|
m = tox_new(0);
|
||||||
|
|
||||||
if ( !m ) {
|
if ( !m ) {
|
||||||
fputs("Failed to allocate Messenger datastructure", stderr);
|
fputs("Failed to allocate Messenger datastructure", stderr);
|
||||||
|
@ -1258,7 +1258,6 @@ int main(int argc, char *argv[])
|
||||||
uint16_t port = htons(atoi(argv[argvoffset + 2]));
|
uint16_t port = htons(atoi(argv[argvoffset + 2]));
|
||||||
unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
|
unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
|
||||||
int res = tox_bootstrap_from_address(m, argv[argvoffset + 1], ipv6enabled, port, binary_string);
|
int res = tox_bootstrap_from_address(m, argv[argvoffset + 1], ipv6enabled, port, binary_string);
|
||||||
free(binary_string);
|
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
|
printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
|
||||||
|
@ -1319,6 +1318,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(binary_string);
|
||||||
tox_kill(m);
|
tox_kill(m);
|
||||||
endwin();
|
endwin();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -214,7 +214,7 @@ int main(int argc, char *argv[])
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Tox *tox = tox_new(ipv6enabled);
|
Tox *tox = tox_new(0);
|
||||||
tox_callback_file_data(tox, write_file, NULL);
|
tox_callback_file_data(tox, write_file, NULL);
|
||||||
tox_callback_file_control(tox, file_print_control, NULL);
|
tox_callback_file_control(tox, file_print_control, NULL);
|
||||||
tox_callback_file_send_request(tox, file_request_accept, NULL);
|
tox_callback_file_send_request(tox, file_request_accept, NULL);
|
||||||
|
|
|
@ -40,6 +40,9 @@
|
||||||
*/
|
*/
|
||||||
int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *client_id)
|
int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *client_id)
|
||||||
{
|
{
|
||||||
|
if (ip_port.ip.family != AF_INET && ip_port.ip.family != AF_INET6)
|
||||||
|
return -1;
|
||||||
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_PATH_NODES; ++i) {
|
for (i = 0; i < MAX_PATH_NODES; ++i) {
|
||||||
|
|
|
@ -815,12 +815,32 @@ uint32_t tox_do_interval(Tox *tox)
|
||||||
* return allocated instance of tox on success.
|
* return allocated instance of tox on success.
|
||||||
* return 0 if there are problems.
|
* return 0 if there are problems.
|
||||||
*/
|
*/
|
||||||
Tox *tox_new(uint8_t ipv6enabled)
|
Tox *tox_new(Tox_Options *options)
|
||||||
{
|
{
|
||||||
LOGGER_INIT(LOGGER_OUTPUT_FILE, LOGGER_LEVEL);
|
LOGGER_INIT(LOGGER_OUTPUT_FILE, LOGGER_LEVEL);
|
||||||
Messenger_Options options = {0};
|
Messenger_Options m_options = {0};
|
||||||
options.ipv6enabled = ipv6enabled;
|
|
||||||
return new_messenger(&options);
|
if (options == NULL) {
|
||||||
|
m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT;
|
||||||
|
} else {
|
||||||
|
m_options.ipv6enabled = options->ipv6enabled;
|
||||||
|
m_options.udp_disabled = options->udp_disabled;
|
||||||
|
m_options.proxy_enabled = options->proxy_enabled;
|
||||||
|
|
||||||
|
if (m_options.proxy_enabled) {
|
||||||
|
ip_init(&m_options.proxy_info.ip_port.ip, m_options.ipv6enabled);
|
||||||
|
|
||||||
|
if (m_options.ipv6enabled)
|
||||||
|
m_options.proxy_info.ip_port.ip.family = AF_UNSPEC;
|
||||||
|
|
||||||
|
if (!addr_resolve_or_parse_ip(options->proxy_address, &m_options.proxy_info.ip_port.ip, NULL))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
m_options.proxy_info.ip_port.port = htons(options->proxy_port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new_messenger(&m_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run this before closing shop.
|
/* Run this before closing shop.
|
||||||
|
|
|
@ -622,20 +622,39 @@ int tox_bootstrap_from_address(Tox *tox, const char *address, uint8_t ipv6enable
|
||||||
*/
|
*/
|
||||||
int tox_isconnected(const Tox *tox);
|
int tox_isconnected(const Tox *tox);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
/*
|
||||||
|
* The type of UDP socket created depends on ipv6enabled:
|
||||||
|
* If set to 0 (zero), creates an IPv4 socket which subsequently only allows
|
||||||
|
* IPv4 communication
|
||||||
|
* If set to anything else (default), creates an IPv6 socket which allows both IPv4 AND
|
||||||
|
* IPv6 communication
|
||||||
|
*/
|
||||||
|
uint8_t ipv6enabled;
|
||||||
|
|
||||||
|
/* Set to 1 to disable udp support. (default: 0)
|
||||||
|
This will force Tox to use TCP only which may slow things down.
|
||||||
|
Disabling udp support is necessary when using anonymous proxies or Tor.*/
|
||||||
|
uint8_t udp_disabled;
|
||||||
|
|
||||||
|
/* Enable proxy support. (only basic TCP socks5 proxy currently supported.) (default: 0 (disabled))*/
|
||||||
|
uint8_t proxy_enabled;
|
||||||
|
char proxy_address[256]; /* Proxy ip or domain in NULL terminated string format. */
|
||||||
|
uint16_t proxy_port; /* Proxy port: in host byte order. */
|
||||||
|
} Tox_Options;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Run this function at startup.
|
* Run this function at startup.
|
||||||
*
|
*
|
||||||
* Initializes a tox structure
|
* Options are some options that can be passed to the Tox instance (see above struct).
|
||||||
* The type of communication socket depends on ipv6enabled:
|
|
||||||
* If set to 0 (zero), creates an IPv4 socket which subsequently only allows
|
|
||||||
* IPv4 communication
|
|
||||||
* If set to anything else, creates an IPv6 socket which allows both IPv4 AND
|
|
||||||
* IPv6 communication
|
|
||||||
*
|
*
|
||||||
|
* If options is NULL, tox_new() will use default settings.
|
||||||
|
*
|
||||||
|
* Initializes a tox structure
|
||||||
* return allocated instance of tox on success.
|
* return allocated instance of tox on success.
|
||||||
* return 0 if there are problems.
|
* return NULL on failure.
|
||||||
*/
|
*/
|
||||||
Tox *tox_new(uint8_t ipv6enabled);
|
Tox *tox_new(Tox_Options *options);
|
||||||
|
|
||||||
/* Run this before closing shop.
|
/* Run this before closing shop.
|
||||||
* Free all datastructures. */
|
* Free all datastructures. */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user