diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-11-11 17:32:48 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-11-11 17:32:48 +0000 |
commit | c7954a8ae4bd0e745de626e22b72328e7b2491f4 (patch) | |
tree | af1c4ff37b84d6244756a8024e170352c98e4cda /src/set | |
parent | 74d9e28db4e0e515ec17c5fdd1994f6f18377c7b (diff) | |
download | gnunet-c7954a8ae4bd0e745de626e22b72328e7b2491f4.tar.gz gnunet-c7954a8ae4bd0e745de626e22b72328e7b2491f4.zip |
added many comments
documented set-union state "machine"
removed many deprecated struct-members from state, ops-spec
improved doxygen-compliant
Diffstat (limited to 'src/set')
-rw-r--r-- | src/set/gnunet-service-set.h | 37 | ||||
-rw-r--r-- | src/set/gnunet-service-set_intersection.c | 46 | ||||
-rw-r--r-- | src/set/gnunet-service-set_union.c | 49 |
3 files changed, 63 insertions, 69 deletions
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h index 7a2c5ba8d..dd6e91da8 100644 --- a/src/set/gnunet-service-set.h +++ b/src/set/gnunet-service-set.h | |||
@@ -91,7 +91,7 @@ struct OperationSpecification | |||
91 | uint32_t salt; | 91 | uint32_t salt; |
92 | 92 | ||
93 | /** | 93 | /** |
94 | * ID used to identify responses to a client. | 94 | * ID used to identify an operation between service and client |
95 | */ | 95 | */ |
96 | uint32_t client_request_id; | 96 | uint32_t client_request_id; |
97 | 97 | ||
@@ -168,16 +168,12 @@ typedef void (*OpCreateImpl) (struct Operation *op); | |||
168 | typedef int (*MsgHandlerImpl) (struct Operation *op, | 168 | typedef int (*MsgHandlerImpl) (struct Operation *op, |
169 | const struct GNUNET_MessageHeader *msg); | 169 | const struct GNUNET_MessageHeader *msg); |
170 | 170 | ||
171 | typedef void (*CancelImpl) (struct Operation *op); | ||
172 | |||
173 | |||
174 | /** | 171 | /** |
175 | * Signature of functions that implement sending all the set's | 172 | * Signature of functions that implement operation cancellation |
176 | * elements to the client. | ||
177 | * | 173 | * |
178 | * @param set set that should be iterated over | 174 | * @param op operation state |
179 | */ | 175 | */ |
180 | typedef void (*IterateImpl) (struct Set *set); | 176 | typedef void (*CancelImpl) (struct Operation *op); |
181 | 177 | ||
182 | 178 | ||
183 | /** | 179 | /** |
@@ -233,11 +229,6 @@ struct SetVT | |||
233 | * its ID. | 229 | * its ID. |
234 | */ | 230 | */ |
235 | CancelImpl cancel; | 231 | CancelImpl cancel; |
236 | |||
237 | /** | ||
238 | * Callback for iterating over all set elements. | ||
239 | */ | ||
240 | IterateImpl iterate; | ||
241 | }; | 232 | }; |
242 | 233 | ||
243 | 234 | ||
@@ -285,6 +276,8 @@ struct ElementEntry | |||
285 | /** | 276 | /** |
286 | * GNUNET_YES if the element is a remote element, and does not belong | 277 | * GNUNET_YES if the element is a remote element, and does not belong |
287 | * to the operation's set. | 278 | * to the operation's set. |
279 | * | ||
280 | * //TODO: Move to Union, unless additional set-operations are implemented ever | ||
288 | */ | 281 | */ |
289 | int remote; | 282 | int remote; |
290 | }; | 283 | }; |
@@ -295,6 +288,8 @@ struct Operation | |||
295 | /** | 288 | /** |
296 | * V-Table for the operation belonging | 289 | * V-Table for the operation belonging |
297 | * to the tunnel contest. | 290 | * to the tunnel contest. |
291 | * | ||
292 | * Used for all operation specific operations after receiving the ops request | ||
298 | */ | 293 | */ |
299 | const struct SetVT *vt; | 294 | const struct SetVT *vt; |
300 | 295 | ||
@@ -311,6 +306,8 @@ struct Operation | |||
311 | /** | 306 | /** |
312 | * GNUNET_YES if this is not a "real" set operation yet, and we still | 307 | * GNUNET_YES if this is not a "real" set operation yet, and we still |
313 | * need to wait for the other peer to give us more details. | 308 | * need to wait for the other peer to give us more details. |
309 | * | ||
310 | * //TODO: replace with state-enum | ||
314 | */ | 311 | */ |
315 | int is_incoming; | 312 | int is_incoming; |
316 | 313 | ||
@@ -372,6 +369,9 @@ struct Set | |||
372 | /** | 369 | /** |
373 | * Virtual table for this set. | 370 | * Virtual table for this set. |
374 | * Determined by the operation type of this set. | 371 | * Determined by the operation type of this set. |
372 | * | ||
373 | * Used only for Add/remove of elements and when receiving an incoming | ||
374 | * operation from a remote peer. | ||
375 | */ | 375 | */ |
376 | const struct SetVT *vt; | 376 | const struct SetVT *vt; |
377 | 377 | ||
@@ -421,6 +421,13 @@ struct Set | |||
421 | }; | 421 | }; |
422 | 422 | ||
423 | 423 | ||
424 | /** | ||
425 | * Destroy the given operation. Call the implementation-specific cancel function | ||
426 | * of the operation. Disconnects from the remote peer. | ||
427 | * Does not disconnect the client, as there may be multiple operations per set. | ||
428 | * | ||
429 | * @param op operation to destroy | ||
430 | */ | ||
424 | void | 431 | void |
425 | _GSS_operation_destroy (struct Operation *op); | 432 | _GSS_operation_destroy (struct Operation *op); |
426 | 433 | ||
@@ -428,6 +435,8 @@ _GSS_operation_destroy (struct Operation *op); | |||
428 | /** | 435 | /** |
429 | * Get the table with implementing functions for | 436 | * Get the table with implementing functions for |
430 | * set union. | 437 | * set union. |
438 | * | ||
439 | * @return the operation specific VTable | ||
431 | */ | 440 | */ |
432 | const struct SetVT * | 441 | const struct SetVT * |
433 | _GSS_union_vt (void); | 442 | _GSS_union_vt (void); |
@@ -436,6 +445,8 @@ _GSS_union_vt (void); | |||
436 | /** | 445 | /** |
437 | * Get the table with implementing functions for | 446 | * Get the table with implementing functions for |
438 | * set intersection. | 447 | * set intersection. |
448 | * | ||
449 | * @return the operation specific VTable | ||
439 | */ | 450 | */ |
440 | const struct SetVT * | 451 | const struct SetVT * |
441 | _GSS_intersection_vt (void); | 452 | _GSS_intersection_vt (void); |
diff --git a/src/set/gnunet-service-set_intersection.c b/src/set/gnunet-service-set_intersection.c index 0e0450bd1..de5198b9c 100644 --- a/src/set/gnunet-service-set_intersection.c +++ b/src/set/gnunet-service-set_intersection.c | |||
@@ -58,22 +58,6 @@ enum IntersectionOperationPhase | |||
58 | struct OperationState | 58 | struct OperationState |
59 | { | 59 | { |
60 | /** | 60 | /** |
61 | * Tunnel to the remote peer. | ||
62 | */ | ||
63 | struct GNUNET_MESH_Tunnel *tunnel; | ||
64 | |||
65 | /** | ||
66 | * Detail information about the set operation, | ||
67 | * including the set to use. | ||
68 | */ | ||
69 | struct OperationSpecification *spec; | ||
70 | |||
71 | /** | ||
72 | * Message queue for the peer. | ||
73 | */ | ||
74 | struct GNUNET_MQ_Handle *mq; | ||
75 | |||
76 | /** | ||
77 | * The bf we currently receive | 61 | * The bf we currently receive |
78 | */ | 62 | */ |
79 | struct GNUNET_CONTAINER_BloomFilter *remote_bf; | 63 | struct GNUNET_CONTAINER_BloomFilter *remote_bf; |
@@ -93,12 +77,6 @@ struct OperationState | |||
93 | * was created. | 77 | * was created. |
94 | */ | 78 | */ |
95 | unsigned int generation_created; | 79 | unsigned int generation_created; |
96 | |||
97 | /** | ||
98 | * Set state of the set that this operation | ||
99 | * belongs to. | ||
100 | */ | ||
101 | struct Set *set; | ||
102 | 80 | ||
103 | /** | 81 | /** |
104 | * Maps element-id-hashes to 'elements in our set'. | 82 | * Maps element-id-hashes to 'elements in our set'. |
@@ -134,24 +112,6 @@ struct OperationState | |||
134 | }; | 112 | }; |
135 | 113 | ||
136 | 114 | ||
137 | /** | ||
138 | * Extra state required for efficient set intersection. | ||
139 | */ | ||
140 | struct SetState | ||
141 | { | ||
142 | /** | ||
143 | * Evaluate operations are held in | ||
144 | * a linked list. | ||
145 | */ | ||
146 | struct OperationState *ops_head; | ||
147 | |||
148 | /** | ||
149 | * Evaluate operations are held in | ||
150 | * a linked list. | ||
151 | */ | ||
152 | struct OperationState *ops_tail; | ||
153 | }; | ||
154 | |||
155 | 115 | ||
156 | /** | 116 | /** |
157 | * Destroy a intersection operation, and free all resources | 117 | * Destroy a intersection operation, and free all resources |
@@ -739,7 +699,11 @@ finish_and_destroy (struct Operation *op) | |||
739 | send_done_and_destroy (op); | 699 | send_done_and_destroy (op); |
740 | } | 700 | } |
741 | 701 | ||
742 | 702 | /** | |
703 | * handler for peer-disconnects, notifies the client about the aborted operation | ||
704 | * | ||
705 | * @param op the destroyed operation | ||
706 | */ | ||
743 | static void | 707 | static void |
744 | intersection_peer_disconnect (struct Operation *op) | 708 | intersection_peer_disconnect (struct Operation *op) |
745 | { | 709 | { |
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index 6bd86c5b5..826071af8 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c | |||
@@ -74,22 +74,35 @@ enum UnionOperationPhase | |||
74 | */ | 74 | */ |
75 | PHASE_EXPECT_SE, | 75 | PHASE_EXPECT_SE, |
76 | /** | 76 | /** |
77 | * We sent the strata estimator, and expect an IBF | 77 | * We sent the strata estimator, and expect an IBF. This phase is entered once |
78 | * upon initialization and later via PHASE_EXPECT_ELEMENTS_AND_REQUESTS. | ||
79 | * | ||
80 | * After receiving the complete IBF, we enter PHASE_EXPECT_ELEMENTS | ||
78 | */ | 81 | */ |
79 | PHASE_EXPECT_IBF, | 82 | PHASE_EXPECT_IBF, |
80 | /** | 83 | /** |
81 | * We know what type of IBF the other peer wants to send us, | 84 | * Continuation for multi part IBFs. |
82 | * and expect the remaining parts | ||
83 | */ | 85 | */ |
84 | PHASE_EXPECT_IBF_CONT, | 86 | PHASE_EXPECT_IBF_CONT, |
85 | /** | 87 | /** |
86 | * We are sending request and elements, | 88 | * We are sending request and elements, |
87 | * and thus only expect elements from the other peer. | 89 | * and thus only expect elements from the other peer. |
90 | * | ||
91 | * We are currently decoding an IBF until it can no longer be decoded, | ||
92 | * we currently send requests and expect elements | ||
93 | * The remote peer is in PHASE_EXPECT_ELEMENTS_AND_REQUESTS | ||
88 | */ | 94 | */ |
89 | PHASE_EXPECT_ELEMENTS, | 95 | PHASE_EXPECT_ELEMENTS, |
90 | /** | 96 | /** |
91 | * We are expecting elements and requests, and send | 97 | * We are expecting elements and requests, and send |
92 | * requested elements back to the other peer. | 98 | * requested elements back to the other peer. |
99 | * | ||
100 | * We are in this phase if we have SENT an IBF for the remote peer to decode. | ||
101 | * We expect requests, send elements or could receive an new IBF, which takes | ||
102 | * us via PHASE_EXPECT_IBF to phase PHASE_EXPECT_ELEMENTS | ||
103 | * | ||
104 | * The remote peer is thus in: | ||
105 | * PHASE_EXPECT_ELEMENTS | ||
93 | */ | 106 | */ |
94 | PHASE_EXPECT_ELEMENTS_AND_REQUESTS, | 107 | PHASE_EXPECT_ELEMENTS_AND_REQUESTS, |
95 | /** | 108 | /** |
@@ -107,16 +120,6 @@ enum UnionOperationPhase | |||
107 | struct OperationState | 120 | struct OperationState |
108 | { | 121 | { |
109 | /** | 122 | /** |
110 | * Tunnel to the remote peer. | ||
111 | */ | ||
112 | struct GNUNET_MESH_Tunnel *tunnel; | ||
113 | |||
114 | /** | ||
115 | * Message queue for the peer. | ||
116 | */ | ||
117 | struct GNUNET_MQ_Handle *mq; | ||
118 | |||
119 | /** | ||
120 | * Number of ibf buckets received | 123 | * Number of ibf buckets received |
121 | */ | 124 | */ |
122 | unsigned int ibf_buckets_received; | 125 | unsigned int ibf_buckets_received; |
@@ -1195,6 +1198,7 @@ static void | |||
1195 | union_evaluate (struct Operation *op) | 1198 | union_evaluate (struct Operation *op) |
1196 | { | 1199 | { |
1197 | op->state = GNUNET_new (struct OperationState); | 1200 | op->state = GNUNET_new (struct OperationState); |
1201 | // copy the current generation's strata estimator for this operation | ||
1198 | op->state->se = strata_estimator_dup (op->spec->set->state->se); | 1202 | op->state->se = strata_estimator_dup (op->spec->set->state->se); |
1199 | /* we started the operation, thus we have to send the operation request */ | 1203 | /* we started the operation, thus we have to send the operation request */ |
1200 | op->state->phase = PHASE_EXPECT_SE; | 1204 | op->state->phase = PHASE_EXPECT_SE; |
@@ -1222,7 +1226,10 @@ union_accept (struct Operation *op) | |||
1222 | 1226 | ||
1223 | /** | 1227 | /** |
1224 | * Create a new set supporting the union operation | 1228 | * Create a new set supporting the union operation |
1225 | * | 1229 | * |
1230 | * We maintain one strata estimator per set and then manipulate it over the | ||
1231 | * lifetime of the set, as recreating a strata estimator would be expensive. | ||
1232 | * | ||
1226 | * @return the newly created set | 1233 | * @return the newly created set |
1227 | */ | 1234 | */ |
1228 | static struct SetState * | 1235 | static struct SetState * |
@@ -1321,7 +1328,12 @@ union_handle_p2p_message (struct Operation *op, | |||
1321 | return GNUNET_OK; | 1328 | return GNUNET_OK; |
1322 | } | 1329 | } |
1323 | 1330 | ||
1324 | 1331 | /** | |
1332 | * handler for peer-disconnects, notifies the client | ||
1333 | * about the aborted operation in case the op was not concluded | ||
1334 | * | ||
1335 | * @param op the destroyed operation | ||
1336 | */ | ||
1325 | static void | 1337 | static void |
1326 | union_peer_disconnect (struct Operation *op) | 1338 | union_peer_disconnect (struct Operation *op) |
1327 | { | 1339 | { |
@@ -1339,12 +1351,19 @@ union_peer_disconnect (struct Operation *op) | |||
1339 | _GSS_operation_destroy (op); | 1351 | _GSS_operation_destroy (op); |
1340 | return; | 1352 | return; |
1341 | } | 1353 | } |
1354 | // else: the session has already been concluded | ||
1342 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "other peer disconnected (finished)\n"); | 1355 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "other peer disconnected (finished)\n"); |
1343 | if (GNUNET_NO == op->state->client_done_sent) | 1356 | if (GNUNET_NO == op->state->client_done_sent) |
1344 | finish_and_destroy (op); | 1357 | finish_and_destroy (op); |
1345 | } | 1358 | } |
1346 | 1359 | ||
1347 | 1360 | ||
1361 | /** | ||
1362 | * Get the table with implementing functions for | ||
1363 | * set union. | ||
1364 | * | ||
1365 | * @return the operation specific VTable | ||
1366 | */ | ||
1348 | const struct SetVT * | 1367 | const struct SetVT * |
1349 | _GSS_union_vt () | 1368 | _GSS_union_vt () |
1350 | { | 1369 | { |