Skip to content
Extraits de code Groupes Projets
receiver_utils.h 1,98 ko
Newer Older
  • Learn to ignore specific revisions
  • /**
     * @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 "utils.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 */
    
    #define RECV_MAX_SLCTV_RPT_WDW 31
    #define TWO_EXP_EIGHT 256
    
    Vany Ingenzi's avatar
    Vany Ingenzi a validé
    #define TIMER_MULTIPLIER_BY_1 1
    #define TIMER_MULTIPLIER_BY_2 2
    
    #define RECEIVER_INACTIVE_TIMEOUT 20
    
    Vany Ingenzi's avatar
    Vany Ingenzi a validé
    #define FEC_CALCULATED_ON 4
    
    
    /* Represent the receiver's connection state */
    typedef struct __attribute__((__packed__))
    {
    
        uint8_t curr_recv_window;
        uint8_t recv_window_start;        
    
    Vany Ingenzi's avatar
    Vany Ingenzi a validé
        uint32_t latest_timestamp;
    
        pkt_t * recvd_data_buf[TWO_EXP_EIGHT]; 
    
        pkt_t * ack_to_send;
        pkt_t * nack_to_send[RECV_MAX_SLCTV_RPT_WDW];
    
    Vany Ingenzi's avatar
    Vany Ingenzi a validé
        uint8_t transfer_done;
    
    Vany Ingenzi's avatar
    Vany Ingenzi a validé
        uint16_t last_packet;
    
    Vany Ingenzi's avatar
    Vany Ingenzi a validé
        uint16_t next_to_consume;
    
     * @brief Loop reading on socket and printing to the stdout
    
    Vany Ingenzi's avatar
    Vany Ingenzi a validé
     * @param sfd : The socket file descriptor. It is both bound and connected.
    
     * @param pathname: Pathname to where write the stats.
     * 
     * @returns As soon as an error occurs or, the total transfer came through.
    
    void receiver_read_write_loop(int sfd, const char * pathname);
    
     * Creates and initialize a receiver_state_t structure
    
     * @return: a valid pointer upon success, else NULL
     */
    
    receiver_state_t * state_new();
    
     * Deletes the receiver_state_t structure pointed by the
    
    Vany Ingenzi's avatar
    Vany Ingenzi a validé
     * @param state: the state to delete.
    
    void state_del(receiver_state_t * state);