Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
1f0a677082652d7fb504dd3987aee5094f51c2a0
[simgrid.git] / examples / msg / dht-kademlia / routing_table.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_KADEMLIA_EXAMPLES_ROUTING_TABLE
8 #define _MSG_KADEMLIA_EXAMPLES_ROUTING_TABLE
9 #include "common.h"
10 #include <xbt/dynar.h>
11
12 /* Routing table bucket */
13 typedef struct s_bucket {
14   xbt_dynar_t nodes;            //Nodes in the bucket.
15   unsigned int id;              //bucket id
16 } s_bucket_t;
17
18 typedef s_bucket_t *bucket_t;
19
20 /* Node routing table */
21 typedef struct s_routing_table {
22   unsigned int id;              //node id of the client's routing table
23   s_bucket_t *buckets;          //Node bucket list - 160 sized.
24 } s_routing_table_t;
25
26 typedef s_routing_table_t *routing_table_t;
27
28 // bucket functions
29 unsigned int bucket_find_id(bucket_t bucket, unsigned int id);
30 unsigned int bucket_contains(bucket_t bucket, unsigned int id);
31
32 // routing table functions
33 routing_table_t routing_table_init(unsigned int node_id);
34 void routing_table_free(routing_table_t table);
35 unsigned int routing_table_contains(routing_table_t table, unsigned int node_id);
36 void routing_table_print(routing_table_t table);
37 bucket_t routing_table_find_bucket(routing_table_t table, unsigned int id);
38
39 #endif                          /* _MSG_KADEMLIA_EXAMPLES_ROUTING_TABLE */