From a6edd9dad6e299f7f5680ff6e846ec6c2213a3db Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sat, 26 Oct 2013 17:35:55 -0400 Subject: [PATCH] Base of hardening stuff. --- toxcore/DHT.c | 12 ++++++++++++ toxcore/DHT.h | 22 +++++++++++++++++----- toxcore/net_crypto.h | 1 + 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 7c3894b3..661ac98a 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -1552,6 +1552,16 @@ static void do_NAT(DHT *dht) /*----------------------------------------------------------------------------------*/ /*-----------------------END OF NAT PUNCHING FUNCTIONS------------------------------*/ + +/* Handle a received ping request for. */ +static int handle_hardening(void *object, IP_Port source, uint8_t *source_pubkey, uint8_t *packet, uint32_t length) +{ + DHT *dht = object; + return 0;/* success*/ +} + +/*----------------------------------------------------------------------------------*/ + DHT *new_DHT(Net_Crypto *c) { if (c == NULL) @@ -1575,6 +1585,8 @@ DHT *new_DHT(Net_Crypto *c) networking_registerhandler(c->lossless_udp->net, NET_PACKET_SEND_NODES_IPV6, &handle_sendnodes_ipv6, dht); init_cryptopackets(dht); cryptopacket_registerhandler(c, CRYPTO_PACKET_NAT_PING, &handle_NATping, dht); + cryptopacket_registerhandler(c, CRYPTO_PACKET_HARDENING, &handle_hardening, dht); + new_symmetric_key(dht->secret_symmetric_key); return dht; } diff --git a/toxcore/DHT.h b/toxcore/DHT.h index b60f744b..b3ab5f89 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h @@ -35,11 +35,6 @@ /* A list of the clients mathematically closest to ours. */ #define LCLIENT_LIST 32 -/* The list of ip ports along with the ping_id of what we sent them and a timestamp. */ -#define LPING_ARRAY 256 // NOTE: Deprecated (doesn't do anything). - -#define LSEND_NODES_ARRAY LPING_ARRAY/2 - /* Maximum newly announced nodes to ping per TIME_TOPING seconds. */ #define MAX_TOPING 16 @@ -76,6 +71,21 @@ typedef struct { uint64_t NATping_timestamp; } NAT; +typedef struct { + /* Node routes request correctly (true (1) or false/didn't check (0)) */ + uint8_t routes_requests_ok; + /* Time which we last checked this.*/ + uint64_t routes_requests_timestamp; + /* Node sends correct send_node (true (1) or false/didn't check (0)) */ + uint8_t send_nodes_ok; + /* Time which we last checked this.*/ + uint64_t send_nodes_timestamp; + /* Node can be used to test other nodes (true (1) or false/didn't check (0)) */ + uint8_t testing_requests; + /* Time which we last checked this.*/ + uint64_t testing_timestamp; +} Hardening; + typedef struct { uint8_t client_id[CLIENT_ID_SIZE]; Client_data_old client_list[MAX_FRIEND_CLIENTS]; @@ -83,6 +93,7 @@ typedef struct { /* Time at which the last get_nodes request was sent. */ uint64_t lastgetnode; + Hardening hardening; /* Symetric NAT hole punching stuff. */ NAT nat; } DHT_Friend_old; /* required to load old state files */ @@ -94,6 +105,7 @@ typedef struct { /* Time at which the last get_nodes request was sent. */ uint64_t lastgetnode; + Hardening hardening; /* Symetric NAT hole punching stuff. */ NAT nat; } DHT_Friend; diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index f44bae6c..38400ebc 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h @@ -27,6 +27,7 @@ #include "Lossless_UDP.h" #define CRYPTO_PACKET_FRIEND_REQ 32 /* Friend request crypto packet ID. */ +#define CRYPTO_PACKET_HARDENING 48 /* Hardening crypto packet ID. */ #define CRYPTO_PACKET_NAT_PING 254 /* NAT ping crypto packet ID. */ #define CRYPTO_HANDSHAKE_TIMEOUT (CONNECTION_TIMEOUT * 2)