Skip to content

feat: network profiler now includes group TCP packets in query results #2892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions toxcore/group_chats.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "mem.h"
#include "mono_time.h"
#include "net_crypto.h"
#include "net_profile.h"
#include "network.h"
#include "onion_announce.h"
#include "onion_client.h"
Expand Down Expand Up @@ -8590,3 +8591,83 @@ int gc_add_peers_from_announces(GC_Chat *chat, const GC_Announce *announces, uin

return added_peers;
}

uint64_t gc_tcp_connections_get_packet_id_count(const GC_Session *c, uint8_t id, Packet_Direction direction)
{
uint64_t count = 0;

for (uint32_t i = 0; i < c->chats_index; ++i) {
GC_Chat *chat = &c->chats[i];

const GC_Conn_State state = chat->connection_state;

if (state == CS_NONE) {
continue;
}

const Net_Profile *tcp_profile = tcp_connection_get_client_net_profile(chat->tcp_conn);
count += netprof_get_packet_count_id(tcp_profile, id, direction);
}

return count;
}

uint64_t gc_tcp_connections_get_packet_total_count(const GC_Session *c, Packet_Direction direction)
{
uint64_t count = 0;

for (uint32_t i = 0; i < c->chats_index; ++i) {
GC_Chat *chat = &c->chats[i];

const GC_Conn_State state = chat->connection_state;

if (state == CS_NONE) {
continue;
}

const Net_Profile *tcp_profile = tcp_connection_get_client_net_profile(chat->tcp_conn);
count += netprof_get_packet_count_total(tcp_profile, direction);
}

return count;
}

uint64_t gc_tcp_connections_get_packet_id_bytes(const GC_Session *c, uint8_t id, Packet_Direction direction)
{
uint64_t bytes = 0;

for (uint32_t i = 0; i < c->chats_index; ++i) {
GC_Chat *chat = &c->chats[i];

const GC_Conn_State state = chat->connection_state;

if (state == CS_NONE) {
continue;
}

const Net_Profile *tcp_profile = tcp_connection_get_client_net_profile(chat->tcp_conn);
bytes += netprof_get_bytes_id(tcp_profile, id, direction);
}

return bytes;
}

