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)
70 * Handle a reply to a pending request. Also called if a request
71 * expires (then with data == NULL). The handler may be called
72 * many times (depending on the request type), but will not be
73 * called during or after a call to GSF_pending_request_cancel
74 * and will also not be called anymore after a call signalling
77 * @param cls user-specified closure
78 * @param pr handle to the original pending request
79 * @param data response data, NULL on request expiration
80 * @param data_len number of bytes in data
82 typedef void (*GSF_PendingRequestReplyHandler)(void *cls,
83 struct GSF_PendingRequest *pr,
89 * Create a new pending request.
91 * @param options request options
92 * @param type type of the block that is being requested
93 * @param query key for the lookup
94 * @param namespace namespace to lookup, NULL for no namespace
95 * @param target preferred target for the request, NULL for none
96 * @param bf bloom filter for known replies, can be NULL
97 * @param mingle mingle value for bf
98 * @param anonymity_level desired anonymity level
99 * @param priority maximum outgoing cummulative request priority to use
100 * @param replies_seen hash codes of known local replies
101 * @param replies_seen_count size of the 'replies_seen' array
102 * @param rh handle to call when we get a reply
103 * @param rh_cls closure for rh
104 * @return handle for the new pending request
106 struct GSF_PendingRequest *
107 GSF_pending_request_create_ (enum GSF_PendingRequestOptions options,
108 enum GNUNET_BLOCK_Type type,
109 const GNUNET_HashCode *query,
110 const GNUNET_HashCode *namespace,
111 const struct GNUNET_PeerIdentity *target,
112 struct GNUNET_CONTAINER_BloomFilter *bf,
114 uint32_t anonymity_level,
116 const GNUNET_HashCode *replies_seen,
117 unsigned int replies_seen_count,
118 GSF_PendingRequestReplyHandler rh,
123 * Update a given pending request with additional replies
124 * that have been seen.
126 * @param pr request to update
127 * @param replies_seen hash codes of replies that we've seen
128 * @param replies_seen_count size of the replies_seen array
131 GSF_pending_request_update_ (struct GSF_PendingRequest *pr,
132 const GNUNET_HashCode *replies_seen,
133 unsigned int replies_seen_count);
137 * Get the query for a given pending request.
139 * @param pr the request
140 * @return pointer to the query (only valid as long as pr is valid)
142 const GNUNET_HashCode *
143 GSF_pending_request_get_query_ (const struct GSF_PendingRequest *pr);
147 * Get the type of a given pending request.
149 * @param pr the request
152 enum GNUNET_BLOCK_Type
153 GSF_pending_request_get_type_ (const struct GSF_PendingRequest *pr);
157 * Generate the message corresponding to the given pending request for
158 * transmission to other peers (or at least determine its size).
160 * @param pr request to generate the message for
161 * @param buf_size number of bytes available in buf
162 * @param buf where to copy the message (can be NULL)
163 * @return number of bytes needed (if > buf_size) or used
166 GSF_pending_request_get_message_ (struct GSF_PendingRequest *pr,
172 * Explicitly cancel a pending request.
174 * @param pr request to cancel
177 GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr);
181 * Signature of function called on each request.
184 * @param key query for the request
185 * @param pr handle to the pending request
187 typedef int (*GSF_PendingRequestIterator)(void *cls,
188 const GNUNET_HashCode *key,
189 struct GSF_PendingRequest *pr);
193 * Iterate over all pending requests.
195 * @param it function to call for each request
196 * @param cls closure for it
199 GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it,
204 * Handle P2P "CONTENT" message. Checks that the message is
205 * well-formed and then checks if there are any pending requests for
206 * this content and possibly passes it on (to local clients or other
207 * peers). Does NOT perform migration (content caching at this peer).
209 * @param other the other peer involved (sender or receiver, NULL
210 * for loopback messages where we are both sender and receiver)
211 * @param message the actual message
212 * @return how valueable was the content to us (0 for not at all),
213 * GNUNET_SYSERR if the message was malformed (close connection,
214 * do not cache under any circumstances)
217 GSF_handle_p2p_content_ (const struct GNUNET_PeerIdentity *other,
218 const struct GNUNET_MessageHeader *message);
222 * Setup the subsystem.
225 GSF_pending_request_init_ (void);
229 * Shutdown the subsystem.
232 GSF_pending_request_done_ (void);
236 /* end of gnunet-service-fs_pr.h */