summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto_tests/dht_test.c22
-rw-r--r--auto_tests/messenger_test.c14
-rw-r--r--auto_tests/onion_test.c38
-rw-r--r--other/DHT_bootstrap.c8
-rw-r--r--other/bootstrap_daemon/src/config.c2
-rw-r--r--other/bootstrap_daemon/src/tox-bootstrapd.c6
-rw-r--r--testing/DHT_test.c12
-rw-r--r--testing/Messenger_test.c2
-rw-r--r--toxcore/DHT.c78
-rw-r--r--toxcore/DHT.h40
-rw-r--r--toxcore/LAN_discovery.c2
-rw-r--r--toxcore/Messenger.c179
-rw-r--r--toxcore/Messenger.h70
-rw-r--r--toxcore/friend_connection.c8
-rw-r--r--toxcore/friend_requests.h5
-rw-r--r--toxcore/group.h7
-rw-r--r--toxcore/net_crypto.c4
-rw-r--r--toxcore/onion_client.c19
-rw-r--r--toxcore/ping.c8
-rw-r--r--toxcore/tox.api.h36
-rw-r--r--toxcore/tox.c164
-rw-r--r--toxcore/tox.h36
-rw-r--r--toxcore/tox_api.c2
-rw-r--r--toxencryptsave/toxencryptsave.c2
24 files changed, 428 insertions, 336 deletions
diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c
index d51825ab..a63a55b0 100644
--- a/auto_tests/dht_test.c
+++ b/auto_tests/dht_test.c
@@ -330,7 +330,7 @@ static void test_addto_lists(IP ip)
330 Networking_Core *net = new_networking(log, ip, TOX_PORT_DEFAULT); 330 Networking_Core *net = new_networking(log, ip, TOX_PORT_DEFAULT);
331 ck_assert_msg(net != nullptr, "Failed to create Networking_Core"); 331 ck_assert_msg(net != nullptr, "Failed to create Networking_Core");
332 332
333 DHT *dht = new_DHT(log, net, true); 333 DHT *dht = new_dht(log, net, true);
334 ck_assert_msg(dht != nullptr, "Failed to create DHT"); 334 ck_assert_msg(dht != nullptr, "Failed to create DHT");
335 335
336 IP_Port ip_port; 336 IP_Port ip_port;
@@ -391,7 +391,7 @@ static void test_addto_lists(IP ip)
391 test_addto_lists_good(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port, 391 test_addto_lists_good(dht, dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, &ip_port,
392 dht->friends_list[i].public_key); 392 dht->friends_list[i].public_key);
393 393
394 kill_DHT(dht); 394 kill_dht(dht);
395 kill_networking(net); 395 kill_networking(net);
396 logger_kill(log); 396 logger_kill(log);
397} 397}
@@ -475,7 +475,7 @@ static void test_list_main(void)
475 index[i] = i + 1; 475 index[i] = i + 1;
476 logger_callback_log(logs[i], (logger_cb *)print_debug_log, nullptr, &index[i]); 476 logger_callback_log(logs[i], (logger_cb *)print_debug_log, nullptr, &index[i]);
477 477
478 dhts[i] = new_DHT(logs[i], new_networking(logs[i], ip, DHT_DEFAULT_PORT + i), true); 478 dhts[i] = new_dht(logs[i], new_networking(logs[i], ip, DHT_DEFAULT_PORT + i), true);
479 ck_assert_msg(dhts[i] != nullptr, "Failed to create dht instances %u", i); 479 ck_assert_msg(dhts[i] != nullptr, "Failed to create dht instances %u", i);
480 ck_assert_msg(net_port(dhts[i]->net) != DHT_DEFAULT_PORT + i, 480 ck_assert_msg(net_port(dhts[i]->net) != DHT_DEFAULT_PORT + i,
481 "Bound to wrong port: %d", net_port(dhts[i]->net)); 481 "Bound to wrong port: %d", net_port(dhts[i]->net));
@@ -580,7 +580,7 @@ static void test_list_main(void)
580 580
581 for (i = 0; i < NUM_DHT; ++i) { 581 for (i = 0; i < NUM_DHT; ++i) {
582 Networking_Core *n = dhts[i]->net; 582 Networking_Core *n = dhts[i]->net;
583 kill_DHT(dhts[i]); 583 kill_dht(dhts[i]);
584 kill_networking(n); 584 kill_networking(n);
585 logger_kill(logs[i]); 585 logger_kill(logs[i]);
586 } 586 }
@@ -620,7 +620,7 @@ START_TEST(test_DHT_test)
620 index[i] = i + 1; 620 index[i] = i + 1;
621 logger_callback_log(logs[i], (logger_cb *)print_debug_log, nullptr, &index[i]); 621 logger_callback_log(logs[i], (logger_cb *)print_debug_log, nullptr, &index[i]);
622 622
623 dhts[i] = new_DHT(logs[i], new_networking(logs[i], ip, DHT_DEFAULT_PORT + i), true); 623 dhts[i] = new_dht(logs[i], new_networking(logs[i], ip, DHT_DEFAULT_PORT + i), true);
624 ck_assert_msg(dhts[i] != nullptr, "Failed to create dht instances %u", i); 624 ck_assert_msg(dhts[i] != nullptr, "Failed to create dht instances %u", i);
625 ck_assert_msg(net_port(dhts[i]->net) != DHT_DEFAULT_PORT + i, "Bound to wrong port"); 625 ck_assert_msg(net_port(dhts[i]->net) != DHT_DEFAULT_PORT + i, "Bound to wrong port");
626 } 626 }
@@ -642,7 +642,7 @@ loop_top:
642 } 642 }
643 643
644 uint16_t lock_count = 0; 644 uint16_t lock_count = 0;
645 ck_assert_msg(DHT_addfriend(dhts[pairs[i].tox2], dhts[pairs[i].tox1]->self_public_key, &ip_callback, &to_comp, 1337, 645 ck_assert_msg(dht_addfriend(dhts[pairs[i].tox2], dhts[pairs[i].tox1]->self_public_key, &ip_callback, &to_comp, 1337,
646 &lock_count) == 0, "Failed to add friend"); 646 &lock_count) == 0, "Failed to add friend");
647 ck_assert_msg(lock_count == 1, "bad lock count: %u %u", lock_count, i); 647 ck_assert_msg(lock_count == 1, "bad lock count: %u %u", lock_count, i);
648 } 648 }
@@ -651,7 +651,7 @@ loop_top:
651 IP_Port ip_port; 651 IP_Port ip_port;
652 ip_port.ip = get_loopback(); 652 ip_port.ip = get_loopback();
653 ip_port.port = net_htons(DHT_DEFAULT_PORT + i); 653 ip_port.port = net_htons(DHT_DEFAULT_PORT + i);
654 DHT_bootstrap(dhts[(i - 1) % NUM_DHT], ip_port, dhts[i]->self_public_key); 654 dht_bootstrap(dhts[(i - 1) % NUM_DHT], ip_port, dhts[i]->self_public_key);
655 } 655 }
656 656
657 while (1) { 657 while (1) {
@@ -660,7 +660,7 @@ loop_top:
660 for (i = 0; i < NUM_DHT_FRIENDS; ++i) { 660 for (i = 0; i < NUM_DHT_FRIENDS; ++i) {
661 IP_Port a; 661 IP_Port a;
662 662
663 if (DHT_getfriendip(dhts[pairs[i].tox2], dhts[pairs[i].tox1]->self_public_key, &a) == 1) { 663 if (dht_getfriendip(dhts[pairs[i].tox2], dhts[pairs[i].tox1]->self_public_key, &a) == 1) {
664 ++counter; 664 ++counter;
665 } 665 }
666 } 666 }
@@ -671,7 +671,7 @@ loop_top:
671 671
672 for (i = 0; i < NUM_DHT; ++i) { 672 for (i = 0; i < NUM_DHT; ++i) {
673 networking_poll(dhts[i]->net, nullptr); 673 networking_poll(dhts[i]->net, nullptr);
674 do_DHT(dhts[i]); 674 do_dht(dhts[i]);
675 } 675 }
676 676
677 c_sleep(500); 677 c_sleep(500);
@@ -679,7 +679,7 @@ loop_top:
679 679
680 for (i = 0; i < NUM_DHT; ++i) { 680 for (i = 0; i < NUM_DHT; ++i) {
681 Networking_Core *n = dhts[i]->net; 681 Networking_Core *n = dhts[i]->net;
682 kill_DHT(dhts[i]); 682 kill_dht(dhts[i]);
683 kill_networking(n); 683 kill_networking(n);
684 logger_kill(logs[i]); 684 logger_kill(logs[i]);
685 } 685 }
@@ -694,7 +694,7 @@ START_TEST(test_dht_create_packet)
694 uint8_t key[CRYPTO_SYMMETRIC_KEY_SIZE]; 694 uint8_t key[CRYPTO_SYMMETRIC_KEY_SIZE];
695 new_symmetric_key(key); 695 new_symmetric_key(key);
696 696
697 int length = DHT_create_packet(key, key, NET_PACKET_GET_NODES, plain, sizeof(plain), pkt); 697 int length = dht_create_packet(key, key, NET_PACKET_GET_NODES, plain, sizeof(plain), pkt);
698 698
699 ck_assert_msg(pkt[0] == NET_PACKET_GET_NODES, "Malformed packet."); 699 ck_assert_msg(pkt[0] == NET_PACKET_GET_NODES, "Malformed packet.");
700 ck_assert_msg(memcmp(pkt + 1, key, CRYPTO_SYMMETRIC_KEY_SIZE) == 0, "Malformed packet."); 700 ck_assert_msg(memcmp(pkt + 1, key, CRYPTO_SYMMETRIC_KEY_SIZE) == 0, "Malformed packet.");
diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c
index d7344f4d..cf42de49 100644
--- a/auto_tests/messenger_test.c
+++ b/auto_tests/messenger_test.c
@@ -241,18 +241,18 @@ START_TEST(test_dht_state_saveloadsave)
241 * c) a second save() is of equal size 241 * c) a second save() is of equal size
242 * d) the second save() is of equal content */ 242 * d) the second save() is of equal content */
243 const size_t extra = 64; 243 const size_t extra = 64;
244 const size_t size = DHT_size(m->dht); 244 const size_t size = dht_size(m->dht);
245 VLA(uint8_t, buffer, size + 2 * extra); 245 VLA(uint8_t, buffer, size + 2 * extra);
246 memset(buffer, 0xCD, extra); 246 memset(buffer, 0xCD, extra);
247 memset(buffer + extra + size, 0xCD, extra); 247 memset(buffer + extra + size, 0xCD, extra);
248 DHT_save(m->dht, buffer + extra); 248 dht_save(m->dht, buffer + extra);
249 249
250 for (size_t i = 0; i < extra; i++) { 250 for (size_t i = 0; i < extra; i++) {
251 ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from DHT_save() @%u", (unsigned)i); 251 ck_assert_msg(buffer[i] == 0xCD, "Buffer underwritten from dht_save() @%u", (unsigned)i);
252 ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from DHT_save() @%u", (unsigned)i); 252 ck_assert_msg(buffer[extra + size + i] == 0xCD, "Buffer overwritten from dht_save() @%u", (unsigned)i);
253 } 253 }
254 254
255 const int res = DHT_load(m->dht, buffer + extra, size); 255 const int res = dht_load(m->dht, buffer + extra, size);
256 256
257 if (res == -1) { 257 if (res == -1) {
258 ck_assert_msg(res == 0, "Failed to load back stored buffer: res == -1"); 258 ck_assert_msg(res == 0, "Failed to load back stored buffer: res == -1");
@@ -264,12 +264,12 @@ START_TEST(test_dht_state_saveloadsave)
264 (unsigned)offset, (unsigned)size, res & 0x0F); 264 (unsigned)offset, (unsigned)size, res & 0x0F);
265 } 265 }
266 266
267 const size_t size2 = DHT_size(m->dht); 267 const size_t size2 = dht_size(m->dht);
268 ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", (unsigned)size, 268 ck_assert_msg(size == size2, "Messenger \"grew\" in size from a store/load cycle: %u -> %u", (unsigned)size,
269 (unsigned)size2); 269 (unsigned)size2);
270 270
271 VLA(uint8_t, buffer2, size2); 271 VLA(uint8_t, buffer2, size2);
272 DHT_save(m->dht, buffer2); 272 dht_save(m->dht, buffer2);
273 273
274 ck_assert_msg(!memcmp(buffer + extra, buffer2, size), "DHT state changed by store/load/store cycle"); 274 ck_assert_msg(!memcmp(buffer + extra, buffer2, size), "DHT state changed by store/load/store cycle");
275} 275}
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c
index 77dc7c49..a4f20cba 100644
--- a/auto_tests/onion_test.c
+++ b/auto_tests/onion_test.c
@@ -40,7 +40,7 @@ static inline IP get_loopback()
40static void do_onion(Onion *onion) 40static void do_onion(Onion *onion)
41{ 41{
42 networking_poll(onion->net, nullptr); 42 networking_poll(onion->net, nullptr);
43 do_DHT(onion->dht); 43 do_dht(onion->dht);
44} 44}
45 45
46static int handled_test_1; 46static int handled_test_1;
@@ -167,8 +167,8 @@ START_TEST(test_basic)
167 logger_callback_log(log2, (logger_cb *)print_debug_log, nullptr, &index[1]); 167 logger_callback_log(log2, (logger_cb *)print_debug_log, nullptr, &index[1]);
168 168
169 IP ip = get_loopback(); 169 IP ip = get_loopback();
170 Onion *onion1 = new_onion(new_DHT(log1, new_networking(log1, ip, 36567), true)); 170 Onion *onion1 = new_onion(new_dht(log1, new_networking(log1, ip, 36567), true));
171 Onion *onion2 = new_onion(new_DHT(log2, new_networking(log2, ip, 36568), true)); 171 Onion *onion2 = new_onion(new_dht(log2, new_networking(log2, ip, 36568), true));
172 ck_assert_msg((onion1 != nullptr) && (onion2 != nullptr), "Onion failed initializing."); 172 ck_assert_msg((onion1 != nullptr) && (onion2 != nullptr), "Onion failed initializing.");
173 networking_registerhandler(onion2->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_test_1, onion2); 173 networking_registerhandler(onion2->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_test_1, onion2);
174 174
@@ -256,7 +256,7 @@ START_TEST(test_basic)
256 Logger *log3 = logger_new(); 256 Logger *log3 = logger_new();
257 logger_callback_log(log3, (logger_cb *)print_debug_log, nullptr, &index[2]); 257 logger_callback_log(log3, (logger_cb *)print_debug_log, nullptr, &index[2]);
258 258
259 Onion *onion3 = new_onion(new_DHT(log3, new_networking(log3, ip, 36569), true)); 259 Onion *onion3 = new_onion(new_dht(log3, new_networking(log3, ip, 36569), true));
260 ck_assert_msg((onion3 != nullptr), "Onion failed initializing."); 260 ck_assert_msg((onion3 != nullptr), "Onion failed initializing.");
261 261
262 random_nonce(nonce); 262 random_nonce(nonce);
@@ -282,7 +282,7 @@ START_TEST(test_basic)
282 Networking_Core *net = dht_get_net(onion->dht); 282 Networking_Core *net = dht_get_net(onion->dht);
283 DHT *dht = onion->dht; 283 DHT *dht = onion->dht;
284 kill_onion(onion); 284 kill_onion(onion);
285 kill_DHT(dht); 285 kill_dht(dht);
286 kill_networking(net); 286 kill_networking(net);
287 logger_kill(log3); 287 logger_kill(log3);
288 } 288 }
@@ -293,7 +293,7 @@ START_TEST(test_basic)
293 Networking_Core *net = dht_get_net(onion->dht); 293 Networking_Core *net = dht_get_net(onion->dht);
294 DHT *dht = onion->dht; 294 DHT *dht = onion->dht;
295 kill_onion(onion); 295 kill_onion(onion);
296 kill_DHT(dht); 296 kill_dht(dht);
297 kill_networking(net); 297 kill_networking(net);
298 logger_kill(log2); 298 logger_kill(log2);
299 } 299 }
@@ -304,7 +304,7 @@ START_TEST(test_basic)
304 Networking_Core *net = dht_get_net(onion->dht); 304 Networking_Core *net = dht_get_net(onion->dht);
305 DHT *dht = onion->dht; 305 DHT *dht = onion->dht;
306 kill_onion(onion); 306 kill_onion(onion);
307 kill_DHT(dht); 307 kill_dht(dht);
308 kill_networking(net); 308 kill_networking(net);
309 logger_kill(log1); 309 logger_kill(log1);
310 } 310 }
@@ -345,7 +345,7 @@ static Onions *new_onions(uint16_t port, uint32_t *index)
345 return nullptr; 345 return nullptr;
346 } 346 }
347 347
348 DHT *dht = new_DHT(on->log, net, true); 348 DHT *dht = new_dht(on->log, net, true);
349 349
350 if (!dht) { 350 if (!dht) {
351 kill_networking(net); 351 kill_networking(net);
@@ -357,7 +357,7 @@ static Onions *new_onions(uint16_t port, uint32_t *index)
357 on->onion = new_onion(dht); 357 on->onion = new_onion(dht);
358 358
359 if (!on->onion) { 359 if (!on->onion) {
360 kill_DHT(dht); 360 kill_dht(dht);
361 kill_networking(net); 361 kill_networking(net);
362 logger_kill(on->log); 362 logger_kill(on->log);
363 free(on); 363 free(on);
@@ -368,7 +368,7 @@ static Onions *new_onions(uint16_t port, uint32_t *index)
368 368
369 if (!on->onion_a) { 369 if (!on->onion_a) {
370 kill_onion(on->onion); 370 kill_onion(on->onion);
371 kill_DHT(dht); 371 kill_dht(dht);
372 kill_networking(net); 372 kill_networking(net);
373 logger_kill(on->log); 373 logger_kill(on->log);
374 free(on); 374 free(on);
@@ -381,7 +381,7 @@ static Onions *new_onions(uint16_t port, uint32_t *index)
381 if (!on->onion_c) { 381 if (!on->onion_c) {
382 kill_onion_announce(on->onion_a); 382 kill_onion_announce(on->onion_a);
383 kill_onion(on->onion); 383 kill_onion(on->onion);
384 kill_DHT(dht); 384 kill_dht(dht);
385 kill_networking(net); 385 kill_networking(net);
386 logger_kill(on->log); 386 logger_kill(on->log);
387 free(on); 387 free(on);
@@ -394,7 +394,7 @@ static Onions *new_onions(uint16_t port, uint32_t *index)
394static void do_onions(Onions *on) 394static void do_onions(Onions *on)
395{ 395{
396 networking_poll(on->onion->net, nullptr); 396 networking_poll(on->onion->net, nullptr);
397 do_DHT(on->onion->dht); 397 do_dht(on->onion->dht);
398 do_onion_client(on->onion_c); 398 do_onion_client(on->onion_c);
399} 399}
400 400
@@ -407,7 +407,7 @@ static void kill_onions(Onions *on)
407 kill_onion_announce(on->onion_a); 407 kill_onion_announce(on->onion_a);
408 kill_onion(on->onion); 408 kill_onion(on->onion);
409 kill_net_crypto(c); 409 kill_net_crypto(c);
410 kill_DHT(dht); 410 kill_dht(dht);
411 kill_networking(net); 411 kill_networking(net);
412 logger_kill(on->log); 412 logger_kill(on->log);
413 free(on); 413 free(on);
@@ -442,8 +442,8 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub
442 if ((NUM_FIRST == number && !first) || (NUM_LAST == number && !last)) { 442 if ((NUM_FIRST == number && !first) || (NUM_LAST == number && !last)) {
443 Onions *on = (Onions *)object; 443 Onions *on = (Onions *)object;
444 uint16_t count = 0; 444 uint16_t count = 0;
445 int ret = DHT_addfriend(on->onion->dht, dht_public_key, &dht_ip_callback, object, number, &count); 445 int ret = dht_addfriend(on->onion->dht, dht_public_key, &dht_ip_callback, object, number, &count);
446 ck_assert_msg(ret == 0, "DHT_addfriend() did not return 0"); 446 ck_assert_msg(ret == 0, "dht_addfriend() did not return 0");
447 ck_assert_msg(count == 1, "Count not 1, count is %u", count); 447 ck_assert_msg(count == 1, "Count not 1, count is %u", count);
448 448
449 if (NUM_FIRST == number && !first) { 449 if (NUM_FIRST == number && !first) {
@@ -486,11 +486,11 @@ START_TEST(test_announce)
486 486
487 for (i = 3; i < NUM_ONIONS; ++i) { 487 for (i = 3; i < NUM_ONIONS; ++i) {
488 IP_Port ip_port = {ip, net_port(onions[i - 1]->onion->net)}; 488 IP_Port ip_port = {ip, net_port(onions[i - 1]->onion->net)};
489 DHT_bootstrap(onions[i]->onion->dht, ip_port, dht_get_self_public_key(onions[i - 1]->onion->dht)); 489 dht_bootstrap(onions[i]->onion->dht, ip_port, dht_get_self_public_key(onions[i - 1]->onion->dht));
490 IP_Port ip_port1 = {ip, net_port(onions[i - 2]->onion->net)}; 490 IP_Port ip_port1 = {ip, net_port(onions[i - 2]->onion->net)};
491 DHT_bootstrap(onions[i]->onion->dht, ip_port1, dht_get_self_public_key(onions[i - 2]->onion->dht)); 491 dht_bootstrap(onions[i]->onion->dht, ip_port1, dht_get_self_public_key(onions[i - 2]->onion->dht));
492 IP_Port ip_port2 = {ip, net_port(onions[i - 3]->onion->net)}; 492 IP_Port ip_port2 = {ip, net_port(onions[i - 3]->onion->net)};
493 DHT_bootstrap(onions[i]->onion->dht, ip_port2, dht_get_self_public_key(onions[i - 3]->onion->dht)); 493 dht_bootstrap(onions[i]->onion->dht, ip_port2, dht_get_self_public_key(onions[i - 3]->onion->dht));
494 } 494 }
495 495
496 uint32_t connected = 0; 496 uint32_t connected = 0;
@@ -500,7 +500,7 @@ START_TEST(test_announce)
500 500
501 for (i = 0; i < NUM_ONIONS; ++i) { 501 for (i = 0; i < NUM_ONIONS; ++i) {
502 do_onions(onions[i]); 502 do_onions(onions[i]);
503 connected += DHT_isconnected(onions[i]->onion->dht); 503 connected += dht_isconnected(onions[i]->onion->dht);
504 } 504 }
505 505
506 c_sleep(50); 506 c_sleep(50);
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c
index ff73c166..f263b471 100644
--- a/other/DHT_bootstrap.c
+++ b/other/DHT_bootstrap.c
@@ -117,7 +117,7 @@ int main(int argc, char *argv[])
117 ip_init(&ip, ipv6enabled); 117 ip_init(&ip, ipv6enabled);
118 118
119 Logger *logger = logger_new(); 119 Logger *logger = logger_new();
120 DHT *dht = new_DHT(logger, new_networking(logger, ip, PORT), true); 120 DHT *dht = new_dht(logger, new_networking(logger, ip, PORT), true);
121 Onion *onion = new_onion(dht); 121 Onion *onion = new_onion(dht);
122 Onion_Announce *onion_a = new_onion_announce(dht); 122 Onion_Announce *onion_a = new_onion_announce(dht);
123 123
@@ -171,7 +171,7 @@ int main(int argc, char *argv[])
171 printf("Trying to bootstrap into the network...\n"); 171 printf("Trying to bootstrap into the network...\n");
172 uint16_t port = net_htons(atoi(argv[argvoffset + 2])); 172 uint16_t port = net_htons(atoi(argv[argvoffset + 2]));
173 uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]); 173 uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
174 int res = DHT_bootstrap_from_address(dht, argv[argvoffset + 1], 174 int res = dht_bootstrap_from_address(dht, argv[argvoffset + 1],
175 ipv6enabled, port, bootstrap_key); 175 ipv6enabled, port, bootstrap_key);
176 free(bootstrap_key); 176 free(bootstrap_key);
177 177
@@ -187,12 +187,12 @@ int main(int argc, char *argv[])
187 lan_discovery_init(dht); 187 lan_discovery_init(dht);
188 188
189 while (1) { 189 while (1) {
190 if (is_waiting_for_dht_connection && DHT_isconnected(dht)) { 190 if (is_waiting_for_dht_connection && dht_isconnected(dht)) {
191 printf("Connected to other bootstrap node successfully.\n"); 191 printf("Connected to other bootstrap node successfully.\n");
192 is_waiting_for_dht_connection = 0; 192 is_waiting_for_dht_connection = 0;
193 } 193 }
194 194
195 do_DHT(dht); 195 do_dht(dht);
196 196
197 if (is_timeout(last_LANdiscovery, is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL)) { 197 if (is_timeout(last_LANdiscovery, is_waiting_for_dht_connection ? 5 : LAN_DISCOVERY_INTERVAL)) {
198 lan_discovery_send(net_htons(PORT), dht); 198 lan_discovery_send(net_htons(PORT), dht);
diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c
index a3c1f250..9fde33b2 100644
--- a/other/bootstrap_daemon/src/config.c
+++ b/other/bootstrap_daemon/src/config.c
@@ -408,7 +408,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
408 } 408 }
409 409
410 bs_public_key_bin = hex_string_to_bin(bs_public_key); 410 bs_public_key_bin = hex_string_to_bin(bs_public_key);
411 address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, net_htons(bs_port), 411 address_resolved = dht_bootstrap_from_address(dht, bs_address, enable_ipv6, net_htons(bs_port),
412 bs_public_key_bin); 412 bs_public_key_bin);
413 free(bs_public_key_bin); 413 free(bs_public_key_bin);
414 414
diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c
index ea849673..3c6d5d2c 100644
--- a/other/bootstrap_daemon/src/tox-bootstrapd.c
+++ b/other/bootstrap_daemon/src/tox-bootstrapd.c
@@ -250,7 +250,7 @@ int main(int argc, char *argv[])
250 } 250 }
251 } 251 }
252 252
253 DHT *dht = new_DHT(logger, net, true); 253 DHT *dht = new_dht(logger, net, true);
254 254
255 if (dht == nullptr) { 255 if (dht == nullptr) {
256 log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox DHT instance. Exiting.\n"); 256 log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox DHT instance. Exiting.\n");
@@ -333,7 +333,7 @@ int main(int argc, char *argv[])
333 } 333 }
334 334
335 while (1) { 335 while (1) {
336 do_DHT(dht); 336 do_dht(dht);
337 337
338 if (enable_lan_discovery && is_timeout(last_LANdiscovery, LAN_DISCOVERY_INTERVAL)) { 338 if (enable_lan_discovery && is_timeout(last_LANdiscovery, LAN_DISCOVERY_INTERVAL)) {
339 lan_discovery_send(net_htons_port, dht); 339 lan_discovery_send(net_htons_port, dht);
@@ -346,7 +346,7 @@ int main(int argc, char *argv[])
346 346
347 networking_poll(dht_get_net(dht), nullptr); 347 networking_poll(dht_get_net(dht), nullptr);
348 348
349 if (waiting_for_dht_connection && DHT_isconnected(dht)) { 349 if (waiting_for_dht_connection && dht_isconnected(dht)) {
350 log_write(LOG_LEVEL_INFO, "Connected to another bootstrap node successfully.\n"); 350 log_write(LOG_LEVEL_INFO, "Connected to another bootstrap node successfully.\n");
351 waiting_for_dht_connection = 0; 351 waiting_for_dht_connection = 0;
352 } 352 }
diff --git a/testing/DHT_test.c b/testing/DHT_test.c
index 59856395..336e7e18 100644
--- a/testing/DHT_test.c
+++ b/testing/DHT_test.c
@@ -128,7 +128,7 @@ static void print_friendlist(DHT *dht)
128 128
129 print_client_id(dht_get_friend_public_key(dht, k)); 129 print_client_id(dht_get_friend_public_key(dht, k));
130 130
131 int friendok = DHT_getfriendip(dht, dht_get_friend_public_key(dht, k), &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
@@ -190,7 +190,7 @@ int main(int argc, char *argv[])
190 IP ip; 190 IP ip;
191 ip_init(&ip, ipv6enabled); 191 ip_init(&ip, ipv6enabled);
192 192
193 DHT *dht = new_DHT(nullptr, new_networking(nullptr, ip, PORT), true); 193 DHT *dht = new_dht(nullptr, new_networking(nullptr, ip, PORT), true);
194 printf("OUR ID: "); 194 printf("OUR ID: ");
195 uint32_t i; 195 uint32_t i;
196 196
@@ -216,14 +216,14 @@ int main(int argc, char *argv[])
216 } 216 }
217 217
218 uint8_t *bin_id = hex_string_to_bin(temp_id); 218 uint8_t *bin_id = hex_string_to_bin(temp_id);
219 DHT_addfriend(dht, bin_id, 0, 0, 0, 0); 219 dht_addfriend(dht, bin_id, 0, 0, 0, 0);
220 free(bin_id); 220 free(bin_id);
221 221
222 perror("Initialization"); 222 perror("Initialization");
223 223
224 uint16_t port = net_htons(atoi(argv[argvoffset + 2])); 224 uint16_t port = net_htons(atoi(argv[argvoffset + 2]));
225 unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]); 225 unsigned char *binary_string = hex_string_to_bin(argv[argvoffset + 3]);
226 int res = DHT_bootstrap_from_address(dht, argv[argvoffset + 1], ipv6enabled, port, binary_string); 226 int res = dht_bootstrap_from_address(dht, argv[argvoffset + 1], ipv6enabled, port, binary_string);
227 free(binary_string); 227 free(binary_string);
228 228
229 if (!res) { 229 if (!res) {
@@ -238,12 +238,12 @@ int main(int argc, char *argv[])
238#endif 238#endif
239 239
240 while (1) { 240 while (1) {
241 do_DHT(dht); 241 do_dht(dht);
242 242
243#if 0 /* TODO(slvr): */ 243#if 0 /* TODO(slvr): */
244 244
245 while (receivepacket(&ip_port, data, &length) != -1) { 245 while (receivepacket(&ip_port, data, &length) != -1) {
246 if (DHT_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port)) { 246 if (dht_handlepacket(data, length, ip_port) && friendreq_handlepacket(data, length, ip_port)) {
247 //unhandled packet 247 //unhandled packet
248 printpacket(data, length, ip_port); 248 printpacket(data, length, ip_port);
249 } else { 249 } else {
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index ebc1975a..7885779b 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -121,7 +121,7 @@ int main(int argc, char *argv[])
121 if (argc == argvoffset + 4) { 121 if (argc == argvoffset + 4) {
122 uint16_t port = net_htons(atoi(argv[argvoffset + 2])); 122 uint16_t port = net_htons(atoi(argv[argvoffset + 2]));
123 uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]); 123 uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]);
124 int res = DHT_bootstrap_from_address(m->dht, argv[argvoffset + 1], 124 int res = dht_bootstrap_from_address(m->dht, argv[argvoffset + 1],
125 ipv6enabled, port, bootstrap_key); 125 ipv6enabled, port, bootstrap_key);
126 free(bootstrap_key); 126 free(bootstrap_key);
127 127
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index bb996e2d..6c104a73 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -283,7 +283,7 @@ void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t
283/* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key 283/* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
284 * for packets that we receive. 284 * for packets that we receive.
285 */ 285 */
286void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *public_key) 286void dht_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *public_key)
287{ 287{
288 get_shared_key(&dht->shared_keys_recv, shared_key, dht->self_secret_key, public_key); 288 get_shared_key(&dht->shared_keys_recv, shared_key, dht->self_secret_key, public_key);
289} 289}
@@ -291,7 +291,7 @@ void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *publi
291/* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key 291/* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
292 * for packets that we send. 292 * for packets that we send.
293 */ 293 */
294void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *public_key) 294void dht_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *public_key)
295{ 295{
296 get_shared_key(&dht->shared_keys_sent, shared_key, dht->self_secret_key, public_key); 296 get_shared_key(&dht->shared_keys_sent, shared_key, dht->self_secret_key, public_key);
297} 297}
@@ -455,7 +455,7 @@ int pack_ip_port(uint8_t *data, uint16_t length, const IP_Port *ip_port)
455 } 455 }
456} 456}
457 457
458static int DHT_create_packet(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE], 458static int dht_create_packet(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
459 const uint8_t *shared_key, const uint8_t type, uint8_t *plain, size_t plain_length, uint8_t *packet) 459 const uint8_t *shared_key, const uint8_t type, uint8_t *plain, size_t plain_length, uint8_t *packet)
460{ 460{
461 VLA(uint8_t, encrypted, plain_length + CRYPTO_MAC_SIZE); 461 VLA(uint8_t, encrypted, plain_length + CRYPTO_MAC_SIZE);
@@ -1315,9 +1315,9 @@ static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const
1315 memcpy(plain + CRYPTO_PUBLIC_KEY_SIZE, &ping_id, sizeof(ping_id)); 1315 memcpy(plain + CRYPTO_PUBLIC_KEY_SIZE, &ping_id, sizeof(ping_id));
1316 1316
1317 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; 1317 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
1318 DHT_get_shared_key_sent(dht, shared_key, public_key); 1318 dht_get_shared_key_sent(dht, shared_key, public_key);
1319 1319
1320 const int len = DHT_create_packet(dht->self_public_key, shared_key, NET_PACKET_GET_NODES, 1320 const int len = dht_create_packet(dht->self_public_key, shared_key, NET_PACKET_GET_NODES,
1321 plain, sizeof(plain), data); 1321 plain, sizeof(plain), data);
1322 1322
1323 if (len != sizeof(data)) { 1323 if (len != sizeof(data)) {
@@ -1364,7 +1364,7 @@ static int sendnodes_ipv6(const DHT *dht, IP_Port ip_port, const uint8_t *public
1364 const uint32_t crypto_size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE; 1364 const uint32_t crypto_size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE;
1365 VLA(uint8_t, data, 1 + nodes_length + length + crypto_size); 1365 VLA(uint8_t, data, 1 + nodes_length + length + crypto_size);
1366 1366
1367 const int len = DHT_create_packet(dht->self_public_key, shared_encryption_key, NET_PACKET_SEND_NODES_IPV6, 1367 const int len = dht_create_packet(dht->self_public_key, shared_encryption_key, NET_PACKET_SEND_NODES_IPV6,
1368 plain, 1 + nodes_length + length, data); 1368 plain, 1 + nodes_length + length, data);
1369 1369
1370 if (len != SIZEOF_VLA(data)) { 1370 if (len != SIZEOF_VLA(data)) {
@@ -1392,7 +1392,7 @@ static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet,
1392 uint8_t plain[CRYPTO_NODE_SIZE]; 1392 uint8_t plain[CRYPTO_NODE_SIZE];
1393 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; 1393 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
1394 1394
1395 DHT_get_shared_key_recv(dht, shared_key, packet + 1); 1395 dht_get_shared_key_recv(dht, shared_key, packet + 1);
1396 const int len = decrypt_data_symmetric( 1396 const int len = decrypt_data_symmetric(
1397 shared_key, 1397 shared_key,
1398 packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, 1398 packet + 1 + CRYPTO_PUBLIC_KEY_SIZE,
@@ -1462,7 +1462,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa
1462 1462
1463 VLA(uint8_t, plain, 1 + data_size + sizeof(uint64_t)); 1463 VLA(uint8_t, plain, 1 + data_size + sizeof(uint64_t));
1464 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; 1464 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
1465 DHT_get_shared_key_sent(dht, shared_key, packet + 1); 1465 dht_get_shared_key_sent(dht, shared_key, packet + 1);
1466 const int len = decrypt_data_symmetric( 1466 const int len = decrypt_data_symmetric(
1467 shared_key, 1467 shared_key,
1468 packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, 1468 packet + 1 + CRYPTO_PUBLIC_KEY_SIZE,
@@ -1538,7 +1538,7 @@ static int handle_sendnodes_ipv6(void *object, IP_Port source, const uint8_t *pa
1538/*----------------------------------------------------------------------------------*/ 1538/*----------------------------------------------------------------------------------*/
1539/*------------------------END of packet handling functions--------------------------*/ 1539/*------------------------END of packet handling functions--------------------------*/
1540 1540
1541int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void *data, int32_t number, IP_Port), 1541int dht_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void *data, int32_t number, IP_Port),
1542 void *data, int32_t number, uint16_t *lock_count) 1542 void *data, int32_t number, uint16_t *lock_count)
1543{ 1543{
1544 const uint32_t friend_num = index_of_friend_pk(dht->friends_list, dht->num_friends, public_key); 1544 const uint32_t friend_num = index_of_friend_pk(dht->friends_list, dht->num_friends, public_key);
@@ -1595,7 +1595,7 @@ int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void
1595 return 0; 1595 return 0;
1596} 1596}
1597 1597
1598int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count) 1598int dht_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
1599{ 1599{
1600 const uint32_t friend_num = index_of_friend_pk(dht->friends_list, dht->num_friends, public_key); 1600 const uint32_t friend_num = index_of_friend_pk(dht->friends_list, dht->num_friends, public_key);
1601 1601
@@ -1639,7 +1639,7 @@ int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
1639} 1639}
1640 1640
1641/* TODO(irungentoo): Optimize this. */ 1641/* TODO(irungentoo): Optimize this. */
1642int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port) 1642int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port)
1643{ 1643{
1644 ip_reset(&ip_port->ip); 1644 ip_reset(&ip_port->ip);
1645 ip_port->port = 0; 1645 ip_port->port = 0;
@@ -1743,7 +1743,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
1743/* Ping each client in the "friends" list every PING_INTERVAL seconds. Send a get nodes request 1743/* Ping each client in the "friends" list every PING_INTERVAL seconds. Send a get nodes request
1744 * every GET_NODE_INTERVAL seconds to a random good node for each "friend" in our "friends" list. 1744 * every GET_NODE_INTERVAL seconds to a random good node for each "friend" in our "friends" list.
1745 */ 1745 */
1746static void do_DHT_friends(DHT *dht) 1746static void do_dht_friends(DHT *dht)
1747{ 1747{
1748 for (size_t i = 0; i < dht->num_friends; ++i) { 1748 for (size_t i = 0; i < dht->num_friends; ++i) {
1749 DHT_Friend *const dht_friend = &dht->friends_list[i]; 1749 DHT_Friend *const dht_friend = &dht->friends_list[i];
@@ -1803,16 +1803,16 @@ static void do_Close(DHT *dht)
1803 } 1803 }
1804} 1804}
1805 1805
1806void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id) 1806void dht_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id)
1807{ 1807{
1808 getnodes(dht, *from_ipp, from_id, which_id, nullptr); 1808 getnodes(dht, *from_ipp, from_id, which_id, nullptr);
1809} 1809}
1810 1810
1811void DHT_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key) 1811void dht_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
1812{ 1812{
1813 getnodes(dht, ip_port, public_key, dht->self_public_key, nullptr); 1813 getnodes(dht, ip_port, public_key, dht->self_public_key, nullptr);
1814} 1814}
1815int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled, 1815int dht_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled,
1816 uint16_t port, const uint8_t *public_key) 1816 uint16_t port, const uint8_t *public_key)
1817{ 1817{
1818 IP_Port ip_port_v64; 1818 IP_Port ip_port_v64;
@@ -1829,11 +1829,11 @@ int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enable
1829 1829
1830 if (addr_resolve_or_parse_ip(address, &ip_port_v64.ip, ip_extra)) { 1830 if (addr_resolve_or_parse_ip(address, &ip_port_v64.ip, ip_extra)) {
1831 ip_port_v64.port = port; 1831 ip_port_v64.port = port;
1832 DHT_bootstrap(dht, ip_port_v64, public_key); 1832 dht_bootstrap(dht, ip_port_v64, public_key);
1833 1833
1834 if ((ip_extra != nullptr) && ip_isset(ip_extra)) { 1834 if ((ip_extra != nullptr) && ip_isset(ip_extra)) {
1835 ip_port_v4.port = port; 1835 ip_port_v4.port = port;
1836 DHT_bootstrap(dht, ip_port_v4, public_key); 1836 dht_bootstrap(dht, ip_port_v4, public_key);
1837 } 1837 }
1838 1838
1839 return 1; 1839 return 1;
@@ -2673,7 +2673,7 @@ static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *pack
2673 2673
2674/*----------------------------------------------------------------------------------*/ 2674/*----------------------------------------------------------------------------------*/
2675 2675
2676DHT *new_DHT(const Logger *log, Networking_Core *net, bool holepunching_enabled) 2676DHT *new_dht(const Logger *log, Networking_Core *net, bool holepunching_enabled)
2677{ 2677{
2678 /* init time */ 2678 /* init time */
2679 unix_time_update(); 2679 unix_time_update();
@@ -2696,7 +2696,7 @@ DHT *new_DHT(const Logger *log, Networking_Core *net, bool holepunching_enabled)
2696 dht->ping = ping_new(dht); 2696 dht->ping = ping_new(dht);
2697 2697
2698 if (dht->ping == nullptr) { 2698 if (dht->ping == nullptr) {
2699 kill_DHT(dht); 2699 kill_dht(dht);
2700 return nullptr; 2700 return nullptr;
2701 } 2701 }
2702 2702
@@ -2715,8 +2715,8 @@ DHT *new_DHT(const Logger *log, Networking_Core *net, bool holepunching_enabled)
2715 uint8_t random_key_bytes[CRYPTO_PUBLIC_KEY_SIZE]; 2715 uint8_t random_key_bytes[CRYPTO_PUBLIC_KEY_SIZE];
2716 random_bytes(random_key_bytes, sizeof(random_key_bytes)); 2716 random_bytes(random_key_bytes, sizeof(random_key_bytes));
2717 2717
2718 if (DHT_addfriend(dht, random_key_bytes, nullptr, nullptr, 0, nullptr) != 0) { 2718 if (dht_addfriend(dht, random_key_bytes, nullptr, nullptr, 0, nullptr) != 0) {
2719 kill_DHT(dht); 2719 kill_dht(dht);
2720 return nullptr; 2720 return nullptr;
2721 } 2721 }
2722 } 2722 }
@@ -2724,7 +2724,7 @@ DHT *new_DHT(const Logger *log, Networking_Core *net, bool holepunching_enabled)
2724 return dht; 2724 return dht;
2725} 2725}
2726 2726
2727void do_DHT(DHT *dht) 2727void do_dht(DHT *dht)
2728{ 2728{
2729 unix_time_update(); 2729 unix_time_update();
2730 2730
@@ -2732,13 +2732,13 @@ void do_DHT(DHT *dht)
2732 return; 2732 return;
2733 } 2733 }
2734 2734
2735 // Load friends/clients if first call to do_DHT 2735 // Load friends/clients if first call to do_dht
2736 if (dht->loaded_num_nodes) { 2736 if (dht->loaded_num_nodes) {
2737 DHT_connect_after_load(dht); 2737 dht_connect_after_load(dht);
2738 } 2738 }
2739 2739
2740 do_Close(dht); 2740 do_Close(dht);
2741 do_DHT_friends(dht); 2741 do_dht_friends(dht);
2742 do_NAT(dht); 2742 do_NAT(dht);
2743 ping_iterate(dht->ping); 2743 ping_iterate(dht->ping);
2744#if DHT_HARDENING 2744#if DHT_HARDENING
@@ -2747,7 +2747,7 @@ void do_DHT(DHT *dht)
2747 dht->last_run = unix_time(); 2747 dht->last_run = unix_time();
2748} 2748}
2749 2749
2750void kill_DHT(DHT *dht) 2750void kill_dht(DHT *dht)
2751{ 2751{
2752 networking_registerhandler(dht->net, NET_PACKET_GET_NODES, nullptr, nullptr); 2752 networking_registerhandler(dht->net, NET_PACKET_GET_NODES, nullptr, nullptr);
2753 networking_registerhandler(dht->net, NET_PACKET_SEND_NODES_IPV6, nullptr, nullptr); 2753 networking_registerhandler(dht->net, NET_PACKET_SEND_NODES_IPV6, nullptr, nullptr);
@@ -2771,7 +2771,7 @@ void kill_DHT(DHT *dht)
2771#define MAX_SAVED_DHT_NODES (((DHT_FAKE_FRIEND_NUMBER * MAX_FRIEND_CLIENTS) + LCLIENT_LIST) * 2) 2771#define MAX_SAVED_DHT_NODES (((DHT_FAKE_FRIEND_NUMBER * MAX_FRIEND_CLIENTS) + LCLIENT_LIST) * 2)
2772 2772
2773/* Get the size of the DHT (for saving). */ 2773/* Get the size of the DHT (for saving). */
2774uint32_t DHT_size(const DHT *dht) 2774uint32_t dht_size(const DHT *dht)
2775{ 2775{
2776 uint32_t numv4 = 0; 2776 uint32_t numv4 = 0;
2777 uint32_t numv6 = 0; 2777 uint32_t numv6 = 0;
@@ -2796,7 +2796,7 @@ uint32_t DHT_size(const DHT *dht)
2796 return size32 + sizesubhead + packed_node_size(net_family_ipv4) * numv4 + packed_node_size(net_family_ipv6) * numv6; 2796 return size32 + sizesubhead + packed_node_size(net_family_ipv4) * numv4 + packed_node_size(net_family_ipv6) * numv6;
2797} 2797}
2798 2798
2799static uint8_t *DHT_save_subheader(uint8_t *data, uint32_t len, uint16_t type) 2799static uint8_t *dht_save_subheader(uint8_t *data, uint32_t len, uint16_t type)
2800{ 2800{
2801 host_to_lendian32(data, len); 2801 host_to_lendian32(data, len);
2802 data += sizeof(uint32_t); 2802 data += sizeof(uint32_t);
@@ -2806,8 +2806,8 @@ static uint8_t *DHT_save_subheader(uint8_t *data, uint32_t len, uint16_t type)
2806} 2806}
2807 2807
2808 2808
2809/* Save the DHT in data where data is an array of size DHT_size(). */ 2809/* Save the DHT in data where data is an array of size dht_size(). */
2810void DHT_save(const DHT *dht, uint8_t *data) 2810void dht_save(const DHT *dht, uint8_t *data)
2811{ 2811{
2812 host_to_lendian32(data, DHT_STATE_COOKIE_GLOBAL); 2812 host_to_lendian32(data, DHT_STATE_COOKIE_GLOBAL);
2813 data += sizeof(uint32_t); 2813 data += sizeof(uint32_t);
@@ -2815,7 +2815,7 @@ void DHT_save(const DHT *dht, uint8_t *data)
2815 uint8_t *const old_data = data; 2815 uint8_t *const old_data = data;
2816 2816
2817 /* get right offset. we write the actual header later. */ 2817 /* get right offset. we write the actual header later. */
2818 data = DHT_save_subheader(data, 0, 0); 2818 data = dht_save_subheader(data, 0, 0);
2819 2819
2820 Node_format clients[MAX_SAVED_DHT_NODES]; 2820 Node_format clients[MAX_SAVED_DHT_NODES];
2821 2821
@@ -2853,14 +2853,14 @@ void DHT_save(const DHT *dht, uint8_t *data)
2853 } 2853 }
2854 } 2854 }
2855 2855
2856 DHT_save_subheader(old_data, pack_nodes(data, sizeof(Node_format) * num, clients, num), DHT_STATE_TYPE_NODES); 2856 dht_save_subheader(old_data, pack_nodes(data, sizeof(Node_format) * num, clients, num), DHT_STATE_TYPE_NODES);
2857} 2857}
2858 2858
2859/* Bootstrap from this number of nodes every time DHT_connect_after_load() is called */ 2859/* Bootstrap from this number of nodes every time dht_connect_after_load() is called */
2860#define SAVE_BOOTSTAP_FREQUENCY 8 2860#define SAVE_BOOTSTAP_FREQUENCY 8
2861 2861
2862/* Start sending packets after DHT loaded_friends_list and loaded_clients_list are set */ 2862/* Start sending packets after DHT loaded_friends_list and loaded_clients_list are set */
2863int DHT_connect_after_load(DHT *dht) 2863int dht_connect_after_load(DHT *dht)
2864{ 2864{
2865 if (dht == nullptr) { 2865 if (dht == nullptr) {
2866 return -1; 2866 return -1;
@@ -2871,7 +2871,7 @@ int DHT_connect_after_load(DHT *dht)
2871 } 2871 }
2872 2872
2873 /* DHT is connected, stop. */ 2873 /* DHT is connected, stop. */
2874 if (DHT_non_lan_connected(dht)) { 2874 if (dht_non_lan_connected(dht)) {
2875 free(dht->loaded_nodes_list); 2875 free(dht->loaded_nodes_list);
2876 dht->loaded_nodes_list = nullptr; 2876 dht->loaded_nodes_list = nullptr;
2877 dht->loaded_num_nodes = 0; 2877 dht->loaded_num_nodes = 0;
@@ -2880,7 +2880,7 @@ int DHT_connect_after_load(DHT *dht)
2880 2880
2881 for (uint32_t i = 0; i < dht->loaded_num_nodes && i < SAVE_BOOTSTAP_FREQUENCY; ++i) { 2881 for (uint32_t i = 0; i < dht->loaded_num_nodes && i < SAVE_BOOTSTAP_FREQUENCY; ++i) {
2882 const unsigned int index = dht->loaded_nodes_index % dht->loaded_num_nodes; 2882 const unsigned int index = dht->loaded_nodes_index % dht->loaded_num_nodes;
2883 DHT_bootstrap(dht, dht->loaded_nodes_list[index].ip_port, dht->loaded_nodes_list[index].public_key); 2883 dht_bootstrap(dht, dht->loaded_nodes_list[index].ip_port, dht->loaded_nodes_list[index].public_key);
2884 ++dht->loaded_nodes_index; 2884 ++dht->loaded_nodes_index;
2885 } 2885 }
2886 2886
@@ -2926,7 +2926,7 @@ static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t le
2926 * return -1 if failure. 2926 * return -1 if failure.
2927 * return 0 if success. 2927 * return 0 if success.
2928 */ 2928 */
2929int DHT_load(DHT *dht, const uint8_t *data, uint32_t length) 2929int dht_load(DHT *dht, const uint8_t *data, uint32_t length)
2930{ 2930{
2931 const uint32_t cookie_len = sizeof(uint32_t); 2931 const uint32_t cookie_len = sizeof(uint32_t);
2932 2932
@@ -2946,7 +2946,7 @@ int DHT_load(DHT *dht, const uint8_t *data, uint32_t length)
2946/* return false if we are not connected to the DHT. 2946/* return false if we are not connected to the DHT.
2947 * return true if we are. 2947 * return true if we are.
2948 */ 2948 */
2949bool DHT_isconnected(const DHT *dht) 2949bool dht_isconnected(const DHT *dht)
2950{ 2950{
2951 unix_time_update(); 2951 unix_time_update();
2952 2952
@@ -2965,7 +2965,7 @@ bool DHT_isconnected(const DHT *dht)
2965/* return false if we are not connected or only connected to lan peers with the DHT. 2965/* return false if we are not connected or only connected to lan peers with the DHT.
2966 * return true if we are. 2966 * return true if we are.
2967 */ 2967 */
2968bool DHT_non_lan_connected(const DHT *dht) 2968bool dht_non_lan_connected(const DHT *dht)
2969{ 2969{
2970 unix_time_update(); 2970 unix_time_update();
2971 2971
diff --git a/toxcore/DHT.h b/toxcore/DHT.h
index bbfeb307..15ff44e5 100644
--- a/toxcore/DHT.h
+++ b/toxcore/DHT.h
@@ -252,14 +252,14 @@ void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, const uint8_t
252/* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key 252/* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
253 * for packets that we receive. 253 * for packets that we receive.
254 */ 254 */
255void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *public_key); 255void dht_get_shared_key_recv(DHT *dht, uint8_t *shared_key, const uint8_t *public_key);
256 256
257/* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key 257/* Copy shared_key to encrypt/decrypt DHT packet from public_key into shared_key
258 * for packets that we send. 258 * for packets that we send.
259 */ 259 */
260void DHT_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *public_key); 260void dht_get_shared_key_sent(DHT *dht, uint8_t *shared_key, const uint8_t *public_key);
261 261
262void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id); 262void dht_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id);
263 263
264/* Add a new friend to the friends list. 264/* Add a new friend to the friends list.
265 * public_key must be CRYPTO_PUBLIC_KEY_SIZE bytes long. 265 * public_key must be CRYPTO_PUBLIC_KEY_SIZE bytes long.
@@ -267,13 +267,13 @@ void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, con
267 * ip_callback is the callback of a function that will be called when the ip address 267 * ip_callback is the callback of a function that will be called when the ip address
268 * is found along with arguments data and number. 268 * is found along with arguments data and number.
269 * 269 *
270 * lock_count will be set to a non zero number that must be passed to DHT_delfriend() 270 * lock_count will be set to a non zero number that must be passed to dht_delfriend()
271 * to properly remove the callback. 271 * to properly remove the callback.
272 * 272 *
273 * return 0 if success. 273 * return 0 if success.
274 * return -1 if failure (friends list is full). 274 * return -1 if failure (friends list is full).
275 */ 275 */
276int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void *data, int32_t number, IP_Port), 276int dht_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void *data, int32_t number, IP_Port),
277 void *data, int32_t number, uint16_t *lock_count); 277 void *data, int32_t number, uint16_t *lock_count);
278 278
279/* Delete a friend from the friends list. 279/* Delete a friend from the friends list.
@@ -282,20 +282,20 @@ int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void
282 * return 0 if success. 282 * return 0 if success.
283 * return -1 if failure (public_key not in friends list). 283 * return -1 if failure (public_key not in friends list).
284 */ 284 */
285int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count); 285int dht_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count);
286 286
287/* Get ip of friend. 287/* Get ip of friend.
288 * public_key must be CRYPTO_PUBLIC_KEY_SIZE bytes long. 288 * public_key must be CRYPTO_PUBLIC_KEY_SIZE bytes long.
289 * ip must be 4 bytes long. 289 * ip must be 4 bytes long.
290 * port must be 2 bytes long. 290 * port must be 2 bytes long.
291 * 291 *
292 * int DHT_getfriendip(DHT *dht, uint8_t *public_key, IP_Port *ip_port); 292 * int dht_getfriendip(DHT *dht, uint8_t *public_key, IP_Port *ip_port);
293 * 293 *
294 * return -1, -- if public_key does NOT refer to a friend 294 * return -1, -- if public_key does NOT refer to a friend
295 * return 0, -- if public_key refers to a friend and we failed to find the friend (yet) 295 * return 0, -- if public_key refers to a friend and we failed to find the friend (yet)
296 * return 1, ip if public_key refers to a friend and we found him 296 * return 1, ip if public_key refers to a friend and we found him
297 */ 297 */
298int DHT_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port); 298int dht_getfriendip(const DHT *dht, const uint8_t *public_key, IP_Port *ip_port);
299 299
300/* Compares pk1 and pk2 with pk. 300/* Compares pk1 and pk2 with pk.
301 * 301 *
@@ -341,7 +341,7 @@ uint16_t randfriends_nodes(DHT *dht, Node_format *nodes, uint16_t max_num);
341uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num); 341uint16_t closelist_nodes(DHT *dht, Node_format *nodes, uint16_t max_num);
342 342
343/* Run this function at least a couple times per second (It's the main loop). */ 343/* Run this function at least a couple times per second (It's the main loop). */
344void do_DHT(DHT *dht); 344void do_dht(DHT *dht);
345 345
346/* 346/*
347 * Use these two functions to bootstrap the client. 347 * Use these two functions to bootstrap the client.
@@ -349,7 +349,7 @@ void do_DHT(DHT *dht);
349/* Sends a "get nodes" request to the given node with ip, port and public_key 349/* Sends a "get nodes" request to the given node with ip, port and public_key
350 * to setup connections 350 * to setup connections
351 */ 351 */
352void DHT_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key); 352void dht_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key);
353/* Resolves address into an IP address. If successful, sends a "get nodes" 353/* Resolves address into an IP address. If successful, sends a "get nodes"
354 * request to the given node with ip, port and public_key to setup connections 354 * request to the given node with ip, port and public_key to setup connections
355 * 355 *
@@ -361,7 +361,7 @@ void DHT_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key);
361 * returns 1 if the address could be converted into an IP address 361 * returns 1 if the address could be converted into an IP address
362 * returns 0 otherwise 362 * returns 0 otherwise
363 */ 363 */
364int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled, 364int dht_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled,
365 uint16_t port, const uint8_t *public_key); 365 uint16_t port, const uint8_t *public_key);
366 366
367/* Start sending packets after DHT loaded_friends_list and loaded_clients_list are set. 367/* Start sending packets after DHT loaded_friends_list and loaded_clients_list are set.
@@ -369,7 +369,7 @@ int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enable
369 * returns 0 if successful 369 * returns 0 if successful
370 * returns -1 otherwise 370 * returns -1 otherwise
371 */ 371 */
372int DHT_connect_after_load(DHT *dht); 372int dht_connect_after_load(DHT *dht);
373 373
374/* ROUTING FUNCTIONS */ 374/* ROUTING FUNCTIONS */
375 375
@@ -392,32 +392,32 @@ void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_c
392/* SAVE/LOAD functions */ 392/* SAVE/LOAD functions */
393 393
394/* Get the size of the DHT (for saving). */ 394/* Get the size of the DHT (for saving). */
395uint32_t DHT_size(const DHT *dht); 395uint32_t dht_size(const DHT *dht);
396 396
397/* Save the DHT in data where data is an array of size DHT_size(). */ 397/* Save the DHT in data where data is an array of size dht_size(). */
398void DHT_save(const DHT *dht, uint8_t *data); 398void dht_save(const DHT *dht, uint8_t *data);
399 399
400/* Load the DHT from data of size size. 400/* Load the DHT from data of size size.
401 * 401 *
402 * return -1 if failure. 402 * return -1 if failure.
403 * return 0 if success. 403 * return 0 if success.
404 */ 404 */
405int DHT_load(DHT *dht, const uint8_t *data, uint32_t length); 405int dht_load(DHT *dht, const uint8_t *data, uint32_t length);
406 406
407/* Initialize DHT. */ 407/* Initialize DHT. */
408DHT *new_DHT(const Logger *log, Networking_Core *net, bool holepunching_enabled); 408DHT *new_dht(const Logger *log, Networking_Core *net, bool holepunching_enabled);
409 409
410void kill_DHT(DHT *dht); 410void kill_dht(DHT *dht);
411 411
412/* return false if we are not connected to the DHT. 412/* return false if we are not connected to the DHT.
413 * return true if we are. 413 * return true if we are.
414 */ 414 */
415bool DHT_isconnected(const DHT *dht); 415bool dht_isconnected(const DHT *dht);
416 416
417/* return false if we are not connected or only connected to lan peers with the DHT. 417/* return false if we are not connected or only connected to lan peers with the DHT.
418 * return true if we are. 418 * return true if we are.
419 */ 419 */
420bool DHT_non_lan_connected(const DHT *dht); 420bool dht_non_lan_connected(const DHT *dht);
421 421
422 422
423uint32_t addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key); 423uint32_t addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key);
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c
index d25aace3..9552ad05 100644
--- a/toxcore/LAN_discovery.c
+++ b/toxcore/LAN_discovery.c
@@ -371,7 +371,7 @@ static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *pack
371 return 1; 371 return 1;
372 } 372 }
373 373
374 DHT_bootstrap(dht, source, packet + 1); 374 dht_bootstrap(dht, source, packet + 1);
375 return 0; 375 return 0;
376} 376}
377 377
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 7b931bdb..b8509706 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -383,7 +383,7 @@ static int do_receipts(Messenger *m, int32_t friendnumber, void *userdata)
383 } 383 }
384 384
385 if (m->read_receipt) { 385 if (m->read_receipt) {
386 (*m->read_receipt)(m, friendnumber, receipts->msg_id, userdata); 386 m->read_receipt(m, friendnumber, receipts->msg_id, userdata);
387 } 387 }
388 388
389 struct Receipts *r_next = receipts->next; 389 struct Receipts *r_next = receipts->next;
@@ -684,7 +684,7 @@ int m_set_userstatus(Messenger *m, uint8_t status)
684 return 0; 684 return 0;
685 } 685 }
686 686
687 m->userstatus = (USERSTATUS)status; 687 m->userstatus = (Userstatus)status;
688 uint32_t i; 688 uint32_t i;
689 689
690 for (i = 0; i < m->numfriends; ++i) { 690 for (i = 0; i < m->numfriends; ++i) {
@@ -830,7 +830,7 @@ static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, co
830 830
831static void set_friend_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status) 831static void set_friend_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
832{ 832{
833 m->friendlist[friendnumber].userstatus = (USERSTATUS)status; 833 m->friendlist[friendnumber].userstatus = (Userstatus)status;
834} 834}
835 835
836static void set_friend_typing(const Messenger *m, int32_t friendnumber, uint8_t is_typing) 836static void set_friend_typing(const Messenger *m, int32_t friendnumber, uint8_t is_typing)
@@ -844,55 +844,53 @@ void m_callback_log(Messenger *m, logger_cb *function, void *context, void *user
844} 844}
845 845
846/* Set the function that will be executed when a friend request is received. */ 846/* Set the function that will be executed when a friend request is received. */
847void m_callback_friendrequest(Messenger *m, void (*function)(Messenger *m, const uint8_t *, const uint8_t *, size_t, 847void m_callback_friendrequest(Messenger *m, m_friend_request_cb *function)
848 void *))
849{ 848{
850 callback_friendrequest(m->fr, (void (*)(void *, const uint8_t *, const uint8_t *, size_t, void *))function, m); 849 callback_friendrequest(m->fr, (fr_friend_request_cb *)function, m);
851} 850}
852 851
853/* Set the function that will be executed when a message from a friend is received. */ 852/* Set the function that will be executed when a message from a friend is received. */
854void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, const uint8_t *, 853void m_callback_friendmessage(Messenger *m, m_friend_message_cb *function)
855 size_t, void *))
856{ 854{
857 m->friend_message = function; 855 m->friend_message = function;
858} 856}
859 857
860void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *)) 858void m_callback_namechange(Messenger *m, m_friend_name_cb *function)
861{ 859{
862 m->friend_namechange = function; 860 m->friend_namechange = function;
863} 861}
864 862
865void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *)) 863void m_callback_statusmessage(Messenger *m, m_friend_status_message_cb *function)
866{ 864{
867 m->friend_statusmessagechange = function; 865 m->friend_statusmessagechange = function;
868} 866}
869 867
870void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *)) 868void m_callback_userstatus(Messenger *m, m_friend_status_cb *function)
871{ 869{
872 m->friend_userstatuschange = function; 870 m->friend_userstatuschange = function;
873} 871}
874 872
875void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, uint32_t, bool, void *)) 873void m_callback_typingchange(Messenger *m, m_friend_typing_cb *function)
876{ 874{
877 m->friend_typingchange = function; 875 m->friend_typingchange = function;
878} 876}
879 877
880void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, void *)) 878void m_callback_read_receipt(Messenger *m, m_friend_read_receipt_cb *function)
881{ 879{
882 m->read_receipt = function; 880 m->read_receipt = function;
883} 881}
884 882
885void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *)) 883void m_callback_connectionstatus(Messenger *m, m_friend_connection_status_cb *function)
886{ 884{
887 m->friend_connectionstatuschange = function; 885 m->friend_connectionstatuschange = function;
888} 886}
889 887
890void m_callback_core_connection(Messenger *m, void (*function)(Messenger *m, unsigned int, void *)) 888void m_callback_core_connection(Messenger *m, m_self_connection_status_cb *function)
891{ 889{
892 m->core_connection_change = function; 890 m->core_connection_change = function;
893} 891}
894 892
895void m_callback_connectionstatus_internal_av(Messenger *m, void (*function)(Messenger *m, uint32_t, uint8_t, void *), 893void m_callback_connectionstatus_internal_av(Messenger *m, m_friend_connectionstatuschange_internal_cb *function,
896 void *userdata) 894 void *userdata)
897{ 895{
898 m->friend_connectionstatuschange_internal = function; 896 m->friend_connectionstatuschange_internal = function;
@@ -993,8 +991,7 @@ static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_
993 * 991 *
994 * Function(Messenger *m, uint32_t friendnumber, uint8_t *data, uint16_t length, void *userdata) 992 * Function(Messenger *m, uint32_t friendnumber, uint8_t *data, uint16_t length, void *userdata)
995 */ 993 */
996void m_callback_conference_invite(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, uint16_t, 994void m_callback_conference_invite(Messenger *m, m_conference_invite_cb *function)
997 void *))
998{ 995{
999 m->conference_invite = function; 996 m->conference_invite = function;
1000} 997}
@@ -1017,8 +1014,7 @@ int send_conference_invite_packet(const Messenger *m, int32_t friendnumber, cons
1017 * 1014 *
1018 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint32_t filetype, uint64_t filesize, uint8_t *filename, size_t filename_length, void *userdata) 1015 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint32_t filetype, uint64_t filesize, uint8_t *filename, size_t filename_length, void *userdata)
1019 */ 1016 */
1020void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t, 1017void callback_file_sendrequest(Messenger *m, m_file_recv_cb *function)
1021 const uint8_t *, size_t, void *))
1022{ 1018{
1023 m->file_sendrequest = function; 1019 m->file_sendrequest = function;
1024} 1020}
@@ -1028,7 +1024,7 @@ void callback_file_sendrequest(Messenger *m, void (*function)(Messenger *m, uin
1028 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, unsigned int control_type, void *userdata) 1024 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, unsigned int control_type, void *userdata)
1029 * 1025 *
1030 */ 1026 */
1031void callback_file_control(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, unsigned int, void *)) 1027void callback_file_control(Messenger *m, m_file_recv_control_cb *function)
1032{ 1028{
1033 m->file_filecontrol = function; 1029 m->file_filecontrol = function;
1034} 1030}
@@ -1038,8 +1034,7 @@ void callback_file_control(Messenger *m, void (*function)(Messenger *m, uint32_t
1038 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, uint8_t *data, size_t length, void *userdata) 1034 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, uint8_t *data, size_t length, void *userdata)
1039 * 1035 *
1040 */ 1036 */
1041void callback_file_data(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, 1037void callback_file_data(Messenger *m, m_file_recv_chunk_cb *function)
1042 size_t, void *))
1043{ 1038{
1044 m->file_filedata = function; 1039 m->file_filedata = function;
1045} 1040}
@@ -1049,7 +1044,7 @@ void callback_file_data(Messenger *m, void (*function)(Messenger *m, uint32_t, u
1049 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, size_t length, void *userdata) 1044 * Function(Tox *tox, uint32_t friendnumber, uint32_t filenumber, uint64_t position, size_t length, void *userdata)
1050 * 1045 *
1051 */ 1046 */
1052void callback_file_reqchunk(Messenger *m, void (*function)(Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *)) 1047void callback_file_reqchunk(Messenger *m, m_file_chunk_request_cb *function)
1053{ 1048{
1054 m->file_reqchunk = function; 1049 m->file_reqchunk = function;
1055} 1050}
@@ -1579,7 +1574,7 @@ static bool do_all_filetransfers(Messenger *m, int32_t friendnumber, void *userd
1579 } 1574 }
1580 1575
1581 // Allocate 1 slot to this file transfer. 1576 // Allocate 1 slot to this file transfer.
1582 ft->slots_allocated++; 1577 ++ft->slots_allocated;
1583 1578
1584 const uint16_t length = min_u64(ft->size - ft->requested, MAX_FILE_DATA_SIZE); 1579 const uint16_t length = min_u64(ft->size - ft->requested, MAX_FILE_DATA_SIZE);
1585 const uint64_t position = ft->requested; 1580 const uint64_t position = ft->requested;
@@ -1628,11 +1623,11 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber, void *userdat
1628 // 1623 //
1629 // TODO(zoff99): Fix this to exit the loop properly when we're done 1624 // TODO(zoff99): Fix this to exit the loop properly when we're done
1630 // requesting all chunks for all file transfers. 1625 // requesting all chunks for all file transfers.
1631 const uint32_t MAX_FT_LOOPS = 16; 1626 const uint32_t max_ft_loops = 16;
1632 1627
1633 while (((free_slots > 0) || loop_counter == 0) && any_active_fts && (loop_counter < MAX_FT_LOOPS)) { 1628 while (((free_slots > 0) || loop_counter == 0) && any_active_fts && (loop_counter < max_ft_loops)) {
1634 any_active_fts = do_all_filetransfers(m, friendnumber, userdata, &free_slots); 1629 any_active_fts = do_all_filetransfers(m, friendnumber, userdata, &free_slots);
1635 loop_counter++; 1630 ++loop_counter;
1636 } 1631 }
1637} 1632}
1638 1633
@@ -1773,7 +1768,8 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receiv
1773 return -1; 1768 return -1;
1774 } 1769 }
1775 1770
1776 ft->transferred = ft->requested = position; 1771 ft->requested = position;
1772 ft->transferred = position;
1777 return 0; 1773 return 0;
1778 } 1774 }
1779 1775
@@ -1791,8 +1787,7 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receiv
1791 * 1787 *
1792 * Function(Messenger *m, int friendnumber, uint8_t *data, uint16_t length, void *userdata) 1788 * Function(Messenger *m, int friendnumber, uint8_t *data, uint16_t length, void *userdata)
1793 */ 1789 */
1794void m_callback_msi_packet(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, uint16_t, void *), 1790void m_callback_msi_packet(Messenger *m, m_msi_packet_cb *function, void *userdata)
1795 void *userdata)
1796{ 1791{
1797 m->msi_packet = function; 1792 m->msi_packet = function;
1798 m->msi_packet_userdata = userdata; 1793 m->msi_packet_userdata = userdata;
@@ -1834,14 +1829,13 @@ static int m_handle_custom_lossy_packet(void *object, int friend_num, const uint
1834 return 1; 1829 return 1;
1835} 1830}
1836 1831
1837void custom_lossy_packet_registerhandler(Messenger *m, void (*lossy_packethandler)(Messenger *m, 1832void custom_lossy_packet_registerhandler(Messenger *m, m_friend_lossy_packet_cb *lossy_packethandler)
1838 uint32_t friendnumber, const uint8_t *data, size_t len, void *object))
1839{ 1833{
1840 m->lossy_packethandler = lossy_packethandler; 1834 m->lossy_packethandler = lossy_packethandler;
1841} 1835}
1842 1836
1843int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, int (*function)(Messenger *m, 1837int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, m_lossy_rtp_packet_cb *function,
1844 uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object), void *object) 1838 void *object)
1845{ 1839{
1846 if (friend_not_valid(m, friendnumber)) { 1840 if (friend_not_valid(m, friendnumber)) {
1847 return -1; 1841 return -1;
@@ -1915,8 +1909,7 @@ static int handle_custom_lossless_packet(void *object, int friend_num, const uin
1915 return 1; 1909 return 1;
1916} 1910}
1917 1911
1918void custom_lossless_packet_registerhandler(Messenger *m, void (*lossless_packethandler)(Messenger *m, 1912void custom_lossless_packet_registerhandler(Messenger *m, m_friend_lossless_packet_cb *lossless_packethandler)
1919 uint32_t friendnumber, const uint8_t *data, size_t len, void *object))
1920{ 1913{
1921 m->lossless_packethandler = lossless_packethandler; 1914 m->lossless_packethandler = lossless_packethandler;
1922} 1915}
@@ -2025,7 +2018,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
2025 return nullptr; 2018 return nullptr;
2026 } 2019 }
2027 2020
2028 m->dht = new_DHT(m->log, m->net, options->hole_punching_enabled); 2021 m->dht = new_dht(m->log, m->net, options->hole_punching_enabled);
2029 2022
2030 if (m->dht == nullptr) { 2023 if (m->dht == nullptr) {
2031 kill_networking(m->net); 2024 kill_networking(m->net);
@@ -2039,7 +2032,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
2039 2032
2040 if (m->net_crypto == nullptr) { 2033 if (m->net_crypto == nullptr) {
2041 kill_networking(m->net); 2034 kill_networking(m->net);
2042 kill_DHT(m->dht); 2035 kill_dht(m->dht);
2043 friendreq_kill(m->fr); 2036 friendreq_kill(m->fr);
2044 logger_kill(m->log); 2037 logger_kill(m->log);
2045 free(m); 2038 free(m);
@@ -2057,7 +2050,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
2057 kill_onion_announce(m->onion_a); 2050 kill_onion_announce(m->onion_a);
2058 kill_onion_client(m->onion_c); 2051 kill_onion_client(m->onion_c);
2059 kill_net_crypto(m->net_crypto); 2052 kill_net_crypto(m->net_crypto);
2060 kill_DHT(m->dht); 2053 kill_dht(m->dht);
2061 kill_networking(m->net); 2054 kill_networking(m->net);
2062 friendreq_kill(m->fr); 2055 friendreq_kill(m->fr);
2063 logger_kill(m->log); 2056 logger_kill(m->log);
@@ -2075,7 +2068,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
2075 kill_onion_announce(m->onion_a); 2068 kill_onion_announce(m->onion_a);
2076 kill_onion_client(m->onion_c); 2069 kill_onion_client(m->onion_c);
2077 kill_net_crypto(m->net_crypto); 2070 kill_net_crypto(m->net_crypto);
2078 kill_DHT(m->dht); 2071 kill_dht(m->dht);
2079 kill_networking(m->net); 2072 kill_networking(m->net);
2080 friendreq_kill(m->fr); 2073 friendreq_kill(m->fr);
2081 logger_kill(m->log); 2074 logger_kill(m->log);
@@ -2121,7 +2114,7 @@ void kill_messenger(Messenger *m)
2121 kill_onion_announce(m->onion_a); 2114 kill_onion_announce(m->onion_a);
2122 kill_onion_client(m->onion_c); 2115 kill_onion_client(m->onion_c);
2123 kill_net_crypto(m->net_crypto); 2116 kill_net_crypto(m->net_crypto);
2124 kill_DHT(m->dht); 2117 kill_dht(m->dht);
2125 kill_networking(m->net); 2118 kill_networking(m->net);
2126 2119
2127 for (i = 0; i < m->numfriends; ++i) { 2120 for (i = 0; i < m->numfriends; ++i) {
@@ -2241,7 +2234,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
2241 break; 2234 break;
2242 } 2235 }
2243 2236
2244 USERSTATUS status = (USERSTATUS)data[0]; 2237 Userstatus status = (Userstatus)data[0];
2245 2238
2246 if (status >= USERSTATUS_INVALID) { 2239 if (status >= USERSTATUS_INVALID) {
2247 break; 2240 break;
@@ -2541,7 +2534,7 @@ static void do_friends(Messenger *m, void *userdata)
2541 } 2534 }
2542} 2535}
2543 2536
2544static void connection_status_cb(Messenger *m, void *userdata) 2537static void connection_status_callback(Messenger *m, void *userdata)
2545{ 2538{
2546 unsigned int conn_status = onion_connection_status(m->onion_c); 2539 unsigned int conn_status = onion_connection_status(m->onion_c);
2547 2540
@@ -2566,7 +2559,7 @@ static char *id_to_string(const uint8_t *pk, char *id_str, size_t length)
2566 return id_str; 2559 return id_str;
2567 } 2560 }
2568 2561
2569 for (uint32_t i = 0; i < CRYPTO_PUBLIC_KEY_SIZE; i++) { 2562 for (uint32_t i = 0; i < CRYPTO_PUBLIC_KEY_SIZE; ++i) {
2570 sprintf(&id_str[i * 2], "%02X", pk[i]); 2563 sprintf(&id_str[i * 2], "%02X", pk[i]);
2571 } 2564 }
2572 2565
@@ -2622,7 +2615,7 @@ void do_messenger(Messenger *m, void *userdata)
2622 2615
2623 if (!m->options.udp_disabled) { 2616 if (!m->options.udp_disabled) {
2624 networking_poll(m->net, userdata); 2617 networking_poll(m->net, userdata);
2625 do_DHT(m->dht); 2618 do_dht(m->dht);
2626 } 2619 }
2627 2620
2628 if (m->tcp_server) { 2621 if (m->tcp_server) {
@@ -2633,18 +2626,18 @@ void do_messenger(Messenger *m, void *userdata)
2633 do_onion_client(m->onion_c); 2626 do_onion_client(m->onion_c);
2634 do_friend_connections(m->fr_c, userdata); 2627 do_friend_connections(m->fr_c, userdata);
2635 do_friends(m, userdata); 2628 do_friends(m, userdata);
2636 connection_status_cb(m, userdata); 2629 connection_status_callback(m, userdata);
2637 2630
2638 if (unix_time() > m->lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) { 2631 if (unix_time() > m->lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) {
2639 m->lastdump = unix_time(); 2632 m->lastdump = unix_time();
2640 uint32_t client, last_pinged; 2633 uint32_t client, last_pinged;
2641 2634
2642 for (client = 0; client < LCLIENT_LIST; client++) { 2635 for (client = 0; client < LCLIENT_LIST; ++client) {
2643 const Client_data *cptr = dht_get_close_client(m->dht, client); 2636 const Client_data *cptr = dht_get_close_client(m->dht, client);
2644 const IPPTsPng *assoc = nullptr; 2637 const IPPTsPng *assoc = nullptr;
2645 uint32_t a; 2638 uint32_t a;
2646 2639
2647 for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6) { 2640 for (a = 0, assoc = &cptr->assoc4; a < 2; ++a, assoc = &cptr->assoc6) {
2648 if (ip_isset(&assoc->ip_port.ip)) { 2641 if (ip_isset(&assoc->ip_port.ip)) {
2649 last_pinged = m->lastdump - assoc->last_pinged; 2642 last_pinged = m->lastdump - assoc->last_pinged;
2650 2643
@@ -2670,7 +2663,7 @@ void do_messenger(Messenger *m, void *userdata)
2670 VLA(int32_t, m2dht, num_dhtfriends); 2663 VLA(int32_t, m2dht, num_dhtfriends);
2671 VLA(int32_t, dht2m, num_dhtfriends); 2664 VLA(int32_t, dht2m, num_dhtfriends);
2672 2665
2673 for (friend_idx = 0; friend_idx < num_dhtfriends; friend_idx++) { 2666 for (friend_idx = 0; friend_idx < num_dhtfriends; ++friend_idx) {
2674 m2dht[friend_idx] = -1; 2667 m2dht[friend_idx] = -1;
2675 dht2m[friend_idx] = -1; 2668 dht2m[friend_idx] = -1;
2676 2669
@@ -2678,7 +2671,7 @@ void do_messenger(Messenger *m, void *userdata)
2678 continue; 2671 continue;
2679 } 2672 }
2680 2673
2681 for (dhtfriend = 0; dhtfriend < dht_get_num_friends(m->dht); dhtfriend++) { 2674 for (dhtfriend = 0; dhtfriend < dht_get_num_friends(m->dht); ++dhtfriend) {
2682 if (id_equal(m->friendlist[friend_idx].real_pk, dht_get_friend_public_key(m->dht, dhtfriend))) { 2675 if (id_equal(m->friendlist[friend_idx].real_pk, dht_get_friend_public_key(m->dht, dhtfriend))) {
2683 m2dht[friend_idx] = dhtfriend; 2676 m2dht[friend_idx] = dhtfriend;
2684 break; 2677 break;
@@ -2686,7 +2679,7 @@ void do_messenger(Messenger *m, void *userdata)
2686 } 2679 }
2687 } 2680 }
2688 2681
2689 for (friend_idx = 0; friend_idx < num_dhtfriends; friend_idx++) { 2682 for (friend_idx = 0; friend_idx < num_dhtfriends; ++friend_idx) {
2690 if (m2dht[friend_idx] >= 0) { 2683 if (m2dht[friend_idx] >= 0) {
2691 dht2m[m2dht[friend_idx]] = friend_idx; 2684 dht2m[m2dht[friend_idx]] = friend_idx;
2692 } 2685 }
@@ -2699,7 +2692,7 @@ void do_messenger(Messenger *m, void *userdata)
2699 Friend *msgfptr; 2692 Friend *msgfptr;
2700 DHT_Friend *dhtfptr; 2693 DHT_Friend *dhtfptr;
2701 2694
2702 for (friend_idx = 0; friend_idx < num_dhtfriends; friend_idx++) { 2695 for (friend_idx = 0; friend_idx < num_dhtfriends; ++friend_idx) {
2703 if (dht2m[friend_idx] >= 0) { 2696 if (dht2m[friend_idx] >= 0) {
2704 msgfptr = &m->friendlist[dht2m[friend_idx]]; 2697 msgfptr = &m->friendlist[dht2m[friend_idx]];
2705 } else { 2698 } else {
@@ -2719,11 +2712,11 @@ void do_messenger(Messenger *m, void *userdata)
2719 id_to_string(dht_friend_public_key(dhtfptr), id_str, sizeof(id_str))); 2712 id_to_string(dht_friend_public_key(dhtfptr), id_str, sizeof(id_str)));
2720 } 2713 }
2721 2714
2722 for (client = 0; client < MAX_FRIEND_CLIENTS; client++) { 2715 for (client = 0; client < MAX_FRIEND_CLIENTS; ++client) {
2723 const Client_data *cptr = dht_friend_client(dhtfptr, client); 2716 const Client_data *cptr = dht_friend_client(dhtfptr, client);
2724 const IPPTsPng *const assocs[] = {&cptr->assoc4, &cptr->assoc6}; 2717 const IPPTsPng *const assocs[] = {&cptr->assoc4, &cptr->assoc6};
2725 2718
2726 for (size_t a = 0; a < sizeof(assocs) / sizeof(assocs[0]); a++) { 2719 for (size_t a = 0; a < sizeof(assocs) / sizeof(assocs[0]); ++a) {
2727 const IPPTsPng *const assoc = assocs[a]; 2720 const IPPTsPng *const assoc = assocs[a];
2728 2721
2729 if (ip_isset(&assoc->ip_port.ip)) { 2722 if (ip_isset(&assoc->ip_port.ip)) {
@@ -2764,7 +2757,7 @@ void do_messenger(Messenger *m, void *userdata)
2764#define SAVED_FRIEND_REQUEST_SIZE 1024 2757#define SAVED_FRIEND_REQUEST_SIZE 1024
2765#define NUM_SAVED_PATH_NODES 8 2758#define NUM_SAVED_PATH_NODES 8
2766 2759
2767struct SAVED_FRIEND { 2760struct Saved_Friend {
2768 uint8_t status; 2761 uint8_t status;
2769 uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; 2762 uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE];
2770 uint8_t info[SAVED_FRIEND_REQUEST_SIZE]; // the data that is sent during the friend requests we do. 2763 uint8_t info[SAVED_FRIEND_REQUEST_SIZE]; // the data that is sent during the friend requests we do.
@@ -2781,21 +2774,21 @@ struct SAVED_FRIEND {
2781static uint32_t friend_size(void) 2774static uint32_t friend_size(void)
2782{ 2775{
2783 uint32_t data = 0; 2776 uint32_t data = 0;
2784 const struct SAVED_FRIEND *const temp = nullptr; 2777 const struct Saved_Friend *const temp = nullptr;
2785 2778
2786#define VALUE_MEMBER(NAME) data += sizeof(temp->NAME) 2779#define VALUE_MEMBER(name) do { data += sizeof(temp->name); } while (0)
2787#define ARRAY_MEMBER(NAME) data += sizeof(temp->NAME) 2780#define ARRAY_MEMBER(name) do { data += sizeof(temp->name); } while (0)
2788 2781
2789 // Exactly the same in friend_load, friend_save, and friend_size 2782 // Exactly the same in friend_load, friend_save, and friend_size
2790 VALUE_MEMBER(status); 2783 VALUE_MEMBER(status);
2791 ARRAY_MEMBER(real_pk); 2784 ARRAY_MEMBER(real_pk);
2792 ARRAY_MEMBER(info); 2785 ARRAY_MEMBER(info);
2793 data++; // padding 2786 ++data; // padding
2794 VALUE_MEMBER(info_size); 2787 VALUE_MEMBER(info_size);
2795 ARRAY_MEMBER(name); 2788 ARRAY_MEMBER(name);
2796 VALUE_MEMBER(name_length); 2789 VALUE_MEMBER(name_length);
2797 ARRAY_MEMBER(statusmessage); 2790 ARRAY_MEMBER(statusmessage);
2798 data++; // padding 2791 ++data; // padding
2799 VALUE_MEMBER(statusmessage_length); 2792 VALUE_MEMBER(statusmessage_length);
2800 VALUE_MEMBER(userstatus); 2793 VALUE_MEMBER(userstatus);
2801 data += 3; // padding 2794 data += 3; // padding
@@ -2813,26 +2806,28 @@ static uint32_t saved_friendslist_size(const Messenger *m)
2813 return count_friendlist(m) * friend_size(); 2806 return count_friendlist(m) * friend_size();
2814} 2807}
2815 2808
2816static uint8_t *friend_save(const struct SAVED_FRIEND *temp, uint8_t *data) 2809static uint8_t *friend_save(const struct Saved_Friend *temp, uint8_t *data)
2817{ 2810{
2818#define VALUE_MEMBER(NAME) \ 2811#define VALUE_MEMBER(name) do { \
2819 memcpy(data, &temp->NAME, sizeof(temp->NAME)); \ 2812 memcpy(data, &temp->name, sizeof(temp->name)); \
2820 data += sizeof(temp->NAME) 2813 data += sizeof(temp->name); \
2814} while (0)
2821 2815
2822#define ARRAY_MEMBER(NAME) \ 2816#define ARRAY_MEMBER(name) do { \
2823 memcpy(data, temp->NAME, sizeof(temp->NAME)); \ 2817 memcpy(data, temp->name, sizeof(temp->name)); \
2824 data += sizeof(temp->NAME) 2818 data += sizeof(temp->name); \
2819} while (0)
2825 2820
2826 // Exactly the same in friend_load, friend_save, and friend_size 2821 // Exactly the same in friend_load, friend_save, and friend_size
2827 VALUE_MEMBER(status); 2822 VALUE_MEMBER(status);
2828 ARRAY_MEMBER(real_pk); 2823 ARRAY_MEMBER(real_pk);
2829 ARRAY_MEMBER(info); 2824 ARRAY_MEMBER(info);
2830 data++; // padding 2825 ++data; // padding
2831 VALUE_MEMBER(info_size); 2826 VALUE_MEMBER(info_size);
2832 ARRAY_MEMBER(name); 2827 ARRAY_MEMBER(name);
2833 VALUE_MEMBER(name_length); 2828 VALUE_MEMBER(name_length);
2834 ARRAY_MEMBER(statusmessage); 2829 ARRAY_MEMBER(statusmessage);
2835 data++; // padding 2830 ++data; // padding
2836 VALUE_MEMBER(statusmessage_length); 2831 VALUE_MEMBER(statusmessage_length);
2837 VALUE_MEMBER(userstatus); 2832 VALUE_MEMBER(userstatus);
2838 data += 3; // padding 2833 data += 3; // padding
@@ -2851,9 +2846,9 @@ static uint32_t friends_list_save(const Messenger *m, uint8_t *data)
2851 uint32_t num = 0; 2846 uint32_t num = 0;
2852 uint8_t *cur_data = data; 2847 uint8_t *cur_data = data;
2853 2848
2854 for (i = 0; i < m->numfriends; i++) { 2849 for (i = 0; i < m->numfriends; ++i) {
2855 if (m->friendlist[i].status > 0) { 2850 if (m->friendlist[i].status > 0) {
2856 struct SAVED_FRIEND temp = { 0 }; 2851 struct Saved_Friend temp = { 0 };
2857 temp.status = m->friendlist[i].status; 2852 temp.status = m->friendlist[i].status;
2858 memcpy(temp.real_pk, m->friendlist[i].real_pk, CRYPTO_PUBLIC_KEY_SIZE); 2853 memcpy(temp.real_pk, m->friendlist[i].real_pk, CRYPTO_PUBLIC_KEY_SIZE);
2859 2854
@@ -2884,7 +2879,7 @@ static uint32_t friends_list_save(const Messenger *m, uint8_t *data)
2884 assert(memcmp(cur_data, &temp, friend_size()) == 0); 2879 assert(memcmp(cur_data, &temp, friend_size()) == 0);
2885#endif 2880#endif
2886 cur_data = next_data; 2881 cur_data = next_data;
2887 num++; 2882 ++num;
2888 } 2883 }
2889 } 2884 }
2890 2885
@@ -2892,26 +2887,28 @@ static uint32_t friends_list_save(const Messenger *m, uint8_t *data)
2892 return cur_data - data; 2887 return cur_data - data;
2893} 2888}
2894 2889
2895static const uint8_t *friend_load(struct SAVED_FRIEND *temp, const uint8_t *data) 2890static const uint8_t *friend_load(struct Saved_Friend *temp, const uint8_t *data)
2896{ 2891{
2897#define VALUE_MEMBER(NAME) \ 2892#define VALUE_MEMBER(name) do { \
2898 memcpy(&temp->NAME, data, sizeof(temp->NAME)); \ 2893 memcpy(&temp->name, data, sizeof(temp->name)); \
2899 data += sizeof(temp->NAME) 2894 data += sizeof(temp->name); \
2895} while (0)
2900 2896
2901#define ARRAY_MEMBER(NAME) \ 2897#define ARRAY_MEMBER(name) do { \
2902 memcpy(temp->NAME, data, sizeof(temp->NAME)); \ 2898 memcpy(temp->name, data, sizeof(temp->name)); \
2903 data += sizeof(temp->NAME) 2899 data += sizeof(temp->name); \
2900} while (0)
2904 2901
2905 // Exactly the same in friend_load, friend_save, and friend_size 2902 // Exactly the same in friend_load, friend_save, and friend_size
2906 VALUE_MEMBER(status); 2903 VALUE_MEMBER(status);
2907 ARRAY_MEMBER(real_pk); 2904 ARRAY_MEMBER(real_pk);
2908 ARRAY_MEMBER(info); 2905 ARRAY_MEMBER(info);
2909 data++; // padding 2906 ++data; // padding
2910 VALUE_MEMBER(info_size); 2907 VALUE_MEMBER(info_size);
2911 ARRAY_MEMBER(name); 2908 ARRAY_MEMBER(name);
2912 VALUE_MEMBER(name_length); 2909 VALUE_MEMBER(name_length);
2913 ARRAY_MEMBER(statusmessage); 2910 ARRAY_MEMBER(statusmessage);
2914 data++; // padding 2911 ++data; // padding
2915 VALUE_MEMBER(statusmessage_length); 2912 VALUE_MEMBER(statusmessage_length);
2916 VALUE_MEMBER(userstatus); 2913 VALUE_MEMBER(userstatus);
2917 data += 3; // padding 2914 data += 3; // padding
@@ -2935,7 +2932,7 @@ static int friends_list_load(Messenger *m, const uint8_t *data, uint32_t length)
2935 const uint8_t *cur_data = data; 2932 const uint8_t *cur_data = data;
2936 2933
2937 for (i = 0; i < num; ++i) { 2934 for (i = 0; i < num; ++i) {
2938 struct SAVED_FRIEND temp = { 0 }; 2935 struct Saved_Friend temp = { 0 };
2939 const uint8_t *next_data = friend_load(&temp, cur_data); 2936 const uint8_t *next_data = friend_load(&temp, cur_data);
2940 assert(next_data - cur_data == friend_size()); 2937 assert(next_data - cur_data == friend_size());
2941#ifdef __LP64__ 2938#ifdef __LP64__
@@ -2977,7 +2974,7 @@ uint32_t messenger_size(const Messenger *m)
2977 uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2; 2974 uint32_t size32 = sizeof(uint32_t), sizesubhead = size32 * 2;
2978 return size32 * 2 // global cookie 2975 return size32 * 2 // global cookie
2979 + sizesubhead + sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE 2976 + sizesubhead + sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE
2980 + sizesubhead + DHT_size(m->dht) // DHT 2977 + sizesubhead + dht_size(m->dht) // DHT
2981 + sizesubhead + saved_friendslist_size(m) // Friendlist itself. 2978 + sizesubhead + saved_friendslist_size(m) // Friendlist itself.
2982 + sizesubhead + m->name_length // Own nickname. 2979 + sizesubhead + m->name_length // Own nickname.
2983 + sizesubhead + m->statusmessage_length // status message 2980 + sizesubhead + m->statusmessage_length // status message
@@ -3042,10 +3039,10 @@ void messenger_save(const Messenger *m, uint8_t *data)
3042 *data = m->userstatus; 3039 *data = m->userstatus;
3043 data += len; 3040 data += len;
3044 3041
3045 len = DHT_size(m->dht); 3042 len = dht_size(m->dht);
3046 type = MESSENGER_STATE_TYPE_DHT; 3043 type = MESSENGER_STATE_TYPE_DHT;
3047 data = messenger_save_subheader(data, len, type); 3044 data = messenger_save_subheader(data, len, type);
3048 DHT_save(m->dht, data); 3045 dht_save(m->dht, data);
3049 data += len; 3046 data += len;
3050 3047
3051 Node_format relays[NUM_SAVED_TCP_RELAYS]; 3048 Node_format relays[NUM_SAVED_TCP_RELAYS];
@@ -3098,7 +3095,7 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
3098 break; 3095 break;
3099 3096
3100 case MESSENGER_STATE_TYPE_DHT: 3097 case MESSENGER_STATE_TYPE_DHT:
3101 DHT_load(m->dht, data, length); 3098 dht_load(m->dht, data, length);
3102 break; 3099 break;
3103 3100
3104 case MESSENGER_STATE_TYPE_FRIENDS: 3101 case MESSENGER_STATE_TYPE_FRIENDS:
@@ -3199,9 +3196,9 @@ uint32_t count_friendlist(const Messenger *m)
3199 uint32_t ret = 0; 3196 uint32_t ret = 0;
3200 uint32_t i; 3197 uint32_t i;
3201 3198
3202 for (i = 0; i < m->numfriends; i++) { 3199 for (i = 0; i < m->numfriends; ++i) {
3203 if (m->friendlist[i].status > 0) { 3200 if (m->friendlist[i].status > 0) {
3204 ret++; 3201 ++ret;
3205 } 3202 }
3206 } 3203 }
3207 3204
@@ -3226,14 +3223,14 @@ uint32_t copy_friendlist(Messenger const *m, uint32_t *out_list, uint32_t list_s
3226 uint32_t i; 3223 uint32_t i;
3227 uint32_t ret = 0; 3224 uint32_t ret = 0;
3228 3225
3229 for (i = 0; i < m->numfriends; i++) { 3226 for (i = 0; i < m->numfriends; ++i) {
3230 if (ret >= list_size) { 3227 if (ret >= list_size) {
3231 break; /* Abandon ship */ 3228 break; /* Abandon ship */
3232 } 3229 }
3233 3230
3234 if (m->friendlist[i].status > 0) { 3231 if (m->friendlist[i].status > 0) {
3235 out_list[ret] = i; 3232 out_list[ret] = i;
3236 ret++; 3233 ++ret;
3237 } 3234 }
3238 } 3235 }
3239 3236
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index 402eb916..47025fcc 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -136,8 +136,7 @@ typedef enum {
136 USERSTATUS_AWAY, 136 USERSTATUS_AWAY,
137 USERSTATUS_BUSY, 137 USERSTATUS_BUSY,
138 USERSTATUS_INVALID 138 USERSTATUS_INVALID
139} 139} Userstatus;
140USERSTATUS;
141 140
142#define FILE_ID_LENGTH 32 141#define FILE_ID_LENGTH 32
143 142
@@ -181,6 +180,26 @@ enum {
181 180
182typedef struct Messenger Messenger; 181typedef struct Messenger Messenger;
183 182
183typedef void m_self_connection_status_cb(Messenger *, unsigned int, void *);
184typedef void m_friend_status_cb(Messenger *, uint32_t, unsigned int, void *);
185typedef void m_friend_connection_status_cb(Messenger *, uint32_t, unsigned int, void *);
186typedef void m_friend_message_cb(Messenger *, uint32_t, unsigned int, const uint8_t *, size_t, void *);
187typedef void m_file_recv_control_cb(Messenger *, uint32_t, uint32_t, unsigned int, void *);
188typedef void m_friend_request_cb(Messenger *, const uint8_t *, const uint8_t *, size_t, void *);
189typedef void m_friend_name_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *);
190typedef void m_friend_status_message_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *);
191typedef void m_friend_typing_cb(Messenger *m, uint32_t, bool, void *);
192typedef void m_friend_read_receipt_cb(Messenger *m, uint32_t, uint32_t, void *);
193typedef void m_file_recv_cb(Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *);
194typedef void m_file_chunk_request_cb(Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *);
195typedef void m_file_recv_chunk_cb(Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *);
196typedef void m_friend_lossy_packet_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *);
197typedef void m_friend_lossless_packet_cb(Messenger *m, uint32_t, const uint8_t *, size_t, void *);
198typedef void m_friend_connectionstatuschange_internal_cb(Messenger *m, uint32_t, uint8_t, void *);
199typedef void m_conference_invite_cb(Messenger *m, uint32_t, const uint8_t *, uint16_t, void *);
200typedef void m_msi_packet_cb(Messenger *m, uint32_t, const uint8_t *, uint16_t, void *);
201typedef int m_lossy_rtp_packet_cb(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object);
202
184typedef struct { 203typedef struct {
185 uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; 204 uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE];
186 int friendcon_id; 205 int friendcon_id;
@@ -195,7 +214,7 @@ typedef struct {
195 uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH]; 214 uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH];
196 uint16_t statusmessage_length; 215 uint16_t statusmessage_length;
197 uint8_t statusmessage_sent; 216 uint8_t statusmessage_sent;
198 USERSTATUS userstatus; 217 Userstatus userstatus;
199 uint8_t userstatus_sent; 218 uint8_t userstatus_sent;
200 uint8_t user_istyping; 219 uint8_t user_istyping;
201 uint8_t user_istyping_sent; 220 uint8_t user_istyping_sent;
@@ -210,7 +229,7 @@ typedef struct {
210 struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES]; 229 struct File_Transfers file_receiving[MAX_CONCURRENT_FILE_PIPES];
211 230
212 struct { 231 struct {
213 int (*function)(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object); 232 m_lossy_rtp_packet_cb *function;
214 void *object; 233 void *object;
215 } lossy_rtp_packethandlers[PACKET_LOSSY_AV_RESERVED]; 234 } lossy_rtp_packethandlers[PACKET_LOSSY_AV_RESERVED];
216 235
@@ -239,7 +258,7 @@ struct Messenger {
239 uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH]; 258 uint8_t statusmessage[MAX_STATUSMESSAGE_LENGTH];
240 uint16_t statusmessage_length; 259 uint16_t statusmessage_length;
241 260
242 USERSTATUS userstatus; 261 Userstatus userstatus;
243 262
244 Friend *friendlist; 263 Friend *friendlist;
245 uint32_t numfriends; 264 uint32_t numfriends;
@@ -249,32 +268,31 @@ struct Messenger {
249 uint8_t has_added_relays; // If the first connection has occurred in do_messenger 268 uint8_t has_added_relays; // If the first connection has occurred in do_messenger
250 Node_format loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config 269 Node_format loaded_relays[NUM_SAVED_TCP_RELAYS]; // Relays loaded from config
251 270
252 void (*friend_message)(struct Messenger *m, uint32_t, unsigned int, const uint8_t *, size_t, void *); 271 m_friend_message_cb *friend_message;
253 void (*friend_namechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); 272 m_friend_name_cb *friend_namechange;
254 void (*friend_statusmessagechange)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); 273 m_friend_status_message_cb *friend_statusmessagechange;
255 void (*friend_userstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *); 274 m_friend_status_cb *friend_userstatuschange;
256 void (*friend_typingchange)(struct Messenger *m, uint32_t, bool, void *); 275 m_friend_typing_cb *friend_typingchange;
257 void (*read_receipt)(struct Messenger *m, uint32_t, uint32_t, void *); 276 m_friend_read_receipt_cb *read_receipt;
258 void (*friend_connectionstatuschange)(struct Messenger *m, uint32_t, unsigned int, void *); 277 m_friend_connection_status_cb *friend_connectionstatuschange;
259 void (*friend_connectionstatuschange_internal)(struct Messenger *m, uint32_t, uint8_t, void *); 278 m_friend_connectionstatuschange_internal_cb *friend_connectionstatuschange_internal;
260 void *friend_connectionstatuschange_internal_userdata; 279 void *friend_connectionstatuschange_internal_userdata;
261 280
262 void *conferences_object; /* Set by new_groupchats()*/ 281 void *conferences_object; /* Set by new_groupchats()*/
263 void (*conference_invite)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t, void *); 282 m_conference_invite_cb *conference_invite;
264 283
265 void (*file_sendrequest)(struct Messenger *m, uint32_t, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, 284 m_file_recv_cb *file_sendrequest;
266 void *); 285 m_file_recv_control_cb *file_filecontrol;
267 void (*file_filecontrol)(struct Messenger *m, uint32_t, uint32_t, unsigned int, void *); 286 m_file_recv_chunk_cb *file_filedata;
268 void (*file_filedata)(struct Messenger *m, uint32_t, uint32_t, uint64_t, const uint8_t *, size_t, void *); 287 m_file_chunk_request_cb *file_reqchunk;
269 void (*file_reqchunk)(struct Messenger *m, uint32_t, uint32_t, uint64_t, size_t, void *);
270 288
271 void (*msi_packet)(struct Messenger *m, uint32_t, const uint8_t *, uint16_t, void *); 289 m_msi_packet_cb *msi_packet;
272 void *msi_packet_userdata; 290 void *msi_packet_userdata;
273 291
274 void (*lossy_packethandler)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); 292 m_friend_lossy_packet_cb *lossy_packethandler;
275 void (*lossless_packethandler)(struct Messenger *m, uint32_t, const uint8_t *, size_t, void *); 293 m_friend_lossless_packet_cb *lossless_packethandler;
276 294
277 void (*core_connection_change)(struct Messenger *m, unsigned int, void *); 295 m_self_connection_status_cb *core_connection_change;
278 unsigned int last_connection_status; 296 unsigned int last_connection_status;
279 297
280 Messenger_Options options; 298 Messenger_Options options;
@@ -440,9 +458,9 @@ int m_get_self_statusmessage_size(const Messenger *m);
440int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen); 458int m_copy_statusmessage(const Messenger *m, int32_t friendnumber, uint8_t *buf, uint32_t maxlen);
441int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf); 459int m_copy_self_statusmessage(const Messenger *m, uint8_t *buf);
442 460
443/* return one of USERSTATUS values. 461/* return one of Userstatus values.
444 * Values unknown to your application should be represented as USERSTATUS_NONE. 462 * Values unknown to your application should be represented as USERSTATUS_NONE.
445 * As above, the self variant will return our own USERSTATUS. 463 * As above, the self variant will return our own Userstatus.
446 * If friendnumber is invalid, this shall return USERSTATUS_INVALID. 464 * If friendnumber is invalid, this shall return USERSTATUS_INVALID.
447 */ 465 */
448uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber); 466uint8_t m_get_userstatus(const Messenger *m, int32_t friendnumber);
@@ -499,7 +517,7 @@ void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, uint32_t
499void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *)); 517void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, uint32_t, const uint8_t *, size_t, void *));
500 518
501/* Set the callback for status type changes. 519/* Set the callback for status type changes.
502 * Function(uint32_t friendnumber, USERSTATUS kind) 520 * Function(uint32_t friendnumber, Userstatus kind)
503 */ 521 */
504void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *)); 522void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, uint32_t, unsigned int, void *));
505 523
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c
index fd5e3078..62f76b22 100644
--- a/toxcore/friend_connection.c
+++ b/toxcore/friend_connection.c
@@ -354,7 +354,7 @@ static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint
354 friend_con->dht_pk_lastrecv = unix_time(); 354 friend_con->dht_pk_lastrecv = unix_time();
355 355
356 if (friend_con->dht_lock) { 356 if (friend_con->dht_lock) {
357 if (DHT_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock) != 0) { 357 if (dht_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock) != 0) {
358 printf("a. Could not delete dht peer. Please report this.\n"); 358 printf("a. Could not delete dht peer. Please report this.\n");
359 return; 359 return;
360 } 360 }
@@ -362,7 +362,7 @@ static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint
362 friend_con->dht_lock = 0; 362 friend_con->dht_lock = 0;
363 } 363 }
364 364
365 DHT_addfriend(fr_c->dht, dht_public_key, dht_ip_callback, fr_c, friendcon_id, &friend_con->dht_lock); 365 dht_addfriend(fr_c->dht, dht_public_key, dht_ip_callback, fr_c, friendcon_id, &friend_con->dht_lock);
366 memcpy(friend_con->dht_temp_pk, dht_public_key, CRYPTO_PUBLIC_KEY_SIZE); 366 memcpy(friend_con->dht_temp_pk, dht_public_key, CRYPTO_PUBLIC_KEY_SIZE);
367} 367}
368 368
@@ -789,7 +789,7 @@ int kill_friend_connection(Friend_Connections *fr_c, int friendcon_id)
789 crypto_kill(fr_c->net_crypto, friend_con->crypt_connection_id); 789 crypto_kill(fr_c->net_crypto, friend_con->crypt_connection_id);
790 790
791 if (friend_con->dht_lock) { 791 if (friend_con->dht_lock) {
792 DHT_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock); 792 dht_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock);
793 } 793 }
794 794
795 return wipe_friend_conn(fr_c, friendcon_id); 795 return wipe_friend_conn(fr_c, friendcon_id);
@@ -909,7 +909,7 @@ void do_friend_connections(Friend_Connections *fr_c, void *userdata)
909 if (friend_con->status == FRIENDCONN_STATUS_CONNECTING) { 909 if (friend_con->status == FRIENDCONN_STATUS_CONNECTING) {
910 if (friend_con->dht_pk_lastrecv + FRIEND_DHT_TIMEOUT < temp_time) { 910 if (friend_con->dht_pk_lastrecv + FRIEND_DHT_TIMEOUT < temp_time) {
911 if (friend_con->dht_lock) { 911 if (friend_con->dht_lock) {
912 DHT_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock); 912 dht_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock);
913 friend_con->dht_lock = 0; 913 friend_con->dht_lock = 0;
914 memset(friend_con->dht_temp_pk, 0, CRYPTO_PUBLIC_KEY_SIZE); 914 memset(friend_con->dht_temp_pk, 0, CRYPTO_PUBLIC_KEY_SIZE);
915 } 915 }
diff --git a/toxcore/friend_requests.h b/toxcore/friend_requests.h
index e6948b6c..91571775 100644
--- a/toxcore/friend_requests.h
+++ b/toxcore/friend_requests.h
@@ -41,11 +41,12 @@ uint32_t get_nospam(const Friend_Requests *fr);
41 */ 41 */
42int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk); 42int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk);
43 43
44typedef void fr_friend_request_cb(void *, const uint8_t *, const uint8_t *, size_t, void *);
45
44/* Set the function that will be executed when a friend request for us is received. 46/* Set the function that will be executed when a friend request for us is received.
45 * Function format is function(uint8_t * public_key, uint8_t * data, size_t length, void * userdata) 47 * Function format is function(uint8_t * public_key, uint8_t * data, size_t length, void * userdata)
46 */ 48 */
47void callback_friendrequest(Friend_Requests *fr, void (*function)(void *, const uint8_t *, const uint8_t *, size_t, 49void callback_friendrequest(Friend_Requests *fr, fr_friend_request_cb *function, void *object);
48 void *), void *object);
49 50
50/* Set the function used to check if a friend request should be displayed to the user or not. 51/* Set the function used to check if a friend request should be displayed to the user or not.
51 * Function format is int function(uint8_t * public_key, void * userdata) 52 * Function format is int function(uint8_t * public_key, void * userdata)
diff --git a/toxcore/group.h b/toxcore/group.h
index a81dac39..684f7972 100644
--- a/toxcore/group.h
+++ b/toxcore/group.h
@@ -108,6 +108,9 @@ typedef struct {
108 void (*group_on_delete)(void *, uint32_t); 108 void (*group_on_delete)(void *, uint32_t);
109} Group_c; 109} Group_c;
110 110
111typedef void g_conference_invite_cb(Messenger *, uint32_t, int, const uint8_t *, size_t, void *);
112typedef void g_conference_message_cb(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *);
113
111typedef struct { 114typedef struct {
112 Messenger *m; 115 Messenger *m;
113 Friend_Connections *fr_c; 116 Friend_Connections *fr_c;
@@ -115,8 +118,8 @@ typedef struct {
115 Group_c *chats; 118 Group_c *chats;
116 uint32_t num_chats; 119 uint32_t num_chats;
117 120
118 void (*invite_callback)(Messenger *m, uint32_t, int, const uint8_t *, size_t, void *); 121 g_conference_invite_cb *invite_callback;
119 void (*message_callback)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *); 122 g_conference_message_cb *message_callback;
120 void (*peer_name_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *); 123 void (*peer_name_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *);
121 void (*peer_list_changed_callback)(Messenger *m, uint32_t, void *); 124 void (*peer_list_changed_callback)(Messenger *m, uint32_t, void *);
122 void (*title_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *); 125 void (*title_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *);
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 5eea7a50..bfdbbe30 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -224,7 +224,7 @@ static int create_cookie_request(const Net_Crypto *c, uint8_t *packet, uint8_t *
224 memcpy(plain + CRYPTO_PUBLIC_KEY_SIZE, padding, CRYPTO_PUBLIC_KEY_SIZE); 224 memcpy(plain + CRYPTO_PUBLIC_KEY_SIZE, padding, CRYPTO_PUBLIC_KEY_SIZE);
225 memcpy(plain + (CRYPTO_PUBLIC_KEY_SIZE * 2), &number, sizeof(uint64_t)); 225 memcpy(plain + (CRYPTO_PUBLIC_KEY_SIZE * 2), &number, sizeof(uint64_t));
226 226
227 DHT_get_shared_key_sent(c->dht, shared_key, dht_public_key); 227 dht_get_shared_key_sent(c->dht, shared_key, dht_public_key);
228 uint8_t nonce[CRYPTO_NONCE_SIZE]; 228 uint8_t nonce[CRYPTO_NONCE_SIZE];
229 random_nonce(nonce); 229 random_nonce(nonce);
230 packet[0] = NET_PACKET_COOKIE_REQUEST; 230 packet[0] = NET_PACKET_COOKIE_REQUEST;
@@ -335,7 +335,7 @@ static int handle_cookie_request(const Net_Crypto *c, uint8_t *request_plain, ui
335 } 335 }
336 336
337 memcpy(dht_public_key, packet + 1, CRYPTO_PUBLIC_KEY_SIZE); 337 memcpy(dht_public_key, packet + 1, CRYPTO_PUBLIC_KEY_SIZE);
338 DHT_get_shared_key_sent(c->dht, shared_key, dht_public_key); 338 dht_get_shared_key_sent(c->dht, shared_key, dht_public_key);
339 int len = decrypt_data_symmetric(shared_key, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, 339 int len = decrypt_data_symmetric(shared_key, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE,
340 packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE, COOKIE_REQUEST_PLAIN_LENGTH + CRYPTO_MAC_SIZE, 340 packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE, COOKIE_REQUEST_PLAIN_LENGTH + CRYPTO_MAC_SIZE,
341 request_plain); 341 request_plain);
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index fa6c08c9..35e725b7 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -265,8 +265,8 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format
265 265
266 unsigned int num_nodes = (onion_c->path_nodes_index < MAX_PATH_NODES) ? onion_c->path_nodes_index : MAX_PATH_NODES; 266 unsigned int num_nodes = (onion_c->path_nodes_index < MAX_PATH_NODES) ? onion_c->path_nodes_index : MAX_PATH_NODES;
267 267
268 //if (DHT_non_lan_connected(onion_c->dht)) { 268 //if (dht_non_lan_connected(onion_c->dht)) {
269 if (DHT_isconnected(onion_c->dht)) { 269 if (dht_isconnected(onion_c->dht)) {
270 if (num_nodes == 0) { 270 if (num_nodes == 0) {
271 return 0; 271 return 0;
272 } 272 }
@@ -990,7 +990,7 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con
990 const Family family = nodes[i].ip_port.ip.family; 990 const Family family = nodes[i].ip_port.ip.family;
991 991
992 if (net_family_is_ipv4(family) || net_family_is_ipv6(family)) { 992 if (net_family_is_ipv4(family) || net_family_is_ipv6(family)) {
993 DHT_getnodes(onion_c->dht, &nodes[i].ip_port, nodes[i].public_key, onion_c->friends_list[friend_num].dht_public_key); 993 dht_getnodes(onion_c->dht, &nodes[i].ip_port, nodes[i].public_key, onion_c->friends_list[friend_num].dht_public_key);
994 } else if (net_family_is_tcp_ipv4(family) || net_family_is_tcp_ipv6(family)) { 994 } else if (net_family_is_tcp_ipv4(family) || net_family_is_tcp_ipv6(family)) {
995 if (onion_c->friends_list[friend_num].tcp_relay_node_callback) { 995 if (onion_c->friends_list[friend_num].tcp_relay_node_callback) {
996 void *obj = onion_c->friends_list[friend_num].tcp_relay_node_callback_object; 996 void *obj = onion_c->friends_list[friend_num].tcp_relay_node_callback_object;
@@ -1326,8 +1326,13 @@ int onion_delfriend(Onion_Client *onion_c, int friend_num)
1326 return -1; 1326 return -1;
1327 } 1327 }
1328 1328
1329 //if (onion_c->friends_list[friend_num].know_dht_public_key) 1329#if 0
1330 // DHT_delfriend(onion_c->dht, onion_c->friends_list[friend_num].dht_public_key, 0); 1330
1331 if (onion_c->friends_list[friend_num].know_dht_public_key) {
1332 dht_delfriend(onion_c->dht, onion_c->friends_list[friend_num].dht_public_key, 0);
1333 }
1334
1335#endif
1331 1336
1332 crypto_memzero(&onion_c->friends_list[friend_num], sizeof(Onion_Friend)); 1337 crypto_memzero(&onion_c->friends_list[friend_num], sizeof(Onion_Friend));
1333 unsigned int i; 1338 unsigned int i;
@@ -1456,7 +1461,7 @@ int onion_getfriendip(const Onion_Client *onion_c, int friend_num, IP_Port *ip_p
1456 return -1; 1461 return -1;
1457 } 1462 }
1458 1463
1459 return DHT_getfriendip(onion_c->dht, dht_public_key, ip_port); 1464 return dht_getfriendip(onion_c->dht, dht_public_key, ip_port);
1460} 1465}
1461 1466
1462 1467
@@ -1824,7 +1829,7 @@ void do_onion_client(Onion_Client *onion_c)
1824 } 1829 }
1825 } 1830 }
1826 1831
1827 bool UDP_connected = DHT_non_lan_connected(onion_c->dht); 1832 bool UDP_connected = dht_non_lan_connected(onion_c->dht);
1828 1833
1829 if (is_timeout(onion_c->first_run, ONION_CONNECTION_SECONDS * 2)) { 1834 if (is_timeout(onion_c->first_run, ONION_CONNECTION_SECONDS * 2)) {
1830 set_tcp_onion_status(nc_get_tcp_c(onion_c->c), !UDP_connected); 1835 set_tcp_onion_status(nc_get_tcp_c(onion_c->c), !UDP_connected);
diff --git a/toxcore/ping.c b/toxcore/ping.c
index 3daeff86..3767805d 100644
--- a/toxcore/ping.c
+++ b/toxcore/ping.c
@@ -72,7 +72,7 @@ int32_t ping_send_request(Ping *ping, IP_Port ipp, const uint8_t *public_key)
72 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; 72 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
73 73
74 // generate key to encrypt ping_id with recipient privkey 74 // generate key to encrypt ping_id with recipient privkey
75 DHT_get_shared_key_sent(ping->dht, shared_key, public_key); 75 dht_get_shared_key_sent(ping->dht, shared_key, public_key);
76 // Generate random ping_id. 76 // Generate random ping_id.
77 uint8_t data[PING_DATA_SIZE]; 77 uint8_t data[PING_DATA_SIZE];
78 id_copy(data, public_key); 78 id_copy(data, public_key);
@@ -154,7 +154,7 @@ static int handle_ping_request(void *object, IP_Port source, const uint8_t *pack
154 154
155 uint8_t ping_plain[PING_PLAIN_SIZE]; 155 uint8_t ping_plain[PING_PLAIN_SIZE];
156 // Decrypt ping_id 156 // Decrypt ping_id
157 DHT_get_shared_key_recv(dht, shared_key, packet + 1); 157 dht_get_shared_key_recv(dht, shared_key, packet + 1);
158 rc = decrypt_data_symmetric(shared_key, 158 rc = decrypt_data_symmetric(shared_key,
159 packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, 159 packet + 1 + CRYPTO_PUBLIC_KEY_SIZE,
160 packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE, 160 packet + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE,
@@ -196,7 +196,7 @@ static int handle_ping_response(void *object, IP_Port source, const uint8_t *pac
196 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE]; 196 uint8_t shared_key[CRYPTO_SHARED_KEY_SIZE];
197 197
198 // generate key to encrypt ping_id with recipient privkey 198 // generate key to encrypt ping_id with recipient privkey
199 DHT_get_shared_key_sent(ping->dht, shared_key, packet + 1); 199 dht_get_shared_key_sent(ping->dht, shared_key, packet + 1);
200 200
201 uint8_t ping_plain[PING_PLAIN_SIZE]; 201 uint8_t ping_plain[PING_PLAIN_SIZE];
202 // Decrypt ping_id 202 // Decrypt ping_id
@@ -291,7 +291,7 @@ int32_t ping_add(Ping *ping, const uint8_t *public_key, IP_Port ip_port)
291 291
292 IP_Port temp; 292 IP_Port temp;
293 293
294 if (DHT_getfriendip(ping->dht, public_key, &temp) == 0) { 294 if (dht_getfriendip(ping->dht, public_key, &temp) == 0) {
295 ping_send_request(ping, ip_port, public_key); 295 ping_send_request(ping, ip_port, public_key);
296 return -1; 296 return -1;
297 } 297 }
diff --git a/toxcore/tox.api.h b/toxcore/tox.api.h
index ae10f688..f2c210e1 100644
--- a/toxcore/tox.api.h
+++ b/toxcore/tox.api.h
@@ -2616,5 +2616,41 @@ inline namespace self {
2616} 2616}
2617#endif 2617#endif
2618 2618
2619typedef TOX_ERR_OPTIONS_NEW Tox_Err_Options_New;
2620typedef TOX_ERR_NEW Tox_Err_New;
2621typedef TOX_ERR_BOOTSTRAP Tox_Err_Bootstrap;
2622typedef TOX_ERR_SET_INFO Tox_Err_Set_Info;
2623typedef TOX_ERR_FRIEND_ADD Tox_Err_Friend_Add;
2624typedef TOX_ERR_FRIEND_DELETE Tox_Err_Friend_Delete;
2625typedef TOX_ERR_FRIEND_BY_PUBLIC_KEY Tox_Err_Friend_By_Public_Key;
2626typedef TOX_ERR_FRIEND_GET_PUBLIC_KEY Tox_Err_Friend_Get_Public_Key;
2627typedef TOX_ERR_FRIEND_GET_LAST_ONLINE Tox_Err_Friend_Get_Last_Online;
2628typedef TOX_ERR_FRIEND_QUERY Tox_Err_Friend_Query;
2629typedef TOX_ERR_SET_TYPING Tox_Err_Set_Typing;
2630typedef TOX_ERR_FRIEND_SEND_MESSAGE Tox_Err_Friend_Send_Message;
2631typedef TOX_ERR_FILE_CONTROL Tox_Err_File_Control;
2632typedef TOX_ERR_FILE_SEEK Tox_Err_File_Seek;
2633typedef TOX_ERR_FILE_GET Tox_Err_File_Get;
2634typedef TOX_ERR_FILE_SEND Tox_Err_File_Send;
2635typedef TOX_ERR_FILE_SEND_CHUNK Tox_Err_File_Send_Chunk;
2636typedef TOX_ERR_CONFERENCE_NEW Tox_Err_Conference_New;
2637typedef TOX_ERR_CONFERENCE_DELETE Tox_Err_Conference_Delete;
2638typedef TOX_ERR_CONFERENCE_PEER_QUERY Tox_Err_Conference_Peer_Query;
2639typedef TOX_ERR_CONFERENCE_INVITE Tox_Err_Conference_Invite;
2640typedef TOX_ERR_CONFERENCE_JOIN Tox_Err_Conference_Join;
2641typedef TOX_ERR_CONFERENCE_SEND_MESSAGE Tox_Err_Conference_Send_Message;
2642typedef TOX_ERR_CONFERENCE_TITLE Tox_Err_Conference_Title;
2643typedef TOX_ERR_CONFERENCE_GET_TYPE Tox_Err_Conference_Get_Type;
2644typedef TOX_ERR_FRIEND_CUSTOM_PACKET Tox_Err_Friend_Custom_Packet;
2645typedef TOX_ERR_GET_PORT Tox_Err_Get_Port;
2646typedef TOX_USER_STATUS Tox_User_Status;
2647typedef TOX_MESSAGE_TYPE Tox_Message_Type;
2648typedef TOX_PROXY_TYPE Tox_Proxy_Type;
2649typedef TOX_SAVEDATA_TYPE Tox_Savedata_Type;
2650typedef TOX_LOG_LEVEL Tox_Log_Level;
2651typedef TOX_CONNECTION Tox_Connection;
2652typedef TOX_FILE_CONTROL Tox_File_Control;
2653typedef TOX_CONFERENCE_TYPE Tox_Conference_Type;
2654
2619#endif 2655#endif
2620%} 2656%}
diff --git a/toxcore/tox.c b/toxcore/tox.c
index f7613d4f..c121eb2e 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -40,38 +40,38 @@ typedef struct Messenger Tox;
40 40
41#include "../toxencryptsave/defines.h" 41#include "../toxencryptsave/defines.h"
42 42
43#define SET_ERROR_PARAMETER(param, x) {if(param) {*param = x;}} 43#define SET_ERROR_PARAMETER(param, x) do { if (param) { *param = x; } } while (0)
44 44
45#if TOX_HASH_LENGTH != CRYPTO_SHA256_SIZE 45#if TOX_HASH_LENGTH != CRYPTO_SHA256_SIZE
46#error TOX_HASH_LENGTH is assumed to be equal to CRYPTO_SHA256_SIZE 46#error "TOX_HASH_LENGTH is assumed to be equal to CRYPTO_SHA256_SIZE"
47#endif 47#endif
48 48
49#if FILE_ID_LENGTH != CRYPTO_SYMMETRIC_KEY_SIZE 49#if FILE_ID_LENGTH != CRYPTO_SYMMETRIC_KEY_SIZE
50#error FILE_ID_LENGTH is assumed to be equal to CRYPTO_SYMMETRIC_KEY_SIZE 50#error "FILE_ID_LENGTH is assumed to be equal to CRYPTO_SYMMETRIC_KEY_SIZE"
51#endif 51#endif
52 52
53#if TOX_FILE_ID_LENGTH != CRYPTO_SYMMETRIC_KEY_SIZE 53#if TOX_FILE_ID_LENGTH != CRYPTO_SYMMETRIC_KEY_SIZE
54#error TOX_FILE_ID_LENGTH is assumed to be equal to CRYPTO_SYMMETRIC_KEY_SIZE 54#error "TOX_FILE_ID_LENGTH is assumed to be equal to CRYPTO_SYMMETRIC_KEY_SIZE"
55#endif 55#endif
56 56
57#if TOX_FILE_ID_LENGTH != TOX_HASH_LENGTH 57#if TOX_FILE_ID_LENGTH != TOX_HASH_LENGTH
58#error TOX_FILE_ID_LENGTH is assumed to be equal to TOX_HASH_LENGTH 58#error "TOX_FILE_ID_LENGTH is assumed to be equal to TOX_HASH_LENGTH"
59#endif 59#endif
60 60
61#if TOX_PUBLIC_KEY_SIZE != CRYPTO_PUBLIC_KEY_SIZE 61#if TOX_PUBLIC_KEY_SIZE != CRYPTO_PUBLIC_KEY_SIZE
62#error TOX_PUBLIC_KEY_SIZE is assumed to be equal to CRYPTO_PUBLIC_KEY_SIZE 62#error "TOX_PUBLIC_KEY_SIZE is assumed to be equal to CRYPTO_PUBLIC_KEY_SIZE"
63#endif 63#endif
64 64
65#if TOX_SECRET_KEY_SIZE != CRYPTO_SECRET_KEY_SIZE 65#if TOX_SECRET_KEY_SIZE != CRYPTO_SECRET_KEY_SIZE
66#error TOX_SECRET_KEY_SIZE is assumed to be equal to CRYPTO_SECRET_KEY_SIZE 66#error "TOX_SECRET_KEY_SIZE is assumed to be equal to CRYPTO_SECRET_KEY_SIZE"
67#endif 67#endif
68 68
69#if TOX_MAX_NAME_LENGTH != MAX_NAME_LENGTH 69#if TOX_MAX_NAME_LENGTH != MAX_NAME_LENGTH
70#error TOX_MAX_NAME_LENGTH is assumed to be equal to MAX_NAME_LENGTH 70#error "TOX_MAX_NAME_LENGTH is assumed to be equal to MAX_NAME_LENGTH"
71#endif 71#endif
72 72
73#if TOX_MAX_STATUS_MESSAGE_LENGTH != MAX_STATUSMESSAGE_LENGTH 73#if TOX_MAX_STATUS_MESSAGE_LENGTH != MAX_STATUSMESSAGE_LENGTH
74#error TOX_MAX_STATUS_MESSAGE_LENGTH is assumed to be equal to MAX_STATUSMESSAGE_LENGTH 74#error "TOX_MAX_STATUS_MESSAGE_LENGTH is assumed to be equal to MAX_STATUSMESSAGE_LENGTH"
75#endif 75#endif
76 76
77 77
@@ -81,7 +81,7 @@ bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch)
81} 81}
82 82
83 83
84Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error) 84Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error)
85{ 85{
86 Messenger_Options m_options = {0}; 86 Messenger_Options m_options = {0};
87 87
@@ -90,7 +90,7 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
90 struct Tox_Options *default_options = nullptr; 90 struct Tox_Options *default_options = nullptr;
91 91
92 if (options == nullptr) { 92 if (options == nullptr) {
93 TOX_ERR_OPTIONS_NEW err; 93 Tox_Err_Options_New err;
94 default_options = tox_options_new(&err); 94 default_options = tox_options_new(&err);
95 95
96 switch (err) { 96 switch (err) {
@@ -248,7 +248,7 @@ void tox_get_savedata(const Tox *tox, uint8_t *savedata)
248 } 248 }
249} 249}
250 250
251bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, TOX_ERR_BOOTSTRAP *error) 251bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, Tox_Err_Bootstrap *error)
252{ 252{
253 if (!host || !public_key) { 253 if (!host || !public_key) {
254 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL); 254 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL);
@@ -272,12 +272,12 @@ bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *pub
272 272
273 unsigned int i; 273 unsigned int i;
274 274
275 for (i = 0; i < count; i++) { 275 for (i = 0; i < count; ++i) {
276 root[i].port = net_htons(port); 276 root[i].port = net_htons(port);
277 277
278 Messenger *m = tox; 278 Messenger *m = tox;
279 onion_add_bs_path_node(m->onion_c, root[i], public_key); 279 onion_add_bs_path_node(m->onion_c, root[i], public_key);
280 DHT_bootstrap(m->dht, root[i], public_key); 280 dht_bootstrap(m->dht, root[i], public_key);
281 } 281 }
282 282
283 net_freeipport(root); 283 net_freeipport(root);
@@ -292,7 +292,7 @@ bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *pub
292} 292}
293 293
294bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, 294bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key,
295 TOX_ERR_BOOTSTRAP *error) 295 Tox_Err_Bootstrap *error)
296{ 296{
297 if (!host || !public_key) { 297 if (!host || !public_key) {
298 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL); 298 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_NULL);
@@ -316,7 +316,7 @@ bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t
316 316
317 unsigned int i; 317 unsigned int i;
318 318
319 for (i = 0; i < count; i++) { 319 for (i = 0; i < count; ++i) {
320 root[i].port = net_htons(port); 320 root[i].port = net_htons(port);
321 321
322 Messenger *m = tox; 322 Messenger *m = tox;
@@ -334,7 +334,7 @@ bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t
334 return 0; 334 return 0;
335} 335}
336 336
337TOX_CONNECTION tox_self_get_connection_status(const Tox *tox) 337Tox_Connection tox_self_get_connection_status(const Tox *tox)
338{ 338{
339 const Messenger *m = tox; 339 const Messenger *m = tox;
340 340
@@ -355,7 +355,7 @@ TOX_CONNECTION tox_self_get_connection_status(const Tox *tox)
355void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback) 355void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback)
356{ 356{
357 Messenger *m = tox; 357 Messenger *m = tox;
358 m_callback_core_connection(m, (void (*)(Messenger *, unsigned int, void *))callback); 358 m_callback_core_connection(m, (m_self_connection_status_cb *)callback);
359} 359}
360 360
361uint32_t tox_iteration_interval(const Tox *tox) 361uint32_t tox_iteration_interval(const Tox *tox)
@@ -409,7 +409,7 @@ void tox_self_get_secret_key(const Tox *tox, uint8_t *secret_key)
409 } 409 }
410} 410}
411 411
412bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, TOX_ERR_SET_INFO *error) 412bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, Tox_Err_Set_Info *error)
413{ 413{
414 if (!name && length != 0) { 414 if (!name && length != 0) {
415 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL); 415 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL);
@@ -443,7 +443,7 @@ void tox_self_get_name(const Tox *tox, uint8_t *name)
443 } 443 }
444} 444}
445 445
446bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t length, TOX_ERR_SET_INFO *error) 446bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t length, Tox_Err_Set_Info *error)
447{ 447{
448 if (!status_message && length != 0) { 448 if (!status_message && length != 0) {
449 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL); 449 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_NULL);
@@ -475,20 +475,20 @@ void tox_self_get_status_message(const Tox *tox, uint8_t *status_message)
475 } 475 }
476} 476}
477 477
478void tox_self_set_status(Tox *tox, TOX_USER_STATUS status) 478void tox_self_set_status(Tox *tox, Tox_User_Status status)
479{ 479{
480 Messenger *m = tox; 480 Messenger *m = tox;
481 m_set_userstatus(m, status); 481 m_set_userstatus(m, status);
482} 482}
483 483
484TOX_USER_STATUS tox_self_get_status(const Tox *tox) 484Tox_User_Status tox_self_get_status(const Tox *tox)
485{ 485{
486 const Messenger *m = tox; 486 const Messenger *m = tox;
487 const uint8_t status = m_get_self_userstatus(m); 487 const uint8_t status = m_get_self_userstatus(m);
488 return (TOX_USER_STATUS)status; 488 return (Tox_User_Status)status;
489} 489}
490 490
491static void set_friend_error(int32_t ret, TOX_ERR_FRIEND_ADD *error) 491static void set_friend_error(int32_t ret, Tox_Err_Friend_Add *error)
492{ 492{
493 switch (ret) { 493 switch (ret) {
494 case FAERR_TOOLONG: 494 case FAERR_TOOLONG:
@@ -522,7 +522,7 @@ static void set_friend_error(int32_t ret, TOX_ERR_FRIEND_ADD *error)
522} 522}
523 523
524uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message, size_t length, 524uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message, size_t length,
525 TOX_ERR_FRIEND_ADD *error) 525 Tox_Err_Friend_Add *error)
526{ 526{
527 if (!address || !message) { 527 if (!address || !message) {
528 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL); 528 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL);
@@ -541,7 +541,7 @@ uint32_t tox_friend_add(Tox *tox, const uint8_t *address, const uint8_t *message
541 return UINT32_MAX; 541 return UINT32_MAX;
542} 542}
543 543
544uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, TOX_ERR_FRIEND_ADD *error) 544uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, Tox_Err_Friend_Add *error)
545{ 545{
546 if (!public_key) { 546 if (!public_key) {
547 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL); 547 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_NULL);
@@ -560,7 +560,7 @@ uint32_t tox_friend_add_norequest(Tox *tox, const uint8_t *public_key, TOX_ERR_F
560 return UINT32_MAX; 560 return UINT32_MAX;
561} 561}
562 562
563bool tox_friend_delete(Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_DELETE *error) 563bool tox_friend_delete(Tox *tox, uint32_t friend_number, Tox_Err_Friend_Delete *error)
564{ 564{
565 Messenger *m = tox; 565 Messenger *m = tox;
566 int ret = m_delfriend(m, friend_number); 566 int ret = m_delfriend(m, friend_number);
@@ -575,7 +575,7 @@ bool tox_friend_delete(Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_DELETE *
575 return 1; 575 return 1;
576} 576}
577 577
578uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, TOX_ERR_FRIEND_BY_PUBLIC_KEY *error) 578uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, Tox_Err_Friend_By_Public_Key *error)
579{ 579{
580 if (!public_key) { 580 if (!public_key) {
581 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_BY_PUBLIC_KEY_NULL); 581 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_BY_PUBLIC_KEY_NULL);
@@ -595,7 +595,7 @@ uint32_t tox_friend_by_public_key(const Tox *tox, const uint8_t *public_key, TOX
595} 595}
596 596
597bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t *public_key, 597bool tox_friend_get_public_key(const Tox *tox, uint32_t friend_number, uint8_t *public_key,
598 TOX_ERR_FRIEND_GET_PUBLIC_KEY *error) 598 Tox_Err_Friend_Get_Public_Key *error)
599{ 599{
600 if (!public_key) { 600 if (!public_key) {
601 return 0; 601 return 0;
@@ -618,13 +618,13 @@ bool tox_friend_exists(const Tox *tox, uint32_t friend_number)
618 return m_friend_exists(m, friend_number); 618 return m_friend_exists(m, friend_number);
619} 619}
620 620
621uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_GET_LAST_ONLINE *error) 621uint64_t tox_friend_get_last_online(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Get_Last_Online *error)
622{ 622{
623 const Messenger *m = tox; 623 const Messenger *m = tox;
624 uint64_t timestamp = m_get_last_online(m, friend_number); 624 uint64_t timestamp = m_get_last_online(m, friend_number);
625 625
626 if (timestamp == UINT64_MAX) { 626 if (timestamp == UINT64_MAX) {
627 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_GET_LAST_ONLINE_FRIEND_NOT_FOUND) 627 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_GET_LAST_ONLINE_FRIEND_NOT_FOUND);
628 return UINT64_MAX; 628 return UINT64_MAX;
629 } 629 }
630 630
@@ -647,7 +647,7 @@ void tox_self_get_friend_list(const Tox *tox, uint32_t *friend_list)
647 } 647 }
648} 648}
649 649
650size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error) 650size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
651{ 651{
652 const Messenger *m = tox; 652 const Messenger *m = tox;
653 int ret = m_get_name_size(m, friend_number); 653 int ret = m_get_name_size(m, friend_number);
@@ -661,7 +661,7 @@ size_t tox_friend_get_name_size(const Tox *tox, uint32_t friend_number, TOX_ERR_
661 return ret; 661 return ret;
662} 662}
663 663
664bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, TOX_ERR_FRIEND_QUERY *error) 664bool tox_friend_get_name(const Tox *tox, uint32_t friend_number, uint8_t *name, Tox_Err_Friend_Query *error)
665{ 665{
666 if (!name) { 666 if (!name) {
667 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL); 667 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL);
@@ -686,7 +686,7 @@ void tox_callback_friend_name(Tox *tox, tox_friend_name_cb *callback)
686 m_callback_namechange(m, callback); 686 m_callback_namechange(m, callback);
687} 687}
688 688
689size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error) 689size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
690{ 690{
691 const Messenger *m = tox; 691 const Messenger *m = tox;
692 int ret = m_get_statusmessage_size(m, friend_number); 692 int ret = m_get_statusmessage_size(m, friend_number);
@@ -701,7 +701,7 @@ size_t tox_friend_get_status_message_size(const Tox *tox, uint32_t friend_number
701} 701}
702 702
703bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8_t *status_message, 703bool tox_friend_get_status_message(const Tox *tox, uint32_t friend_number, uint8_t *status_message,
704 TOX_ERR_FRIEND_QUERY *error) 704 Tox_Err_Friend_Query *error)
705{ 705{
706 if (!status_message) { 706 if (!status_message) {
707 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL); 707 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_NULL);
@@ -727,7 +727,7 @@ void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb *
727 m_callback_statusmessage(m, callback); 727 m_callback_statusmessage(m, callback);
728} 728}
729 729
730TOX_USER_STATUS tox_friend_get_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error) 730Tox_User_Status tox_friend_get_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
731{ 731{
732 const Messenger *m = tox; 732 const Messenger *m = tox;
733 733
@@ -735,20 +735,20 @@ TOX_USER_STATUS tox_friend_get_status(const Tox *tox, uint32_t friend_number, TO
735 735
736 if (ret == USERSTATUS_INVALID) { 736 if (ret == USERSTATUS_INVALID) {
737 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND); 737 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND);
738 return (TOX_USER_STATUS)(TOX_USER_STATUS_BUSY + 1); 738 return (Tox_User_Status)(TOX_USER_STATUS_BUSY + 1);
739 } 739 }
740 740
741 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_OK); 741 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_OK);
742 return (TOX_USER_STATUS)ret; 742 return (Tox_User_Status)ret;
743} 743}
744 744
745void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *callback) 745void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *callback)
746{ 746{
747 Messenger *m = tox; 747 Messenger *m = tox;
748 m_callback_userstatus(m, (void (*)(Messenger *, uint32_t, unsigned int, void *))callback); 748 m_callback_userstatus(m, (m_friend_status_cb *)callback);
749} 749}
750 750
751TOX_CONNECTION tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error) 751Tox_Connection tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
752{ 752{
753 const Messenger *m = tox; 753 const Messenger *m = tox;
754 754
@@ -760,16 +760,16 @@ TOX_CONNECTION tox_friend_get_connection_status(const Tox *tox, uint32_t friend_
760 } 760 }
761 761
762 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_OK); 762 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_OK);
763 return (TOX_CONNECTION)ret; 763 return (Tox_Connection)ret;
764} 764}
765 765
766void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback) 766void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback)
767{ 767{
768 Messenger *m = tox; 768 Messenger *m = tox;
769 m_callback_connectionstatus(m, (void (*)(Messenger *, uint32_t, unsigned int, void *))callback); 769 m_callback_connectionstatus(m, (m_friend_connection_status_cb *)callback);
770} 770}
771 771
772bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error) 772bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, Tox_Err_Friend_Query *error)
773{ 773{
774 const Messenger *m = tox; 774 const Messenger *m = tox;
775 int ret = m_get_istyping(m, friend_number); 775 int ret = m_get_istyping(m, friend_number);
@@ -789,7 +789,7 @@ void tox_callback_friend_typing(Tox *tox, tox_friend_typing_cb *callback)
789 m_callback_typingchange(m, callback); 789 m_callback_typingchange(m, callback);
790} 790}
791 791
792bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool typing, TOX_ERR_SET_TYPING *error) 792bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool typing, Tox_Err_Set_Typing *error)
793{ 793{
794 Messenger *m = tox; 794 Messenger *m = tox;
795 795
@@ -802,7 +802,7 @@ bool tox_self_set_typing(Tox *tox, uint32_t friend_number, bool typing, TOX_ERR_
802 return 1; 802 return 1;
803} 803}
804 804
805static void set_message_error(int ret, TOX_ERR_FRIEND_SEND_MESSAGE *error) 805static void set_message_error(int ret, Tox_Err_Friend_Send_Message *error)
806{ 806{
807 switch (ret) { 807 switch (ret) {
808 case 0: 808 case 0:
@@ -831,8 +831,8 @@ static void set_message_error(int ret, TOX_ERR_FRIEND_SEND_MESSAGE *error)
831 } 831 }
832} 832}
833 833
834uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, TOX_MESSAGE_TYPE type, const uint8_t *message, 834uint32_t tox_friend_send_message(Tox *tox, uint32_t friend_number, Tox_Message_Type type, const uint8_t *message,
835 size_t length, TOX_ERR_FRIEND_SEND_MESSAGE *error) 835 size_t length, Tox_Err_Friend_Send_Message *error)
836{ 836{
837 if (!message) { 837 if (!message) {
838 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_NULL); 838 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_SEND_MESSAGE_NULL);
@@ -865,7 +865,7 @@ void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback)
865void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback) 865void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback)
866{ 866{
867 Messenger *m = tox; 867 Messenger *m = tox;
868 m_callback_friendmessage(m, (void (*)(Messenger *, uint32_t, unsigned int, const uint8_t *, size_t, void *))callback); 868 m_callback_friendmessage(m, (m_friend_message_cb *)callback);
869} 869}
870 870
871bool tox_hash(uint8_t *hash, const uint8_t *data, size_t length) 871bool tox_hash(uint8_t *hash, const uint8_t *data, size_t length)
@@ -878,8 +878,8 @@ bool tox_hash(uint8_t *hash, const uint8_t *data, size_t length)
878 return 1; 878 return 1;
879} 879}
880 880
881bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TOX_FILE_CONTROL control, 881bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, Tox_File_Control control,
882 TOX_ERR_FILE_CONTROL *error) 882 Tox_Err_File_Control *error)
883{ 883{
884 Messenger *m = tox; 884 Messenger *m = tox;
885 int ret = file_control(m, friend_number, file_number, control); 885 int ret = file_control(m, friend_number, file_number, control);
@@ -928,7 +928,7 @@ bool tox_file_control(Tox *tox, uint32_t friend_number, uint32_t file_number, TO
928} 928}
929 929
930bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, 930bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position,
931 TOX_ERR_FILE_SEEK *error) 931 Tox_Err_File_Seek *error)
932{ 932{
933 Messenger *m = tox; 933 Messenger *m = tox;
934 int ret = file_seek(m, friend_number, file_number, position); 934 int ret = file_seek(m, friend_number, file_number, position);
@@ -972,11 +972,11 @@ bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint6
972void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback) 972void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback)
973{ 973{
974 Messenger *m = tox; 974 Messenger *m = tox;
975 callback_file_control(m, (void (*)(Messenger *, uint32_t, uint32_t, unsigned int, void *))callback); 975 callback_file_control(m, (m_file_recv_control_cb *)callback);
976} 976}
977 977
978bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id, 978bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id,
979 TOX_ERR_FILE_GET *error) 979 Tox_Err_File_Get *error)
980{ 980{
981 if (!file_id) { 981 if (!file_id) {
982 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NULL); 982 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NULL);
@@ -1001,7 +1001,7 @@ bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_
1001} 1001}
1002 1002
1003uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t file_size, const uint8_t *file_id, 1003uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t file_size, const uint8_t *file_id,
1004 const uint8_t *filename, size_t filename_length, TOX_ERR_FILE_SEND *error) 1004 const uint8_t *filename, size_t filename_length, Tox_Err_File_Send *error)
1005{ 1005{
1006 if (filename_length && !filename) { 1006 if (filename_length && !filename) {
1007 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_NULL); 1007 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_SEND_NULL);
@@ -1047,7 +1047,7 @@ uint32_t tox_file_send(Tox *tox, uint32_t friend_number, uint32_t kind, uint64_t
1047} 1047}
1048 1048
1049bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data, 1049bool tox_file_send_chunk(Tox *tox, uint32_t friend_number, uint32_t file_number, uint64_t position, const uint8_t *data,
1050 size_t length, TOX_ERR_FILE_SEND_CHUNK *error) 1050 size_t length, Tox_Err_File_Send_Chunk *error)
1051{ 1051{
1052 Messenger *m = tox; 1052 Messenger *m = tox;
1053 int ret = file_data(m, friend_number, file_number, position, data, length); 1053 int ret = file_data(m, friend_number, file_number, position, data, length);
@@ -1112,17 +1112,13 @@ void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback)
1112void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback) 1112void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback)
1113{ 1113{
1114 Messenger *m = tox; 1114 Messenger *m = tox;
1115 g_callback_group_invite((Group_Chats *)m->conferences_object, (void (*)(Messenger * m, uint32_t, int, const uint8_t *, 1115 g_callback_group_invite((Group_Chats *)m->conferences_object, (g_conference_invite_cb *)callback);
1116 size_t,
1117 void *))callback);
1118} 1116}
1119 1117
1120void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callback) 1118void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callback)
1121{ 1119{
1122 Messenger *m = tox; 1120 Messenger *m = tox;
1123 g_callback_group_message((Group_Chats *)m->conferences_object, (void (*)(Messenger * m, uint32_t, uint32_t, int, 1121 g_callback_group_message((Group_Chats *)m->conferences_object, (g_conference_message_cb *)callback);
1124 const uint8_t *,
1125 size_t, void *))callback);
1126} 1122}
1127 1123
1128void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback) 1124void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback)
@@ -1143,7 +1139,7 @@ void tox_callback_conference_peer_list_changed(Tox *tox, tox_conference_peer_lis
1143 g_callback_peer_list_changed((Group_Chats *)m->conferences_object, callback); 1139 g_callback_peer_list_changed((Group_Chats *)m->conferences_object, callback);
1144} 1140}
1145 1141
1146uint32_t tox_conference_new(Tox *tox, TOX_ERR_CONFERENCE_NEW *error) 1142uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error)
1147{ 1143{
1148 Messenger *m = tox; 1144 Messenger *m = tox;
1149 int ret = add_groupchat((Group_Chats *)m->conferences_object, GROUPCHAT_TYPE_TEXT); 1145 int ret = add_groupchat((Group_Chats *)m->conferences_object, GROUPCHAT_TYPE_TEXT);
@@ -1157,7 +1153,7 @@ uint32_t tox_conference_new(Tox *tox, TOX_ERR_CONFERENCE_NEW *error)
1157 return ret; 1153 return ret;
1158} 1154}
1159 1155
1160bool tox_conference_delete(Tox *tox, uint32_t conference_number, TOX_ERR_CONFERENCE_DELETE *error) 1156bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Conference_Delete *error)
1161{ 1157{
1162 Messenger *m = tox; 1158 Messenger *m = tox;
1163 int ret = del_groupchat((Group_Chats *)m->conferences_object, conference_number); 1159 int ret = del_groupchat((Group_Chats *)m->conferences_object, conference_number);
@@ -1171,7 +1167,7 @@ bool tox_conference_delete(Tox *tox, uint32_t conference_number, TOX_ERR_CONFERE
1171 return true; 1167 return true;
1172} 1168}
1173 1169
1174uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, TOX_ERR_CONFERENCE_PEER_QUERY *error) 1170uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Peer_Query *error)
1175{ 1171{
1176 const Messenger *m = tox; 1172 const Messenger *m = tox;
1177 int ret = group_number_peers((Group_Chats *)m->conferences_object, conference_number); 1173 int ret = group_number_peers((Group_Chats *)m->conferences_object, conference_number);
@@ -1186,7 +1182,7 @@ uint32_t tox_conference_peer_count(const Tox *tox, uint32_t conference_number, T
1186} 1182}
1187 1183
1188size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_number, uint32_t peer_number, 1184size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_number, uint32_t peer_number,
1189 TOX_ERR_CONFERENCE_PEER_QUERY *error) 1185 Tox_Err_Conference_Peer_Query *error)
1190{ 1186{
1191 const Messenger *m = tox; 1187 const Messenger *m = tox;
1192 int ret = group_peername_size((Group_Chats *)m->conferences_object, conference_number, peer_number); 1188 int ret = group_peername_size((Group_Chats *)m->conferences_object, conference_number, peer_number);
@@ -1206,7 +1202,7 @@ size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t conference_num
1206} 1202}
1207 1203
1208bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, uint32_t peer_number, uint8_t *name, 1204bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, uint32_t peer_number, uint8_t *name,
1209 TOX_ERR_CONFERENCE_PEER_QUERY *error) 1205 Tox_Err_Conference_Peer_Query *error)
1210{ 1206{
1211 const Messenger *m = tox; 1207 const Messenger *m = tox;
1212 int ret = group_peername((Group_Chats *)m->conferences_object, conference_number, peer_number, name); 1208 int ret = group_peername((Group_Chats *)m->conferences_object, conference_number, peer_number, name);
@@ -1226,7 +1222,7 @@ bool tox_conference_peer_get_name(const Tox *tox, uint32_t conference_number, ui
1226} 1222}
1227 1223
1228bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_number, uint32_t peer_number, 1224bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_number, uint32_t peer_number,
1229 uint8_t *public_key, TOX_ERR_CONFERENCE_PEER_QUERY *error) 1225 uint8_t *public_key, Tox_Err_Conference_Peer_Query *error)
1230{ 1226{
1231 const Messenger *m = tox; 1227 const Messenger *m = tox;
1232 int ret = group_peer_pubkey((Group_Chats *)m->conferences_object, conference_number, peer_number, public_key); 1228 int ret = group_peer_pubkey((Group_Chats *)m->conferences_object, conference_number, peer_number, public_key);
@@ -1246,7 +1242,7 @@ bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t conference_numb
1246} 1242}
1247 1243
1248bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_number, uint32_t peer_number, 1244bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_number, uint32_t peer_number,
1249 TOX_ERR_CONFERENCE_PEER_QUERY *error) 1245 Tox_Err_Conference_Peer_Query *error)
1250{ 1246{
1251 const Messenger *m = tox; 1247 const Messenger *m = tox;
1252 int ret = group_peernumber_is_ours((Group_Chats *)m->conferences_object, conference_number, peer_number); 1248 int ret = group_peernumber_is_ours((Group_Chats *)m->conferences_object, conference_number, peer_number);
@@ -1270,7 +1266,7 @@ bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t conference_numb
1270} 1266}
1271 1267
1272bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference_number, 1268bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference_number,
1273 TOX_ERR_CONFERENCE_INVITE *error) 1269 Tox_Err_Conference_Invite *error)
1274{ 1270{
1275 Messenger *m = tox; 1271 Messenger *m = tox;
1276 int ret = invite_friend((Group_Chats *)m->conferences_object, friend_number, conference_number); 1272 int ret = invite_friend((Group_Chats *)m->conferences_object, friend_number, conference_number);
@@ -1290,7 +1286,7 @@ bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t conference
1290} 1286}
1291 1287
1292uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *cookie, size_t length, 1288uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *cookie, size_t length,
1293 TOX_ERR_CONFERENCE_JOIN *error) 1289 Tox_Err_Conference_Join *error)
1294{ 1290{
1295 Messenger *m = tox; 1291 Messenger *m = tox;
1296 int ret = join_groupchat((Group_Chats *)m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length); 1292 int ret = join_groupchat((Group_Chats *)m->conferences_object, friend_number, GROUPCHAT_TYPE_TEXT, cookie, length);
@@ -1325,8 +1321,8 @@ uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *co
1325 return ret; 1321 return ret;
1326} 1322}
1327 1323
1328bool tox_conference_send_message(Tox *tox, uint32_t conference_number, TOX_MESSAGE_TYPE type, const uint8_t *message, 1324bool tox_conference_send_message(Tox *tox, uint32_t conference_number, Tox_Message_Type type, const uint8_t *message,
1329 size_t length, TOX_ERR_CONFERENCE_SEND_MESSAGE *error) 1325 size_t length, Tox_Err_Conference_Send_Message *error)
1330{ 1326{
1331 Messenger *m = tox; 1327 Messenger *m = tox;
1332 int ret = 0; 1328 int ret = 0;
@@ -1359,7 +1355,7 @@ bool tox_conference_send_message(Tox *tox, uint32_t conference_number, TOX_MESSA
1359 return true; 1355 return true;
1360} 1356}
1361 1357
1362size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, TOX_ERR_CONFERENCE_TITLE *error) 1358size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number, Tox_Err_Conference_Title *error)
1363{ 1359{
1364 const Messenger *m = tox; 1360 const Messenger *m = tox;
1365 int ret = group_title_get_size((Group_Chats *)m->conferences_object, conference_number); 1361 int ret = group_title_get_size((Group_Chats *)m->conferences_object, conference_number);
@@ -1379,7 +1375,7 @@ size_t tox_conference_get_title_size(const Tox *tox, uint32_t conference_number,
1379} 1375}
1380 1376
1381bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_t *title, 1377bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_t *title,
1382 TOX_ERR_CONFERENCE_TITLE *error) 1378 Tox_Err_Conference_Title *error)
1383{ 1379{
1384 const Messenger *m = tox; 1380 const Messenger *m = tox;
1385 int ret = group_title_get((Group_Chats *)m->conferences_object, conference_number, title); 1381 int ret = group_title_get((Group_Chats *)m->conferences_object, conference_number, title);
@@ -1399,7 +1395,7 @@ bool tox_conference_get_title(const Tox *tox, uint32_t conference_number, uint8_
1399} 1395}
1400 1396
1401bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_t *title, size_t length, 1397bool tox_conference_set_title(Tox *tox, uint32_t conference_number, const uint8_t *title, size_t length,
1402 TOX_ERR_CONFERENCE_TITLE *error) 1398 Tox_Err_Conference_Title *error)
1403{ 1399{
1404 Messenger *m = tox; 1400 Messenger *m = tox;
1405 int ret = group_title_send((Group_Chats *)m->conferences_object, conference_number, title, length); 1401 int ret = group_title_send((Group_Chats *)m->conferences_object, conference_number, title, length);
@@ -1435,22 +1431,22 @@ void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist)
1435 copy_chatlist((Group_Chats *)m->conferences_object, chatlist, list_size); 1431 copy_chatlist((Group_Chats *)m->conferences_object, chatlist, list_size);
1436} 1432}
1437 1433
1438TOX_CONFERENCE_TYPE tox_conference_get_type(const Tox *tox, uint32_t conference_number, 1434Tox_Conference_Type tox_conference_get_type(const Tox *tox, uint32_t conference_number,
1439 TOX_ERR_CONFERENCE_GET_TYPE *error) 1435 Tox_Err_Conference_Get_Type *error)
1440{ 1436{
1441 const Messenger *m = tox; 1437 const Messenger *m = tox;
1442 int ret = group_get_type((Group_Chats *)m->conferences_object, conference_number); 1438 int ret = group_get_type((Group_Chats *)m->conferences_object, conference_number);
1443 1439
1444 if (ret == -1) { 1440 if (ret == -1) {
1445 SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_GET_TYPE_CONFERENCE_NOT_FOUND); 1441 SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_GET_TYPE_CONFERENCE_NOT_FOUND);
1446 return (TOX_CONFERENCE_TYPE)ret; 1442 return (Tox_Conference_Type)ret;
1447 } 1443 }
1448 1444
1449 SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_GET_TYPE_OK); 1445 SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_GET_TYPE_OK);
1450 return (TOX_CONFERENCE_TYPE)ret; 1446 return (Tox_Conference_Type)ret;
1451} 1447}
1452 1448
1453static void set_custom_packet_error(int ret, TOX_ERR_FRIEND_CUSTOM_PACKET *error) 1449static void set_custom_packet_error(int ret, Tox_Err_Friend_Custom_Packet *error)
1454{ 1450{
1455 switch (ret) { 1451 switch (ret) {
1456 case 0: 1452 case 0:
@@ -1480,7 +1476,7 @@ static void set_custom_packet_error(int ret, TOX_ERR_FRIEND_CUSTOM_PACKET *error
1480} 1476}
1481 1477
1482bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, 1478bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length,
1483 TOX_ERR_FRIEND_CUSTOM_PACKET *error) 1479 Tox_Err_Friend_Custom_Packet *error)
1484{ 1480{
1485 if (!data) { 1481 if (!data) {
1486 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL); 1482 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL);
@@ -1517,7 +1513,7 @@ void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *call
1517} 1513}
1518 1514
1519bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length, 1515bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length,
1520 TOX_ERR_FRIEND_CUSTOM_PACKET *error) 1516 Tox_Err_Friend_Custom_Packet *error)
1521{ 1517{
1522 if (!data) { 1518 if (!data) {
1523 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL); 1519 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_CUSTOM_PACKET_NULL);
@@ -1556,7 +1552,7 @@ void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id)
1556 } 1552 }
1557} 1553}
1558 1554
1559uint16_t tox_self_get_udp_port(const Tox *tox, TOX_ERR_GET_PORT *error) 1555uint16_t tox_self_get_udp_port(const Tox *tox, Tox_Err_Get_Port *error)
1560{ 1556{
1561 const Messenger *m = tox; 1557 const Messenger *m = tox;
1562 uint16_t port = net_htons(net_port(m->net)); 1558 uint16_t port = net_htons(net_port(m->net));
@@ -1570,7 +1566,7 @@ uint16_t tox_self_get_udp_port(const Tox *tox, TOX_ERR_GET_PORT *error)
1570 return port; 1566 return port;
1571} 1567}
1572 1568
1573uint16_t tox_self_get_tcp_port(const Tox *tox, TOX_ERR_GET_PORT *error) 1569uint16_t tox_self_get_tcp_port(const Tox *tox, Tox_Err_Get_Port *error)
1574{ 1570{
1575 const Messenger *m = tox; 1571 const Messenger *m = tox;
1576 1572
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 45ebf176..faf4e559 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -2976,4 +2976,40 @@ uint16_t tox_self_get_tcp_port(const Tox *tox, TOX_ERR_GET_PORT *error);
2976} 2976}
2977#endif 2977#endif
2978 2978
2979typedef TOX_ERR_OPTIONS_NEW Tox_Err_Options_New;
2980typedef TOX_ERR_NEW Tox_Err_New;
2981typedef TOX_ERR_BOOTSTRAP Tox_Err_Bootstrap;
2982typedef TOX_ERR_SET_INFO Tox_Err_Set_Info;
2983typedef TOX_ERR_FRIEND_ADD Tox_Err_Friend_Add;
2984typedef TOX_ERR_FRIEND_DELETE Tox_Err_Friend_Delete;
2985typedef TOX_ERR_FRIEND_BY_PUBLIC_KEY Tox_Err_Friend_By_Public_Key;
2986typedef TOX_ERR_FRIEND_GET_PUBLIC_KEY Tox_Err_Friend_Get_Public_Key;
2987typedef TOX_ERR_FRIEND_GET_LAST_ONLINE Tox_Err_Friend_Get_Last_Online;
2988typedef TOX_ERR_FRIEND_QUERY Tox_Err_Friend_Query;
2989typedef TOX_ERR_SET_TYPING Tox_Err_Set_Typing;
2990typedef TOX_ERR_FRIEND_SEND_MESSAGE Tox_Err_Friend_Send_Message;
2991typedef TOX_ERR_FILE_CONTROL Tox_Err_File_Control;
2992typedef TOX_ERR_FILE_SEEK Tox_Err_File_Seek;
2993typedef TOX_ERR_FILE_GET Tox_Err_File_Get;
2994typedef TOX_ERR_FILE_SEND Tox_Err_File_Send;
2995typedef TOX_ERR_FILE_SEND_CHUNK Tox_Err_File_Send_Chunk;
2996typedef TOX_ERR_CONFERENCE_NEW Tox_Err_Conference_New;
2997typedef TOX_ERR_CONFERENCE_DELETE Tox_Err_Conference_Delete;
2998typedef TOX_ERR_CONFERENCE_PEER_QUERY Tox_Err_Conference_Peer_Query;
2999typedef TOX_ERR_CONFERENCE_INVITE Tox_Err_Conference_Invite;
3000typedef TOX_ERR_CONFERENCE_JOIN Tox_Err_Conference_Join;
3001typedef TOX_ERR_CONFERENCE_SEND_MESSAGE Tox_Err_Conference_Send_Message;
3002typedef TOX_ERR_CONFERENCE_TITLE Tox_Err_Conference_Title;
3003typedef TOX_ERR_CONFERENCE_GET_TYPE Tox_Err_Conference_Get_Type;
3004typedef TOX_ERR_FRIEND_CUSTOM_PACKET Tox_Err_Friend_Custom_Packet;
3005typedef TOX_ERR_GET_PORT Tox_Err_Get_Port;
3006typedef TOX_USER_STATUS Tox_User_Status;
3007typedef TOX_MESSAGE_TYPE Tox_Message_Type;
3008typedef TOX_PROXY_TYPE Tox_Proxy_Type;
3009typedef TOX_SAVEDATA_TYPE Tox_Savedata_Type;
3010typedef TOX_LOG_LEVEL Tox_Log_Level;
3011typedef TOX_CONNECTION Tox_Connection;
3012typedef TOX_FILE_CONTROL Tox_File_Control;
3013typedef TOX_CONFERENCE_TYPE Tox_Conference_Type;
3014
2979#endif 3015#endif
diff --git a/toxcore/tox_api.c b/toxcore/tox_api.c
index 31f21158..87123968 100644
--- a/toxcore/tox_api.c
+++ b/toxcore/tox_api.c
@@ -5,7 +5,7 @@
5#include <stdlib.h> 5#include <stdlib.h>
6#include <string.h> 6#include <string.h>
7 7
8#define SET_ERROR_PARAMETER(param, x) {if(param) {*param = x;}} 8#define SET_ERROR_PARAMETER(param, x) do { if (param) { *param = x; } } while (0)
9 9
10 10
11#define CONST_FUNCTION(lowercase, uppercase) \ 11#define CONST_FUNCTION(lowercase, uppercase) \
diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c
index 4f827c9e..7c81f722 100644
--- a/toxencryptsave/toxencryptsave.c
+++ b/toxencryptsave/toxencryptsave.c
@@ -29,7 +29,7 @@
29#include "../toxcore/crypto_core.h" 29#include "../toxcore/crypto_core.h"
30#include "defines.h" 30#include "defines.h"
31#include "toxencryptsave.h" 31#include "toxencryptsave.h"
32#define SET_ERROR_PARAMETER(param, x) {if(param) {*param = x;}} 32#define SET_ERROR_PARAMETER(param, x) do { if (param) { *param = x; } } while (0)
33 33
34#ifdef VANILLA_NACL 34#ifdef VANILLA_NACL
35#include <crypto_box.h> 35#include <crypto_box.h>