Ajout de node.c, de la structure du code et des notes.
This commit is contained in:
parent
10c3893f37
commit
62b01d973f
8
Notes.md
8
Notes.md
@ -1 +1,9 @@
|
|||||||
# Notes et recherches sur le projet
|
# Notes et recherches sur le projet
|
||||||
|
|
||||||
|
Arithétique et ordres modulo
|
||||||
|
|
||||||
|
s ⊕ n = (s+n) % 2^(16)
|
||||||
|
s ⊕ n = (s + n) and 65535
|
||||||
|
|
||||||
|
s ≼ s ′ lorsque ((s ′ − s) mod 2 16 ) < 32768
|
||||||
|
s ≼ s ′ lorsque ((s ′ − s) and 32768) = 0
|
||||||
|
85
src/node.c
Normal file
85
src/node.c
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
// 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(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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){
|
||||||
|
|
||||||
|
// For every TLV,
|
||||||
|
// We make sure the TLV is legal.
|
||||||
|
if(!validate_tlvs(tlv)){
|
||||||
|
perror(">> Invalid TLV receivied, is 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[]) {
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user