summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-01-15 01:23:08 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-01-16 20:06:07 +0000
commit643eea60bb9dcf4ecb33d64666b1bc77cbfd7438 (patch)
tree2f98b0c7869fddac03f834be508a182da06f07b4 /toxcore/DHT.c
parent22db2b9fe581a35300b66126604d12e83c2eafb1 (diff)
Make DHT a module-private type.
Diffstat (limited to 'toxcore/DHT.c')
-rw-r--r--toxcore/DHT.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index a4251518..33ebc690 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -59,6 +59,94 @@
59 59
60#define ASSOC_COUNT 2 60#define ASSOC_COUNT 2
61 61
62struct DHT {
63 Logger *log;
64 Networking_Core *net;
65
66 bool hole_punching_enabled;
67
68 Client_data close_clientlist[LCLIENT_LIST];
69 uint64_t close_lastgetnodes;
70 uint32_t close_bootstrap_times;
71
72 /* Note: this key should not be/is not used to transmit any sensitive materials */
73 uint8_t secret_symmetric_key[CRYPTO_SYMMETRIC_KEY_SIZE];
74 /* DHT keypair */
75 uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
76 uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
77
78 DHT_Friend *friends_list;
79 uint16_t num_friends;
80
81 Node_format *loaded_nodes_list;
82 uint32_t loaded_num_nodes;
83 unsigned int loaded_nodes_index;
84
85 Shared_Keys shared_keys_recv;
86 Shared_Keys shared_keys_sent;
87
88 struct Ping *ping;
89 Ping_Array *dht_ping_array;
90 Ping_Array *dht_harden_ping_array;
91 uint64_t last_run;
92
93 Cryptopacket_Handles cryptopackethandlers[256];
94
95 Node_format to_bootstrap[MAX_CLOSE_TO_BOOTSTRAP_NODES];
96 unsigned int num_to_bootstrap;
97};
98
99const uint8_t *dht_get_self_public_key(const DHT *dht)
100{
101 return dht->self_public_key;
102}
103const uint8_t *dht_get_self_secret_key(const DHT *dht)
104{
105 return dht->self_secret_key;
106}
107
108void dht_set_self_public_key(DHT *dht, const uint8_t *key)
109{
110 memcpy(dht->self_public_key, key, CRYPTO_PUBLIC_KEY_SIZE);
111}
112void dht_set_self_secret_key(DHT *dht, const uint8_t *key)
113{
114 memcpy(dht->self_secret_key, key, CRYPTO_SECRET_KEY_SIZE);
115}
116
117Networking_Core *dht_get_net(const DHT *dht)
118{
119 return dht->net;
120}
121struct Ping *dht_get_ping(const DHT *dht)
122{
123 return dht->ping;
124}
125const Client_data *dht_get_close_clientlist(const DHT *dht)
126{
127 return dht->close_clientlist;
128}
129const Client_data *dht_get_close_client(const DHT *dht, uint32_t client_num)
130{
131 assert(client_num < sizeof(dht->close_clientlist) / sizeof(dht->close_clientlist[0]));
132 return &dht->close_clientlist[client_num];
133}
134uint16_t dht_get_num_friends(const DHT *dht)
135{
136 return dht->num_friends;
137}
138
139DHT_Friend *dht_get_friend(DHT *dht, uint32_t friend_num)
140{
141 assert(friend_num < dht->num_friends);
142 return &dht->friends_list[friend_num];
143}
144const uint8_t *dht_get_friend_public_key(const DHT *dht, uint32_t friend_num)
145{
146 assert(friend_num < dht->num_friends);
147 return dht->friends_list[friend_num].public_key;
148}
149
62/* Compares pk1 and pk2 with pk. 150/* Compares pk1 and pk2 with pk.
63 * 151 *
64 * return 0 if both are same distance. 152 * return 0 if both are same distance.