aboutsummaryrefslogtreecommitdiff
path: root/src/psyc/psyc_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/psyc/psyc_api.c
parentc3bc1d8ef6e78e543d0077a57b04ae480f1d7caf (diff)
downloadgnunet-a7100389deab562e67d22ff68961b68a62341aec.tar.gz
gnunet-a7100389deab562e67d22ff68961b68a62341aec.zip
psyc, multicast: join decision
Diffstat (limited to 'src/psyc/psyc_api.c')
-rw-r--r--src/psyc/psyc_api.c45
1 files changed, 38 insertions, 7 deletions
diff --git a/src/psyc/psyc_api.c b/src/psyc/psyc_api.c
index 62f099166..82ff18347 100644
--- a/src/psyc/psyc_api.c
+++ b/src/psyc/psyc_api.c
@@ -45,6 +45,7 @@ struct MessageQueue
45{ 45{
46 struct MessageQueue *prev; 46 struct MessageQueue *prev;
47 struct MessageQueue *next; 47 struct MessageQueue *next;
48 /* Followed by struct GNUNET_MessageHeader msg */
48}; 49};
49 50
50 51
@@ -222,7 +223,8 @@ struct GNUNET_PSYC_Slave
222 */ 223 */
223struct GNUNET_PSYC_JoinHandle 224struct GNUNET_PSYC_JoinHandle
224{ 225{
225 226 struct GNUNET_PSYC_Master *mst;
227 struct GNUNET_CRYPTO_EddsaPublicKey slave_key;
226}; 228};
227 229
228 230
@@ -912,11 +914,15 @@ static void
912handle_psyc_join_request (struct GNUNET_PSYC_Master *mst, 914handle_psyc_join_request (struct GNUNET_PSYC_Master *mst,
913 const struct MasterJoinRequest *req) 915 const struct MasterJoinRequest *req)
914{ 916{
915 // FIXME: extract join message from req[1] 917 struct GNUNET_PSYC_MessageHeader *msg = NULL;
916 const char *method_name = "_fixme"; 918 if (ntohs (req->header.size) <= sizeof (*req) + sizeof (*msg))
919 msg = (struct GNUNET_PSYC_MessageHeader *) &req[1];
920
917 struct GNUNET_PSYC_JoinHandle *jh = GNUNET_malloc (sizeof (*jh)); 921 struct GNUNET_PSYC_JoinHandle *jh = GNUNET_malloc (sizeof (*jh));
918 mst->join_cb (mst->ch.cb_cls, &req->slave_key, method_name, 922 jh->mst = mst;
919 0, NULL, NULL, 0, jh); 923 jh->slave_key = req->slave_key;
924
925 mst->join_cb (mst->ch.cb_cls, &req->slave_key, msg, jh);
920} 926}
921 927
922 928
@@ -931,7 +937,6 @@ static void
931message_handler (void *cls, 937message_handler (void *cls,
932 const struct GNUNET_MessageHeader *msg) 938 const struct GNUNET_MessageHeader *msg)
933{ 939{
934 // YUCK! => please have disjoint message handlers...
935 struct GNUNET_PSYC_Channel *ch = cls; 940 struct GNUNET_PSYC_Channel *ch = cls;
936 struct GNUNET_PSYC_Master *mst = cls; 941 struct GNUNET_PSYC_Master *mst = cls;
937 struct GNUNET_PSYC_Slave *slv = cls; 942 struct GNUNET_PSYC_Slave *slv = cls;
@@ -1264,7 +1269,33 @@ GNUNET_PSYC_join_decision (struct GNUNET_PSYC_JoinHandle *jh,
1264 const void *data, 1269 const void *data,
1265 size_t data_size) 1270 size_t data_size)
1266{ 1271{
1267 1272 struct GNUNET_PSYC_Channel *ch = &jh->mst->ch;
1273
1274 struct MasterJoinDecision *dcsn;
1275 struct GNUNET_PSYC_MessageHeader *pmsg;
1276 uint16_t pmsg_size = 0;
1277/* FIXME:
1278 sizeof (*pmsg)
1279 + sizeof (struct GNUNET_PSYC_MessageMethod)
1280 + vars_size
1281 + sizeof (struct GNUNET_MessageHeader) + data_size
1282 + sizeof (struct GNUNET_MessageHeader);
1283*/
1284 uint16_t relay_size = relay_count * sizeof (*relays);
1285 struct MessageQueue *
1286 mq = GNUNET_malloc (sizeof (*mq) + sizeof (*dcsn) + relay_size + pmsg_size);
1287 dcsn = (struct MasterJoinDecision *) &mq[1];
1288 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;
1292 dcsn->slave_key = jh->slave_key;
1293
1294 /* FIXME: add message parts to pmsg */
1295 memcpy (&dcsn[1], pmsg, pmsg_size);
1296
1297 GNUNET_CONTAINER_DLL_insert_tail (ch->tmit_head, ch->tmit_tail, mq);
1298 transmit_next (ch);
1268} 1299}
1269 1300
1270 1301