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 * Fields for the plan module to track a DLL with the request.
97 struct GSF_RequestPlan *rp_head;
100 * Fields for the plan module to track a DLL with the request.
102 struct GSF_RequestPlan *rp_tail;
105 * Current TTL for the request.
107 struct GNUNET_TIME_Absolute ttl;
110 * When did we start with the request.
112 struct GNUNET_TIME_Absolute start_time;
115 * Desired anonymity level.
117 uint32_t anonymity_level;
120 * Priority that this request (still) has for us.
125 * Priority that this request (originally) had for us.
127 uint32_t original_priority;
130 * Options for the request.
132 enum GSF_PendingRequestOptions options;
135 * Type of the requested block.
137 enum GNUNET_BLOCK_Type type;
140 * Number of results we have found for this request so far.
142 unsigned int results_found;
145 * Is the 'target' value set to a valid peer identity?
153 * Handle a reply to a pending request. Also called if a request
154 * expires (then with data == NULL). The handler may be called
155 * many times (depending on the request type), but will not be
156 * called during or after a call to GSF_pending_request_cancel
157 * and will also not be called anymore after a call signalling
160 * @param cls user-specified closure
161 * @param pr handle to the original pending request
162 * @param expiration when does 'data' expire?
163 * @param type type of the block
164 * @param data response data, NULL on request expiration
165 * @param data_len number of bytes in data
167 typedef void (*GSF_PendingRequestReplyHandler)(void *cls,
168 struct GSF_PendingRequest *pr,
169 struct GNUNET_TIME_Absolute expiration,
170 enum GNUNET_BLOCK_Type type,
176 * Create a new pending request.
178 * @param options request options
179 * @param type type of the block that is being requested
180 * @param query key for the lookup
181 * @param namespace namespace to lookup, NULL for no namespace
182 * @param target preferred target for the request, NULL for none
183 * @param bf_data raw data for bloom filter for known replies, can be NULL
184 * @param bf_size number of bytes in bf_data
185 * @param mingle mingle value for bf
186 * @param anonymity_level desired anonymity level
187 * @param priority maximum outgoing cummulative request priority to use
188 * @param ttl current time-to-live for the request
189 * @param sender_pid peer ID to use for the sender when forwarding, 0 for none;
190 * reference counter is taken over by this function
191 * @param replies_seen hash codes of known local replies
192 * @param replies_seen_count size of the 'replies_seen' array
193 * @param rh handle to call when we get a reply
194 * @param rh_cls closure for rh
195 * @return handle for the new pending request
197 struct GSF_PendingRequest *
198 GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
199 enum GNUNET_BLOCK_Type type,
200 const GNUNET_HashCode *query,
201 const GNUNET_HashCode *namespace,
202 const struct GNUNET_PeerIdentity *target,
206 uint32_t anonymity_level,
209 GNUNET_PEER_Id sender_pid,
210 const GNUNET_HashCode *replies_seen,
211 unsigned int replies_seen_count,
212 GSF_PendingRequestReplyHandler rh,
217 * Update a given pending request with additional replies
218 * that have been seen.
220 * @param pr request to update
221 * @param replies_seen hash codes of replies that we've seen
222 * @param replies_seen_count size of the replies_seen array
225 GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
226 const GNUNET_HashCode *replies_seen,
227 unsigned int replies_seen_count);
231 * Obtain the public data associated with a pending request
233 * @param pr pending request
234 * @return associated public data
236 struct GSF_PendingRequestData *
237 GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr);
241 * Generate the message corresponding to the given pending request for
242 * transmission to other peers (or at least determine its size).
244 * @param pr request to generate the message for
245 * @param buf_size number of bytes available in buf
246 * @param buf where to copy the message (can be NULL)
247 * @return number of bytes needed (if buf_size too small) or used
250 GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
256 * Explicitly cancel a pending request.
258 * @param pr request to cancel
261 GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr);
265 * Signature of function called on each request.
266 * (Note: 'subtype' of GNUNET_CONTAINER_HashMapIterator).
269 * @param key query for the request
270 * @param pr handle to the pending request
271 * @return GNUNET_YES to continue to iterate
273 typedef int (*GSF_PendingRequestIterator)(void *cls,
274 const GNUNET_HashCode *key,
275 struct GSF_PendingRequest *pr);
279 * Iterate over all pending requests.
281 * @param it function to call for each request
282 * @param cls closure for it
285 GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
290 * Handle P2P "CONTENT" message. Checks that the message is
291 * well-formed and then checks if there are any pending requests for
292 * this content and possibly passes it on (to local clients or other
293 * peers). Does NOT perform migration (content caching at this peer).
295 * @param cp the other peer involved (sender or receiver, NULL
296 * for loopback messages where we are both sender and receiver)
297 * @param message the actual message
298 * @return GNUNET_OK if the message was well-formed,
299 * GNUNET_SYSERR if the message was malformed (close connection,
300 * do not cache under any circumstances)
303 GSF_handle_p2p_content_ (struct GSF_ConnectedPeer *cp,
304 const struct GNUNET_MessageHeader *message);
308 * Consider looking up the data in the DHT (anonymity-level permitting).
310 * @param pr the pending request to process
313 GSF_dht_lookup_ (struct GSF_PendingRequest *pr);
317 * Function to be called after we're done processing
318 * replies from the local lookup.
321 * @param pr the pending request we were processing
322 * @param result final datastore lookup result
324 typedef void (*GSF_LocalLookupContinuation)(void *cls,
325 struct GSF_PendingRequest *pr,
326 enum GNUNET_BLOCK_EvaluationResult result);
330 * Look up the request in the local datastore.
332 * @param pr the pending request to process
333 * @param cont function to call at the end
334 * @param cont_cls closure for cont
337 GSF_local_lookup_ (struct GSF_PendingRequest *pr,
338 GSF_LocalLookupContinuation cont,
343 * Setup the subsystem.
346 GSF_pending_request_init_ (void);
350 * Shutdown the subsystem.
353 GSF_pending_request_done_ (void);
357 /* end of gnunet-service-fs_pr.h */