Logo AND Algorithmique Numérique Distribuée

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