Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fb49c098732e604b609ef0bc6c9d0e4891897250
[simgrid.git] / examples / deprecated / msg / dht-kademlia / node.h
1 /* Copyright (c) 2012-2019. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef _MSG_EXAMPLES_ROUTING_H
8 #define _MSG_EXAMPLES_ROUTING_H
9 #include "xbt/dynar.h"
10 #include "simgrid/msg.h"
11
12 #include "common.h"
13 #include "answer.h"
14 #include "routing_table.h"
15
16 /* Information about a foreign node */
17 typedef struct s_node_contact {
18   unsigned int id;              //The node identifier
19   unsigned int distance;        //The distance from the node
20 } s_node_contact_t;
21
22 typedef s_node_contact_t *node_contact_t;
23 typedef const s_node_contact_t* const_node_contact_t;
24
25 /* Node data */
26 typedef struct s_node {
27   unsigned int id;              //node id - 160 bits
28   routing_table_t table;        //node routing table
29   msg_comm_t receive_comm;      //current receiving communication.
30   msg_task_t task_received;     //current task being received
31
32   char mailbox[MAILBOX_NAME_SIZE];      //node mailbox
33   unsigned int find_node_success;       //Number of find_node which have succeeded.
34   unsigned int find_node_failed;        //Number of find_node which have failed.
35
36 } s_node_t;
37
38 typedef s_node_t *node_t;
39 typedef const s_node_t* const_node_t;
40
41 // node functions
42 node_t node_init(unsigned int id);
43 void node_free(node_t node);
44 void node_routing_table_update(const_node_t node, unsigned int id);
45 answer_t node_find_closest(const_node_t node, unsigned int destination_id);
46
47 // identifier functions
48 unsigned int get_id_in_prefix(unsigned int id, unsigned int prefix);
49 unsigned int get_node_prefix(unsigned int id, unsigned int nb_bits);
50 void get_node_mailbox(unsigned int id, char *mailbox);
51
52 // node contact functions
53 node_contact_t node_contact_new(unsigned int id, unsigned int distance);
54 node_contact_t node_contact_copy(const_node_contact_t node_contact);
55 void node_contact_free(node_contact_t contact);
56 #endif                          /* _MSG_EXAMPLES_ROUTING_H */