More API function tests...
[oweals/gnunet.git] / src / dht / gnunet-service-xdht_routing.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2011 - 2014 GNUnet e.V.
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @file dht/gnunet-service-xdht_routing.h
23  * @brief GNUnet DHT tracking of requests for routing replies
24  * @author Christian Grothoff
25  */
26 #ifndef GNUNET_SERVICE_XDHT_ROUTING_H
27 #define GNUNET_SERVICE_XDHT_ROUTING_H
28
29 #include "gnunet_util_lib.h"
30 #include "gnunet_block_lib.h"
31 #include "gnunet_dht_service.h"
32
33 /**
34  * To understand the direction in which trial should be read. 
35  */
36 enum GDS_ROUTING_trail_direction 
37 {
38   GDS_ROUTING_SRC_TO_DEST,
39   GDS_ROUTING_DEST_TO_SRC
40 };
41
42
43 /**
44  * Update the prev. hop of the trail. Call made by trail teardown where
45  * if you are the first friend now in the trail then you need to update
46  * your prev. hop.
47  * @param trail_id
48  * @return #GNUNET_OK success
49  *         #GNUNET_SYSERR in case no matching entry found in routing table. 
50  */
51 int
52 GDS_ROUTING_update_trail_prev_hop (const struct GNUNET_HashCode *trail_id,
53                                    const struct GNUNET_PeerIdentity *prev_hop);
54
55
56 /**
57  * Update the next hop of the trail. Call made by trail compression where
58  * if you are source of the trail and now you have a new first friend, then
59  * you should update the trail. 
60  * @param trail_id
61  * @return #GNUNET_OK success
62  *         #GNUNET_SYSERR in case no matching entry found in routing table.
63  */
64 int
65 GDS_ROUTING_update_trail_next_hop (const struct GNUNET_HashCode *trail_id,
66                                    const struct GNUNET_PeerIdentity *next_hop);
67
68 /**
69  * Get the next hop for trail corresponding to trail_id
70  * @param trail_id Trail id to be searched. 
71  * @return Next_hop if found
72  *         NULL If next hop not found. 
73  */
74 const struct GNUNET_PeerIdentity *
75 GDS_ROUTING_get_next_hop (const struct GNUNET_HashCode *trail_id,
76                           enum GDS_ROUTING_trail_direction trail_direction);
77
78
79 /**
80  * Remove every trail where peer is either next_hop or prev_hop 
81  * @param peer Peer to be searched.
82  */
83 int
84 GDS_ROUTING_remove_trail_by_peer (const struct GNUNET_PeerIdentity *peer);
85
86
87 /**
88  * Remove trail with trail_id
89  *
90  * @param trail_id Trail id to be removed
91  * @return #GNUNET_YES success 
92  *         #GNUNET_NO if entry not found.
93  */
94 int
95 GDS_ROUTING_remove_trail (const struct GNUNET_HashCode *remove_trail_id);
96
97
98 /**
99  * Add a new entry in routing table
100  * @param new_trail_id
101  * @param prev_hop
102  * @param next_hop
103  * @return #GNUNET_OK success
104  *         #GNUNET_SYSERR in case new_trail_id already exists in the network
105  *                         but with different prev_hop/next_hop
106  */
107 int
108 GDS_ROUTING_add (const struct GNUNET_HashCode *new_trail_id, 
109                  const struct GNUNET_PeerIdentity *prev_hop,
110                  const struct GNUNET_PeerIdentity *next_hop);
111
112
113 /**
114  * Check if the size of routing table has crossed threshold. 
115  * @return #GNUNET_YES, if threshold crossed 
116  *         #GNUNET_NO, if size is within threshold 
117  */
118 int
119 GDS_ROUTING_threshold_reached (void);
120
121 #if 0
122 /**
123  * Test function. Remove afterwards. 
124  */
125 void 
126 GDS_ROUTING_test_print (void);
127 #endif
128
129 /**
130  * Initialize routing subsystem.
131  */
132 void
133 GDS_ROUTING_init (void);
134
135 /**
136  * Shutdown routing subsystem.
137  */
138 void
139 GDS_ROUTING_done (void);
140
141 #endif