diff options
author | Gabor X Toth <*@tg-x.net> | 2016-01-15 22:12:29 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2016-01-15 22:12:29 +0000 |
commit | 377e7340cce5136867734fb19e89a5fc51ac0c99 (patch) | |
tree | 8dbf1f5ccec45b91367c32b67a031a7a73a4ab2d /src/psycutil | |
parent | 61e8794662ce2fc6ca669906822840a3743b4b78 (diff) | |
download | gnunet-377e7340cce5136867734fb19e89a5fc51ac0c99.tar.gz gnunet-377e7340cce5136867734fb19e89a5fc51ac0c99.zip |
social: set/clear msg proc flags
Diffstat (limited to 'src/psycutil')
-rw-r--r-- | src/psycutil/psyc_slicer.c | 101 |
1 files changed, 90 insertions, 11 deletions
diff --git a/src/psycutil/psyc_slicer.c b/src/psycutil/psyc_slicer.c index fe9912416..e372d3ae2 100644 --- a/src/psycutil/psyc_slicer.c +++ b/src/psycutil/psyc_slicer.c | |||
@@ -50,6 +50,11 @@ struct GNUNET_PSYC_Slicer | |||
50 | struct GNUNET_CONTAINER_MultiHashMap *modifier_handlers; | 50 | struct GNUNET_CONTAINER_MultiHashMap *modifier_handlers; |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * Receive handle for incoming messages. | ||
54 | */ | ||
55 | struct GNUNET_PSYC_ReceiveHandle *recv; | ||
56 | |||
57 | /** | ||
53 | * Currently being processed message part. | 58 | * Currently being processed message part. |
54 | */ | 59 | */ |
55 | const struct GNUNET_MessageHeader *msg; | 60 | const struct GNUNET_MessageHeader *msg; |
@@ -151,7 +156,7 @@ struct SlicerModifierRemoveClosure | |||
151 | /** | 156 | /** |
152 | * Call a method handler for an incoming message part. | 157 | * Call a method handler for an incoming message part. |
153 | */ | 158 | */ |
154 | int | 159 | static int |
155 | slicer_method_handler_notify (void *cls, const struct GNUNET_HashCode *key, | 160 | slicer_method_handler_notify (void *cls, const struct GNUNET_HashCode *key, |
156 | void *value) | 161 | void *value) |
157 | { | 162 | { |
@@ -229,7 +234,7 @@ slicer_method_handler_notify (void *cls, const struct GNUNET_HashCode *key, | |||
229 | /** | 234 | /** |
230 | * Call a method handler for an incoming message part. | 235 | * Call a method handler for an incoming message part. |
231 | */ | 236 | */ |
232 | int | 237 | static int |
233 | slicer_modifier_handler_notify (void *cls, const struct GNUNET_HashCode *key, | 238 | slicer_modifier_handler_notify (void *cls, const struct GNUNET_HashCode *key, |
234 | void *value) | 239 | void *value) |
235 | { | 240 | { |
@@ -244,6 +249,22 @@ slicer_modifier_handler_notify (void *cls, const struct GNUNET_HashCode *key, | |||
244 | 249 | ||
245 | 250 | ||
246 | /** | 251 | /** |
252 | * Process an incoming message and call matching handlers. | ||
253 | * | ||
254 | * @param slicer | ||
255 | * The slicer to use. | ||
256 | * @param msg | ||
257 | * The message as it arrived from the network. | ||
258 | */ | ||
259 | void | ||
260 | GNUNET_PSYC_slicer_message (struct GNUNET_PSYC_Slicer *slicer, | ||
261 | const struct GNUNET_PSYC_MessageHeader *msg) | ||
262 | { | ||
263 | GNUNET_PSYC_receive_message (slicer->recv, msg); | ||
264 | } | ||
265 | |||
266 | |||
267 | /** | ||
247 | * Process an incoming message part and call matching handlers. | 268 | * Process an incoming message part and call matching handlers. |
248 | * | 269 | * |
249 | * @param cls | 270 | * @param cls |
@@ -257,11 +278,13 @@ slicer_modifier_handler_notify (void *cls, const struct GNUNET_HashCode *key, | |||
257 | * The message part. as it arrived from the network. | 278 | * The message part. as it arrived from the network. |
258 | */ | 279 | */ |
259 | void | 280 | void |
260 | GNUNET_PSYC_slicer_message (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_pub_key, | 281 | GNUNET_PSYC_slicer_message_part (struct GNUNET_PSYC_Slicer *slicer, |
261 | uint64_t message_id, uint32_t flags, uint64_t fragment_offset, | 282 | const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_pub_key, |
262 | const struct GNUNET_MessageHeader *msg) | 283 | uint64_t message_id, |
284 | uint32_t flags, | ||
285 | uint64_t fragment_offset, | ||
286 | const struct GNUNET_MessageHeader *msg) | ||
263 | { | 287 | { |
264 | struct GNUNET_PSYC_Slicer *slicer = cls; | ||
265 | slicer->nym_pub_key = *slave_pub_key; | 288 | slicer->nym_pub_key = *slave_pub_key; |
266 | 289 | ||
267 | uint16_t ptype = ntohs (msg->type); | 290 | uint16_t ptype = ntohs (msg->type); |
@@ -381,6 +404,10 @@ GNUNET_PSYC_slicer_create (void) | |||
381 | struct GNUNET_PSYC_Slicer *slicer = GNUNET_malloc (sizeof (*slicer)); | 404 | struct GNUNET_PSYC_Slicer *slicer = GNUNET_malloc (sizeof (*slicer)); |
382 | slicer->method_handlers = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); | 405 | slicer->method_handlers = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); |
383 | slicer->modifier_handlers = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); | 406 | slicer->modifier_handlers = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); |
407 | slicer->recv = GNUNET_PSYC_receive_create (NULL, | ||
408 | (GNUNET_PSYC_MessagePartCallback) | ||
409 | GNUNET_PSYC_slicer_message_part, | ||
410 | slicer); | ||
384 | return slicer; | 411 | return slicer; |
385 | } | 412 | } |
386 | 413 | ||
@@ -430,7 +457,7 @@ GNUNET_PSYC_slicer_method_add (struct GNUNET_PSYC_Slicer *slicer, | |||
430 | } | 457 | } |
431 | 458 | ||
432 | 459 | ||
433 | int | 460 | static int |
434 | slicer_method_remove (void *cls, const struct GNUNET_HashCode *key, void *value) | 461 | slicer_method_remove (void *cls, const struct GNUNET_HashCode *key, void *value) |
435 | { | 462 | { |
436 | struct SlicerMethodRemoveClosure *rm_cls = cls; | 463 | struct SlicerMethodRemoveClosure *rm_cls = cls; |
@@ -531,7 +558,7 @@ GNUNET_PSYC_slicer_modifier_add (struct GNUNET_PSYC_Slicer *slicer, | |||
531 | } | 558 | } |
532 | 559 | ||
533 | 560 | ||
534 | int | 561 | static int |
535 | slicer_modifier_remove (void *cls, const struct GNUNET_HashCode *key, void *value) | 562 | slicer_modifier_remove (void *cls, const struct GNUNET_HashCode *key, void *value) |
536 | { | 563 | { |
537 | struct SlicerModifierRemoveClosure *rm_cls = cls; | 564 | struct SlicerModifierRemoveClosure *rm_cls = cls; |
@@ -585,7 +612,7 @@ GNUNET_PSYC_slicer_modifier_remove (struct GNUNET_PSYC_Slicer *slicer, | |||
585 | } | 612 | } |
586 | 613 | ||
587 | 614 | ||
588 | int | 615 | static int |
589 | slicer_method_free (void *cls, const struct GNUNET_HashCode *key, void *value) | 616 | slicer_method_free (void *cls, const struct GNUNET_HashCode *key, void *value) |
590 | { | 617 | { |
591 | struct SlicerMethodCallbacks *cbs = value; | 618 | struct SlicerMethodCallbacks *cbs = value; |
@@ -594,6 +621,57 @@ slicer_method_free (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
594 | } | 621 | } |
595 | 622 | ||
596 | 623 | ||
624 | static int | ||
625 | slicer_modifier_free (void *cls, const struct GNUNET_HashCode *key, void *value) | ||
626 | { | ||
627 | struct SlicerModifierCallbacks *cbs = value; | ||
628 | GNUNET_free (cbs); | ||
629 | return GNUNET_YES; | ||
630 | } | ||
631 | |||
632 | |||
633 | /** | ||
634 | * Remove all registered method handlers. | ||
635 | * | ||
636 | * @param slicer | ||
637 | * Slicer to clear. | ||
638 | */ | ||
639 | void | ||
640 | GNUNET_PSYC_slicer_method_clear (struct GNUNET_PSYC_Slicer *slicer) | ||
641 | { | ||
642 | GNUNET_CONTAINER_multihashmap_iterate (slicer->method_handlers, | ||
643 | slicer_method_free, NULL); | ||
644 | } | ||
645 | |||
646 | |||
647 | /** | ||
648 | * Remove all registered modifier handlers. | ||
649 | * | ||
650 | * @param slicer | ||
651 | * Slicer to clear. | ||
652 | */ | ||
653 | void | ||
654 | GNUNET_PSYC_slicer_modifier_clear (struct GNUNET_PSYC_Slicer *slicer) | ||
655 | { | ||
656 | GNUNET_CONTAINER_multihashmap_iterate (slicer->modifier_handlers, | ||
657 | slicer_modifier_free, NULL); | ||
658 | } | ||
659 | |||
660 | |||
661 | /** | ||
662 | * Remove all registered method & modifier handlers. | ||
663 | * | ||
664 | * @param slicer | ||
665 | * Slicer to clear. | ||
666 | */ | ||
667 | void | ||
668 | GNUNET_PSYC_slicer_clear (struct GNUNET_PSYC_Slicer *slicer) | ||
669 | { | ||
670 | GNUNET_PSYC_slicer_method_clear (slicer); | ||
671 | GNUNET_PSYC_slicer_modifier_clear (slicer); | ||
672 | } | ||
673 | |||
674 | |||
597 | /** | 675 | /** |
598 | * Destroy a given try-and-slice instance. | 676 | * Destroy a given try-and-slice instance. |
599 | * | 677 | * |
@@ -603,8 +681,9 @@ slicer_method_free (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
603 | void | 681 | void |
604 | GNUNET_PSYC_slicer_destroy (struct GNUNET_PSYC_Slicer *slicer) | 682 | GNUNET_PSYC_slicer_destroy (struct GNUNET_PSYC_Slicer *slicer) |
605 | { | 683 | { |
606 | GNUNET_CONTAINER_multihashmap_iterate (slicer->method_handlers, | 684 | GNUNET_PSYC_slicer_clear (slicer); |
607 | slicer_method_free, NULL); | ||
608 | GNUNET_CONTAINER_multihashmap_destroy (slicer->method_handlers); | 685 | GNUNET_CONTAINER_multihashmap_destroy (slicer->method_handlers); |
686 | GNUNET_CONTAINER_multihashmap_destroy (slicer->modifier_handlers); | ||
687 | GNUNET_PSYC_receive_destroy (slicer->recv); | ||
609 | GNUNET_free (slicer); | 688 | GNUNET_free (slicer); |
610 | } | 689 | } |