Modified signature for t_* functions, run_node and bootstrap_node
This commit is contained in:
parent
03e5b69553
commit
d6a2ca7c3b
40
src/node.c
40
src/node.c
@ -718,19 +718,19 @@ int listen_for_packets(char * received_data_buffer[], int received_data_len, str
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int t_ask_for_more_peers(){
|
int t_ask_for_more_peers(list * neighbourhood, int sock_fd){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int t_get_network_state(){
|
int t_get_network_state(list * neighbourhood, int sock_fd){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int t_update_neighbours(){
|
int t_update_neighbours(list * neighbourhood){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int run_node(int sock_fd){
|
int run_node(int sock_fd, list * neighbourhood){
|
||||||
printf(">> Running node...\n");
|
printf(">> Running node...\n");
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
@ -756,11 +756,11 @@ int run_node(int sock_fd){
|
|||||||
|
|
||||||
if (time(NULL) >= delay) {
|
if (time(NULL) >= delay) {
|
||||||
printf(">> Asking for more peers...\n");
|
printf(">> Asking for more peers...\n");
|
||||||
t_ask_for_more_peers();
|
t_ask_for_more_peers(neighbourhood, sock_fd);
|
||||||
printf(">> Updating neighbours...\n");
|
printf(">> Updating neighbours...\n");
|
||||||
t_update_neighbours();
|
t_update_neighbours(neighbourhood);
|
||||||
printf(">> Getting network state...\n");
|
printf(">> Getting network state...\n");
|
||||||
t_get_network_state();
|
t_get_network_state(neighbourhood, sock_fd);
|
||||||
delay = time(NULL) + 20 + (rand() % 10);
|
delay = time(NULL) + 20 + (rand() % 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -848,7 +848,9 @@ int run_node(int sock_fd){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bootstrap_node(int * sock_fd){
|
|
||||||
|
// This function runs once, and sets the sock_fd as well as the neighbourhood
|
||||||
|
int bootstrap_node(int * sock_fd, list * neighbourhood){
|
||||||
printf(">> Boostraping node...\n");
|
printf(">> Boostraping node...\n");
|
||||||
|
|
||||||
struct sockaddr_in6 server_addr;
|
struct sockaddr_in6 server_addr;
|
||||||
@ -870,6 +872,22 @@ int bootstrap_node(int * sock_fd){
|
|||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Make the first peer*/
|
||||||
|
struct neighbour_peer root_peer;
|
||||||
|
struct timeval root_peer_seen;
|
||||||
|
|
||||||
|
int inet_p = inet_pton(AF_INET6, ROOT_PEER_ADDR, &root_peer.ip);
|
||||||
|
if(inet_p < 1){
|
||||||
|
perror(">> Failed to create the root peer.");
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
|
root_peer.port = 1212;
|
||||||
|
root_peer.is_temporary = 0;
|
||||||
|
root_peer.last_seen = root_peer_seen;
|
||||||
|
|
||||||
|
// TODO: Add the first peer to the neighbourhood
|
||||||
|
|
||||||
printf(">> Boostraping done.\n");
|
printf(">> Boostraping done.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -878,9 +896,11 @@ int bootstrap_node(int * sock_fd){
|
|||||||
int main(int argc, const char *argv[]) {
|
int main(int argc, const char *argv[]) {
|
||||||
printf(">> Starting node\n");
|
printf(">> Starting node\n");
|
||||||
|
|
||||||
|
list neighbourhood;
|
||||||
|
|
||||||
int sock_fd;
|
int sock_fd;
|
||||||
bootstrap_node(&sock_fd);
|
bootstrap_node(&sock_fd, &neighbourhood);
|
||||||
run_node(sock_fd);
|
run_node(sock_fd, &neighbourhood);
|
||||||
close(sock_fd);
|
close(sock_fd);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
11
src/node.h
11
src/node.h
@ -59,6 +59,9 @@ typedef struct list {
|
|||||||
// The neighbour table has 15 entries
|
// The neighbour table has 15 entries
|
||||||
#define NEIGHBOUR_MAX 15
|
#define NEIGHBOUR_MAX 15
|
||||||
|
|
||||||
|
// The adress of the main peer
|
||||||
|
#define ROOT_PEER_ADDR "2001:660:3301:9200::51c2:1b9b"
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
// fonctions signatures
|
// fonctions signatures
|
||||||
@ -79,7 +82,7 @@ int send_packet(char *packet_buff, int16_t length, struct sockaddr_in6 *dest, in
|
|||||||
int send_single_tlv(tlv *tlv, struct sockaddr_in6 *dest, int socket_num);
|
int send_single_tlv(tlv *tlv, struct sockaddr_in6 *dest, int socket_num);
|
||||||
|
|
||||||
// This function is in charge of saying how and what goes where.
|
// This function is in charge of saying how and what goes where.
|
||||||
int run_node(int sock_fd);
|
int run_node(int sock_fd, list * neighbourhood);
|
||||||
|
|
||||||
/* Takes a TLV and sends it over to everyone in the list of addresses.
|
/* Takes a TLV and sends it over to everyone in the list of addresses.
|
||||||
* Returns -1 in case of error, 0 otherwise.
|
* Returns -1 in case of error, 0 otherwise.
|
||||||
@ -94,7 +97,7 @@ int send_tlvs(struct list * tlv_list, int16_t length, struct sockaddr_in6 * dest
|
|||||||
/* Check our peer list. If we have less than 5 peers, send out a
|
/* Check our peer list. If we have less than 5 peers, send out a
|
||||||
TLV NEIGHBOUR_REQUEST to a random peer
|
TLV NEIGHBOUR_REQUEST to a random peer
|
||||||
*/
|
*/
|
||||||
int t_ask_for_more_peers(list * neighbourhood);
|
int t_ask_for_more_peers(list * neighbourhood, int sock_fd);
|
||||||
|
|
||||||
/* We look at every peer, if he is marked as is_temporary, AND we didn't get a
|
/* We look at every peer, if he is marked as is_temporary, AND we didn't get a
|
||||||
packet from him in the last 70 sec, we remove him from the list.
|
packet from him in the last 70 sec, we remove him from the list.
|
||||||
@ -104,14 +107,14 @@ int t_update_neighbours(list * neighbourhood);
|
|||||||
/* We send out a TLV Network Hash to every peer, and we expect getting a TLV
|
/* We send out a TLV Network Hash to every peer, and we expect getting a TLV
|
||||||
Network state from each of them.
|
Network state from each of them.
|
||||||
*/
|
*/
|
||||||
int t_get_network_state(list * neighbourhood);
|
int t_get_network_state(list * neighbourhoodn, int sock_fd);
|
||||||
|
|
||||||
// This function adds a message to the message table.
|
// This function adds a message to the message table.
|
||||||
int add_message(char * message, int message_len);
|
int add_message(char * message, int message_len);
|
||||||
|
|
||||||
// This functions creates the structures needed for the rest of the project,
|
// This functions creates the structures needed for the rest of the project,
|
||||||
// creates the socket, and returns all of it.
|
// creates the socket, and returns all of it.
|
||||||
int bootstrap_node(int * sock_fd);
|
int bootstrap_node(int * sock_fd, list * neighbourhood);
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
int len_list(list *l);
|
int len_list(list *l);
|
||||||
|
BIN
src/node.o
BIN
src/node.o
Binary file not shown.
Loading…
Reference in New Issue
Block a user