aboutsummaryrefslogtreecommitdiff
path: root/src/psyc
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/psyc
parent5fe013c4b7b150533839dbca964ffcd2b3fe80a5 (diff)
downloadgnunet-c0d549b6ab07a951380b807f1a1c1a767bfd5be0.tar.gz
gnunet-c0d549b6ab07a951380b807f1a1c1a767bfd5be0.zip
psyc, multicast: fixes, comments
Diffstat (limited to 'src/psyc')
-rw-r--r--src/psyc/gnunet-service-psyc.c45
-rw-r--r--src/psyc/psyc_api.c8
2 files changed, 36 insertions, 17 deletions
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);