summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
diff options
context:
space:
mode:
authorDiadlo <polsha3@gmail.com>2017-03-02 23:15:51 +0300
committerDiadlo <polsha3@gmail.com>2017-08-24 20:09:08 +0300
commit66b8a7685e8fdecd6104f01f840f5d792ce1e041 (patch)
tree7c65281aefeb21c55ba422ff7d9587675eeb7070 /toxcore/DHT.c
parent8f19c926c0d5231ede61a831050664103e54000e (diff)
AF_INET -> TOX_AF_INET
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r--toxcore/DHT.c64
1 files changed, 32 insertions, 32 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index e12c4d64..193cb632 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -258,9 +258,9 @@ int handle_request(const uint8_t *self_public_key, const uint8_t *self_secret_ke
258 258
259void to_net_family(IP *ip) 259void to_net_family(IP *ip)
260{ 260{
261 if (ip->family == AF_INET) { 261 if (ip->family == TOX_AF_INET) {
262 ip->family = TOX_AF_INET; 262 ip->family = TOX_AF_INET;
263 } else if (ip->family == AF_INET6) { 263 } else if (ip->family == TOX_AF_INET6) {
264 ip->family = TOX_AF_INET6; 264 ip->family = TOX_AF_INET6;
265 } 265 }
266} 266}
@@ -268,12 +268,12 @@ void to_net_family(IP *ip)
268int to_host_family(IP *ip) 268int to_host_family(IP *ip)
269{ 269{
270 if (ip->family == TOX_AF_INET) { 270 if (ip->family == TOX_AF_INET) {
271 ip->family = AF_INET; 271 ip->family = TOX_AF_INET;
272 return 0; 272 return 0;
273 } 273 }
274 274
275 if (ip->family == TOX_AF_INET6) { 275 if (ip->family == TOX_AF_INET6) {
276 ip->family = AF_INET6; 276 ip->family = TOX_AF_INET6;
277 return 0; 277 return 0;
278 } 278 }
279 279
@@ -289,11 +289,11 @@ int to_host_family(IP *ip)
289int packed_node_size(uint8_t ip_family) 289int packed_node_size(uint8_t ip_family)
290{ 290{
291 switch (ip_family) { 291 switch (ip_family) {
292 case AF_INET: 292 case TOX_AF_INET:
293 case TCP_INET: 293 case TCP_INET:
294 return PACKED_NODE_SIZE_IP4; 294 return PACKED_NODE_SIZE_IP4;
295 295
296 case AF_INET6: 296 case TOX_AF_INET6:
297 case TCP_INET6: 297 case TCP_INET6:
298 return PACKED_NODE_SIZE_IP6; 298 return PACKED_NODE_SIZE_IP6;
299 299
@@ -317,14 +317,14 @@ static int pack_ip_port(uint8_t *data, uint16_t length, const IP_Port *ip_port)
317 bool is_ipv4; 317 bool is_ipv4;
318 uint8_t net_family; 318 uint8_t net_family;
319 319
320 if (ip_port->ip.family == AF_INET) { 320 if (ip_port->ip.family == TOX_AF_INET) {
321 // TODO(irungentoo): use functions to convert endianness 321 // TODO(irungentoo): use functions to convert endianness
322 is_ipv4 = true; 322 is_ipv4 = true;
323 net_family = TOX_AF_INET; 323 net_family = TOX_AF_INET;
324 } else if (ip_port->ip.family == TCP_INET) { 324 } else if (ip_port->ip.family == TCP_INET) {
325 is_ipv4 = true; 325 is_ipv4 = true;
326 net_family = TOX_TCP_INET; 326 net_family = TOX_TCP_INET;
327 } else if (ip_port->ip.family == AF_INET6) { 327 } else if (ip_port->ip.family == TOX_AF_INET6) {
328 is_ipv4 = false; 328 is_ipv4 = false;
329 net_family = TOX_AF_INET6; 329 net_family = TOX_AF_INET6;
330 } else if (ip_port->ip.family == TCP_INET6) { 330 } else if (ip_port->ip.family == TCP_INET6) {
@@ -397,7 +397,7 @@ static int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length
397 397
398 if (data[0] == TOX_AF_INET) { 398 if (data[0] == TOX_AF_INET) {
399 is_ipv4 = true; 399 is_ipv4 = true;
400 host_family = AF_INET; 400 host_family = TOX_AF_INET;
401 } else if (data[0] == TOX_TCP_INET) { 401 } else if (data[0] == TOX_TCP_INET) {
402 if (!tcp_enabled) { 402 if (!tcp_enabled) {
403 return -1; 403 return -1;
@@ -407,7 +407,7 @@ static int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length
407 host_family = TCP_INET; 407 host_family = TCP_INET;
408 } else if (data[0] == TOX_AF_INET6) { 408 } else if (data[0] == TOX_AF_INET6) {
409 is_ipv4 = false; 409 is_ipv4 = false;
410 host_family = AF_INET6; 410 host_family = TOX_AF_INET6;
411 } else if (data[0] == TOX_TCP_INET6) { 411 } else if (data[0] == TOX_TCP_INET6) {
412 if (!tcp_enabled) { 412 if (!tcp_enabled) {
413 return -1; 413 return -1;
@@ -551,8 +551,8 @@ static uint32_t index_of_node_pk(const Node_format *array, uint32_t size, const
551static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size, const IP_Port *ip_port) 551static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size, const IP_Port *ip_port)
552{ 552{
553 for (uint32_t i = 0; i < size; ++i) { 553 for (uint32_t i = 0; i < size; ++i) {
554 if (ip_port->ip.family == AF_INET && ipport_equal(&array[i].assoc4.ip_port, ip_port) || 554 if (ip_port->ip.family == TOX_AF_INET && ipport_equal(&array[i].assoc4.ip_port, ip_port) ||
555 ip_port->ip.family == AF_INET6 && ipport_equal(&array[i].assoc6.ip_port, ip_port)) { 555 ip_port->ip.family == TOX_AF_INET6 && ipport_equal(&array[i].assoc6.ip_port, ip_port)) {
556 return i; 556 return i;
557 } 557 }
558 } 558 }
@@ -567,10 +567,10 @@ static void update_client(Logger *log, int index, Client_data *client, IP_Port i
567 IPPTsPng *assoc; 567 IPPTsPng *assoc;
568 int ip_version; 568 int ip_version;
569 569
570 if (ip_port.ip.family == AF_INET) { 570 if (ip_port.ip.family == TOX_AF_INET) {
571 assoc = &client->assoc4; 571 assoc = &client->assoc4;
572 ip_version = 4; 572 ip_version = 4;
573 } else if (ip_port.ip.family == AF_INET6) { 573 } else if (ip_port.ip.family == TOX_AF_INET6) {
574 assoc = &client->assoc6; 574 assoc = &client->assoc6;
575 ip_version = 6; 575 ip_version = 6;
576 } else { 576 } else {
@@ -628,7 +628,7 @@ static int client_or_ip_port_in_list(Logger *log, Client_data *list, uint16_t le
628 IPPTsPng *assoc; 628 IPPTsPng *assoc;
629 int ip_version; 629 int ip_version;
630 630
631 if (ip_port.ip.family == AF_INET) { 631 if (ip_port.ip.family == TOX_AF_INET) {
632 assoc = &list[index].assoc4; 632 assoc = &list[index].assoc4;
633 ip_version = 4; 633 ip_version = 4;
634 } else { 634 } else {
@@ -692,7 +692,7 @@ static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_
692 Family sa_family, const Client_data *client_list, uint32_t client_list_length, 692 Family sa_family, const Client_data *client_list, uint32_t client_list_length,
693 uint32_t *num_nodes_ptr, uint8_t is_LAN, uint8_t want_good) 693 uint32_t *num_nodes_ptr, uint8_t is_LAN, uint8_t want_good)
694{ 694{
695 if ((sa_family != AF_INET) && (sa_family != AF_INET6) && (sa_family != 0)) { 695 if ((sa_family != TOX_AF_INET) && (sa_family != TOX_AF_INET6) && (sa_family != 0)) {
696 return; 696 return;
697 } 697 }
698 698
@@ -708,9 +708,9 @@ static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_
708 708
709 const IPPTsPng *ipptp = NULL; 709 const IPPTsPng *ipptp = NULL;
710 710
711 if (sa_family == AF_INET) { 711 if (sa_family == TOX_AF_INET) {
712 ipptp = &client->assoc4; 712 ipptp = &client->assoc4;
713 } else if (sa_family == AF_INET6) { 713 } else if (sa_family == TOX_AF_INET6) {
714 ipptp = &client->assoc6; 714 ipptp = &client->assoc6;
715 } else if (client->assoc4.timestamp >= client->assoc6.timestamp) { 715 } else if (client->assoc4.timestamp >= client->assoc6.timestamp) {
716 ipptp = &client->assoc4; 716 ipptp = &client->assoc4;
@@ -879,7 +879,7 @@ static void update_client_with_reset(Client_data *client, const IP_Port *ip_port
879 IPPTsPng *ipptp_write = NULL; 879 IPPTsPng *ipptp_write = NULL;
880 IPPTsPng *ipptp_clear = NULL; 880 IPPTsPng *ipptp_clear = NULL;
881 881
882 if (ip_port->ip.family == AF_INET) { 882 if (ip_port->ip.family == TOX_AF_INET) {
883 ipptp_write = &client->assoc4; 883 ipptp_write = &client->assoc4;
884 ipptp_clear = &client->assoc6; 884 ipptp_clear = &client->assoc6;
885 } else { 885 } else {
@@ -917,7 +917,7 @@ static int replace_all(Client_data *list,
917 IP_Port ip_port, 917 IP_Port ip_port,
918 const uint8_t *comp_public_key) 918 const uint8_t *comp_public_key)
919{ 919{
920 if ((ip_port.ip.family != AF_INET) && (ip_port.ip.family != AF_INET6)) { 920 if ((ip_port.ip.family != TOX_AF_INET) && (ip_port.ip.family != TOX_AF_INET6)) {
921 return 0; 921 return 0;
922 } 922 }
923 923
@@ -988,7 +988,7 @@ static bool is_pk_in_client_list(Client_data *list, unsigned int client_list_len
988 return 0; 988 return 0;
989 } 989 }
990 990
991 const IPPTsPng *assoc = ip_port.ip.family == AF_INET ? 991 const IPPTsPng *assoc = ip_port.ip.family == TOX_AF_INET ?
992 &list[index].assoc4 : 992 &list[index].assoc4 :
993 &list[index].assoc6; 993 &list[index].assoc6;
994 994
@@ -1079,8 +1079,8 @@ uint32_t addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
1079 uint32_t used = 0; 1079 uint32_t used = 0;
1080 1080
1081 /* convert IPv4-in-IPv6 to IPv4 */ 1081 /* convert IPv4-in-IPv6 to IPv4 */
1082 if ((ip_port.ip.family == AF_INET6) && IPV6_IPV4_IN_V6(ip_port.ip.ip6)) { 1082 if ((ip_port.ip.family == TOX_AF_INET6) && IPV6_IPV4_IN_V6(ip_port.ip.ip6)) {
1083 ip_port.ip.family = AF_INET; 1083 ip_port.ip.family = TOX_AF_INET;
1084 ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3]; 1084 ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3];
1085 } 1085 }
1086 1086
@@ -1140,9 +1140,9 @@ static bool update_client_data(Client_data *array, size_t size, IP_Port ip_port,
1140 Client_data *data = &array[index]; 1140 Client_data *data = &array[index];
1141 IPPTsPng *assoc; 1141 IPPTsPng *assoc;
1142 1142
1143 if (ip_port.ip.family == AF_INET) { 1143 if (ip_port.ip.family == TOX_AF_INET) {
1144 assoc = &data->assoc4; 1144 assoc = &data->assoc4;
1145 } else if (ip_port.ip.family == AF_INET6) { 1145 } else if (ip_port.ip.family == TOX_AF_INET6) {
1146 assoc = &data->assoc6; 1146 assoc = &data->assoc6;
1147 } else { 1147 } else {
1148 return true; 1148 return true;
@@ -1159,8 +1159,8 @@ static bool update_client_data(Client_data *array, size_t size, IP_Port ip_port,
1159static void returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *nodepublic_key) 1159static void returnedip_ports(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const uint8_t *nodepublic_key)
1160{ 1160{
1161 /* convert IPv4-in-IPv6 to IPv4 */ 1161 /* convert IPv4-in-IPv6 to IPv4 */
1162 if ((ip_port.ip.family == AF_INET6) && IPV6_IPV4_IN_V6(ip_port.ip.ip6)) { 1162 if ((ip_port.ip.family == TOX_AF_INET6) && IPV6_IPV4_IN_V6(ip_port.ip.ip6)) {
1163 ip_port.ip.family = AF_INET; 1163 ip_port.ip.family = TOX_AF_INET;
1164 ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3]; 1164 ip_port.ip.ip4.uint32 = ip_port.ip.ip6.uint32[3];
1165 } 1165 }
1166 1166
@@ -2237,11 +2237,11 @@ static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *public_key, Fam
2237 continue; 2237 continue;
2238 } 2238 }
2239 2239
2240 if (sa_family == AF_INET) { 2240 if (sa_family == TOX_AF_INET) {
2241 return &dht->close_clientlist[i].assoc4; 2241 return &dht->close_clientlist[i].assoc4;
2242 } 2242 }
2243 2243
2244 if (sa_family == AF_INET6) { 2244 if (sa_family == TOX_AF_INET6) {
2245 return &dht->close_clientlist[i].assoc6; 2245 return &dht->close_clientlist[i].assoc6;
2246 } 2246 }
2247 } 2247 }
@@ -2464,10 +2464,10 @@ static void do_hardening(DHT *dht)
2464 2464
2465 if (i % 2 == 0) { 2465 if (i % 2 == 0) {
2466 cur_iptspng = &dht->close_clientlist[i / 2].assoc4; 2466 cur_iptspng = &dht->close_clientlist[i / 2].assoc4;
2467 sa_family = AF_INET; 2467 sa_family = TOX_AF_INET;
2468 } else { 2468 } else {
2469 cur_iptspng = &dht->close_clientlist[i / 2].assoc6; 2469 cur_iptspng = &dht->close_clientlist[i / 2].assoc6;
2470 sa_family = AF_INET6; 2470 sa_family = TOX_AF_INET6;
2471 } 2471 }
2472 2472
2473 if (is_timeout(cur_iptspng->timestamp, BAD_NODE_TIMEOUT)) { 2473 if (is_timeout(cur_iptspng->timestamp, BAD_NODE_TIMEOUT)) {
@@ -2675,7 +2675,7 @@ uint32_t DHT_size(const DHT *dht)
2675 2675
2676 uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2; 2676 uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2;
2677 2677
2678 return size32 + sizesubhead + (packed_node_size(AF_INET) * numv4) + (packed_node_size(AF_INET6) * numv6); 2678 return size32 + sizesubhead + (packed_node_size(TOX_AF_INET) * numv4) + (packed_node_size(TOX_AF_INET6) * numv6);
2679} 2679}
2680 2680
2681static uint8_t *DHT_save_subheader(uint8_t *data, uint32_t len, uint16_t type) 2681static uint8_t *DHT_save_subheader(uint8_t *data, uint32_t len, uint16_t type)