summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-09-02 19:38:44 -0400
committerirungentoo <irungentoo@gmail.com>2014-09-02 19:38:44 -0400
commit01203a22727ffb33bdeca702381e1d86e00bde2b (patch)
tree733e8c997cf1da7f7e308ed3fbeb0e4367198a43 /toxcore
parent6d680274f608130b4d005a43aaa542b6d9a9406e (diff)
Expose the tox_add_tcp_relay() function in the public api.
Clients can use this function to make Tox connect to user specified TCP relays.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/tox.c17
-rw-r--r--toxcore/tox.h7
2 files changed, 17 insertions, 7 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c
index ca87bbe1..d9d88105 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -729,17 +729,20 @@ uint64_t tox_file_data_remaining(const Tox *tox, int32_t friendnumber, uint8_t f
729 729
730/***************END OF FILE SENDING FUNCTIONS******************/ 730/***************END OF FILE SENDING FUNCTIONS******************/
731 731
732/* TODO: expose this properly. */ 732/* Like tox_bootstrap_from_address but for TCP relays only.
733static int tox_add_tcp_relay(Tox *tox, const char *address, uint8_t ipv6enabled, uint16_t port, 733 *
734 const uint8_t *public_key) 734 * return 0 on failure.
735 * return 1 on success.
736 */
737int tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key)
735{ 738{
736 Messenger *m = tox; 739 Messenger *m = tox;
737 IP_Port ip_port_v64; 740 IP_Port ip_port_v64;
738 IP *ip_extra = NULL; 741 IP *ip_extra = NULL;
739 IP_Port ip_port_v4; 742 IP_Port ip_port_v4;
740 ip_init(&ip_port_v64.ip, ipv6enabled); 743 ip_init(&ip_port_v64.ip, m->options.ipv6enabled);
741 744
742 if (ipv6enabled) { 745 if (m->options.ipv6enabled) {
743 /* setup for getting BOTH: an IPv6 AND an IPv4 address */ 746 /* setup for getting BOTH: an IPv6 AND an IPv4 address */
744 ip_port_v64.ip.family = AF_UNSPEC; 747 ip_port_v64.ip.family = AF_UNSPEC;
745 ip_reset(&ip_port_v4.ip); 748 ip_reset(&ip_port_v4.ip);
@@ -747,7 +750,7 @@ static int tox_add_tcp_relay(Tox *tox, const char *address, uint8_t ipv6enabled,
747 } 750 }
748 751
749 if (addr_resolve_or_parse_ip(address, &ip_port_v64.ip, ip_extra)) { 752 if (addr_resolve_or_parse_ip(address, &ip_port_v64.ip, ip_extra)) {
750 ip_port_v64.port = port; 753 ip_port_v64.port = htons(port);
751 add_tcp_relay(m->net_crypto, ip_port_v64, public_key); 754 add_tcp_relay(m->net_crypto, ip_port_v64, public_key);
752 onion_add_path_node(m->onion_c, ip_port_v64, public_key); //TODO: move this 755 onion_add_path_node(m->onion_c, ip_port_v64, public_key); //TODO: move this
753 return 1; 756 return 1;
@@ -759,7 +762,7 @@ static int tox_add_tcp_relay(Tox *tox, const char *address, uint8_t ipv6enabled,
759int tox_bootstrap_from_address(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key) 762int tox_bootstrap_from_address(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key)
760{ 763{
761 Messenger *m = tox; 764 Messenger *m = tox;
762 tox_add_tcp_relay(tox, address, m->options.ipv6enabled, htons(port), public_key); 765 tox_add_tcp_relay(tox, address, port, public_key);
763 return DHT_bootstrap_from_address(m->dht, address, m->options.ipv6enabled, htons(port), public_key); 766 return DHT_bootstrap_from_address(m->dht, address, m->options.ipv6enabled, htons(port), public_key);
764} 767}
765 768
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 550600f9..99ae0a58 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -601,6 +601,13 @@ uint64_t tox_file_data_remaining(const Tox *tox, int32_t friendnumber, uint8_t f
601 */ 601 */
602int tox_bootstrap_from_address(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key); 602int tox_bootstrap_from_address(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key);
603 603
604/* Like tox_bootstrap_from_address but for TCP relays only.
605 *
606 * return 0 on failure.
607 * return 1 on success.
608 */
609int tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key);
610
604/* return 0 if we are not connected to the DHT. 611/* return 0 if we are not connected to the DHT.
605 * return 1 if we are. 612 * return 1 if we are.
606 */ 613 */