aboutsummaryrefslogtreecommitdiff
path: root/src/multicast/multicast_api.c
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2014-05-22 23:05:27 +0000
committerGabor X Toth <*@tg-x.net>2014-05-22 23:05:27 +0000
commita7100389deab562e67d22ff68961b68a62341aec (patch)
treedbafc72c162df8627e639bd5e5190d8dc321d63d /src/multicast/multicast_api.c
parentc3bc1d8ef6e78e543d0077a57b04ae480f1d7caf (diff)
downloadgnunet-a7100389deab562e67d22ff68961b68a62341aec.tar.gz
gnunet-a7100389deab562e67d22ff68961b68a62341aec.zip
psyc, multicast: join decision
Diffstat (limited to 'src/multicast/multicast_api.c')
-rw-r--r--src/multicast/multicast_api.c77
1 files changed, 63 insertions, 14 deletions
diff --git a/src/multicast/multicast_api.c b/src/multicast/multicast_api.c
index 84dac0545..477cb1f2c 100644
--- a/src/multicast/multicast_api.c
+++ b/src/multicast/multicast_api.c
@@ -182,8 +182,6 @@ struct GNUNET_MULTICAST_Member
182 struct GNUNET_PeerIdentity relays; 182 struct GNUNET_PeerIdentity relays;
183 uint32_t relay_count; 183 uint32_t relay_count;
184 184
185 struct GNUNET_MessageHeader *join_request;
186
187 uint64_t next_fragment_id; 185 uint64_t next_fragment_id;
188}; 186};
189 187
@@ -501,7 +499,7 @@ join_request_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash,
501 499
502 const struct GNUNET_MessageHeader *msg = NULL; 500 const struct GNUNET_MessageHeader *msg = NULL;
503 if (sizeof (*req) + sizeof (*msg) <= ntohs (req->header.size)) 501 if (sizeof (*req) + sizeof (*msg) <= ntohs (req->header.size))
504 msg =(const struct GNUNET_MessageHeader *) &req[1]; 502 msg = (const struct GNUNET_MessageHeader *) &req[1];
505 503
506 grp->join_cb (grp->cb_cls, &req->member_key, msg, jh); 504 grp->join_cb (grp->cb_cls, &req->member_key, msg, jh);
507 return GNUNET_YES; 505 return GNUNET_YES;
@@ -509,6 +507,25 @@ join_request_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash,
509 507
510 508
511/** 509/**
510 * Iterator callback for calling join decision callbacks of members.
511 */
512static int
513join_decision_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash,
514 void *member)
515{
516 const struct MulticastJoinDecisionMessage *dcsn = cls;
517 struct GNUNET_MULTICAST_Member *mem = member;
518 struct GNUNET_MULTICAST_Group *grp = &mem->grp;
519
520 const struct GNUNET_MessageHeader *msg = NULL;
521 if (sizeof (*dcsn) + sizeof (*msg) <= ntohs (dcsn->header.size))
522 msg = (const struct GNUNET_MessageHeader *) &dcsn[1];
523
524 // FIXME: grp->join_decision_cb (grp->cb_cls, msg);
525 return GNUNET_YES;
526}
527
528/**
512 * Function called when we receive a message from the service. 529 * Function called when we receive a message from the service.
513 * 530 *
514 * @param cls struct GNUNET_MULTICAST_Group 531 * @param cls struct GNUNET_MULTICAST_Group
@@ -549,6 +566,10 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
549 size_min = sizeof (struct MulticastJoinRequestMessage); 566 size_min = sizeof (struct MulticastJoinRequestMessage);
550 break; 567 break;
551 568
569 case GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION:
570 size_min = sizeof (struct MulticastJoinDecisionMessage);
571 break;
572
552 default: 573 default:
553 GNUNET_break_op (0); 574 GNUNET_break_op (0);
554 type = 0; 575 type = 0;
@@ -592,6 +613,15 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
592 GNUNET_CONTAINER_multihashmap_get_multiple (members, &grp->pub_key_hash, 613 GNUNET_CONTAINER_multihashmap_get_multiple (members, &grp->pub_key_hash,
593 join_request_cb, (void *) msg); 614 join_request_cb, (void *) msg);
594 break; 615 break;
616
617 case GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION:
618 if (NULL != origins)
619 GNUNET_CONTAINER_multihashmap_get_multiple (origins, &grp->pub_key_hash,
620 join_decision_cb, (void *) msg);
621 if (NULL != members)
622 GNUNET_CONTAINER_multihashmap_get_multiple (members, &grp->pub_key_hash,
623 join_decision_cb, (void *) msg);
624 break;
595 } 625 }
596 626
597 if (NULL != grp->client) 627 if (NULL != grp->client)
@@ -619,7 +649,7 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
619 * be the multicast origin) is a good candidate for building the 649 * be the multicast origin) is a good candidate for building the
620 * multicast tree. Note that it is unnecessary to specify our own 650 * multicast tree. Note that it is unnecessary to specify our own
621 * peer identity in this array. 651 * peer identity in this array.
622 * @param join_response Message to send in response to the joining peer; 652 * @param join_resp Message to send in response to the joining peer;
623 * can also be used to redirect the peer to a different group at the 653 * can also be used to redirect the peer to a different group at the
624 * application layer; this response is to be transmitted to the 654 * application layer; this response is to be transmitted to the
625 * peer that issued the request even if admission is denied. 655 * peer that issued the request even if admission is denied.
@@ -629,8 +659,29 @@ GNUNET_MULTICAST_join_decision (struct GNUNET_MULTICAST_JoinHandle *jh,
629 int is_admitted, 659 int is_admitted,
630 unsigned int relay_count, 660 unsigned int relay_count,
631 const struct GNUNET_PeerIdentity *relays, 661 const struct GNUNET_PeerIdentity *relays,
632 const struct GNUNET_MessageHeader *join_response) 662 const struct GNUNET_MessageHeader *join_resp)
633{ 663{
664 struct GNUNET_MULTICAST_Group *grp = jh->group;
665 uint16_t join_resp_size = (NULL != join_resp) ? ntohs (join_resp->size) : 0;
666 uint16_t relay_size = relay_count * sizeof (*relays);
667 struct MulticastClientJoinDecisionMessage * dcsn;
668 struct MessageQueue *
669 mq = GNUNET_malloc (sizeof (*mq) + sizeof (*dcsn)
670 + relay_size + join_resp_size);
671
672 dcsn = (struct MulticastClientJoinDecisionMessage *) &mq[1];
673 dcsn->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION);
674 dcsn->header.size = htons (sizeof (*dcsn) + relay_size + join_resp_size);
675 dcsn->member_key = jh->member_key;
676 dcsn->member_peer = jh->member_peer;
677 dcsn->is_admitted = is_admitted;
678 dcsn->relay_count = relay_count;
679 memcpy (&dcsn[1], relays, relay_size);
680 memcpy (((char *) &dcsn[1]) + relay_size, join_resp, join_resp_size);
681
682 GNUNET_CONTAINER_DLL_insert_tail (grp->tmit_head, grp->tmit_tail, mq);
683 transmit_next (grp);
684
634 GNUNET_free (jh); 685 GNUNET_free (jh);
635 return NULL; 686 return NULL;
636} 687}
@@ -908,10 +959,8 @@ GNUNET_MULTICAST_origin_to_all_cancel (struct GNUNET_MULTICAST_OriginTransmitHan
908 * @param relays Peer identities of members of the group, which serve as relays 959 * @param relays Peer identities of members of the group, which serve as relays
909 * and can be used to join the group at. and send the @a join_request to. 960 * and can be used to join the group at. and send the @a join_request to.
910 * If empty, the @a join_request is sent directly to the @a origin. 961 * If empty, the @a join_request is sent directly to the @a origin.
911 * @param join_req Application-dependent join request to be passed to the peer 962 * @param join_msg Application-dependent join message to be passed to the peer
912 * @a relay (might, for example, contain a user, bind user 963 * @a origin.
913 * identity/pseudonym to peer identity, application-level message to
914 * origin, etc.).
915 * @param join_cb Function called to approve / disapprove joining of a peer. 964 * @param join_cb Function called to approve / disapprove joining of a peer.
916 * @param member_test_cb Function multicast can use to test group membership. 965 * @param member_test_cb Function multicast can use to test group membership.
917 * @param replay_frag_cb Function that can be called to replay message fragments 966 * @param replay_frag_cb Function that can be called to replay message fragments
@@ -933,7 +982,7 @@ GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
933 const struct GNUNET_PeerIdentity *origin, 982 const struct GNUNET_PeerIdentity *origin,
934 uint32_t relay_count, 983 uint32_t relay_count,
935 const struct GNUNET_PeerIdentity *relays, 984 const struct GNUNET_PeerIdentity *relays,
936 const struct GNUNET_MessageHeader *join_req, 985 const struct GNUNET_MessageHeader *join_msg,
937 GNUNET_MULTICAST_JoinCallback join_cb, 986 GNUNET_MULTICAST_JoinCallback join_cb,
938 GNUNET_MULTICAST_MembershipTestCallback member_test_cb, 987 GNUNET_MULTICAST_MembershipTestCallback member_test_cb,
939 GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb, 988 GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb,
@@ -945,16 +994,16 @@ GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
945 struct GNUNET_MULTICAST_Group *grp = &mem->grp; 994 struct GNUNET_MULTICAST_Group *grp = &mem->grp;
946 995
947 uint16_t relay_size = relay_count * sizeof (*relays); 996 uint16_t relay_size = relay_count * sizeof (*relays);
948 uint16_t join_req_size = (NULL != join_req) ? ntohs (join_req->size) : 0; 997 uint16_t join_msg_size = (NULL != join_msg) ? ntohs (join_msg->size) : 0;
949 struct MulticastMemberJoinMessage * 998 struct MulticastMemberJoinMessage *
950 join = GNUNET_malloc (sizeof (*join) + relay_size + join_req_size); 999 join = GNUNET_malloc (sizeof (*join) + relay_size + join_msg_size);
951 join->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MEMBER_JOIN); 1000 join->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MEMBER_JOIN);
952 join->header.size = htons (sizeof (*join) + relay_size + join_req_size); 1001 join->header.size = htons (sizeof (*join) + relay_size + join_msg_size);
953 join->group_key = *group_key; 1002 join->group_key = *group_key;
954 join->member_key = *member_key; 1003 join->member_key = *member_key;
955 join->origin = *origin; 1004 join->origin = *origin;
956 memcpy (&join[1], relays, relay_size); 1005 memcpy (&join[1], relays, relay_size);
957 memcpy (((char *) &join[1]) + relay_size, join_req, join_req_size); 1006 memcpy (((char *) &join[1]) + relay_size, join_msg, join_msg_size);
958 1007
959 grp->reconnect_msg = (struct GNUNET_MessageHeader *) join; 1008 grp->reconnect_msg = (struct GNUNET_MessageHeader *) join;
960 grp->is_origin = GNUNET_NO; 1009 grp->is_origin = GNUNET_NO;