Start implementation of some functions.
[oweals/gnunet.git] / src / dht / gnunet-service-xdht_routing.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2011 - 2014 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, 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 (struct GNUNET_HashCode trail_id,
53                                    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                                    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 struct GNUNET_PeerIdentity *
75 GDS_ROUTING_get_next_hop (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  * Remove trail with trail_id
87  * @param trail_id Trail id to be removed
88  * @return #GNUNET_YES success 
89  *         #GNUNET_NO if entry not found.
90  */
91 int
92 GDS_ROUTING_remove_trail (struct GNUNET_HashCode remove_trail_id);
93
94
95 /**
96  * Add a new entry in routing table
97  * @param new_trail_id
98  * @param prev_hop
99  * @param next_hop
100  * @return #GNUNET_OK success
101  *         #GNUNET_SYSERR in case new_trail_id already exists in the network
102  *                         but with different prev_hop/next_hop
103  */
104 int
105 GDS_ROUTING_add (struct GNUNET_HashCode new_trail_id, 
106                  struct GNUNET_PeerIdentity prev_hop,
107                  struct GNUNET_PeerIdentity next_hop);
108
109
110 /**
111  * Check if the size of routing table has crossed threshold. 
112  * @return #GNUNET_YES, if threshold crossed 
113  *         #GNUNET_NO, if size is within threshold 
114  */
115 int
116 GDS_ROUTING_threshold_reached (void);
117
118 #if 0
119 /**
120  * Test function. Remove afterwards. 
121  */
122 void 
123 GDS_ROUTING_test_print (void);
124 #endif
125
126 /**
127  * Initialize routing subsystem.
128  */
129 void
130 GDS_ROUTING_init (void);
131
132 /**
133  * Shutdown routing subsystem.
134  */
135 void
136 GDS_ROUTING_done (void);
137
138 #endif