aboutsummaryrefslogtreecommitdiff
path: root/src/psycutil/psyc_slicer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/psycutil/psyc_slicer.c')
-rw-r--r--src/psycutil/psyc_slicer.c101
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 */
154int 159static int
155slicer_method_handler_notify (void *cls, const struct GNUNET_HashCode *key, 160slicer_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 */
232int 237static int
233slicer_modifier_handler_notify (void *cls, const struct GNUNET_HashCode *key, 238slicer_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 */
259void
260GNUNET_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 */
259void 280void
260GNUNET_PSYC_slicer_message (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_pub_key, 281GNUNET_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
433int 460static int
434slicer_method_remove (void *cls, const struct GNUNET_HashCode *key, void *value) 461slicer_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
534int 561static int
535slicer_modifier_remove (void *cls, const struct GNUNET_HashCode *key, void *value) 562slicer_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
588int 615static int
589slicer_method_free (void *cls, const struct GNUNET_HashCode *key, void *value) 616slicer_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
624static int
625slicer_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 */
639void
640GNUNET_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 */
653void
654GNUNET_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 */
667void
668GNUNET_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)
603void 681void
604GNUNET_PSYC_slicer_destroy (struct GNUNET_PSYC_Slicer *slicer) 682GNUNET_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}