diff options
Diffstat (limited to 'toxcore/ping.c')
-rw-r--r-- | toxcore/ping.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/toxcore/ping.c b/toxcore/ping.c index bd754c53..80e85a45 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c | |||
@@ -40,6 +40,12 @@ | |||
40 | #define TIME_TOPING 5 | 40 | #define TIME_TOPING 5 |
41 | 41 | ||
42 | typedef struct { | 42 | typedef struct { |
43 | IP_Port ip_port; | ||
44 | uint64_t id; | ||
45 | uint64_t timestamp; | ||
46 | } pinged_t; | ||
47 | |||
48 | typedef struct { | ||
43 | Net_Crypto *c; | 49 | Net_Crypto *c; |
44 | 50 | ||
45 | pinged_t pings[PING_NUM_MAX]; | 51 | pinged_t pings[PING_NUM_MAX]; |
@@ -139,7 +145,7 @@ static int is_pinging(PING *ping, IP_Port ipp, uint64_t ping_id) | |||
139 | return 0; | 145 | return 0; |
140 | } | 146 | } |
141 | 147 | ||
142 | #define DHT_PING_SIZE (1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(uint64_t) + ENCRYPTION_PADDING) | 148 | #define DHT_PING_SIZE (1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(uint64_t) + crypto_box_MACBYTES) |
143 | 149 | ||
144 | int send_ping_request(PING *ping, IP_Port ipp, uint8_t *client_id) | 150 | int send_ping_request(PING *ping, IP_Port ipp, uint8_t *client_id) |
145 | { | 151 | { |
@@ -164,7 +170,7 @@ int send_ping_request(PING *ping, IP_Port ipp, uint8_t *client_id) | |||
164 | (uint8_t *) &ping_id, sizeof(ping_id), | 170 | (uint8_t *) &ping_id, sizeof(ping_id), |
165 | pk + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES); | 171 | pk + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES); |
166 | 172 | ||
167 | if (rc != sizeof(ping_id) + ENCRYPTION_PADDING) | 173 | if (rc != sizeof(ping_id) + crypto_box_MACBYTES) |
168 | return 1; | 174 | return 1; |
169 | 175 | ||
170 | return sendpacket(ping->c->lossless_udp->net, ipp, pk, sizeof(pk)); | 176 | return sendpacket(ping->c->lossless_udp->net, ipp, pk, sizeof(pk)); |
@@ -189,7 +195,7 @@ static int send_ping_response(PING *ping, IP_Port ipp, uint8_t *client_id, uint6 | |||
189 | (uint8_t *) &ping_id, sizeof(ping_id), | 195 | (uint8_t *) &ping_id, sizeof(ping_id), |
190 | pk + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES); | 196 | pk + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES); |
191 | 197 | ||
192 | if (rc != sizeof(ping_id) + ENCRYPTION_PADDING) | 198 | if (rc != sizeof(ping_id) + crypto_box_MACBYTES) |
193 | return 1; | 199 | return 1; |
194 | 200 | ||
195 | return sendpacket(ping->c->lossless_udp->net, ipp, pk, sizeof(pk)); | 201 | return sendpacket(ping->c->lossless_udp->net, ipp, pk, sizeof(pk)); |
@@ -214,7 +220,7 @@ static int handle_ping_request(void *_dht, IP_Port source, uint8_t *packet, uint | |||
214 | ping->c->self_secret_key, | 220 | ping->c->self_secret_key, |
215 | packet + 1 + CLIENT_ID_SIZE, | 221 | packet + 1 + CLIENT_ID_SIZE, |
216 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, | 222 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, |
217 | sizeof(ping_id) + ENCRYPTION_PADDING, | 223 | sizeof(ping_id) + crypto_box_MACBYTES, |
218 | (uint8_t *) &ping_id); | 224 | (uint8_t *) &ping_id); |
219 | 225 | ||
220 | if (rc != sizeof(ping_id)) | 226 | if (rc != sizeof(ping_id)) |
@@ -246,7 +252,7 @@ static int handle_ping_response(void *_dht, IP_Port source, uint8_t *packet, uin | |||
246 | ping->c->self_secret_key, | 252 | ping->c->self_secret_key, |
247 | packet + 1 + CLIENT_ID_SIZE, | 253 | packet + 1 + CLIENT_ID_SIZE, |
248 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, | 254 | packet + 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES, |
249 | sizeof(ping_id) + ENCRYPTION_PADDING, | 255 | sizeof(ping_id) + crypto_box_MACBYTES, |
250 | (uint8_t *) &ping_id); | 256 | (uint8_t *) &ping_id); |
251 | 257 | ||
252 | if (rc != sizeof(ping_id)) | 258 | if (rc != sizeof(ping_id)) |