diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-01-15 01:23:08 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-01-16 20:06:07 +0000 |
commit | 643eea60bb9dcf4ecb33d64666b1bc77cbfd7438 (patch) | |
tree | 2f98b0c7869fddac03f834be508a182da06f07b4 | |
parent | 22db2b9fe581a35300b66126604d12e83c2eafb1 (diff) |
Make DHT a module-private type.
-rw-r--r-- | auto_tests/helpers.h | 3 | ||||
-rw-r--r-- | auto_tests/onion_test.c | 56 | ||||
-rw-r--r-- | other/DHT_bootstrap.c | 21 | ||||
-rw-r--r-- | other/bootstrap_daemon/src/tox-bootstrapd.c | 16 | ||||
-rw-r--r-- | testing/DHT_test.c | 26 | ||||
-rw-r--r-- | toxcore/DHT.c | 88 | ||||
-rw-r--r-- | toxcore/DHT.h | 44 | ||||
-rw-r--r-- | toxcore/LAN_discovery.c | 17 | ||||
-rw-r--r-- | toxcore/Messenger.c | 19 | ||||
-rw-r--r-- | toxcore/group.c | 2 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 26 | ||||
-rw-r--r-- | toxcore/onion.c | 12 | ||||
-rw-r--r-- | toxcore/onion_announce.c | 8 | ||||
-rw-r--r-- | toxcore/onion_client.c | 6 | ||||
-rw-r--r-- | toxcore/ping.c | 32 | ||||
-rw-r--r-- | toxcore/tox.c | 2 |
16 files changed, 229 insertions, 149 deletions
diff --git a/auto_tests/helpers.h b/auto_tests/helpers.h index 20085d6e..745c5d22 100644 --- a/auto_tests/helpers.h +++ b/auto_tests/helpers.h | |||
@@ -51,8 +51,7 @@ static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *path, uint3 | |||
51 | return; | 51 | return; |
52 | } | 52 | } |
53 | 53 | ||
54 | if (strncmp(message, "Bound successfully to ", strlen("Bound successfully to ")) || | 54 | if (strncmp(message, "Bound successfully to ", strlen("Bound successfully to "))) { |
55 | strncmp(message, "Found node in LAN: ", strlen("Found node in LAN: "))) { | ||
56 | return; | 55 | return; |
57 | } | 56 | } |
58 | 57 | ||
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 28fcbb40..7db683de 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c | |||
@@ -102,7 +102,8 @@ static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, ui | |||
102 | #if 0 | 102 | #if 0 |
103 | print_client_id(packet, length); | 103 | print_client_id(packet, length); |
104 | #endif | 104 | #endif |
105 | int len = decrypt_data(test_3_pub_key, onion->dht->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, | 105 | int len = decrypt_data(test_3_pub_key, dht_get_self_secret_key(onion->dht), |
106 | packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, | ||
106 | packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE, | 107 | packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + CRYPTO_NONCE_SIZE, |
107 | 1 + CRYPTO_SHA256_SIZE + CRYPTO_MAC_SIZE, plain); | 108 | 1 + CRYPTO_SHA256_SIZE + CRYPTO_MAC_SIZE, plain); |
108 | 109 | ||
@@ -140,7 +141,7 @@ static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, ui | |||
140 | return 1; | 141 | return 1; |
141 | } | 142 | } |
142 | 143 | ||
143 | int len = decrypt_data(packet + 1 + CRYPTO_NONCE_SIZE, onion->dht->self_secret_key, packet + 1, | 144 | int len = decrypt_data(packet + 1 + CRYPTO_NONCE_SIZE, dht_get_self_secret_key(onion->dht), packet + 1, |
144 | packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, sizeof("Install gentoo") + CRYPTO_MAC_SIZE, plain); | 145 | packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, sizeof("Install gentoo") + CRYPTO_MAC_SIZE, plain); |
145 | 146 | ||
146 | if (len == -1) { | 147 | if (len == -1) { |
@@ -165,12 +166,12 @@ START_TEST(test_basic) | |||
165 | 166 | ||
166 | IP_Port on1 = {ip, net_port(onion1->net)}; | 167 | IP_Port on1 = {ip, net_port(onion1->net)}; |
167 | Node_format n1; | 168 | Node_format n1; |
168 | memcpy(n1.public_key, onion1->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 169 | memcpy(n1.public_key, dht_get_self_public_key(onion1->dht), CRYPTO_PUBLIC_KEY_SIZE); |
169 | n1.ip_port = on1; | 170 | n1.ip_port = on1; |
170 | 171 | ||
171 | IP_Port on2 = {ip, net_port(onion2->net)}; | 172 | IP_Port on2 = {ip, net_port(onion2->net)}; |
172 | Node_format n2; | 173 | Node_format n2; |
173 | memcpy(n2.public_key, onion2->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 174 | memcpy(n2.public_key, dht_get_self_public_key(onion2->dht), CRYPTO_PUBLIC_KEY_SIZE); |
174 | n2.ip_port = on2; | 175 | n2.ip_port = on2; |
175 | 176 | ||
176 | Node_format nodes[4]; | 177 | Node_format nodes[4]; |
@@ -208,9 +209,12 @@ START_TEST(test_basic) | |||
208 | uint64_t s; | 209 | uint64_t s; |
209 | memcpy(&s, sb_data, sizeof(uint64_t)); | 210 | memcpy(&s, sb_data, sizeof(uint64_t)); |
210 | memcpy(test_3_pub_key, nodes[3].public_key, CRYPTO_PUBLIC_KEY_SIZE); | 211 | memcpy(test_3_pub_key, nodes[3].public_key, CRYPTO_PUBLIC_KEY_SIZE); |
211 | ret = send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, | 212 | ret = send_announce_request(onion1->net, &path, nodes[3], |
212 | onion1->dht->self_secret_key, | 213 | dht_get_self_public_key(onion1->dht), |
213 | zeroes, onion1->dht->self_public_key, onion1->dht->self_public_key, s); | 214 | dht_get_self_secret_key(onion1->dht), |
215 | zeroes, | ||
216 | dht_get_self_public_key(onion1->dht), | ||
217 | dht_get_self_public_key(onion1->dht), s); | ||
214 | ck_assert_msg(ret == 0, "Failed to create/send onion announce_request packet."); | 218 | ck_assert_msg(ret == 0, "Failed to create/send onion announce_request packet."); |
215 | handled_test_3 = 0; | 219 | handled_test_3 = 0; |
216 | 220 | ||
@@ -222,13 +226,18 @@ START_TEST(test_basic) | |||
222 | 226 | ||
223 | random_bytes(sb_data, sizeof(sb_data)); | 227 | random_bytes(sb_data, sizeof(sb_data)); |
224 | memcpy(&s, sb_data, sizeof(uint64_t)); | 228 | memcpy(&s, sb_data, sizeof(uint64_t)); |
225 | memcpy(onion_announce_entry_public_key(onion2_a, 1), onion2->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 229 | memcpy(onion_announce_entry_public_key(onion2_a, 1), dht_get_self_public_key(onion2->dht), CRYPTO_PUBLIC_KEY_SIZE); |
226 | onion_announce_entry_set_time(onion2_a, 1, unix_time()); | 230 | onion_announce_entry_set_time(onion2_a, 1, unix_time()); |
227 | networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1); | 231 | networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1); |
228 | send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, onion1->dht->self_secret_key, | 232 | send_announce_request(onion1->net, &path, nodes[3], |
229 | test_3_ping_id, onion1->dht->self_public_key, onion1->dht->self_public_key, s); | 233 | dht_get_self_public_key(onion1->dht), |
230 | 234 | dht_get_self_secret_key(onion1->dht), | |
231 | while (memcmp(onion_announce_entry_public_key(onion2_a, ONION_ANNOUNCE_MAX_ENTRIES - 2), onion1->dht->self_public_key, | 235 | test_3_ping_id, |
236 | dht_get_self_public_key(onion1->dht), | ||
237 | dht_get_self_public_key(onion1->dht), s); | ||
238 | |||
239 | while (memcmp(onion_announce_entry_public_key(onion2_a, ONION_ANNOUNCE_MAX_ENTRIES - 2), | ||
240 | dht_get_self_public_key(onion1->dht), | ||
232 | CRYPTO_PUBLIC_KEY_SIZE) != 0) { | 241 | CRYPTO_PUBLIC_KEY_SIZE) != 0) { |
233 | do_onion(onion1); | 242 | do_onion(onion1); |
234 | do_onion(onion2); | 243 | do_onion(onion2); |
@@ -240,8 +249,9 @@ START_TEST(test_basic) | |||
240 | ck_assert_msg((onion3 != NULL), "Onion failed initializing."); | 249 | ck_assert_msg((onion3 != NULL), "Onion failed initializing."); |
241 | 250 | ||
242 | random_nonce(nonce); | 251 | random_nonce(nonce); |
243 | ret = send_data_request(onion3->net, &path, nodes[3].ip_port, onion1->dht->self_public_key, | 252 | ret = send_data_request(onion3->net, &path, nodes[3].ip_port, |
244 | onion1->dht->self_public_key, | 253 | dht_get_self_public_key(onion1->dht), |
254 | dht_get_self_public_key(onion1->dht), | ||
245 | nonce, (const uint8_t *)"Install gentoo", sizeof("Install gentoo")); | 255 | nonce, (const uint8_t *)"Install gentoo", sizeof("Install gentoo")); |
246 | ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet."); | 256 | ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet."); |
247 | handled_test_4 = 0; | 257 | handled_test_4 = 0; |
@@ -258,7 +268,7 @@ START_TEST(test_basic) | |||
258 | { | 268 | { |
259 | Onion *onion = onion1; | 269 | Onion *onion = onion1; |
260 | 270 | ||
261 | Networking_Core *net = onion->dht->net; | 271 | Networking_Core *net = dht_get_net(onion->dht); |
262 | DHT *dht = onion->dht; | 272 | DHT *dht = onion->dht; |
263 | kill_onion(onion); | 273 | kill_onion(onion); |
264 | kill_DHT(dht); | 274 | kill_DHT(dht); |
@@ -268,7 +278,7 @@ START_TEST(test_basic) | |||
268 | { | 278 | { |
269 | Onion *onion = onion2; | 279 | Onion *onion = onion2; |
270 | 280 | ||
271 | Networking_Core *net = onion->dht->net; | 281 | Networking_Core *net = dht_get_net(onion->dht); |
272 | DHT *dht = onion->dht; | 282 | DHT *dht = onion->dht; |
273 | kill_onion(onion); | 283 | kill_onion(onion); |
274 | kill_DHT(dht); | 284 | kill_DHT(dht); |
@@ -278,7 +288,7 @@ START_TEST(test_basic) | |||
278 | { | 288 | { |
279 | Onion *onion = onion3; | 289 | Onion *onion = onion3; |
280 | 290 | ||
281 | Networking_Core *net = onion->dht->net; | 291 | Networking_Core *net = dht_get_net(onion->dht); |
282 | DHT *dht = onion->dht; | 292 | DHT *dht = onion->dht; |
283 | kill_onion(onion); | 293 | kill_onion(onion); |
284 | kill_DHT(dht); | 294 | kill_DHT(dht); |
@@ -361,7 +371,7 @@ static void do_onions(Onions *on) | |||
361 | 371 | ||
362 | static void kill_onions(Onions *on) | 372 | static void kill_onions(Onions *on) |
363 | { | 373 | { |
364 | Networking_Core *net = on->onion->dht->net; | 374 | Networking_Core *net = dht_get_net(on->onion->dht); |
365 | DHT *dht = on->onion->dht; | 375 | DHT *dht = on->onion->dht; |
366 | Net_Crypto *c = onion_get_net_crypto(on->onion_c); | 376 | Net_Crypto *c = onion_get_net_crypto(on->onion_c); |
367 | kill_onion_client(on->onion_c); | 377 | kill_onion_client(on->onion_c); |
@@ -444,11 +454,11 @@ START_TEST(test_announce) | |||
444 | 454 | ||
445 | for (i = 3; i < NUM_ONIONS; ++i) { | 455 | for (i = 3; i < NUM_ONIONS; ++i) { |
446 | IP_Port ip_port = {ip, net_port(onions[i - 1]->onion->net)}; | 456 | IP_Port ip_port = {ip, net_port(onions[i - 1]->onion->net)}; |
447 | DHT_bootstrap(onions[i]->onion->dht, ip_port, onions[i - 1]->onion->dht->self_public_key); | 457 | DHT_bootstrap(onions[i]->onion->dht, ip_port, dht_get_self_public_key(onions[i - 1]->onion->dht)); |
448 | IP_Port ip_port1 = {ip, net_port(onions[i - 2]->onion->net)}; | 458 | IP_Port ip_port1 = {ip, net_port(onions[i - 2]->onion->net)}; |
449 | DHT_bootstrap(onions[i]->onion->dht, ip_port1, onions[i - 2]->onion->dht->self_public_key); | 459 | DHT_bootstrap(onions[i]->onion->dht, ip_port1, dht_get_self_public_key(onions[i - 2]->onion->dht)); |
450 | IP_Port ip_port2 = {ip, net_port(onions[i - 3]->onion->net)}; | 460 | IP_Port ip_port2 = {ip, net_port(onions[i - 3]->onion->net)}; |
451 | DHT_bootstrap(onions[i]->onion->dht, ip_port2, onions[i - 3]->onion->dht->self_public_key); | 461 | DHT_bootstrap(onions[i]->onion->dht, ip_port2, dht_get_self_public_key(onions[i - 3]->onion->dht)); |
452 | } | 462 | } |
453 | 463 | ||
454 | uint32_t connected = 0; | 464 | uint32_t connected = 0; |
@@ -474,8 +484,8 @@ START_TEST(test_announce) | |||
474 | c_sleep(50); | 484 | c_sleep(50); |
475 | } | 485 | } |
476 | 486 | ||
477 | memcpy(first_dht_pk, onions[NUM_FIRST]->onion->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 487 | memcpy(first_dht_pk, dht_get_self_public_key(onions[NUM_FIRST]->onion->dht), CRYPTO_PUBLIC_KEY_SIZE); |
478 | memcpy(last_dht_pk, onions[NUM_LAST]->onion->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 488 | memcpy(last_dht_pk, dht_get_self_public_key(onions[NUM_LAST]->onion->dht), CRYPTO_PUBLIC_KEY_SIZE); |
479 | 489 | ||
480 | printf("adding friend\n"); | 490 | printf("adding friend\n"); |
481 | int frnum_f = onion_addfriend(onions[NUM_FIRST]->onion_c, | 491 | int frnum_f = onion_addfriend(onions[NUM_FIRST]->onion_c, |
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 5eae46b9..33ca45c2 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c | |||
@@ -70,12 +70,12 @@ static void manage_keys(DHT *dht) | |||
70 | exit(1); | 70 | exit(1); |
71 | } | 71 | } |
72 | 72 | ||
73 | memcpy(dht->self_public_key, keys, CRYPTO_PUBLIC_KEY_SIZE); | 73 | dht_set_self_public_key(dht, keys); |
74 | memcpy(dht->self_secret_key, keys + CRYPTO_PUBLIC_KEY_SIZE, CRYPTO_SECRET_KEY_SIZE); | 74 | dht_set_self_public_key(dht, keys + CRYPTO_PUBLIC_KEY_SIZE); |
75 | printf("Keys loaded successfully.\n"); | 75 | printf("Keys loaded successfully.\n"); |
76 | } else { | 76 | } else { |
77 | memcpy(keys, dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 77 | memcpy(keys, dht_get_self_public_key(dht), CRYPTO_PUBLIC_KEY_SIZE); |
78 | memcpy(keys + CRYPTO_PUBLIC_KEY_SIZE, dht->self_secret_key, CRYPTO_SECRET_KEY_SIZE); | 78 | memcpy(keys + CRYPTO_PUBLIC_KEY_SIZE, dht_get_self_secret_key(dht), CRYPTO_SECRET_KEY_SIZE); |
79 | keys_file = fopen("key", "w"); | 79 | keys_file = fopen("key", "w"); |
80 | 80 | ||
81 | if (keys_file == NULL) { | 81 | if (keys_file == NULL) { |
@@ -120,7 +120,7 @@ int main(int argc, char *argv[]) | |||
120 | Onion_Announce *onion_a = new_onion_announce(dht); | 120 | Onion_Announce *onion_a = new_onion_announce(dht); |
121 | 121 | ||
122 | #ifdef DHT_NODE_EXTRA_PACKETS | 122 | #ifdef DHT_NODE_EXTRA_PACKETS |
123 | bootstrap_set_callbacks(dht->net, DHT_VERSION_NUMBER, DHT_MOTD, sizeof(DHT_MOTD)); | 123 | bootstrap_set_callbacks(dht_get_net(dht), DHT_VERSION_NUMBER, DHT_MOTD, sizeof(DHT_MOTD)); |
124 | #endif | 124 | #endif |
125 | 125 | ||
126 | if (!(onion && onion_a)) { | 126 | if (!(onion && onion_a)) { |
@@ -137,7 +137,7 @@ int main(int argc, char *argv[]) | |||
137 | #ifdef TCP_RELAY_ENABLED | 137 | #ifdef TCP_RELAY_ENABLED |
138 | #define NUM_PORTS 3 | 138 | #define NUM_PORTS 3 |
139 | uint16_t ports[NUM_PORTS] = {443, 3389, PORT}; | 139 | uint16_t ports[NUM_PORTS] = {443, 3389, PORT}; |
140 | TCP_Server *tcp_s = new_TCP_server(ipv6enabled, NUM_PORTS, ports, dht->self_secret_key, onion); | 140 | TCP_Server *tcp_s = new_TCP_server(ipv6enabled, NUM_PORTS, ports, dht_get_self_secret_key(dht), onion); |
141 | 141 | ||
142 | if (tcp_s == NULL) { | 142 | if (tcp_s == NULL) { |
143 | printf("TCP server failed to initialize.\n"); | 143 | printf("TCP server failed to initialize.\n"); |
@@ -155,14 +155,15 @@ int main(int argc, char *argv[]) | |||
155 | } | 155 | } |
156 | 156 | ||
157 | for (i = 0; i < 32; i++) { | 157 | for (i = 0; i < 32; i++) { |
158 | printf("%02hhX", dht->self_public_key[i]); | 158 | const uint8_t *const self_public_key = dht_get_self_public_key(dht); |
159 | fprintf(file, "%02hhX", dht->self_public_key[i]); | 159 | printf("%02hhX", self_public_key[i]); |
160 | fprintf(file, "%02hhX", self_public_key[i]); | ||
160 | } | 161 | } |
161 | 162 | ||
162 | fclose(file); | 163 | fclose(file); |
163 | 164 | ||
164 | printf("\n"); | 165 | printf("\n"); |
165 | printf("Port: %u\n", net_ntohs(net_port(dht->net))); | 166 | printf("Port: %u\n", net_ntohs(net_port(dht_get_net(dht)))); |
166 | 167 | ||
167 | if (argc > argvoffset + 3) { | 168 | if (argc > argvoffset + 3) { |
168 | printf("Trying to bootstrap into the network...\n"); | 169 | printf("Trying to bootstrap into the network...\n"); |
@@ -199,7 +200,7 @@ int main(int argc, char *argv[]) | |||
199 | #ifdef TCP_RELAY_ENABLED | 200 | #ifdef TCP_RELAY_ENABLED |
200 | do_TCP_server(tcp_s); | 201 | do_TCP_server(tcp_s); |
201 | #endif | 202 | #endif |
202 | networking_poll(dht->net, NULL); | 203 | networking_poll(dht_get_net(dht), NULL); |
203 | 204 | ||
204 | c_sleep(1); | 205 | c_sleep(1); |
205 | } | 206 | } |
diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index c6780fa3..e0472cba 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c | |||
@@ -73,12 +73,12 @@ static int manage_keys(DHT *dht, char *keys_file_path) | |||
73 | return 0; | 73 | return 0; |
74 | } | 74 | } |
75 | 75 | ||
76 | memcpy(dht->self_public_key, keys, CRYPTO_PUBLIC_KEY_SIZE); | 76 | dht_set_self_public_key(dht, keys); |
77 | memcpy(dht->self_secret_key, keys + CRYPTO_PUBLIC_KEY_SIZE, CRYPTO_SECRET_KEY_SIZE); | 77 | dht_set_self_secret_key(dht, keys + CRYPTO_PUBLIC_KEY_SIZE); |
78 | } else { | 78 | } else { |
79 | // Otherwise save new keys | 79 | // Otherwise save new keys |
80 | memcpy(keys, dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 80 | memcpy(keys, dht_get_self_public_key(dht), CRYPTO_PUBLIC_KEY_SIZE); |
81 | memcpy(keys + CRYPTO_PUBLIC_KEY_SIZE, dht->self_secret_key, CRYPTO_SECRET_KEY_SIZE); | 81 | memcpy(keys + CRYPTO_PUBLIC_KEY_SIZE, dht_get_self_secret_key(dht), CRYPTO_SECRET_KEY_SIZE); |
82 | 82 | ||
83 | keys_file = fopen(keys_file_path, "w"); | 83 | keys_file = fopen(keys_file_path, "w"); |
84 | 84 | ||
@@ -261,7 +261,7 @@ int main(int argc, char *argv[]) | |||
261 | } | 261 | } |
262 | 262 | ||
263 | if (enable_motd) { | 263 | if (enable_motd) { |
264 | if (bootstrap_set_callbacks(dht->net, DAEMON_VERSION_NUMBER, (uint8_t *)motd, strlen(motd) + 1) == 0) { | 264 | if (bootstrap_set_callbacks(dht_get_net(dht), DAEMON_VERSION_NUMBER, (uint8_t *)motd, strlen(motd) + 1) == 0) { |
265 | log_write(LOG_LEVEL_INFO, "Set MOTD successfully.\n"); | 265 | log_write(LOG_LEVEL_INFO, "Set MOTD successfully.\n"); |
266 | } else { | 266 | } else { |
267 | log_write(LOG_LEVEL_ERROR, "Couldn't set MOTD: %s. Exiting.\n", motd); | 267 | log_write(LOG_LEVEL_ERROR, "Couldn't set MOTD: %s. Exiting.\n", motd); |
@@ -288,7 +288,7 @@ int main(int argc, char *argv[]) | |||
288 | return 1; | 288 | return 1; |
289 | } | 289 | } |
290 | 290 | ||
291 | tcp_server = new_TCP_server(enable_ipv6, tcp_relay_port_count, tcp_relay_ports, dht->self_secret_key, onion); | 291 | tcp_server = new_TCP_server(enable_ipv6, tcp_relay_port_count, tcp_relay_ports, dht_get_self_secret_key(dht), onion); |
292 | 292 | ||
293 | // tcp_relay_port_count != 0 at this point | 293 | // tcp_relay_port_count != 0 at this point |
294 | free(tcp_relay_ports); | 294 | free(tcp_relay_ports); |
@@ -308,7 +308,7 @@ int main(int argc, char *argv[]) | |||
308 | return 1; | 308 | return 1; |
309 | } | 309 | } |
310 | 310 | ||
311 | print_public_key(dht->self_public_key); | 311 | print_public_key(dht_get_self_public_key(dht)); |
312 | 312 | ||
313 | uint64_t last_LANdiscovery = 0; | 313 | uint64_t last_LANdiscovery = 0; |
314 | const uint16_t net_htons_port = net_htons(port); | 314 | const uint16_t net_htons_port = net_htons(port); |
@@ -332,7 +332,7 @@ int main(int argc, char *argv[]) | |||
332 | do_TCP_server(tcp_server); | 332 | do_TCP_server(tcp_server); |
333 | } | 333 | } |
334 | 334 | ||
335 | networking_poll(dht->net, NULL); | 335 | networking_poll(dht_get_net(dht), NULL); |
336 | 336 | ||
337 | if (waiting_for_dht_connection && DHT_isconnected(dht)) { | 337 | if (waiting_for_dht_connection && DHT_isconnected(dht)) { |
338 | log_write(LOG_LEVEL_INFO, "Connected to another bootstrap node successfully.\n"); | 338 | log_write(LOG_LEVEL_INFO, "Connected to another bootstrap node successfully.\n"); |
diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 6e65bf3a..c9d34238 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c | |||
@@ -49,7 +49,7 @@ | |||
49 | 49 | ||
50 | static uint8_t zeroes_cid[CRYPTO_PUBLIC_KEY_SIZE]; | 50 | static uint8_t zeroes_cid[CRYPTO_PUBLIC_KEY_SIZE]; |
51 | 51 | ||
52 | static void print_client_id(uint8_t *public_key) | 52 | static void print_client_id(const uint8_t *public_key) |
53 | { | 53 | { |
54 | uint32_t j; | 54 | uint32_t j; |
55 | 55 | ||
@@ -58,7 +58,7 @@ static void print_client_id(uint8_t *public_key) | |||
58 | } | 58 | } |
59 | } | 59 | } |
60 | 60 | ||
61 | static void print_hardening(Hardening *h) | 61 | static void print_hardening(const Hardening *h) |
62 | { | 62 | { |
63 | printf("Hardening:\n"); | 63 | printf("Hardening:\n"); |
64 | printf("routes_requests_ok: %hhu\n", h->routes_requests_ok); | 64 | printf("routes_requests_ok: %hhu\n", h->routes_requests_ok); |
@@ -76,9 +76,9 @@ static void print_hardening(Hardening *h) | |||
76 | printf("\n\n"); | 76 | printf("\n\n"); |
77 | } | 77 | } |
78 | 78 | ||
79 | static void print_assoc(IPPTsPng *assoc, uint8_t ours) | 79 | static void print_assoc(const IPPTsPng *assoc, uint8_t ours) |
80 | { | 80 | { |
81 | IP_Port *ipp = &assoc->ip_port; | 81 | const IP_Port *ipp = &assoc->ip_port; |
82 | char ip_str[IP_NTOA_LEN]; | 82 | char ip_str[IP_NTOA_LEN]; |
83 | printf("\nIP: %s Port: %u", ip_ntoa(&ipp->ip, ip_str, sizeof(ip_str)), net_ntohs(ipp->port)); | 83 | printf("\nIP: %s Port: %u", ip_ntoa(&ipp->ip, ip_str, sizeof(ip_str)), net_ntohs(ipp->port)); |
84 | printf("\nTimestamp: %llu", (long long unsigned int) assoc->timestamp); | 84 | printf("\nTimestamp: %llu", (long long unsigned int) assoc->timestamp); |
@@ -102,7 +102,7 @@ static void print_clientlist(DHT *dht) | |||
102 | printf("___________________CLOSE________________________________\n"); | 102 | printf("___________________CLOSE________________________________\n"); |
103 | 103 | ||
104 | for (i = 0; i < LCLIENT_LIST; i++) { | 104 | for (i = 0; i < LCLIENT_LIST; i++) { |
105 | Client_data *client = &dht->close_clientlist[i]; | 105 | const Client_data *client = dht_get_close_client(dht, i); |
106 | 106 | ||
107 | if (public_key_cmp(client->public_key, zeroes_cid) == 0) { | 107 | if (public_key_cmp(client->public_key, zeroes_cid) == 0) { |
108 | continue; | 108 | continue; |
@@ -122,20 +122,20 @@ static void print_friendlist(DHT *dht) | |||
122 | IP_Port p_ip; | 122 | IP_Port p_ip; |
123 | printf("_________________FRIENDS__________________________________\n"); | 123 | printf("_________________FRIENDS__________________________________\n"); |
124 | 124 | ||
125 | for (k = 0; k < dht->num_friends; k++) { | 125 | for (k = 0; k < dht_get_num_friends(dht); k++) { |
126 | printf("FRIEND %u\n", k); | 126 | printf("FRIEND %u\n", k); |
127 | printf("ID: "); | 127 | printf("ID: "); |
128 | 128 | ||
129 | print_client_id(dht->friends_list[k].public_key); | 129 | print_client_id(dht_get_friend_public_key(dht, k)); |
130 | 130 | ||
131 | int friendok = DHT_getfriendip(dht, dht->friends_list[k].public_key, &p_ip); | 131 | int friendok = DHT_getfriendip(dht, dht_get_friend_public_key(dht, k), &p_ip); |
132 | char ip_str[IP_NTOA_LEN]; | 132 | char ip_str[IP_NTOA_LEN]; |
133 | printf("\nIP: %s:%u (%d)", ip_ntoa(&p_ip.ip, ip_str, sizeof(ip_str)), net_ntohs(p_ip.port), friendok); | 133 | printf("\nIP: %s:%u (%d)", ip_ntoa(&p_ip.ip, ip_str, sizeof(ip_str)), net_ntohs(p_ip.port), friendok); |
134 | 134 | ||
135 | printf("\nCLIENTS IN LIST:\n\n"); | 135 | printf("\nCLIENTS IN LIST:\n\n"); |
136 | 136 | ||
137 | for (i = 0; i < MAX_FRIEND_CLIENTS; i++) { | 137 | for (i = 0; i < MAX_FRIEND_CLIENTS; i++) { |
138 | Client_data *client = &dht->friends_list[k].client_list[i]; | 138 | const Client_data *client = &dht_get_friend(dht, k)->client_list[i]; |
139 | 139 | ||
140 | if (public_key_cmp(client->public_key, zeroes_cid) == 0) { | 140 | if (public_key_cmp(client->public_key, zeroes_cid) == 0) { |
141 | continue; | 141 | continue; |
@@ -195,11 +195,13 @@ int main(int argc, char *argv[]) | |||
195 | uint32_t i; | 195 | uint32_t i; |
196 | 196 | ||
197 | for (i = 0; i < 32; i++) { | 197 | for (i = 0; i < 32; i++) { |
198 | if (dht->self_public_key[i] < 16) { | 198 | const uint8_t *const self_public_key = dht_get_self_public_key(dht); |
199 | |||
200 | if (self_public_key[i] < 16) { | ||
199 | printf("0"); | 201 | printf("0"); |
200 | } | 202 | } |
201 | 203 | ||
202 | printf("%hhX", dht->self_public_key[i]); | 204 | printf("%hhX", self_public_key[i]); |
203 | } | 205 | } |
204 | 206 | ||
205 | char temp_id[128]; | 207 | char temp_id[128]; |
@@ -250,7 +252,7 @@ int main(int argc, char *argv[]) | |||
250 | } | 252 | } |
251 | 253 | ||
252 | #endif | 254 | #endif |
253 | networking_poll(dht->net, NULL); | 255 | networking_poll(dht_get_net(dht), NULL); |
254 | 256 | ||
255 | print_clientlist(dht); | 257 | print_clientlist(dht); |
256 | print_friendlist(dht); | 258 | print_friendlist(dht); |
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 | ||
62 | struct 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 | |||
99 | const uint8_t *dht_get_self_public_key(const DHT *dht) | ||
100 | { | ||
101 | return dht->self_public_key; | ||
102 | } | ||
103 | const uint8_t *dht_get_self_secret_key(const DHT *dht) | ||
104 | { | ||
105 | return dht->self_secret_key; | ||
106 | } | ||
107 | |||
108 | void dht_set_self_public_key(DHT *dht, const uint8_t *key) | ||
109 | { | ||
110 | memcpy(dht->self_public_key, key, CRYPTO_PUBLIC_KEY_SIZE); | ||
111 | } | ||
112 | void 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 | |||
117 | Networking_Core *dht_get_net(const DHT *dht) | ||
118 | { | ||
119 | return dht->net; | ||
120 | } | ||
121 | struct Ping *dht_get_ping(const DHT *dht) | ||
122 | { | ||
123 | return dht->ping; | ||
124 | } | ||
125 | const Client_data *dht_get_close_clientlist(const DHT *dht) | ||
126 | { | ||
127 | return dht->close_clientlist; | ||
128 | } | ||
129 | const 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 | } | ||
134 | uint16_t dht_get_num_friends(const DHT *dht) | ||
135 | { | ||
136 | return dht->num_friends; | ||
137 | } | ||
138 | |||
139 | DHT_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 | } | ||
144 | const 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. |
diff --git a/toxcore/DHT.h b/toxcore/DHT.h index 8fdd80b0..808470fc 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h | |||
@@ -240,42 +240,22 @@ typedef struct { | |||
240 | } Cryptopacket_Handles; | 240 | } Cryptopacket_Handles; |
241 | 241 | ||
242 | #define DHT_DEFINED | 242 | #define DHT_DEFINED |
243 | typedef struct DHT { | 243 | typedef struct DHT DHT; |
244 | Logger *log; | ||
245 | Networking_Core *net; | ||
246 | 244 | ||
247 | bool hole_punching_enabled; | 245 | const uint8_t *dht_get_self_public_key(const DHT *dht); |
246 | const uint8_t *dht_get_self_secret_key(const DHT *dht); | ||
247 | void dht_set_self_public_key(DHT *dht, const uint8_t *key); | ||
248 | void dht_set_self_secret_key(DHT *dht, const uint8_t *key); | ||
248 | 249 | ||
249 | Client_data close_clientlist[LCLIENT_LIST]; | 250 | Networking_Core *dht_get_net(const DHT *dht); |
250 | uint64_t close_lastgetnodes; | 251 | struct Ping *dht_get_ping(const DHT *dht); |
251 | uint32_t close_bootstrap_times; | 252 | const Client_data *dht_get_close_clientlist(const DHT *dht); |
253 | const Client_data *dht_get_close_client(const DHT *dht, uint32_t client_num); | ||
254 | uint16_t dht_get_num_friends(const DHT *dht); | ||
252 | 255 | ||
253 | /* Note: this key should not be/is not used to transmit any sensitive materials */ | 256 | DHT_Friend *dht_get_friend(DHT *dht, uint32_t friend_num); |
254 | uint8_t secret_symmetric_key[CRYPTO_SYMMETRIC_KEY_SIZE]; | 257 | const uint8_t *dht_get_friend_public_key(const DHT *dht, uint32_t friend_num); |
255 | /* DHT keypair */ | ||
256 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; | ||
257 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; | ||
258 | 258 | ||
259 | DHT_Friend *friends_list; | ||
260 | uint16_t num_friends; | ||
261 | |||
262 | Node_format *loaded_nodes_list; | ||
263 | uint32_t loaded_num_nodes; | ||
264 | unsigned int loaded_nodes_index; | ||
265 | |||
266 | Shared_Keys shared_keys_recv; | ||
267 | Shared_Keys shared_keys_sent; | ||
268 | |||
269 | struct Ping *ping; | ||
270 | Ping_Array *dht_ping_array; | ||
271 | Ping_Array *dht_harden_ping_array; | ||
272 | uint64_t last_run; | ||
273 | |||
274 | Cryptopacket_Handles cryptopackethandlers[256]; | ||
275 | |||
276 | Node_format to_bootstrap[MAX_CLOSE_TO_BOOTSTRAP_NODES]; | ||
277 | unsigned int num_to_bootstrap; | ||
278 | } DHT; | ||
279 | /*----------------------------------------------------------------------------------*/ | 259 | /*----------------------------------------------------------------------------------*/ |
280 | 260 | ||
281 | /* Shared key generations are costly, it is therefor smart to store commonly used | 261 | /* Shared key generations are costly, it is therefor smart to store commonly used |
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index b5cf2c52..c0724ad9 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c | |||
@@ -356,7 +356,6 @@ static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *pack | |||
356 | 356 | ||
357 | char ip_str[IP_NTOA_LEN] = { 0 }; | 357 | char ip_str[IP_NTOA_LEN] = { 0 }; |
358 | ip_ntoa(&source.ip, ip_str, sizeof(ip_str)); | 358 | ip_ntoa(&source.ip, ip_str, sizeof(ip_str)); |
359 | LOGGER_DEBUG(dht->log, "Found node in LAN: %s", ip_str); | ||
360 | 359 | ||
361 | DHT_bootstrap(dht, source, packet + 1); | 360 | DHT_bootstrap(dht, source, packet + 1); |
362 | return 0; | 361 | return 0; |
@@ -367,30 +366,30 @@ int lan_discovery_send(uint16_t port, DHT *dht) | |||
367 | { | 366 | { |
368 | uint8_t data[CRYPTO_PUBLIC_KEY_SIZE + 1]; | 367 | uint8_t data[CRYPTO_PUBLIC_KEY_SIZE + 1]; |
369 | data[0] = NET_PACKET_LAN_DISCOVERY; | 368 | data[0] = NET_PACKET_LAN_DISCOVERY; |
370 | id_copy(data + 1, dht->self_public_key); | 369 | id_copy(data + 1, dht_get_self_public_key(dht)); |
371 | 370 | ||
372 | send_broadcasts(dht->net, port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE); | 371 | send_broadcasts(dht_get_net(dht), port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE); |
373 | 372 | ||
374 | int res = -1; | 373 | int res = -1; |
375 | IP_Port ip_port; | 374 | IP_Port ip_port; |
376 | ip_port.port = port; | 375 | ip_port.port = port; |
377 | 376 | ||
378 | /* IPv6 multicast */ | 377 | /* IPv6 multicast */ |
379 | if (net_family(dht->net) == TOX_AF_INET6) { | 378 | if (net_family(dht_get_net(dht)) == TOX_AF_INET6) { |
380 | ip_port.ip = broadcast_ip(TOX_AF_INET6, TOX_AF_INET6); | 379 | ip_port.ip = broadcast_ip(TOX_AF_INET6, TOX_AF_INET6); |
381 | 380 | ||
382 | if (ip_isset(&ip_port.ip)) { | 381 | if (ip_isset(&ip_port.ip)) { |
383 | if (sendpacket(dht->net, ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE) > 0) { | 382 | if (sendpacket(dht_get_net(dht), ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE) > 0) { |
384 | res = 1; | 383 | res = 1; |
385 | } | 384 | } |
386 | } | 385 | } |
387 | } | 386 | } |
388 | 387 | ||
389 | /* IPv4 broadcast (has to be IPv4-in-IPv6 mapping if socket is TOX_AF_INET6 */ | 388 | /* IPv4 broadcast (has to be IPv4-in-IPv6 mapping if socket is TOX_AF_INET6 */ |
390 | ip_port.ip = broadcast_ip(net_family(dht->net), TOX_AF_INET); | 389 | ip_port.ip = broadcast_ip(net_family(dht_get_net(dht)), TOX_AF_INET); |
391 | 390 | ||
392 | if (ip_isset(&ip_port.ip)) { | 391 | if (ip_isset(&ip_port.ip)) { |
393 | if (sendpacket(dht->net, ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE)) { | 392 | if (sendpacket(dht_get_net(dht), ip_port, data, 1 + CRYPTO_PUBLIC_KEY_SIZE)) { |
394 | res = 1; | 393 | res = 1; |
395 | } | 394 | } |
396 | } | 395 | } |
@@ -401,10 +400,10 @@ int lan_discovery_send(uint16_t port, DHT *dht) | |||
401 | 400 | ||
402 | void lan_discovery_init(DHT *dht) | 401 | void lan_discovery_init(DHT *dht) |
403 | { | 402 | { |
404 | networking_registerhandler(dht->net, NET_PACKET_LAN_DISCOVERY, &handle_LANdiscovery, dht); | 403 | networking_registerhandler(dht_get_net(dht), NET_PACKET_LAN_DISCOVERY, &handle_LANdiscovery, dht); |
405 | } | 404 | } |
406 | 405 | ||
407 | void lan_discovery_kill(DHT *dht) | 406 | void lan_discovery_kill(DHT *dht) |
408 | { | 407 | { |
409 | networking_registerhandler(dht->net, NET_PACKET_LAN_DISCOVERY, NULL, NULL); | 408 | networking_registerhandler(dht_get_net(dht), NET_PACKET_LAN_DISCOVERY, NULL, NULL); |
410 | } | 409 | } |
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index fcee455c..3cb0fbb6 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -2010,7 +2010,8 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error) | |||
2010 | } | 2010 | } |
2011 | 2011 | ||
2012 | if (options->tcp_server_port) { | 2012 | if (options->tcp_server_port) { |
2013 | m->tcp_server = new_TCP_server(options->ipv6enabled, 1, &options->tcp_server_port, m->dht->self_secret_key, m->onion); | 2013 | m->tcp_server = new_TCP_server(options->ipv6enabled, 1, &options->tcp_server_port, dht_get_self_secret_key(m->dht), |
2014 | m->onion); | ||
2014 | 2015 | ||
2015 | if (m->tcp_server == NULL) { | 2016 | if (m->tcp_server == NULL) { |
2016 | kill_friend_connections(m->fr_c); | 2017 | kill_friend_connections(m->fr_c); |
@@ -2571,8 +2572,8 @@ void do_messenger(Messenger *m, void *userdata) | |||
2571 | uint32_t client, last_pinged; | 2572 | uint32_t client, last_pinged; |
2572 | 2573 | ||
2573 | for (client = 0; client < LCLIENT_LIST; client++) { | 2574 | for (client = 0; client < LCLIENT_LIST; client++) { |
2574 | Client_data *cptr = &m->dht->close_clientlist[client]; | 2575 | const Client_data *cptr = dht_get_close_client(m->dht, client); |
2575 | IPPTsPng *assoc = NULL; | 2576 | const IPPTsPng *assoc = NULL; |
2576 | uint32_t a; | 2577 | uint32_t a; |
2577 | 2578 | ||
2578 | for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6) { | 2579 | for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6) { |
@@ -2597,7 +2598,7 @@ void do_messenger(Messenger *m, void *userdata) | |||
2597 | uint32_t friend_idx, dhtfriend; | 2598 | uint32_t friend_idx, dhtfriend; |
2598 | 2599 | ||
2599 | /* dht contains additional "friends" (requests) */ | 2600 | /* dht contains additional "friends" (requests) */ |
2600 | uint32_t num_dhtfriends = m->dht->num_friends; | 2601 | uint32_t num_dhtfriends = dht_get_num_friends(m->dht); |
2601 | VLA(int32_t, m2dht, num_dhtfriends); | 2602 | VLA(int32_t, m2dht, num_dhtfriends); |
2602 | VLA(int32_t, dht2m, num_dhtfriends); | 2603 | VLA(int32_t, dht2m, num_dhtfriends); |
2603 | 2604 | ||
@@ -2609,8 +2610,8 @@ void do_messenger(Messenger *m, void *userdata) | |||
2609 | continue; | 2610 | continue; |
2610 | } | 2611 | } |
2611 | 2612 | ||
2612 | for (dhtfriend = 0; dhtfriend < m->dht->num_friends; dhtfriend++) { | 2613 | for (dhtfriend = 0; dhtfriend < dht_get_num_friends(m->dht); dhtfriend++) { |
2613 | if (id_equal(m->friendlist[friend_idx].real_pk, m->dht->friends_list[dhtfriend].public_key)) { | 2614 | if (id_equal(m->friendlist[friend_idx].real_pk, dht_get_friend_public_key(m->dht, dhtfriend))) { |
2614 | m2dht[friend_idx] = dhtfriend; | 2615 | m2dht[friend_idx] = dhtfriend; |
2615 | break; | 2616 | break; |
2616 | } | 2617 | } |
@@ -2623,8 +2624,8 @@ void do_messenger(Messenger *m, void *userdata) | |||
2623 | } | 2624 | } |
2624 | } | 2625 | } |
2625 | 2626 | ||
2626 | if (m->numfriends != m->dht->num_friends) { | 2627 | if (m->numfriends != dht_get_num_friends(m->dht)) { |
2627 | LOGGER_TRACE(m->log, "Friend num in DHT %u != friend num in msger %u\n", m->dht->num_friends, m->numfriends); | 2628 | LOGGER_TRACE(m->log, "Friend num in DHT %u != friend num in msger %u\n", dht_get_num_friends(m->dht), m->numfriends); |
2628 | } | 2629 | } |
2629 | 2630 | ||
2630 | Friend *msgfptr; | 2631 | Friend *msgfptr; |
@@ -2637,7 +2638,7 @@ void do_messenger(Messenger *m, void *userdata) | |||
2637 | msgfptr = NULL; | 2638 | msgfptr = NULL; |
2638 | } | 2639 | } |
2639 | 2640 | ||
2640 | dhtfptr = &m->dht->friends_list[friend_idx]; | 2641 | dhtfptr = dht_get_friend(m->dht, friend_idx); |
2641 | 2642 | ||
2642 | if (msgfptr) { | 2643 | if (msgfptr) { |
2643 | char id_str[IDSTRING_LEN]; | 2644 | char id_str[IDSTRING_LEN]; |
diff --git a/toxcore/group.c b/toxcore/group.c index 30f241ad..543b1f0a 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -744,7 +744,7 @@ int add_groupchat(Group_Chats *g_c, uint8_t type) | |||
744 | g->identifier[0] = type; | 744 | g->identifier[0] = type; |
745 | g->peer_number = 0; /* Founder is peer 0. */ | 745 | g->peer_number = 0; /* Founder is peer 0. */ |
746 | memcpy(g->real_pk, nc_get_self_public_key(g_c->m->net_crypto), CRYPTO_PUBLIC_KEY_SIZE); | 746 | memcpy(g->real_pk, nc_get_self_public_key(g_c->m->net_crypto), CRYPTO_PUBLIC_KEY_SIZE); |
747 | int peer_index = addpeer(g_c, groupnumber, g->real_pk, g_c->m->dht->self_public_key, 0, NULL, false); | 747 | int peer_index = addpeer(g_c, groupnumber, g->real_pk, dht_get_self_public_key(g_c->m->dht), 0, NULL, false); |
748 | 748 | ||
749 | if (peer_index == -1) { | 749 | if (peer_index == -1) { |
750 | return -1; | 750 | return -1; |
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 521dad2f..f03ddb87 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -223,7 +223,7 @@ static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, uint8_t * | |||
223 | uint8_t nonce[CRYPTO_NONCE_SIZE]; | 223 | uint8_t nonce[CRYPTO_NONCE_SIZE]; |
224 | random_nonce(nonce); | 224 | random_nonce(nonce); |
225 | packet[0] = NET_PACKET_COOKIE_REQUEST; | 225 | packet[0] = NET_PACKET_COOKIE_REQUEST; |
226 | memcpy(packet + 1, c->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 226 | memcpy(packet + 1, dht_get_self_public_key(c->dht), CRYPTO_PUBLIC_KEY_SIZE); |
227 | memcpy(packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, nonce, CRYPTO_NONCE_SIZE); | 227 | memcpy(packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, nonce, CRYPTO_NONCE_SIZE); |
228 | int len = encrypt_data_symmetric(shared_key, nonce, plain, sizeof(plain), | 228 | int len = encrypt_data_symmetric(shared_key, nonce, plain, sizeof(plain), |
229 | packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE); | 229 | packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE); |
@@ -362,7 +362,7 @@ static int udp_handle_cookie_request(void *object, IP_Port source, const uint8_t | |||
362 | return 1; | 362 | return 1; |
363 | } | 363 | } |
364 | 364 | ||
365 | if ((uint32_t)sendpacket(c->dht->net, source, data, sizeof(data)) != sizeof(data)) { | 365 | if ((uint32_t)sendpacket(dht_get_net(c->dht), source, data, sizeof(data)) != sizeof(data)) { |
366 | return 1; | 366 | return 1; |
367 | } | 367 | } |
368 | 368 | ||
@@ -662,7 +662,7 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t | |||
662 | crypto_connection_status(c, crypt_connection_id, &direct_connected, NULL); | 662 | crypto_connection_status(c, crypt_connection_id, &direct_connected, NULL); |
663 | 663 | ||
664 | if (direct_connected) { | 664 | if (direct_connected) { |
665 | if ((uint32_t)sendpacket(c->dht->net, ip_port, data, length) == length) { | 665 | if ((uint32_t)sendpacket(dht_get_net(c->dht), ip_port, data, length) == length) { |
666 | pthread_mutex_unlock(&conn->mutex); | 666 | pthread_mutex_unlock(&conn->mutex); |
667 | return 0; | 667 | return 0; |
668 | } | 668 | } |
@@ -676,7 +676,7 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t | |||
676 | 676 | ||
677 | if ((((UDP_DIRECT_TIMEOUT / 2) + conn->direct_send_attempt_time) > current_time && length < 96) | 677 | if ((((UDP_DIRECT_TIMEOUT / 2) + conn->direct_send_attempt_time) > current_time && length < 96) |
678 | || data[0] == NET_PACKET_COOKIE_REQUEST || data[0] == NET_PACKET_CRYPTO_HS) { | 678 | || data[0] == NET_PACKET_COOKIE_REQUEST || data[0] == NET_PACKET_CRYPTO_HS) { |
679 | if ((uint32_t)sendpacket(c->dht->net, ip_port, data, length) == length) { | 679 | if ((uint32_t)sendpacket(dht_get_net(c->dht), ip_port, data, length) == length) { |
680 | direct_send_attempt = 1; | 680 | direct_send_attempt = 1; |
681 | conn->direct_send_attempt_time = unix_time(); | 681 | conn->direct_send_attempt_time = unix_time(); |
682 | } | 682 | } |
@@ -2941,7 +2941,7 @@ Net_Crypto *new_net_crypto(Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info) | |||
2941 | 2941 | ||
2942 | temp->log = log; | 2942 | temp->log = log; |
2943 | 2943 | ||
2944 | temp->tcp_c = new_tcp_connections(dht->self_secret_key, proxy_info); | 2944 | temp->tcp_c = new_tcp_connections(dht_get_self_secret_key(dht), proxy_info); |
2945 | 2945 | ||
2946 | if (temp->tcp_c == NULL) { | 2946 | if (temp->tcp_c == NULL) { |
2947 | free(temp); | 2947 | free(temp); |
@@ -2965,10 +2965,10 @@ Net_Crypto *new_net_crypto(Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info) | |||
2965 | 2965 | ||
2966 | temp->current_sleep_time = CRYPTO_SEND_PACKET_INTERVAL; | 2966 | temp->current_sleep_time = CRYPTO_SEND_PACKET_INTERVAL; |
2967 | 2967 | ||
2968 | networking_registerhandler(dht->net, NET_PACKET_COOKIE_REQUEST, &udp_handle_cookie_request, temp); | 2968 | networking_registerhandler(dht_get_net(dht), NET_PACKET_COOKIE_REQUEST, &udp_handle_cookie_request, temp); |
2969 | networking_registerhandler(dht->net, NET_PACKET_COOKIE_RESPONSE, &udp_handle_packet, temp); | 2969 | networking_registerhandler(dht_get_net(dht), NET_PACKET_COOKIE_RESPONSE, &udp_handle_packet, temp); |
2970 | networking_registerhandler(dht->net, NET_PACKET_CRYPTO_HS, &udp_handle_packet, temp); | 2970 | networking_registerhandler(dht_get_net(dht), NET_PACKET_CRYPTO_HS, &udp_handle_packet, temp); |
2971 | networking_registerhandler(dht->net, NET_PACKET_CRYPTO_DATA, &udp_handle_packet, temp); | 2971 | networking_registerhandler(dht_get_net(dht), NET_PACKET_CRYPTO_DATA, &udp_handle_packet, temp); |
2972 | 2972 | ||
2973 | bs_list_init(&temp->ip_port_list, sizeof(IP_Port), 8); | 2973 | bs_list_init(&temp->ip_port_list, sizeof(IP_Port), 8); |
2974 | 2974 | ||
@@ -3039,10 +3039,10 @@ void kill_net_crypto(Net_Crypto *c) | |||
3039 | 3039 | ||
3040 | kill_tcp_connections(c->tcp_c); | 3040 | kill_tcp_connections(c->tcp_c); |
3041 | bs_list_free(&c->ip_port_list); | 3041 | bs_list_free(&c->ip_port_list); |
3042 | networking_registerhandler(c->dht->net, NET_PACKET_COOKIE_REQUEST, NULL, NULL); | 3042 | networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_REQUEST, NULL, NULL); |
3043 | networking_registerhandler(c->dht->net, NET_PACKET_COOKIE_RESPONSE, NULL, NULL); | 3043 | networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_RESPONSE, NULL, NULL); |
3044 | networking_registerhandler(c->dht->net, NET_PACKET_CRYPTO_HS, NULL, NULL); | 3044 | networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_HS, NULL, NULL); |
3045 | networking_registerhandler(c->dht->net, NET_PACKET_CRYPTO_DATA, NULL, NULL); | 3045 | networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_DATA, NULL, NULL); |
3046 | crypto_memzero(c, sizeof(Net_Crypto)); | 3046 | crypto_memzero(c, sizeof(Net_Crypto)); |
3047 | free(c); | 3047 | free(c); |
3048 | } | 3048 | } |
diff --git a/toxcore/onion.c b/toxcore/onion.c index fbaf7205..2279d4e3 100644 --- a/toxcore/onion.c +++ b/toxcore/onion.c | |||
@@ -120,8 +120,8 @@ int create_onion_path(const DHT *dht, Onion_Path *new_path, const Node_format *n | |||
120 | return -1; | 120 | return -1; |
121 | } | 121 | } |
122 | 122 | ||
123 | encrypt_precompute(nodes[0].public_key, dht->self_secret_key, new_path->shared_key1); | 123 | encrypt_precompute(nodes[0].public_key, dht_get_self_secret_key(dht), new_path->shared_key1); |
124 | memcpy(new_path->public_key1, dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 124 | memcpy(new_path->public_key1, dht_get_self_public_key(dht), CRYPTO_PUBLIC_KEY_SIZE); |
125 | 125 | ||
126 | uint8_t random_public_key[CRYPTO_PUBLIC_KEY_SIZE]; | 126 | uint8_t random_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
127 | uint8_t random_secret_key[CRYPTO_SECRET_KEY_SIZE]; | 127 | uint8_t random_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
@@ -338,7 +338,7 @@ static int handle_send_initial(void *object, IP_Port source, const uint8_t *pack | |||
338 | 338 | ||
339 | uint8_t plain[ONION_MAX_PACKET_SIZE]; | 339 | uint8_t plain[ONION_MAX_PACKET_SIZE]; |
340 | uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; | 340 | uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; |
341 | get_shared_key(&onion->shared_keys_1, shared_key, onion->dht->self_secret_key, packet + 1 + CRYPTO_NONCE_SIZE); | 341 | get_shared_key(&onion->shared_keys_1, shared_key, dht_get_self_secret_key(onion->dht), packet + 1 + CRYPTO_NONCE_SIZE); |
342 | int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, | 342 | int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, |
343 | length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE), plain); | 343 | length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE), plain); |
344 | 344 | ||
@@ -407,7 +407,7 @@ static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, ui | |||
407 | 407 | ||
408 | uint8_t plain[ONION_MAX_PACKET_SIZE]; | 408 | uint8_t plain[ONION_MAX_PACKET_SIZE]; |
409 | uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; | 409 | uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; |
410 | get_shared_key(&onion->shared_keys_2, shared_key, onion->dht->self_secret_key, packet + 1 + CRYPTO_NONCE_SIZE); | 410 | get_shared_key(&onion->shared_keys_2, shared_key, dht_get_self_secret_key(onion->dht), packet + 1 + CRYPTO_NONCE_SIZE); |
411 | int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, | 411 | int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, |
412 | length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + RETURN_1), plain); | 412 | length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + RETURN_1), plain); |
413 | 413 | ||
@@ -463,7 +463,7 @@ static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, ui | |||
463 | 463 | ||
464 | uint8_t plain[ONION_MAX_PACKET_SIZE]; | 464 | uint8_t plain[ONION_MAX_PACKET_SIZE]; |
465 | uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; | 465 | uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; |
466 | get_shared_key(&onion->shared_keys_3, shared_key, onion->dht->self_secret_key, packet + 1 + CRYPTO_NONCE_SIZE); | 466 | get_shared_key(&onion->shared_keys_3, shared_key, dht_get_self_secret_key(onion->dht), packet + 1 + CRYPTO_NONCE_SIZE); |
467 | int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, | 467 | int len = decrypt_data_symmetric(shared_key, packet + 1, packet + 1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE, |
468 | length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + RETURN_2), plain); | 468 | length - (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + RETURN_2), plain); |
469 | 469 | ||
@@ -646,7 +646,7 @@ Onion *new_onion(DHT *dht) | |||
646 | } | 646 | } |
647 | 647 | ||
648 | onion->dht = dht; | 648 | onion->dht = dht; |
649 | onion->net = dht->net; | 649 | onion->net = dht_get_net(dht); |
650 | new_symmetric_key(onion->secret_symmetric_key); | 650 | new_symmetric_key(onion->secret_symmetric_key); |
651 | onion->timestamp = unix_time(); | 651 | onion->timestamp = unix_time(); |
652 | 652 | ||
diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index ab96a546..0ff22a3d 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c | |||
@@ -343,7 +343,7 @@ static int add_to_entries(Onion_Announce *onion_a, IP_Port ret_ip_port, const ui | |||
343 | } | 343 | } |
344 | 344 | ||
345 | if (pos == -1) { | 345 | if (pos == -1) { |
346 | if (id_closest(onion_a->dht->self_public_key, public_key, onion_a->entries[0].public_key) == 1) { | 346 | if (id_closest(dht_get_self_public_key(onion_a->dht), public_key, onion_a->entries[0].public_key) == 1) { |
347 | pos = 0; | 347 | pos = 0; |
348 | } | 348 | } |
349 | } | 349 | } |
@@ -358,7 +358,7 @@ static int add_to_entries(Onion_Announce *onion_a, IP_Port ret_ip_port, const ui | |||
358 | memcpy(onion_a->entries[pos].data_public_key, data_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 358 | memcpy(onion_a->entries[pos].data_public_key, data_public_key, CRYPTO_PUBLIC_KEY_SIZE); |
359 | onion_a->entries[pos].time = unix_time(); | 359 | onion_a->entries[pos].time = unix_time(); |
360 | 360 | ||
361 | sort_onion_announce_list(onion_a->entries, ONION_ANNOUNCE_MAX_ENTRIES, onion_a->dht->self_public_key); | 361 | sort_onion_announce_list(onion_a->entries, ONION_ANNOUNCE_MAX_ENTRIES, dht_get_self_public_key(onion_a->dht)); |
362 | return in_entries(onion_a, public_key); | 362 | return in_entries(onion_a, public_key); |
363 | } | 363 | } |
364 | 364 | ||
@@ -372,7 +372,7 @@ static int handle_announce_request(void *object, IP_Port source, const uint8_t * | |||
372 | 372 | ||
373 | const uint8_t *packet_public_key = packet + 1 + CRYPTO_NONCE_SIZE; | 373 | const uint8_t *packet_public_key = packet + 1 + CRYPTO_NONCE_SIZE; |
374 | uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; | 374 | uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; |
375 | get_shared_key(&onion_a->shared_keys_recv, shared_key, onion_a->dht->self_secret_key, packet_public_key); | 375 | get_shared_key(&onion_a->shared_keys_recv, shared_key, dht_get_self_secret_key(onion_a->dht), packet_public_key); |
376 | 376 | ||
377 | uint8_t plain[ONION_PING_ID_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_PUBLIC_KEY_SIZE + | 377 | uint8_t plain[ONION_PING_ID_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_PUBLIC_KEY_SIZE + |
378 | ONION_ANNOUNCE_SENDBACK_DATA_LENGTH]; | 378 | ONION_ANNOUNCE_SENDBACK_DATA_LENGTH]; |
@@ -504,7 +504,7 @@ Onion_Announce *new_onion_announce(DHT *dht) | |||
504 | } | 504 | } |
505 | 505 | ||
506 | onion_a->dht = dht; | 506 | onion_a->dht = dht; |
507 | onion_a->net = dht->net; | 507 | onion_a->net = dht_get_net(dht); |
508 | new_symmetric_key(onion_a->secret_bytes); | 508 | new_symmetric_key(onion_a->secret_bytes); |
509 | 509 | ||
510 | networking_registerhandler(onion_a->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_announce_request, onion_a); | 510 | networking_registerhandler(onion_a->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_announce_request, onion_a); |
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index f7ff41bd..c652d7f3 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -1133,7 +1133,7 @@ static int send_dht_dhtpk(const Onion_Client *onion_c, int friend_num, const uin | |||
1133 | } | 1133 | } |
1134 | 1134 | ||
1135 | uint8_t packet[MAX_CRYPTO_REQUEST_SIZE]; | 1135 | uint8_t packet[MAX_CRYPTO_REQUEST_SIZE]; |
1136 | len = create_request(onion_c->dht->self_public_key, onion_c->dht->self_secret_key, packet, | 1136 | len = create_request(dht_get_self_public_key(onion_c->dht), dht_get_self_secret_key(onion_c->dht), packet, |
1137 | onion_c->friends_list[friend_num].dht_public_key, temp, SIZEOF_VLA(temp), CRYPTO_PACKET_DHTPK); | 1137 | onion_c->friends_list[friend_num].dht_public_key, temp, SIZEOF_VLA(temp), CRYPTO_PACKET_DHTPK); |
1138 | 1138 | ||
1139 | if (len == -1) { | 1139 | if (len == -1) { |
@@ -1192,7 +1192,7 @@ static int send_dhtpk_announce(Onion_Client *onion_c, uint16_t friend_num, uint8 | |||
1192 | uint64_t no_replay = unix_time(); | 1192 | uint64_t no_replay = unix_time(); |
1193 | host_to_net((uint8_t *)&no_replay, sizeof(no_replay)); | 1193 | host_to_net((uint8_t *)&no_replay, sizeof(no_replay)); |
1194 | memcpy(data + 1, &no_replay, sizeof(no_replay)); | 1194 | memcpy(data + 1, &no_replay, sizeof(no_replay)); |
1195 | memcpy(data + 1 + sizeof(uint64_t), onion_c->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 1195 | memcpy(data + 1 + sizeof(uint64_t), dht_get_self_public_key(onion_c->dht), CRYPTO_PUBLIC_KEY_SIZE); |
1196 | Node_format nodes[MAX_SENT_NODES]; | 1196 | Node_format nodes[MAX_SENT_NODES]; |
1197 | uint16_t num_relays = copy_connected_tcp_relays(onion_c->c, nodes, (MAX_SENT_NODES / 2)); | 1197 | uint16_t num_relays = copy_connected_tcp_relays(onion_c->c, nodes, (MAX_SENT_NODES / 2)); |
1198 | uint16_t num_nodes = closelist_nodes(onion_c->dht, &nodes[num_relays], MAX_SENT_NODES - num_relays); | 1198 | uint16_t num_nodes = closelist_nodes(onion_c->dht, &nodes[num_relays], MAX_SENT_NODES - num_relays); |
@@ -1864,7 +1864,7 @@ Onion_Client *new_onion_client(Net_Crypto *c) | |||
1864 | } | 1864 | } |
1865 | 1865 | ||
1866 | onion_c->dht = nc_get_dht(c); | 1866 | onion_c->dht = nc_get_dht(c); |
1867 | onion_c->net = onion_c->dht->net; | 1867 | onion_c->net = dht_get_net(onion_c->dht); |
1868 | onion_c->c = c; | 1868 | onion_c->c = c; |
1869 | new_symmetric_key(onion_c->secret_symmetric_key); | 1869 | new_symmetric_key(onion_c->secret_symmetric_key); |
1870 | crypto_new_keypair(onion_c->temp_public_key, onion_c->temp_secret_key); | 1870 | crypto_new_keypair(onion_c->temp_public_key, onion_c->temp_secret_key); |
diff --git a/toxcore/ping.c b/toxcore/ping.c index f2f56013..1e5892eb 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c | |||
@@ -64,7 +64,7 @@ int32_t ping_send_request(Ping *ping, IP_Port ipp, const uint8_t *public_key) | |||
64 | int rc; | 64 | int rc; |
65 | uint64_t ping_id; | 65 | uint64_t ping_id; |
66 | 66 | ||
67 | if (id_equal(public_key, ping->dht->self_public_key)) { | 67 | if (id_equal(public_key, dht_get_self_public_key(ping->dht))) { |
68 | return 1; | 68 | return 1; |
69 | } | 69 | } |
70 | 70 | ||
@@ -87,7 +87,7 @@ int32_t ping_send_request(Ping *ping, IP_Port ipp, const uint8_t *public_key) | |||
87 | memcpy(ping_plain + 1, &ping_id, sizeof(ping_id)); | 87 | memcpy(ping_plain + 1, &ping_id, sizeof(ping_id)); |
88 | 88 | ||
89 | pk[0] = NET_PACKET_PING_REQUEST; | 89 | pk[0] = NET_PACKET_PING_REQUEST; |
90 | id_copy(pk + 1, ping->dht->self_public_key); // Our pubkey | 90 | id_copy(pk + 1, dht_get_self_public_key(ping->dht)); // Our pubkey |
91 | random_nonce(pk + 1 + CRYPTO_PUBLIC_KEY_SIZE); // Generate new nonce | 91 | random_nonce(pk + 1 + CRYPTO_PUBLIC_KEY_SIZE); // Generate new nonce |
92 | 92 | ||
93 | 93 | ||
@@ -100,7 +100,7 @@ int32_t ping_send_request(Ping *ping, IP_Port ipp, const uint8_t *public_key) | |||
100 | return 1; | 100 | return 1; |
101 | } | 101 | } |
102 | 102 | ||
103 | return sendpacket(ping->dht->net, ipp, pk, sizeof(pk)); | 103 | return sendpacket(dht_get_net(ping->dht), ipp, pk, sizeof(pk)); |
104 | } | 104 | } |
105 | 105 | ||
106 | static int ping_send_response(Ping *ping, IP_Port ipp, const uint8_t *public_key, uint64_t ping_id, | 106 | static int ping_send_response(Ping *ping, IP_Port ipp, const uint8_t *public_key, uint64_t ping_id, |
@@ -109,7 +109,7 @@ static int ping_send_response(Ping *ping, IP_Port ipp, const uint8_t *public_key | |||
109 | uint8_t pk[DHT_PING_SIZE]; | 109 | uint8_t pk[DHT_PING_SIZE]; |
110 | int rc; | 110 | int rc; |
111 | 111 | ||
112 | if (id_equal(public_key, ping->dht->self_public_key)) { | 112 | if (id_equal(public_key, dht_get_self_public_key(ping->dht))) { |
113 | return 1; | 113 | return 1; |
114 | } | 114 | } |
115 | 115 | ||
@@ -118,7 +118,7 @@ static int ping_send_response(Ping *ping, IP_Port ipp, const uint8_t *public_key | |||
118 | memcpy(ping_plain + 1, &ping_id, sizeof(ping_id)); | 118 | memcpy(ping_plain + 1, &ping_id, sizeof(ping_id)); |
119 | 119 | ||
120 | pk[0] = NET_PACKET_PING_RESPONSE; | 120 | pk[0] = NET_PACKET_PING_RESPONSE; |
121 | id_copy(pk + 1, ping->dht->self_public_key); // Our pubkey | 121 | id_copy(pk + 1, dht_get_self_public_key(ping->dht)); // Our pubkey |
122 | random_nonce(pk + 1 + CRYPTO_PUBLIC_KEY_SIZE); // Generate new nonce | 122 | random_nonce(pk + 1 + CRYPTO_PUBLIC_KEY_SIZE); // Generate new nonce |
123 | 123 | ||
124 | // Encrypt ping_id using recipient privkey | 124 | // Encrypt ping_id using recipient privkey |
@@ -131,7 +131,7 @@ static int ping_send_response(Ping *ping, IP_Port ipp, const uint8_t *public_key | |||
131 | return 1; | 131 | return 1; |
132 | } | 132 | } |
133 | 133 | ||
134 | return sendpacket(ping->dht->net, ipp, pk, sizeof(pk)); | 134 | return sendpacket(dht_get_net(ping->dht), ipp, pk, sizeof(pk)); |
135 | } | 135 | } |
136 | 136 | ||
137 | static int handle_ping_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) | 137 | static int handle_ping_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) |
@@ -143,9 +143,9 @@ static int handle_ping_request(void *object, IP_Port source, const uint8_t *pack | |||
143 | return 1; | 143 | return 1; |
144 | } | 144 | } |
145 | 145 | ||
146 | Ping *ping = dht->ping; | 146 | Ping *ping = dht_get_ping(dht); |
147 | 147 | ||
148 | if (id_equal(packet + 1, ping->dht->self_public_key)) { | 148 | if (id_equal(packet + 1, dht_get_self_public_key(ping->dht))) { |
149 | return 1; | 149 | return 1; |
150 | } | 150 | } |
151 | 151 | ||
@@ -186,9 +186,9 @@ static int handle_ping_response(void *object, IP_Port source, const uint8_t *pac | |||
186 | return 1; | 186 | return 1; |
187 | } | 187 | } |
188 | 188 | ||
189 | Ping *ping = dht->ping; | 189 | Ping *ping = dht_get_ping(dht); |
190 | 190 | ||
191 | if (id_equal(packet + 1, ping->dht->self_public_key)) { | 191 | if (id_equal(packet + 1, dht_get_self_public_key(ping->dht))) { |
192 | return 1; | 192 | return 1; |
193 | } | 193 | } |
194 | 194 | ||
@@ -284,7 +284,7 @@ int32_t ping_add(Ping *ping, const uint8_t *public_key, IP_Port ip_port) | |||
284 | return -1; | 284 | return -1; |
285 | } | 285 | } |
286 | 286 | ||
287 | if (in_list(ping->dht->close_clientlist, LCLIENT_LIST, public_key, ip_port)) { | 287 | if (in_list(dht_get_close_clientlist(ping->dht), LCLIENT_LIST, public_key, ip_port)) { |
288 | return -1; | 288 | return -1; |
289 | } | 289 | } |
290 | 290 | ||
@@ -309,7 +309,7 @@ int32_t ping_add(Ping *ping, const uint8_t *public_key, IP_Port ip_port) | |||
309 | } | 309 | } |
310 | } | 310 | } |
311 | 311 | ||
312 | if (add_to_list(ping->to_ping, MAX_TO_PING, public_key, ip_port, ping->dht->self_public_key)) { | 312 | if (add_to_list(ping->to_ping, MAX_TO_PING, public_key, ip_port, dht_get_self_public_key(ping->dht))) { |
313 | return 0; | 313 | return 0; |
314 | } | 314 | } |
315 | 315 | ||
@@ -367,16 +367,16 @@ Ping *ping_new(DHT *dht) | |||
367 | } | 367 | } |
368 | 368 | ||
369 | ping->dht = dht; | 369 | ping->dht = dht; |
370 | networking_registerhandler(ping->dht->net, NET_PACKET_PING_REQUEST, &handle_ping_request, dht); | 370 | networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_REQUEST, &handle_ping_request, dht); |
371 | networking_registerhandler(ping->dht->net, NET_PACKET_PING_RESPONSE, &handle_ping_response, dht); | 371 | networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_RESPONSE, &handle_ping_response, dht); |
372 | 372 | ||
373 | return ping; | 373 | return ping; |
374 | } | 374 | } |
375 | 375 | ||
376 | void ping_kill(Ping *ping) | 376 | void ping_kill(Ping *ping) |
377 | { | 377 | { |
378 | networking_registerhandler(ping->dht->net, NET_PACKET_PING_REQUEST, NULL, NULL); | 378 | networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_REQUEST, NULL, NULL); |
379 | networking_registerhandler(ping->dht->net, NET_PACKET_PING_RESPONSE, NULL, NULL); | 379 | networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_RESPONSE, NULL, NULL); |
380 | ping_array_kill(ping->ping_array); | 380 | ping_array_kill(ping->ping_array); |
381 | 381 | ||
382 | free(ping); | 382 | free(ping); |
diff --git a/toxcore/tox.c b/toxcore/tox.c index 2fd478dc..a1f850d1 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -1519,7 +1519,7 @@ void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id) | |||
1519 | { | 1519 | { |
1520 | if (dht_id) { | 1520 | if (dht_id) { |
1521 | const Messenger *m = tox; | 1521 | const Messenger *m = tox; |
1522 | memcpy(dht_id, m->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE); | 1522 | memcpy(dht_id, dht_get_self_public_key(m->dht), CRYPTO_PUBLIC_KEY_SIZE); |
1523 | } | 1523 | } |
1524 | } | 1524 | } |
1525 | 1525 | ||