aboutsummaryrefslogtreecommitdiff
path: root/src/service/fs/gnunet-service-fs_pr.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/fs/gnunet-service-fs_pr.h')
-rw-r--r--src/service/fs/gnunet-service-fs_pr.h422
1 files changed, 422 insertions, 0 deletions
diff --git a/src/service/fs/gnunet-service-fs_pr.h b/src/service/fs/gnunet-service-fs_pr.h
new file mode 100644
index 000000000..339e409c5
--- /dev/null
+++ b/src/service/fs/gnunet-service-fs_pr.h
@@ -0,0 +1,422 @@
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 fs/gnunet-service-fs_pr.h
23 * @brief API to handle pending requests
24 * @author Christian Grothoff
25 */
26#ifndef GNUNET_SERVICE_FS_PR_H
27#define GNUNET_SERVICE_FS_PR_H
28
29#include "gnunet-service-fs.h"
30
31
32/**
33 * Options for pending requests (bits to be ORed).
34 */
35enum GSF_PendingRequestOptions
36{
37 /**
38 * No special options (P2P-default).
39 */
40 GSF_PRO_DEFAULTS = 0,
41
42 /**
43 * Request must only be processed locally.
44 */
45 GSF_PRO_LOCAL_ONLY = 1,
46
47 /**
48 * Request must only be forwarded (no routing)
49 */
50 GSF_PRO_FORWARD_ONLY = 2,
51
52 /**
53 * Request persists indefinitely (no expiration).
54 */
55 GSF_PRO_REQUEST_NEVER_EXPIRES = 4,
56
57 /**
58 * Request is allowed to refresh bloomfilter and change mingle value.
59 */
60 GSF_PRO_BLOOMFILTER_FULL_REFRESH = 8,
61
62 /**
63 * Request priority is allowed to be exceeded.
64 */
65 GSF_PRO_PRIORITY_UNLIMITED = 16,
66
67 /**
68 * Option mask for typical local requests.
69 */
70 GSF_PRO_LOCAL_REQUEST =
71 (GSF_PRO_BLOOMFILTER_FULL_REFRESH | GSF_PRO_PRIORITY_UNLIMITED
72 | GSF_PRO_REQUEST_NEVER_EXPIRES)
73};
74
75
76/**
77 * Public data (in the sense of not encapsulated within
78 * 'gnunet-service-fs_pr', not in the sense of network-wide
79 * known) associated with each pending request.
80 */
81struct GSF_PendingRequestData
82{
83 /**
84 * Primary query hash for this request.
85 */
86 struct GNUNET_HashCode query;
87
88 /**
89 * Identity of a peer hosting the content, otherwise NULl.
90 * Allocated after struct only if needed. Do not free!
91 */
92 const struct GNUNET_PeerIdentity *target;
93
94 /**
95 * Fields for the plan module to track a DLL with the request.
96 */
97 struct GSF_PendingRequestPlanBijection *pr_head;
98
99 /**
100 * Fields for the plan module to track a DLL with the request.
101 */
102 struct GSF_PendingRequestPlanBijection *pr_tail;
103
104 /**
105 * Current TTL for the request.
106 */
107 struct GNUNET_TIME_Absolute ttl;
108
109 /**
110 * When did we start with the request.
111 */
112 struct GNUNET_TIME_Absolute start_time;
113
114 /**
115 * Desired anonymity level.
116 */
117 uint32_t anonymity_level;
118
119 /**
120 * Priority that this request (still) has for us.
121 */
122 uint32_t priority;
123
124 /**
125 * Priority that this request (originally) had for us.
126 */
127 uint32_t original_priority;
128
129 /**
130 * Counter for how often this request has been transmitted (estimate,
131 * because we might have the same request pending for multiple clients,
132 * and of course because a transmission may have failed at a lower
133 * layer).
134 */
135 uint32_t num_transmissions;
136
137 /**
138 * How much respect did we (in total) offer for this request so far (estimate,
139 * because we might have the same request pending for multiple clients,
140 * and of course because a transmission may have failed at a lower
141 * layer).
142 */
143 uint32_t respect_offered;
144
145 /**
146 * Options for the request.
147 */
148 enum GSF_PendingRequestOptions options;
149
150 /**
151 * Type of the requested block.
152 */
153 enum GNUNET_BLOCK_Type type;
154
155 /**
156 * Number of results we have found for this request so far.
157 */
158 unsigned int results_found;
159
160 /**
161 * Has this request been started yet (local/p2p operations)? Or are
162 * we still constructing it?
163 */
164 int has_started;
165};
166
167
168/**
169 * Handle a reply to a pending request. Also called if a request
170 * expires (then with data == NULL). The handler may be called
171 * many times (depending on the request type), but will not be
172 * called during or after a call to GSF_pending_request_cancel
173 * and will also not be called anymore after a call signalling
174 * expiration.
175 *
176 * @param cls user-specified closure
177 * @param eval evaluation of the result
178 * @param pr handle to the original pending request
179 * @param reply_anonymity_level anonymity level for the reply, UINT32_MAX for "unknown"
180 * @param expiration when does @a data expire?
181 * @param last_transmission the last time we've tried to get this block (FOREVER if unknown)
182 * @param type type of the block
183 * @param data response data, NULL on request expiration
184 * @param data_len number of bytes in @a data
185 */
186typedef void
187(*GSF_PendingRequestReplyHandler) (
188 void *cls,
189 enum GNUNET_BLOCK_ReplyEvaluationResult eval,
190 struct GSF_PendingRequest *pr,
191 uint32_t reply_anonymity_level,
192 struct GNUNET_TIME_Absolute expiration,
193 struct GNUNET_TIME_Absolute
194 last_transmission,
195 enum GNUNET_BLOCK_Type type,
196 const void *data,
197 size_t data_len);
198
199
200/**
201 * Create a new pending request.
202 *
203 * @param options request options
204 * @param type type of the block that is being requested
205 * @param query key for the lookup
206 * @param target preferred target for the request, NULL for none
207 * @param bf_data raw data for bloom filter for known replies, can be NULL
208 * @param bf_size number of bytes in bf_data
209 * @param anonymity_level desired anonymity level
210 * @param priority maximum outgoing cumulative request priority to use
211 * @param ttl current time-to-live for the request
212 * @param sender_pid peer ID to use for the sender when forwarding, 0 for none;
213 * reference counter is taken over by this function
214 * @param origin_pid peer ID of origin of query (do not loop back)
215 * @param replies_seen hash codes of known local replies
216 * @param replies_seen_count size of the 'replies_seen' array
217 * @param rh handle to call when we get a reply
218 * @param rh_cls closure for rh
219 * @return handle for the new pending request
220 */
221struct GSF_PendingRequest *
222GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
223 enum GNUNET_BLOCK_Type type,
224 const struct GNUNET_HashCode *query,
225 const struct GNUNET_PeerIdentity *target,
226 const char *bf_data,
227 size_t bf_size,
228 uint32_t anonymity_level,
229 uint32_t priority,
230 int32_t ttl,
231 GNUNET_PEER_Id sender_pid,
232 GNUNET_PEER_Id origin_pid,
233 const struct GNUNET_HashCode *replies_seen,
234 unsigned int replies_seen_count,
235 GSF_PendingRequestReplyHandler rh,
236 void *rh_cls);
237
238
239/**
240 * Update a given pending request with additional replies
241 * that have been seen.
242 *
243 * @param pr request to update
244 * @param replies_seen hash codes of replies that we've seen
245 * @param replies_seen_count size of the @a replies_seen array
246 */
247void
248GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
249 const struct GNUNET_HashCode *replies_seen,
250 unsigned int replies_seen_count);
251
252
253/**
254 * Obtain the public data associated with a pending request
255 *
256 * @param pr pending request
257 * @return associated public data
258 */
259struct GSF_PendingRequestData *
260GSF_pending_request_get_data_ (struct GSF_PendingRequest *pr);
261
262
263/**
264 * Check if the given request is still active.
265 *
266 * @param pr pending request
267 * @return #GNUNET_YES if the request is still active
268 */
269int
270GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr);
271
272
273/**
274 * Test if two pending requests are compatible (would generate
275 * the same query modulo filters and should thus be processed
276 * jointly).
277 *
278 * @param pra a pending request
279 * @param prb another pending request
280 * @return #GNUNET_OK if the requests are compatible
281 */
282int
283GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra,
284 struct GSF_PendingRequest *prb);
285
286
287/**
288 * Generate the message corresponding to the given pending request for
289 * transmission to other peers.
290 *
291 * @param pr request to generate the message for
292 * @return envelope with the request message
293 */
294struct GNUNET_MQ_Envelope *
295GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr);
296
297
298/**
299 * Explicitly cancel a pending request.
300 *
301 * @param pr request to cancel
302 * @param full_cleanup fully purge the request
303 */
304void
305GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr,
306 int full_cleanup);
307
308
309/**
310 * Signature of function called on each request.
311 * (Note: 'subtype' of GNUNET_CONTAINER_HashMapIterator).
312 *
313 * @param cls closure
314 * @param key query for the request
315 * @param pr handle to the pending request
316 * @return #GNUNET_YES to continue to iterate
317 */
318typedef int
319(*GSF_PendingRequestIterator) (void *cls,
320 const struct GNUNET_HashCode *key,
321 struct GSF_PendingRequest *pr);
322
323
324/**
325 * Iterate over all pending requests.
326 *
327 * @param it function to call for each request
328 * @param cls closure for it
329 */
330void
331GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
332 void *cls);
333
334
335/**
336 * Handle P2P "CONTENT" message. Checks that the message is
337 * well-formed and then checks if there are any pending requests for
338 * this content and possibly passes it on (to local clients or other
339 * peers). Does NOT perform migration (content caching at this peer).
340 *
341 * @param cls the other peer involved (sender)
342 * @param put the actual message
343 */
344void
345handle_p2p_put (void *cls,
346 const struct PutMessage *put);
347
348
349/**
350 * Consider looking up the data in the DHT (anonymity-level permitting).
351 *
352 * @param pr the pending request to process
353 */
354void
355GSF_dht_lookup_ (struct GSF_PendingRequest *pr);
356
357
358/**
359 * Consider downloading via cadet (if possible)
360 *
361 * @param pr the pending request to process
362 */
363void
364GSF_cadet_lookup_ (struct GSF_PendingRequest *pr);
365
366
367/**
368 * Function to be called after we're done processing
369 * replies from the local lookup.
370 *
371 * @param cls closure
372 * @param pr the pending request we were processing
373 * @param result final datastore lookup result
374 */
375typedef void
376(*GSF_LocalLookupContinuation) (
377 void *cls,
378 struct GSF_PendingRequest *pr,
379 enum GNUNET_BLOCK_ReplyEvaluationResult result);
380
381
382/**
383 * Look up the request in the local datastore.
384 *
385 * @param pr the pending request to process
386 * @param cont function to call at the end
387 * @param cont_cls closure for @a cont
388 */
389void
390GSF_local_lookup_ (struct GSF_PendingRequest *pr,
391 GSF_LocalLookupContinuation cont,
392 void *cont_cls);
393
394
395/**
396 * Is the given target a legitimate peer for forwarding the given request?
397 *
398 * @param pr request
399 * @param target
400 * @return #GNUNET_YES if this request could be forwarded to the given peer
401 */
402int
403GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr,
404 const struct GNUNET_PeerIdentity *target);
405
406
407/**
408 * Setup the subsystem.
409 */
410void
411GSF_pending_request_init_ (void);
412
413
414/**
415 * Shutdown the subsystem.
416 */
417void
418GSF_pending_request_done_ (void);
419
420
421#endif
422/* end of gnunet-service-fs_pr.h */