summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
diff options
context:
space:
mode:
authorKostya <kostyarjcnz@gmail.com>2013-08-30 03:28:50 -0400
committerKostya <kostyarjcnz@gmail.com>2013-08-30 03:28:50 -0400
commit25563ac07005448706d294dccdabf14fbe01d100 (patch)
tree2166609dfed18c1e4625c05ac0478220dd842d87 /toxcore/DHT.c
parent790867d984841ba0e28c4100615590870895e7d4 (diff)
Fixed build errors.
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r--toxcore/DHT.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 78ea5b8c..f1cef9f4 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -88,7 +88,7 @@ static int id_closest(uint8_t *id, uint8_t *id1, uint8_t *id2)
88 88
89static int ipport_equal(IP_Port a, IP_Port b) 89static int ipport_equal(IP_Port a, IP_Port b)
90{ 90{
91 return (a.ip.i == b.ip.i) && (a.port == b.port); 91 return (a.ip.uint32 == b.ip.uint32) && (a.port == b.port);
92} 92}
93 93
94static int id_equal(uint8_t *a, uint8_t *b) 94static int id_equal(uint8_t *a, uint8_t *b)
@@ -122,7 +122,7 @@ static int client_in_list(Client_data *list, uint32_t length, uint8_t *client_id
122 if (id_equal(list[i].client_id, client_id)) { 122 if (id_equal(list[i].client_id, client_id)) {
123 /* Refresh the client timestamp. */ 123 /* Refresh the client timestamp. */
124 list[i].timestamp = temp_time; 124 list[i].timestamp = temp_time;
125 list[i].ip_port.ip.i = ip_port.ip.i; 125 list[i].ip_port.ip.uint32 = ip_port.ip.uint32;
126 list[i].ip_port.port = ip_port.port; 126 list[i].ip_port.port = ip_port.port;
127 return 1; 127 return 1;
128 } 128 }
@@ -268,7 +268,7 @@ static int replace_bad( Client_data *list,
268 memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE); 268 memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE);
269 list[i].ip_port = ip_port; 269 list[i].ip_port = ip_port;
270 list[i].timestamp = temp_time; 270 list[i].timestamp = temp_time;
271 list[i].ret_ip_port.ip.i = 0; 271 list[i].ret_ip_port.ip.uint32 = 0;
272 list[i].ret_ip_port.port = 0; 272 list[i].ret_ip_port.port = 0;
273 list[i].ret_timestamp = 0; 273 list[i].ret_timestamp = 0;
274 return 0; 274 return 0;
@@ -320,7 +320,7 @@ static int replace_good( Client_data *list,
320 memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE); 320 memcpy(list[i].client_id, client_id, CLIENT_ID_SIZE);
321 list[i].ip_port = ip_port; 321 list[i].ip_port = ip_port;
322 list[i].timestamp = temp_time; 322 list[i].timestamp = temp_time;
323 list[i].ret_ip_port.ip.i = 0; 323 list[i].ret_ip_port.ip.uint32 = 0;
324 list[i].ret_ip_port.port = 0; 324 list[i].ret_ip_port.port = 0;
325 list[i].ret_timestamp = 0; 325 list[i].ret_timestamp = 0;
326 return 0; 326 return 0;
@@ -418,13 +418,13 @@ static int is_gettingnodes(DHT *dht, IP_Port ip_port, uint64_t ping_id)
418 if (!is_timeout(temp_time, dht->send_nodes[i].timestamp, PING_TIMEOUT)) { 418 if (!is_timeout(temp_time, dht->send_nodes[i].timestamp, PING_TIMEOUT)) {
419 pinging = 0; 419 pinging = 0;
420 420
421 if (ip_port.ip.i != 0 && ipport_equal(dht->send_nodes[i].ip_port, ip_port)) 421 if (ip_port.ip.uint32 != 0 && ipport_equal(dht->send_nodes[i].ip_port, ip_port))
422 ++pinging; 422 ++pinging;
423 423
424 if (ping_id != 0 && dht->send_nodes[i].ping_id == ping_id) 424 if (ping_id != 0 && dht->send_nodes[i].ping_id == ping_id)
425 ++pinging; 425 ++pinging;
426 426
427 if (pinging == (ping_id != 0) + (ip_port.ip.i != 0)) 427 if (pinging == (ping_id != 0) + (ip_port.ip.uint32 != 0))
428 return 1; 428 return 1;
429 } 429 }
430 } 430 }
@@ -690,7 +690,7 @@ IP_Port DHT_getfriendip(DHT *dht, uint8_t *client_id)
690 } 690 }
691 } 691 }
692 692
693 empty.ip.i = 1; 693 empty.ip.uint32 = 1;
694 return empty; 694 return empty;
695} 695}
696 696
@@ -814,7 +814,7 @@ static int friend_iplist(DHT *dht, IP_Port *ip_portlist, uint16_t friend_num)
814 client = &friend->client_list[i]; 814 client = &friend->client_list[i];
815 815
816 /* If ip is not zero and node is good */ 816 /* If ip is not zero and node is good */
817 if (client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) { 817 if (client->ret_ip_port.ip.uint32 != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
818 818
819 if (id_equal(client->client_id, friend->client_id)) 819 if (id_equal(client->client_id, friend->client_id))
820 return 0; 820 return 0;
@@ -856,7 +856,7 @@ int route_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint32_t lengt
856 client = &friend->client_list[i]; 856 client = &friend->client_list[i];
857 857
858 /* If ip is not zero and node is good */ 858 /* If ip is not zero and node is good */
859 if (client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) { 859 if (client->ret_ip_port.ip.uint32 != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
860 if (sendpacket(dht->c->lossless_udp->net->sock, client->ip_port, packet, length) == length) 860 if (sendpacket(dht->c->lossless_udp->net->sock, client->ip_port, packet, length) == length)
861 ++sent; 861 ++sent;
862 } 862 }
@@ -887,7 +887,7 @@ static int routeone_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint
887 client = &friend->client_list[i]; 887 client = &friend->client_list[i];
888 888
889 /* If ip is not zero and node is good. */ 889 /* If ip is not zero and node is good. */
890 if (client->ret_ip_port.ip.i != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) { 890 if (client->ret_ip_port.ip.uint32 != 0 && !is_timeout(temp_time, client->ret_timestamp, BAD_NODE_TIMEOUT)) {
891 ip_list[n] = client->ip_port; 891 ip_list[n] = client->ip_port;
892 ++n; 892 ++n;
893 } 893 }
@@ -998,7 +998,7 @@ static IP NAT_commonip(IP_Port *ip_portlist, uint16_t len, uint16_t min_num)
998 998
999 for (i = 0; i < len; ++i) { 999 for (i = 0; i < len; ++i) {
1000 for (j = 0; j < len; ++j) { 1000 for (j = 0; j < len; ++j) {
1001 if (ip_portlist[i].ip.i == ip_portlist[j].ip.i) 1001 if (ip_portlist[i].ip.uint32 == ip_portlist[j].ip.uint32)
1002 ++numbers[i]; 1002 ++numbers[i];
1003 } 1003 }
1004 1004
@@ -1020,7 +1020,7 @@ static uint16_t NAT_getports(uint16_t *portlist, IP_Port *ip_portlist, uint16_t
1020 uint16_t num = 0; 1020 uint16_t num = 0;
1021 1021
1022 for (i = 0; i < len; ++i) { 1022 for (i = 0; i < len; ++i) {
1023 if (ip_portlist[i].ip.i == ip.i) { 1023 if (ip_portlist[i].ip.uint32 == ip.uint32) {
1024 portlist[num] = ntohs(ip_portlist[i].port); 1024 portlist[num] = ntohs(ip_portlist[i].port);
1025 ++num; 1025 ++num;
1026 } 1026 }
@@ -1071,7 +1071,7 @@ static void do_NAT(DHT *dht)
1071 1071
1072 IP ip = NAT_commonip(ip_list, num, MAX_FRIEND_CLIENTS / 2); 1072 IP ip = NAT_commonip(ip_list, num, MAX_FRIEND_CLIENTS / 2);
1073 1073
1074 if (ip.i == 0) 1074 if (ip.uint32 == 0)
1075 continue; 1075 continue;
1076 1076
1077 uint16_t port_list[MAX_FRIEND_CLIENTS]; 1077 uint16_t port_list[MAX_FRIEND_CLIENTS];
@@ -1099,15 +1099,15 @@ static void do_NAT(DHT *dht)
1099 */ 1099 */
1100int add_toping(DHT *dht, uint8_t *client_id, IP_Port ip_port) 1100int add_toping(DHT *dht, uint8_t *client_id, IP_Port ip_port)
1101{ 1101{
1102 if (ip_port.ip.i == 0) 1102 if (ip_port.ip.uint32 == 0)
1103 return -1; 1103 return -1;
1104 1104
1105 uint32_t i; 1105 uint32_t i;
1106 1106
1107 for (i = 0; i < MAX_TOPING; ++i) { 1107 for (i = 0; i < MAX_TOPING; ++i) {
1108 if (dht->toping[i].ip_port.ip.i == 0) { 1108 if (dht->toping[i].ip_port.ip.uint32 == 0) {
1109 memcpy(dht->toping[i].client_id, client_id, CLIENT_ID_SIZE); 1109 memcpy(dht->toping[i].client_id, client_id, CLIENT_ID_SIZE);
1110 dht->toping[i].ip_port.ip.i = ip_port.ip.i; 1110 dht->toping[i].ip_port.ip.uint32 = ip_port.ip.uint32;
1111 dht->toping[i].ip_port.port = ip_port.port; 1111 dht->toping[i].ip_port.port = ip_port.port;
1112 return 0; 1112 return 0;
1113 } 1113 }
@@ -1116,7 +1116,7 @@ int add_toping(DHT *dht, uint8_t *client_id, IP_Port ip_port)
1116 for (i = 0; i < MAX_TOPING; ++i) { 1116 for (i = 0; i < MAX_TOPING; ++i) {
1117 if (id_closest(dht->c->self_public_key, dht->toping[i].client_id, client_id) == 2) { 1117 if (id_closest(dht->c->self_public_key, dht->toping[i].client_id, client_id) == 2) {
1118 memcpy(dht->toping[i].client_id, client_id, CLIENT_ID_SIZE); 1118 memcpy(dht->toping[i].client_id, client_id, CLIENT_ID_SIZE);
1119 dht->toping[i].ip_port.ip.i = ip_port.ip.i; 1119 dht->toping[i].ip_port.ip.uint32 = ip_port.ip.uint32;
1120 dht->toping[i].ip_port.port = ip_port.port; 1120 dht->toping[i].ip_port.port = ip_port.port;
1121 return 0; 1121 return 0;
1122 } 1122 }
@@ -1139,11 +1139,11 @@ static void do_toping(DHT *dht)
1139 uint32_t i; 1139 uint32_t i;
1140 1140
1141 for (i = 0; i < MAX_TOPING; ++i) { 1141 for (i = 0; i < MAX_TOPING; ++i) {
1142 if (dht->toping[i].ip_port.ip.i == 0) 1142 if (dht->toping[i].ip_port.ip.uint32 == 0)
1143 return; 1143 return;
1144 1144
1145 send_ping_request(dht->ping, dht->c, dht->toping[i].ip_port, dht->toping[i].client_id); 1145 send_ping_request(dht->ping, dht->c, dht->toping[i].ip_port, dht->toping[i].client_id);
1146 dht->toping[i].ip_port.ip.i = 0; 1146 dht->toping[i].ip_port.ip.uint32 = 0;
1147 } 1147 }
1148} 1148}
1149 1149