diff options
Diffstat (limited to 'src/multicast/multicast_api.c')
-rw-r--r-- | src/multicast/multicast_api.c | 99 |
1 files changed, 55 insertions, 44 deletions
diff --git a/src/multicast/multicast_api.c b/src/multicast/multicast_api.c index d42f438ae..84dac0545 100644 --- a/src/multicast/multicast_api.c +++ b/src/multicast/multicast_api.c | |||
@@ -196,6 +196,17 @@ struct GNUNET_MULTICAST_Member | |||
196 | */ | 196 | */ |
197 | struct GNUNET_MULTICAST_JoinHandle | 197 | struct GNUNET_MULTICAST_JoinHandle |
198 | { | 198 | { |
199 | struct GNUNET_MULTICAST_Group *group; | ||
200 | |||
201 | /** | ||
202 | * Public key of the joining member. | ||
203 | */ | ||
204 | struct GNUNET_CRYPTO_EddsaPublicKey member_key; | ||
205 | |||
206 | /** | ||
207 | * Peer identity of the joining member. | ||
208 | */ | ||
209 | struct GNUNET_PeerIdentity member_peer; | ||
199 | }; | 210 | }; |
200 | 211 | ||
201 | 212 | ||
@@ -437,8 +448,7 @@ disconnect (void *g) | |||
437 | * Iterator callback for calling message callbacks for all groups. | 448 | * Iterator callback for calling message callbacks for all groups. |
438 | */ | 449 | */ |
439 | static int | 450 | static int |
440 | message_callback (void *cls, const struct GNUNET_HashCode *pub_key_hash, | 451 | message_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, void *group) |
441 | void *group) | ||
442 | { | 452 | { |
443 | const struct GNUNET_MessageHeader *msg = cls; | 453 | const struct GNUNET_MessageHeader *msg = cls; |
444 | struct GNUNET_MULTICAST_Group *grp = group; | 454 | struct GNUNET_MULTICAST_Group *grp = group; |
@@ -456,32 +466,10 @@ message_callback (void *cls, const struct GNUNET_HashCode *pub_key_hash, | |||
456 | 466 | ||
457 | 467 | ||
458 | /** | 468 | /** |
459 | * Handle a multicast message from the service. | ||
460 | * | ||
461 | * Call message callbacks of all origins and members of the destination group. | ||
462 | * | ||
463 | * @param grp Destination group of the message. | ||
464 | * @param msg The message. | ||
465 | */ | ||
466 | static void | ||
467 | handle_multicast_message (struct GNUNET_MULTICAST_Group *grp, | ||
468 | const struct GNUNET_MULTICAST_MessageHeader *msg) | ||
469 | { | ||
470 | if (origins != NULL) | ||
471 | GNUNET_CONTAINER_multihashmap_get_multiple (origins, &grp->pub_key_hash, | ||
472 | message_callback, (void *) msg); | ||
473 | if (members != NULL) | ||
474 | GNUNET_CONTAINER_multihashmap_get_multiple (members, &grp->pub_key_hash, | ||
475 | message_callback, (void *) msg); | ||
476 | } | ||
477 | |||
478 | |||
479 | /** | ||
480 | * Iterator callback for calling request callbacks of origins. | 469 | * Iterator callback for calling request callbacks of origins. |
481 | */ | 470 | */ |
482 | static int | 471 | static int |
483 | request_callback (void *cls, const struct GNUNET_HashCode *chan_key_hash, | 472 | request_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, void *origin) |
484 | void *origin) | ||
485 | { | 473 | { |
486 | const struct GNUNET_MULTICAST_RequestHeader *req = cls; | 474 | const struct GNUNET_MULTICAST_RequestHeader *req = cls; |
487 | struct GNUNET_MULTICAST_Origin *orig = origin; | 475 | struct GNUNET_MULTICAST_Origin *orig = origin; |
@@ -497,20 +485,26 @@ request_callback (void *cls, const struct GNUNET_HashCode *chan_key_hash, | |||
497 | 485 | ||
498 | 486 | ||
499 | /** | 487 | /** |
500 | * Handle a multicast request from the service. | 488 | * Iterator callback for calling join request callbacks of origins. |
501 | * | ||
502 | * Call request callbacks of all origins of the destination group. | ||
503 | * | ||
504 | * @param grp Destination group of the message. | ||
505 | * @param msg The message. | ||
506 | */ | 489 | */ |
507 | static void | 490 | static int |
508 | handle_multicast_request (struct GNUNET_MULTICAST_Group *grp, | 491 | join_request_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, |
509 | const struct GNUNET_MULTICAST_RequestHeader *req) | 492 | void *group) |
510 | { | 493 | { |
511 | if (NULL != origins) | 494 | const struct MulticastJoinRequestMessage *req = cls; |
512 | GNUNET_CONTAINER_multihashmap_get_multiple (origins, &grp->pub_key_hash, | 495 | struct GNUNET_MULTICAST_Group *grp = group; |
513 | request_callback, (void *) req); | 496 | |
497 | struct GNUNET_MULTICAST_JoinHandle *jh = GNUNET_malloc (sizeof (*jh)); | ||
498 | jh->group = grp; | ||
499 | jh->member_key = req->member_key; | ||
500 | jh->member_peer = req->member_peer; | ||
501 | |||
502 | const struct GNUNET_MessageHeader *msg = NULL; | ||
503 | if (sizeof (*req) + sizeof (*msg) <= ntohs (req->header.size)) | ||
504 | msg =(const struct GNUNET_MessageHeader *) &req[1]; | ||
505 | |||
506 | grp->join_cb (grp->cb_cls, &req->member_key, msg, jh); | ||
507 | return GNUNET_YES; | ||
514 | } | 508 | } |
515 | 509 | ||
516 | 510 | ||
@@ -551,22 +545,31 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
551 | size_min = sizeof (struct GNUNET_MULTICAST_RequestHeader); | 545 | size_min = sizeof (struct GNUNET_MULTICAST_RequestHeader); |
552 | break; | 546 | break; |
553 | 547 | ||
548 | case GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST: | ||
549 | size_min = sizeof (struct MulticastJoinRequestMessage); | ||
550 | break; | ||
551 | |||
554 | default: | 552 | default: |
555 | GNUNET_break_op (0); | 553 | GNUNET_break_op (0); |
556 | return; | 554 | type = 0; |
557 | } | 555 | } |
558 | 556 | ||
559 | if (! ((0 < size_eq && size == size_eq) | 557 | if (! ((0 < size_eq && size == size_eq) |
560 | || (0 < size_min && size_min <= size))) | 558 | || (0 < size_min && size_min <= size))) |
561 | { | 559 | { |
562 | GNUNET_break_op (0); | 560 | GNUNET_break_op (0); |
563 | return; | 561 | type = 0; |
564 | } | 562 | } |
565 | 563 | ||
566 | switch (type) | 564 | switch (type) |
567 | { | 565 | { |
568 | case GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE: | 566 | case GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE: |
569 | handle_multicast_message (grp, (struct GNUNET_MULTICAST_MessageHeader *) msg); | 567 | if (origins != NULL) |
568 | GNUNET_CONTAINER_multihashmap_get_multiple (origins, &grp->pub_key_hash, | ||
569 | message_cb, (void *) msg); | ||
570 | if (members != NULL) | ||
571 | GNUNET_CONTAINER_multihashmap_get_multiple (members, &grp->pub_key_hash, | ||
572 | message_cb, (void *) msg); | ||
570 | break; | 573 | break; |
571 | 574 | ||
572 | case GNUNET_MESSAGE_TYPE_MULTICAST_REQUEST: | 575 | case GNUNET_MESSAGE_TYPE_MULTICAST_REQUEST: |
@@ -576,12 +579,19 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
576 | break; | 579 | break; |
577 | } | 580 | } |
578 | 581 | ||
579 | handle_multicast_request (grp, (struct GNUNET_MULTICAST_RequestHeader *) msg); | 582 | if (NULL != origins) |
583 | GNUNET_CONTAINER_multihashmap_get_multiple (origins, &grp->pub_key_hash, | ||
584 | request_cb, (void *) msg); | ||
580 | break; | 585 | break; |
581 | 586 | ||
582 | default: | 587 | case GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST: |
583 | GNUNET_break_op (0); | 588 | if (NULL != origins) |
584 | return; | 589 | GNUNET_CONTAINER_multihashmap_get_multiple (origins, &grp->pub_key_hash, |
590 | join_request_cb, (void *) msg); | ||
591 | if (NULL != members) | ||
592 | GNUNET_CONTAINER_multihashmap_get_multiple (members, &grp->pub_key_hash, | ||
593 | join_request_cb, (void *) msg); | ||
594 | break; | ||
585 | } | 595 | } |
586 | 596 | ||
587 | if (NULL != grp->client) | 597 | if (NULL != grp->client) |
@@ -621,6 +631,7 @@ GNUNET_MULTICAST_join_decision (struct GNUNET_MULTICAST_JoinHandle *jh, | |||
621 | const struct GNUNET_PeerIdentity *relays, | 631 | const struct GNUNET_PeerIdentity *relays, |
622 | const struct GNUNET_MessageHeader *join_response) | 632 | const struct GNUNET_MessageHeader *join_response) |
623 | { | 633 | { |
634 | GNUNET_free (jh); | ||
624 | return NULL; | 635 | return NULL; |
625 | } | 636 | } |
626 | 637 | ||