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