Commit 7a1cf723 authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Replaced constants for header sizes with sizeof operator.

parent 275ffc5d
......@@ -69,7 +69,7 @@ int PrrtBlock_insert_data_packet(PrrtBlock *block_ptr, const PrrtPacket *packet_
int PrrtBlock_insert_redundancy_packet(PrrtBlock *block_ptr, const PrrtPacket *ptr) {
List_push(block_ptr->redundancy_blocks, ptr);
block_ptr->redundancy_count++;
block_ptr->largest_data_length = MAX(block_ptr->largest_data_length, ptr->payload_len - PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
block_ptr->largest_data_length = (uint32_t) MAX(block_ptr->largest_data_length, ptr->payload_len - PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
return 0;
}
......
......@@ -353,7 +353,7 @@ int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, cons
packet_ptr->index = 0;
packet_ptr->seqno = seqno;
void *content_buf = calloc(1, sizeof(PrrtPacketDataPayload) + data_len);
void *content_buf = calloc(1, payload_length);
check_mem(content_buf);
PrrtPacketDataPayload *source_payload = content_buf;
......@@ -379,7 +379,7 @@ int PrrtPacket_create_data_packet(PrrtPacket *packet_ptr, uint8_t priority, cons
PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *data_ptr, uint32_t data_len,
uint16_t seqno, uint8_t index, uint16_t base_seqno,
PrrtCodingParams codingParams) {
uint32_t payload_length = (uint32_t) (data_len + sizeof(PrrtPacketRedundancyPayload));
uint32_t payload_length = (uint32_t) (data_len + PRRT_PACKET_REDUNDANCY_HEADER_SIZE);
PrrtPacket *packet_ptr = calloc(1, sizeof(PrrtPacket));
check_mem(packet_ptr);
......@@ -389,7 +389,7 @@ PrrtPacket *PrrtPacket_create_redundancy_packet(uint8_t priority, void *data_ptr
packet_ptr->index = index;
packet_ptr->seqno = seqno;
void *content_buf = calloc(1, sizeof(PrrtPacketRedundancyPayload) + data_len);
void *content_buf = calloc(1, PRRT_PACKET_REDUNDANCY_HEADER_SIZE + data_len);
check_mem(content_buf);
PrrtPacketRedundancyPayload *redundancy_payload = content_buf;
......@@ -420,7 +420,7 @@ PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, u
packet_ptr->index = index;
packet_ptr->seqno = seqno;
PrrtPacketFeedbackPayload *payload = calloc(1, sizeof(PrrtPacketFeedbackPayload));
PrrtPacketFeedbackPayload *payload = calloc(1, PRRT_PACKET_FEEDBACK_HEADER_SIZE);
check_mem(payload);
payload->group_round_trip_time = round_trip_time;
......@@ -434,7 +434,7 @@ PrrtPacket *PrrtPacket_create_feedback_packet(uint8_t priority, uint8_t index, u
payload->buffer_feedback = buffer_feedback;
packet_ptr->payload = (void *) payload;
packet_ptr->payload_len = (uint32_t) (sizeof(PrrtPacketFeedbackPayload));
packet_ptr->payload_len = (uint32_t) (PRRT_PACKET_FEEDBACK_HEADER_SIZE);
return packet_ptr;
......
......@@ -16,7 +16,6 @@
#define PACKET_TYPE_PRE_REDUNDANCY 4
#define PACKET_TYPE_CHANNEL_FEEDBACK 5
#define PRRT_PACKET_GENERAL_HEADER_SIZE 4
typedef struct {
uint8_t type_priority;
uint8_t index;
......@@ -24,10 +23,10 @@ typedef struct {
void* payload;
uint32_t payload_len;
} PrrtPacket;
#define PRRT_PACKET_GENERAL_HEADER_SIZE sizeof(PrrtPacket) - sizeof(uint32_t) - sizeof(void*)
#define SEQNO_SPACE 65536 // 2**16 as seqno is uint16_t
#define PRRT_PACKET_DATA_HEADER_SIZE 12
typedef struct {
uint32_t timestamp;
uint16_t group_round_trip_time;
......@@ -35,15 +34,15 @@ typedef struct {
uint16_t decoding_timeout;
uint16_t feedback_timeout;
} PrrtPacketDataPayload;
#define PRRT_PACKET_DATA_HEADER_SIZE sizeof(PrrtPacketDataPayload)
#define PRRT_PACKET_REDUNDANCY_HEADER_SIZE 4
typedef struct {
uint16_t base_seqno;
uint8_t n;
uint8_t k;
} PrrtPacketRedundancyPayload;
#define PRRT_PACKET_REDUNDANCY_HEADER_SIZE sizeof(PrrtPacketRedundancyPayload)
# define PRRT_PACKET_FEEDBACK_HEADER_SIZE 32
typedef struct {
uint32_t receiver_addr;
uint32_t group_round_trip_time;
......@@ -56,6 +55,7 @@ typedef struct {
uint32_t bandwidth_estimate;
uint32_t buffer_feedback;
} PrrtPacketFeedbackPayload;
#define PRRT_PACKET_FEEDBACK_HEADER_SIZE sizeof(PrrtPacketFeedbackPayload)
uint8_t PrrtPacket_type(PrrtPacket *packet_ptr);
uint8_t PrrtPacket_priority(PrrtPacket *packet_ptr);
......
......@@ -29,7 +29,6 @@ void decode_block(const PrrtSocket *sock_ptr, uint16_t base_seqno) {
LIST_FOREACH(block->data_blocks, first, next, cur) {
PrrtPacket *pkt = cur->value;
if (PrrtForwardPacketTable_test_set_is_number_relevant(sock_ptr->forwardPacketTable, pkt->seqno)) {
printf("RECOVERED %d via coding.\n", pkt->seqno);
pthread_mutex_lock(&sock_ptr->inQueueFilledMutex);
List_push(sock_ptr->inQueue, pkt);
pthread_cond_signal(&sock_ptr->inQueueFilledMutexCv);
......@@ -39,7 +38,10 @@ void decode_block(const PrrtSocket *sock_ptr, uint16_t base_seqno) {
}
}
int send_feedback(const PrrtSocket *sock_ptr, const char *remote_host, const int remote_port) {
int send_feedback(const PrrtSocket *sock_ptr, struct sockaddr_in remote) {
uint16_t remote_port = ntohs(remote.sin_port);
char *remote_host = inet_ntoa(remote.sin_addr);
struct sockaddr_in targetaddr;
memset((char *) &targetaddr, 0, sizeof(targetaddr));
targetaddr.sin_family = AF_INET;
......@@ -66,8 +68,6 @@ int send_feedback(const PrrtSocket *sock_ptr, const char *remote_host, const int
void receive_data_loop(void *ptr) {
ssize_t n;
uint16_t remote_port;
char *remote_host;
struct sockaddr_in remote;
socklen_t addrlen = sizeof(remote);
unsigned char buffer[MAX_PAYLOAD_LENGTH];
......@@ -79,15 +79,13 @@ void receive_data_loop(void *ptr) {
while (1) {
memset(buffer, 0, MAX_PAYLOAD_LENGTH);
n = recvfrom(sock_ptr->dataSocketFd, buffer, MAX_PAYLOAD_LENGTH, 0, (struct sockaddr *) &remote, &addrlen);
remote_port = ntohs(remote.sin_port);
remote_host = inet_ntoa(remote.sin_addr);
check(send_feedback(sock_ptr, remote) == EXIT_SUCCESS, "Sending feedback failed.");
packet = calloc(1, sizeof(PrrtPacket));
check_mem(packet);
PrrtPacket_decode(buffer, (uint16_t) n, packet);
check(send_feedback(sock_ptr, remote_host, remote_port) == EXIT_SUCCESS, "Sending feedback failed.");
switch (PrrtPacket_type(packet)) {
case PACKET_TYPE_DATA:
// packet.timestamp + packet.timeout < now: break
......@@ -143,6 +141,8 @@ void receive_data_loop(void *ptr) {
}
}
// TODO: occasionally clean up dataStore and blockStore !!!
error:
free(packet);
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment