Refactoring
[oweals/gnunet.git] / src / dht / gnunet-service-xdht_routing.h
1 /*
2      This file is part of GNUnet.
3      (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 /**
35  * Add a new entry to our routing table.
36  * @param source peer Source of the trail.
37  * @param destintation Destination of the trail.
38  * @param next_hop Next peer to forward the message to reach the destination.
39  * @return GNUNET_YES
40  *         GNUNET_SYSERR If the number of routing entries crossed thershold.
41  */
42 int
43 GDS_ROUTING_add (const struct GNUNET_PeerIdentity *source,
44                  const struct GNUNET_PeerIdentity *dest,
45                  const struct GNUNET_PeerIdentity *next_hop,
46                  const struct GNUNET_PeerIdentity *prev_hop);
47
48
49 /**
50  * Iterate over routing table and remove entries for which peer is a part. 
51  * @param peer
52  * @return 
53  */
54 void
55 GDS_ROUTING_remove_entry (const struct GNUNET_PeerIdentity *peer);
56
57
58 /**
59  * Search the next hop to send the packet to in routing table.
60  * @return next hop peer id
61  */
62 struct GNUNET_PeerIdentity *
63 GDS_ROUTING_search(struct GNUNET_PeerIdentity *source_peer,
64                    struct GNUNET_PeerIdentity *destination_peer,
65                    const struct GNUNET_PeerIdentity *prev_hop);
66
67 /**
68  * FIXME: How to ensure that with only 3 fields also we have a unique trail.
69  * in case of redundant routes we can have different next hop.
70  * in that case we have to call this function on each entry of routing table
71  * and from multiple next hop we return one. Here also we are going to return one.
72  * URGENT. 
73  * Assumption - there can be only on one trail with all these fields. But if
74  * we consider only 3 fields then it is possible that next hop is differet. 
75  * Update prev_hop field to source_peer. Trail from source peer to destination
76  * peer is compressed such that I am the first friend in the trail. 
77  * @param source_peer Source of the trail.
78  * @param destination_peer Destination of the trail.
79  * @param prev_hop Peer before me in the trail.
80  * @return #GNUNET_YES trail is updated.
81  *         #GNUNET_NO, trail not found. 
82  */
83 int
84 GDS_ROUTING_trail_update (struct GNUNET_PeerIdentity *source_peer,
85                           struct GNUNET_PeerIdentity *destination_peer,
86                           const struct GNUNET_PeerIdentity *prev_hop);
87
88
89 /**
90  * Remove the trail as result of trail tear down message. 
91  * @param source_peer Source of the trail.
92  * @param destination_peer Destination of the trail.
93  * @param next_hop Next hop
94  * @param prev_hop Previous hop. 
95  * @return #GNUNET_YES if successful
96  *         #GNUNET_NO if not successful. 
97  */
98 int
99 GDS_ROUTING_remove_trail (struct GNUNET_PeerIdentity *source_peer,
100                           struct GNUNET_PeerIdentity *destination_peer, 
101                           const struct GNUNET_PeerIdentity *prev_hop);
102
103 /**
104  * Check if size of routing table is greater than threshold or not. 
105  */
106 int
107 GDS_ROUTING_check_threshold (void);
108
109 /**
110  * Initialize routing subsystem.
111  */
112 void
113 GDS_ROUTING_init (void);
114
115
116 /**
117  * Shutdown routing subsystem.
118  */
119 void
120 GDS_ROUTING_done (void);
121
122 #endif