From f625058a3c3ec33d767bbcd6094fbe0010b4cd6c Mon Sep 17 00:00:00 2001 From: N07070 Date: Fri, 13 Mar 2020 14:46:24 +0100 Subject: [PATCH] Modifications pour faire le message toutes les 20 secondes --- src/node.c | 55 +++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/node.c b/src/node.c index 4c7bc7c..fdfb6fe 100644 --- a/src/node.c +++ b/src/node.c @@ -53,33 +53,38 @@ void work_with_tlvs(struct tlvs_list receivied_tlvs){ int main(int argc, char const *argv[]) { - // We create the neighbourhood table - // We create the message table - // We create our own message. + while(CONTINUE){ - // Listen for incoming packets - listen_for_packets(); - // For every packet recivied, we fork, - // then we make sure it's conform - // We then extract the data from it to make it easy to work with - check_header(); - // If the sender is not in the neighbourhood, and we have 15 neighbours, we - // ignore the packet. Otherwise, we add him to the neighbourhood, marked as - // temporary. - update_neighbours(); - // We then look at the differents TLVs in the packet. - work_with_tlvs(); + // We create the neighbourhood table + // We create the message table + // We create our own message. + // Listen for incoming packets + listen_for_packets(); + // For every packet recivied, we fork, + // then we make sure it's conform + // We then extract the data from it to make it easy to work with + check_header(); + // If the sender is not in the neighbourhood, and we have 15 neighbours, we + // ignore the packet. Otherwise, we add him to the neighbourhood, marked as + // temporary. + update_neighbours(); + // We then look at the differents TLVs in the packet. + work_with_tlvs(); - // Theses functions are there for general book-keeping,and run in there own - // thread, being run every 20 seconds. - // Every 20 sec, if we have less than 5 neighbours, we ask for more peers - // by sending out a TLV neighbour Request at a random peer. - t_ask_for_more_peers(); - // Every 20 sec, we also check for a peer that didn't emit a new message for - // the past 70 sec, if he's temporary, we delete him from the neighbourhood. - t_update_neighbours(); - // We send out a TLV Network hash to get an ideal of the network state. - t_get_network_state(); + time_t delay = time(NULL) + 20; + while(! (delay < time(NULL)){ + // Theses functions are there for general book-keeping,and run in there own + // thread, being run every 20 seconds. + // Every 20 sec, if we have less than 5 neighbours, we ask for more peers + // by sending out a TLV neighbour Request at a random peer. + t_ask_for_more_peers(); + // Every 20 sec, we also check for a peer that didn't emit a new message for + // the past 70 sec, if he's temporary, we delete him from the neighbourhood. + t_update_neighbours(); + // We send out a TLV Network hash to get an ideal of the network state. + t_get_network_state(); + } + } return 0; }