diff options
author | Gabor X Toth <*@tg-x.net> | 2014-05-26 22:16:05 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2014-05-26 22:16:05 +0000 |
commit | 83495695331fcfa8824d7a6d407b82cfcfc8b13c (patch) | |
tree | 2d2a7717d81890f5142da9561bccf9e164b1deee /src/multicast/multicast_api.c | |
parent | 1cfab01aaea932539c39dcb2118ec4d6c6d44381 (diff) | |
download | gnunet-83495695331fcfa8824d7a6d407b82cfcfc8b13c.tar.gz gnunet-83495695331fcfa8824d7a6d407b82cfcfc8b13c.zip |
psyc, multicast: join decision, tests
Diffstat (limited to 'src/multicast/multicast_api.c')
-rw-r--r-- | src/multicast/multicast_api.c | 120 |
1 files changed, 77 insertions, 43 deletions
diff --git a/src/multicast/multicast_api.c b/src/multicast/multicast_api.c index 501ff4b70..e568e77ee 100644 --- a/src/multicast/multicast_api.c +++ b/src/multicast/multicast_api.c | |||
@@ -132,7 +132,7 @@ struct GNUNET_MULTICAST_Group | |||
132 | struct GNUNET_CRYPTO_EddsaPublicKey pub_key; | 132 | struct GNUNET_CRYPTO_EddsaPublicKey pub_key; |
133 | struct GNUNET_HashCode pub_key_hash; | 133 | struct GNUNET_HashCode pub_key_hash; |
134 | 134 | ||
135 | GNUNET_MULTICAST_JoinCallback join_cb; | 135 | GNUNET_MULTICAST_JoinRequestCallback join_req_cb; |
136 | GNUNET_MULTICAST_MembershipTestCallback member_test_cb; | 136 | GNUNET_MULTICAST_MembershipTestCallback member_test_cb; |
137 | GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb; | 137 | GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb; |
138 | GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb; | 138 | GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb; |
@@ -177,10 +177,7 @@ struct GNUNET_MULTICAST_Member | |||
177 | struct GNUNET_MULTICAST_Group grp; | 177 | struct GNUNET_MULTICAST_Group grp; |
178 | struct GNUNET_MULTICAST_MemberTransmitHandle tmit; | 178 | struct GNUNET_MULTICAST_MemberTransmitHandle tmit; |
179 | 179 | ||
180 | struct GNUNET_CRYPTO_EddsaPrivateKey priv_key; | 180 | GNUNET_MULTICAST_JoinDecisionCallback join_dcsn_cb; |
181 | struct GNUNET_PeerIdentity origin; | ||
182 | struct GNUNET_PeerIdentity relays; | ||
183 | uint32_t relay_count; | ||
184 | 181 | ||
185 | uint64_t next_fragment_id; | 182 | uint64_t next_fragment_id; |
186 | }; | 183 | }; |
@@ -197,12 +194,12 @@ struct GNUNET_MULTICAST_JoinHandle | |||
197 | struct GNUNET_MULTICAST_Group *group; | 194 | struct GNUNET_MULTICAST_Group *group; |
198 | 195 | ||
199 | /** | 196 | /** |
200 | * Public key of the joining member. | 197 | * Public key of the member requesting join. |
201 | */ | 198 | */ |
202 | struct GNUNET_CRYPTO_EddsaPublicKey member_key; | 199 | struct GNUNET_CRYPTO_EddsaPublicKey member_key; |
203 | 200 | ||
204 | /** | 201 | /** |
205 | * Peer identity of the joining member. | 202 | * Peer identity of the member requesting join. |
206 | */ | 203 | */ |
207 | struct GNUNET_PeerIdentity member_peer; | 204 | struct GNUNET_PeerIdentity member_peer; |
208 | }; | 205 | }; |
@@ -476,8 +473,9 @@ request_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, void *origin) | |||
476 | "Calling request callback for a request of type %u and size %u.\n", | 473 | "Calling request callback for a request of type %u and size %u.\n", |
477 | ntohs (req->header.type), ntohs (req->header.size)); | 474 | ntohs (req->header.type), ntohs (req->header.size)); |
478 | 475 | ||
479 | orig->request_cb (orig->grp.cb_cls, &req->member_key, | 476 | if (NULL != orig->request_cb) |
480 | (const struct GNUNET_MessageHeader *) req, 0); | 477 | orig->request_cb (orig->grp.cb_cls, &req->member_key, |
478 | (const struct GNUNET_MessageHeader *) req, 0); | ||
481 | return GNUNET_YES; | 479 | return GNUNET_YES; |
482 | } | 480 | } |
483 | 481 | ||
@@ -501,7 +499,8 @@ join_request_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, | |||
501 | if (sizeof (*req) + sizeof (*msg) <= ntohs (req->header.size)) | 499 | if (sizeof (*req) + sizeof (*msg) <= ntohs (req->header.size)) |
502 | msg = (const struct GNUNET_MessageHeader *) &req[1]; | 500 | msg = (const struct GNUNET_MessageHeader *) &req[1]; |
503 | 501 | ||
504 | grp->join_cb (grp->cb_cls, &req->member_key, msg, jh); | 502 | if (NULL != grp->join_req_cb) |
503 | grp->join_req_cb (grp->cb_cls, &req->member_key, msg, jh); | ||
505 | return GNUNET_YES; | 504 | return GNUNET_YES; |
506 | } | 505 | } |
507 | 506 | ||
@@ -513,15 +512,44 @@ static int | |||
513 | join_decision_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, | 512 | join_decision_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, |
514 | void *member) | 513 | void *member) |
515 | { | 514 | { |
516 | const struct MulticastJoinDecisionMessage *dcsn = cls; | 515 | const struct MulticastJoinDecisionMessageHeader *hdcsn = cls; |
516 | const struct MulticastJoinDecisionMessage * | ||
517 | dcsn = (const struct MulticastJoinDecisionMessage *) &hdcsn[1]; | ||
517 | struct GNUNET_MULTICAST_Member *mem = member; | 518 | struct GNUNET_MULTICAST_Member *mem = member; |
518 | struct GNUNET_MULTICAST_Group *grp = &mem->grp; | 519 | struct GNUNET_MULTICAST_Group *grp = &mem->grp; |
519 | 520 | ||
520 | const struct GNUNET_MessageHeader *msg = NULL; | 521 | uint16_t dcsn_size = ntohs (dcsn->header.size); |
521 | if (sizeof (*dcsn) + sizeof (*msg) <= ntohs (dcsn->header.size)) | 522 | int is_admitted = ntohl (dcsn->is_admitted); |
522 | msg = (const struct GNUNET_MessageHeader *) &dcsn[1]; | 523 | |
524 | const struct GNUNET_MessageHeader *join_resp = NULL; | ||
525 | uint16_t join_resp_size = 0; | ||
526 | |||
527 | uint16_t relay_count = ntohl (dcsn->relay_count); | ||
528 | const struct GNUNET_PeerIdentity *relays = NULL; | ||
529 | uint16_t relay_size = relay_count * sizeof (*relays); | ||
530 | if (0 < relay_count && dcsn_size < sizeof (*dcsn) + relay_size) | ||
531 | relays = (struct GNUNET_PeerIdentity *) &dcsn[1]; | ||
532 | |||
533 | if (sizeof (*dcsn) + relay_size + sizeof (*join_resp) <= dcsn_size) | ||
534 | { | ||
535 | join_resp = (const struct GNUNET_MessageHeader *) &dcsn[1]; | ||
536 | join_resp_size = ntohs (join_resp->size); | ||
537 | } | ||
538 | if (dcsn_size < sizeof (*dcsn) + relay_size + join_resp_size) | ||
539 | { | ||
540 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
541 | "Received invalid join decision message from multicast.\n"); | ||
542 | GNUNET_break_op (0); | ||
543 | is_admitted = GNUNET_SYSERR; | ||
544 | } | ||
545 | |||
546 | if (NULL != mem->join_dcsn_cb) | ||
547 | mem->join_dcsn_cb (grp->cb_cls, is_admitted, &hdcsn->peer, | ||
548 | relay_count, relays, join_resp); | ||
549 | |||
550 | if (GNUNET_YES != is_admitted) | ||
551 | GNUNET_MULTICAST_member_part (mem); | ||
523 | 552 | ||
524 | // FIXME: grp->join_decision_cb (grp->cb_cls, msg); | ||
525 | return GNUNET_YES; | 553 | return GNUNET_YES; |
526 | } | 554 | } |
527 | 555 | ||
@@ -599,7 +627,6 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
599 | GNUNET_break (0); | 627 | GNUNET_break (0); |
600 | break; | 628 | break; |
601 | } | 629 | } |
602 | |||
603 | if (NULL != origins) | 630 | if (NULL != origins) |
604 | GNUNET_CONTAINER_multihashmap_get_multiple (origins, &grp->pub_key_hash, | 631 | GNUNET_CONTAINER_multihashmap_get_multiple (origins, &grp->pub_key_hash, |
605 | request_cb, (void *) msg); | 632 | request_cb, (void *) msg); |
@@ -615,9 +642,11 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
615 | break; | 642 | break; |
616 | 643 | ||
617 | case GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION: | 644 | case GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION: |
618 | if (NULL != origins) | 645 | if (GNUNET_NO != grp->is_origin) |
619 | GNUNET_CONTAINER_multihashmap_get_multiple (origins, &grp->pub_key_hash, | 646 | { |
620 | join_decision_cb, (void *) msg); | 647 | GNUNET_break (0); |
648 | break; | ||
649 | } | ||
621 | if (NULL != members) | 650 | if (NULL != members) |
622 | GNUNET_CONTAINER_multihashmap_get_multiple (members, &grp->pub_key_hash, | 651 | GNUNET_CONTAINER_multihashmap_get_multiple (members, &grp->pub_key_hash, |
623 | join_decision_cb, (void *) msg); | 652 | join_decision_cb, (void *) msg); |
@@ -636,11 +665,12 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
636 | * Function to call with the decision made for a join request. | 665 | * Function to call with the decision made for a join request. |
637 | * | 666 | * |
638 | * Must be called once and only once in response to an invocation of the | 667 | * Must be called once and only once in response to an invocation of the |
639 | * #GNUNET_MULTICAST_JoinCallback. | 668 | * #GNUNET_MULTICAST_JoinRequestCallback. |
640 | * | 669 | * |
641 | * @param jh Join request handle. | 670 | * @param jh Join request handle. |
642 | * @param is_admitted #GNUNET_YES if joining is approved, | 671 | * @param is_admitted #GNUNET_YES if the join is approved, |
643 | * #GNUNET_NO if it is disapproved | 672 | * #GNUNET_NO if it is disapproved, |
673 | * #GNUNET_SYSERR if we cannot answer the request. | ||
644 | * @param relay_count Number of relays given. | 674 | * @param relay_count Number of relays given. |
645 | * @param relays Array of suggested peers that might be useful relays to use | 675 | * @param relays Array of suggested peers that might be useful relays to use |
646 | * when joining the multicast group (essentially a list of peers that | 676 | * when joining the multicast group (essentially a list of peers that |
@@ -657,25 +687,31 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
657 | struct GNUNET_MULTICAST_ReplayHandle * | 687 | struct GNUNET_MULTICAST_ReplayHandle * |
658 | GNUNET_MULTICAST_join_decision (struct GNUNET_MULTICAST_JoinHandle *jh, | 688 | GNUNET_MULTICAST_join_decision (struct GNUNET_MULTICAST_JoinHandle *jh, |
659 | int is_admitted, | 689 | int is_admitted, |
660 | unsigned int relay_count, | 690 | uint16_t relay_count, |
661 | const struct GNUNET_PeerIdentity *relays, | 691 | const struct GNUNET_PeerIdentity *relays, |
662 | const struct GNUNET_MessageHeader *join_resp) | 692 | const struct GNUNET_MessageHeader *join_resp) |
663 | { | 693 | { |
664 | struct GNUNET_MULTICAST_Group *grp = jh->group; | 694 | struct GNUNET_MULTICAST_Group *grp = jh->group; |
665 | uint16_t join_resp_size = (NULL != join_resp) ? ntohs (join_resp->size) : 0; | 695 | uint16_t join_resp_size = (NULL != join_resp) ? ntohs (join_resp->size) : 0; |
666 | uint16_t relay_size = relay_count * sizeof (*relays); | 696 | uint16_t relay_size = relay_count * sizeof (*relays); |
667 | struct MulticastClientJoinDecisionMessage * dcsn; | 697 | struct MulticastJoinDecisionMessageHeader * hdcsn; |
698 | struct MulticastJoinDecisionMessage *dcsn; | ||
668 | struct MessageQueue * | 699 | struct MessageQueue * |
669 | mq = GNUNET_malloc (sizeof (*mq) + sizeof (*dcsn) | 700 | mq = GNUNET_malloc (sizeof (*mq) + sizeof (*hdcsn) + sizeof (*dcsn) |
670 | + relay_size + join_resp_size); | 701 | + relay_size + join_resp_size); |
671 | 702 | ||
672 | dcsn = (struct MulticastClientJoinDecisionMessage *) &mq[1]; | 703 | hdcsn = (struct MulticastJoinDecisionMessageHeader *) &mq[1]; |
704 | hdcsn->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION); | ||
705 | hdcsn->header.size = htons (sizeof (*hdcsn) + sizeof (*dcsn) | ||
706 | + relay_size + join_resp_size); | ||
707 | hdcsn->member_key = jh->member_key; | ||
708 | hdcsn->peer = jh->member_peer; | ||
709 | |||
710 | dcsn = (struct MulticastJoinDecisionMessage *) &hdcsn[1]; | ||
673 | dcsn->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION); | 711 | dcsn->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION); |
674 | dcsn->header.size = htons (sizeof (*dcsn) + relay_size + join_resp_size); | 712 | dcsn->header.size = htons (sizeof (*dcsn) + relay_size + join_resp_size); |
675 | dcsn->member_key = jh->member_key; | 713 | dcsn->is_admitted = htonl (is_admitted); |
676 | dcsn->member_peer = jh->member_peer; | 714 | dcsn->relay_count = htonl (relay_count); |
677 | dcsn->is_admitted = is_admitted; | ||
678 | dcsn->relay_count = relay_count; | ||
679 | if (0 < relay_size) | 715 | if (0 < relay_size) |
680 | memcpy (&dcsn[1], relays, relay_size); | 716 | memcpy (&dcsn[1], relays, relay_size); |
681 | if (0 < join_resp_size) | 717 | if (0 < join_resp_size) |
@@ -763,7 +799,7 @@ GNUNET_MULTICAST_replay_response2 (struct GNUNET_MULTICAST_ReplayHandle *rh, | |||
763 | * multicast session; public key is used to identify the multicast group; | 799 | * multicast session; public key is used to identify the multicast group; |
764 | * @param max_fragment_id Maximum fragment ID already sent to the group. | 800 | * @param max_fragment_id Maximum fragment ID already sent to the group. |
765 | * 0 for a new group. | 801 | * 0 for a new group. |
766 | * @param join_cb Function called to approve / disapprove joining of a peer. | 802 | * @param join_request_cb Function called to approve / disapprove joining of a peer. |
767 | * @param member_test_cb Function multicast can use to test group membership. | 803 | * @param member_test_cb Function multicast can use to test group membership. |
768 | * @param replay_frag_cb Function that can be called to replay a message fragment. | 804 | * @param replay_frag_cb Function that can be called to replay a message fragment. |
769 | * @param replay_msg_cb Function that can be called to replay a message. | 805 | * @param replay_msg_cb Function that can be called to replay a message. |
@@ -779,7 +815,7 @@ struct GNUNET_MULTICAST_Origin * | |||
779 | GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 815 | GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
780 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key, | 816 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key, |
781 | uint64_t max_fragment_id, | 817 | uint64_t max_fragment_id, |
782 | GNUNET_MULTICAST_JoinCallback join_cb, | 818 | GNUNET_MULTICAST_JoinRequestCallback join_request_cb, |
783 | GNUNET_MULTICAST_MembershipTestCallback member_test_cb, | 819 | GNUNET_MULTICAST_MembershipTestCallback member_test_cb, |
784 | GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb, | 820 | GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb, |
785 | GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb, | 821 | GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb, |
@@ -801,7 +837,7 @@ GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
801 | grp->cfg = cfg; | 837 | grp->cfg = cfg; |
802 | 838 | ||
803 | grp->cb_cls = cls; | 839 | grp->cb_cls = cls; |
804 | grp->join_cb = join_cb; | 840 | grp->join_req_cb = join_request_cb; |
805 | grp->member_test_cb = member_test_cb; | 841 | grp->member_test_cb = member_test_cb; |
806 | grp->replay_frag_cb = replay_frag_cb; | 842 | grp->replay_frag_cb = replay_frag_cb; |
807 | grp->replay_msg_cb = replay_msg_cb; | 843 | grp->replay_msg_cb = replay_msg_cb; |
@@ -963,7 +999,8 @@ GNUNET_MULTICAST_origin_to_all_cancel (struct GNUNET_MULTICAST_OriginTransmitHan | |||
963 | * If empty, the @a join_request is sent directly to the @a origin. | 999 | * If empty, the @a join_request is sent directly to the @a origin. |
964 | * @param join_msg Application-dependent join message to be passed to the peer | 1000 | * @param join_msg Application-dependent join message to be passed to the peer |
965 | * @a origin. | 1001 | * @a origin. |
966 | * @param join_cb Function called to approve / disapprove joining of a peer. | 1002 | * @param join_request_cb Function called to approve / disapprove joining of a peer. |
1003 | * @param join_decision_cb Function called to inform about the join decision. | ||
967 | * @param member_test_cb Function multicast can use to test group membership. | 1004 | * @param member_test_cb Function multicast can use to test group membership. |
968 | * @param replay_frag_cb Function that can be called to replay message fragments | 1005 | * @param replay_frag_cb Function that can be called to replay message fragments |
969 | * this peer already knows from this group. NULL if this | 1006 | * this peer already knows from this group. NULL if this |
@@ -982,10 +1019,11 @@ GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
982 | const struct GNUNET_CRYPTO_EddsaPublicKey *group_key, | 1019 | const struct GNUNET_CRYPTO_EddsaPublicKey *group_key, |
983 | const struct GNUNET_CRYPTO_EddsaPrivateKey *member_key, | 1020 | const struct GNUNET_CRYPTO_EddsaPrivateKey *member_key, |
984 | const struct GNUNET_PeerIdentity *origin, | 1021 | const struct GNUNET_PeerIdentity *origin, |
985 | uint32_t relay_count, | 1022 | uint16_t relay_count, |
986 | const struct GNUNET_PeerIdentity *relays, | 1023 | const struct GNUNET_PeerIdentity *relays, |
987 | const struct GNUNET_MessageHeader *join_msg, | 1024 | const struct GNUNET_MessageHeader *join_msg, |
988 | GNUNET_MULTICAST_JoinCallback join_cb, | 1025 | GNUNET_MULTICAST_JoinRequestCallback join_request_cb, |
1026 | GNUNET_MULTICAST_JoinDecisionCallback join_decision_cb, | ||
989 | GNUNET_MULTICAST_MembershipTestCallback member_test_cb, | 1027 | GNUNET_MULTICAST_MembershipTestCallback member_test_cb, |
990 | GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb, | 1028 | GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb, |
991 | GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb, | 1029 | GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb, |
@@ -1014,18 +1052,14 @@ GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1014 | grp->cfg = cfg; | 1052 | grp->cfg = cfg; |
1015 | grp->pub_key = *group_key; | 1053 | grp->pub_key = *group_key; |
1016 | 1054 | ||
1017 | grp->join_cb = join_cb; | 1055 | mem->join_dcsn_cb = join_decision_cb; |
1056 | grp->join_req_cb = join_request_cb; | ||
1018 | grp->member_test_cb = member_test_cb; | 1057 | grp->member_test_cb = member_test_cb; |
1019 | grp->replay_frag_cb = replay_frag_cb; | 1058 | grp->replay_frag_cb = replay_frag_cb; |
1020 | grp->message_cb = message_cb; | 1059 | grp->message_cb = message_cb; |
1021 | grp->cb_cls = cls; | 1060 | grp->cb_cls = cls; |
1022 | 1061 | ||
1023 | mem->origin = *origin; | 1062 | GNUNET_CRYPTO_eddsa_key_get_public (member_key, &grp->pub_key); |
1024 | mem->relay_count = relay_count; | ||
1025 | mem->relays = *relays; | ||
1026 | mem->priv_key = *member_key; | ||
1027 | |||
1028 | GNUNET_CRYPTO_eddsa_key_get_public (&mem->priv_key, &grp->pub_key); | ||
1029 | GNUNET_CRYPTO_hash (&grp->pub_key, sizeof (grp->pub_key), &grp->pub_key_hash); | 1063 | GNUNET_CRYPTO_hash (&grp->pub_key, sizeof (grp->pub_key), &grp->pub_key_hash); |
1030 | 1064 | ||
1031 | if (NULL == members) | 1065 | if (NULL == members) |