diff --git a/CMakeLists.txt b/CMakeLists.txt index a092be5fb9..2394bc06df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -307,10 +307,10 @@ set(toxcore_SOURCES toxcore/mem.h toxcore/mono_time.c toxcore/mono_time.h - toxcore/net_profile.c - toxcore/net_profile.h toxcore/net_crypto.c toxcore/net_crypto.h + toxcore/net_profile.c + toxcore/net_profile.h toxcore/network.c toxcore/network.h toxcore/onion_announce.c diff --git a/auto_tests/netprof_test.c b/auto_tests/netprof_test.c index 1ea37d94de..6eeb654c52 100644 --- a/auto_tests/netprof_test.c +++ b/auto_tests/netprof_test.c @@ -2,6 +2,7 @@ * TODO(JFreegman): test TCP packets as well */ +#include #include #include @@ -91,18 +92,18 @@ static void test_netprof(AutoTox *autotoxes) const uint64_t total_packets = total_sent_count + total_recv_count; ck_assert_msg(total_packets == UDP_count_sent1 + UDP_count_recv1, - "%lu does not match %lu\n", total_packets, UDP_count_sent1 + UDP_count_recv1); + "%" PRIu64 "does not match %" PRIu64 "\n", total_packets, UDP_count_sent1 + UDP_count_recv1); - ck_assert_msg(total_sent_count == UDP_count_sent1, "%lu does not match %lu\n", total_sent_count, UDP_count_sent1); - ck_assert_msg(total_recv_count == UDP_count_recv1, "%lu does not match %lu\n", total_recv_count, UDP_count_recv1); + ck_assert_msg(total_sent_count == UDP_count_sent1, "%" PRIu64 " does not match %" PRIu64 "\n", total_sent_count, UDP_count_sent1); + ck_assert_msg(total_recv_count == UDP_count_recv1, "%" PRIu64 " does not match %" PRIu64"\n", total_recv_count, UDP_count_recv1); const uint64_t total_bytes = total_sent_bytes + total_recv_bytes; ck_assert_msg(total_bytes == UDP_bytes_sent1 + UDP_bytes_recv1, - "%lu does not match %lu\n", total_bytes, UDP_bytes_sent1 + UDP_bytes_recv1); + "%" PRIu64 "does not match %" PRIu64 "\n", total_bytes, UDP_bytes_sent1 + UDP_bytes_recv1); - ck_assert_msg(total_sent_bytes == UDP_bytes_sent1, "%lu does not match %lu\n", total_sent_bytes, UDP_bytes_sent1); - ck_assert_msg(total_recv_bytes == UDP_bytes_recv1, "%lu does not match %lu\n", total_recv_bytes, UDP_bytes_recv1); + ck_assert_msg(total_sent_bytes == UDP_bytes_sent1, "%" PRIu64 " does not match %" PRIu64 "\n", total_sent_bytes, UDP_bytes_sent1); + ck_assert_msg(total_recv_bytes == UDP_bytes_recv1, "%" PRIu64 " does not match %" PRIu64 "\n", total_recv_bytes, UDP_bytes_recv1); } int main(void) diff --git a/toxcore/net_profile.h b/toxcore/net_profile.h index 217a829d19..a2f66a19ff 100644 --- a/toxcore/net_profile.h +++ b/toxcore/net_profile.h @@ -18,6 +18,7 @@ /* The max number of packet ID's (must fit inside one byte) */ #define NET_PROF_MAX_PACKET_IDS 256 +/* If passed to a netprof function as a nullptr the function will have no effect. */ typedef struct Net_Profile Net_Profile; /** Specifies whether the query is for sent or received packets. */ diff --git a/toxcore/tox_api.c b/toxcore/tox_api.c index b979e4e1e2..99cfaf4ded 100644 --- a/toxcore/tox_api.c +++ b/toxcore/tox_api.c @@ -1722,3 +1722,117 @@ const char *tox_group_mod_event_to_string(Tox_Group_Mod_Event value) return ""; } +const char *tox_netprof_packet_id_to_string(Tox_Netprof_Packet_Id value) { + switch (value) { + case TOX_NETPROF_PACKET_ID_ZERO: + return "TOX_NETPROF_PACKET_ID_ZERO"; + case TOX_NETPROF_PACKET_ID_ONE: + return "TOX_NETPROF_PACKET_ID_ONE"; + case TOX_NETPROF_PACKET_ID_TWO: + return "TOX_NETPROF_PACKET_ID_TWO"; + case TOX_NETPROF_PACKET_ID_TCP_DISCONNECT: + return "TOX_NETPROF_PACKET_ID_TCP_DISCONNECT"; + case TOX_NETPROF_PACKET_ID_FOUR: + return "TOX_NETPROF_PACKET_ID_FOUR"; + case TOX_NETPROF_PACKET_ID_TCP_PONG: + return "TOX_NETPROF_PACKET_ID_TCP_PONG"; + case TOX_NETPROF_PACKET_ID_TCP_OOB_SEND: + return "TOX_NETPROF_PACKET_ID_TCP_OOB_SEND"; + case TOX_NETPROF_PACKET_ID_TCP_OOB_RECV: + return "TOX_NETPROF_PACKET_ID_TCP_OOB_RECV"; + case TOX_NETPROF_PACKET_ID_TCP_ONION_REQUEST: + return "TOX_NETPROF_PACKET_ID_TCP_ONION_REQUEST"; + case TOX_NETPROF_PACKET_ID_TCP_ONION_RESPONSE: + return "TOX_NETPROF_PACKET_ID_TCP_ONION_RESPONSE"; + case TOX_NETPROF_PACKET_ID_TCP_DATA: + return "TOX_NETPROF_PACKET_ID_TCP_DATA"; + case TOX_NETPROF_PACKET_ID_COOKIE_REQUEST: + return "TOX_NETPROF_PACKET_ID_COOKIE_REQUEST"; + case TOX_NETPROF_PACKET_ID_COOKIE_RESPONSE: + return "TOX_NETPROF_PACKET_ID_COOKIE_RESPONSE"; + case TOX_NETPROF_PACKET_ID_CRYPTO_HS: + return "TOX_NETPROF_PACKET_ID_CRYPTO_HS"; + case TOX_NETPROF_PACKET_ID_CRYPTO_DATA: + return "TOX_NETPROF_PACKET_ID_CRYPTO_DATA"; + case TOX_NETPROF_PACKET_ID_CRYPTO: + return "TOX_NETPROF_PACKET_ID_CRYPTO"; + case TOX_NETPROF_PACKET_ID_LAN_DISCOVERY: + return "TOX_NETPROF_PACKET_ID_LAN_DISCOVERY"; + case TOX_NETPROF_PACKET_ID_GC_HANDSHAKE: + return "TOX_NETPROF_PACKET_ID_GC_HANDSHAKE"; + case TOX_NETPROF_PACKET_ID_GC_LOSSLESS: + return "TOX_NETPROF_PACKET_ID_GC_LOSSLESS"; + case TOX_NETPROF_PACKET_ID_GC_LOSSY: + return "TOX_NETPROF_PACKET_ID_GC_LOSSY"; + case TOX_NETPROF_PACKET_ID_ONION_SEND_INITIAL: + return "TOX_NETPROF_PACKET_ID_ONION_SEND_INITIAL"; + case TOX_NETPROF_PACKET_ID_ONION_SEND_1: + return "TOX_NETPROF_PACKET_ID_ONION_SEND_1"; + case TOX_NETPROF_PACKET_ID_ONION_SEND_2: + return "TOX_NETPROF_PACKET_ID_ONION_SEND_2"; + case TOX_NETPROF_PACKET_ID_ANNOUNCE_REQUEST_OLD: + return "TOX_NETPROF_PACKET_ID_ANNOUNCE_REQUEST_OLD"; + case TOX_NETPROF_PACKET_ID_ANNOUNCE_RESPONSE_OLD: + return "TOX_NETPROF_PACKET_ID_ANNOUNCE_RESPONSE_OLD"; + case TOX_NETPROF_PACKET_ID_ONION_DATA_REQUEST: + return "TOX_NETPROF_PACKET_ID_ONION_DATA_REQUEST"; + case TOX_NETPROF_PACKET_ID_ONION_DATA_RESPONSE: + return "TOX_NETPROF_PACKET_ID_ONION_DATA_RESPONSE"; + case TOX_NETPROF_PACKET_ID_ANNOUNCE_REQUEST: + return "TOX_NETPROF_PACKET_ID_ANNOUNCE_REQUEST"; + case TOX_NETPROF_PACKET_ID_ANNOUNCE_RESPONSE: + return "TOX_NETPROF_PACKET_ID_ANNOUNCE_RESPONSE"; + case TOX_NETPROF_PACKET_ID_ONION_RECV_3: + return "TOX_NETPROF_PACKET_ID_ONION_RECV_3"; + case TOX_NETPROF_PACKET_ID_ONION_RECV_2: + return "TOX_NETPROF_PACKET_ID_ONION_RECV_2"; + case TOX_NETPROF_PACKET_ID_ONION_RECV_1: + return "TOX_NETPROF_PACKET_ID_ONION_RECV_1"; + case TOX_NETPROF_PACKET_ID_FORWARD_REQUEST: + return "TOX_NETPROF_PACKET_ID_FORWARD_REQUEST"; + case TOX_NETPROF_PACKET_ID_FORWARDING: + return "TOX_NETPROF_PACKET_ID_FORWARDING"; + case TOX_NETPROF_PACKET_ID_FORWARD_REPLY: + return "TOX_NETPROF_PACKET_ID_FORWARD_REPLY"; + case TOX_NETPROF_PACKET_ID_DATA_SEARCH_REQUEST: + return "TOX_NETPROF_PACKET_ID_DATA_SEARCH_REQUEST"; + case TOX_NETPROF_PACKET_ID_DATA_SEARCH_RESPONSE: + return "TOX_NETPROF_PACKET_ID_DATA_SEARCH_RESPONSE"; + case TOX_NETPROF_PACKET_ID_DATA_RETRIEVE_REQUEST: + return "TOX_NETPROF_PACKET_ID_DATA_RETRIEVE_REQUEST"; + case TOX_NETPROF_PACKET_ID_DATA_RETRIEVE_RESPONSE: + return "TOX_NETPROF_PACKET_ID_DATA_RETRIEVE_RESPONSE"; + case TOX_NETPROF_PACKET_ID_STORE_ANNOUNCE_REQUEST: + return "TOX_NETPROF_PACKET_ID_STORE_ANNOUNCE_REQUEST"; + case TOX_NETPROF_PACKET_ID_STORE_ANNOUNCE_RESPONSE: + return "TOX_NETPROF_PACKET_ID_STORE_ANNOUNCE_RESPONSE"; + case TOX_NETPROF_PACKET_ID_BOOTSTRAP_INFO: + return "TOX_NETPROF_PACKET_ID_BOOTSTRAP_INFO"; + } + + return ""; +} +const char *tox_netprof_packet_type_to_string(Tox_Netprof_Packet_Type value) { + switch (value) { + case TOX_NETPROF_PACKET_TYPE_TCP_CLIENT: + return "TOX_NETPROF_PACKET_TYPE_TCP_CLIENT"; + case TOX_NETPROF_PACKET_TYPE_TCP_SERVER: + return "TOX_NETPROF_PACKET_TYPE_TCP_SERVER"; + case TOX_NETPROF_PACKET_TYPE_TCP: + return "TOX_NETPROF_PACKET_TYPE_TCP"; + case TOX_NETPROF_PACKET_TYPE_UDP: + return "TOX_NETPROF_PACKET_TYPE_UDP"; + } + + return ""; +} +const char *tox_netprof_direction_to_string(Tox_Netprof_Direction value) { + switch (value) { + case TOX_NETPROF_DIRECTION_SENT: + return "TOX_NETPROF_DIRECTION_SENT"; + case TOX_NETPROF_DIRECTION_RECV: + return "TOX_NETPROF_DIRECTION_RECV"; + } + + return ""; +} diff --git a/toxcore/tox_private.h b/toxcore/tox_private.h index 04f51da720..2c53c75c12 100644 --- a/toxcore/tox_private.h +++ b/toxcore/tox_private.h @@ -345,6 +345,8 @@ typedef enum Tox_Netprof_Packet_Id { TOX_NETPROF_PACKET_ID_BOOTSTRAP_INFO = 0xf0, } Tox_Netprof_Packet_Id; +const char *tox_netprof_packet_id_to_string(Tox_Netprof_Packet_Id value); + /** * Specifies the packet type for a given query. */ @@ -370,6 +372,8 @@ typedef enum Tox_Netprof_Packet_Type { TOX_NETPROF_PACKET_TYPE_UDP, } Tox_Netprof_Packet_Type; +const char *tox_netprof_packet_type_to_string(Tox_Netprof_Packet_Type value); + /** * Specifies the packet direction for a given query. */ @@ -385,6 +389,8 @@ typedef enum Tox_Netprof_Direction { TOX_NETPROF_DIRECTION_RECV, } Tox_Netprof_Direction; +const char *tox_netprof_direction_to_string(Tox_Netprof_Direction value); + /** * Return the number of packets sent or received for a specific packet ID. *