summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-09-20 12:19:21 -0400
committerirungentoo <irungentoo@gmail.com>2014-09-20 12:19:21 -0400
commitfcc6d43cf25ee45d732e2acbc92caab6e153ca78 (patch)
tree15342b6793a3f6a81acef840dd08f25b9ff31268 /toxcore
parent53ce4f393b9e76b85db4453c525b7bedbf778c1c (diff)
Prevent core from doing DNS requests when UDP is disabled.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/tox.c47
1 files changed, 27 insertions, 20 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 602432cb..c1851f06 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -808,33 +808,40 @@ uint64_t tox_file_data_remaining(const Tox *tox, int32_t friendnumber, uint8_t f
808int tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key) 808int tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key)
809{ 809{
810 Messenger *m = tox; 810 Messenger *m = tox;
811 IP_Port ip_port_v64; 811 IP_Port ip_port, ip_port_v4;
812 IP *ip_extra = NULL; 812 if (!addr_parse_ip(address, &ip_port.ip)) {
813 IP_Port ip_port_v4; 813 if (m->options.udp_disabled) /* Disable DNS when udp is disabled. */
814 ip_init(&ip_port_v64.ip, m->options.ipv6enabled); 814 return 0;
815 815
816 if (m->options.ipv6enabled) { 816 IP *ip_extra = NULL;
817 /* setup for getting BOTH: an IPv6 AND an IPv4 address */ 817 ip_init(&ip_port.ip, m->options.ipv6enabled);
818 ip_port_v64.ip.family = AF_UNSPEC; 818
819 ip_reset(&ip_port_v4.ip); 819 if (m->options.ipv6enabled) {
820 ip_extra = &ip_port_v4.ip; 820 /* setup for getting BOTH: an IPv6 AND an IPv4 address */
821 } 821 ip_port.ip.family = AF_UNSPEC;
822 ip_reset(&ip_port_v4.ip);
823 ip_extra = &ip_port_v4.ip;
824 }
822 825
823 if (addr_resolve_or_parse_ip(address, &ip_port_v64.ip, ip_extra)) { 826 if (!addr_resolve(address, &ip_port.ip, ip_extra))
824 ip_port_v64.port = htons(port); 827 return 0;
825 add_tcp_relay(m->net_crypto, ip_port_v64, public_key);
826 onion_add_path_node(m->onion_c, ip_port_v64, public_key); //TODO: move this
827 return 1;
828 } else {
829 return 0;
830 } 828 }
829
830 ip_port.port = htons(port);
831 add_tcp_relay(m->net_crypto, ip_port, public_key);
832 onion_add_path_node(m->onion_c, ip_port, public_key); //TODO: move this
833 return 1;
831} 834}
832 835
833int tox_bootstrap_from_address(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key) 836int tox_bootstrap_from_address(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key)
834{ 837{
835 Messenger *m = tox; 838 Messenger *m = tox;
836 tox_add_tcp_relay(tox, address, port, public_key); 839 int ret = tox_add_tcp_relay(tox, address, port, public_key);
837 return DHT_bootstrap_from_address(m->dht, address, m->options.ipv6enabled, htons(port), public_key); 840 if (m->options.udp_disabled) {
841 return ret;
842 } else { /* DHT only works on UDP. */
843 return DHT_bootstrap_from_address(m->dht, address, m->options.ipv6enabled, htons(port), public_key);
844 }
838} 845}
839 846
840/* return 0 if we are not connected to the DHT. 847/* return 0 if we are not connected to the DHT.