aboutsummaryrefslogtreecommitdiff
path: root/src/set/gnunet-service-set.h
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-03-13 01:24:22 +0100
committerChristian Grothoff <christian@grothoff.org>2017-03-13 01:24:34 +0100
commitbf6f552fdefe75425635f66343f98995e2f602f6 (patch)
treeadd6ea146823579a137763b78e89839ff97b3902 /src/set/gnunet-service-set.h
parenta9a5994e518ded483edb87513d5197b6539ed4ff (diff)
downloadgnunet-bf6f552fdefe75425635f66343f98995e2f602f6.tar.gz
gnunet-bf6f552fdefe75425635f66343f98995e2f602f6.zip
major clean up and bugfixes of SET
Diffstat (limited to 'src/set/gnunet-service-set.h')
-rw-r--r--src/set/gnunet-service-set.h360
1 files changed, 185 insertions, 175 deletions
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h
index 86313d179..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,23 +128,31 @@ 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 operation cancellation 138 * Signature of functions that implement operation cancelation.
139 * This includes notifying the client about the operation's final
140 * state.
217 * 141 *
218 * @param op operation state 142 * @param op operation state
219 */ 143 */
220typedef void 144typedef void
221(*CancelImpl) (struct Operation *op); 145(*OpCancelImpl) (struct Operation *op);
222 146
223 147
224typedef struct SetState * 148/**
225(*CopyStateImpl) (struct Set *op); 149 * Signature of functions called when the CADET channel died.
150 *
151 * @param op operation state
152 */
153typedef void
154(*OpChannelDeathImpl) (struct Operation *op);
155
226 156
227 157
228/** 158/**
@@ -234,17 +164,27 @@ struct SetVT
234 /** 164 /**
235 * Callback for the set creation. 165 * Callback for the set creation.
236 */ 166 */
237 CreateImpl create; 167 SetCreateImpl create;
238 168
239 /** 169 /**
240 * Callback for element insertion 170 * Callback for element insertion
241 */ 171 */
242 AddRemoveImpl add; 172 SetAddRemoveImpl add;
243 173
244 /** 174 /**
245 * Callback for element removal. 175 * Callback for element removal.
246 */ 176 */
247 AddRemoveImpl remove; 177 SetAddRemoveImpl remove;
178
179 /**
180 * Callback for making a copy of a set's internal state.
181 */
182 SetCopyStateImpl copy_state;
183
184 /**
185 * Callback for destruction of the set state.
186 */
187 SetDestroyImpl destroy_set;
248 188
249 /** 189 /**
250 * Callback for accepting a set operation request 190 * Callback for accepting a set operation request
@@ -257,21 +197,15 @@ struct SetVT
257 OpEvaluateImpl evaluate; 197 OpEvaluateImpl evaluate;
258 198
259 /** 199 /**
260 * Callback for destruction of the set state. 200 * Callback for canceling an operation.
261 */
262 DestroySetImpl destroy_set;
263
264 /**
265 * Callback for handling the remote peer's disconnect.
266 */ 201 */
267 PeerDisconnectImpl peer_disconnect; 202 OpCancelImpl cancel;
268 203
269 /** 204 /**
270 * Callback for canceling an operation by its ID. 205 * Callback called in case the CADET channel died.
271 */ 206 */
272 CancelImpl cancel; 207 OpChannelDeathImpl channel_death;
273 208
274 CopyStateImpl copy_state;
275}; 209};
276 210
277 211
@@ -341,20 +275,56 @@ struct ElementEntry
341}; 275};
342 276
343 277
278/**
279 * A listener is inhabited by a client, and waits for evaluation
280 * requests from remote peers.
281 */
344struct Listener; 282struct Listener;
345 283
346 284
347/** 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/**
348 * Operation context used to execute a set operation. 314 * Operation context used to execute a set operation.
349 */ 315 */
350struct Operation 316struct Operation
351{ 317{
318
352 /** 319 /**
353 * V-Table for the operation belonging to the tunnel contest. 320 * Kept in a DLL of the listener, if @e listener is non-NULL.
354 *
355 * Used for all operation specific operations after receiving the ops request
356 */ 321 */
357 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;
358 328
359 /** 329 /**
360 * Channel to the peer. 330 * Channel to the peer.
@@ -372,11 +342,15 @@ struct Operation
372 struct GNUNET_MQ_Handle *mq; 342 struct GNUNET_MQ_Handle *mq;
373 343
374 /** 344 /**
375 * Detail information about the set operation, including the set to 345 * Context message, may be NULL.
376 * use. When 'spec' is NULL, the operation is not yet entirely 346 */
377 * 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.
378 */ 352 */
379 struct OperationSpecification *spec; 353 struct Set *set;
380 354
381 /** 355 /**
382 * Operation-specific operation state. Note that the exact 356 * Operation-specific operation state. Note that the exact
@@ -386,16 +360,6 @@ struct Operation
386 struct OperationState *state; 360 struct OperationState *state;
387 361
388 /** 362 /**
389 * Evaluate operations are held in a linked list.
390 */
391 struct Operation *next;
392
393 /**
394 * Evaluate operations are held in a linked list.
395 */
396 struct Operation *prev;
397
398 /**
399 * The identity of the requesting peer. Needs to 363 * The identity of the requesting peer. Needs to
400 * 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.
401 */ 365 */
@@ -408,9 +372,48 @@ struct Operation
408 struct GNUNET_SCHEDULER_Task *timeout_task; 372 struct GNUNET_SCHEDULER_Task *timeout_task;
409 373
410 /** 374 /**
411 * The type of the operation. 375 * Salt to use for the operation.
412 */ 376 */
413 enum GNUNET_SET_OperationType operation; 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;
414 417
415 /** 418 /**
416 * 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
@@ -420,45 +423,26 @@ struct Operation
420 uint32_t suggest_id; 423 uint32_t suggest_id;
421 424
422 /** 425 /**
423 * #GNUNET_YES if this is not a "real" set operation yet, and we still
424 * need to wait for the other peer to give us more details.
425 */
426 int is_incoming;
427
428 /**
429 * Generation in which the operation handle 426 * Generation in which the operation handle
430 * was created. 427 * was created.
431 */ 428 */
432 unsigned int generation_created; 429 unsigned int generation_created;
433 430
434 /**
435 * Incremented whenever (during shutdown) some component still
436 * needs to do something with this before the operation is freed.
437 * (Used as a reference counter, but only during termination.)
438 */
439 unsigned int keep;
440}; 431};
441 432
442 433
443/** 434/**
444 * SetContent stores the actual set elements, 435 * SetContent stores the actual set elements, which may be shared by
445 * which may be shared by multiple generations derived 436 * multiple generations derived from one set.
446 * from one set.
447 */ 437 */
448struct SetContent 438struct SetContent
449{ 439{
450 /**
451 * Number of references to the content.
452 */
453 unsigned int refcount;
454 440
455 /** 441 /**
456 * Maps `struct GNUNET_HashCode *` to `struct ElementEntry *`. 442 * Maps `struct GNUNET_HashCode *` to `struct ElementEntry *`.
457 */ 443 */
458 struct GNUNET_CONTAINER_MultiHashMap *elements; 444 struct GNUNET_CONTAINER_MultiHashMap *elements;
459 445
460 unsigned int latest_generation;
461
462 /** 446 /**
463 * Mutations requested by the client that we're 447 * Mutations requested by the client that we're
464 * unable to execute right now because we're iterating 448 * unable to execute right now because we're iterating
@@ -474,6 +458,16 @@ struct SetContent
474 struct PendingMutation *pending_mutations_tail; 458 struct PendingMutation *pending_mutations_tail;
475 459
476 /** 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 /**
477 * Number of concurrently active iterators. 471 * Number of concurrently active iterators.
478 */ 472 */
479 int iterator_count; 473 int iterator_count;
@@ -494,11 +488,24 @@ struct GenerationRange
494}; 488};
495 489
496 490
491/**
492 * Information about a mutation to apply to a set.
493 */
497struct PendingMutation 494struct PendingMutation
498{ 495{
496 /**
497 * Mutations are kept in a DLL.
498 */
499 struct PendingMutation *prev; 499 struct PendingMutation *prev;
500
501 /**
502 * Mutations are kept in a DLL.
503 */
500 struct PendingMutation *next; 504 struct PendingMutation *next;
501 505
506 /**
507 * Set this mutation is about.
508 */
502 struct Set *set; 509 struct Set *set;
503 510
504 /** 511 /**
@@ -506,7 +513,7 @@ struct PendingMutation
506 * May only be a #GNUNET_MESSAGE_TYPE_SET_ADD or 513 * May only be a #GNUNET_MESSAGE_TYPE_SET_ADD or
507 * #GNUNET_MESSAGE_TYPE_SET_REMOVE. 514 * #GNUNET_MESSAGE_TYPE_SET_REMOVE.
508 */ 515 */
509 struct GNUNET_MessageHeader *mutation_message; 516 struct GNUNET_SET_ElementMessage *msg;
510}; 517};
511 518
512 519
@@ -530,12 +537,13 @@ struct Set
530 * 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,
531 * and there can only be one set per client. 538 * and there can only be one set per client.
532 */ 539 */
533 struct GNUNET_SERVICE_Client *client; 540 struct ClientState *cs;
534 541
535 /** 542 /**
536 * Message queue for the client. 543 * Content, possibly shared by multiple sets,
544 * and thus reference counted.
537 */ 545 */
538 struct GNUNET_MQ_Handle *client_mq; 546 struct SetContent *content;
539 547
540 /** 548 /**
541 * Virtual table for this set. Determined by the operation type of 549 * Virtual table for this set. Determined by the operation type of
@@ -568,15 +576,15 @@ struct Set
568 struct Operation *ops_tail; 576 struct Operation *ops_tail;
569 577
570 /** 578 /**
571 * Current generation, that is, number of previously executed 579 * List of generations we have to exclude, due to lazy copies.
572 * operations and lazy copies on the underlying set content.
573 */ 580 */
574 unsigned int current_generation; 581 struct GenerationRange *excluded_generations;
575 582
576 /** 583 /**
577 * 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.
578 */ 586 */
579 struct GenerationRange *excluded_generations; 587 unsigned int current_generation;
580 588
581 /** 589 /**
582 * Number of elements in array @a excluded_generations. 590 * Number of elements in array @a excluded_generations.
@@ -589,21 +597,16 @@ struct Set
589 enum GNUNET_SET_OperationType operation; 597 enum GNUNET_SET_OperationType operation;
590 598
591 /** 599 /**
592 * Each @e iter is assigned a unique number, so that the client
593 * can distinguish iterations.
594 */
595 uint16_t iteration_id;
596
597 /**
598 * Generation we're currently iteration over. 600 * Generation we're currently iteration over.
599 */ 601 */
600 unsigned int iter_generation; 602 unsigned int iter_generation;
601 603
602 /** 604 /**
603 * Content, possibly shared by multiple sets, 605 * Each @e iter is assigned a unique number, so that the client
604 * and thus reference counted. 606 * can distinguish iterations.
605 */ 607 */
606 struct SetContent *content; 608 uint16_t iteration_id;
609
607}; 610};
608 611
609 612
@@ -611,10 +614,14 @@ extern struct GNUNET_STATISTICS_Handle *_GSS_statistics;
611 614
612 615
613/** 616/**
614 * Destroy the given operation. Call the implementation-specific 617 * Destroy the given operation. Used for any operation where both
615 * cancel function of the operation. Disconnects from the remote 618 * peers were known and that thus actually had a vt and channel. Must
616 * 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
617 * 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.
618 * 625 *
619 * @param op operation to destroy 626 * @param op operation to destroy
620 * @param gc #GNUNET_YES to perform garbage collection on the set 627 * @param gc #GNUNET_YES to perform garbage collection on the set
@@ -642,10 +649,13 @@ const struct SetVT *
642_GSS_intersection_vt (void); 649_GSS_intersection_vt (void);
643 650
644 651
645int 652/**
646_GSS_is_element_of_set (struct ElementEntry *ee, 653 * Is element @a ee part of the set used by @a op?
647 struct Set *set); 654 *
648 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 */
649int 659int
650_GSS_is_element_of_operation (struct ElementEntry *ee, 660_GSS_is_element_of_operation (struct ElementEntry *ee,
651 struct Operation *op); 661 struct Operation *op);