summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-01-14 20:25:26 -0500
committerirungentoo <irungentoo@gmail.com>2014-01-14 20:25:26 -0500
commitb345bcea8b1c41b7312e793515040a5a4abad230 (patch)
tree56230da6d4f511956887463adb94e18c36f175e4
parenta49a09f94b6b9754e322f2f29a4abf9ae1be106c (diff)
Some packet handling code added to onion_client.
-rw-r--r--toxcore/DHT.c15
-rw-r--r--toxcore/onion_client.c45
2 files changed, 52 insertions, 8 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 820c3b9c..e5fe402d 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -1374,13 +1374,14 @@ void DHT_getnodes(DHT *dht, IP_Port *from_ipp, uint8_t *from_id, uint8_t *which_
1374 1374
1375void DHT_bootstrap(DHT *dht, IP_Port ip_port, uint8_t *public_key) 1375void DHT_bootstrap(DHT *dht, IP_Port ip_port, uint8_t *public_key)
1376{ 1376{
1377 if (dht->assoc) { 1377 /*
1378 IPPTs ippts; 1378 if (dht->assoc) {
1379 ippts.ip_port = ip_port; 1379 IPPTs ippts;
1380 ippts.timestamp = 0; 1380 ippts.ip_port = ip_port;
1381 1381 ippts.timestamp = 0;
1382 Assoc_add_entry(dht->assoc, public_key, &ippts, NULL, 0); 1382
1383 } 1383 Assoc_add_entry(dht->assoc, public_key, &ippts, NULL, 0);
1384 }*/
1384 1385
1385 getnodes(dht, ip_port, public_key, dht->c->self_public_key, NULL); 1386 getnodes(dht, ip_port, public_key, dht->c->self_public_key, NULL);
1386} 1387}
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index f865dcd9..93dd06cd 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -30,7 +30,7 @@
30 30
31#define ANNOUNCE_TIMEOUT 10 31#define ANNOUNCE_TIMEOUT 10
32 32
33uint8_t zero_ping[ONION_PING_ID_SIZE]; 33static uint8_t zero_ping[ONION_PING_ID_SIZE];
34 34
35/* Creates a sendback for use in an announce request. 35/* Creates a sendback for use in an announce request.
36 * 36 *
@@ -332,6 +332,48 @@ static int handle_data_response(void *object, IP_Port source, uint8_t *packet, u
332 sizeof(plain)); 332 sizeof(plain));
333} 333}
334 334
335#define FAKEID_DATA_ID 156
336#define FAKEID_DATA_MIN_LENGTH (1 + crypto_box_PUBLICKEYBYTES)
337#define FAKEID_DATA_MAX_LENGTH (FAKEID_DATA_MIN_LENGTH + sizeof(Node_format)*MAX_SENT_NODES)
338static int handle_fakeid_announce(void *object, uint8_t *source_pubkey, uint8_t *data, uint32_t length)
339{
340 Onion_Client *onion_c = object;
341
342 if (length < FAKEID_DATA_MIN_LENGTH)
343 return 1;
344
345 if (length > FAKEID_DATA_MAX_LENGTH)
346 return 1;
347
348 if ((length - FAKEID_DATA_MIN_LENGTH) % sizeof(Node_format) != 0)
349 return 1;
350
351 int friend_num = onion_friend_num(onion_c, source_pubkey);
352
353 if (friend_num == -1)
354 return 1;
355
356 if (memcmp(data + 1, onion_c->friends_list[friend_num].fake_client_id, crypto_box_PUBLICKEYBYTES) != 0) {
357 DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].fake_client_id);
358
359 if (DHT_addfriend(onion_c->dht, data + 1) == 1) {
360 return 1;
361 }
362 }
363
364 uint16_t num_nodes = (length - FAKEID_DATA_MIN_LENGTH) / sizeof(Node_format);
365 Node_format nodes[num_nodes];
366 memcpy(nodes, data + 1 + crypto_box_PUBLICKEYBYTES, sizeof(nodes));
367 uint32_t i;
368
369 for (i = 0; i < num_nodes; ++i) {
370 to_host_family(&nodes[i].ip_port.ip);
371 DHT_bootstrap(onion_c->dht, nodes[i].ip_port, nodes[i].client_id);
372 }
373
374 //TODO replay protection
375 return 0;
376}
335/* Send data of length length to friendnum. 377/* Send data of length length to friendnum.
336 * This data will be recieved by the friend using the Onion_Data_Handlers callbacks. 378 * This data will be recieved by the friend using the Onion_Data_Handlers callbacks.
337 * 379 *
@@ -633,6 +675,7 @@ Onion_Client *new_onion_client(DHT *dht)
633 675
634 networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_announce_response, onion_c); 676 networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_announce_response, onion_c);
635 networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_data_response, onion_c); 677 networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_data_response, onion_c);
678 oniondata_registerhandler(onion_c, FAKEID_DATA_ID, &handle_fakeid_announce, onion_c);
636 679
637 return onion_c; 680 return onion_c;
638} 681}