// This is the main file of the Dazibao project. It represents the node, and // handles all of the main logic, including the network connexions. // Will return a packet when we receive one that's valid. 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){ } void work_with_tlvs(struct tlvs_list receivied_tlvs){ // For every TLV, // We make sure the TLV is legal. if(!validate_tlvs(tlv)){ perror(">> Invalid TLV receivied, it will be ignored."); } // Switch // TLV Network Hash // We calculate a network hash, // We compare both, // If they differ, we send a TLV Network State Request // back to the sender. // TLV Network State Request // We check our neighbourhood, and for each peer, we send back // to the sender a TLV Node Hash // TLV Node hash // We get a hash _h_ for the node _l_ // If we don't have an entry for _l_, or if we have the same one as the // on we just receivied, we send out a TLV Node State Request back. // TLV Node State // We get a hash _h_, sequence number _s_, data _d_ for node _l_. // We compute a network hash, // We compare the hash, if they differ, then with l',s',d' our data and // h' the corresponding hash, // if _l_ is our own node id, then // if s >> s' then we update our sequence number to s ⊕ 1 mod 2^16 // If it's another's node id, then // If there is no entry for the sender, // we store the entry in our data table. } int main(int argc, char const *argv[]) { int continue = 1; while(continue){ // We create the neighbourhood table neighbour_peer neighbour_list[NEIGHBOUR_MAX]; // 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(); 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; }