summaryrefslogtreecommitdiff
path: root/toxcore/DHT.h
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/DHT.h')
-rw-r--r--toxcore/DHT.h37
1 files changed, 17 insertions, 20 deletions
diff --git a/toxcore/DHT.h b/toxcore/DHT.h
index e6f227f7..7cb3198d 100644
--- a/toxcore/DHT.h
+++ b/toxcore/DHT.h
@@ -26,7 +26,6 @@
26 26
27#include "net_crypto.h" 27#include "net_crypto.h"
28 28
29
30/* Size of the client_id in bytes. */ 29/* Size of the client_id in bytes. */
31#define CLIENT_ID_SIZE crypto_box_PUBLICKEYBYTES 30#define CLIENT_ID_SIZE crypto_box_PUBLICKEYBYTES
32 31
@@ -92,22 +91,23 @@ typedef Node46_format Node_format;
92typedef Node4_format Node_format; 91typedef Node4_format Node_format;
93#endif 92#endif
94 93
94/*----------------------------------------------------------------------------------*/
95
95typedef struct { 96typedef struct {
96 IP_Port ip_port; 97 IP_Port ip_port;
97 uint64_t ping_id; 98 uint64_t id;
98 uint64_t timestamp; 99 uint64_t timestamp;
99} Pinged; 100} pinged_t;
100 101
101/*----------------------------------------------------------------------------------*/
102typedef struct { 102typedef struct {
103 Net_Crypto *c; 103 Net_Crypto *c;
104
104 Client_data close_clientlist[LCLIENT_LIST]; 105 Client_data close_clientlist[LCLIENT_LIST];
105 DHT_Friend *friends_list; 106 DHT_Friend *friends_list;
106 uint16_t num_friends; 107 uint16_t num_friends;
107 Pinged send_nodes[LSEND_NODES_ARRAY];
108 Node_format toping[MAX_TOPING];
109 uint64_t last_toping;
110 uint64_t close_lastgetnodes; 108 uint64_t close_lastgetnodes;
109
110 pinged_t send_nodes[LSEND_NODES_ARRAY];
111 void *ping; 111 void *ping;
112} DHT; 112} DHT;
113/*----------------------------------------------------------------------------------*/ 113/*----------------------------------------------------------------------------------*/
@@ -152,6 +152,14 @@ int DHT_delfriend(DHT *dht, uint8_t *client_id);
152 */ 152 */
153int DHT_getfriendip(DHT *dht, uint8_t *client_id, IP_Port *ip_port); 153int DHT_getfriendip(DHT *dht, uint8_t *client_id, IP_Port *ip_port);
154 154
155/* Compares client_id1 and client_id2 with client_id.
156 *
157 * return 0 if both are same distance.
158 * return 1 if client_id1 is closer.
159 * return 2 if client_id2 is closer.
160 */
161int id_closest(uint8_t *id, uint8_t *id1, uint8_t *id2);
162
155/* Run this function at least a couple times per second (It's the main loop). */ 163/* Run this function at least a couple times per second (It's the main loop). */
156void do_DHT(DHT *dht); 164void do_DHT(DHT *dht);
157 165
@@ -176,17 +184,6 @@ void DHT_bootstrap(DHT *dht, IP_Port ip_port, uint8_t *public_key);
176int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled, 184int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled,
177 uint16_t port, uint8_t *public_key); 185 uint16_t port, uint8_t *public_key);
178 186
179/* Add nodes to the toping list.
180 * All nodes in this list are pinged every TIME_TOPING seconds
181 * and are then removed from the list.
182 * If the list is full the nodes farthest from our client_id are replaced.
183 * The purpose of this list is to enable quick integration of new nodes into the
184 * network while preventing amplification attacks.
185 *
186 * return 0 if node was added.
187 * return -1 if node was not added.
188 */
189int add_toping(DHT *dht, uint8_t *client_id, IP_Port ip_port);
190 187
191/* ROUTING FUNCTIONS */ 188/* ROUTING FUNCTIONS */
192 189