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) |
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 fe99124164..e372d3ae2d 100644 --- a/src/psycutil/psyc_slicer.c +++ b/src/psycutil/psyc_slicer.c @@ -50,6 +50,11 @@ struct GNUNET_PSYC_Slicer struct GNUNET_CONTAINER_MultiHashMap *modifier_handlers; /** + * Receive handle for incoming messages. + */ + struct GNUNET_PSYC_ReceiveHandle *recv; + + /** * Currently being processed message part. */ const struct GNUNET_MessageHeader *msg; @@ -151,7 +156,7 @@ struct SlicerModifierRemoveClosure /** * Call a method handler for an incoming message part. */ -int +static int slicer_method_handler_notify (void *cls, const struct GNUNET_HashCode *key, void *value) { @@ -229,7 +234,7 @@ slicer_method_handler_notify (void *cls, const struct GNUNET_HashCode *key, /** * Call a method handler for an incoming message part. */ -int +static int slicer_modifier_handler_notify (void *cls, const struct GNUNET_HashCode *key, void *value) { @@ -244,6 +249,22 @@ slicer_modifier_handler_notify (void *cls, const struct GNUNET_HashCode *key, /** + * Process an incoming message and call matching handlers. + * + * @param slicer + * The slicer to use. + * @param msg + * The message as it arrived from the network. + */ +void +GNUNET_PSYC_slicer_message (struct GNUNET_PSYC_Slicer *slicer, + const struct GNUNET_PSYC_MessageHeader *msg) +{ + GNUNET_PSYC_receive_message (slicer->recv, msg); +} + + +/** * Process an incoming message part and call matching handlers. * * @param cls @@ -257,11 +278,13 @@ slicer_modifier_handler_notify (void *cls, const struct GNUNET_HashCode *key, * The message part. as it arrived from the network. */ void -GNUNET_PSYC_slicer_message (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_pub_key, - uint64_t message_id, uint32_t flags, uint64_t fragment_offset, - const struct GNUNET_MessageHeader *msg) +GNUNET_PSYC_slicer_message_part (struct GNUNET_PSYC_Slicer *slicer, + const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_pub_key, + uint64_t message_id, + uint32_t flags, + uint64_t fragment_offset, + const struct GNUNET_MessageHeader *msg) { - struct GNUNET_PSYC_Slicer *slicer = cls; slicer->nym_pub_key = *slave_pub_key; uint16_t ptype = ntohs (msg->type); @@ -381,6 +404,10 @@ GNUNET_PSYC_slicer_create (void) struct GNUNET_PSYC_Slicer *slicer = GNUNET_malloc (sizeof (*slicer)); slicer->method_handlers = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); slicer->modifier_handlers = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); + slicer->recv = GNUNET_PSYC_receive_create (NULL, + (GNUNET_PSYC_MessagePartCallback) + GNUNET_PSYC_slicer_message_part, + slicer); return slicer; } @@ -430,7 +457,7 @@ GNUNET_PSYC_slicer_method_add (struct GNUNET_PSYC_Slicer *slicer, } -int +static int slicer_method_remove (void *cls, const struct GNUNET_HashCode *key, void *value) { struct SlicerMethodRemoveClosure *rm_cls = cls; @@ -531,7 +558,7 @@ GNUNET_PSYC_slicer_modifier_add (struct GNUNET_PSYC_Slicer *slicer, } -int +static int slicer_modifier_remove (void *cls, const struct GNUNET_HashCode *key, void *value) { struct SlicerModifierRemoveClosure *rm_cls = cls; @@ -585,7 +612,7 @@ GNUNET_PSYC_slicer_modifier_remove (struct GNUNET_PSYC_Slicer *slicer, } -int +static int slicer_method_free (void *cls, const struct GNUNET_HashCode *key, void *value) { struct SlicerMethodCallbacks *cbs = value; @@ -594,6 +621,57 @@ slicer_method_free (void *cls, const struct GNUNET_HashCode *key, void *value) } +static int +slicer_modifier_free (void *cls, const struct GNUNET_HashCode *key, void *value) +{ + struct SlicerModifierCallbacks *cbs = value; + GNUNET_free (cbs); + return GNUNET_YES; +} + + +/** + * Remove all registered method handlers. + * + * @param slicer + * Slicer to clear. + */ +void +GNUNET_PSYC_slicer_method_clear (struct GNUNET_PSYC_Slicer *slicer) +{ + GNUNET_CONTAINER_multihashmap_iterate (slicer->method_handlers, + slicer_method_free, NULL); +} + + +/** + * Remove all registered modifier handlers. + * + * @param slicer + * Slicer to clear. + */ +void +GNUNET_PSYC_slicer_modifier_clear (struct GNUNET_PSYC_Slicer *slicer) +{ + GNUNET_CONTAINER_multihashmap_iterate (slicer->modifier_handlers, + slicer_modifier_free, NULL); +} + + +/** + * Remove all registered method & modifier handlers. + * + * @param slicer + * Slicer to clear. + */ +void +GNUNET_PSYC_slicer_clear (struct GNUNET_PSYC_Slicer *slicer) +{ + GNUNET_PSYC_slicer_method_clear (slicer); + GNUNET_PSYC_slicer_modifier_clear (slicer); +} + + /** * Destroy a given try-and-slice instance. * @@ -603,8 +681,9 @@ slicer_method_free (void *cls, const struct GNUNET_HashCode *key, void *value) void GNUNET_PSYC_slicer_destroy (struct GNUNET_PSYC_Slicer *slicer) { - GNUNET_CONTAINER_multihashmap_iterate (slicer->method_handlers, - slicer_method_free, NULL); + GNUNET_PSYC_slicer_clear (slicer); GNUNET_CONTAINER_multihashmap_destroy (slicer->method_handlers); + GNUNET_CONTAINER_multihashmap_destroy (slicer->modifier_handlers); + GNUNET_PSYC_receive_destroy (slicer->recv); GNUNET_free (slicer); } |