summaryrefslogtreecommitdiff
path: root/core/ping.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/ping.c')
-rw-r--r--core/ping.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/core/ping.c b/core/ping.c
index d2b290a0..10b9b19f 100644
--- a/core/ping.c
+++ b/core/ping.c
@@ -26,7 +26,6 @@ typedef struct {
26static pinged_t pings[PING_NUM_MAX]; 26static pinged_t pings[PING_NUM_MAX];
27static size_t num_pings; 27static size_t num_pings;
28static size_t pos_pings; 28static size_t pos_pings;
29static clientid_t *self_id = (clientid_t *) &self_public_key;
30 29
31extern uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; // DHT.c 30extern uint8_t self_secret_key[crypto_box_SECRETKEYBYTES]; // DHT.c
32 31
@@ -115,19 +114,19 @@ int send_ping_request(IP_Port ipp, clientid_t *client_id)
115 int rc; 114 int rc;
116 uint64_t ping_id; 115 uint64_t ping_id;
117 116
118 if (is_pinging(ipp, 0) || id_eq(client_id, self_id)) 117 if (is_pinging(ipp, 0) || id_eq(client_id, (clientid_t *)temp_net_crypto->self_public_key))
119 return 1; 118 return 1;
120 119
121 // Generate random ping_id 120 // Generate random ping_id
122 ping_id = add_ping(ipp); 121 ping_id = add_ping(ipp);
123 122
124 pk.magic = PACKET_PING_REQ; 123 pk.magic = PACKET_PING_REQ;
125 id_cpy(&pk.client_id, self_id); // Our pubkey 124 id_cpy(&pk.client_id, (clientid_t *)temp_net_crypto->self_public_key); // Our pubkey
126 random_nonce((uint8_t *) &pk.nonce); // Generate random nonce 125 random_nonce((uint8_t *) &pk.nonce); // Generate random nonce
127 126
128 // Encrypt ping_id using recipient privkey 127 // Encrypt ping_id using recipient privkey
129 rc = encrypt_data((uint8_t *) client_id, 128 rc = encrypt_data((uint8_t *) client_id,
130 self_secret_key, 129 temp_net_crypto->self_secret_key,
131 (uint8_t *) &pk.nonce, 130 (uint8_t *) &pk.nonce,
132 (uint8_t *) &ping_id, sizeof(ping_id), 131 (uint8_t *) &ping_id, sizeof(ping_id),
133 (uint8_t *) &pk.ping_id); 132 (uint8_t *) &pk.ping_id);
@@ -135,7 +134,7 @@ int send_ping_request(IP_Port ipp, clientid_t *client_id)
135 if (rc != sizeof(ping_id) + ENCRYPTION_PADDING) 134 if (rc != sizeof(ping_id) + ENCRYPTION_PADDING)
136 return 1; 135 return 1;
137 136
138 return sendpacket(temp_net->sock, ipp, (uint8_t *) &pk, sizeof(pk)); 137 return sendpacket(temp_net_crypto->lossless_udp->net->sock, ipp, (uint8_t *) &pk, sizeof(pk));
139} 138}
140 139
141int send_ping_response(IP_Port ipp, clientid_t *client_id, uint64_t ping_id) 140int send_ping_response(IP_Port ipp, clientid_t *client_id, uint64_t ping_id)
@@ -143,16 +142,16 @@ int send_ping_response(IP_Port ipp, clientid_t *client_id, uint64_t ping_id)
143 pingres_t pk; 142 pingres_t pk;
144 int rc; 143 int rc;
145 144
146 if (id_eq(client_id, self_id)) 145 if (id_eq(client_id, (clientid_t *)temp_net_crypto->self_public_key))
147 return 1; 146 return 1;
148 147
149 pk.magic = PACKET_PING_RES; 148 pk.magic = PACKET_PING_RES;
150 id_cpy(&pk.client_id, self_id); // Our pubkey 149 id_cpy(&pk.client_id, (clientid_t *)temp_net_crypto->self_public_key); // Our pubkey
151 random_nonce((uint8_t *) &pk.nonce); // Generate random nonce 150 random_nonce((uint8_t *) &pk.nonce); // Generate random nonce
152 151
153 // Encrypt ping_id using recipient privkey 152 // Encrypt ping_id using recipient privkey
154 rc = encrypt_data((uint8_t *) client_id, 153 rc = encrypt_data((uint8_t *) client_id,
155 self_secret_key, 154 temp_net_crypto->self_secret_key,
156 (uint8_t *) &pk.nonce, 155 (uint8_t *) &pk.nonce,
157 (uint8_t *) &ping_id, sizeof(ping_id), 156 (uint8_t *) &ping_id, sizeof(ping_id),
158 (uint8_t *) &pk.ping_id); 157 (uint8_t *) &pk.ping_id);
@@ -160,21 +159,22 @@ int send_ping_response(IP_Port ipp, clientid_t *client_id, uint64_t ping_id)
160 if (rc != sizeof(ping_id) + ENCRYPTION_PADDING) 159 if (rc != sizeof(ping_id) + ENCRYPTION_PADDING)
161 return 1; 160 return 1;
162 161
163 return sendpacket(temp_net->sock, ipp, (uint8_t *) &pk, sizeof(pk)); 162 return sendpacket(temp_net_crypto->lossless_udp->net->sock, ipp, (uint8_t *) &pk, sizeof(pk));
164} 163}
165 164
166int handle_ping_request(void * object, IP_Port source, uint8_t *packet, uint32_t length) 165int handle_ping_request(void * object, IP_Port source, uint8_t *packet, uint32_t length)
167{ 166{
167 DHT * dht = object;
168 pingreq_t *p = (pingreq_t *) packet; 168 pingreq_t *p = (pingreq_t *) packet;
169 int rc; 169 int rc;
170 uint64_t ping_id; 170 uint64_t ping_id;
171 171
172 if (length != sizeof(pingreq_t) || id_eq(&p->client_id, self_id)) 172 if (length != sizeof(pingreq_t) || id_eq(&p->client_id, (clientid_t *)dht->c->self_public_key))
173 return 1; 173 return 1;
174 174
175 // Decrypt ping_id 175 // Decrypt ping_id
176 rc = decrypt_data((uint8_t *) &p->client_id, 176 rc = decrypt_data((uint8_t *) &p->client_id,
177 self_secret_key, 177 dht->c->self_secret_key,
178 (uint8_t *) &p->nonce, 178 (uint8_t *) &p->nonce,
179 (uint8_t *) &p->ping_id, 179 (uint8_t *) &p->ping_id,
180 sizeof(ping_id) + ENCRYPTION_PADDING, 180 sizeof(ping_id) + ENCRYPTION_PADDING,
@@ -185,23 +185,24 @@ int handle_ping_request(void * object, IP_Port source, uint8_t *packet, uint32_t
185 185
186 // Send response 186 // Send response
187 send_ping_response(source, &p->client_id, ping_id); 187 send_ping_response(source, &p->client_id, ping_id);
188 add_toping((uint8_t *) &p->client_id, source); 188 add_toping(dht, (uint8_t *) &p->client_id, source);
189 189
190 return 0; 190 return 0;
191} 191}
192 192
193int handle_ping_response(void * object, IP_Port source, uint8_t *packet, uint32_t length) 193int handle_ping_response(void * object, IP_Port source, uint8_t *packet, uint32_t length)
194{ 194{
195 DHT * dht = object;
195 pingres_t *p = (pingres_t *) packet; 196 pingres_t *p = (pingres_t *) packet;
196 int rc; 197 int rc;
197 uint64_t ping_id; 198 uint64_t ping_id;
198 199
199 if (length != sizeof(pingres_t) || id_eq(&p->client_id, self_id)) 200 if (length != sizeof(pingres_t) || id_eq(&p->client_id, (clientid_t *)dht->c->self_public_key))
200 return 1; 201 return 1;
201 202
202 // Decrypt ping_id 203 // Decrypt ping_id
203 rc = decrypt_data((uint8_t *) &p->client_id, 204 rc = decrypt_data((uint8_t *) &p->client_id,
204 self_secret_key, 205 dht->c->self_secret_key,
205 (uint8_t *) &p->nonce, 206 (uint8_t *) &p->nonce,
206 (uint8_t *) &p->ping_id, 207 (uint8_t *) &p->ping_id,
207 sizeof(ping_id) + ENCRYPTION_PADDING, 208 sizeof(ping_id) + ENCRYPTION_PADDING,
@@ -215,6 +216,6 @@ int handle_ping_response(void * object, IP_Port source, uint8_t *packet, uint32_
215 return 1; 216 return 1;
216 217
217 // Associate source ip with client_id 218 // Associate source ip with client_id
218 addto_lists(source, (uint8_t *) &p->client_id); 219 addto_lists(dht, source, (uint8_t *) &p->client_id);
219 return 0; 220 return 0;
220} 221}