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
10 changes: 9 additions & 1 deletion src/process_packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,11 @@ static inline struct SwiftNetPendingMessage* create_new_pending_message(struct S
.packet_info = *packet_info,
.packet_data_start = allocated_memory,
.chunks_received_number = 0x00,
#ifndef DISABLE_DYNAMIC_RATE_LIMITING
.last_index_checked = 0,
.sending_lost_packets = false,
.last_chunks_received_number = 0,
#endif
.sending_lost_packets = false,
.chunks_received_length = chunks_received_byte_size,
.chunks_received = calloc(chunks_received_byte_size, 1),
.packet_id = packet_id,
Expand Down Expand Up @@ -271,6 +273,7 @@ static inline struct SwiftNetPacketSending* get_packet_sending(struct SwiftNetHa
return result;
}

#ifndef DISABLE_DYNAMIC_RATE_LIMITING
static inline void signal_delay_change(const enum PacketDelayUpdateStatus status, const struct ip* restrict const ip_header, const uint16_t source_port, const uint16_t destination_port, const struct ether_header* const eth_hdr, const struct SwiftNetNetworkData* const net_data) {
struct ip send_server_info_ip_header;
struct SwiftNetPacketInfo packet_info_new;
Expand Down Expand Up @@ -306,6 +309,7 @@ static inline void signal_delay_change(const enum PacketDelayUpdateStatus status

SWIFTNET_SEND_PACKET(net_data, buffer, sizeof(buffer));
}
#endif

struct PacketQueueNode* wait_for_next_packet(struct PacketQueue* const packet_queue) {
struct PacketQueueNode* node_to_process;
Expand Down Expand Up @@ -640,6 +644,7 @@ static inline void swiftnet_process_packets(

goto next_packet;
}
#ifndef DISABLE_DYNAMIC_RATE_LIMITING
case PACKET_DELAY_UPDATE:
{
enum PacketDelayUpdateStatus* status;
Expand All @@ -665,6 +670,7 @@ static inline void swiftnet_process_packets(

goto next_packet;
}
#endif
default:
break;
}
Expand Down Expand Up @@ -873,6 +879,7 @@ static inline void swiftnet_process_packets(

goto next_packet;
} else {
#ifndef DISABLE_DYNAMIC_RATE_LIMITING
uint32_t new_packets;
uint32_t new_packets_validated;
float ratio;
Expand All @@ -894,6 +901,7 @@ static inline void swiftnet_process_packets(
pending_message->last_index_checked = packet_info.chunk_index;
}
}
#endif

memcpy(pending_message->packet_data_start + (chunk_data_size * packet_info.chunk_index), packet_data, bytes_to_write);

Expand Down
4 changes: 4 additions & 0 deletions src/send_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ inline void swiftnet_send_packet(
.packet_id = packet_id,
};

#ifndef DISABLE_DYNAMIC_RATE_LIMITING
atomic_store_explicit(&new_packet_sending->current_send_delay, 50, memory_order_release);
#endif
atomic_store_explicit(&new_packet_sending->updated, NO_UPDATE, memory_order_release);

hashmap_insert(key_data_mem, sizeof(uint16_t), new_packet_sending, packets_sending);
Expand Down Expand Up @@ -366,7 +368,9 @@ inline void swiftnet_send_packet(

memcpy(buffer_header_location, temp_data_buffer, prepend_size + PACKET_HEADER_SIZE);

#ifndef DISABLE_DYNAMIC_RATE_LIMITING
usleep(atomic_load_explicit(&new_packet_sending->current_send_delay, memory_order_acquire));
#endif
}
}
} else {
Expand Down
10 changes: 9 additions & 1 deletion src/swift_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,22 @@ enum PacketType {
REQUEST_INFORMATION = 0x02,
SEND_LOST_PACKETS_REQUEST = 0x03,
SEND_LOST_PACKETS_RESPONSE = 0x04,
SUCCESSFULLY_RECEIVED_PACKET = 0x05,
SUCCESSFULLY_RECEIVED_PACKET = 0x05,
#ifndef DISABLE_DYNAMIC_RATE_LIMITING
PACKET_DELAY_UPDATE = 0x06,
#endif
#ifdef SWIFT_NET_REQUESTS
REQUEST = 0x07,
RESPONSE = 0x08,
#endif
};

#ifndef DISABLE_DYNAMIC_RATE_LIMITING
enum PacketDelayUpdateStatus {
LOWER_DELAY,
INCREASE_DELAY
};
#endif

#define PACKET_INFO_ID_NONE 0xFFFF

Expand Down Expand Up @@ -126,8 +130,10 @@ struct SwiftNetPendingMessage {
uint8_t* packet_data_start;
uint32_t chunks_received_length;
uint32_t chunks_received_number;
#ifndef DISABLE_DYNAMIC_RATE_LIMITING
uint32_t last_index_checked;
uint32_t last_chunks_received_number;
#endif
uint16_t source_port;
uint16_t packet_id;
bool sending_lost_packets;
Expand Down Expand Up @@ -156,7 +162,9 @@ enum PacketSendingUpdated {
struct SwiftNetPacketSending {
uint32_t* lost_chunks;
_Atomic enum PacketSendingUpdated updated;
#ifndef DISABLE_DYNAMIC_RATE_LIMITING
_Atomic uint32_t current_send_delay;
#endif
uint32_t lost_chunks_size;
uint16_t packet_id;
_Atomic bool locked;
Expand Down
Loading