aboutsummaryrefslogtreecommitdiff
path: root/src/multicast
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2014-07-25 13:24:15 +0000
committerGabor X Toth <*@tg-x.net>2014-07-25 13:24:15 +0000
commit30752e6cb73b6c71ad5aab392c40ac482257e410 (patch)
treee33ab995a7a56853e20d448f339b10d87cb7e32b /src/multicast
parentac2af3883bbceafd3258cad788587a70057010d9 (diff)
downloadgnunet-30752e6cb73b6c71ad5aab392c40ac482257e410.tar.gz
gnunet-30752e6cb73b6c71ad5aab392c40ac482257e410.zip
multicast: send join decision to remote peer
Diffstat (limited to 'src/multicast')
-rw-r--r--src/multicast/gnunet-service-multicast.c94
-rw-r--r--src/multicast/multicast.h2
-rw-r--r--src/multicast/multicast_api.c6
3 files changed, 66 insertions, 36 deletions
diff --git a/src/multicast/gnunet-service-multicast.c b/src/multicast/gnunet-service-multicast.c
index 4072c7066..2998ce972 100644
--- a/src/multicast/gnunet-service-multicast.c
+++ b/src/multicast/gnunet-service-multicast.c
@@ -70,19 +70,19 @@ static struct GNUNET_STATISTICS_Handle *stats;
70static struct GNUNET_SERVER_NotificationContext *nc; 70static struct GNUNET_SERVER_NotificationContext *nc;
71 71
72/** 72/**
73 * All connected origins. 73 * All connected origin clients.
74 * Group's pub_key_hash -> struct Origin * (uniq) 74 * Group's pub_key_hash -> struct Origin * (uniq)
75 */ 75 */
76static struct GNUNET_CONTAINER_MultiHashMap *origins; 76static struct GNUNET_CONTAINER_MultiHashMap *origins;
77 77
78/** 78/**
79 * All connected members. 79 * All connected member clients.
80 * Group's pub_key_hash -> struct Member * (multi) 80 * Group's pub_key_hash -> struct Member * (multi)
81 */ 81 */
82static struct GNUNET_CONTAINER_MultiHashMap *members; 82static struct GNUNET_CONTAINER_MultiHashMap *members;
83 83
84/** 84/**
85 * Connected members per group. 85 * Connected member clients per group.
86 * Group's pub_key_hash -> Member's pub_key_hash (uniq) -> struct Member * (uniq) 86 * Group's pub_key_hash -> Member's pub_key_hash (uniq) -> struct Member * (uniq)
87 */ 87 */
88static struct GNUNET_CONTAINER_MultiHashMap *group_members; 88static struct GNUNET_CONTAINER_MultiHashMap *group_members;
@@ -437,8 +437,8 @@ client_notify_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
437 * Send message to all clients connected to the group. 437 * Send message to all clients connected to the group.
438 */ 438 */
439static void 439static void
440client_send (const struct Group *grp, 440client_send_msg (const struct Group *grp,
441 const struct GNUNET_MessageHeader *msg) 441 const struct GNUNET_MessageHeader *msg)
442{ 442{
443 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 443 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
444 "%p Sending message to clients.\n", grp); 444 "%p Sending message to clients.\n", grp);
@@ -463,7 +463,7 @@ client_send_origin_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash,
463 const struct GNUNET_MessageHeader *msg = cls; 463 const struct GNUNET_MessageHeader *msg = cls;
464 struct Member *orig = origin; 464 struct Member *orig = origin;
465 465
466 client_send (&orig->grp, msg); 466 client_send_msg (&orig->grp, msg);
467 return GNUNET_YES; 467 return GNUNET_YES;
468} 468}
469 469
@@ -480,7 +480,7 @@ client_send_member_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash,
480 480
481 if (NULL != mem->join_dcsn) 481 if (NULL != mem->join_dcsn)
482 { /* Only send message to admitted members */ 482 { /* Only send message to admitted members */
483 client_send (&mem->grp, msg); 483 client_send_msg (&mem->grp, msg);
484 } 484 }
485 return GNUNET_YES; 485 return GNUNET_YES;
486} 486}
@@ -616,6 +616,37 @@ cadet_send_join_request (struct Member *mem)
616} 616}
617 617
618 618
619static int
620cadet_send_join_decision_cb (void *cls,
621 const struct GNUNET_HashCode *group_key_hash,
622 void *channel)
623{
624 const struct MulticastJoinDecisionMessageHeader *hdcsn = cls;
625 struct Channel *chn = channel;
626
627 if (0 == memcmp (&hdcsn->member_key, &chn->member_key, sizeof (chn->member_key))
628 && 0 == memcmp (&hdcsn->peer, &chn->peer, sizeof (chn->peer)))
629 {
630 cadet_send_msg (chn, &hdcsn->header);
631 return GNUNET_NO;
632 }
633 return GNUNET_YES;
634}
635
636
637/**
638 * Send join decision to a remote peer.
639 */
640static void
641cadet_send_join_decision (struct Group *grp,
642 const struct MulticastJoinDecisionMessageHeader *hdcsn)
643{
644 GNUNET_CONTAINER_multihashmap_get_multiple (channels_in, &grp->pub_key_hash,
645 &cadet_send_join_decision_cb,
646 (void *) hdcsn);
647}
648
649
619/** 650/**
620 * Iterator callback for sending a message to origin clients. 651 * Iterator callback for sending a message to origin clients.
621 */ 652 */
@@ -797,7 +828,7 @@ client_recv_member_join (void *cls, struct GNUNET_SERVER_Client *client,
797 req->header.size = htons (sizeof (*req) + join_msg_size); 828 req->header.size = htons (sizeof (*req) + join_msg_size);
798 req->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST); 829 req->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST);
799 req->group_key = grp->pub_key; 830 req->group_key = grp->pub_key;
800 req->member_peer = this_peer; 831 req->peer = this_peer;
801 GNUNET_CRYPTO_ecdsa_key_get_public (&mem->priv_key, &req->member_key); 832 GNUNET_CRYPTO_ecdsa_key_get_public (&mem->priv_key, &req->member_key);
802 if (0 < join_msg_size) 833 if (0 < join_msg_size)
803 memcpy (&req[1], join_msg, join_msg_size); 834 memcpy (&req[1], join_msg, join_msg_size);
@@ -832,7 +863,7 @@ static void
832client_send_join_decision (struct Member *mem, 863client_send_join_decision (struct Member *mem,
833 const struct MulticastJoinDecisionMessageHeader *hdcsn) 864 const struct MulticastJoinDecisionMessageHeader *hdcsn)
834{ 865{
835 client_send (&mem->grp, &hdcsn->header); 866 client_send_msg (&mem->grp, &hdcsn->header);
836 867
837 const struct MulticastJoinDecisionMessage * 868 const struct MulticastJoinDecisionMessage *
838 dcsn = (const struct MulticastJoinDecisionMessage *) &hdcsn[1]; 869 dcsn = (const struct MulticastJoinDecisionMessage *) &hdcsn[1];
@@ -854,6 +885,7 @@ client_send_join_decision (struct Member *mem,
854 } 885 }
855} 886}
856 887
888
857/** 889/**
858 * Join decision from client. 890 * Join decision from client.
859 */ 891 */
@@ -870,29 +902,27 @@ client_recv_join_decision (void *cls, struct GNUNET_SERVER_Client *client,
870 "%p Got join decision from client for group %s..\n", 902 "%p Got join decision from client for group %s..\n",
871 grp, GNUNET_h2s (&grp->pub_key_hash)); 903 grp, GNUNET_h2s (&grp->pub_key_hash));
872 904
873 if (GNUNET_YES 905 struct GNUNET_CONTAINER_MultiHashMap *
874 == GNUNET_CONTAINER_multihashmap_contains (origins, &grp->pub_key_hash)) 906 grp_mem = GNUNET_CONTAINER_multihashmap_get (group_members,
875 { /* Local origin */ 907 &grp->pub_key_hash);
876 struct GNUNET_CONTAINER_MultiHashMap * 908 struct Member *mem = NULL;
877 grp_mem = GNUNET_CONTAINER_multihashmap_get (group_members, 909 if (NULL != grp_mem)
878 &grp->pub_key_hash); 910 {
879 if (NULL != grp_mem) 911 struct GNUNET_HashCode member_key_hash;
880 { 912 GNUNET_CRYPTO_hash (&hdcsn->member_key, sizeof (hdcsn->member_key),
881 struct GNUNET_HashCode member_key_hash; 913 &member_key_hash);
882 GNUNET_CRYPTO_hash (&hdcsn->member_key, sizeof (hdcsn->member_key), 914 mem = GNUNET_CONTAINER_multihashmap_get (grp_mem, &member_key_hash);
883 &member_key_hash); 915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
884 struct Member * 916 "%p ..and member %s: %p\n",
885 mem = GNUNET_CONTAINER_multihashmap_get (grp_mem, &member_key_hash); 917 grp, GNUNET_h2s (&member_key_hash), mem);
886 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 918 }
887 "%p ..and member %s: %p\n", 919 if (NULL != mem)
888 grp, GNUNET_h2s (&member_key_hash), mem); 920 { /* Found local member */
889 if (NULL != mem) 921 client_send_join_decision (mem, hdcsn);
890 client_send_join_decision (mem, hdcsn);
891 }
892 } 922 }
893 else 923 else
894 { 924 { /* Look for remote member */
895 /* FIXME: send join decision to hdcsn->peer */ 925 cadet_send_join_decision (grp, hdcsn);
896 } 926 }
897 GNUNET_SERVER_receive_done (client, GNUNET_OK); 927 GNUNET_SERVER_receive_done (client, GNUNET_OK);
898} 928}
@@ -1097,7 +1127,7 @@ cadet_recv_join_request (void *cls,
1097 chn->group_key = req->group_key; 1127 chn->group_key = req->group_key;
1098 chn->group_key_hash = group_key_hash; 1128 chn->group_key_hash = group_key_hash;
1099 chn->member_key = req->member_key; 1129 chn->member_key = req->member_key;
1100 chn->peer = req->member_peer; 1130 chn->peer = req->peer;
1101 chn->join_status = JOIN_WAITING; 1131 chn->join_status = JOIN_WAITING;
1102 GNUNET_CONTAINER_multihashmap_put (channels_in, &chn->group_key_hash, chn, 1132 GNUNET_CONTAINER_multihashmap_put (channels_in, &chn->group_key_hash, chn,
1103 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1133 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
@@ -1108,7 +1138,7 @@ cadet_recv_join_request (void *cls,
1108 1138
1109 1139
1110/** 1140/**
1111 * Incoming join request message from CADET. 1141 * Incoming join decision message from CADET.
1112 */ 1142 */
1113int 1143int
1114cadet_recv_join_decision (void *cls, 1144cadet_recv_join_decision (void *cls,
diff --git a/src/multicast/multicast.h b/src/multicast/multicast.h
index 82831a218..9b50799ac 100644
--- a/src/multicast/multicast.h
+++ b/src/multicast/multicast.h
@@ -70,7 +70,7 @@ struct MulticastJoinRequestMessage
70 /** 70 /**
71 * Peer identity of the joining member. 71 * Peer identity of the joining member.
72 */ 72 */
73 struct GNUNET_PeerIdentity member_peer; 73 struct GNUNET_PeerIdentity peer;
74 74
75 /* Followed by struct GNUNET_MessageHeader join_message */ 75 /* Followed by struct GNUNET_MessageHeader join_message */
76}; 76};
diff --git a/src/multicast/multicast_api.c b/src/multicast/multicast_api.c
index 5f22741be..aa15edccf 100644
--- a/src/multicast/multicast_api.c
+++ b/src/multicast/multicast_api.c
@@ -159,7 +159,7 @@ struct GNUNET_MULTICAST_JoinHandle
159 /** 159 /**
160 * Peer identity of the member requesting join. 160 * Peer identity of the member requesting join.
161 */ 161 */
162 struct GNUNET_PeerIdentity member_peer; 162 struct GNUNET_PeerIdentity peer;
163}; 163};
164 164
165 165
@@ -232,7 +232,7 @@ group_recv_join_request (void *cls,
232 struct GNUNET_MULTICAST_JoinHandle *jh = GNUNET_malloc (sizeof (*jh)); 232 struct GNUNET_MULTICAST_JoinHandle *jh = GNUNET_malloc (sizeof (*jh));
233 jh->group = grp; 233 jh->group = grp;
234 jh->member_key = jreq->member_key; 234 jh->member_key = jreq->member_key;
235 jh->member_peer = jreq->member_peer; 235 jh->peer = jreq->peer;
236 236
237 const struct GNUNET_MessageHeader *jmsg = NULL; 237 const struct GNUNET_MessageHeader *jmsg = NULL;
238 if (sizeof (*jreq) + sizeof (*jmsg) <= ntohs (jreq->header.size)) 238 if (sizeof (*jreq) + sizeof (*jmsg) <= ntohs (jreq->header.size))
@@ -461,7 +461,7 @@ GNUNET_MULTICAST_join_decision (struct GNUNET_MULTICAST_JoinHandle *join,
461 + relay_size + join_resp_size); 461 + relay_size + join_resp_size);
462 hdcsn->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION); 462 hdcsn->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION);
463 hdcsn->member_key = join->member_key; 463 hdcsn->member_key = join->member_key;
464 hdcsn->peer = join->member_peer; 464 hdcsn->peer = join->peer;
465 465
466 dcsn = (struct MulticastJoinDecisionMessage *) &hdcsn[1]; 466 dcsn = (struct MulticastJoinDecisionMessage *) &hdcsn[1];
467 dcsn->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION); 467 dcsn->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION);