Skip to content

Commit 8e460d7

Browse files
committed
feat: network profiler now includes group TCP packets in query results
1 parent 9324a97 commit 8e460d7

File tree

3 files changed

+111
-8
lines changed

3 files changed

+111
-8
lines changed

Diff for: toxcore/group_chats.c

+81
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "mem.h"
3333
#include "mono_time.h"
3434
#include "net_crypto.h"
35+
#include "net_profile.h"
3536
#include "network.h"
3637
#include "onion_announce.h"
3738
#include "onion_client.h"
@@ -8590,3 +8591,83 @@ int gc_add_peers_from_announces(GC_Chat *chat, const GC_Announce *announces, uin
85908591

85918592
return added_peers;
85928593
}
8594+
8595+
uint64_t gc_tcp_connections_get_packet_id_count(const GC_Session *c, uint8_t id, Packet_Direction direction)
8596+
{
8597+
uint64_t count = 0;
8598+
8599+
for (uint32_t i = 0; i < c->chats_index; ++i) {
8600+
GC_Chat *chat = &c->chats[i];
8601+
8602+
const GC_Conn_State state = chat->connection_state;
8603+
8604+
if (state == CS_NONE) {
8605+
continue;
8606+
}
8607+
8608+
const Net_Profile *tcp_profile = tcp_connection_get_client_net_profile(chat->tcp_conn);
8609+
count += netprof_get_packet_count_id(tcp_profile, id, direction);
8610+
}
8611+
8612+
return count;
8613+
}
8614+
8615+
uint64_t gc_tcp_connections_get_packet_total_count(const GC_Session *c, Packet_Direction direction)
8616+
{
8617+
uint64_t count = 0;
8618+
8619+
for (uint32_t i = 0; i < c->chats_index; ++i) {
8620+
GC_Chat *chat = &c->chats[i];
8621+
8622+
const GC_Conn_State state = chat->connection_state;
8623+
8624+
if (state == CS_NONE) {
8625+
continue;
8626+
}
8627+
8628+
const Net_Profile *tcp_profile = tcp_connection_get_client_net_profile(chat->tcp_conn);
8629+
count += netprof_get_packet_count_total(tcp_profile, direction);
8630+
}
8631+
8632+
return count;
8633+
}
8634+
8635+
uint64_t gc_tcp_connections_get_packet_id_bytes(const GC_Session *c, uint8_t id, Packet_Direction direction)
8636+
{
8637+
uint64_t bytes = 0;
8638+
8639+
for (uint32_t i = 0; i < c->chats_index; ++i) {
8640+
GC_Chat *chat = &c->chats[i];
8641+
8642+
const GC_Conn_State state = chat->connection_state;
8643+
8644+
if (state == CS_NONE) {
8645+
continue;
8646+
}
8647+
8648+
const Net_Profile *tcp_profile = tcp_connection_get_client_net_profile(chat->tcp_conn);
8649+
bytes += netprof_get_bytes_id(tcp_profile, id, direction);
8650+
}
8651+
8652+
return bytes;
8653+
}
8654+
8655+
uint64_t gc_tcp_connections_get_packet_total_bytes(const GC_Session *c, Packet_Direction direction)
8656+
{
8657+
uint64_t bytes = 0;
8658+
8659+
for (uint32_t i = 0; i < c->chats_index; ++i) {
8660+
GC_Chat *chat = &c->chats[i];
8661+
8662+
const GC_Conn_State state = chat->connection_state;
8663+
8664+
if (state == CS_NONE) {
8665+
continue;
8666+
}
8667+
8668+
const Net_Profile *tcp_profile = tcp_connection_get_client_net_profile(chat->tcp_conn);
8669+
bytes += netprof_get_bytes_total(tcp_profile, direction);
8670+
}
8671+
8672+
return bytes;
8673+
}

Diff for: toxcore/group_chats.h

+10
Original file line numberDiff line numberDiff line change
@@ -807,4 +807,14 @@ GC_Chat *gc_get_group_by_public_key(const GC_Session *c, const uint8_t *public_k
807807
non_null()
808808
int gc_add_peers_from_announces(GC_Chat *chat, const GC_Announce *announces, uint8_t gc_announces_count);
809809

810+
/** @brief Returns total packet or byte counts for all active group chats. */
811+
non_null()
812+
uint64_t gc_tcp_connections_get_packet_id_count(const GC_Session *c, uint8_t id, Packet_Direction direction);
813+
non_null()
814+
uint64_t gc_tcp_connections_get_packet_total_count(const GC_Session *c, Packet_Direction direction);
815+
non_null()
816+
uint64_t gc_tcp_connections_get_packet_id_bytes(const GC_Session *c, uint8_t id, Packet_Direction direction);
817+
non_null()
818+
uint64_t gc_tcp_connections_get_packet_total_bytes(const GC_Session *c, Packet_Direction direction);
819+
810820
#endif /* C_TOXCORE_TOXCORE_GROUP_CHATS_H */

Diff for: toxcore/tox_private.c

+20-8
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ uint64_t tox_netprof_get_packet_id_count(const Tox *tox, Tox_Netprof_Packet_Type
246246

247247
switch (type) {
248248
case TOX_NETPROF_PACKET_TYPE_TCP_CLIENT: {
249-
count = netprof_get_packet_count_id(tcp_c_profile, id, dir);
249+
const uint64_t tcp_c_count = netprof_get_packet_count_id(tcp_c_profile, id, dir);
250+
const uint64_t tcp_group_count = gc_tcp_connections_get_packet_id_count(tox->m->group_handler, id, dir);
251+
count = tcp_c_count + tcp_group_count;
250252
break;
251253
}
252254

@@ -258,7 +260,8 @@ uint64_t tox_netprof_get_packet_id_count(const Tox *tox, Tox_Netprof_Packet_Type
258260
case TOX_NETPROF_PACKET_TYPE_TCP: {
259261
const uint64_t tcp_c_count = netprof_get_packet_count_id(tcp_c_profile, id, dir);
260262
const uint64_t tcp_s_count = netprof_get_packet_count_id(tcp_s_profile, id, dir);
261-
count = tcp_c_count + tcp_s_count;
263+
const uint64_t tcp_group_count = gc_tcp_connections_get_packet_id_count(tox->m->group_handler, id, dir);
264+
count = tcp_c_count + tcp_s_count + tcp_group_count;
262265
break;
263266
}
264267

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

296299
switch (type) {
297300
case TOX_NETPROF_PACKET_TYPE_TCP_CLIENT: {
298-
count = netprof_get_packet_count_total(tcp_c_profile, dir);
301+
const uint64_t tcp_c_count = netprof_get_packet_count_total(tcp_c_profile, dir);
302+
const uint64_t tcp_group_count = gc_tcp_connections_get_packet_total_count(tox->m->group_handler, dir);
303+
count = tcp_c_count + tcp_group_count;
299304
break;
300305
}
301306

@@ -307,7 +312,8 @@ uint64_t tox_netprof_get_packet_total_count(const Tox *tox, Tox_Netprof_Packet_T
307312
case TOX_NETPROF_PACKET_TYPE_TCP: {
308313
const uint64_t tcp_c_count = netprof_get_packet_count_total(tcp_c_profile, dir);
309314
const uint64_t tcp_s_count = netprof_get_packet_count_total(tcp_s_profile, dir);
310-
count = tcp_c_count + tcp_s_count;
315+
const uint64_t tcp_group_count = gc_tcp_connections_get_packet_total_count(tox->m->group_handler, dir);
316+
count = tcp_c_count + tcp_s_count + tcp_group_count;
311317
break;
312318
}
313319

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

345351
switch (type) {
346352
case TOX_NETPROF_PACKET_TYPE_TCP_CLIENT: {
347-
bytes = netprof_get_bytes_id(tcp_c_profile, id, dir);
353+
const uint64_t tcp_c_bytes = netprof_get_bytes_id(tcp_c_profile, id, dir);
354+
const uint64_t tcp_group_bytes = gc_tcp_connections_get_packet_id_bytes(tox->m->group_handler, id, dir);
355+
bytes = tcp_c_bytes + tcp_group_bytes;
348356
break;
349357
}
350358

@@ -356,7 +364,8 @@ uint64_t tox_netprof_get_packet_id_bytes(const Tox *tox, Tox_Netprof_Packet_Type
356364
case TOX_NETPROF_PACKET_TYPE_TCP: {
357365
const uint64_t tcp_c_bytes = netprof_get_bytes_id(tcp_c_profile, id, dir);
358366
const uint64_t tcp_s_bytes = netprof_get_bytes_id(tcp_s_profile, id, dir);
359-
bytes = tcp_c_bytes + tcp_s_bytes;
367+
const uint64_t tcp_group_bytes = gc_tcp_connections_get_packet_id_bytes(tox->m->group_handler, id, dir);
368+
bytes = tcp_c_bytes + tcp_s_bytes + tcp_group_bytes;
360369
break;
361370
}
362371

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

394403
switch (type) {
395404
case TOX_NETPROF_PACKET_TYPE_TCP_CLIENT: {
396-
bytes = netprof_get_bytes_total(tcp_c_profile, dir);
405+
const uint64_t tcp_c_bytes = netprof_get_bytes_total(tcp_c_profile, dir);
406+
const uint64_t tcp_group_bytes = gc_tcp_connections_get_packet_total_bytes(tox->m->group_handler, dir);
407+
bytes = tcp_c_bytes + tcp_group_bytes;
397408
break;
398409
}
399410

@@ -405,7 +416,8 @@ uint64_t tox_netprof_get_packet_total_bytes(const Tox *tox, Tox_Netprof_Packet_T
405416
case TOX_NETPROF_PACKET_TYPE_TCP: {
406417
const uint64_t tcp_c_bytes = netprof_get_bytes_total(tcp_c_profile, dir);
407418
const uint64_t tcp_s_bytes = netprof_get_bytes_total(tcp_s_profile, dir);
408-
bytes = tcp_c_bytes + tcp_s_bytes;
419+
const uint64_t tcp_group_bytes = gc_tcp_connections_get_packet_total_bytes(tox->m->group_handler, dir);
420+
bytes = tcp_c_bytes + tcp_s_bytes + tcp_group_bytes;
409421
break;
410422
}
411423

0 commit comments

Comments
 (0)