summaryrefslogtreecommitdiff
path: root/toxcore/net_crypto.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/net_crypto.c')
-rw-r--r--toxcore/net_crypto.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index b9d8a360..5477fea7 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -573,7 +573,7 @@ static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, IP_Por
573 return -1; 573 return -1;
574 } 574 }
575 575
576 if (ip_port.ip.family == TOX_AF_INET) { 576 if (net_family_is_ipv4(ip_port.ip.family)) {
577 if (!ipport_equal(&ip_port, &conn->ip_portv4) && ip_is_lan(conn->ip_portv4.ip) != 0) { 577 if (!ipport_equal(&ip_port, &conn->ip_portv4) && ip_is_lan(conn->ip_portv4.ip) != 0) {
578 if (!bs_list_add(&c->ip_port_list, (uint8_t *)&ip_port, crypt_connection_id)) { 578 if (!bs_list_add(&c->ip_port_list, (uint8_t *)&ip_port, crypt_connection_id)) {
579 return -1; 579 return -1;
@@ -583,7 +583,7 @@ static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, IP_Por
583 conn->ip_portv4 = ip_port; 583 conn->ip_portv4 = ip_port;
584 return 0; 584 return 0;
585 } 585 }
586 } else if (ip_port.ip.family == TOX_AF_INET6) { 586 } else if (net_family_is_ipv6(ip_port.ip.family)) {
587 if (!ipport_equal(&ip_port, &conn->ip_portv6)) { 587 if (!ipport_equal(&ip_port, &conn->ip_portv6)) {
588 if (!bs_list_add(&c->ip_port_list, (uint8_t *)&ip_port, crypt_connection_id)) { 588 if (!bs_list_add(&c->ip_port_list, (uint8_t *)&ip_port, crypt_connection_id)) {
589 return -1; 589 return -1;
@@ -605,7 +605,7 @@ static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, IP_Por
605 */ 605 */
606static IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id) 606static IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id)
607{ 607{
608 const IP_Port empty = {{0}}; 608 const IP_Port empty = {{{0}}};
609 609
610 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 610 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
611 611
@@ -628,11 +628,11 @@ static IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id)
628 return conn->ip_portv4; 628 return conn->ip_portv4;
629 } 629 }
630 630
631 if (v6 && conn->ip_portv6.ip.family == TOX_AF_INET6) { 631 if (v6 && net_family_is_ipv6(conn->ip_portv6.ip.family)) {
632 return conn->ip_portv6; 632 return conn->ip_portv6;
633 } 633 }
634 634
635 if (conn->ip_portv4.ip.family == TOX_AF_INET) { 635 if (net_family_is_ipv4(conn->ip_portv4.ip.family)) {
636 return conn->ip_portv4; 636 return conn->ip_portv4;
637 } 637 }
638 638
@@ -659,7 +659,7 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t
659 IP_Port ip_port = return_ip_port_connection(c, crypt_connection_id); 659 IP_Port ip_port = return_ip_port_connection(c, crypt_connection_id);
660 660
661 // TODO(irungentoo): on bad networks, direct connections might not last indefinitely. 661 // TODO(irungentoo): on bad networks, direct connections might not last indefinitely.
662 if (ip_port.ip.family != 0) { 662 if (!net_family_is_unspec(ip_port.ip.family)) {
663 bool direct_connected = 0; 663 bool direct_connected = 0;
664 crypto_connection_status(c, crypt_connection_id, &direct_connected, nullptr); 664 crypto_connection_status(c, crypt_connection_id, &direct_connected, nullptr);
665 665
@@ -1835,12 +1835,12 @@ static int crypto_connection_add_source(Net_Crypto *c, int crypt_connection_id,
1835 return -1; 1835 return -1;
1836 } 1836 }
1837 1837
1838 if (source.ip.family == TOX_AF_INET || source.ip.family == TOX_AF_INET6) { 1838 if (net_family_is_ipv4(source.ip.family) || net_family_is_ipv6(source.ip.family)) {
1839 if (add_ip_port_connection(c, crypt_connection_id, source) != 0) { 1839 if (add_ip_port_connection(c, crypt_connection_id, source) != 0) {
1840 return -1; 1840 return -1;
1841 } 1841 }
1842 1842
1843 if (source.ip.family == TOX_AF_INET) { 1843 if (net_family_is_ipv4(source.ip.family)) {
1844 conn->direct_lastrecv_timev4 = unix_time(); 1844 conn->direct_lastrecv_timev4 = unix_time();
1845 } else { 1845 } else {
1846 conn->direct_lastrecv_timev6 = unix_time(); 1846 conn->direct_lastrecv_timev6 = unix_time();
@@ -1849,7 +1849,7 @@ static int crypto_connection_add_source(Net_Crypto *c, int crypt_connection_id,
1849 return 0; 1849 return 0;
1850 } 1850 }
1851 1851
1852 if (source.ip.family == TCP_FAMILY) { 1852 if (net_family_is_tcp_family(source.ip.family)) {
1853 if (add_tcp_number_relay_connection(c->tcp_c, conn->connection_number_tcp, source.ip.ip.v6.uint32[0]) == 0) { 1853 if (add_tcp_number_relay_connection(c->tcp_c, conn->connection_number_tcp, source.ip.ip.v6.uint32[0]) == 0) {
1854 return 1; 1854 return 1;
1855 } 1855 }
@@ -2065,13 +2065,13 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port,
2065 2065
2066 if (add_ip_port_connection(c, crypt_connection_id, ip_port) == 0) { 2066 if (add_ip_port_connection(c, crypt_connection_id, ip_port) == 0) {
2067 if (connected) { 2067 if (connected) {
2068 if (ip_port.ip.family == TOX_AF_INET) { 2068 if (net_family_is_ipv4(ip_port.ip.family)) {
2069 conn->direct_lastrecv_timev4 = unix_time(); 2069 conn->direct_lastrecv_timev4 = unix_time();
2070 } else { 2070 } else {
2071 conn->direct_lastrecv_timev6 = unix_time(); 2071 conn->direct_lastrecv_timev6 = unix_time();
2072 } 2072 }
2073 } else { 2073 } else {
2074 if (ip_port.ip.family == TOX_AF_INET) { 2074 if (net_family_is_ipv4(ip_port.ip.family)) {
2075 conn->direct_lastrecv_timev4 = 0; 2075 conn->direct_lastrecv_timev4 = 0;
2076 } else { 2076 } else {
2077 conn->direct_lastrecv_timev6 = 0; 2077 conn->direct_lastrecv_timev6 = 0;
@@ -2133,7 +2133,7 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, unsigned in
2133 if (data[0] == NET_PACKET_CRYPTO_HS) { 2133 if (data[0] == NET_PACKET_CRYPTO_HS) {
2134 IP_Port source; 2134 IP_Port source;
2135 source.port = 0; 2135 source.port = 0;
2136 source.ip.family = TCP_FAMILY; 2136 source.ip.family = net_family_tcp_family;
2137 source.ip.ip.v6.uint32[0] = tcp_connections_number; 2137 source.ip.ip.v6.uint32[0] = tcp_connections_number;
2138 2138
2139 if (handle_new_connection_handshake(c, source, data, length, userdata) != 0) { 2139 if (handle_new_connection_handshake(c, source, data, length, userdata) != 0) {
@@ -2411,7 +2411,7 @@ static int udp_handle_packet(void *object, IP_Port source, const uint8_t *packet
2411 2411
2412 pthread_mutex_lock(&conn->mutex); 2412 pthread_mutex_lock(&conn->mutex);
2413 2413
2414 if (source.ip.family == TOX_AF_INET) { 2414 if (net_family_is_ipv4(source.ip.family)) {
2415 conn->direct_lastrecv_timev4 = unix_time(); 2415 conn->direct_lastrecv_timev4 = unix_time();
2416 } else { 2416 } else {
2417 conn->direct_lastrecv_timev6 = unix_time(); 2417 conn->direct_lastrecv_timev6 = unix_time();