paragraph for gnunet devs that don't know how to use the web
[oweals/gnunet.git] / src / dht / gnunet-service-dht_neighbours.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009, 2010, 2011 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @file dht/gnunet-service-dht_neighbours.h
21  * @brief GNUnet DHT routing code
22  * @author Christian Grothoff
23  * @author Nathan Evans
24  */
25 #ifndef GNUNET_SERVICE_DHT_NEIGHBOURS_H
26 #define GNUNET_SERVICE_DHT_NEIGHBOURS_H
27
28 #include "gnunet_util_lib.h"
29 #include "gnunet_block_lib.h"
30 #include "gnunet_dht_service.h"
31
32 /**
33  * Hash of the identity of this peer.
34  */
35 extern struct GNUNET_HashCode my_identity_hash;
36
37
38 /**
39  * Perform a PUT operation.  Forwards the given request to other
40  * peers.   Does not store the data locally.  Does not give the
41  * data to local clients.  May do nothing if this is the only
42  * peer in the network (or if we are the closest peer in the
43  * network).
44  *
45  * @param type type of the block
46  * @param options routing options
47  * @param desired_replication_level desired replication level
48  * @param expiration_time when does the content expire
49  * @param hop_count how many hops has this message traversed so far
50  * @param bf Bloom filter of peers this PUT has already traversed
51  * @param key key for the content
52  * @param put_path_length number of entries in put_path
53  * @param put_path peers this request has traversed so far (if tracked)
54  * @param data payload to store
55  * @param data_size number of bytes in data
56  * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
57  */
58 int
59 GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
60                            enum GNUNET_DHT_RouteOption options,
61                            uint32_t desired_replication_level,
62                            struct GNUNET_TIME_Absolute expiration_time,
63                            uint32_t hop_count,
64                            struct GNUNET_CONTAINER_BloomFilter *bf,
65                            const struct GNUNET_HashCode *key,
66                            unsigned int put_path_length,
67                            struct GNUNET_PeerIdentity *put_path,
68                            const void *data, size_t data_size);
69
70
71 /**
72  * Perform a GET operation.  Forwards the given request to other
73  * peers.  Does not lookup the key locally.  May do nothing if this is
74  * the only peer in the network (or if we are the closest peer in the
75  * network).
76  *
77  * @param type type of the block
78  * @param options routing options
79  * @param desired_replication_level desired replication count
80  * @param hop_count how many hops did this request traverse so far?
81  * @param key key for the content
82  * @param xquery extended query
83  * @param xquery_size number of bytes in @a xquery
84  * @param bg block group to filter replies
85  * @param peer_bf filter for peers not to select (again, updated)
86  * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
87  */
88 int
89 GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
90                            enum GNUNET_DHT_RouteOption options,
91                            uint32_t desired_replication_level,
92                            uint32_t hop_count,
93                            const struct GNUNET_HashCode *key,
94                            const void *xquery,
95                            size_t xquery_size,
96                            struct GNUNET_BLOCK_Group *bg,
97                            struct GNUNET_CONTAINER_BloomFilter *peer_bf);
98
99
100 /**
101  * Handle a reply (route to origin).  Only forwards the reply back to
102  * other peers waiting for it.  Does not do local caching or
103  * forwarding to local clients.
104  *
105  * @param target neighbour that should receive the block (if still connected)
106  * @param type type of the block
107  * @param expiration_time when does the content expire
108  * @param key key for the content
109  * @param put_path_length number of entries in put_path
110  * @param put_path peers the original PUT traversed (if tracked)
111  * @param get_path_length number of entries in put_path
112  * @param get_path peers this reply has traversed so far (if tracked)
113  * @param data payload of the reply
114  * @param data_size number of bytes in data
115  */
116 void
117 GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
118                              enum GNUNET_BLOCK_Type type,
119                              struct GNUNET_TIME_Absolute expiration_time,
120                              const struct GNUNET_HashCode *key,
121                              unsigned int put_path_length,
122                              const struct GNUNET_PeerIdentity *put_path,
123                              unsigned int get_path_length,
124                              const struct GNUNET_PeerIdentity *get_path,
125                              const void *data,
126                              size_t data_size);
127
128
129 /**
130  * Check whether my identity is closer than any known peers.  If a
131  * non-null bloomfilter is given, check if this is the closest peer
132  * that hasn't already been routed to.
133  *
134  * @param key hash code to check closeness to
135  * @param bloom bloomfilter, exclude these entries from the decision
136  * @return #GNUNET_YES if node location is closest,
137  *         #GNUNET_NO otherwise.
138  */
139 int
140 GDS_am_closest_peer (const struct GNUNET_HashCode *key,
141                      const struct GNUNET_CONTAINER_BloomFilter *bloom);
142
143
144
145 /**
146  * Initialize neighbours subsystem.
147  *
148  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
149  */
150 int
151 GDS_NEIGHBOURS_init (void);
152
153
154 /**
155  * Shutdown neighbours subsystem.
156  */
157 void
158 GDS_NEIGHBOURS_done (void);
159
160
161 /**
162  * Get the ID of the local node.
163  *
164  * @return identity of the local node
165  */
166 struct GNUNET_PeerIdentity *
167 GDS_NEIGHBOURS_get_id (void);
168
169
170 #endif