2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file fs/gnunet-service-fs_pr.h
23 * @brief API to handle pending requests
24 * @author Christian Grothoff
26 #ifndef GNUNET_SERVICE_FS_PR_H
27 #define GNUNET_SERVICE_FS_PR_H
29 #include "gnunet-service-fs.h"
33 * Options for pending requests (bits to be ORed).
35 enum GSF_PendingRequestOptions
38 * Request must only be processed locally.
40 GSF_PRO_LOCAL_ONLY = 1,
43 * Request must only be forwarded (no routing)
45 GSF_PRO_FORWARD_ONLY = 2,
48 * Request persists indefinitely (no expiration).
50 GSF_PRO_REQUEST_EXPIRES = 4,
53 * Request is allowed to refresh bloomfilter and change mingle value.
55 GSF_PRO_BLOOMFILTER_FULL_REFRESH = 8,
58 * Request priority is allowed to be exceeded.
60 GSF_PRO_PRIORITY_UNLIMITED = 16,
63 * Option mask for typical local requests.
65 GSF_PRO_LOCAL_REQUEST = (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED)
71 * Public data (in the sense of not encapsulated within
72 * 'gnunet-service-fs_pr', not in the sense of network-wide
73 * known) associated with each pending request.
75 struct GSF_PendingRequestData
79 * Primary query hash for this request.
81 GNUNET_HashCode query;
84 * Namespace to query, only set if the type is SBLOCK.
86 GNUNET_HashCode namespace;
89 * Identity of a peer hosting the content, only set if
90 * 'has_target' is GNUNET_YES.
92 struct GNUNET_PeerIdentity target;
95 * Current TTL for the request.
97 struct GNUNET_TIME_Absolute ttl;
100 * When did we start with the request.
102 struct GNUNET_TIME_Absolute start_time;
105 * Desired anonymity level.
107 uint32_t anonymity_level;
110 * Priority that this request (still) has for us.
115 * Options for the request.
117 enum GSF_PendingRequestOptions options;
120 * Type of the requested block.
122 enum GNUNET_BLOCK_Type type;
125 * Is the 'target' value set to a valid peer identity?
133 * Handle a reply to a pending request. Also called if a request
134 * expires (then with data == NULL). The handler may be called
135 * many times (depending on the request type), but will not be
136 * called during or after a call to GSF_pending_request_cancel
137 * and will also not be called anymore after a call signalling
140 * @param cls user-specified closure
141 * @param pr handle to the original pending request
142 * @param data response data, NULL on request expiration
143 * @param data_len number of bytes in data
145 typedef void (*GSF_PendingRequestReplyHandler)(void *cls,
146 struct GSF_PendingRequest *pr,
152 * Create a new pending request.
154 * @param options request options
155 * @param type type of the block that is being requested
156 * @param query key for the lookup
157 * @param namespace namespace to lookup, NULL for no namespace
158 * @param target preferred target for the request, NULL for none
159 * @param bf_data raw data for bloom filter for known replies, can be NULL
160 * @param bf_size number of bytes in bf_data
161 * @param mingle mingle value for bf
162 * @param anonymity_level desired anonymity level
163 * @param priority maximum outgoing cummulative request priority to use
164 * @param ttl current time-to-live for the request
165 * @param replies_seen hash codes of known local replies
166 * @param replies_seen_count size of the 'replies_seen' array
167 * @param rh handle to call when we get a reply
168 * @param rh_cls closure for rh
169 * @return handle for the new pending request
171 struct GSF_PendingRequest *
172 GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
173 enum GNUNET_BLOCK_Type type,
174 const GNUNET_HashCode *query,
175 const GNUNET_HashCode *namespace,
176 const struct GNUNET_PeerIdentity *target,
180 uint32_t anonymity_level,
183 const GNUNET_HashCode *replies_seen,
184 unsigned int replies_seen_count,
185 GSF_PendingRequestReplyHandler rh,
190 * Update a given pending request with additional replies
191 * that have been seen.
193 * @param pr request to update
194 * @param replies_seen hash codes of replies that we've seen
195 * @param replies_seen_count size of the replies_seen array
198 GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
199 const GNUNET_HashCode *replies_seen,
200 unsigned int replies_seen_count);
204 * Obtain the public data associated with a pending request
206 * @param pr pending request
207 * @return associated public data
209 struct GSF_PendingRequestData *
210 GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr);
214 * Generate the message corresponding to the given pending request for
215 * transmission to other peers (or at least determine its size).
217 * @param pr request to generate the message for
218 * @param do_route are we routing the reply
219 * @param buf_size number of bytes available in buf
220 * @param buf where to copy the message (can be NULL)
221 * @return number of bytes needed (if buf_size too small) or used
224 GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
231 * Explicitly cancel a pending request.
233 * @param pr request to cancel
236 GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr);
240 * Signature of function called on each request.
241 * (Note: 'subtype' of GNUNET_CONTAINER_HashMapIterator).
244 * @param key query for the request
245 * @param pr handle to the pending request
246 * @return GNUNET_YES to continue to iterate
248 typedef int (*GSF_PendingRequestIterator)(void *cls,
249 const GNUNET_HashCode *key,
250 struct GSF_PendingRequest *pr);
254 * Iterate over all pending requests.
256 * @param it function to call for each request
257 * @param cls closure for it
260 GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
265 * Handle P2P "CONTENT" message. Checks that the message is
266 * well-formed and then checks if there are any pending requests for
267 * this content and possibly passes it on (to local clients or other
268 * peers). Does NOT perform migration (content caching at this peer).
270 * @param cp the other peer involved (sender or receiver, NULL
271 * for loopback messages where we are both sender and receiver)
272 * @param message the actual message
273 * @return GNUNET_OK if the message was well-formed,
274 * GNUNET_SYSERR if the message was malformed (close connection,
275 * do not cache under any circumstances)
278 GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
279 const struct GNUNET_MessageHeader *message);
283 * Iterator called on each result obtained for a DHT
284 * operation that expects a reply
286 * @param cls closure, the 'struct GSF_PendingRequest *'.
287 * @param exp when will this value expire
288 * @param key key of the result
289 * @param get_path NULL-terminated array of pointers
290 * to the peers on reverse GET path (or NULL if not recorded)
291 * @param put_path NULL-terminated array of pointers
292 * to the peers on the PUT path (or NULL if not recorded)
293 * @param type type of the result
294 * @param size number of bytes in data
295 * @param data pointer to the result data
298 GSF_handle_dht_reply_ (void *cls,
299 struct GNUNET_TIME_Absolute exp,
300 const GNUNET_HashCode * key,
301 const struct GNUNET_PeerIdentity * const *get_path,
302 const struct GNUNET_PeerIdentity * const *put_path,
303 enum GNUNET_BLOCK_Type type,
309 * Setup the subsystem.
312 GSF_pending_request_init_ (void);
316 * Shutdown the subsystem.
319 GSF_pending_request_done_ (void);
323 /* end of gnunet-service-fs_pr.h */