Newer
Older
/**
* @file receiver.h
* @brief This header contains all the structures and functions definitions that ae going to be used by the receiver.c
*/
#ifndef __RECEIVER_UTILS_
#define __RECEIVER_UTILS_
#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <poll.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <unistd.h>
#include "log.h"
#include "packet_interface.h"
/* We are using 8 bits to encode the seqnum therefore to fight redondance our window is of 2**(8)/2 */
Vany Ingenzi
a validé
#define RECV_MAX_SLCTV_RPT_WDW 31
#define TWO_EXP_EIGHT 256
#define RECEIVER_INACTIVE_TIMEOUT 20
/* Represent the receiver's connection state */
typedef struct __attribute__((__packed__))
{
Vany Ingenzi
a validé
uint8_t curr_recv_window;
uint8_t recv_window_start;
uint8_t last_received_in_order;
pkt_t * recvd_data_buf[TWO_EXP_EIGHT];
Vany Ingenzi
a validé
pkt_t * ack_to_send;
pkt_t * nack_to_send[RECV_MAX_SLCTV_RPT_WDW];
uint16_t last_data_packet;
Vany Ingenzi
a validé
transfer_stats_t * stats;
} receiver_state_t;
Vany Ingenzi
a validé
* @brief Loop reading on socket and printing to the stdout
* @param sfd : The socket file descriptor. It is both bound and connected.
Vany Ingenzi
a validé
* @param pathname: Pathname to where write the stats.
*
* @returns As soon as an error occurs or, the total transfer came through.
Vany Ingenzi
a validé
void receiver_read_write_loop(int sfd, const char * pathname);
Vany Ingenzi
a validé
/**
* Creates and initialize a receiver_state_t structure
Vany Ingenzi
a validé
* @return: a valid pointer upon success, else NULL
*/
receiver_state_t * state_new();
Vany Ingenzi
a validé
/**
* Deletes the receiver_state_t structure pointed by the
Vany Ingenzi
a validé
* state argument.
Vany Ingenzi
a validé
* @return: /
*/
void state_del(receiver_state_t * state);