aboutsummaryrefslogtreecommitdiff
path: root/src/multicast/gnunet-service-multicast.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/multicast/gnunet-service-multicast.c')
-rw-r--r--src/multicast/gnunet-service-multicast.c54
1 files changed, 40 insertions, 14 deletions
diff --git a/src/multicast/gnunet-service-multicast.c b/src/multicast/gnunet-service-multicast.c
index e84fdb20f..de65e0ab7 100644
--- a/src/multicast/gnunet-service-multicast.c
+++ b/src/multicast/gnunet-service-multicast.c
@@ -710,15 +710,19 @@ cadet_notify_transmit_ready (void *cls, size_t buf_size, void *buf)
710static void 710static void
711cadet_send_channel (struct Channel *chn, const struct GNUNET_MessageHeader *msg) 711cadet_send_channel (struct Channel *chn, const struct GNUNET_MessageHeader *msg)
712{ 712{
713 uint16_t msg_size = ntohs (msg->size);
714 struct GNUNET_MessageHeader *msg_copy = GNUNET_malloc (msg_size);
715 GNUNET_memcpy (msg_copy, msg, msg_size);
716
713 struct CadetTransmitClosure *tcls = GNUNET_malloc (sizeof (*tcls)); 717 struct CadetTransmitClosure *tcls = GNUNET_malloc (sizeof (*tcls));
714 tcls->chn = chn; 718 tcls->chn = chn;
715 tcls->msg = msg; 719 tcls->msg = msg_copy;
716 720
717 chn->msgs_pending++; 721 chn->msgs_pending++;
718 chn->tmit_handle 722 chn->tmit_handle
719 = GNUNET_CADET_notify_transmit_ready (chn->channel, GNUNET_NO, 723 = GNUNET_CADET_notify_transmit_ready (chn->channel, GNUNET_NO,
720 GNUNET_TIME_UNIT_FOREVER_REL, 724 GNUNET_TIME_UNIT_FOREVER_REL,
721 ntohs (msg->size), 725 msg_size,
722 &cadet_notify_transmit_ready, 726 &cadet_notify_transmit_ready,
723 tcls); 727 tcls);
724 GNUNET_assert (NULL != chn->tmit_handle); 728 GNUNET_assert (NULL != chn->tmit_handle);
@@ -783,9 +787,21 @@ cadet_send_join_decision_cb (void *cls,
783 const struct MulticastJoinDecisionMessageHeader *hdcsn = cls; 787 const struct MulticastJoinDecisionMessageHeader *hdcsn = cls;
784 struct Channel *chn = channel; 788 struct Channel *chn = channel;
785 789
790 const struct MulticastJoinDecisionMessage *dcsn =
791 (struct MulticastJoinDecisionMessage *) &hdcsn[1];
792
786 if (0 == memcmp (&hdcsn->member_pub_key, &chn->member_pub_key, sizeof (chn->member_pub_key)) 793 if (0 == memcmp (&hdcsn->member_pub_key, &chn->member_pub_key, sizeof (chn->member_pub_key))
787 && 0 == memcmp (&hdcsn->peer, &chn->peer, sizeof (chn->peer))) 794 && 0 == memcmp (&hdcsn->peer, &chn->peer, sizeof (chn->peer)))
788 { 795 {
796 if (GNUNET_YES == ntohl (dcsn->is_admitted))
797 {
798 chn->join_status = JOIN_ADMITTED;
799 }
800 else
801 {
802 chn->join_status = JOIN_REFUSED;
803 }
804
789 cadet_send_channel (chn, &hdcsn->header); 805 cadet_send_channel (chn, &hdcsn->header);
790 return GNUNET_NO; 806 return GNUNET_NO;
791 } 807 }
@@ -1019,6 +1035,7 @@ handle_client_member_join (void *cls,
1019 if (NULL == mem) 1035 if (NULL == mem)
1020 { 1036 {
1021 mem = GNUNET_new (struct Member); 1037 mem = GNUNET_new (struct Member);
1038 mem->origin = msg->origin;
1022 mem->priv_key = msg->member_key; 1039 mem->priv_key = msg->member_key;
1023 mem->pub_key = mem_pub_key; 1040 mem->pub_key = mem_pub_key;
1024 mem->pub_key_hash = mem_pub_key_hash; 1041 mem->pub_key_hash = mem_pub_key_hash;
@@ -1083,9 +1100,10 @@ handle_client_member_join (void *cls,
1083 join_msg_size = ntohs (join_msg->size); 1100 join_msg_size = ntohs (join_msg->size);
1084 } 1101 }
1085 1102
1103 uint16_t req_msg_size = sizeof (struct MulticastJoinRequestMessage) + join_msg_size;
1086 struct MulticastJoinRequestMessage * 1104 struct MulticastJoinRequestMessage *
1087 req = GNUNET_malloc (sizeof (*req) + join_msg_size); 1105 req = GNUNET_malloc (req_msg_size);
1088 req->header.size = htons (sizeof (*req) + join_msg_size); 1106 req->header.size = htons (req_msg_size);
1089 req->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST); 1107 req->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST);
1090 req->group_pub_key = grp->pub_key; 1108 req->group_pub_key = grp->pub_key;
1091 req->peer = this_peer; 1109 req->peer = this_peer;
@@ -1094,7 +1112,7 @@ handle_client_member_join (void *cls,
1094 GNUNET_memcpy (&req[1], join_msg, join_msg_size); 1112 GNUNET_memcpy (&req[1], join_msg, join_msg_size);
1095 1113
1096 req->member_pub_key = mem->pub_key; 1114 req->member_pub_key = mem->pub_key;
1097 req->purpose.size = htonl (msg_size 1115 req->purpose.size = htonl (req_msg_size
1098 - sizeof (req->header) 1116 - sizeof (req->header)
1099 - sizeof (req->reserved) 1117 - sizeof (req->reserved)
1100 - sizeof (req->signature)); 1118 - sizeof (req->signature));
@@ -1534,6 +1552,7 @@ cadet_recv_join_request (void *cls,
1534 void **ctx, 1552 void **ctx,
1535 const struct GNUNET_MessageHeader *m) 1553 const struct GNUNET_MessageHeader *m)
1536{ 1554{
1555 GNUNET_CADET_receive_done(channel);
1537 const struct MulticastJoinRequestMessage * 1556 const struct MulticastJoinRequestMessage *
1538 req = (const struct MulticastJoinRequestMessage *) m; 1557 req = (const struct MulticastJoinRequestMessage *) m;
1539 uint16_t size = ntohs (m->size); 1558 uint16_t size = ntohs (m->size);
@@ -1576,6 +1595,7 @@ cadet_recv_join_request (void *cls,
1576 chn->join_status = JOIN_WAITING; 1595 chn->join_status = JOIN_WAITING;
1577 GNUNET_CONTAINER_multihashmap_put (channels_in, &chn->group_pub_hash, chn, 1596 GNUNET_CONTAINER_multihashmap_put (channels_in, &chn->group_pub_hash, chn,
1578 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1597 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1598 *ctx = chn;
1579 1599
1580 client_send_all (&group_pub_hash, m); 1600 client_send_all (&group_pub_hash, m);
1581 return GNUNET_OK; 1601 return GNUNET_OK;
@@ -1591,10 +1611,14 @@ cadet_recv_join_decision (void *cls,
1591 void **ctx, 1611 void **ctx,
1592 const struct GNUNET_MessageHeader *m) 1612 const struct GNUNET_MessageHeader *m)
1593{ 1613{
1614 GNUNET_CADET_receive_done (channel);
1615 const struct MulticastJoinDecisionMessageHeader *
1616 hdcsn = (const struct MulticastJoinDecisionMessageHeader *) m;
1594 const struct MulticastJoinDecisionMessage * 1617 const struct MulticastJoinDecisionMessage *
1595 dcsn = (const struct MulticastJoinDecisionMessage *) m; 1618 dcsn = (const struct MulticastJoinDecisionMessage *) &hdcsn[1];
1596 uint16_t size = ntohs (m->size); 1619 uint16_t size = ntohs (m->size);
1597 if (size < sizeof (*dcsn)) 1620 if (size < sizeof (struct MulticastJoinDecisionMessageHeader) +
1621 sizeof (struct MulticastJoinDecisionMessage))
1598 { 1622 {
1599 GNUNET_break_op (0); 1623 GNUNET_break_op (0);
1600 return GNUNET_SYSERR; 1624 return GNUNET_SYSERR;
@@ -1623,15 +1647,10 @@ cadet_recv_join_decision (void *cls,
1623 break; 1647 break;
1624 } 1648 }
1625 1649
1626 struct MulticastJoinDecisionMessageHeader * 1650 // FIXME: do we need to copy chn->peer or compare it with hdcsn->peer?
1627 hdcsn = GNUNET_malloc (sizeof (*hdcsn) + size);
1628 hdcsn->peer = chn->peer;
1629 GNUNET_memcpy (&hdcsn[1], dcsn, sizeof (*hdcsn) + size);
1630
1631 struct Member *mem = (struct Member *) chn->group; 1651 struct Member *mem = (struct Member *) chn->group;
1632 client_send_join_decision (mem, hdcsn); 1652 client_send_join_decision (mem, hdcsn);
1633 GNUNET_free (hdcsn); 1653 if (GNUNET_YES == ntohl (dcsn->is_admitted))
1634 if (GNUNET_YES == ntohs (dcsn->is_admitted))
1635 { 1654 {
1636 chn->join_status = JOIN_ADMITTED; 1655 chn->join_status = JOIN_ADMITTED;
1637 return GNUNET_OK; 1656 return GNUNET_OK;
@@ -1652,6 +1671,7 @@ cadet_recv_message (void *cls,
1652 void **ctx, 1671 void **ctx,
1653 const struct GNUNET_MessageHeader *m) 1672 const struct GNUNET_MessageHeader *m)
1654{ 1673{
1674 GNUNET_CADET_receive_done(channel);
1655 const struct GNUNET_MULTICAST_MessageHeader * 1675 const struct GNUNET_MULTICAST_MessageHeader *
1656 msg = (const struct GNUNET_MULTICAST_MessageHeader *) m; 1676 msg = (const struct GNUNET_MULTICAST_MessageHeader *) m;
1657 uint16_t size = ntohs (m->size); 1677 uint16_t size = ntohs (m->size);
@@ -1697,6 +1717,7 @@ cadet_recv_request (void *cls,
1697 void **ctx, 1717 void **ctx,
1698 const struct GNUNET_MessageHeader *m) 1718 const struct GNUNET_MessageHeader *m)
1699{ 1719{
1720 GNUNET_CADET_receive_done(channel);
1700 const struct GNUNET_MULTICAST_RequestHeader * 1721 const struct GNUNET_MULTICAST_RequestHeader *
1701 req = (const struct GNUNET_MULTICAST_RequestHeader *) m; 1722 req = (const struct GNUNET_MULTICAST_RequestHeader *) m;
1702 uint16_t size = ntohs (m->size); 1723 uint16_t size = ntohs (m->size);
@@ -1742,6 +1763,7 @@ cadet_recv_replay_request (void *cls,
1742 void **ctx, 1763 void **ctx,
1743 const struct GNUNET_MessageHeader *m) 1764 const struct GNUNET_MessageHeader *m)
1744{ 1765{
1766 GNUNET_CADET_receive_done(channel);
1745 struct MulticastReplayRequestMessage rep; 1767 struct MulticastReplayRequestMessage rep;
1746 uint16_t size = ntohs (m->size); 1768 uint16_t size = ntohs (m->size);
1747 if (size < sizeof (rep)) 1769 if (size < sizeof (rep))
@@ -1784,6 +1806,7 @@ cadet_recv_replay_response (void *cls,
1784 void **ctx, 1806 void **ctx,
1785 const struct GNUNET_MessageHeader *m) 1807 const struct GNUNET_MessageHeader *m)
1786{ 1808{
1809 GNUNET_CADET_receive_done(channel);
1787 //struct Channel *chn = *ctx; 1810 //struct Channel *chn = *ctx;
1788 1811
1789 /* @todo FIXME: got replay error response, send request to other members */ 1812 /* @todo FIXME: got replay error response, send request to other members */
@@ -1882,6 +1905,9 @@ static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
1882 { cadet_recv_join_request, 1905 { cadet_recv_join_request,
1883 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST, 0 }, 1906 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST, 0 },
1884 1907
1908 { cadet_recv_join_decision,
1909 GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION, 0 },
1910
1885 { cadet_recv_message, 1911 { cadet_recv_message,
1886 GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE, 0 }, 1912 GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE, 0 },
1887 1913