summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c50
1 files changed, 32 insertions, 18 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index db5b484d..8291fab0 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -2024,6 +2024,8 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
2024 set_nospam(&(m->fr), random_int()); 2024 set_nospam(&(m->fr), random_int());
2025 set_filter_function(&(m->fr), &friend_already_added, m); 2025 set_filter_function(&(m->fr), &friend_already_added, m);
2026 2026
2027 m->lastdump = 0;
2028
2027 if (error) { 2029 if (error) {
2028 *error = MESSENGER_ERROR_NONE; 2030 *error = MESSENGER_ERROR_NONE;
2029 } 2031 }
@@ -2471,18 +2473,22 @@ static void connection_status_cb(Messenger *m, void *userdata)
2471 2473
2472 2474
2473#define DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS 60UL 2475#define DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS 60UL
2474static time_t lastdump = 0; 2476
2475static char IDString[CRYPTO_PUBLIC_KEY_SIZE * 2 + 1]; 2477#define IDSTRING_LEN (CRYPTO_PUBLIC_KEY_SIZE * 2 + 1)
2476static char *ID2String(const uint8_t *pk) 2478/* id_str should be of length at least IDSTRING_LEN */
2479static char *id_to_string(const uint8_t *pk, char *id_str, size_t length)
2477{ 2480{
2478 uint32_t i; 2481 if (length < IDSTRING_LEN) {
2482 snprintf(id_str, length, "Bad buf length");
2483 return id_str;
2484 }
2479 2485
2480 for (i = 0; i < CRYPTO_PUBLIC_KEY_SIZE; i++) { 2486 for (uint32_t i = 0; i < CRYPTO_PUBLIC_KEY_SIZE; i++) {
2481 sprintf(&IDString[i * 2], "%02X", pk[i]); 2487 sprintf(&id_str[i * 2], "%02X", pk[i]);
2482 } 2488 }
2483 2489
2484 IDString[CRYPTO_PUBLIC_KEY_SIZE * 2] = 0; 2490 id_str[CRYPTO_PUBLIC_KEY_SIZE * 2] = 0;
2485 return IDString; 2491 return id_str;
2486} 2492}
2487 2493
2488/* Minimum messenger run interval in ms 2494/* Minimum messenger run interval in ms
@@ -2546,8 +2552,8 @@ void do_messenger(Messenger *m, void *userdata)
2546 do_friends(m, userdata); 2552 do_friends(m, userdata);
2547 connection_status_cb(m, userdata); 2553 connection_status_cb(m, userdata);
2548 2554
2549 if (unix_time() > lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) { 2555 if (unix_time() > m->lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) {
2550 lastdump = unix_time(); 2556 m->lastdump = unix_time();
2551 uint32_t client, last_pinged; 2557 uint32_t client, last_pinged;
2552 2558
2553 for (client = 0; client < LCLIENT_LIST; client++) { 2559 for (client = 0; client < LCLIENT_LIST; client++) {
@@ -2557,15 +2563,18 @@ void do_messenger(Messenger *m, void *userdata)
2557 2563
2558 for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6) { 2564 for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6) {
2559 if (ip_isset(&assoc->ip_port.ip)) { 2565 if (ip_isset(&assoc->ip_port.ip)) {
2560 last_pinged = lastdump - assoc->last_pinged; 2566 last_pinged = m->lastdump - assoc->last_pinged;
2561 2567
2562 if (last_pinged > 999) { 2568 if (last_pinged > 999) {
2563 last_pinged = 999; 2569 last_pinged = 999;
2564 } 2570 }
2565 2571
2572 char ip_str[IP_NTOA_LEN];
2573 char id_str[IDSTRING_LEN];
2566 LOGGER_TRACE(m->log, "C[%2u] %s:%u [%3u] %s", 2574 LOGGER_TRACE(m->log, "C[%2u] %s:%u [%3u] %s",
2567 client, ip_ntoa(&assoc->ip_port.ip), ntohs(assoc->ip_port.port), 2575 client, ip_ntoa(&assoc->ip_port.ip, ip_str, sizeof(ip_str)),
2568 last_pinged, ID2String(cptr->public_key)); 2576 ntohs(assoc->ip_port.port), last_pinged,
2577 id_to_string(cptr->public_key, id_str, sizeof(id_str)));
2569 } 2578 }
2570 } 2579 }
2571 } 2580 }
@@ -2617,11 +2626,14 @@ void do_messenger(Messenger *m, void *userdata)
2617 dhtfptr = &m->dht->friends_list[friend_idx]; 2626 dhtfptr = &m->dht->friends_list[friend_idx];
2618 2627
2619 if (msgfptr) { 2628 if (msgfptr) {
2629 char id_str[IDSTRING_LEN];
2620 LOGGER_TRACE(m->log, "F[%2u:%2u] <%s> %s", 2630 LOGGER_TRACE(m->log, "F[%2u:%2u] <%s> %s",
2621 dht2m[friend_idx], friend_idx, msgfptr->name, 2631 dht2m[friend_idx], friend_idx, msgfptr->name,
2622 ID2String(msgfptr->real_pk)); 2632 id_to_string(msgfptr->real_pk, id_str, sizeof(id_str)));
2623 } else { 2633 } else {
2624 LOGGER_TRACE(m->log, "F[--:%2u] %s", friend_idx, ID2String(dhtfptr->public_key)); 2634 char id_str[IDSTRING_LEN];
2635 LOGGER_TRACE(m->log, "F[--:%2u] %s", friend_idx,
2636 id_to_string(dhtfptr->public_key, id_str, sizeof(id_str)));
2625 } 2637 }
2626 2638
2627 for (client = 0; client < MAX_FRIEND_CLIENTS; client++) { 2639 for (client = 0; client < MAX_FRIEND_CLIENTS; client++) {
@@ -2631,16 +2643,18 @@ void do_messenger(Messenger *m, void *userdata)
2631 2643
2632 for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6) { 2644 for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6) {
2633 if (ip_isset(&assoc->ip_port.ip)) { 2645 if (ip_isset(&assoc->ip_port.ip)) {
2634 last_pinged = lastdump - assoc->last_pinged; 2646 last_pinged = m->lastdump - assoc->last_pinged;
2635 2647
2636 if (last_pinged > 999) { 2648 if (last_pinged > 999) {
2637 last_pinged = 999; 2649 last_pinged = 999;
2638 } 2650 }
2639 2651
2652 char ip_str[IP_NTOA_LEN];
2653 char id_str[IDSTRING_LEN];
2640 LOGGER_TRACE(m->log, "F[%2u] => C[%2u] %s:%u [%3u] %s", 2654 LOGGER_TRACE(m->log, "F[%2u] => C[%2u] %s:%u [%3u] %s",
2641 friend_idx, client, ip_ntoa(&assoc->ip_port.ip), 2655 friend_idx, client, ip_ntoa(&assoc->ip_port.ip, ip_str, sizeof(ip_str)),
2642 ntohs(assoc->ip_port.port), last_pinged, 2656 ntohs(assoc->ip_port.port), last_pinged,
2643 ID2String(cptr->public_key)); 2657 id_to_string(cptr->public_key, id_str, sizeof(id_str)));
2644 } 2658 }
2645 } 2659 }
2646 } 2660 }