diff options
author | iphydf <iphydf@users.noreply.github.com> | 2020-05-04 00:40:59 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2020-05-04 01:27:36 +0100 |
commit | 02a5bdc60c9ff8474a959027882048290571f806 (patch) | |
tree | 202664eeef476f77e73e63fefb59451ec5e008b7 | |
parent | 4efe541814ec2ddd073428d6928497b50c48397a (diff) |
Add logging to TCP and onion client.
-rw-r--r-- | auto_tests/TCP_test.c | 92 | ||||
-rw-r--r-- | auto_tests/onion_test.c | 2 | ||||
-rw-r--r-- | other/DHT_bootstrap.c | 2 | ||||
-rw-r--r-- | other/bootstrap_daemon/docker/tox-bootstrapd.sha256 | 2 | ||||
-rw-r--r-- | other/bootstrap_daemon/src/tox-bootstrapd.c | 3 | ||||
-rw-r--r-- | toxcore/Messenger.c | 8 | ||||
-rw-r--r-- | toxcore/TCP_client.c | 38 | ||||
-rw-r--r-- | toxcore/TCP_client.h | 3 | ||||
-rw-r--r-- | toxcore/TCP_connection.c | 8 | ||||
-rw-r--r-- | toxcore/TCP_connection.h | 3 | ||||
-rw-r--r-- | toxcore/TCP_server.c | 39 | ||||
-rw-r--r-- | toxcore/TCP_server.h | 12 | ||||
-rw-r--r-- | toxcore/friend_connection.c | 7 | ||||
-rw-r--r-- | toxcore/friend_connection.h | 2 | ||||
-rw-r--r-- | toxcore/net_crypto.c | 2 | ||||
-rw-r--r-- | toxcore/onion_client.c | 4 | ||||
-rw-r--r-- | toxcore/onion_client.h | 2 | ||||
-rw-r--r-- | toxcore/util.c | 4 |
18 files changed, 128 insertions, 105 deletions
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index 8a109317..c09e336c 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c | |||
@@ -48,12 +48,13 @@ static uint16_t ports[NUM_PORTS] = {13215, 33445, 25643}; | |||
48 | START_TEST(test_basic) | 48 | START_TEST(test_basic) |
49 | { | 49 | { |
50 | Mono_Time *mono_time = mono_time_new(); | 50 | Mono_Time *mono_time = mono_time_new(); |
51 | Logger *logger = logger_new(); | ||
51 | 52 | ||
52 | // Attempt to create a new TCP_Server instance. | 53 | // Attempt to create a new TCP_Server instance. |
53 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; | 54 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
54 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; | 55 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
55 | crypto_new_keypair(self_public_key, self_secret_key); | 56 | crypto_new_keypair(self_public_key, self_secret_key); |
56 | TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr); | 57 | TCP_Server *tcp_s = new_TCP_server(logger, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr); |
57 | ck_assert_msg(tcp_s != nullptr, "Failed to create a TCP relay server."); | 58 | ck_assert_msg(tcp_s != nullptr, "Failed to create a TCP relay server."); |
58 | ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, | 59 | ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, |
59 | "Failed to bind a TCP relay server to all %d attempted ports.", NUM_PORTS); | 60 | "Failed to bind a TCP relay server to all %d attempted ports.", NUM_PORTS); |
@@ -170,6 +171,7 @@ START_TEST(test_basic) | |||
170 | kill_sock(sock); | 171 | kill_sock(sock); |
171 | kill_TCP_server(tcp_s); | 172 | kill_TCP_server(tcp_s); |
172 | 173 | ||
174 | logger_kill(logger); | ||
173 | mono_time_free(mono_time); | 175 | mono_time_free(mono_time); |
174 | } | 176 | } |
175 | END_TEST | 177 | END_TEST |
@@ -272,11 +274,12 @@ static int read_packet_sec_TCP(struct sec_TCP_con *con, uint8_t *data, uint16_t | |||
272 | START_TEST(test_some) | 274 | START_TEST(test_some) |
273 | { | 275 | { |
274 | Mono_Time *mono_time = mono_time_new(); | 276 | Mono_Time *mono_time = mono_time_new(); |
277 | Logger *logger = logger_new(); | ||
275 | 278 | ||
276 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; | 279 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
277 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; | 280 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
278 | crypto_new_keypair(self_public_key, self_secret_key); | 281 | crypto_new_keypair(self_public_key, self_secret_key); |
279 | TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr); | 282 | TCP_Server *tcp_s = new_TCP_server(logger, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr); |
280 | ck_assert_msg(tcp_s != nullptr, "Failed to create TCP relay server"); | 283 | ck_assert_msg(tcp_s != nullptr, "Failed to create TCP relay server"); |
281 | ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports."); | 284 | ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports."); |
282 | 285 | ||
@@ -371,6 +374,7 @@ START_TEST(test_some) | |||
371 | kill_TCP_con(con2); | 374 | kill_TCP_con(con2); |
372 | kill_TCP_con(con3); | 375 | kill_TCP_con(con3); |
373 | 376 | ||
377 | logger_kill(logger); | ||
374 | mono_time_free(mono_time); | 378 | mono_time_free(mono_time); |
375 | } | 379 | } |
376 | END_TEST | 380 | END_TEST |
@@ -459,11 +463,12 @@ static int oob_data_callback(void *object, const uint8_t *public_key, const uint | |||
459 | START_TEST(test_client) | 463 | START_TEST(test_client) |
460 | { | 464 | { |
461 | Mono_Time *mono_time = mono_time_new(); | 465 | Mono_Time *mono_time = mono_time_new(); |
466 | Logger *logger = logger_new(); | ||
462 | 467 | ||
463 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; | 468 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
464 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; | 469 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
465 | crypto_new_keypair(self_public_key, self_secret_key); | 470 | crypto_new_keypair(self_public_key, self_secret_key); |
466 | TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr); | 471 | TCP_Server *tcp_s = new_TCP_server(logger, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr); |
467 | ck_assert_msg(tcp_s != nullptr, "Failed to create a TCP relay server."); | 472 | ck_assert_msg(tcp_s != nullptr, "Failed to create a TCP relay server."); |
468 | ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind the relay server to all ports."); | 473 | ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind the relay server to all ports."); |
469 | 474 | ||
@@ -477,7 +482,7 @@ START_TEST(test_client) | |||
477 | 482 | ||
478 | TCP_Client_Connection *conn = new_TCP_connection(mono_time, ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, | 483 | TCP_Client_Connection *conn = new_TCP_connection(mono_time, ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, |
479 | nullptr); | 484 | nullptr); |
480 | do_TCP_connection(mono_time, conn, nullptr); | 485 | do_TCP_connection(logger, mono_time, conn, nullptr); |
481 | c_sleep(50); | 486 | c_sleep(50); |
482 | 487 | ||
483 | // The connection status should be unconfirmed here because we have finished | 488 | // The connection status should be unconfirmed here because we have finished |
@@ -491,7 +496,7 @@ START_TEST(test_client) | |||
491 | 496 | ||
492 | for (uint8_t i = 0; i < LOOP_SIZE; i++) { | 497 | for (uint8_t i = 0; i < LOOP_SIZE; i++) { |
493 | mono_time_update(mono_time); | 498 | mono_time_update(mono_time); |
494 | do_TCP_connection(mono_time, conn, nullptr); // Run the connection loop. | 499 | do_TCP_connection(logger, mono_time, conn, nullptr); // Run the connection loop. |
495 | 500 | ||
496 | // The status of the connection should continue to be TCP_CLIENT_CONFIRMED after multiple subsequent do_TCP_connection() calls. | 501 | // The status of the connection should continue to be TCP_CLIENT_CONFIRMED after multiple subsequent do_TCP_connection() calls. |
497 | ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONFIRMED, "Wrong connection status. Expected: %d, is: %d", | 502 | ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONFIRMED, "Wrong connection status. Expected: %d, is: %d", |
@@ -525,13 +530,13 @@ START_TEST(test_client) | |||
525 | // These integers will increment per successful callback. | 530 | // These integers will increment per successful callback. |
526 | oob_data_callback_good = response_callback_good = status_callback_good = data_callback_good = 0; | 531 | oob_data_callback_good = response_callback_good = status_callback_good = data_callback_good = 0; |
527 | 532 | ||
528 | do_TCP_connection(mono_time, conn, nullptr); | 533 | do_TCP_connection(logger, mono_time, conn, nullptr); |
529 | do_TCP_connection(mono_time, conn2, nullptr); | 534 | do_TCP_connection(logger, mono_time, conn2, nullptr); |
530 | 535 | ||
531 | do_TCP_server_delay(tcp_s, mono_time, 50); | 536 | do_TCP_server_delay(tcp_s, mono_time, 50); |
532 | 537 | ||
533 | do_TCP_connection(mono_time, conn, nullptr); | 538 | do_TCP_connection(logger, mono_time, conn, nullptr); |
534 | do_TCP_connection(mono_time, conn2, nullptr); | 539 | do_TCP_connection(logger, mono_time, conn2, nullptr); |
535 | c_sleep(50); | 540 | c_sleep(50); |
536 | 541 | ||
537 | uint8_t data[5] = {1, 2, 3, 4, 5}; | 542 | uint8_t data[5] = {1, 2, 3, 4, 5}; |
@@ -542,8 +547,8 @@ START_TEST(test_client) | |||
542 | 547 | ||
543 | do_TCP_server_delay(tcp_s, mono_time, 50); | 548 | do_TCP_server_delay(tcp_s, mono_time, 50); |
544 | 549 | ||
545 | do_TCP_connection(mono_time, conn, nullptr); | 550 | do_TCP_connection(logger, mono_time, conn, nullptr); |
546 | do_TCP_connection(mono_time, conn2, nullptr); | 551 | do_TCP_connection(logger, mono_time, conn2, nullptr); |
547 | 552 | ||
548 | // All callback methods save data should have run during the above network prodding. | 553 | // All callback methods save data should have run during the above network prodding. |
549 | ck_assert_msg(oob_data_callback_good == 1, "OOB callback not called"); | 554 | ck_assert_msg(oob_data_callback_good == 1, "OOB callback not called"); |
@@ -560,16 +565,16 @@ START_TEST(test_client) | |||
560 | 565 | ||
561 | do_TCP_server_delay(tcp_s, mono_time, 50); | 566 | do_TCP_server_delay(tcp_s, mono_time, 50); |
562 | 567 | ||
563 | do_TCP_connection(mono_time, conn, nullptr); | 568 | do_TCP_connection(logger, mono_time, conn, nullptr); |
564 | do_TCP_connection(mono_time, conn2, nullptr); | 569 | do_TCP_connection(logger, mono_time, conn2, nullptr); |
565 | ck_assert_msg(data_callback_good == 1, "Data callback was not called."); | 570 | ck_assert_msg(data_callback_good == 1, "Data callback was not called."); |
566 | status_callback_good = 0; | 571 | status_callback_good = 0; |
567 | send_disconnect_request(conn2, 0); | 572 | send_disconnect_request(conn2, 0); |
568 | 573 | ||
569 | do_TCP_server_delay(tcp_s, mono_time, 50); | 574 | do_TCP_server_delay(tcp_s, mono_time, 50); |
570 | 575 | ||
571 | do_TCP_connection(mono_time, conn, nullptr); | 576 | do_TCP_connection(logger, mono_time, conn, nullptr); |
572 | do_TCP_connection(mono_time, conn2, nullptr); | 577 | do_TCP_connection(logger, mono_time, conn2, nullptr); |
573 | ck_assert_msg(status_callback_good == 1, "Status callback not called"); | 578 | ck_assert_msg(status_callback_good == 1, "Status callback not called"); |
574 | ck_assert_msg(status_callback_status == 1, "Wrong status callback status."); | 579 | ck_assert_msg(status_callback_status == 1, "Wrong status callback status."); |
575 | 580 | ||
@@ -578,6 +583,7 @@ START_TEST(test_client) | |||
578 | kill_TCP_connection(conn); | 583 | kill_TCP_connection(conn); |
579 | kill_TCP_connection(conn2); | 584 | kill_TCP_connection(conn2); |
580 | 585 | ||
586 | logger_kill(logger); | ||
581 | mono_time_free(mono_time); | 587 | mono_time_free(mono_time); |
582 | } | 588 | } |
583 | END_TEST | 589 | END_TEST |
@@ -586,6 +592,7 @@ END_TEST | |||
586 | START_TEST(test_client_invalid) | 592 | START_TEST(test_client_invalid) |
587 | { | 593 | { |
588 | Mono_Time *mono_time = mono_time_new(); | 594 | Mono_Time *mono_time = mono_time_new(); |
595 | Logger *logger = logger_new(); | ||
589 | 596 | ||
590 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; | 597 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
591 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; | 598 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
@@ -603,7 +610,7 @@ START_TEST(test_client_invalid) | |||
603 | 610 | ||
604 | // Run the client's main loop but not the server. | 611 | // Run the client's main loop but not the server. |
605 | mono_time_update(mono_time); | 612 | mono_time_update(mono_time); |
606 | do_TCP_connection(mono_time, conn, nullptr); | 613 | do_TCP_connection(logger, mono_time, conn, nullptr); |
607 | c_sleep(50); | 614 | c_sleep(50); |
608 | 615 | ||
609 | // After 50ms of no response... | 616 | // After 50ms of no response... |
@@ -612,18 +619,19 @@ START_TEST(test_client_invalid) | |||
612 | // After 5s... | 619 | // After 5s... |
613 | c_sleep(5000); | 620 | c_sleep(5000); |
614 | mono_time_update(mono_time); | 621 | mono_time_update(mono_time); |
615 | do_TCP_connection(mono_time, conn, nullptr); | 622 | do_TCP_connection(logger, mono_time, conn, nullptr); |
616 | ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %d, is: %d.", | 623 | ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %d, is: %d.", |
617 | TCP_CLIENT_CONNECTING, tcp_con_status(conn)); | 624 | TCP_CLIENT_CONNECTING, tcp_con_status(conn)); |
618 | // 11s... (Should wait for 10 before giving up.) | 625 | // 11s... (Should wait for 10 before giving up.) |
619 | c_sleep(6000); | 626 | c_sleep(6000); |
620 | mono_time_update(mono_time); | 627 | mono_time_update(mono_time); |
621 | do_TCP_connection(mono_time, conn, nullptr); | 628 | do_TCP_connection(logger, mono_time, conn, nullptr); |
622 | ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %d, is: %d.", | 629 | ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %d, is: %d.", |
623 | TCP_CLIENT_DISCONNECTED, tcp_con_status(conn)); | 630 | TCP_CLIENT_DISCONNECTED, tcp_con_status(conn)); |
624 | 631 | ||
625 | kill_TCP_connection(conn); | 632 | kill_TCP_connection(conn); |
626 | 633 | ||
634 | logger_kill(logger); | ||
627 | mono_time_free(mono_time); | 635 | mono_time_free(mono_time); |
628 | } | 636 | } |
629 | END_TEST | 637 | END_TEST |
@@ -657,12 +665,13 @@ static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t | |||
657 | START_TEST(test_tcp_connection) | 665 | START_TEST(test_tcp_connection) |
658 | { | 666 | { |
659 | Mono_Time *mono_time = mono_time_new(); | 667 | Mono_Time *mono_time = mono_time_new(); |
668 | Logger *logger = logger_new(); | ||
660 | 669 | ||
661 | tcp_data_callback_called = 0; | 670 | tcp_data_callback_called = 0; |
662 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; | 671 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
663 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; | 672 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
664 | crypto_new_keypair(self_public_key, self_secret_key); | 673 | crypto_new_keypair(self_public_key, self_secret_key); |
665 | TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr); | 674 | TCP_Server *tcp_s = new_TCP_server(logger, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr); |
666 | ck_assert_msg(public_key_cmp(tcp_server_public_key(tcp_s), self_public_key) == 0, "Wrong public key"); | 675 | ck_assert_msg(public_key_cmp(tcp_server_public_key(tcp_s), self_public_key) == 0, "Wrong public key"); |
667 | 676 | ||
668 | TCP_Proxy_Info proxy_info; | 677 | TCP_Proxy_Info proxy_info; |
@@ -696,18 +705,18 @@ START_TEST(test_tcp_connection) | |||
696 | 705 | ||
697 | do_TCP_server_delay(tcp_s, mono_time, 50); | 706 | do_TCP_server_delay(tcp_s, mono_time, 50); |
698 | 707 | ||
699 | do_tcp_connections(tc_1, nullptr); | 708 | do_tcp_connections(logger, tc_1, nullptr); |
700 | do_tcp_connections(tc_2, nullptr); | 709 | do_tcp_connections(logger, tc_2, nullptr); |
701 | 710 | ||
702 | do_TCP_server_delay(tcp_s, mono_time, 50); | 711 | do_TCP_server_delay(tcp_s, mono_time, 50); |
703 | 712 | ||
704 | do_tcp_connections(tc_1, nullptr); | 713 | do_tcp_connections(logger, tc_1, nullptr); |
705 | do_tcp_connections(tc_2, nullptr); | 714 | do_tcp_connections(logger, tc_2, nullptr); |
706 | 715 | ||
707 | do_TCP_server_delay(tcp_s, mono_time, 50); | 716 | do_TCP_server_delay(tcp_s, mono_time, 50); |
708 | 717 | ||
709 | do_tcp_connections(tc_1, nullptr); | 718 | do_tcp_connections(logger, tc_1, nullptr); |
710 | do_tcp_connections(tc_2, nullptr); | 719 | do_tcp_connections(logger, tc_2, nullptr); |
711 | 720 | ||
712 | int ret = send_packet_tcp_connection(tc_1, 0, (const uint8_t *)"Gentoo", 6); | 721 | int ret = send_packet_tcp_connection(tc_1, 0, (const uint8_t *)"Gentoo", 6); |
713 | ck_assert_msg(ret == 0, "could not send packet."); | 722 | ck_assert_msg(ret == 0, "could not send packet."); |
@@ -715,8 +724,8 @@ START_TEST(test_tcp_connection) | |||
715 | 724 | ||
716 | do_TCP_server_delay(tcp_s, mono_time, 50); | 725 | do_TCP_server_delay(tcp_s, mono_time, 50); |
717 | 726 | ||
718 | do_tcp_connections(tc_1, nullptr); | 727 | do_tcp_connections(logger, tc_1, nullptr); |
719 | do_tcp_connections(tc_2, nullptr); | 728 | do_tcp_connections(logger, tc_2, nullptr); |
720 | 729 | ||
721 | ck_assert_msg(tcp_data_callback_called, "could not recv packet."); | 730 | ck_assert_msg(tcp_data_callback_called, "could not recv packet."); |
722 | ck_assert_msg(tcp_connection_to_online_tcp_relays(tc_1, 0) == 1, "Wrong number of connected relays"); | 731 | ck_assert_msg(tcp_connection_to_online_tcp_relays(tc_1, 0) == 1, "Wrong number of connected relays"); |
@@ -724,8 +733,8 @@ START_TEST(test_tcp_connection) | |||
724 | 733 | ||
725 | do_TCP_server_delay(tcp_s, mono_time, 50); | 734 | do_TCP_server_delay(tcp_s, mono_time, 50); |
726 | 735 | ||
727 | do_tcp_connections(tc_1, nullptr); | 736 | do_tcp_connections(logger, tc_1, nullptr); |
728 | do_tcp_connections(tc_2, nullptr); | 737 | do_tcp_connections(logger, tc_2, nullptr); |
729 | 738 | ||
730 | ck_assert_msg(send_packet_tcp_connection(tc_1, 0, (const uint8_t *)"Gentoo", 6) == -1, "could send packet."); | 739 | ck_assert_msg(send_packet_tcp_connection(tc_1, 0, (const uint8_t *)"Gentoo", 6) == -1, "could send packet."); |
731 | ck_assert_msg(kill_tcp_connection_to(tc_2, 0) == 0, "could not kill connection to\n"); | 740 | ck_assert_msg(kill_tcp_connection_to(tc_2, 0) == 0, "could not kill connection to\n"); |
@@ -734,6 +743,7 @@ START_TEST(test_tcp_connection) | |||
734 | kill_tcp_connections(tc_1); | 743 | kill_tcp_connections(tc_1); |
735 | kill_tcp_connections(tc_2); | 744 | kill_tcp_connections(tc_2); |
736 | 745 | ||
746 | logger_kill(logger); | ||
737 | mono_time_free(mono_time); | 747 | mono_time_free(mono_time); |
738 | } | 748 | } |
739 | END_TEST | 749 | END_TEST |
@@ -762,6 +772,7 @@ static int tcp_oobdata_callback(void *object, const uint8_t *public_key, unsigne | |||
762 | START_TEST(test_tcp_connection2) | 772 | START_TEST(test_tcp_connection2) |
763 | { | 773 | { |
764 | Mono_Time *mono_time = mono_time_new(); | 774 | Mono_Time *mono_time = mono_time_new(); |
775 | Logger *logger = logger_new(); | ||
765 | 776 | ||
766 | tcp_oobdata_callback_called = 0; | 777 | tcp_oobdata_callback_called = 0; |
767 | tcp_data_callback_called = 0; | 778 | tcp_data_callback_called = 0; |
@@ -769,7 +780,7 @@ START_TEST(test_tcp_connection2) | |||
769 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; | 780 | uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
770 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; | 781 | uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE]; |
771 | crypto_new_keypair(self_public_key, self_secret_key); | 782 | crypto_new_keypair(self_public_key, self_secret_key); |
772 | TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr); | 783 | TCP_Server *tcp_s = new_TCP_server(logger, USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr); |
773 | ck_assert_msg(public_key_cmp(tcp_server_public_key(tcp_s), self_public_key) == 0, "Wrong public key"); | 784 | ck_assert_msg(public_key_cmp(tcp_server_public_key(tcp_s), self_public_key) == 0, "Wrong public key"); |
774 | 785 | ||
775 | TCP_Proxy_Info proxy_info; | 786 | TCP_Proxy_Info proxy_info; |
@@ -797,18 +808,18 @@ START_TEST(test_tcp_connection2) | |||
797 | 808 | ||
798 | do_TCP_server_delay(tcp_s, mono_time, 50); | 809 | do_TCP_server_delay(tcp_s, mono_time, 50); |
799 | 810 | ||
800 | do_tcp_connections(tc_1, nullptr); | 811 | do_tcp_connections(logger, tc_1, nullptr); |
801 | do_tcp_connections(tc_2, nullptr); | 812 | do_tcp_connections(logger, tc_2, nullptr); |
802 | 813 | ||
803 | do_TCP_server_delay(tcp_s, mono_time, 50); | 814 | do_TCP_server_delay(tcp_s, mono_time, 50); |
804 | 815 | ||
805 | do_tcp_connections(tc_1, nullptr); | 816 | do_tcp_connections(logger, tc_1, nullptr); |
806 | do_tcp_connections(tc_2, nullptr); | 817 | do_tcp_connections(logger, tc_2, nullptr); |
807 | 818 | ||
808 | do_TCP_server_delay(tcp_s, mono_time, 50); | 819 | do_TCP_server_delay(tcp_s, mono_time, 50); |
809 | 820 | ||
810 | do_tcp_connections(tc_1, nullptr); | 821 | do_tcp_connections(logger, tc_1, nullptr); |
811 | do_tcp_connections(tc_2, nullptr); | 822 | do_tcp_connections(logger, tc_2, nullptr); |
812 | 823 | ||
813 | int ret = send_packet_tcp_connection(tc_1, 0, (const uint8_t *)"Gentoo", 6); | 824 | int ret = send_packet_tcp_connection(tc_1, 0, (const uint8_t *)"Gentoo", 6); |
814 | ck_assert_msg(ret == 0, "could not send packet."); | 825 | ck_assert_msg(ret == 0, "could not send packet."); |
@@ -817,15 +828,15 @@ START_TEST(test_tcp_connection2) | |||
817 | 828 | ||
818 | do_TCP_server_delay(tcp_s, mono_time, 50); | 829 | do_TCP_server_delay(tcp_s, mono_time, 50); |
819 | 830 | ||
820 | do_tcp_connections(tc_1, nullptr); | 831 | do_tcp_connections(logger, tc_1, nullptr); |
821 | do_tcp_connections(tc_2, nullptr); | 832 | do_tcp_connections(logger, tc_2, nullptr); |
822 | 833 | ||
823 | ck_assert_msg(tcp_oobdata_callback_called, "could not recv packet."); | 834 | ck_assert_msg(tcp_oobdata_callback_called, "could not recv packet."); |
824 | 835 | ||
825 | do_TCP_server_delay(tcp_s, mono_time, 50); | 836 | do_TCP_server_delay(tcp_s, mono_time, 50); |
826 | 837 | ||
827 | do_tcp_connections(tc_1, nullptr); | 838 | do_tcp_connections(logger, tc_1, nullptr); |
828 | do_tcp_connections(tc_2, nullptr); | 839 | do_tcp_connections(logger, tc_2, nullptr); |
829 | 840 | ||
830 | ck_assert_msg(tcp_data_callback_called, "could not recv packet."); | 841 | ck_assert_msg(tcp_data_callback_called, "could not recv packet."); |
831 | ck_assert_msg(kill_tcp_connection_to(tc_1, 0) == 0, "could not kill connection to\n"); | 842 | ck_assert_msg(kill_tcp_connection_to(tc_1, 0) == 0, "could not kill connection to\n"); |
@@ -834,6 +845,7 @@ START_TEST(test_tcp_connection2) | |||
834 | kill_tcp_connections(tc_1); | 845 | kill_tcp_connections(tc_1); |
835 | kill_tcp_connections(tc_2); | 846 | kill_tcp_connections(tc_2); |
836 | 847 | ||
848 | logger_kill(logger); | ||
837 | mono_time_free(mono_time); | 849 | mono_time_free(mono_time); |
838 | } | 850 | } |
839 | END_TEST | 851 | END_TEST |
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 20c7ff86..61ba07fa 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c | |||
@@ -390,7 +390,7 @@ static Onions *new_onions(uint16_t port, uint32_t *index) | |||
390 | } | 390 | } |
391 | 391 | ||
392 | TCP_Proxy_Info inf = {{{{0}}}}; | 392 | TCP_Proxy_Info inf = {{{{0}}}}; |
393 | on->onion_c = new_onion_client(on->mono_time, new_net_crypto(on->log, on->mono_time, dht, &inf)); | 393 | on->onion_c = new_onion_client(on->log, on->mono_time, new_net_crypto(on->log, on->mono_time, dht, &inf)); |
394 | 394 | ||
395 | if (!on->onion_c) { | 395 | if (!on->onion_c) { |
396 | kill_onion_announce(on->onion_a); | 396 | kill_onion_announce(on->onion_a); |
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 49ad8013..b54a31cb 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c | |||
@@ -163,7 +163,7 @@ int main(int argc, char *argv[]) | |||
163 | #ifdef TCP_RELAY_ENABLED | 163 | #ifdef TCP_RELAY_ENABLED |
164 | #define NUM_PORTS 3 | 164 | #define NUM_PORTS 3 |
165 | uint16_t ports[NUM_PORTS] = {443, 3389, PORT}; | 165 | uint16_t ports[NUM_PORTS] = {443, 3389, PORT}; |
166 | TCP_Server *tcp_s = new_TCP_server(ipv6enabled, NUM_PORTS, ports, dht_get_self_secret_key(dht), onion); | 166 | TCP_Server *tcp_s = new_TCP_server(logger, ipv6enabled, NUM_PORTS, ports, dht_get_self_secret_key(dht), onion); |
167 | 167 | ||
168 | if (tcp_s == nullptr) { | 168 | if (tcp_s == nullptr) { |
169 | printf("TCP server failed to initialize.\n"); | 169 | printf("TCP server failed to initialize.\n"); |
diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 82043e0d..6ccdea6a 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 | |||
@@ -1 +1 @@ | |||
79c4f7416951d024f95d08e7fc48e127181b7465935cc75b9b3e0ab001bd43b4 /usr/local/bin/tox-bootstrapd | 6f719e76aedd7b386c40ef096412e0336dbc608e69112329932a2c7b60dd8652 /usr/local/bin/tox-bootstrapd | ||
diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 2bef50e9..549d4625 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c | |||
@@ -406,7 +406,8 @@ int main(int argc, char *argv[]) | |||
406 | return 1; | 406 | return 1; |
407 | } | 407 | } |
408 | 408 | ||
409 | tcp_server = new_TCP_server(enable_ipv6, tcp_relay_port_count, tcp_relay_ports, dht_get_self_secret_key(dht), onion); | 409 | tcp_server = new_TCP_server(logger, enable_ipv6, tcp_relay_port_count, tcp_relay_ports, dht_get_self_secret_key(dht), |
410 | onion); | ||
410 | 411 | ||
411 | free(tcp_relay_ports); | 412 | free(tcp_relay_ports); |
412 | 413 | ||
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 556acc27..32c89867 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1977,8 +1977,8 @@ Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsig | |||
1977 | 1977 | ||
1978 | m->onion = new_onion(m->mono_time, m->dht); | 1978 | m->onion = new_onion(m->mono_time, m->dht); |
1979 | m->onion_a = new_onion_announce(m->mono_time, m->dht); | 1979 | m->onion_a = new_onion_announce(m->mono_time, m->dht); |
1980 | m->onion_c = new_onion_client(m->mono_time, m->net_crypto); | 1980 | m->onion_c = new_onion_client(m->log, m->mono_time, m->net_crypto); |
1981 | m->fr_c = new_friend_connections(m->mono_time, m->onion_c, options->local_discovery_enabled); | 1981 | m->fr_c = new_friend_connections(m->log, m->mono_time, m->onion_c, options->local_discovery_enabled); |
1982 | 1982 | ||
1983 | if (!(m->onion && m->onion_a && m->onion_c && m->fr_c)) { | 1983 | if (!(m->onion && m->onion_a && m->onion_c && m->fr_c)) { |
1984 | kill_friend_connections(m->fr_c); | 1984 | kill_friend_connections(m->fr_c); |
@@ -1995,8 +1995,8 @@ Messenger *new_messenger(Mono_Time *mono_time, Messenger_Options *options, unsig | |||
1995 | } | 1995 | } |
1996 | 1996 | ||
1997 | if (options->tcp_server_port) { | 1997 | if (options->tcp_server_port) { |
1998 | m->tcp_server = new_TCP_server(options->ipv6enabled, 1, &options->tcp_server_port, dht_get_self_secret_key(m->dht), | 1998 | m->tcp_server = new_TCP_server(m->log, options->ipv6enabled, 1, &options->tcp_server_port, |
1999 | m->onion); | 1999 | dht_get_self_secret_key(m->dht), m->onion); |
2000 | 2000 | ||
2001 | if (m->tcp_server == nullptr) { | 2001 | if (m->tcp_server == nullptr) { |
2002 | kill_friend_connections(m->fr_c); | 2002 | kill_friend_connections(m->fr_c); |
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index 408ec489..1405d9b2 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c | |||
@@ -151,12 +151,12 @@ static int proxy_http_generate_connection_request(TCP_Client_Connection *tcp_con | |||
151 | * return 0 if no data received. | 151 | * return 0 if no data received. |
152 | * return -1 on failure (connection refused). | 152 | * return -1 on failure (connection refused). |
153 | */ | 153 | */ |
154 | static int proxy_http_read_connection_response(TCP_Client_Connection *tcp_conn) | 154 | static int proxy_http_read_connection_response(const Logger *logger, TCP_Client_Connection *tcp_conn) |
155 | { | 155 | { |
156 | char success[] = "200"; | 156 | char success[] = "200"; |
157 | uint8_t data[16]; // draining works the best if the length is a power of 2 | 157 | uint8_t data[16]; // draining works the best if the length is a power of 2 |
158 | 158 | ||
159 | int ret = read_TCP_packet(tcp_conn->sock, data, sizeof(data) - 1); | 159 | int ret = read_TCP_packet(logger, tcp_conn->sock, data, sizeof(data) - 1); |
160 | 160 | ||
161 | if (ret == -1) { | 161 | if (ret == -1) { |
162 | return 0; | 162 | return 0; |
@@ -170,7 +170,7 @@ static int proxy_http_read_connection_response(TCP_Client_Connection *tcp_conn) | |||
170 | 170 | ||
171 | if (data_left) { | 171 | if (data_left) { |
172 | VLA(uint8_t, temp_data, data_left); | 172 | VLA(uint8_t, temp_data, data_left); |
173 | read_TCP_packet(tcp_conn->sock, temp_data, data_left); | 173 | read_TCP_packet(logger, tcp_conn->sock, temp_data, data_left); |
174 | } | 174 | } |
175 | 175 | ||
176 | return 1; | 176 | return 1; |
@@ -193,10 +193,10 @@ static void proxy_socks5_generate_handshake(TCP_Client_Connection *tcp_conn) | |||
193 | * return 0 if no data received. | 193 | * return 0 if no data received. |
194 | * return -1 on failure (connection refused). | 194 | * return -1 on failure (connection refused). |
195 | */ | 195 | */ |
196 | static int socks5_read_handshake_response(TCP_Client_Connection *tcp_conn) | 196 | static int socks5_read_handshake_response(const Logger *logger, TCP_Client_Connection *tcp_conn) |
197 | { | 197 | { |
198 | uint8_t data[2]; | 198 | uint8_t data[2]; |
199 | int ret = read_TCP_packet(tcp_conn->sock, data, sizeof(data)); | 199 | int ret = read_TCP_packet(logger, tcp_conn->sock, data, sizeof(data)); |
200 | 200 | ||
201 | if (ret == -1) { | 201 | if (ret == -1) { |
202 | return 0; | 202 | return 0; |
@@ -239,11 +239,11 @@ static void proxy_socks5_generate_connection_request(TCP_Client_Connection *tcp_ | |||
239 | * return 0 if no data received. | 239 | * return 0 if no data received. |
240 | * return -1 on failure (connection refused). | 240 | * return -1 on failure (connection refused). |
241 | */ | 241 | */ |
242 | static int proxy_socks5_read_connection_response(TCP_Client_Connection *tcp_conn) | 242 | static int proxy_socks5_read_connection_response(const Logger *logger, TCP_Client_Connection *tcp_conn) |
243 | { | 243 | { |
244 | if (net_family_is_ipv4(tcp_conn->ip_port.ip.family)) { | 244 | if (net_family_is_ipv4(tcp_conn->ip_port.ip.family)) { |
245 | uint8_t data[4 + sizeof(IP4) + sizeof(uint16_t)]; | 245 | uint8_t data[4 + sizeof(IP4) + sizeof(uint16_t)]; |
246 | int ret = read_TCP_packet(tcp_conn->sock, data, sizeof(data)); | 246 | int ret = read_TCP_packet(logger, tcp_conn->sock, data, sizeof(data)); |
247 | 247 | ||
248 | if (ret == -1) { | 248 | if (ret == -1) { |
249 | return 0; | 249 | return 0; |
@@ -254,7 +254,7 @@ static int proxy_socks5_read_connection_response(TCP_Client_Connection *tcp_conn | |||
254 | } | 254 | } |
255 | } else { | 255 | } else { |
256 | uint8_t data[4 + sizeof(IP6) + sizeof(uint16_t)]; | 256 | uint8_t data[4 + sizeof(IP6) + sizeof(uint16_t)]; |
257 | int ret = read_TCP_packet(tcp_conn->sock, data, sizeof(data)); | 257 | int ret = read_TCP_packet(logger, tcp_conn->sock, data, sizeof(data)); |
258 | 258 | ||
259 | if (ret == -1) { | 259 | if (ret == -1) { |
260 | return 0; | 260 | return 0; |
@@ -900,10 +900,10 @@ static int handle_TCP_client_packet(TCP_Client_Connection *conn, const uint8_t * | |||
900 | return 0; | 900 | return 0; |
901 | } | 901 | } |
902 | 902 | ||
903 | static bool tcp_process_packet(TCP_Client_Connection *conn, void *userdata) | 903 | static bool tcp_process_packet(const Logger *logger, TCP_Client_Connection *conn, void *userdata) |
904 | { | 904 | { |
905 | uint8_t packet[MAX_PACKET_SIZE]; | 905 | uint8_t packet[MAX_PACKET_SIZE]; |
906 | const int len = read_packet_TCP_secure_connection(conn->sock, &conn->next_packet_length, conn->shared_key, | 906 | const int len = read_packet_TCP_secure_connection(logger, conn->sock, &conn->next_packet_length, conn->shared_key, |
907 | conn->recv_nonce, packet, sizeof(packet)); | 907 | conn->recv_nonce, packet, sizeof(packet)); |
908 | 908 | ||
909 | if (len == 0) { | 909 | if (len == 0) { |
@@ -923,7 +923,8 @@ static bool tcp_process_packet(TCP_Client_Connection *conn, void *userdata) | |||
923 | return true; | 923 | return true; |
924 | } | 924 | } |
925 | 925 | ||
926 | static int do_confirmed_TCP(TCP_Client_Connection *conn, const Mono_Time *mono_time, void *userdata) | 926 | static int do_confirmed_TCP(const Logger *logger, TCP_Client_Connection *conn, const Mono_Time *mono_time, |
927 | void *userdata) | ||
927 | { | 928 | { |
928 | client_send_pending_data(conn); | 929 | client_send_pending_data(conn); |
929 | tcp_send_ping_response(conn); | 930 | tcp_send_ping_response(conn); |
@@ -947,7 +948,7 @@ static int do_confirmed_TCP(TCP_Client_Connection *conn, const Mono_Time *mono_t | |||
947 | return 0; | 948 | return 0; |
948 | } | 949 | } |
949 | 950 | ||
950 | while (tcp_process_packet(conn, userdata)) { | 951 | while (tcp_process_packet(logger, conn, userdata)) { |
951 | // Keep reading until error or out of data. | 952 | // Keep reading until error or out of data. |
952 | continue; | 953 | continue; |
953 | } | 954 | } |
@@ -957,7 +958,8 @@ static int do_confirmed_TCP(TCP_Client_Connection *conn, const Mono_Time *mono_t | |||
957 | 958 | ||
958 | /* Run the TCP connection | 959 | /* Run the TCP connection |
959 | */ | 960 | */ |
960 | void do_TCP_connection(Mono_Time *mono_time, TCP_Client_Connection *tcp_connection, void *userdata) | 961 | void do_TCP_connection(const Logger *logger, Mono_Time *mono_time, TCP_Client_Connection *tcp_connection, |
962 | void *userdata) | ||
961 | { | 963 | { |
962 | if (tcp_connection->status == TCP_CLIENT_DISCONNECTED) { | 964 | if (tcp_connection->status == TCP_CLIENT_DISCONNECTED) { |
963 | return; | 965 | return; |
@@ -965,7 +967,7 @@ void do_TCP_connection(Mono_Time *mono_time, TCP_Client_Connection *tcp_connecti | |||
965 | 967 | ||
966 | if (tcp_connection->status == TCP_CLIENT_PROXY_HTTP_CONNECTING) { | 968 | if (tcp_connection->status == TCP_CLIENT_PROXY_HTTP_CONNECTING) { |
967 | if (client_send_pending_data(tcp_connection) == 0) { | 969 | if (client_send_pending_data(tcp_connection) == 0) { |
968 | int ret = proxy_http_read_connection_response(tcp_connection); | 970 | int ret = proxy_http_read_connection_response(logger, tcp_connection); |
969 | 971 | ||
970 | if (ret == -1) { | 972 | if (ret == -1) { |
971 | tcp_connection->kill_at = 0; | 973 | tcp_connection->kill_at = 0; |
@@ -981,7 +983,7 @@ void do_TCP_connection(Mono_Time *mono_time, TCP_Client_Connection *tcp_connecti | |||
981 | 983 | ||
982 | if (tcp_connection->status == TCP_CLIENT_PROXY_SOCKS5_CONNECTING) { | 984 | if (tcp_connection->status == TCP_CLIENT_PROXY_SOCKS5_CONNECTING) { |
983 | if (client_send_pending_data(tcp_connection) == 0) { | 985 | if (client_send_pending_data(tcp_connection) == 0) { |
984 | int ret = socks5_read_handshake_response(tcp_connection); | 986 | int ret = socks5_read_handshake_response(logger, tcp_connection); |
985 | 987 | ||
986 | if (ret == -1) { | 988 | if (ret == -1) { |
987 | tcp_connection->kill_at = 0; | 989 | tcp_connection->kill_at = 0; |
@@ -997,7 +999,7 @@ void do_TCP_connection(Mono_Time *mono_time, TCP_Client_Connection *tcp_connecti | |||
997 | 999 | ||
998 | if (tcp_connection->status == TCP_CLIENT_PROXY_SOCKS5_UNCONFIRMED) { | 1000 | if (tcp_connection->status == TCP_CLIENT_PROXY_SOCKS5_UNCONFIRMED) { |
999 | if (client_send_pending_data(tcp_connection) == 0) { | 1001 | if (client_send_pending_data(tcp_connection) == 0) { |
1000 | int ret = proxy_socks5_read_connection_response(tcp_connection); | 1002 | int ret = proxy_socks5_read_connection_response(logger, tcp_connection); |
1001 | 1003 | ||
1002 | if (ret == -1) { | 1004 | if (ret == -1) { |
1003 | tcp_connection->kill_at = 0; | 1005 | tcp_connection->kill_at = 0; |
@@ -1019,7 +1021,7 @@ void do_TCP_connection(Mono_Time *mono_time, TCP_Client_Connection *tcp_connecti | |||
1019 | 1021 | ||
1020 | if (tcp_connection->status == TCP_CLIENT_UNCONFIRMED) { | 1022 | if (tcp_connection->status == TCP_CLIENT_UNCONFIRMED) { |
1021 | uint8_t data[TCP_SERVER_HANDSHAKE_SIZE]; | 1023 | uint8_t data[TCP_SERVER_HANDSHAKE_SIZE]; |
1022 | int len = read_TCP_packet(tcp_connection->sock, data, sizeof(data)); | 1024 | int len = read_TCP_packet(logger, tcp_connection->sock, data, sizeof(data)); |
1023 | 1025 | ||
1024 | if (sizeof(data) == len) { | 1026 | if (sizeof(data) == len) { |
1025 | if (handle_handshake(tcp_connection, data) == 0) { | 1027 | if (handle_handshake(tcp_connection, data) == 0) { |
@@ -1033,7 +1035,7 @@ void do_TCP_connection(Mono_Time *mono_time, TCP_Client_Connection *tcp_connecti | |||
1033 | } | 1035 | } |
1034 | 1036 | ||
1035 | if (tcp_connection->status == TCP_CLIENT_CONFIRMED) { | 1037 | if (tcp_connection->status == TCP_CLIENT_CONFIRMED) { |
1036 | do_confirmed_TCP(tcp_connection, mono_time, userdata); | 1038 | do_confirmed_TCP(logger, tcp_connection, mono_time, userdata); |
1037 | } | 1039 | } |
1038 | 1040 | ||
1039 | if (tcp_connection->kill_at <= mono_time_get(mono_time)) { | 1041 | if (tcp_connection->kill_at <= mono_time_get(mono_time)) { |
diff --git a/toxcore/TCP_client.h b/toxcore/TCP_client.h index cecf5a6d..ed4304cb 100644 --- a/toxcore/TCP_client.h +++ b/toxcore/TCP_client.h | |||
@@ -54,7 +54,8 @@ TCP_Client_Connection *new_TCP_connection(const Mono_Time *mono_time, IP_Port ip | |||
54 | 54 | ||
55 | /* Run the TCP connection | 55 | /* Run the TCP connection |
56 | */ | 56 | */ |
57 | void do_TCP_connection(Mono_Time *mono_time, TCP_Client_Connection *tcp_connection, void *userdata); | 57 | void do_TCP_connection(const Logger *logger, Mono_Time *mono_time, TCP_Client_Connection *tcp_connection, |
58 | void *userdata); | ||
58 | 59 | ||
59 | /* Kill the TCP connection | 60 | /* Kill the TCP connection |
60 | */ | 61 | */ |
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index adef3175..411589bf 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c | |||
@@ -1398,7 +1398,7 @@ TCP_Connections *new_tcp_connections(Mono_Time *mono_time, const uint8_t *secret | |||
1398 | return temp; | 1398 | return temp; |
1399 | } | 1399 | } |
1400 | 1400 | ||
1401 | static void do_tcp_conns(TCP_Connections *tcp_c, void *userdata) | 1401 | static void do_tcp_conns(const Logger *logger, TCP_Connections *tcp_c, void *userdata) |
1402 | { | 1402 | { |
1403 | unsigned int i; | 1403 | unsigned int i; |
1404 | 1404 | ||
@@ -1407,7 +1407,7 @@ static void do_tcp_conns(TCP_Connections *tcp_c, void *userdata) | |||
1407 | 1407 | ||
1408 | if (tcp_con) { | 1408 | if (tcp_con) { |
1409 | if (tcp_con->status != TCP_CONN_SLEEPING) { | 1409 | if (tcp_con->status != TCP_CONN_SLEEPING) { |
1410 | do_TCP_connection(tcp_c->mono_time, tcp_con->connection, userdata); | 1410 | do_TCP_connection(logger, tcp_c->mono_time, tcp_con->connection, userdata); |
1411 | 1411 | ||
1412 | /* callbacks can change TCP connection address. */ | 1412 | /* callbacks can change TCP connection address. */ |
1413 | tcp_con = get_tcp_connection(tcp_c, i); | 1413 | tcp_con = get_tcp_connection(tcp_c, i); |
@@ -1485,9 +1485,9 @@ static void kill_nonused_tcp(TCP_Connections *tcp_c) | |||
1485 | } | 1485 | } |
1486 | } | 1486 | } |
1487 | 1487 | ||
1488 | void do_tcp_connections(TCP_Connections *tcp_c, void *userdata) | 1488 | void do_tcp_connections(const Logger *logger, TCP_Connections *tcp_c, void *userdata) |
1489 | { | 1489 | { |
1490 | do_tcp_conns(tcp_c, userdata); | 1490 | do_tcp_conns(logger, tcp_c, userdata); |
1491 | kill_nonused_tcp(tcp_c); | 1491 | kill_nonused_tcp(tcp_c); |
1492 | } | 1492 | } |
1493 | 1493 | ||
diff --git a/toxcore/TCP_connection.h b/toxcore/TCP_connection.h index a8e522d3..1bd5b85a 100644 --- a/toxcore/TCP_connection.h +++ b/toxcore/TCP_connection.h | |||
@@ -206,7 +206,8 @@ uint32_t tcp_copy_connected_relays(TCP_Connections *tcp_c, Node_format *tcp_rela | |||
206 | */ | 206 | */ |
207 | TCP_Connections *new_tcp_connections(Mono_Time *mono_time, const uint8_t *secret_key, TCP_Proxy_Info *proxy_info); | 207 | TCP_Connections *new_tcp_connections(Mono_Time *mono_time, const uint8_t *secret_key, TCP_Proxy_Info *proxy_info); |
208 | 208 | ||
209 | void do_tcp_connections(TCP_Connections *tcp_c, void *userdata); | 209 | void do_tcp_connections(const Logger *logger, TCP_Connections *tcp_c, void *userdata); |
210 | |||
210 | void kill_tcp_connections(TCP_Connections *tcp_c); | 211 | void kill_tcp_connections(TCP_Connections *tcp_c); |
211 | 212 | ||
212 | #endif | 213 | #endif |
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index b22bdb80..79a9e560 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c | |||
@@ -12,7 +12,6 @@ | |||
12 | 12 | ||
13 | #include "TCP_server.h" | 13 | #include "TCP_server.h" |
14 | 14 | ||
15 | #include <stdio.h> | ||
16 | #include <stdlib.h> | 15 | #include <stdlib.h> |
17 | #include <string.h> | 16 | #include <string.h> |
18 | #if !defined(_WIN32) && !defined(__WIN32__) && !defined (WIN32) | 17 | #if !defined(_WIN32) && !defined(__WIN32__) && !defined (WIN32) |
@@ -66,6 +65,7 @@ typedef struct TCP_Secure_Connection { | |||
66 | 65 | ||
67 | 66 | ||
68 | struct TCP_Server { | 67 | struct TCP_Server { |
68 | const Logger *logger; | ||
69 | Onion *onion; | 69 | Onion *onion; |
70 | 70 | ||
71 | #ifdef TCP_SERVER_USE_EPOLL | 71 | #ifdef TCP_SERVER_USE_EPOLL |
@@ -220,7 +220,7 @@ static int add_accepted(TCP_Server *tcp_server, const Mono_Time *mono_time, TCP_ | |||
220 | } | 220 | } |
221 | 221 | ||
222 | if (index == -1) { | 222 | if (index == -1) { |
223 | fprintf(stderr, "FAIL index is -1\n"); | 223 | LOGGER_ERROR(tcp_server->logger, "FAIL index is -1"); |
224 | return -1; | 224 | return -1; |
225 | } | 225 | } |
226 | 226 | ||
@@ -275,7 +275,7 @@ static int del_accepted(TCP_Server *tcp_server, int index) | |||
275 | * return 0 if nothing has been read from socket. | 275 | * return 0 if nothing has been read from socket. |
276 | * return -1 on failure. | 276 | * return -1 on failure. |
277 | */ | 277 | */ |
278 | uint16_t read_TCP_length(Socket sock) | 278 | uint16_t read_TCP_length(const Logger *logger, Socket sock) |
279 | { | 279 | { |
280 | const unsigned int count = net_socket_data_recv_buffer(sock); | 280 | const unsigned int count = net_socket_data_recv_buffer(sock); |
281 | 281 | ||
@@ -284,7 +284,7 @@ uint16_t read_TCP_length(Socket sock) | |||
284 | const int len = net_recv(sock, &length, sizeof(uint16_t)); | 284 | const int len = net_recv(sock, &length, sizeof(uint16_t)); |
285 | 285 | ||
286 | if (len != sizeof(uint16_t)) { | 286 | if (len != sizeof(uint16_t)) { |
287 | fprintf(stderr, "FAIL recv packet\n"); | 287 | LOGGER_ERROR(logger, "FAIL recv packet"); |
288 | return 0; | 288 | return 0; |
289 | } | 289 | } |
290 | 290 | ||
@@ -305,7 +305,7 @@ uint16_t read_TCP_length(Socket sock) | |||
305 | * return length on success | 305 | * return length on success |
306 | * return -1 on failure/no data in buffer. | 306 | * return -1 on failure/no data in buffer. |
307 | */ | 307 | */ |
308 | int read_TCP_packet(Socket sock, uint8_t *data, uint16_t length) | 308 | int read_TCP_packet(const Logger *logger, Socket sock, uint8_t *data, uint16_t length) |
309 | { | 309 | { |
310 | unsigned int count = net_socket_data_recv_buffer(sock); | 310 | unsigned int count = net_socket_data_recv_buffer(sock); |
311 | 311 | ||
@@ -313,7 +313,7 @@ int read_TCP_packet(Socket sock, uint8_t *data, uint16_t length) | |||
313 | const int len = net_recv(sock, data, length); | 313 | const int len = net_recv(sock, data, length); |
314 | 314 | ||
315 | if (len != length) { | 315 | if (len != length) { |
316 | fprintf(stderr, "FAIL recv packet\n"); | 316 | LOGGER_ERROR(logger, "FAIL recv packet"); |
317 | return -1; | 317 | return -1; |
318 | } | 318 | } |
319 | 319 | ||
@@ -327,11 +327,11 @@ int read_TCP_packet(Socket sock, uint8_t *data, uint16_t length) | |||
327 | * return 0 if could not read any packet. | 327 | * return 0 if could not read any packet. |
328 | * return -1 on failure (connection must be killed). | 328 | * return -1 on failure (connection must be killed). |
329 | */ | 329 | */ |
330 | int read_packet_TCP_secure_connection(Socket sock, uint16_t *next_packet_length, const uint8_t *shared_key, | 330 | int read_packet_TCP_secure_connection(const Logger *logger, Socket sock, uint16_t *next_packet_length, |
331 | uint8_t *recv_nonce, uint8_t *data, uint16_t max_len) | 331 | const uint8_t *shared_key, uint8_t *recv_nonce, uint8_t *data, uint16_t max_len) |
332 | { | 332 | { |
333 | if (*next_packet_length == 0) { | 333 | if (*next_packet_length == 0) { |
334 | uint16_t len = read_TCP_length(sock); | 334 | uint16_t len = read_TCP_length(logger, sock); |
335 | 335 | ||
336 | if (len == (uint16_t) -1) { | 336 | if (len == (uint16_t) -1) { |
337 | return -1; | 337 | return -1; |
@@ -349,7 +349,7 @@ int read_packet_TCP_secure_connection(Socket sock, uint16_t *next_packet_length, | |||
349 | } | 349 | } |
350 | 350 | ||
351 | VLA(uint8_t, data_encrypted, *next_packet_length); | 351 | VLA(uint8_t, data_encrypted, *next_packet_length); |
352 | int len_packet = read_TCP_packet(sock, data_encrypted, *next_packet_length); | 352 | int len_packet = read_TCP_packet(logger, sock, data_encrypted, *next_packet_length); |
353 | 353 | ||
354 | if (len_packet != *next_packet_length) { | 354 | if (len_packet != *next_packet_length) { |
355 | return 0; | 355 | return 0; |
@@ -617,10 +617,10 @@ static int handle_TCP_handshake(TCP_Secure_Connection *con, const uint8_t *data, | |||
617 | * return 0 if we didn't get it yet. | 617 | * return 0 if we didn't get it yet. |
618 | * return -1 if the connection must be killed. | 618 | * return -1 if the connection must be killed. |
619 | */ | 619 | */ |
620 | static int read_connection_handshake(TCP_Secure_Connection *con, const uint8_t *self_secret_key) | 620 | static int read_connection_handshake(const Logger *logger, TCP_Secure_Connection *con, const uint8_t *self_secret_key) |
621 | { | 621 | { |
622 | uint8_t data[TCP_CLIENT_HANDSHAKE_SIZE]; | 622 | uint8_t data[TCP_CLIENT_HANDSHAKE_SIZE]; |
623 | const int len = read_TCP_packet(con->sock, data, TCP_CLIENT_HANDSHAKE_SIZE); | 623 | const int len = read_TCP_packet(logger, con->sock, data, TCP_CLIENT_HANDSHAKE_SIZE); |
624 | 624 | ||
625 | if (len != -1) { | 625 | if (len != -1) { |
626 | return handle_TCP_handshake(con, data, len, self_secret_key); | 626 | return handle_TCP_handshake(con, data, len, self_secret_key); |
@@ -1055,8 +1055,8 @@ static Socket new_listening_TCP_socket(Family family, uint16_t port) | |||
1055 | return sock; | 1055 | return sock; |
1056 | } | 1056 | } |
1057 | 1057 | ||
1058 | TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uint16_t *ports, const uint8_t *secret_key, | 1058 | TCP_Server *new_TCP_server(const Logger *logger, uint8_t ipv6_enabled, uint16_t num_sockets, const uint16_t *ports, |
1059 | Onion *onion) | 1059 | const uint8_t *secret_key, Onion *onion) |
1060 | { | 1060 | { |
1061 | if (num_sockets == 0 || ports == nullptr) { | 1061 | if (num_sockets == 0 || ports == nullptr) { |
1062 | return nullptr; | 1062 | return nullptr; |
@@ -1072,6 +1072,8 @@ TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uin | |||
1072 | return nullptr; | 1072 | return nullptr; |
1073 | } | 1073 | } |
1074 | 1074 | ||
1075 | temp->logger = logger; | ||
1076 | |||
1075 | temp->socks_listening = (Socket *)calloc(num_sockets, sizeof(Socket)); | 1077 | temp->socks_listening = (Socket *)calloc(num_sockets, sizeof(Socket)); |
1076 | 1078 | ||
1077 | if (temp->socks_listening == nullptr) { | 1079 | if (temp->socks_listening == nullptr) { |
@@ -1156,7 +1158,8 @@ static int do_incoming(TCP_Server *tcp_server, uint32_t i) | |||
1156 | return -1; | 1158 | return -1; |
1157 | } | 1159 | } |
1158 | 1160 | ||
1159 | int ret = read_connection_handshake(&tcp_server->incoming_connection_queue[i], tcp_server->secret_key); | 1161 | int ret = read_connection_handshake(tcp_server->logger, &tcp_server->incoming_connection_queue[i], |
1162 | tcp_server->secret_key); | ||
1160 | 1163 | ||
1161 | if (ret == -1) { | 1164 | if (ret == -1) { |
1162 | kill_TCP_secure_connection(&tcp_server->incoming_connection_queue[i]); | 1165 | kill_TCP_secure_connection(&tcp_server->incoming_connection_queue[i]); |
@@ -1187,8 +1190,8 @@ static int do_unconfirmed(TCP_Server *tcp_server, const Mono_Time *mono_time, ui | |||
1187 | } | 1190 | } |
1188 | 1191 | ||
1189 | uint8_t packet[MAX_PACKET_SIZE]; | 1192 | uint8_t packet[MAX_PACKET_SIZE]; |
1190 | int len = read_packet_TCP_secure_connection(conn->sock, &conn->next_packet_length, conn->shared_key, conn->recv_nonce, | 1193 | int len = read_packet_TCP_secure_connection(tcp_server->logger, conn->sock, &conn->next_packet_length, conn->shared_key, |
1191 | packet, sizeof(packet)); | 1194 | conn->recv_nonce, packet, sizeof(packet)); |
1192 | 1195 | ||
1193 | if (len == 0) { | 1196 | if (len == 0) { |
1194 | return -1; | 1197 | return -1; |
@@ -1207,7 +1210,7 @@ static bool tcp_process_secure_packet(TCP_Server *tcp_server, uint32_t i) | |||
1207 | TCP_Secure_Connection *const conn = &tcp_server->accepted_connection_array[i]; | 1210 | TCP_Secure_Connection *const conn = &tcp_server->accepted_connection_array[i]; |
1208 | 1211 | ||
1209 | uint8_t packet[MAX_PACKET_SIZE]; | 1212 | uint8_t packet[MAX_PACKET_SIZE]; |
1210 | int len = read_packet_TCP_secure_connection(conn->sock, &conn->next_packet_length, conn->shared_key, | 1213 | int len = read_packet_TCP_secure_connection(tcp_server->logger, conn->sock, &conn->next_packet_length, conn->shared_key, |
1211 | conn->recv_nonce, packet, sizeof(packet)); | 1214 | conn->recv_nonce, packet, sizeof(packet)); |
1212 | 1215 | ||
1213 | if (len == 0) { | 1216 | if (len == 0) { |
diff --git a/toxcore/TCP_server.h b/toxcore/TCP_server.h index 5862a473..46dd0330 100644 --- a/toxcore/TCP_server.h +++ b/toxcore/TCP_server.h | |||
@@ -69,8 +69,8 @@ size_t tcp_server_listen_count(const TCP_Server *tcp_server); | |||
69 | 69 | ||
70 | /* Create new TCP server instance. | 70 | /* Create new TCP server instance. |
71 | */ | 71 | */ |
72 | TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uint16_t *ports, const uint8_t *secret_key, | 72 | TCP_Server *new_TCP_server(const Logger *logger, uint8_t ipv6_enabled, uint16_t num_sockets, const uint16_t *ports, |
73 | Onion *onion); | 73 | const uint8_t *secret_key, Onion *onion); |
74 | 74 | ||
75 | /* Run the TCP_server | 75 | /* Run the TCP_server |
76 | */ | 76 | */ |
@@ -87,21 +87,21 @@ void kill_TCP_server(TCP_Server *tcp_server); | |||
87 | * return 0 if nothing has been read from socket. | 87 | * return 0 if nothing has been read from socket. |
88 | * return -1 on failure. | 88 | * return -1 on failure. |
89 | */ | 89 | */ |
90 | uint16_t read_TCP_length(Socket sock); | 90 | uint16_t read_TCP_length(const Logger *logger, Socket sock); |
91 | 91 | ||
92 | /* Read length bytes from socket. | 92 | /* Read length bytes from socket. |
93 | * | 93 | * |
94 | * return length on success | 94 | * return length on success |
95 | * return -1 on failure/no data in buffer. | 95 | * return -1 on failure/no data in buffer. |
96 | */ | 96 | */ |
97 | int read_TCP_packet(Socket sock, uint8_t *data, uint16_t length); | 97 | int read_TCP_packet(const Logger *logger, Socket sock, uint8_t *data, uint16_t length); |
98 | 98 | ||
99 | /* return length of received packet on success. | 99 | /* return length of received packet on success. |
100 | * return 0 if could not read any packet. | 100 | * return 0 if could not read any packet. |
101 | * return -1 on failure (connection must be killed). | 101 | * return -1 on failure (connection must be killed). |
102 | */ | 102 | */ |
103 | int read_packet_TCP_secure_connection(Socket sock, uint16_t *next_packet_length, const uint8_t *shared_key, | 103 | int read_packet_TCP_secure_connection(const Logger *logger, Socket sock, uint16_t *next_packet_length, |
104 | uint8_t *recv_nonce, uint8_t *data, uint16_t max_len); | 104 | const uint8_t *shared_key, uint8_t *recv_nonce, uint8_t *data, uint16_t max_len); |
105 | 105 | ||
106 | 106 | ||
107 | #endif | 107 | #endif |
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index af5d09e3..fd1fa71c 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c | |||
@@ -12,7 +12,6 @@ | |||
12 | 12 | ||
13 | #include "friend_connection.h" | 13 | #include "friend_connection.h" |
14 | 14 | ||
15 | #include <stdio.h> | ||
16 | #include <stdlib.h> | 15 | #include <stdlib.h> |
17 | #include <string.h> | 16 | #include <string.h> |
18 | 17 | ||
@@ -60,6 +59,7 @@ typedef struct Friend_Conn { | |||
60 | 59 | ||
61 | struct Friend_Connections { | 60 | struct Friend_Connections { |
62 | const Mono_Time *mono_time; | 61 | const Mono_Time *mono_time; |
62 | const Logger *logger; | ||
63 | Net_Crypto *net_crypto; | 63 | Net_Crypto *net_crypto; |
64 | DHT *dht; | 64 | DHT *dht; |
65 | Onion_Client *onion_c; | 65 | Onion_Client *onion_c; |
@@ -348,7 +348,7 @@ static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint | |||
348 | 348 | ||
349 | if (friend_con->dht_lock) { | 349 | if (friend_con->dht_lock) { |
350 | if (dht_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock) != 0) { | 350 | if (dht_delfriend(fr_c->dht, friend_con->dht_temp_pk, friend_con->dht_lock) != 0) { |
351 | printf("a. Could not delete dht peer. Please report this.\n"); | 351 | LOGGER_ERROR(fr_c->logger, "a. Could not delete dht peer. Please report this."); |
352 | return; | 352 | return; |
353 | } | 353 | } |
354 | 354 | ||
@@ -848,7 +848,7 @@ int send_friend_request_packet(Friend_Connections *fr_c, int friendcon_id, uint3 | |||
848 | } | 848 | } |
849 | 849 | ||
850 | /* Create new friend_connections instance. */ | 850 | /* Create new friend_connections instance. */ |
851 | Friend_Connections *new_friend_connections(const Mono_Time *mono_time, Onion_Client *onion_c, | 851 | Friend_Connections *new_friend_connections(const Logger *logger, const Mono_Time *mono_time, Onion_Client *onion_c, |
852 | bool local_discovery_enabled) | 852 | bool local_discovery_enabled) |
853 | { | 853 | { |
854 | if (onion_c == nullptr) { | 854 | if (onion_c == nullptr) { |
@@ -862,6 +862,7 @@ Friend_Connections *new_friend_connections(const Mono_Time *mono_time, Onion_Cli | |||
862 | } | 862 | } |
863 | 863 | ||
864 | temp->mono_time = mono_time; | 864 | temp->mono_time = mono_time; |
865 | temp->logger = logger; | ||
865 | temp->dht = onion_get_dht(onion_c); | 866 | temp->dht = onion_get_dht(onion_c); |
866 | temp->net_crypto = onion_get_net_crypto(onion_c); | 867 | temp->net_crypto = onion_get_net_crypto(onion_c); |
867 | temp->onion_c = onion_c; | 868 | temp->onion_c = onion_c; |
diff --git a/toxcore/friend_connection.h b/toxcore/friend_connection.h index 92e38703..2263c8c3 100644 --- a/toxcore/friend_connection.h +++ b/toxcore/friend_connection.h | |||
@@ -148,7 +148,7 @@ typedef int fr_request_cb(void *object, const uint8_t *source_pubkey, const uint | |||
148 | void set_friend_request_callback(Friend_Connections *fr_c, fr_request_cb *fr_request_callback, void *object); | 148 | void set_friend_request_callback(Friend_Connections *fr_c, fr_request_cb *fr_request_callback, void *object); |
149 | 149 | ||
150 | /* Create new friend_connections instance. */ | 150 | /* Create new friend_connections instance. */ |
151 | Friend_Connections *new_friend_connections(const Mono_Time *mono_time, Onion_Client *onion_c, | 151 | Friend_Connections *new_friend_connections(const Logger *logger, const Mono_Time *mono_time, Onion_Client *onion_c, |
152 | bool local_discovery_enabled); | 152 | bool local_discovery_enabled); |
153 | 153 | ||
154 | /* main friend_connections loop. */ | 154 | /* main friend_connections loop. */ |
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 2851053b..f57886a8 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c | |||
@@ -2281,7 +2281,7 @@ unsigned int copy_connected_tcp_relays(Net_Crypto *c, Node_format *tcp_relays, u | |||
2281 | static void do_tcp(Net_Crypto *c, void *userdata) | 2281 | static void do_tcp(Net_Crypto *c, void *userdata) |
2282 | { | 2282 | { |
2283 | pthread_mutex_lock(&c->tcp_mutex); | 2283 | pthread_mutex_lock(&c->tcp_mutex); |
2284 | do_tcp_connections(c->tcp_c, userdata); | 2284 | do_tcp_connections(c->log, c->tcp_c, userdata); |
2285 | pthread_mutex_unlock(&c->tcp_mutex); | 2285 | pthread_mutex_unlock(&c->tcp_mutex); |
2286 | 2286 | ||
2287 | uint32_t i; | 2287 | uint32_t i; |
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index e161928b..60a80bc6 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c | |||
@@ -97,6 +97,7 @@ typedef struct Onion_Data_Handler { | |||
97 | 97 | ||
98 | struct Onion_Client { | 98 | struct Onion_Client { |
99 | Mono_Time *mono_time; | 99 | Mono_Time *mono_time; |
100 | const Logger *logger; | ||
100 | 101 | ||
101 | DHT *dht; | 102 | DHT *dht; |
102 | Net_Crypto *c; | 103 | Net_Crypto *c; |
@@ -1849,7 +1850,7 @@ void do_onion_client(Onion_Client *onion_c) | |||
1849 | onion_c->last_run = mono_time_get(onion_c->mono_time); | 1850 | onion_c->last_run = mono_time_get(onion_c->mono_time); |
1850 | } | 1851 | } |
1851 | 1852 | ||
1852 | Onion_Client *new_onion_client(Mono_Time *mono_time, Net_Crypto *c) | 1853 | Onion_Client *new_onion_client(const Logger *logger, Mono_Time *mono_time, Net_Crypto *c) |
1853 | { | 1854 | { |
1854 | if (c == nullptr) { | 1855 | if (c == nullptr) { |
1855 | return nullptr; | 1856 | return nullptr; |
@@ -1869,6 +1870,7 @@ Onion_Client *new_onion_client(Mono_Time *mono_time, Net_Crypto *c) | |||
1869 | } | 1870 | } |
1870 | 1871 | ||
1871 | onion_c->mono_time = mono_time; | 1872 | onion_c->mono_time = mono_time; |
1873 | onion_c->logger = logger; | ||
1872 | onion_c->dht = nc_get_dht(c); | 1874 | onion_c->dht = nc_get_dht(c); |
1873 | onion_c->net = dht_get_net(onion_c->dht); | 1875 | onion_c->net = dht_get_net(onion_c->dht); |
1874 | onion_c->c = c; | 1876 | onion_c->c = c; |
diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index 5b6bea65..88e97dd6 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h | |||
@@ -171,7 +171,7 @@ void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_ha | |||
171 | 171 | ||
172 | void do_onion_client(Onion_Client *onion_c); | 172 | void do_onion_client(Onion_Client *onion_c); |
173 | 173 | ||
174 | Onion_Client *new_onion_client(Mono_Time *mono_time, Net_Crypto *c); | 174 | Onion_Client *new_onion_client(const Logger *logger, Mono_Time *mono_time, Net_Crypto *c); |
175 | 175 | ||
176 | void kill_onion_client(Onion_Client *onion_c); | 176 | void kill_onion_client(Onion_Client *onion_c); |
177 | 177 | ||
diff --git a/toxcore/util.c b/toxcore/util.c index 58b75763..2f00adac 100644 --- a/toxcore/util.c +++ b/toxcore/util.c | |||
@@ -17,12 +17,12 @@ | |||
17 | 17 | ||
18 | #include "util.h" | 18 | #include "util.h" |
19 | 19 | ||
20 | #include "crypto_core.h" /* for CRYPTO_PUBLIC_KEY_SIZE */ | ||
21 | |||
22 | #include <stdlib.h> | 20 | #include <stdlib.h> |
23 | #include <string.h> | 21 | #include <string.h> |
24 | #include <time.h> | 22 | #include <time.h> |
25 | 23 | ||
24 | #include "crypto_core.h" /* for CRYPTO_PUBLIC_KEY_SIZE */ | ||
25 | |||
26 | 26 | ||
27 | /* id functions */ | 27 | /* id functions */ |
28 | bool id_equal(const uint8_t *dest, const uint8_t *src) | 28 | bool id_equal(const uint8_t *dest, const uint8_t *src) |