aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2014-05-23 14:41:42 +0000
committerGabor X Toth <*@tg-x.net>2014-05-23 14:41:42 +0000
commitc0d549b6ab07a951380b807f1a1c1a767bfd5be0 (patch)
treeba70cffb14676ea17c3ca6ef302d9ffe6d3fc3f2 /src
parent5fe013c4b7b150533839dbca964ffcd2b3fe80a5 (diff)
downloadgnunet-c0d549b6ab07a951380b807f1a1c1a767bfd5be0.tar.gz
gnunet-c0d549b6ab07a951380b807f1a1c1a767bfd5be0.zip
psyc, multicast: fixes, comments
Diffstat (limited to 'src')
-rw-r--r--src/multicast/gnunet-service-multicast.c30
-rw-r--r--src/multicast/multicast_api.c14
-rw-r--r--src/psyc/gnunet-service-psyc.c45
-rw-r--r--src/psyc/psyc_api.c8
4 files changed, 65 insertions, 32 deletions
diff --git a/src/multicast/gnunet-service-multicast.c b/src/multicast/gnunet-service-multicast.c
index bd6616589..d412d3f8e 100644
--- a/src/multicast/gnunet-service-multicast.c
+++ b/src/multicast/gnunet-service-multicast.c
@@ -499,10 +499,16 @@ handle_member_join (void *cls, struct GNUNET_SERVER_Client *client,
499 { /* First client, send join request. */ 499 { /* First client, send join request. */
500 struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &msg[1]; 500 struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &msg[1];
501 uint32_t relay_count = ntohs (msg->relay_count); 501 uint32_t relay_count = ntohs (msg->relay_count);
502 struct GNUNET_MessageHeader * 502 uint16_t relay_size = relay_count * sizeof (*relays);
503 join_msg = ((struct GNUNET_MessageHeader *) 503 struct GNUNET_MessageHeader *join_msg = NULL;
504 ((char *) &msg[1]) + relay_count * sizeof (*relays)); 504 uint16_t join_msg_size = 0;
505 uint16_t join_msg_size = ntohs (join_msg->size); 505 if (sizeof (*msg) + relay_size + sizeof (struct GNUNET_MessageHeader)
506 <= ntohs (msg->header.size))
507 {
508 join_msg = (struct GNUNET_MessageHeader *)
509 (((char *) &msg[1]) + relay_size);
510 join_msg_size = ntohs (join_msg->size);
511 }
506 512
507 struct MulticastJoinRequestMessage * 513 struct MulticastJoinRequestMessage *
508 req = GNUNET_malloc (sizeof (*req) + join_msg_size); 514 req = GNUNET_malloc (sizeof (*req) + join_msg_size);
@@ -510,7 +516,8 @@ handle_member_join (void *cls, struct GNUNET_SERVER_Client *client,
510 req->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST); 516 req->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST);
511 req->group_key = grp->pub_key; 517 req->group_key = grp->pub_key;
512 GNUNET_CRYPTO_eddsa_key_get_public (&mem->priv_key, &req->member_key); 518 GNUNET_CRYPTO_eddsa_key_get_public (&mem->priv_key, &req->member_key);
513 memcpy (&req[1], join_msg, join_msg_size); 519 if (0 < join_msg_size)
520 memcpy (&req[1], join_msg, join_msg_size);
514 521
515 req->purpose.size = htonl (sizeof (*req) + join_msg_size 522 req->purpose.size = htonl (sizeof (*req) + join_msg_size
516 - sizeof (req->header) 523 - sizeof (req->header)
@@ -556,17 +563,18 @@ handle_join_decision (void *cls, struct GNUNET_SERVER_Client *client,
556 563
557 struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &cl_dcsn[1]; 564 struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &cl_dcsn[1];
558 uint32_t relay_count = ntohs (cl_dcsn->relay_count); 565 uint32_t relay_count = ntohs (cl_dcsn->relay_count);
566 uint16_t relay_size = relay_count * sizeof (*relays);
559 567
560 struct GNUNET_MessageHeader *join_msg = NULL; 568 struct GNUNET_MessageHeader *join_msg = NULL;
561 uint16_t join_msg_size = 0; 569 uint16_t join_msg_size = 0;
562 if (sizeof (*cl_dcsn) + relay_count * sizeof (*relays) + sizeof (*m) 570 if (sizeof (*cl_dcsn) + relay_size + sizeof (*m) <= ntohs (m->size))
563 <= ntohs (m->size))
564 { 571 {
565 join_msg = ((struct GNUNET_MessageHeader *) 572 join_msg = (struct GNUNET_MessageHeader *)
566 ((char *) &cl_dcsn[1]) + relay_count * sizeof (*relays)); 573 (((char *) &cl_dcsn[1]) + relay_size);
567 join_msg_size = ntohs (join_msg->size); 574 join_msg_size = ntohs (join_msg->size);
568 } 575 }
569 576
577 int keep_dcsn = GNUNET_NO;
570 struct MulticastJoinDecisionMessage * 578 struct MulticastJoinDecisionMessage *
571 dcsn = GNUNET_malloc (sizeof (*dcsn) + join_msg_size); 579 dcsn = GNUNET_malloc (sizeof (*dcsn) + join_msg_size);
572 dcsn->header.size = htons (sizeof (*dcsn) + join_msg_size); 580 dcsn->header.size = htons (sizeof (*dcsn) + join_msg_size);
@@ -600,10 +608,10 @@ handle_join_decision (void *cls, struct GNUNET_SERVER_Client *client,
600 if (GNUNET_YES == dcsn->is_admitted) 608 if (GNUNET_YES == dcsn->is_admitted)
601 { /* Member admitted, store join_decision. */ 609 { /* Member admitted, store join_decision. */
602 mem->join_decision = dcsn; 610 mem->join_decision = dcsn;
611 keep_dcsn = GNUNET_YES;
603 } 612 }
604 else 613 else
605 { /* Refused entry, disconnect clients. */ 614 { /* Refused entry, disconnect clients. */
606 GNUNET_free (dcsn);
607 struct ClientList *cl = mem->grp.clients_head; 615 struct ClientList *cl = mem->grp.clients_head;
608 while (NULL != cl) 616 while (NULL != cl)
609 { 617 {
@@ -618,6 +626,8 @@ handle_join_decision (void *cls, struct GNUNET_SERVER_Client *client,
618 { 626 {
619 /* FIXME: send join decision to remote peers */ 627 /* FIXME: send join decision to remote peers */
620 } 628 }
629 if (GNUNET_NO == keep_dcsn)
630 GNUNET_free (dcsn);
621 GNUNET_SERVER_receive_done (client, GNUNET_OK); 631 GNUNET_SERVER_receive_done (client, GNUNET_OK);
622} 632}
623 633
diff --git a/src/multicast/multicast_api.c b/src/multicast/multicast_api.c
index 477cb1f2c..501ff4b70 100644
--- a/src/multicast/multicast_api.c
+++ b/src/multicast/multicast_api.c
@@ -676,8 +676,10 @@ GNUNET_MULTICAST_join_decision (struct GNUNET_MULTICAST_JoinHandle *jh,
676 dcsn->member_peer = jh->member_peer; 676 dcsn->member_peer = jh->member_peer;
677 dcsn->is_admitted = is_admitted; 677 dcsn->is_admitted = is_admitted;
678 dcsn->relay_count = relay_count; 678 dcsn->relay_count = relay_count;
679 memcpy (&dcsn[1], relays, relay_size); 679 if (0 < relay_size)
680 memcpy (((char *) &dcsn[1]) + relay_size, join_resp, join_resp_size); 680 memcpy (&dcsn[1], relays, relay_size);
681 if (0 < join_resp_size)
682 memcpy (((char *) &dcsn[1]) + relay_size, join_resp, join_resp_size);
681 683
682 GNUNET_CONTAINER_DLL_insert_tail (grp->tmit_head, grp->tmit_tail, mq); 684 GNUNET_CONTAINER_DLL_insert_tail (grp->tmit_head, grp->tmit_tail, mq);
683 transmit_next (grp); 685 transmit_next (grp);
@@ -997,13 +999,15 @@ GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
997 uint16_t join_msg_size = (NULL != join_msg) ? ntohs (join_msg->size) : 0; 999 uint16_t join_msg_size = (NULL != join_msg) ? ntohs (join_msg->size) : 0;
998 struct MulticastMemberJoinMessage * 1000 struct MulticastMemberJoinMessage *
999 join = GNUNET_malloc (sizeof (*join) + relay_size + join_msg_size); 1001 join = GNUNET_malloc (sizeof (*join) + relay_size + join_msg_size);
1000 join->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MEMBER_JOIN);
1001 join->header.size = htons (sizeof (*join) + relay_size + join_msg_size); 1002 join->header.size = htons (sizeof (*join) + relay_size + join_msg_size);
1003 join->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MEMBER_JOIN);
1002 join->group_key = *group_key; 1004 join->group_key = *group_key;
1003 join->member_key = *member_key; 1005 join->member_key = *member_key;
1004 join->origin = *origin; 1006 join->origin = *origin;
1005 memcpy (&join[1], relays, relay_size); 1007 if (0 < relay_size)
1006 memcpy (((char *) &join[1]) + relay_size, join_msg, join_msg_size); 1008 memcpy (&join[1], relays, relay_size);
1009 if (0 < join_msg_size)
1010 memcpy (((char *) &join[1]) + relay_size, join_msg, join_msg_size);
1007 1011
1008 grp->reconnect_msg = (struct GNUNET_MessageHeader *) join; 1012 grp->reconnect_msg = (struct GNUNET_MessageHeader *) join;
1009 grp->is_origin = GNUNET_NO; 1013 grp->is_origin = GNUNET_NO;
diff --git a/src/psyc/gnunet-service-psyc.c b/src/psyc/gnunet-service-psyc.c
index 7669eed15..2b9ee7135 100644
--- a/src/psyc/gnunet-service-psyc.c
+++ b/src/psyc/gnunet-service-psyc.c
@@ -628,7 +628,8 @@ join_cb (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key,
628 req->header.size = htons (sizeof (*req) + join_msg_size); 628 req->header.size = htons (sizeof (*req) + join_msg_size);
629 req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST); 629 req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST);
630 req->slave_key = *slave_key; 630 req->slave_key = *slave_key;
631 memcpy (&req[1], join_msg, join_msg_size); 631 if (0 < join_msg_size)
632 memcpy (&req[1], join_msg, join_msg_size);
632 633
633 struct JoinMemTestClosure *jcls = GNUNET_malloc (sizeof (*jcls)); 634 struct JoinMemTestClosure *jcls = GNUNET_malloc (sizeof (*jcls));
634 jcls->slave_key = *slave_key; 635 jcls->slave_key = *slave_key;
@@ -1700,17 +1701,28 @@ slave_queue_message (struct Slave *slv, struct TransmitMessage *tmit_msg,
1700} 1701}
1701 1702
1702 1703
1704/**
1705 * Queue PSYC message parts for sending to multicast.
1706 *
1707 * @param ch Channel to send to.
1708 * @param client Client the message originates from.
1709 * @param data_size Size of @a data.
1710 * @param data Concatenated message parts.
1711 * @param first_ptype First message part type in @a data.
1712 * @param last_ptype Last message part type in @a data.
1713 */
1703static void 1714static void
1704queue_message (struct Channel *ch, 1715queue_message (struct Channel *ch,
1705 struct GNUNET_SERVER_Client *client, 1716 struct GNUNET_SERVER_Client *client,
1706 const struct GNUNET_MessageHeader *msg, 1717 size_t data_size,
1718 const void *data,
1707 uint16_t first_ptype, uint16_t last_ptype) 1719 uint16_t first_ptype, uint16_t last_ptype)
1708{ 1720{
1709 uint16_t size = ntohs (msg->size) - sizeof (*msg); 1721 struct TransmitMessage *
1710 struct TransmitMessage *tmit_msg = GNUNET_malloc (sizeof (*tmit_msg) + size); 1722 tmit_msg = GNUNET_malloc (sizeof (*tmit_msg) + data_size);
1711 memcpy (&tmit_msg[1], &msg[1], size); 1723 memcpy (&tmit_msg[1], data, data_size);
1712 tmit_msg->client = client; 1724 tmit_msg->client = client;
1713 tmit_msg->size = size; 1725 tmit_msg->size = data_size;
1714 tmit_msg->state = ch->tmit_state; 1726 tmit_msg->state = ch->tmit_state;
1715 1727
1716 GNUNET_CONTAINER_DLL_insert_tail (ch->tmit_head, ch->tmit_tail, tmit_msg); 1728 GNUNET_CONTAINER_DLL_insert_tail (ch->tmit_head, ch->tmit_tail, tmit_msg);
@@ -1723,16 +1735,22 @@ queue_message (struct Channel *ch,
1723} 1735}
1724 1736
1725 1737
1738/**
1739 * Cancel transmission of current message.
1740 *
1741 * @param ch Channel to send to.
1742 * @param client Client the message originates from.
1743 */
1726static void 1744static void
1727transmit_error (struct Channel *ch, struct GNUNET_SERVER_Client *client) 1745transmit_cancel (struct Channel *ch, struct GNUNET_SERVER_Client *client)
1728{ 1746{
1729 uint16_t type = GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL; 1747 uint16_t type = GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL;
1730 1748
1731 struct GNUNET_MessageHeader msg; 1749 struct GNUNET_MessageHeader msg;
1732 msg.size = ntohs (sizeof (msg)); 1750 msg.size = htons (sizeof (msg));
1733 msg.type = ntohs (type); 1751 msg.type = htons (type);
1734 1752
1735 queue_message (ch, client, &msg, type, type); 1753 queue_message (ch, client, sizeof (msg), &msg, type, type);
1736 transmit_message (ch); 1754 transmit_message (ch);
1737 1755
1738 /* FIXME: cleanup */ 1756 /* FIXME: cleanup */
@@ -1768,7 +1786,7 @@ handle_psyc_message (void *cls, struct GNUNET_SERVER_Client *client,
1768 { 1786 {
1769 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%p Message payload too large\n", ch); 1787 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%p Message payload too large\n", ch);
1770 GNUNET_break (0); 1788 GNUNET_break (0);
1771 transmit_error (ch, client); 1789 transmit_cancel (ch, client);
1772 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1790 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1773 return; 1791 return;
1774 } 1792 }
@@ -1782,12 +1800,13 @@ handle_psyc_message (void *cls, struct GNUNET_SERVER_Client *client,
1782 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1800 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1783 "%p Received invalid message part from client.\n", ch); 1801 "%p Received invalid message part from client.\n", ch);
1784 GNUNET_break (0); 1802 GNUNET_break (0);
1785 transmit_error (ch, client); 1803 transmit_cancel (ch, client);
1786 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1804 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1787 return; 1805 return;
1788 } 1806 }
1789 1807
1790 queue_message (ch, client, msg, first_ptype, last_ptype); 1808 queue_message (ch, client, size - sizeof (*msg), &msg[1],
1809 first_ptype, last_ptype);
1791 transmit_message (ch); 1810 transmit_message (ch);
1792 1811
1793 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1812 GNUNET_SERVER_receive_done (client, GNUNET_OK);
diff --git a/src/psyc/psyc_api.c b/src/psyc/psyc_api.c
index 82ff18347..ee49a584f 100644
--- a/src/psyc/psyc_api.c
+++ b/src/psyc/psyc_api.c
@@ -1272,7 +1272,7 @@ GNUNET_PSYC_join_decision (struct GNUNET_PSYC_JoinHandle *jh,
1272 struct GNUNET_PSYC_Channel *ch = &jh->mst->ch; 1272 struct GNUNET_PSYC_Channel *ch = &jh->mst->ch;
1273 1273
1274 struct MasterJoinDecision *dcsn; 1274 struct MasterJoinDecision *dcsn;
1275 struct GNUNET_PSYC_MessageHeader *pmsg; 1275 struct GNUNET_PSYC_MessageHeader *pmsg = NULL;
1276 uint16_t pmsg_size = 0; 1276 uint16_t pmsg_size = 0;
1277/* FIXME: 1277/* FIXME:
1278 sizeof (*pmsg) 1278 sizeof (*pmsg)
@@ -1285,14 +1285,14 @@ GNUNET_PSYC_join_decision (struct GNUNET_PSYC_JoinHandle *jh,
1285 struct MessageQueue * 1285 struct MessageQueue *
1286 mq = GNUNET_malloc (sizeof (*mq) + sizeof (*dcsn) + relay_size + pmsg_size); 1286 mq = GNUNET_malloc (sizeof (*mq) + sizeof (*dcsn) + relay_size + pmsg_size);
1287 dcsn = (struct MasterJoinDecision *) &mq[1]; 1287 dcsn = (struct MasterJoinDecision *) &mq[1];
1288 dcsn->header.size = htons (sizeof (*dcsn) + relay_size + pmsg_size);
1288 dcsn->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION); 1289 dcsn->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION);
1289 dcsn->header.size = htons (sizeof (*mq) + sizeof (*dcsn)
1290 + relay_size + pmsg_size);
1291 dcsn->is_admitted = (GNUNET_YES == is_admitted) ? GNUNET_YES : GNUNET_NO; 1290 dcsn->is_admitted = (GNUNET_YES == is_admitted) ? GNUNET_YES : GNUNET_NO;
1292 dcsn->slave_key = jh->slave_key; 1291 dcsn->slave_key = jh->slave_key;
1293 1292
1294 /* FIXME: add message parts to pmsg */ 1293 /* FIXME: add message parts to pmsg */
1295 memcpy (&dcsn[1], pmsg, pmsg_size); 1294 if (0 < pmsg_size)
1295 memcpy (&dcsn[1], pmsg, pmsg_size);
1296 1296
1297 GNUNET_CONTAINER_DLL_insert_tail (ch->tmit_head, ch->tmit_tail, mq); 1297 GNUNET_CONTAINER_DLL_insert_tail (ch->tmit_head, ch->tmit_tail, mq);
1298 transmit_next (ch); 1298 transmit_next (ch);