diff options
author | Diadlo <polsha3@gmail.com> | 2017-01-07 11:28:53 +0300 |
---|---|---|
committer | Diadlo <polsha3@gmail.com> | 2017-02-26 23:16:16 +0300 |
commit | b19a9e54643eceaa52e71c0f38fa2ecae5a6809e (patch) | |
tree | 4c6fff0a086988ab21636e88dbf65c2e40a76a67 /toxcore/DHT.c | |
parent | b2d04eae9d9b76523b877a9e5efd5989f83b143d (diff) |
Add part of platform-independent network API implementation
socket -> net_socket
htons -> net_htons
htonl -> net_htonl
connect -> net_connect
sendto -> net_sendto_ip4
getaddrinfo -> net_getipport
sa_family_t -> Family
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r-- | toxcore/DHT.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 7064d3d5..9cfe1ae1 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c | |||
@@ -541,9 +541,9 @@ static int client_or_ip_port_in_list(Logger *log, Client_data *list, uint16_t le | |||
541 | char ip_str[IP_NTOA_LEN]; | 541 | char ip_str[IP_NTOA_LEN]; |
542 | LOGGER_TRACE(log, "coipil[%u]: switching ipv4 from %s:%u to %s:%u", i, | 542 | LOGGER_TRACE(log, "coipil[%u]: switching ipv4 from %s:%u to %s:%u", i, |
543 | ip_ntoa(&list[i].assoc4.ip_port.ip, ip_str, sizeof(ip_str)), | 543 | ip_ntoa(&list[i].assoc4.ip_port.ip, ip_str, sizeof(ip_str)), |
544 | ntohs(list[i].assoc4.ip_port.port), | 544 | net_ntohs(list[i].assoc4.ip_port.port), |
545 | ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), | 545 | ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), |
546 | ntohs(ip_port.port)); | 546 | net_ntohs(ip_port.port)); |
547 | } | 547 | } |
548 | 548 | ||
549 | if (LAN_ip(list[i].assoc4.ip_port.ip) != 0 && LAN_ip(ip_port.ip) == 0) { | 549 | if (LAN_ip(list[i].assoc4.ip_port.ip) != 0 && LAN_ip(ip_port.ip) == 0) { |
@@ -558,9 +558,9 @@ static int client_or_ip_port_in_list(Logger *log, Client_data *list, uint16_t le | |||
558 | char ip_str[IP_NTOA_LEN]; | 558 | char ip_str[IP_NTOA_LEN]; |
559 | LOGGER_TRACE(log, "coipil[%u]: switching ipv6 from %s:%u to %s:%u", i, | 559 | LOGGER_TRACE(log, "coipil[%u]: switching ipv6 from %s:%u to %s:%u", i, |
560 | ip_ntoa(&list[i].assoc6.ip_port.ip, ip_str, sizeof(ip_str)), | 560 | ip_ntoa(&list[i].assoc6.ip_port.ip, ip_str, sizeof(ip_str)), |
561 | ntohs(list[i].assoc6.ip_port.port), | 561 | net_ntohs(list[i].assoc6.ip_port.port), |
562 | ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), | 562 | ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), |
563 | ntohs(ip_port.port)); | 563 | net_ntohs(ip_port.port)); |
564 | } | 564 | } |
565 | 565 | ||
566 | if (LAN_ip(list[i].assoc6.ip_port.ip) != 0 && LAN_ip(ip_port.ip) == 0) { | 566 | if (LAN_ip(list[i].assoc6.ip_port.ip) != 0 && LAN_ip(ip_port.ip) == 0) { |
@@ -687,7 +687,7 @@ static uint8_t hardening_correct(const Hardening *h) | |||
687 | * helper for get_close_nodes(). argument list is a monster :D | 687 | * helper for get_close_nodes(). argument list is a monster :D |
688 | */ | 688 | */ |
689 | static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_list, | 689 | static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_list, |
690 | sa_family_t sa_family, const Client_data *client_list, uint32_t client_list_length, | 690 | Family sa_family, const Client_data *client_list, uint32_t client_list_length, |
691 | uint32_t *num_nodes_ptr, uint8_t is_LAN, uint8_t want_good) | 691 | uint32_t *num_nodes_ptr, uint8_t is_LAN, uint8_t want_good) |
692 | { | 692 | { |
693 | if ((sa_family != AF_INET) && (sa_family != AF_INET6) && (sa_family != 0)) { | 693 | if ((sa_family != AF_INET) && (sa_family != AF_INET6) && (sa_family != 0)) { |
@@ -758,7 +758,7 @@ static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_ | |||
758 | * want_good : do we want only good nodes as checked with the hardening returned or not? | 758 | * want_good : do we want only good nodes as checked with the hardening returned or not? |
759 | */ | 759 | */ |
760 | static int get_somewhat_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, | 760 | static int get_somewhat_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, |
761 | sa_family_t sa_family, uint8_t is_LAN, uint8_t want_good) | 761 | Family sa_family, uint8_t is_LAN, uint8_t want_good) |
762 | { | 762 | { |
763 | uint32_t num_nodes = 0, i; | 763 | uint32_t num_nodes = 0, i; |
764 | get_close_nodes_inner(public_key, nodes_list, sa_family, | 764 | get_close_nodes_inner(public_key, nodes_list, sa_family, |
@@ -784,7 +784,7 @@ static int get_somewhat_close_nodes(const DHT *dht, const uint8_t *public_key, N | |||
784 | return num_nodes; | 784 | return num_nodes; |
785 | } | 785 | } |
786 | 786 | ||
787 | int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, sa_family_t sa_family, | 787 | int get_close_nodes(const DHT *dht, const uint8_t *public_key, Node_format *nodes_list, Family sa_family, |
788 | uint8_t is_LAN, uint8_t want_good) | 788 | uint8_t is_LAN, uint8_t want_good) |
789 | { | 789 | { |
790 | memset(nodes_list, 0, MAX_SENT_NODES * sizeof(Node_format)); | 790 | memset(nodes_list, 0, MAX_SENT_NODES * sizeof(Node_format)); |
@@ -2093,7 +2093,7 @@ static uint16_t NAT_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t | |||
2093 | 2093 | ||
2094 | for (i = 0; i < len; ++i) { | 2094 | for (i = 0; i < len; ++i) { |
2095 | if (ip_equal(&ip_portlist[i].ip, &ip)) { | 2095 | if (ip_equal(&ip_portlist[i].ip, &ip)) { |
2096 | portlist[num] = ntohs(ip_portlist[i].port); | 2096 | portlist[num] = net_ntohs(ip_portlist[i].port); |
2097 | ++num; | 2097 | ++num; |
2098 | } | 2098 | } |
2099 | } | 2099 | } |
@@ -2124,7 +2124,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, | |||
2124 | if (i == numports) { /* If all ports are the same, only try that one port. */ | 2124 | if (i == numports) { /* If all ports are the same, only try that one port. */ |
2125 | IP_Port pinging; | 2125 | IP_Port pinging; |
2126 | ip_copy(&pinging.ip, &ip); | 2126 | ip_copy(&pinging.ip, &ip); |
2127 | pinging.port = htons(firstport); | 2127 | pinging.port = net_htons(firstport); |
2128 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key); | 2128 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key); |
2129 | } else { | 2129 | } else { |
2130 | for (i = dht->friends_list[friend_num].nat.punching_index; i != top; ++i) { | 2130 | for (i = dht->friends_list[friend_num].nat.punching_index; i != top; ++i) { |
@@ -2132,7 +2132,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, | |||
2132 | uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); | 2132 | uint16_t port = port_list[(i / 2) % numports] + (i / (2 * numports)) * ((i % 2) ? -1 : 1); |
2133 | IP_Port pinging; | 2133 | IP_Port pinging; |
2134 | ip_copy(&pinging.ip, &ip); | 2134 | ip_copy(&pinging.ip, &ip); |
2135 | pinging.port = htons(port); | 2135 | pinging.port = net_htons(port); |
2136 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key); | 2136 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key); |
2137 | } | 2137 | } |
2138 | 2138 | ||
@@ -2146,7 +2146,7 @@ static void punch_holes(DHT *dht, IP ip, uint16_t *port_list, uint16_t numports, | |||
2146 | ip_copy(&pinging.ip, &ip); | 2146 | ip_copy(&pinging.ip, &ip); |
2147 | 2147 | ||
2148 | for (i = dht->friends_list[friend_num].nat.punching_index2; i != top; ++i) { | 2148 | for (i = dht->friends_list[friend_num].nat.punching_index2; i != top; ++i) { |
2149 | pinging.port = htons(port + i); | 2149 | pinging.port = net_htons(port + i); |
2150 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key); | 2150 | send_ping_request(dht->ping, pinging, dht->friends_list[friend_num].public_key); |
2151 | } | 2151 | } |
2152 | 2152 | ||
@@ -2262,7 +2262,7 @@ static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto, | |||
2262 | } | 2262 | } |
2263 | 2263 | ||
2264 | /* TODO(irungentoo): improve */ | 2264 | /* TODO(irungentoo): improve */ |
2265 | static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *public_key, sa_family_t sa_family) | 2265 | static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *public_key, Family sa_family) |
2266 | { | 2266 | { |
2267 | uint32_t i; | 2267 | uint32_t i; |
2268 | 2268 | ||
@@ -2393,7 +2393,7 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_ | |||
2393 | /* Return a random node from all the nodes we are connected to. | 2393 | /* Return a random node from all the nodes we are connected to. |
2394 | * TODO(irungentoo): improve this function. | 2394 | * TODO(irungentoo): improve this function. |
2395 | */ | 2395 | */ |
2396 | static Node_format random_node(DHT *dht, sa_family_t sa_family) | 2396 | static Node_format random_node(DHT *dht, Family sa_family) |
2397 | { | 2397 | { |
2398 | uint8_t id[CRYPTO_PUBLIC_KEY_SIZE]; | 2398 | uint8_t id[CRYPTO_PUBLIC_KEY_SIZE]; |
2399 | uint32_t i; | 2399 | uint32_t i; |
@@ -2499,7 +2499,7 @@ static void do_hardening(DHT *dht) | |||
2499 | 2499 | ||
2500 | for (i = 0; i < LCLIENT_LIST * 2; ++i) { | 2500 | for (i = 0; i < LCLIENT_LIST * 2; ++i) { |
2501 | IPPTsPng *cur_iptspng; | 2501 | IPPTsPng *cur_iptspng; |
2502 | sa_family_t sa_family; | 2502 | Family sa_family; |
2503 | uint8_t *public_key = dht->close_clientlist[i / 2].public_key; | 2503 | uint8_t *public_key = dht->close_clientlist[i / 2].public_key; |
2504 | 2504 | ||
2505 | if (i % 2 == 0) { | 2505 | if (i % 2 == 0) { |