aboutsummaryrefslogtreecommitdiff
path: root/src/setu/gnunet-service-setu.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/setu/gnunet-service-setu.h')
-rw-r--r--src/setu/gnunet-service-setu.h393
1 files changed, 393 insertions, 0 deletions
diff --git a/src/setu/gnunet-service-setu.h b/src/setu/gnunet-service-setu.h
new file mode 100644
index 000000000..eb6b7a8e5
--- /dev/null
+++ b/src/setu/gnunet-service-setu.h
@@ -0,0 +1,393 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2013-2017 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 * @file set/gnunet-service-setu.h
22 * @brief common components for the implementation the different set operations
23 * @author Florian Dold
24 * @author Christian Grothoff
25 */
26#ifndef GNUNET_SERVICE_SETU_H_PRIVATE
27#define GNUNET_SERVICE_SETU_H_PRIVATE
28
29#include "platform.h"
30#include "gnunet_util_lib.h"
31#include "gnunet_protocols.h"
32#include "gnunet_applications.h"
33#include "gnunet_core_service.h"
34#include "gnunet_cadet_service.h"
35#include "gnunet_setu_service.h"
36#include "setu.h"
37
38
39/**
40 * Implementation-specific set state. Used as opaque pointer, and
41 * specified further in the respective implementation.
42 */
43struct SetState;
44
45/**
46 * Implementation-specific set operation. Used as opaque pointer, and
47 * specified further in the respective implementation.
48 */
49struct OperationState;
50
51/**
52 * A set that supports a specific operation with other peers.
53 */
54struct Set;
55
56/**
57 * Information about an element element in the set. All elements are
58 * stored in a hash-table from their hash-code to their 'struct
59 * Element', so that the remove and add operations are reasonably
60 * fast.
61 */
62struct ElementEntry;
63
64/**
65 * Operation context used to execute a set operation.
66 */
67struct Operation;
68
69
70/**
71 * Information about an element element in the set. All elements are
72 * stored in a hash-table from their hash-code to their `struct
73 * Element`, so that the remove and add operations are reasonably
74 * fast.
75 */
76struct ElementEntry
77{
78 /**
79 * The actual element. The data for the element
80 * should be allocated at the end of this struct.
81 */
82 struct GNUNET_SETU_Element element;
83
84 /**
85 * Hash of the element. For set union: Will be used to derive the
86 * different IBF keys for different salts.
87 */
88 struct GNUNET_HashCode element_hash;
89
90 /**
91 * First generation that includes this element.
92 */
93 unsigned int generation;
94
95 /**
96 * #GNUNET_YES if the element is a remote element, and does not belong
97 * to the operation's set.
98 */
99 int remote;
100};
101
102
103/**
104 * A listener is inhabited by a client, and waits for evaluation
105 * requests from remote peers.
106 */
107struct Listener;
108
109
110/**
111 * State we keep per client.
112 */
113struct ClientState
114{
115 /**
116 * Set, if associated with the client, otherwise NULL.
117 */
118 struct Set *set;
119
120 /**
121 * Listener, if associated with the client, otherwise NULL.
122 */
123 struct Listener *listener;
124
125 /**
126 * Client handle.
127 */
128 struct GNUNET_SERVICE_Client *client;
129
130 /**
131 * Message queue.
132 */
133 struct GNUNET_MQ_Handle *mq;
134};
135
136
137/**
138 * Operation context used to execute a set operation.
139 */
140struct Operation
141{
142 /**
143 * Kept in a DLL of the listener, if @e listener is non-NULL.
144 */
145 struct Operation *next;
146
147 /**
148 * Kept in a DLL of the listener, if @e listener is non-NULL.
149 */
150 struct Operation *prev;
151
152 /**
153 * Channel to the peer.
154 */
155 struct GNUNET_CADET_Channel *channel;
156
157 /**
158 * Port this operation runs on.
159 */
160 struct Listener *listener;
161
162 /**
163 * Message queue for the channel.
164 */
165 struct GNUNET_MQ_Handle *mq;
166
167 /**
168 * Context message, may be NULL.
169 */
170 struct GNUNET_MessageHeader *context_msg;
171
172 /**
173 * Set associated with the operation, NULL until the spec has been
174 * associated with a set.
175 */
176 struct Set *set;
177
178 /**
179 * Operation-specific operation state. Note that the exact
180 * type depends on this being a union or intersection operation
181 * (and thus on @e vt).
182 */
183 struct OperationState *state;
184
185 /**
186 * The identity of the requesting peer. Needs to
187 * be stored here as the op spec might not have been created yet.
188 */
189 struct GNUNET_PeerIdentity peer;
190
191 /**
192 * Timeout task, if the incoming peer has not been accepted
193 * after the timeout, it will be disconnected.
194 */
195 struct GNUNET_SCHEDULER_Task *timeout_task;
196
197 /**
198 * Salt to use for the operation.
199 */
200 uint32_t salt;
201
202 /**
203 * Remote peers element count
204 */
205 uint32_t remote_element_count;
206
207 /**
208 * ID used to identify an operation between service and client
209 */
210 uint32_t client_request_id;
211
212 /**
213 * Always use delta operation instead of sending full sets,
214 * even it it's less efficient.
215 */
216 int force_delta;
217
218 /**
219 * Always send full sets, even if delta operations would
220 * be more efficient.
221 */
222 int force_full;
223
224 /**
225 * #GNUNET_YES to fail operations where Byzantine faults
226 * are suspected
227 */
228 int byzantine;
229
230 /**
231 * Lower bound for the set size, used only when
232 * byzantine mode is enabled.
233 */
234 int byzantine_lower_bound;
235
236 /**
237 * Unique request id for the request from a remote peer, sent to the
238 * client, which will accept or reject the request. Set to '0' iff
239 * the request has not been suggested yet.
240 */
241 uint32_t suggest_id;
242
243 /**
244 * Generation in which the operation handle
245 * was created.
246 */
247 unsigned int generation_created;
248};
249
250
251/**
252 * SetContent stores the actual set elements, which may be shared by
253 * multiple generations derived from one set.
254 */
255struct SetContent
256{
257 /**
258 * Maps `struct GNUNET_HashCode *` to `struct ElementEntry *`.
259 */
260 struct GNUNET_CONTAINER_MultiHashMap *elements;
261
262 /**
263 * Number of references to the content.
264 */
265 unsigned int refcount;
266
267 /**
268 * FIXME: document!
269 */
270 unsigned int latest_generation;
271
272 /**
273 * Number of concurrently active iterators.
274 */
275 int iterator_count;
276};
277
278
279struct GenerationRange
280{
281 /**
282 * First generation that is excluded.
283 */
284 unsigned int start;
285
286 /**
287 * Generation after the last excluded generation.
288 */
289 unsigned int end;
290};
291
292
293/**
294 * A set that supports a specific operation with other peers.
295 */
296struct Set
297{
298 /**
299 * Sets are held in a doubly linked list (in `sets_head` and `sets_tail`).
300 */
301 struct Set *next;
302
303 /**
304 * Sets are held in a doubly linked list.
305 */
306 struct Set *prev;
307
308 /**
309 * Client that owns the set. Only one client may own a set,
310 * and there can only be one set per client.
311 */
312 struct ClientState *cs;
313
314 /**
315 * Content, possibly shared by multiple sets,
316 * and thus reference counted.
317 */
318 struct SetContent *content;
319
320 /**
321 * Implementation-specific state.
322 */
323 struct SetState *state;
324
325 /**
326 * Evaluate operations are held in a linked list.
327 */
328 struct Operation *ops_head;
329
330 /**
331 * Evaluate operations are held in a linked list.
332 */
333 struct Operation *ops_tail;
334
335 /**
336 * Current generation, that is, number of previously executed
337 * operations and lazy copies on the underlying set content.
338 */
339 unsigned int current_generation;
340
341};
342
343
344extern struct GNUNET_STATISTICS_Handle *_GSS_statistics;
345
346
347/**
348 * Destroy the given operation. Used for any operation where both
349 * peers were known and that thus actually had a vt and channel. Must
350 * not be used for operations where 'listener' is still set and we do
351 * not know the other peer.
352 *
353 * Call the implementation-specific cancel function of the operation.
354 * Disconnects from the remote peer. Does not disconnect the client,
355 * as there may be multiple operations per set.
356 *
357 * @param op operation to destroy
358 */
359void
360_GSS_operation_destroy (struct Operation *op);
361
362
363/**
364 * This function probably should not exist
365 * and be replaced by inlining more specific
366 * logic in the various places where it is called.
367 */
368void
369_GSS_operation_destroy2 (struct Operation *op);
370
371
372/**
373 * Get the table with implementing functions for set union.
374 *
375 * @return the operation specific VTable
376 */
377const struct SetVT *
378_GSS_union_vt (void);
379
380
381/**
382 * Is element @a ee part of the set used by @a op?
383 *
384 * @param ee element to test
385 * @param op operation the defines the set and its generation
386 * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not
387 */
388int
389_GSS_is_element_of_operation (struct ElementEntry *ee,
390 struct Operation *op);
391
392
393#endif