summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto_tests/tox_test.c8
-rw-r--r--testing/nTox.c4
-rw-r--r--testing/tox_sync.c2
-rw-r--r--toxcore/onion_client.c3
-rw-r--r--toxcore/tox.c28
-rw-r--r--toxcore/tox.h35
6 files changed, 61 insertions, 19 deletions
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index f765fcd3..04dd3c22 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -124,9 +124,9 @@ void write_file(Tox *m, int friendnumber, uint8_t filenumber, const uint8_t *dat
124START_TEST(test_few_clients) 124START_TEST(test_few_clients)
125{ 125{
126 long long unsigned int con_time, cur_time = time(NULL); 126 long long unsigned int con_time, cur_time = time(NULL);
127 Tox *tox1 = tox_new(TOX_ENABLE_IPV6_DEFAULT); 127 Tox *tox1 = tox_new(0);
128 Tox *tox2 = tox_new(TOX_ENABLE_IPV6_DEFAULT); 128 Tox *tox2 = tox_new(0);
129 Tox *tox3 = tox_new(TOX_ENABLE_IPV6_DEFAULT); 129 Tox *tox3 = tox_new(0);
130 ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances"); 130 ck_assert_msg(tox1 || tox2 || tox3, "Failed to create 3 tox instances");
131 uint32_t to_compare = 974536; 131 uint32_t to_compare = 974536;
132 tox_callback_friend_request(tox2, accept_friend_request, &to_compare); 132 tox_callback_friend_request(tox2, accept_friend_request, &to_compare);
@@ -302,7 +302,7 @@ START_TEST(test_many_clients)
302 uint32_t to_comp = 974536; 302 uint32_t to_comp = 974536;
303 303
304 for (i = 0; i < NUM_TOXES; ++i) { 304 for (i = 0; i < NUM_TOXES; ++i) {
305 toxes[i] = tox_new(TOX_ENABLE_IPV6_DEFAULT); 305 toxes[i] = tox_new(0);
306 ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); 306 ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
307 tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp); 307 tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp);
308 } 308 }
diff --git a/testing/nTox.c b/testing/nTox.c
index 971a2571..53cbbb5d 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -1225,7 +1225,7 @@ int main(int argc, char *argv[])
1225 if (!strcmp(argv[argc - 2], "-f")) 1225 if (!strcmp(argv[argc - 2], "-f"))
1226 filename = argv[argc - 1]; 1226 filename = argv[argc - 1];
1227 1227
1228 m = tox_new(ipv6enabled); 1228 m = tox_new(0);
1229 1229
1230 if ( !m ) { 1230 if ( !m ) {
1231 fputs("Failed to allocate Messenger datastructure", stderr); 1231 fputs("Failed to allocate Messenger datastructure", stderr);
@@ -1258,7 +1258,6 @@ int main(int argc, char *argv[])
1258 uint16_t port = htons(atoi(argv[argvoffset + 2])); 1258 uint16_t port = htons(atoi(argv[argvoffset + 2]));
1259 unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]); 1259 unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
1260 int res = tox_bootstrap_from_address(m, argv[argvoffset + 1], ipv6enabled, port, binary_string); 1260 int res = tox_bootstrap_from_address(m, argv[argvoffset + 1], ipv6enabled, port, binary_string);
1261 free(binary_string);
1262 1261
1263 if (!res) { 1262 if (!res) {
1264 printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]); 1263 printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]);
@@ -1319,6 +1318,7 @@ int main(int argc, char *argv[])
1319 } 1318 }
1320 } 1319 }
1321 1320
1321 free(binary_string);
1322 tox_kill(m); 1322 tox_kill(m);
1323 endwin(); 1323 endwin();
1324 return 0; 1324 return 0;
diff --git a/testing/tox_sync.c b/testing/tox_sync.c
index 523f2c56..206e613f 100644
--- a/testing/tox_sync.c
+++ b/testing/tox_sync.c
@@ -214,7 +214,7 @@ int main(int argc, char *argv[])
214 exit(0); 214 exit(0);
215 } 215 }
216 216
217 Tox *tox = tox_new(ipv6enabled); 217 Tox *tox = tox_new(0);
218 tox_callback_file_data(tox, write_file, NULL); 218 tox_callback_file_data(tox, write_file, NULL);
219 tox_callback_file_control(tox, file_print_control, NULL); 219 tox_callback_file_control(tox, file_print_control, NULL);
220 tox_callback_file_send_request(tox, file_request_accept, NULL); 220 tox_callback_file_send_request(tox, file_request_accept, NULL);
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index 424711d5..24f41e6f 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -40,6 +40,9 @@
40 */ 40 */
41int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *client_id) 41int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t *client_id)
42{ 42{
43 if (ip_port.ip.family != AF_INET && ip_port.ip.family != AF_INET6)
44 return -1;
45
43 unsigned int i; 46 unsigned int i;
44 47
45 for (i = 0; i < MAX_PATH_NODES; ++i) { 48 for (i = 0; i < MAX_PATH_NODES; ++i) {
diff --git a/toxcore/tox.c b/toxcore/tox.c
index d352f672..4b9cff8e 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -815,12 +815,32 @@ uint32_t tox_do_interval(Tox *tox)
815 * return allocated instance of tox on success. 815 * return allocated instance of tox on success.
816 * return 0 if there are problems. 816 * return 0 if there are problems.
817 */ 817 */
818Tox *tox_new(uint8_t ipv6enabled) 818Tox *tox_new(Tox_Options *options)
819{ 819{
820 LOGGER_INIT(LOGGER_OUTPUT_FILE, LOGGER_LEVEL); 820 LOGGER_INIT(LOGGER_OUTPUT_FILE, LOGGER_LEVEL);
821 Messenger_Options options = {0}; 821 Messenger_Options m_options = {0};
822 options.ipv6enabled = ipv6enabled; 822
823 return new_messenger(&options); 823 if (options == NULL) {
824 m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT;
825 } else {
826 m_options.ipv6enabled = options->ipv6enabled;
827 m_options.udp_disabled = options->udp_disabled;
828 m_options.proxy_enabled = options->proxy_enabled;
829
830 if (m_options.proxy_enabled) {
831 ip_init(&m_options.proxy_info.ip_port.ip, m_options.ipv6enabled);
832
833 if (m_options.ipv6enabled)
834 m_options.proxy_info.ip_port.ip.family = AF_UNSPEC;
835
836 if (!addr_resolve_or_parse_ip(options->proxy_address, &m_options.proxy_info.ip_port.ip, NULL))
837 return NULL;
838
839 m_options.proxy_info.ip_port.port = htons(options->proxy_port);
840 }
841 }
842
843 return new_messenger(&m_options);
824} 844}
825 845
826/* Run this before closing shop. 846/* Run this before closing shop.
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 8caa01e0..6cad6b10 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -622,20 +622,39 @@ int tox_bootstrap_from_address(Tox *tox, const char *address, uint8_t ipv6enable
622 */ 622 */
623int tox_isconnected(const Tox *tox); 623int tox_isconnected(const Tox *tox);
624 624
625typedef struct {
626 /*
627 * The type of UDP socket created depends on ipv6enabled:
628 * If set to 0 (zero), creates an IPv4 socket which subsequently only allows
629 * IPv4 communication
630 * If set to anything else (default), creates an IPv6 socket which allows both IPv4 AND
631 * IPv6 communication
632 */
633 uint8_t ipv6enabled;
634
635 /* Set to 1 to disable udp support. (default: 0)
636 This will force Tox to use TCP only which may slow things down.
637 Disabling udp support is necessary when using anonymous proxies or Tor.*/
638 uint8_t udp_disabled;
639
640 /* Enable proxy support. (only basic TCP socks5 proxy currently supported.) (default: 0 (disabled))*/
641 uint8_t proxy_enabled;
642 char proxy_address[256]; /* Proxy ip or domain in NULL terminated string format. */
643 uint16_t proxy_port; /* Proxy port: in host byte order. */
644} Tox_Options;
645
625/* 646/*
626 * Run this function at startup. 647 * Run this function at startup.
627 * 648 *
628 * Initializes a tox structure 649 * Options are some options that can be passed to the Tox instance (see above struct).
629 * The type of communication socket depends on ipv6enabled:
630 * If set to 0 (zero), creates an IPv4 socket which subsequently only allows
631 * IPv4 communication
632 * If set to anything else, creates an IPv6 socket which allows both IPv4 AND
633 * IPv6 communication
634 * 650 *
651 * If options is NULL, tox_new() will use default settings.
652 *
653 * Initializes a tox structure
635 * return allocated instance of tox on success. 654 * return allocated instance of tox on success.
636 * return 0 if there are problems. 655 * return NULL on failure.
637 */ 656 */
638Tox *tox_new(uint8_t ipv6enabled); 657Tox *tox_new(Tox_Options *options);
639 658
640/* Run this before closing shop. 659/* Run this before closing shop.
641 * Free all datastructures. */ 660 * Free all datastructures. */