summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/onion_client.c3
-rw-r--r--toxcore/tox.c28
-rw-r--r--toxcore/tox.h35
3 files changed, 54 insertions, 12 deletions
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. */