aboutsummaryrefslogtreecommitdiff
path: root/src/set/gnunet-service-set.h
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-11-24 13:57:17 +0000
committerChristian Grothoff <christian@grothoff.org>2014-11-24 13:57:17 +0000
commit82f034f771b4fd8e18c61487f4bd239e0e200408 (patch)
tree29d37b77fee94a49359a462bd5adbdb460733a69 /src/set/gnunet-service-set.h
parent3fb00702b5ebd54301d5827774fbebcd11d206c9 (diff)
downloadgnunet-82f034f771b4fd8e18c61487f4bd239e0e200408.tar.gz
gnunet-82f034f771b4fd8e18c61487f4bd239e0e200408.zip
fixing collect_generation_garbage() complexity, doxygen, etc.
Diffstat (limited to 'src/set/gnunet-service-set.h')
-rw-r--r--src/set/gnunet-service-set.h246
1 files changed, 126 insertions, 120 deletions
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h
index d8450e242..b92eb47ff 100644
--- a/src/set/gnunet-service-set.h
+++ b/src/set/gnunet-service-set.h
@@ -22,8 +22,8 @@
22 * @file set/gnunet-service-set.h 22 * @file set/gnunet-service-set.h
23 * @brief common components for the implementation the different set operations 23 * @brief common components for the implementation the different set operations
24 * @author Florian Dold 24 * @author Florian Dold
25 * @author Christian Grothoff
25 */ 26 */
26
27#ifndef GNUNET_SERVICE_SET_H_PRIVATE 27#ifndef GNUNET_SERVICE_SET_H_PRIVATE
28#define GNUNET_SERVICE_SET_H_PRIVATE 28#define GNUNET_SERVICE_SET_H_PRIVATE
29 29
@@ -38,24 +38,33 @@
38 38
39 39
40/** 40/**
41 * Implementation-specific set state. 41 * Implementation-specific set state. Used as opaque pointer, and
42 * Used as opaque pointer, and specified further 42 * specified further in the respective implementation.
43 * in the respective implementation.
44 */ 43 */
45struct SetState; 44struct SetState;
46 45
47
48/** 46/**
49 * Implementation-specific set operation. 47 * Implementation-specific set operation. Used as opaque pointer, and
50 * Used as opaque pointer, and specified further 48 * specified further in the respective implementation.
51 * in the respective implementation.
52 */ 49 */
53struct OperationState; 50struct OperationState;
54 51
55 52/**
56/* forward declarations */ 53 * A set that supports a specific operation with other peers.
54 */
57struct Set; 55struct Set;
56
57/**
58 * Information about an element element in the set. All elements are
59 * stored in a hash-table from their hash-code to their 'struct
60 * Element', so that the remove and add operations are reasonably
61 * fast.
62 */
58struct ElementEntry; 63struct ElementEntry;
64
65/**
66 * Operation context used to execute a set operation.
67 */
59struct Operation; 68struct Operation;
60 69
61 70
@@ -64,13 +73,9 @@ struct Operation;
64 */ 73 */
65struct OperationSpecification 74struct OperationSpecification
66{ 75{
67 /**
68 * The type of the operation.
69 */
70 enum GNUNET_SET_OperationType operation;
71 76
72 /** 77 /**
73 * The remove peer we evaluate the operation with 78 * The remove peer we evaluate the operation with.
74 */ 79 */
75 struct GNUNET_PeerIdentity peer; 80 struct GNUNET_PeerIdentity peer;
76 81
@@ -86,6 +91,12 @@ struct OperationSpecification
86 struct GNUNET_MessageHeader *context_msg; 91 struct GNUNET_MessageHeader *context_msg;
87 92
88 /** 93 /**
94 * Set associated with the operation, NULL until the spec has been
95 * associated with a set.
96 */
97 struct Set *set;
98
99 /**
89 * Salt to use for the operation. 100 * Salt to use for the operation.
90 */ 101 */
91 uint32_t salt; 102 uint32_t salt;
@@ -101,10 +112,9 @@ struct OperationSpecification
101 uint32_t client_request_id; 112 uint32_t client_request_id;
102 113
103 /** 114 /**
104 * Set associated with the operation, NULL until the spec has been associated 115 * The type of the operation.
105 * with a set.
106 */ 116 */
107 struct Set *set; 117 enum GNUNET_SET_OperationType operation;
108 118
109 /** 119 /**
110 * When are elements sent to the client, and which elements are sent? 120 * When are elements sent to the client, and which elements are sent?
@@ -113,15 +123,14 @@ struct OperationSpecification
113}; 123};
114 124
115 125
116
117
118/** 126/**
119 * Signature of functions that create the implementation-specific 127 * Signature of functions that create the implementation-specific
120 * state for a set supporting a specific operation. 128 * state for a set supporting a specific operation.
121 * 129 *
122 * @return a set state specific to the supported operation 130 * @return a set state specific to the supported operation
123 */ 131 */
124typedef struct SetState *(*CreateImpl) (void); 132typedef struct SetState *
133(*CreateImpl) (void);
125 134
126 135
127/** 136/**
@@ -129,18 +138,21 @@ typedef struct SetState *(*CreateImpl) (void);
129 * for a set supporting a specific operation. 138 * for a set supporting a specific operation.
130 * 139 *
131 * @param set implementation-specific set state 140 * @param set implementation-specific set state
132 * @param msg element message from the client 141 * @param ee element message from the client
133 */ 142 */
134typedef void (*AddRemoveImpl) (struct SetState *state, struct ElementEntry *ee); 143typedef void
144(*AddRemoveImpl) (struct SetState *state,
145 struct ElementEntry *ee);
135 146
136 147
137/** 148/**
138 * Signature of functions that handle disconnection 149 * Signature of functions that handle disconnection of the remote
139 * of the remote peer. 150 * peer.
140 * 151 *
141 * @param op the set operation, contains implementation-specific data 152 * @param op the set operation, contains implementation-specific data
142 */ 153 */
143typedef void (*PeerDisconnectImpl) (struct Operation *op); 154typedef void
155(*PeerDisconnectImpl) (struct Operation *op);
144 156
145 157
146/** 158/**
@@ -149,16 +161,18 @@ typedef void (*PeerDisconnectImpl) (struct Operation *op);
149 * 161 *
150 * @param state the set state, contains implementation-specific data 162 * @param state the set state, contains implementation-specific data
151 */ 163 */
152typedef void (*DestroySetImpl) (struct SetState *state); 164typedef void
165(*DestroySetImpl) (struct SetState *state);
153 166
154 167
155/** 168/**
156 * Signature of functions that implement the creation of set operations 169 * Signature of functions that implement the creation of set operations
157 * (currently evaluate and accept). 170 * (currently "evaluate" and "accept").
158 * 171 *
159 * @param op operation that is created, should be initialized by the implementation 172 * @param op operation that is created, should be initialized by the implementation
160 */ 173 */
161typedef void (*OpCreateImpl) (struct Operation *op); 174typedef void
175(*OpCreateImpl) (struct Operation *op);
162 176
163 177
164/** 178/**
@@ -167,24 +181,26 @@ typedef void (*OpCreateImpl) (struct Operation *op);
167 * 181 *
168 * @param op operation state 182 * @param op operation state
169 * @param msg received message 183 * @param msg received message
170 * @return GNUNET_OK on success, GNUNET_SYSERR to 184 * @return #GNUNET_OK on success, #GNUNET_SYSERR to
171 * destroy the operation and the tunnel 185 * destroy the operation and the tunnel
172 */ 186 */
173typedef int (*MsgHandlerImpl) (struct Operation *op, 187typedef int
174 const struct GNUNET_MessageHeader *msg); 188(*MsgHandlerImpl) (struct Operation *op,
189 const struct GNUNET_MessageHeader *msg);
190
175 191
176/** 192/**
177 * Signature of functions that implement operation cancellation 193 * Signature of functions that implement operation cancellation
178 * 194 *
179 * @param op operation state 195 * @param op operation state
180 */ 196 */
181typedef void (*CancelImpl) (struct Operation *op); 197typedef void
198(*CancelImpl) (struct Operation *op);
182 199
183 200
184/** 201/**
185 * Dispatch table for a specific set operation. 202 * Dispatch table for a specific set operation. Every set operation
186 * Every set operation has to implement the callback 203 * has to implement the callback in this struct.
187 * in this struct.
188 */ 204 */
189struct SetVT 205struct SetVT
190{ 206{
@@ -224,24 +240,21 @@ struct SetVT
224 MsgHandlerImpl msg_handler; 240 MsgHandlerImpl msg_handler;
225 241
226 /** 242 /**
227 * Callback for handling the remote peer's 243 * Callback for handling the remote peer's disconnect.
228 * disconnect.
229 */ 244 */
230 PeerDisconnectImpl peer_disconnect; 245 PeerDisconnectImpl peer_disconnect;
231 246
232 /** 247 /**
233 * Callback for canceling an operation by 248 * Callback for canceling an operation by its ID.
234 * its ID.
235 */ 249 */
236 CancelImpl cancel; 250 CancelImpl cancel;
237}; 251};
238 252
239 253
240/** 254/**
241 * Information about an element element in the set. 255 * Information about an element element in the set. All elements are
242 * All elements are stored in a hash-table 256 * stored in a hash-table from their hash-code to their `struct
243 * from their hash-code to their 'struct Element', 257 * Element`, so that the remove and add operations are reasonably
244 * so that the remove and add operations are reasonably
245 * fast. 258 * fast.
246 */ 259 */
247struct ElementEntry 260struct ElementEntry
@@ -253,10 +266,8 @@ struct ElementEntry
253 struct GNUNET_SET_Element element; 266 struct GNUNET_SET_Element element;
254 267
255 /** 268 /**
256 * Hash of the element. 269 * Hash of the element. For set union: Will be used to derive the
257 * For set union: 270 * different IBF keys for different salts.
258 * Will be used to derive the different IBF keys
259 * for different salts.
260 */ 271 */
261 struct GNUNET_HashCode element_hash; 272 struct GNUNET_HashCode element_hash;
262 273
@@ -267,32 +278,32 @@ struct ElementEntry
267 unsigned int generation_added; 278 unsigned int generation_added;
268 279
269 /** 280 /**
270 * GNUNET_YES if the element has been removed in some generation.
271 */
272 int removed;
273
274 /**
275 * Generation the element was removed by the client. 281 * Generation the element was removed by the client.
276 * Operations of later generations will not consider the element. 282 * Operations of later generations will not consider the element.
277 * Only valid if is_removed is GNUNET_YES. 283 * Only valid if @e removed is #GNUNET_YES.
278 */ 284 */
279 unsigned int generation_removed; 285 unsigned int generation_removed;
280 286
281 /** 287 /**
282 * GNUNET_YES if the element is a remote element, and does not belong 288 * #GNUNET_YES if the element has been removed in some generation.
289 */
290 int removed;
291
292 /**
293 * #GNUNET_YES if the element is a remote element, and does not belong
283 * to the operation's set. 294 * to the operation's set.
284 *
285 * //TODO: Move to Union, unless additional set-operations are implemented ever
286 */ 295 */
287 int remote; 296 int remote;
288}; 297};
289 298
290 299
300/**
301 * Operation context used to execute a set operation.
302 */
291struct Operation 303struct Operation
292{ 304{
293 /** 305 /**
294 * V-Table for the operation belonging 306 * V-Table for the operation belonging to the tunnel contest.
295 * to the tunnel contest.
296 * 307 *
297 * Used for all operation specific operations after receiving the ops request 308 * Used for all operation specific operations after receiving the ops request
298 */ 309 */
@@ -309,21 +320,8 @@ struct Operation
309 struct GNUNET_MQ_Handle *mq; 320 struct GNUNET_MQ_Handle *mq;
310 321
311 /** 322 /**
312 * GNUNET_YES if this is not a "real" set operation yet, and we still 323 * Detail information about the set operation, including the set to
313 * need to wait for the other peer to give us more details. 324 * use. When 'spec' is NULL, the operation is not yet entirely
314 */
315 int is_incoming;
316
317 /**
318 * Generation in which the operation handle
319 * was created.
320 */
321 unsigned int generation_created;
322
323 /**
324 * Detail information about the set operation,
325 * including the set to use.
326 * When 'spec' is NULL, the operation is not yet entirely
327 * initialized. 325 * initialized.
328 */ 326 */
329 struct OperationSpecification *spec; 327 struct OperationSpecification *spec;
@@ -334,65 +332,70 @@ struct Operation
334 struct OperationState *state; 332 struct OperationState *state;
335 333
336 /** 334 /**
337 * Evaluate operations are held in 335 * Evaluate operations are held in a linked list.
338 * a linked list.
339 */ 336 */
340 struct Operation *next; 337 struct Operation *next;
341 338
342 /** 339 /**
343 * Evaluate operations are held in 340 * Evaluate operations are held in a linked list.
344 * a linked list. 341 */
345 */
346 struct Operation *prev; 342 struct Operation *prev;
347 343
348 /** 344 /**
349 * Set to GNUNET_YES if the set service should not free 345 * #GNUNET_YES if this is not a "real" set operation yet, and we still
350 * the operation, as it is still needed (e.g. in some scheduled task). 346 * need to wait for the other peer to give us more details.
347 */
348 int is_incoming;
349
350 /**
351 * Generation in which the operation handle
352 * was created.
353 */
354 unsigned int generation_created;
355
356 /**
357 * Set to #GNUNET_YES if the set service should not free the
358 * operation, as it is still needed (e.g. in some scheduled task).
351 */ 359 */
352 int keep; 360 int keep;
353}; 361};
354 362
355 363
356/** 364/**
357 * A set that supports a specific operation 365 * A set that supports a specific operation with other peers.
358 * with other peers.
359 */ 366 */
360struct Set 367struct Set
361{ 368{
362 /**
363 * Client that owns the set.
364 * Only one client may own a set.
365 */
366 struct GNUNET_SERVER_Client *client;
367 369
368 /** 370 /**
369 * Message queue for the client 371 * Sets are held in a doubly linked list (in `sets_head` and `sets_tail`).
370 */ 372 */
371 struct GNUNET_MQ_Handle *client_mq; 373 struct Set *next;
372 374
373 /** 375 /**
374 * Type of operation supported for this set 376 * Sets are held in a doubly linked list.
375 */ 377 */
376 enum GNUNET_SET_OperationType operation; 378 struct Set *prev;
377 379
378 /** 380 /**
379 * Virtual table for this set. 381 * Client that owns the set. Only one client may own a set,
380 * Determined by the operation type of this set. 382 * and there can only be one set per client.
381 *
382 * Used only for Add/remove of elements and when receiving an incoming
383 * operation from a remote peer.
384 */ 383 */
385 const struct SetVT *vt; 384 struct GNUNET_SERVER_Client *client;
386 385
387 /** 386 /**
388 * Sets are held in a doubly linked list. 387 * Message queue for the client.
389 */ 388 */
390 struct Set *next; 389 struct GNUNET_MQ_Handle *client_mq;
391 390
392 /** 391 /**
393 * Sets are held in a doubly linked list. 392 * Virtual table for this set. Determined by the operation type of
393 * this set.
394 *
395 * Used only for Add/remove of elements and when receiving an incoming
396 * operation from a remote peer.
394 */ 397 */
395 struct Set *prev; 398 const struct SetVT *vt;
396 399
397 /** 400 /**
398 * Implementation-specific state. 401 * Implementation-specific state.
@@ -406,34 +409,39 @@ struct Set
406 struct GNUNET_CONTAINER_MultiHashMapIterator *iter; 409 struct GNUNET_CONTAINER_MultiHashMapIterator *iter;
407 410
408 /** 411 /**
409 * Maps 'struct GNUNET_HashCode' to 'struct ElementEntry'. 412 * Maps `struct GNUNET_HashCode *` to `struct ElementEntry *`.
410 */ 413 */
411 struct GNUNET_CONTAINER_MultiHashMap *elements; 414 struct GNUNET_CONTAINER_MultiHashMap *elements;
412 415
413 /** 416 /**
414 * Current generation, that is, number of 417 * Evaluate operations are held in a linked list.
415 * previously executed operations on this set
416 */ 418 */
417 unsigned int current_generation; 419 struct Operation *ops_head;
418 420
419 /** 421 /**
420 * Evaluate operations are held in 422 * Evaluate operations are held in a linked list.
421 * a linked list.
422 */ 423 */
423 struct Operation *ops_head; 424 struct Operation *ops_tail;
424 425
425 /** 426 /**
426 * Evaluate operations are held in 427 * Current generation, that is, number of previously executed
427 * a linked list. 428 * operations on this set
428 */ 429 */
429 struct Operation *ops_tail; 430 unsigned int current_generation;
431
432 /**
433 * Type of operation supported for this set
434 */
435 enum GNUNET_SET_OperationType operation;
436
430}; 437};
431 438
432 439
433/** 440/**
434 * Destroy the given operation. Call the implementation-specific cancel function 441 * Destroy the given operation. Call the implementation-specific
435 * of the operation. Disconnects from the remote peer. 442 * cancel function of the operation. Disconnects from the remote
436 * Does not disconnect the client, as there may be multiple operations per set. 443 * peer. Does not disconnect the client, as there may be multiple
444 * operations per set.
437 * 445 *
438 * @param op operation to destroy 446 * @param op operation to destroy
439 */ 447 */
@@ -442,8 +450,7 @@ _GSS_operation_destroy (struct Operation *op);
442 450
443 451
444/** 452/**
445 * Get the table with implementing functions for 453 * Get the table with implementing functions for set union.
446 * set union.
447 * 454 *
448 * @return the operation specific VTable 455 * @return the operation specific VTable
449 */ 456 */
@@ -452,8 +459,7 @@ _GSS_union_vt (void);
452 459
453 460
454/** 461/**
455 * Get the table with implementing functions for 462 * Get the table with implementing functions for set intersection.
456 * set intersection.
457 * 463 *
458 * @return the operation specific VTable 464 * @return the operation specific VTable
459 */ 465 */