uint64_t gc_tcp_connections_get_packet_total_bytes(const GC_Session *c, Packet_Direction direction)
{
uint64_t bytes = 0;

for (uint32_t i = 0; i < c->chats_index; ++i) {
GC_Chat *chat = &c->chats[i];

const GC_Conn_State state = chat->connection_state;

if (state == CS_NONE) {
continue;
}

const Net_Profile *tcp_profile = tcp_connection_get_client_net_profile(chat->tcp_conn);
bytes += netprof_get_bytes_total(tcp_profile, direction);
}

return bytes;
}
10 changes: 10 additions & 0 deletions toxcore/group_chats.h
Original file line number Diff line number Diff line change
Expand Up @@ -807,4 +807,14 @@ GC_Chat *gc_get_group_by_public_key(const GC_Session *c, const uint8_t *public_k
non_null()
int gc_add_peers_from_announces(GC_Chat *chat, const GC_Announce *announces, uint8_t gc_announces_count);

/** @brief Returns total packet or byte counts for all active group chats. */
non_null()
uint64_t gc_tcp_connections_get_packet_id_count(const GC_Session *c, uint8_t id, Packet_Direction direction);
non_null()
uint64_t gc_tcp_connections_get_packet_total_count(const GC_Session *c, Packet_Direction direction);
non_null()
uint64_t gc_tcp_connections_get_packet_id_bytes(const GC_Session *c, uint8_t id, Packet_Direction direction);
non_null()
uint64_t gc_tcp_connections_get_packet_total_bytes(const GC_Session *c, Packet_Direction direction);

#endif /* C_TOXCORE_TOXCORE_GROUP_CHATS_H */
28 changes: 20 additions & 8 deletions toxcore/tox_private.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ uint64_t tox_netprof_get_packet_id_count(const Tox *tox, Tox_Netprof_Packet_Type

switch (type) {
case TOX_NETPROF_PACKET_TYPE_TCP_CLIENT: {
count = netprof_get_packet_count_id(tcp_c_profile, id, dir);
const uint64_t tcp_c_count = netprof_get_packet_count_id(tcp_c_profile, id, dir);
const uint64_t tcp_group_count = gc_tcp_connections_get_packet_id_count(tox->m->group_handler, id, dir);
count = tcp_c_count + tcp_group_count;
break;
}

Expand All @@ -258,7 +260,8 @@ uint64_t tox_netprof_get_packet_id_count(const Tox *tox, Tox_Netprof_Packet_Type
case TOX_NETPROF_PACKET_TYPE_TCP: {
const uint64_t tcp_c_count = netprof_get_packet_count_id(tcp_c_profile, id, dir);
const uint64_t tcp_s_count = netprof_get_packet_count_id(tcp_s_profile, id, dir);
count = tcp_c_count + tcp_s_count;
const uint64_t tcp_group_count = gc_tcp_connections_get_packet_id_count(tox->m->group_handler, id, dir);
count = tcp_c_count + tcp_s_count + tcp_group_count;
break;
}

Expand Down Expand Up @@ -295,7 +298,9 @@ uint64_t tox_netprof_get_packet_total_count(const Tox *tox, Tox_Netprof_Packet_T

switch (type) {
case TOX_NETPROF_PACKET_TYPE_TCP_CLIENT: {
count = netprof_get_packet_count_total(tcp_c_profile, dir);
const uint64_t tcp_c_count = netprof_get_packet_count_total(tcp_c_profile, dir);
const uint64_t tcp_group_count = gc_tcp_connections_get_packet_total_count(tox->m->group_handler, dir);
count = tcp_c_count + tcp_group_count;
break;
}

Expand All @@ -307,7 +312,8 @@ uint64_t tox_netprof_get_packet_total_count(const Tox *tox, Tox_Netprof_Packet_T
case TOX_NETPROF_PACKET_TYPE_TCP: {
const uint64_t tcp_c_count = netprof_get_packet_count_total(tcp_c_profile, dir);
const uint64_t tcp_s_count = netprof_get_packet_count_total(tcp_s_profile, dir);
count = tcp_c_count + tcp_s_count;
const uint64_t tcp_group_count = gc_tcp_connections_get_packet_total_count(tox->m->group_handler, dir);
count = tcp_c_count + tcp_s_count + tcp_group_count;
break;
}

Expand Down Expand Up @@ -344,7 +350,9 @@ uint64_t tox_netprof_get_packet_id_bytes(const Tox *tox, Tox_Netprof_Packet_Type

switch (type) {
case TOX_NETPROF_PACKET_TYPE_TCP_CLIENT: {
bytes = netprof_get_bytes_id(tcp_c_profile, id, dir);
const uint64_t tcp_c_bytes = netprof_get_bytes_id(tcp_c_profile, id, dir);
const uint64_t tcp_group_bytes = gc_tcp_connections_get_packet_id_bytes(tox->m->group_handler, id, dir);
bytes = tcp_c_bytes + tcp_group_bytes;
break;
}

Expand All @@ -356,7 +364,8 @@ uint64_t tox_netprof_get_packet_id_bytes(const Tox *tox, Tox_Netprof_Packet_Type
case TOX_NETPROF_PACKET_TYPE_TCP: {
const uint64_t tcp_c_bytes = netprof_get_bytes_id(tcp_c_profile, id, dir);
const uint64_t tcp_s_bytes = netprof_get_bytes_id(tcp_s_profile, id, dir);
bytes = tcp_c_bytes + tcp_s_bytes;
const uint64_t tcp_group_bytes = gc_tcp_connections_get_packet_id_bytes(tox->m->group_handler, id, dir);
bytes = tcp_c_bytes + tcp_s_bytes + tcp_group_bytes;
break;
}

Expand Down Expand Up @@ -393,7 +402,9 @@ uint64_t tox_netprof_get_packet_total_bytes(const Tox *tox, Tox_Netprof_Packet_T

switch (type) {
case TOX_NETPROF_PACKET_TYPE_TCP_CLIENT: {
bytes = netprof_get_bytes_total(tcp_c_profile, dir);
const uint64_t tcp_c_bytes = netprof_get_bytes_total(tcp_c_profile, dir);
const uint64_t tcp_group_bytes = gc_tcp_connections_get_packet_total_bytes(tox->m->group_handler, dir);
bytes = tcp_c_bytes + tcp_group_bytes;
break;
}

Expand All @@ -405,7 +416,8 @@ uint64_t tox_netprof_get_packet_total_bytes(const Tox *tox, Tox_Netprof_Packet_T
case TOX_NETPROF_PACKET_TYPE_TCP: {
const uint64_t tcp_c_bytes = netprof_get_bytes_total(tcp_c_profile, dir);
const uint64_t tcp_s_bytes = netprof_get_bytes_total(tcp_s_profile, dir);
bytes = tcp_c_bytes + tcp_s_bytes;
const uint64_t tcp_group_bytes = gc_tcp_connections_get_packet_total_bytes(tox->m->group_handler, dir);
bytes = tcp_c_bytes + tcp_s_bytes + tcp_group_bytes;
break;
}

Expand Down
Loading