Added new structures for the messages, the neighbours, and broke line

feed for a comment
This commit is contained in:
n07070 2020-03-24 13:25:18 +01:00
parent 35d50d178a
commit fafebaa32f
3 changed files with 47 additions and 8 deletions

View File

@ -7,9 +7,10 @@ packet listen_for_packets(){
} }
// We need to make sure the TLV announces a length that will no go onto
// another tlv, as we might end up reading bullshit.
int validate_tlvs(union tlv tlv_to_validate){ int validate_tlvs(union tlv tlv_to_validate){
// We need to make sure the TLV announces a length that will no go onto
// another tlv, as we might end up reading bullshit.
} }
void work_with_tlvs(struct tlvs_list receivied_tlvs){ void work_with_tlvs(struct tlvs_list receivied_tlvs){
@ -17,7 +18,7 @@ void work_with_tlvs(struct tlvs_list receivied_tlvs){
// For every TLV, // For every TLV,
// We make sure the TLV is legal. // We make sure the TLV is legal.
if(!validate_tlvs(tlv)){ if(!validate_tlvs(tlv)){
perror(">> Invalid TLV receivied, is will be ignored."); perror(">> Invalid TLV receivied, it will be ignored.");
} }
// Switch // Switch
@ -52,11 +53,14 @@ void work_with_tlvs(struct tlvs_list receivied_tlvs){
} }
int main(int argc, char const *argv[]) { int main(int argc, char const *argv[]) {
int continue = 1;
while(CONTINUE){ while(continue){
// We create the neighbourhood table // We create the neighbourhood table
neighbour_peer neighbour_list[NEIGHBOUR_MAX];
// We create the message table // We create the message table
// We create our own message. // We create our own message.
// Listen for incoming packets // Listen for incoming packets

View File

@ -3,6 +3,40 @@
#ifndef NODE_H #ifndef NODE_H
#define NODE_H #define NODE_H
// 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
*/
typedef struct message {
long node_id_publisher;
short seqno;
char *data;
} message;
// TODO
// fonctions signatures // fonctions signatures
void listen_for_packets(); void listen_for_packets();

View File

@ -10,7 +10,8 @@ cmd_token parse_cmd() {
if(fgets(buf, 198, stdin) == NULL) if(fgets(buf, 198, stdin) == NULL)
return token; return token;
// cmd sera le premier mot rencontré et arg la suite de mots après celui ci, si les deux variables ne sont pas remplies alors il y a une erreur // cmd sera le premier mot rencontré et arg la suite de mots après celui ci,
// si les deux variables ne sont pas remplies alors il y a une erreur
if(sscanf(buf, "%s %[^\t\n]", cmd, arg) != 2) if(sscanf(buf, "%s %[^\t\n]", cmd, arg) != 2)
return token; return token;