aboutsummaryrefslogtreecommitdiff
path: root/src/set/gnunet-service-set.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/set/gnunet-service-set.h')
-rw-r--r--src/set/gnunet-service-set.h366
1 files changed, 181 insertions, 185 deletions
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h
index 68d8fe81f..19413fd30 100644
--- a/src/set/gnunet-service-set.h
+++ b/src/set/gnunet-service-set.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2013, 2014 GNUnet e.V. 3 Copyright (C) 2013-2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -68,92 +68,13 @@ struct Operation;
68 68
69 69
70/** 70/**
71 * Detail information about an operation.
72 */
73struct OperationSpecification
74{
75
76 /**
77 * The remove peer we evaluate the operation with.
78 */
79 struct GNUNET_PeerIdentity peer;
80
81 /**
82 * Application ID for the operation, used to distinguish
83 * multiple operations of the same type with the same peer.
84 */
85 struct GNUNET_HashCode app_id;
86
87 /**
88 * Context message, may be NULL.
89 */
90 struct GNUNET_MessageHeader *context_msg;
91
92 /**
93 * Set associated with the operation, NULL until the spec has been
94 * associated with a set.
95 */
96 struct Set *set;
97
98 /**
99 * Salt to use for the operation.
100 */
101 uint32_t salt;
102
103 /**
104 * Remote peers element count
105 */
106 uint32_t remote_element_count;
107
108 /**
109 * ID used to identify an operation between service and client
110 */
111 uint32_t client_request_id;
112
113 /**
114 * The type of the operation.
115 */
116 enum GNUNET_SET_OperationType operation;
117
118 /**
119 * When are elements sent to the client, and which elements are sent?
120 */
121 enum GNUNET_SET_ResultMode result_mode;
122
123 /**
124 * Always use delta operation instead of sending full sets,
125 * even it it's less efficient.
126 */
127 int force_delta;
128
129 /**
130 * Always send full sets, even if delta operations would
131 * be more efficient.
132 */
133 int force_full;
134
135 /**
136 * #GNUNET_YES to fail operations where Byzantine faults
137 * are suspected
138 */
139 int byzantine;
140
141 /**
142 * Lower bound for the set size, used only when
143 * byzantine mode is enabled.
144 */
145 int byzantine_lower_bound;
146};
147
148
149/**
150 * Signature of functions that create the implementation-specific 71 * Signature of functions that create the implementation-specific
151 * state for a set supporting a specific operation. 72 * state for a set supporting a specific operation.
152 * 73 *
153 * @return a set state specific to the supported operation, NULL on error 74 * @return a set state specific to the supported operation, NULL on error
154 */ 75 */
155typedef struct SetState * 76typedef struct SetState *
156(*CreateImpl) (void); 77(*SetCreateImpl) (void);
157 78
158 79
159/** 80/**
@@ -164,18 +85,18 @@ typedef struct SetState *
164 * @param ee element message from the client 85 * @param ee element message from the client
165 */ 86 */
166typedef void 87typedef void
167(*AddRemoveImpl) (struct SetState *state, 88(*SetAddRemoveImpl) (struct SetState *state,
168 struct ElementEntry *ee); 89 struct ElementEntry *ee);
169 90
170 91
171/** 92/**
172 * Signature of functions that handle disconnection of the remote 93 * Make a copy of a set's internal state.
173 * peer.
174 * 94 *
175 * @param op the set operation, contains implementation-specific data 95 * @param state set state to copy
96 * @return copy of the internal state
176 */ 97 */
177typedef void 98typedef struct SetState *
178(*PeerDisconnectImpl) (struct Operation *op); 99(*SetCopyStateImpl) (struct SetState *state);
179 100
180 101
181/** 102/**
@@ -185,7 +106,7 @@ typedef void
185 * @param state the set state, contains implementation-specific data 106 * @param state the set state, contains implementation-specific data
186 */ 107 */
187typedef void 108typedef void
188(*DestroySetImpl) (struct SetState *state); 109(*SetDestroyImpl) (struct SetState *state);
189 110
190 111
191/** 112/**
@@ -193,8 +114,9 @@ typedef void
193 * 114 *
194 * @param op operation that is created by accepting the operation, 115 * @param op operation that is created by accepting the operation,
195 * should be initialized by the implementation 116 * should be initialized by the implementation
117 * @return operation-specific state to keep in @a op
196 */ 118 */
197typedef void 119typedef struct OperationState *
198(*OpAcceptImpl) (struct Operation *op); 120(*OpAcceptImpl) (struct Operation *op);
199 121
200 122
@@ -206,38 +128,32 @@ typedef void
206 * begin the evaluation 128 * begin the evaluation
207 * @param opaque_context message to be transmitted to the listener 129 * @param opaque_context message to be transmitted to the listener
208 * to convince him to accept, may be NULL 130 * to convince him to accept, may be NULL
131 * @return operation-specific state to keep in @a op
209 */ 132 */
210typedef void 133typedef struct OperationState *
211(*OpEvaluateImpl) (struct Operation *op, 134(*OpEvaluateImpl) (struct Operation *op,
212 const struct GNUNET_MessageHeader *opaque_context); 135 const struct GNUNET_MessageHeader *opaque_context);
213 136
214
215/** 137/**
216 * Signature of functions that implement the message handling for 138 * Signature of functions that implement operation cancelation.
217 * the different set operations. 139 * This includes notifying the client about the operation's final
140 * state.
218 * 141 *
219 * @param op operation state 142 * @param op operation state
220 * @param msg received message
221 * @return #GNUNET_OK on success, #GNUNET_SYSERR to
222 * destroy the operation and the tunnel
223 */ 143 */
224typedef int 144typedef void
225(*MsgHandlerImpl) (struct Operation *op, 145(*OpCancelImpl) (struct Operation *op);
226 const struct GNUNET_MessageHeader *msg);
227 146
228 147
229/** 148/**
230 * Signature of functions that implement operation cancellation 149 * Signature of functions called when the CADET channel died.
231 * 150 *
232 * @param op operation state 151 * @param op operation state
233 */ 152 */
234typedef void 153typedef void
235(*CancelImpl) (struct Operation *op); 154(*OpChannelDeathImpl) (struct Operation *op);
236 155
237 156
238typedef struct SetState *
239(*CopyStateImpl) (struct Set *op);
240
241 157
242/** 158/**
243 * Dispatch table for a specific set operation. Every set operation 159 * Dispatch table for a specific set operation. Every set operation
@@ -248,49 +164,48 @@ struct SetVT
248 /** 164 /**
249 * Callback for the set creation. 165 * Callback for the set creation.
250 */ 166 */
251 CreateImpl create; 167 SetCreateImpl create;
252 168
253 /** 169 /**
254 * Callback for element insertion 170 * Callback for element insertion
255 */ 171 */
256 AddRemoveImpl add; 172 SetAddRemoveImpl add;
257 173
258 /** 174 /**
259 * Callback for element removal. 175 * Callback for element removal.
260 */ 176 */
261 AddRemoveImpl remove; 177 SetAddRemoveImpl remove;
262 178
263 /** 179 /**
264 * Callback for accepting a set operation request 180 * Callback for making a copy of a set's internal state.
265 */ 181 */
266 OpAcceptImpl accept; 182 SetCopyStateImpl copy_state;
267 183
268 /** 184 /**
269 * Callback for starting evaluation with a remote peer. 185 * Callback for destruction of the set state.
270 */ 186 */
271 OpEvaluateImpl evaluate; 187 SetDestroyImpl destroy_set;
272 188
273 /** 189 /**
274 * Callback for destruction of the set state. 190 * Callback for accepting a set operation request
275 */ 191 */
276 DestroySetImpl destroy_set; 192 OpAcceptImpl accept;
277 193
278 /** 194 /**
279 * Callback for handling operation-specific messages. 195 * Callback for starting evaluation with a remote peer.
280 */ 196 */
281 MsgHandlerImpl msg_handler; 197 OpEvaluateImpl evaluate;
282 198
283 /** 199 /**
284 * Callback for handling the remote peer's disconnect. 200 * Callback for canceling an operation.
285 */ 201 */
286 PeerDisconnectImpl peer_disconnect; 202 OpCancelImpl cancel;
287 203
288 /** 204 /**
289 * Callback for canceling an operation by its ID. 205 * Callback called in case the CADET channel died.
290 */ 206 */
291 CancelImpl cancel; 207 OpChannelDeathImpl channel_death;
292 208
293 CopyStateImpl copy_state;
294}; 209};
295 210
296 211
@@ -360,20 +275,56 @@ struct ElementEntry
360}; 275};
361 276
362 277
278/**
279 * A listener is inhabited by a client, and waits for evaluation
280 * requests from remote peers.
281 */
363struct Listener; 282struct Listener;
364 283
365 284
366/** 285/**
286 * State we keep per client.
287 */
288struct ClientState
289{
290 /**
291 * Set, if associated with the client, otherwise NULL.
292 */
293 struct Set *set;
294
295 /**
296 * Listener, if associated with the client, otherwise NULL.
297 */
298 struct Listener *listener;
299
300 /**
301 * Client handle.
302 */
303 struct GNUNET_SERVICE_Client *client;
304
305 /**
306 * Message queue.
307 */
308 struct GNUNET_MQ_Handle *mq;
309
310};
311
312
313/**
367 * Operation context used to execute a set operation. 314 * Operation context used to execute a set operation.
368 */ 315 */
369struct Operation 316struct Operation
370{ 317{
318
371 /** 319 /**
372 * V-Table for the operation belonging to the tunnel contest. 320 * Kept in a DLL of the listener, if @e listener is non-NULL.
373 *
374 * Used for all operation specific operations after receiving the ops request
375 */ 321 */
376 const struct SetVT *vt; 322 struct Operation *next;
323
324 /**
325 * Kept in a DLL of the listener, if @e listener is non-NULL.
326 */
327 struct Operation *prev;
377 328
378 /** 329 /**
379 * Channel to the peer. 330 * Channel to the peer.
@@ -391,11 +342,15 @@ struct Operation
391 struct GNUNET_MQ_Handle *mq; 342 struct GNUNET_MQ_Handle *mq;
392 343
393 /** 344 /**
394 * Detail information about the set operation, including the set to 345 * Context message, may be NULL.
395 * use. When 'spec' is NULL, the operation is not yet entirely 346 */
396 * initialized. 347 struct GNUNET_MessageHeader *context_msg;
348
349 /**
350 * Set associated with the operation, NULL until the spec has been
351 * associated with a set.
397 */ 352 */
398 struct OperationSpecification *spec; 353 struct Set *set;
399 354
400 /** 355 /**
401 * Operation-specific operation state. Note that the exact 356 * Operation-specific operation state. Note that the exact
@@ -405,16 +360,6 @@ struct Operation
405 struct OperationState *state; 360 struct OperationState *state;
406 361
407 /** 362 /**
408 * Evaluate operations are held in a linked list.
409 */
410 struct Operation *next;
411
412 /**
413 * Evaluate operations are held in a linked list.
414 */
415 struct Operation *prev;
416
417 /**
418 * The identity of the requesting peer. Needs to 363 * The identity of the requesting peer. Needs to
419 * be stored here as the op spec might not have been created yet. 364 * be stored here as the op spec might not have been created yet.
420 */ 365 */
@@ -427,6 +372,50 @@ struct Operation
427 struct GNUNET_SCHEDULER_Task *timeout_task; 372 struct GNUNET_SCHEDULER_Task *timeout_task;
428 373
429 /** 374 /**
375 * Salt to use for the operation.
376 */
377 uint32_t salt;
378
379 /**
380 * Remote peers element count
381 */
382 uint32_t remote_element_count;
383
384 /**
385 * ID used to identify an operation between service and client
386 */
387 uint32_t client_request_id;
388
389 /**
390 * When are elements sent to the client, and which elements are sent?
391 */
392 enum GNUNET_SET_ResultMode result_mode;
393
394 /**
395 * Always use delta operation instead of sending full sets,
396 * even it it's less efficient.
397 */
398 int force_delta;
399
400 /**
401 * Always send full sets, even if delta operations would
402 * be more efficient.
403 */
404 int force_full;
405
406 /**
407 * #GNUNET_YES to fail operations where Byzantine faults
408 * are suspected
409 */
410 int byzantine;
411
412 /**
413 * Lower bound for the set size, used only when
414 * byzantine mode is enabled.
415 */
416 int byzantine_lower_bound;
417
418 /**
430 * Unique request id for the request from a remote peer, sent to the 419 * Unique request id for the request from a remote peer, sent to the
431 * client, which will accept or reject the request. Set to '0' iff 420 * client, which will accept or reject the request. Set to '0' iff
432 * the request has not been suggested yet. 421 * the request has not been suggested yet.
@@ -434,45 +423,26 @@ struct Operation
434 uint32_t suggest_id; 423 uint32_t suggest_id;
435 424
436 /** 425 /**
437 * #GNUNET_YES if this is not a "real" set operation yet, and we still
438 * need to wait for the other peer to give us more details.
439 */
440 int is_incoming;
441
442 /**
443 * Generation in which the operation handle 426 * Generation in which the operation handle
444 * was created. 427 * was created.
445 */ 428 */
446 unsigned int generation_created; 429 unsigned int generation_created;
447 430
448 /**
449 * Incremented whenever (during shutdown) some component still
450 * needs to do something with this before the operation is freed.
451 * (Used as a reference counter, but only during termination.)
452 */
453 unsigned int keep;
454}; 431};
455 432
456 433
457/** 434/**
458 * SetContent stores the actual set elements, 435 * SetContent stores the actual set elements, which may be shared by
459 * which may be shared by multiple generations derived 436 * multiple generations derived from one set.
460 * from one set.
461 */ 437 */
462struct SetContent 438struct SetContent
463{ 439{
464 /**
465 * Number of references to the content.
466 */
467 unsigned int refcount;
468 440
469 /** 441 /**
470 * Maps `struct GNUNET_HashCode *` to `struct ElementEntry *`. 442 * Maps `struct GNUNET_HashCode *` to `struct ElementEntry *`.
471 */ 443 */
472 struct GNUNET_CONTAINER_MultiHashMap *elements; 444 struct GNUNET_CONTAINER_MultiHashMap *elements;
473 445
474 unsigned int latest_generation;
475
476 /** 446 /**
477 * Mutations requested by the client that we're 447 * Mutations requested by the client that we're
478 * unable to execute right now because we're iterating 448 * unable to execute right now because we're iterating
@@ -488,6 +458,16 @@ struct SetContent
488 struct PendingMutation *pending_mutations_tail; 458 struct PendingMutation *pending_mutations_tail;
489 459
490 /** 460 /**
461 * Number of references to the content.
462 */
463 unsigned int refcount;
464
465 /**
466 * FIXME: document!
467 */
468 unsigned int latest_generation;
469
470 /**
491 * Number of concurrently active iterators. 471 * Number of concurrently active iterators.
492 */ 472 */
493 int iterator_count; 473 int iterator_count;
@@ -508,11 +488,24 @@ struct GenerationRange
508}; 488};
509 489
510 490
491/**
492 * Information about a mutation to apply to a set.
493 */
511struct PendingMutation 494struct PendingMutation
512{ 495{
496 /**
497 * Mutations are kept in a DLL.
498 */
513 struct PendingMutation *prev; 499 struct PendingMutation *prev;
500
501 /**
502 * Mutations are kept in a DLL.
503 */
514 struct PendingMutation *next; 504 struct PendingMutation *next;
515 505
506 /**
507 * Set this mutation is about.
508 */
516 struct Set *set; 509 struct Set *set;
517 510
518 /** 511 /**
@@ -520,7 +513,7 @@ struct PendingMutation
520 * May only be a #GNUNET_MESSAGE_TYPE_SET_ADD or 513 * May only be a #GNUNET_MESSAGE_TYPE_SET_ADD or
521 * #GNUNET_MESSAGE_TYPE_SET_REMOVE. 514 * #GNUNET_MESSAGE_TYPE_SET_REMOVE.
522 */ 515 */
523 struct GNUNET_MessageHeader *mutation_message; 516 struct GNUNET_SET_ElementMessage *msg;
524}; 517};
525 518
526 519
@@ -544,12 +537,13 @@ struct Set
544 * Client that owns the set. Only one client may own a set, 537 * Client that owns the set. Only one client may own a set,
545 * and there can only be one set per client. 538 * and there can only be one set per client.
546 */ 539 */
547 struct GNUNET_SERVICE_Client *client; 540 struct ClientState *cs;
548 541
549 /** 542 /**
550 * Message queue for the client. 543 * Content, possibly shared by multiple sets,
544 * and thus reference counted.
551 */ 545 */
552 struct GNUNET_MQ_Handle *client_mq; 546 struct SetContent *content;
553 547
554 /** 548 /**
555 * Virtual table for this set. Determined by the operation type of 549 * Virtual table for this set. Determined by the operation type of
@@ -582,15 +576,15 @@ struct Set
582 struct Operation *ops_tail; 576 struct Operation *ops_tail;
583 577
584 /** 578 /**
585 * Current generation, that is, number of previously executed 579 * List of generations we have to exclude, due to lazy copies.
586 * operations and lazy copies on the underlying set content.
587 */ 580 */
588 unsigned int current_generation; 581 struct GenerationRange *excluded_generations;
589 582
590 /** 583 /**
591 * List of generations we have to exclude, due to lazy copies. 584 * Current generation, that is, number of previously executed
585 * operations and lazy copies on the underlying set content.
592 */ 586 */
593 struct GenerationRange *excluded_generations; 587 unsigned int current_generation;
594 588
595 /** 589 /**
596 * Number of elements in array @a excluded_generations. 590 * Number of elements in array @a excluded_generations.
@@ -603,21 +597,16 @@ struct Set
603 enum GNUNET_SET_OperationType operation; 597 enum GNUNET_SET_OperationType operation;
604 598
605 /** 599 /**
606 * Each @e iter is assigned a unique number, so that the client
607 * can distinguish iterations.
608 */
609 uint16_t iteration_id;
610
611 /**
612 * Generation we're currently iteration over. 600 * Generation we're currently iteration over.
613 */ 601 */
614 unsigned int iter_generation; 602 unsigned int iter_generation;
615 603
616 /** 604 /**
617 * Content, possibly shared by multiple sets, 605 * Each @e iter is assigned a unique number, so that the client
618 * and thus reference counted. 606 * can distinguish iterations.
619 */ 607 */
620 struct SetContent *content; 608 uint16_t iteration_id;
609
621}; 610};
622 611
623 612
@@ -625,10 +614,14 @@ extern struct GNUNET_STATISTICS_Handle *_GSS_statistics;
625 614
626 615
627/** 616/**
628 * Destroy the given operation. Call the implementation-specific 617 * Destroy the given operation. Used for any operation where both
629 * cancel function of the operation. Disconnects from the remote 618 * peers were known and that thus actually had a vt and channel. Must
630 * peer. Does not disconnect the client, as there may be multiple 619 * not be used for operations where 'listener' is still set and we do
631 * operations per set. 620 * not know the other peer.
621 *
622 * Call the implementation-specific cancel function of the operation.
623 * Disconnects from the remote peer. Does not disconnect the client,
624 * as there may be multiple operations per set.
632 * 625 *
633 * @param op operation to destroy 626 * @param op operation to destroy
634 * @param gc #GNUNET_YES to perform garbage collection on the set 627 * @param gc #GNUNET_YES to perform garbage collection on the set
@@ -656,10 +649,13 @@ const struct SetVT *
656_GSS_intersection_vt (void); 649_GSS_intersection_vt (void);
657 650
658 651
659int 652/**
660_GSS_is_element_of_set (struct ElementEntry *ee, 653 * Is element @a ee part of the set used by @a op?
661 struct Set *set); 654 *
662 655 * @param ee element to test
656 * @param op operation the defines the set and its generation
657 * @return #GNUNET_YES if the element is in the set, #GNUNET_NO if not
658 */
663int 659int
664_GSS_is_element_of_operation (struct ElementEntry *ee, 660_GSS_is_element_of_operation (struct ElementEntry *ee,
665 struct Operation *op); 661 struct Operation *op);