Skip to content
Merged
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
6 changes: 3 additions & 3 deletions src/handle_packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static void handle_client_init(struct SwiftNetClientConnection* user, const stru

if(bytes_received != PACKET_HEADER_SIZE + sizeof(struct SwiftNetServerInformation) + client_connection->prepend_size) {
#ifdef SWIFT_NET_DEBUG
if (check_debug_flag(INITIALIZATION)) {
if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) {
send_debug_message("Invalid packet received from server. Expected server information: {\"bytes_received\": %u, \"expected_bytes\": %u}\n", bytes_received, PACKET_HEADER_SIZE + sizeof(struct SwiftNetServerInformation));
}
#endif
Expand All @@ -141,7 +141,7 @@ static void handle_client_init(struct SwiftNetClientConnection* user, const stru

if(packet_info->port_info.destination_port != client_connection->port_info.source_port || packet_info->port_info.source_port != client_connection->port_info.destination_port) {
#ifdef SWIFT_NET_DEBUG
if (check_debug_flag(INITIALIZATION)) {
if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) {
send_debug_message("Port info does not match: {\"destination_port\": %d, \"source_port\": %d, \"source_ip_address\": \"%s\"}\n", packet_info->port_info.destination_port, packet_info->port_info.source_port, inet_ntoa(ip_header->ip_src));
}
#endif
Expand All @@ -151,7 +151,7 @@ static void handle_client_init(struct SwiftNetClientConnection* user, const stru

if(packet_info->packet_type != REQUEST_INFORMATION) {
#ifdef SWIFT_NET_DEBUG
if (check_debug_flag(INITIALIZATION)) {
if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) {
send_debug_message("Invalid packet type: {\"packet_type\": %d}\n", packet_info->packet_type);
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/initialize_client_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void* request_server_information(void* const request_server_information_args_voi
}

#ifdef SWIFT_NET_DEBUG
if (check_debug_flag(INITIALIZATION)) {
if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) {
send_debug_message("Requested server information: {\"server_ip_address\": \"%s\"}\n", inet_ntoa(request_server_information_args->server_addr));
}
#endif
Expand Down Expand Up @@ -182,7 +182,7 @@ struct SwiftNetClientConnection* swiftnet_create_client(const char* const ip_add
pthread_cond_init(&new_connection->execute_callback_cond, NULL);

#ifdef SWIFT_NET_DEBUG
if (check_debug_flag(INITIALIZATION)) {
if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) {
send_debug_message("Successfully initialized client\n");
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/initialize_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct SwiftNetServer* swiftnet_create_server(const uint16_t port, const bool lo
pthread_cond_init(&new_server->execute_callback_cond, NULL);

#ifdef SWIFT_NET_DEBUG
if (check_debug_flag(INITIALIZATION)) {
if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) {
send_debug_message("Successfully initialized server\n");
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/internal/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ extern uint32_t items_leaked;
#ifdef SWIFT_NET_DEBUG
extern struct SwiftNetDebugger debugger;

static inline bool check_debug_flag(const enum SwiftNetDebugFlags flag) {
static inline bool check_debug_flag(const SwiftNetDebugFlags flag) {
return (debugger.flags & flag) != 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/manipulate_debug_flags.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "internal/internal.h"
#include "swift_net.h"

void swiftnet_add_debug_flags(const enum SwiftNetDebugFlags flags) {
void swiftnet_add_debug_flags(const SwiftNetDebugFlags flags) {
debugger.flags |= flags;
}
void swiftnet_remove_debug_flags(const enum SwiftNetDebugFlags flags) {
void swiftnet_remove_debug_flags(const SwiftNetDebugFlags flags) {
debugger.flags &= ~flags;
}
4 changes: 2 additions & 2 deletions src/process_packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ static inline void swiftnet_process_packets(
if(memcmp(&ip_header.ip_src, &ip_header.ip_dst, sizeof(struct in_addr)) != 0 && is_private_ip(ip_header.ip_src) == false && is_private_ip(ip_header.ip_dst)) {
if(ip_header.ip_sum != 0 && packet_corrupted(checksum_received, node->data_read, packet_buffer) == true) {
#ifdef SWIFT_NET_DEBUG
if (check_debug_flag(PACKETS_RECEIVING)) {
if (check_debug_flag(SWIFTNET_DEBUG_PACKETS_RECEIVING)) {
send_debug_message("Received corrupted packet: {\"source_ip_address\": \"%s\", \"source_port\": %d, \"packet_id\": %d, \"received_checsum\": %d, \"real_checksum\": %d}\n", inet_ntoa(ip_header.ip_src), packet_info.port_info.source_port, ip_header.ip_id, checksum_received, crc16(packet_buffer, node->data_read));
}
#endif
Expand All @@ -375,7 +375,7 @@ static inline void swiftnet_process_packets(
}

#ifdef SWIFT_NET_DEBUG
if (check_debug_flag(PACKETS_RECEIVING)) {
if (check_debug_flag(SWIFTNET_DEBUG_PACKETS_RECEIVING)) {
send_debug_message("Received packet: {\"source_ip_address\": \"%s\", \"source_port\": %d, \"packet_id\": %d, \"packet_type\": %d, \"packet_length\": %d, \"chunk_index\": %d, \"connection_type\": %d, \"checksum_received\": %d, \"real_checksum\": %d}\n", inet_ntoa(ip_header.ip_src), packet_info.port_info.source_port, ip_header.ip_id, packet_info.packet_type, packet_info.packet_length, packet_info.chunk_index, connection_type, checksum_received, crc16(node->data, node->data_read));
}
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/send_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

static inline enum RequestLostPacketsReturnType request_lost_packets_bitarray(const uint8_t* const raw_data, const uint32_t data_size, const struct sockaddr* const destination, pcap_t* const pcap, struct SwiftNetPacketSending* const packet_sending) {
while(1) {
if(check_debug_flag(LOST_PACKETS)) {
if(check_debug_flag(SWIFTNET_DEBUG_LOST_PACKETS)) {
send_debug_message("Requested list of lost packets: {\"packet_id\": %d}\n", packet_sending->packet_id);
}

Expand Down Expand Up @@ -145,7 +145,7 @@ static inline void handle_lost_packets(

memcpy(current_buffer_header_ptr, prepend_buffer, prepend_size + PACKET_HEADER_SIZE);

if (check_debug_flag(LOST_PACKETS) == true) {
if (check_debug_flag(SWIFTNET_DEBUG_LOST_PACKETS) == true) {
send_debug_message("Packet lost: {\"packet_id\": %d, \"chunk index\": %d}\n", packet_sending->packet_id, lost_chunk_index);
}

Expand Down Expand Up @@ -199,7 +199,7 @@ inline void swiftnet_send_packet(
const uint32_t mtu = MIN(target_maximum_transmission_unit, maximum_transmission_unit);

#ifdef SWIFT_NET_DEBUG
if (check_debug_flag(PACKETS_SENDING)) {
if (check_debug_flag(SWIFTNET_DEBUG_PACKETS_SENDING)) {
send_debug_message("Sending packet: {\"destination_ip_address\": \"%s\", \"destination_port\": %d, \"packet_length\": %d}\n", inet_ntoa(*target_addr), port_info.destination_port, packet_length);
}
#endif
Expand Down Expand Up @@ -291,7 +291,7 @@ inline void swiftnet_send_packet(
const uint32_t current_offset = i * (mtu - PACKET_HEADER_SIZE);

#ifdef SWIFT_NET_DEBUG
if (check_debug_flag(PACKETS_SENDING)) {
if (check_debug_flag(SWIFTNET_DEBUG_PACKETS_SENDING)) {
send_debug_message("Sent chunk: {\"chunk_index\": %d}\n", i);
}
#endif
Expand Down
18 changes: 9 additions & 9 deletions src/swift_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ enum PacketType {
extern uint32_t maximum_transmission_unit;

#ifdef SWIFT_NET_DEBUG
#define SWIFTNET_DEBUG_FLAGS(num) ((enum SwiftNetDebugFlags)(num))
#define SWIFTNET_DEBUG_FLAGS(num) ((SwiftNetDebugFlags)(num))

enum SwiftNetDebugFlags {
PACKETS_SENDING = 1u << 1,
PACKETS_RECEIVING = 1u << 2,
INITIALIZATION = 1u << 3,
LOST_PACKETS = 1u << 4
};
typedef uint8_t SwiftNetDebugFlags;

#define SWIFTNET_DEBUG_PACKETS_SENDING (1u << 1)
#define SWIFTNET_DEBUG_PACKETS_RECEIVING (1u << 2)
#define SWIFTNET_DEBUG_INITIALIZATION (1u << 3)
#define SWIFTNET_DEBUG_LOST_PACKETS (1u << 4)

struct SwiftNetDebugger {
int flags;
Expand Down Expand Up @@ -425,9 +425,9 @@ extern void swiftnet_server_make_response(

#ifdef SWIFT_NET_DEBUG
// Adds one or more debug flags to the global debugger state.
extern void swiftnet_add_debug_flags(const enum SwiftNetDebugFlags flags);
extern void swiftnet_add_debug_flags(const SwiftNetDebugFlags flags);
// Removes one or more debug flags from the global debugger state.
extern void swiftnet_remove_debug_flags(const enum SwiftNetDebugFlags flags);
extern void swiftnet_remove_debug_flags(const SwiftNetDebugFlags flags);
#endif


Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/src/run_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ int main() {

swiftnet_initialize();

swiftnet_add_debug_flags(SWIFTNET_DEBUG_FLAGS(PACKETS_SENDING | PACKETS_RECEIVING | INITIALIZATION | LOST_PACKETS));
swiftnet_add_debug_flags(SWIFTNET_DEBUG_FLAGS(SWIFTNET_DEBUG_PACKETS_SENDING | SWIFTNET_DEBUG_PACKETS_RECEIVING | SWIFTNET_DEBUG_INITIALIZATION | SWIFTNET_DEBUG_LOST_PACKETS));

for (uint16_t i = 0; i < sizeof(tests) / sizeof(struct Test); i++) {
const struct Test* current_test = &tests[i];
Expand Down
2 changes: 1 addition & 1 deletion tests/performance_tests/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void send_large_packets(const bool loopback) {
int main() {
swiftnet_initialize();

swiftnet_add_debug_flags(SWIFTNET_DEBUG_FLAGS(PACKETS_SENDING | PACKETS_RECEIVING | INITIALIZATION | LOST_PACKETS));
swiftnet_add_debug_flags(SWIFTNET_DEBUG_FLAGS(SWIFTNET_DEBUG_PACKETS_SENDING | SWIFTNET_DEBUG_PACKETS_RECEIVING | SWIFTNET_DEBUG_INITIALIZATION | SWIFTNET_DEBUG_LOST_PACKETS));

send_large_packets(false);

Expand Down
Loading