dazibao/src/node.h

78 lines
1.7 KiB
C
Raw Normal View History

2020-03-13 14:46:06 +01:00
// Define constants
2020-03-24 12:24:56 +01:00
#ifndef NODE_H
#define NODE_H
2020-03-13 14:46:06 +01:00
2020-03-24 18:19:35 +01:00
#include "tlv.h"
2020-03-31 15:57:31 +02:00
#include "misc.h"
2020-03-24 18:19:35 +01:00
// On which port do we listen to
#define LISTEN_PORT 1212
// The node ID
#define NODE_ID 203242402519736214145149136169422092269247115186189140178187251487819615911212154252117172522111472481308026129190139512419121015210238252292031613214452118122204415160254
// The number of neighbours
// The neighbour table has 15 entries
#define NEIGHBOUR_MAX 15
/* la table de voisins, qui est indexée par adresses de socket (des paires (IP, Port)),
* et dont chaque entrée contient un booléen indiquant si le pair est permanent
* (configuré au lancement) ou transitoire, et la date de dernière réception dun
* paquet de la part de ce pair ;
*/
typedef struct neighbour_peer {
struct in6_addr ip;
short port;
char is_temporary;
struct timeval last_seen;
} neighbour_peer;
// The strucuture to hold the messages
/* It's a list of triplets, (Li,Si,Di)
* Li : The Node ID of the publisher 64 bits
* Si : the sequence number 16 bits
* Di : the data of the message 192 bytes
*/
2020-03-31 15:57:31 +02:00
typedef struct pub_data {
unsigned char length;
long id;
short seqno;
char *data;
2020-03-31 15:57:31 +02:00
} pub_data;
// static lists
static list *data_list;
static list *neighbour_list;
// TODO
2020-03-13 14:46:06 +01:00
// fonctions signatures
void listen_for_packets();
2020-03-24 18:19:35 +01:00
int check_header(char * received_datagram[], int len, packet pack);
2020-03-13 14:46:06 +01:00
2020-03-24 18:19:35 +01:00
int update_neighbours();
2020-03-13 14:46:06 +01:00
2020-03-31 15:57:31 +02:00
int validate_tlv(unsigned char *data, int pos);
2020-03-13 14:46:06 +01:00
void work_with_tlvs();
2020-03-31 15:57:31 +02:00
void add_tlv(packet *packet, tlv *tlv, char type);
2020-03-13 14:46:06 +01:00
// threaded functions
void t_ask_for_more_peers();
void t_update_neighbours();
void t_get_network_state();
// Helper functions
char * hash();
short * get_seq_no(short s, int n);
2020-03-24 12:24:56 +01:00
#endif