diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-11-27 11:56:28 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-11-27 11:56:28 +0000 |
commit | ce9b32618b6ee488352ef0eb506c744868145f82 (patch) | |
tree | dde0f1de9dfec7d3814a29cfb5b252a79a64d726 /src/set | |
parent | 2b0e3f9ba871095d003fc078eee75b5eda6fc8b8 (diff) | |
download | gnunet-ce9b32618b6ee488352ef0eb506c744868145f82.tar.gz gnunet-ce9b32618b6ee488352ef0eb506c744868145f82.zip |
clean up internal set API, avoid copying context message needlessly
Diffstat (limited to 'src/set')
-rw-r--r-- | src/set/gnunet-service-set.c | 32 | ||||
-rw-r--r-- | src/set/gnunet-service-set.h | 26 | ||||
-rw-r--r-- | src/set/gnunet-service-set_intersection.c | 81 | ||||
-rw-r--r-- | src/set/gnunet-service-set_union.c | 81 | ||||
-rw-r--r-- | src/set/set.h | 3 | ||||
-rw-r--r-- | src/set/set_api.c | 43 |
6 files changed, 125 insertions, 141 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index c3c0d34f6..97ee1480d 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c | |||
@@ -549,7 +549,7 @@ incoming_suggest (struct Operation *incoming, | |||
549 | incoming->spec->context_msg); | 549 | incoming->spec->context_msg); |
550 | GNUNET_assert (NULL != mqm); | 550 | GNUNET_assert (NULL != mqm); |
551 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 551 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
552 | "suggesting request with accept id %u\n", | 552 | "Suggesting incoming request with accept id %u to listener\n", |
553 | incoming->suggest_id); | 553 | incoming->suggest_id); |
554 | cmsg->accept_id = htonl (incoming->suggest_id); | 554 | cmsg->accept_id = htonl (incoming->suggest_id); |
555 | cmsg->peer_id = incoming->spec->peer; | 555 | cmsg->peer_id = incoming->spec->peer; |
@@ -581,6 +581,7 @@ handle_incoming_msg (struct Operation *op, | |||
581 | const struct OperationRequestMessage *msg; | 581 | const struct OperationRequestMessage *msg; |
582 | struct Listener *listener; | 582 | struct Listener *listener; |
583 | struct OperationSpecification *spec; | 583 | struct OperationSpecification *spec; |
584 | const struct GNUNET_MessageHeader *nested_context; | ||
584 | 585 | ||
585 | msg = (const struct OperationRequestMessage *) mh; | 586 | msg = (const struct OperationRequestMessage *) mh; |
586 | GNUNET_assert (GNUNET_YES == op->is_incoming); | 587 | GNUNET_assert (GNUNET_YES == op->is_incoming); |
@@ -596,17 +597,19 @@ handle_incoming_msg (struct Operation *op, | |||
596 | return GNUNET_SYSERR; | 597 | return GNUNET_SYSERR; |
597 | } | 598 | } |
598 | spec = GNUNET_new (struct OperationSpecification); | 599 | spec = GNUNET_new (struct OperationSpecification); |
599 | spec->context_msg = GNUNET_MQ_extract_nested_mh (msg); | 600 | nested_context = GNUNET_MQ_extract_nested_mh (msg); |
600 | /* for simplicity we just backup the context msg instead of rebuilding it later on */ | 601 | if ( (NULL != nested_context) && |
601 | if ( (NULL != spec->context_msg) && | 602 | (ntohs (nested_context->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE) ) |
602 | (ntohs (spec->context_msg->size) > GNUNET_SET_CONTEXT_MESSAGE_MAX_SIZE) ) | ||
603 | { | 603 | { |
604 | GNUNET_break_op (0); | 604 | GNUNET_break_op (0); |
605 | GNUNET_free (spec); | 605 | GNUNET_free (spec); |
606 | return GNUNET_SYSERR; | 606 | return GNUNET_SYSERR; |
607 | } | 607 | } |
608 | /* Make a copy of the nested_context (application-specific context | ||
609 | information that is opaque to set) so we can pass it to the | ||
610 | listener later on */ | ||
608 | if (NULL != spec->context_msg) | 611 | if (NULL != spec->context_msg) |
609 | spec->context_msg = GNUNET_copy_message (spec->context_msg); | 612 | spec->context_msg = GNUNET_copy_message (nested_context); |
610 | spec->operation = ntohl (msg->operation); | 613 | spec->operation = ntohl (msg->operation); |
611 | spec->app_id = msg->app_id; | 614 | spec->app_id = msg->app_id; |
612 | spec->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 615 | spec->salt = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
@@ -994,7 +997,9 @@ handle_client_remove (void *cls, | |||
994 | 997 | ||
995 | 998 | ||
996 | /** | 999 | /** |
997 | * Called when a client wants to evaluate a set operation with another peer. | 1000 | * Called when a client wants to evaluate a set operation with another |
1001 | * peer. Initiates the CADET connection to the listener and sends the | ||
1002 | * request. | ||
998 | * | 1003 | * |
999 | * @param cls unused | 1004 | * @param cls unused |
1000 | * @param client client that sent the message | 1005 | * @param client client that sent the message |
@@ -1018,7 +1023,6 @@ handle_client_evaluate (void *cls, | |||
1018 | GNUNET_SERVER_client_disconnect (client); | 1023 | GNUNET_SERVER_client_disconnect (client); |
1019 | return; | 1024 | return; |
1020 | } | 1025 | } |
1021 | |||
1022 | msg = (const struct GNUNET_SET_EvaluateMessage *) m; | 1026 | msg = (const struct GNUNET_SET_EvaluateMessage *) m; |
1023 | spec = GNUNET_new (struct OperationSpecification); | 1027 | spec = GNUNET_new (struct OperationSpecification); |
1024 | spec->operation = set->operation; | 1028 | spec->operation = set->operation; |
@@ -1030,13 +1034,6 @@ handle_client_evaluate (void *cls, | |||
1030 | spec->result_mode = ntohs (msg->result_mode); | 1034 | spec->result_mode = ntohs (msg->result_mode); |
1031 | spec->client_request_id = ntohl (msg->request_id); | 1035 | spec->client_request_id = ntohl (msg->request_id); |
1032 | context = GNUNET_MQ_extract_nested_mh (msg); | 1036 | context = GNUNET_MQ_extract_nested_mh (msg); |
1033 | /* The evaluate message MAY contain a nested message to be passed to | ||
1034 | the listner for additional authentication or application-specific | ||
1035 | context. We make a copy of this nested/context msg as we need | ||
1036 | to transmit it later. */ | ||
1037 | if (NULL != context) | ||
1038 | spec->context_msg = GNUNET_copy_message (context); | ||
1039 | |||
1040 | op = GNUNET_new (struct Operation); | 1037 | op = GNUNET_new (struct Operation); |
1041 | op->spec = spec; | 1038 | op->spec = spec; |
1042 | op->generation_created = set->current_generation++; | 1039 | op->generation_created = set->current_generation++; |
@@ -1044,14 +1041,14 @@ handle_client_evaluate (void *cls, | |||
1044 | GNUNET_CONTAINER_DLL_insert (set->ops_head, | 1041 | GNUNET_CONTAINER_DLL_insert (set->ops_head, |
1045 | set->ops_tail, | 1042 | set->ops_tail, |
1046 | op); | 1043 | op); |
1047 | |||
1048 | op->channel = GNUNET_CADET_channel_create (cadet, | 1044 | op->channel = GNUNET_CADET_channel_create (cadet, |
1049 | op, | 1045 | op, |
1050 | &msg->target_peer, | 1046 | &msg->target_peer, |
1051 | GNUNET_APPLICATION_TYPE_SET, | 1047 | GNUNET_APPLICATION_TYPE_SET, |
1052 | GNUNET_CADET_OPTION_RELIABLE); | 1048 | GNUNET_CADET_OPTION_RELIABLE); |
1053 | op->mq = GNUNET_CADET_mq_create (op->channel); | 1049 | op->mq = GNUNET_CADET_mq_create (op->channel); |
1054 | set->vt->evaluate (op); | 1050 | set->vt->evaluate (op, |
1051 | context); | ||
1055 | GNUNET_SERVER_receive_done (client, | 1052 | GNUNET_SERVER_receive_done (client, |
1056 | GNUNET_OK); | 1053 | GNUNET_OK); |
1057 | } | 1054 | } |
@@ -1226,7 +1223,6 @@ handle_client_accept (void *cls, | |||
1226 | op->spec->result_mode = ntohl (msg->result_mode); | 1223 | op->spec->result_mode = ntohl (msg->result_mode); |
1227 | op->generation_created = set->current_generation++; | 1224 | op->generation_created = set->current_generation++; |
1228 | op->vt = op->spec->set->vt; | 1225 | op->vt = op->spec->set->vt; |
1229 | GNUNET_assert (NULL != op->vt->accept); | ||
1230 | set->vt->accept (op); | 1226 | set->vt->accept (op); |
1231 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1227 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1232 | } | 1228 | } |
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h index 834f78780..448ed9478 100644 --- a/src/set/gnunet-service-set.h +++ b/src/set/gnunet-service-set.h | |||
@@ -165,13 +165,27 @@ typedef void | |||
165 | 165 | ||
166 | 166 | ||
167 | /** | 167 | /** |
168 | * Signature of functions that implement the creation of set operations | 168 | * Signature of functions that implement accepting a set operation. |
169 | * (currently "evaluate" and "accept"). | ||
170 | * | 169 | * |
171 | * @param op operation that is created, should be initialized by the implementation | 170 | * @param op operation that is created by accepting the operation, |
171 | * should be initialized by the implementation | ||
172 | */ | 172 | */ |
173 | typedef void | 173 | typedef void |
174 | (*OpCreateImpl) (struct Operation *op); | 174 | (*OpAcceptImpl) (struct Operation *op); |
175 | |||
176 | |||
177 | /** | ||
178 | * Signature of functions that implement starting the evaluation of | ||
179 | * set operations. | ||
180 | * | ||
181 | * @param op operation that is created, should be initialized to | ||
182 | * begin the evaluation | ||
183 | * @param opaque_context message to be transmitted to the listener | ||
184 | * to convince him to accept, may be NULL | ||
185 | */ | ||
186 | typedef void | ||
187 | (*OpEvaluateImpl) (struct Operation *op, | ||
188 | const struct GNUNET_MessageHeader *opaque_context); | ||
175 | 189 | ||
176 | 190 | ||
177 | /** | 191 | /** |
@@ -221,12 +235,12 @@ struct SetVT | |||
221 | /** | 235 | /** |
222 | * Callback for accepting a set operation request | 236 | * Callback for accepting a set operation request |
223 | */ | 237 | */ |
224 | OpCreateImpl accept; | 238 | OpAcceptImpl accept; |
225 | 239 | ||
226 | /** | 240 | /** |
227 | * Callback for starting evaluation with a remote peer. | 241 | * Callback for starting evaluation with a remote peer. |
228 | */ | 242 | */ |
229 | OpCreateImpl evaluate; | 243 | OpEvaluateImpl evaluate; |
230 | 244 | ||
231 | /** | 245 | /** |
232 | * Callback for destruction of the set state. | 246 | * Callback for destruction of the set state. |
diff --git a/src/set/gnunet-service-set_intersection.c b/src/set/gnunet-service-set_intersection.c index 70c3fb450..734783137 100644 --- a/src/set/gnunet-service-set_intersection.c +++ b/src/set/gnunet-service-set_intersection.c | |||
@@ -362,49 +362,6 @@ fail_intersection_operation (struct Operation *op) | |||
362 | } | 362 | } |
363 | 363 | ||
364 | 364 | ||
365 | /** | ||
366 | * Send a request for the evaluate operation to a remote peer | ||
367 | * | ||
368 | * @param op operation with the other peer | ||
369 | */ | ||
370 | static void | ||
371 | send_operation_request (struct Operation *op) | ||
372 | { | ||
373 | struct GNUNET_MQ_Envelope *ev; | ||
374 | struct OperationRequestMessage *msg; | ||
375 | |||
376 | ev = GNUNET_MQ_msg_nested_mh (msg, GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, | ||
377 | op->spec->context_msg); | ||
378 | |||
379 | if (NULL == ev) | ||
380 | { | ||
381 | /* the context message is too large */ | ||
382 | GNUNET_break (0); | ||
383 | GNUNET_SERVER_client_disconnect (op->spec->set->client); | ||
384 | return; | ||
385 | } | ||
386 | msg->operation = htonl (GNUNET_SET_OPERATION_INTERSECTION); | ||
387 | msg->app_id = op->spec->app_id; | ||
388 | msg->salt = htonl (op->spec->salt); | ||
389 | msg->element_count = htonl(op->state->my_element_count); | ||
390 | |||
391 | GNUNET_MQ_send (op->mq, ev); | ||
392 | |||
393 | if (NULL != op->spec->context_msg) | ||
394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
395 | "sent op request with context message\n"); | ||
396 | else | ||
397 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
398 | "sent op request without context message\n"); | ||
399 | |||
400 | if (NULL != op->spec->context_msg) | ||
401 | { | ||
402 | GNUNET_free (op->spec->context_msg); | ||
403 | op->spec->context_msg = NULL; | ||
404 | } | ||
405 | } | ||
406 | |||
407 | |||
408 | static void | 365 | static void |
409 | send_bloomfilter_multipart (struct Operation *op, | 366 | send_bloomfilter_multipart (struct Operation *op, |
410 | uint32_t offset) | 367 | uint32_t offset) |
@@ -877,14 +834,20 @@ handle_p2p_done (void *cls, | |||
877 | 834 | ||
878 | 835 | ||
879 | /** | 836 | /** |
880 | * Evaluate a union operation with | 837 | * Initiate a set union operation with a remote peer. |
881 | * a remote peer. | ||
882 | * | 838 | * |
883 | * @param op operation to evaluate | 839 | * @param op operation that is created, should be initialized to |
840 | * begin the evaluation | ||
841 | * @param opaque_context message to be transmitted to the listener | ||
842 | * to convince him to accept, may be NULL | ||
884 | */ | 843 | */ |
885 | static void | 844 | static void |
886 | intersection_evaluate (struct Operation *op) | 845 | intersection_evaluate (struct Operation *op, |
846 | const struct GNUNET_MessageHeader *opaque_context) | ||
887 | { | 847 | { |
848 | struct GNUNET_MQ_Envelope *ev; | ||
849 | struct OperationRequestMessage *msg; | ||
850 | |||
888 | op->state = GNUNET_new (struct OperationState); | 851 | op->state = GNUNET_new (struct OperationState); |
889 | /* we started the operation, thus we have to send the operation request */ | 852 | /* we started the operation, thus we have to send the operation request */ |
890 | op->state->phase = PHASE_INITIAL; | 853 | op->state->phase = PHASE_INITIAL; |
@@ -892,8 +855,28 @@ intersection_evaluate (struct Operation *op) | |||
892 | op->state->my_element_count = op->spec->set->state->current_set_element_count; | 855 | op->state->my_element_count = op->spec->set->state->current_set_element_count; |
893 | 856 | ||
894 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 857 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
895 | "evaluating intersection operation"); | 858 | "Initiating intersection operation evaluation"); |
896 | send_operation_request (op); | 859 | ev = GNUNET_MQ_msg_nested_mh (msg, |
860 | GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, | ||
861 | opaque_context); | ||
862 | if (NULL == ev) | ||
863 | { | ||
864 | /* the context message is too large */ | ||
865 | GNUNET_break (0); | ||
866 | GNUNET_SERVER_client_disconnect (op->spec->set->client); | ||
867 | return; | ||
868 | } | ||
869 | msg->operation = htonl (GNUNET_SET_OPERATION_INTERSECTION); | ||
870 | msg->app_id = op->spec->app_id; | ||
871 | msg->salt = htonl (op->spec->salt); | ||
872 | msg->element_count = htonl(op->state->my_element_count); | ||
873 | GNUNET_MQ_send (op->mq, ev); | ||
874 | if (NULL != opaque_context) | ||
875 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
876 | "sent op request with context message\n"); | ||
877 | else | ||
878 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
879 | "sent op request without context message\n"); | ||
897 | } | 880 | } |
898 | 881 | ||
899 | 882 | ||
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c index 88b8856b0..5926b25f5 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c | |||
@@ -345,47 +345,6 @@ get_ibf_key (const struct GNUNET_HashCode *src, uint16_t salt) | |||
345 | 345 | ||
346 | 346 | ||
347 | /** | 347 | /** |
348 | * Send a request for the evaluate operation to a remote peer | ||
349 | * | ||
350 | * @param op operation with the other peer | ||
351 | */ | ||
352 | static void | ||
353 | send_operation_request (struct Operation *op) | ||
354 | { | ||
355 | struct GNUNET_MQ_Envelope *ev; | ||
356 | struct OperationRequestMessage *msg; | ||
357 | |||
358 | ev = GNUNET_MQ_msg_nested_mh (msg, | ||
359 | GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, | ||
360 | op->spec->context_msg); | ||
361 | |||
362 | if (NULL == ev) | ||
363 | { | ||
364 | /* the context message is too large */ | ||
365 | GNUNET_break (0); | ||
366 | GNUNET_SERVER_client_disconnect (op->spec->set->client); | ||
367 | return; | ||
368 | } | ||
369 | msg->operation = htonl (GNUNET_SET_OPERATION_UNION); | ||
370 | msg->app_id = op->spec->app_id; | ||
371 | msg->salt = htonl (op->spec->salt); | ||
372 | GNUNET_MQ_send (op->mq, ev); | ||
373 | |||
374 | if (NULL != op->spec->context_msg) | ||
375 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
376 | "sent op request with context message\n"); | ||
377 | else | ||
378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
379 | "sent op request without context message\n"); | ||
380 | if (NULL != op->spec->context_msg) | ||
381 | { | ||
382 | GNUNET_free (op->spec->context_msg); | ||
383 | op->spec->context_msg = NULL; | ||
384 | } | ||
385 | } | ||
386 | |||
387 | |||
388 | /** | ||
389 | * Iterator to create the mapping between ibf keys | 348 | * Iterator to create the mapping between ibf keys |
390 | * and element entries. | 349 | * and element entries. |
391 | * | 350 | * |
@@ -1209,21 +1168,47 @@ handle_p2p_done (void *cls, const struct GNUNET_MessageHeader *mh) | |||
1209 | 1168 | ||
1210 | 1169 | ||
1211 | /** | 1170 | /** |
1212 | * Evaluate a union operation with | 1171 | * Initiate operation to evaluate a set union with a remote peer. |
1213 | * a remote peer. | ||
1214 | * | 1172 | * |
1215 | * @param op operation to evaluate | 1173 | * @param op operation to perform (to be initialized) |
1174 | * @param opaque_context message to be transmitted to the listener | ||
1175 | * to convince him to accept, may be NULL | ||
1216 | */ | 1176 | */ |
1217 | static void | 1177 | static void |
1218 | union_evaluate (struct Operation *op) | 1178 | union_evaluate (struct Operation *op, |
1179 | const struct GNUNET_MessageHeader *opaque_context) | ||
1219 | { | 1180 | { |
1181 | struct GNUNET_MQ_Envelope *ev; | ||
1182 | struct OperationRequestMessage *msg; | ||
1183 | |||
1220 | op->state = GNUNET_new (struct OperationState); | 1184 | op->state = GNUNET_new (struct OperationState); |
1221 | // copy the current generation's strata estimator for this operation | 1185 | /* copy the current generation's strata estimator for this operation */ |
1222 | op->state->se = strata_estimator_dup (op->spec->set->state->se); | 1186 | op->state->se = strata_estimator_dup (op->spec->set->state->se); |
1223 | /* we started the operation, thus we have to send the operation request */ | 1187 | /* we started the operation, thus we have to send the operation request */ |
1224 | op->state->phase = PHASE_EXPECT_SE; | 1188 | op->state->phase = PHASE_EXPECT_SE; |
1225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "evaluating union operation\n"); | 1189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1226 | send_operation_request (op); | 1190 | "Initiating union operation evaluation\n"); |
1191 | ev = GNUNET_MQ_msg_nested_mh (msg, | ||
1192 | GNUNET_MESSAGE_TYPE_SET_P2P_OPERATION_REQUEST, | ||
1193 | opaque_context); | ||
1194 | if (NULL == ev) | ||
1195 | { | ||
1196 | /* the context message is too large */ | ||
1197 | GNUNET_break (0); | ||
1198 | GNUNET_SERVER_client_disconnect (op->spec->set->client); | ||
1199 | return; | ||
1200 | } | ||
1201 | msg->operation = htonl (GNUNET_SET_OPERATION_UNION); | ||
1202 | msg->app_id = op->spec->app_id; | ||
1203 | msg->salt = htonl (op->spec->salt); | ||
1204 | GNUNET_MQ_send (op->mq, ev); | ||
1205 | |||
1206 | if (NULL != opaque_context) | ||
1207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1208 | "sent op request with context message\n"); | ||
1209 | else | ||
1210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1211 | "sent op request without context message\n"); | ||
1227 | } | 1212 | } |
1228 | 1213 | ||
1229 | 1214 | ||
diff --git a/src/set/set.h b/src/set/set.h index f3aedff4f..b470ebf92 100644 --- a/src/set/set.h +++ b/src/set/set.h | |||
@@ -150,7 +150,8 @@ struct GNUNET_SET_RequestMessage | |||
150 | */ | 150 | */ |
151 | struct GNUNET_PeerIdentity peer_id; | 151 | struct GNUNET_PeerIdentity peer_id; |
152 | 152 | ||
153 | /* rest: nested context message */ | 153 | /* rest: context message, that is, application-specific |
154 | message to convince listener to pick up */ | ||
154 | }; | 155 | }; |
155 | 156 | ||
156 | 157 | ||
diff --git a/src/set/set_api.c b/src/set/set_api.c index ff0c959e4..90cba446c 100644 --- a/src/set/set_api.c +++ b/src/set/set_api.c | |||
@@ -402,18 +402,16 @@ set_destroy (struct GNUNET_SET_Handle *set) | |||
402 | } | 402 | } |
403 | 403 | ||
404 | 404 | ||
405 | |||
406 | |||
407 | /** | 405 | /** |
408 | * Cancel the given set operation. We need to send an explicit cancel message, | 406 | * Cancel the given set operation. We need to send an explicit cancel message, |
409 | * as all operations one one set communicate using one handle. | 407 | * as all operations one one set communicate using one handle. |
410 | * | 408 | * |
411 | * In contrast to GNUNET_SET_operation_cancel, this function indicates whether | 409 | * In contrast to #GNUNET_SET_operation_cancel(), this function indicates whether |
412 | * the set of the operation has been destroyed because all operations are done and | 410 | * the set of the operation has been destroyed because all operations are done and |
413 | * the set's destruction was requested before. | 411 | * the set's destruction was requested before. |
414 | * | 412 | * |
415 | * @param oh set operation to cancel | 413 | * @param oh set operation to cancel |
416 | * @return GNUNET_YES if the set of the operation was destroyed | 414 | * @return #GNUNET_YES if the set of the operation was destroyed |
417 | */ | 415 | */ |
418 | static int | 416 | static int |
419 | set_operation_cancel (struct GNUNET_SET_OperationHandle *oh) | 417 | set_operation_cancel (struct GNUNET_SET_OperationHandle *oh) |
@@ -430,8 +428,11 @@ set_operation_cancel (struct GNUNET_SET_OperationHandle *oh) | |||
430 | struct GNUNET_SET_CancelMessage *m; | 428 | struct GNUNET_SET_CancelMessage *m; |
431 | struct GNUNET_MQ_Envelope *mqm; | 429 | struct GNUNET_MQ_Envelope *mqm; |
432 | 430 | ||
433 | GNUNET_CONTAINER_DLL_remove (oh->set->ops_head, oh->set->ops_tail, oh); | 431 | GNUNET_CONTAINER_DLL_remove (oh->set->ops_head, |
434 | h_assoc = GNUNET_MQ_assoc_remove (oh->set->mq, oh->request_id); | 432 | oh->set->ops_tail, |
433 | oh); | ||
434 | h_assoc = GNUNET_MQ_assoc_remove (oh->set->mq, | ||
435 | oh->request_id); | ||
435 | GNUNET_assert ((h_assoc == NULL) || (h_assoc == oh)); | 436 | GNUNET_assert ((h_assoc == NULL) || (h_assoc == oh)); |
436 | mqm = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_SET_CANCEL); | 437 | mqm = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_SET_CANCEL); |
437 | m->request_id = htonl (oh->request_id); | 438 | m->request_id = htonl (oh->request_id); |
@@ -439,20 +440,20 @@ set_operation_cancel (struct GNUNET_SET_OperationHandle *oh) | |||
439 | 440 | ||
440 | if (GNUNET_YES == oh->set->destroy_requested) | 441 | if (GNUNET_YES == oh->set->destroy_requested) |
441 | { | 442 | { |
442 | LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying set after operation cancel\n"); | 443 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
444 | "Destroying set after operation cancel\n"); | ||
443 | ret = set_destroy (oh->set); | 445 | ret = set_destroy (oh->set); |
444 | } | 446 | } |
445 | } | 447 | } |
446 | |||
447 | GNUNET_free (oh); | 448 | GNUNET_free (oh); |
448 | |||
449 | return ret; | 449 | return ret; |
450 | } | 450 | } |
451 | 451 | ||
452 | 452 | ||
453 | /** | 453 | /** |
454 | * Cancel the given set operation. We need to send an explicit cancel message, | 454 | * Cancel the given set operation. We need to send an explicit cancel |
455 | * as all operations one one set communicate using one handle. | 455 | * message, as all operations one one set communicate using one |
456 | * handle. | ||
456 | * | 457 | * |
457 | * @param oh set operation to cancel | 458 | * @param oh set operation to cancel |
458 | */ | 459 | */ |
@@ -468,7 +469,8 @@ handle_client_set_error (void *cls, enum GNUNET_MQ_Error error) | |||
468 | { | 469 | { |
469 | struct GNUNET_SET_Handle *set = cls; | 470 | struct GNUNET_SET_Handle *set = cls; |
470 | 471 | ||
471 | LOG (GNUNET_ERROR_TYPE_DEBUG, "handling client set error\n"); | 472 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
473 | "handling client set error\n"); | ||
472 | 474 | ||
473 | while (NULL != set->ops_head) | 475 | while (NULL != set->ops_head) |
474 | { | 476 | { |
@@ -588,7 +590,9 @@ GNUNET_SET_remove_element (struct GNUNET_SET_Handle *set, | |||
588 | return GNUNET_SYSERR; | 590 | return GNUNET_SYSERR; |
589 | } | 591 | } |
590 | 592 | ||
591 | mqm = GNUNET_MQ_msg_extra (msg, element->size, GNUNET_MESSAGE_TYPE_SET_REMOVE); | 593 | mqm = GNUNET_MQ_msg_extra (msg, |
594 | element->size, | ||
595 | GNUNET_MESSAGE_TYPE_SET_REMOVE); | ||
592 | msg->element_type = element->element_type; | 596 | msg->element_type = element->element_type; |
593 | memcpy (&msg[1], element->data, element->size); | 597 | memcpy (&msg[1], element->data, element->size); |
594 | GNUNET_MQ_notify_sent (mqm, cont, cont_cls); | 598 | GNUNET_MQ_notify_sent (mqm, cont, cont_cls); |
@@ -842,13 +846,15 @@ GNUNET_SET_commit (struct GNUNET_SET_OperationHandle *oh, | |||
842 | * | 846 | * |
843 | * @param set the set to iterate over | 847 | * @param set the set to iterate over |
844 | * @param iter the iterator to call for each element | 848 | * @param iter the iterator to call for each element |
845 | * @param cls closure for @a iter | 849 | * @param iter_cls closure for @a iter |
846 | * @return #GNUNET_YES if the iteration started successfuly, | 850 | * @return #GNUNET_YES if the iteration started successfuly, |
847 | * #GNUNET_NO if another iteration is active | 851 | * #GNUNET_NO if another iteration is active |
848 | * #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected) | 852 | * #GNUNET_SYSERR if the set is invalid (e.g. the server crashed, disconnected) |
849 | */ | 853 | */ |
850 | int | 854 | int |
851 | GNUNET_SET_iterate (struct GNUNET_SET_Handle *set, GNUNET_SET_ElementIterator iter, void *cls) | 855 | GNUNET_SET_iterate (struct GNUNET_SET_Handle *set, |
856 | GNUNET_SET_ElementIterator iter, | ||
857 | void *iter_cls) | ||
852 | { | 858 | { |
853 | struct GNUNET_MQ_Envelope *ev; | 859 | struct GNUNET_MQ_Envelope *ev; |
854 | 860 | ||
@@ -859,11 +865,10 @@ GNUNET_SET_iterate (struct GNUNET_SET_Handle *set, GNUNET_SET_ElementIterator it | |||
859 | return GNUNET_SYSERR; | 865 | return GNUNET_SYSERR; |
860 | if (NULL != set->iterator) | 866 | if (NULL != set->iterator) |
861 | return GNUNET_NO; | 867 | return GNUNET_NO; |
862 | 868 | LOG (GNUNET_ERROR_TYPE_DEBUG, | |
863 | LOG (GNUNET_ERROR_TYPE_DEBUG, "iterating set\n"); | 869 | "iterating set\n"); |
864 | |||
865 | set->iterator = iter; | 870 | set->iterator = iter; |
866 | set->iterator_cls = cls; | 871 | set->iterator_cls = iter_cls; |
867 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST); | 872 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_SET_ITER_REQUEST); |
868 | GNUNET_MQ_send (set->mq, ev); | 873 | GNUNET_MQ_send (set->mq, ev); |
869 | return GNUNET_YES; | 874 | return GNUNET_YES; |