diff options
author | Gabor X Toth <*@tg-x.net> | 2013-09-27 10:13:36 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2013-09-27 10:13:36 +0000 |
commit | 7bbbb8a1f5725497b1edf68cba59529d95fe585d (patch) | |
tree | 339f5f6797c3eeb58c6abeda6e13005270dcbd44 /src/multicast | |
parent | bcdae74167d2e1f9d8dd9b01fb368bf8bcc2287d (diff) | |
download | gnunet-7bbbb8a1f5725497b1edf68cba59529d95fe585d.tar.gz gnunet-7bbbb8a1f5725497b1edf68cba59529d95fe585d.zip |
multicast: simplistic origin_to_all() code to be able to test the psyc service
Diffstat (limited to 'src/multicast')
-rw-r--r-- | src/multicast/multicast_api.c | 143 |
1 files changed, 120 insertions, 23 deletions
diff --git a/src/multicast/multicast_api.c b/src/multicast/multicast_api.c index b49d21032..6a7cf98eb 100644 --- a/src/multicast/multicast_api.c +++ b/src/multicast/multicast_api.c | |||
@@ -25,13 +25,23 @@ | |||
25 | * @author Gabor X Toth | 25 | * @author Gabor X Toth |
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_signatures.h" | ||
28 | #include "gnunet_multicast_service.h" | 30 | #include "gnunet_multicast_service.h" |
31 | #include "multicast.h" | ||
29 | 32 | ||
30 | /** | 33 | /** |
31 | * Opaque handle for a multicast group member. | 34 | * Handle for a request to send a message to all multicast group members |
35 | * (from the origin). | ||
32 | */ | 36 | */ |
33 | struct GNUNET_MULTICAST_Member | 37 | struct GNUNET_MULTICAST_OriginMessageHandle |
34 | { | 38 | { |
39 | GNUNET_MULTICAST_OriginTransmitNotify notify; | ||
40 | void *notify_cls; | ||
41 | |||
42 | uint64_t message_id; | ||
43 | uint64_t group_generation; | ||
44 | uint64_t fragment_offset; | ||
35 | }; | 45 | }; |
36 | 46 | ||
37 | 47 | ||
@@ -40,6 +50,34 @@ struct GNUNET_MULTICAST_Member | |||
40 | */ | 50 | */ |
41 | struct GNUNET_MULTICAST_Origin | 51 | struct GNUNET_MULTICAST_Origin |
42 | { | 52 | { |
53 | struct GNUNET_CRYPTO_EccPrivateKey priv_key; | ||
54 | struct GNUNET_MULTICAST_OriginMessageHandle msg_handle; | ||
55 | |||
56 | GNUNET_MULTICAST_JoinCallback join_cb; | ||
57 | GNUNET_MULTICAST_MembershipTestCallback mem_test_cb; | ||
58 | GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb; | ||
59 | GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb; | ||
60 | GNUNET_MULTICAST_RequestCallback request_cb; | ||
61 | GNUNET_MULTICAST_MessageCallback message_cb; | ||
62 | void *cls; | ||
63 | |||
64 | uint64_t next_fragment_id; | ||
65 | }; | ||
66 | |||
67 | |||
68 | /** | ||
69 | * Handle for a message to be delivered from a member to the origin. | ||
70 | */ | ||
71 | struct GNUNET_MULTICAST_MemberRequestHandle | ||
72 | { | ||
73 | }; | ||
74 | |||
75 | |||
76 | /** | ||
77 | * Opaque handle for a multicast group member. | ||
78 | */ | ||
79 | struct GNUNET_MULTICAST_Member | ||
80 | { | ||
43 | }; | 81 | }; |
44 | 82 | ||
45 | 83 | ||
@@ -272,10 +310,10 @@ GNUNET_MULTICAST_replay_response2 (struct GNUNET_MULTICAST_ReplayHandle *rh, | |||
272 | * @param cfg Configuration to use. | 310 | * @param cfg Configuration to use. |
273 | * @param priv_key ECC key that will be used to sign messages for this | 311 | * @param priv_key ECC key that will be used to sign messages for this |
274 | * multicast session; public key is used to identify the multicast group; | 312 | * multicast session; public key is used to identify the multicast group; |
275 | * @param last_fragment_id Last fragment ID to continue counting fragments from | 313 | * @param next_fragment_id Next fragment ID to continue counting fragments from |
276 | * when restarting the origin. 0 for a new group. | 314 | * when restarting the origin. 0 for a new group. |
277 | * @param join_cb Function called to approve / disapprove joining of a peer. | 315 | * @param join_cb Function called to approve / disapprove joining of a peer. |
278 | * @param test_cb Function multicast can use to test group membership. | 316 | * @param mem_test_cb Function multicast can use to test group membership. |
279 | * @param replay_frag_cb Function that can be called to replay a message fragment. | 317 | * @param replay_frag_cb Function that can be called to replay a message fragment. |
280 | * @param replay_msg_cb Function that can be called to replay a message. | 318 | * @param replay_msg_cb Function that can be called to replay a message. |
281 | * @param request_cb Function called with message fragments from group members. | 319 | * @param request_cb Function called with message fragments from group members. |
@@ -288,27 +326,81 @@ GNUNET_MULTICAST_replay_response2 (struct GNUNET_MULTICAST_ReplayHandle *rh, | |||
288 | struct GNUNET_MULTICAST_Origin * | 326 | struct GNUNET_MULTICAST_Origin * |
289 | GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 327 | GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
290 | const struct GNUNET_CRYPTO_EccPrivateKey *priv_key, | 328 | const struct GNUNET_CRYPTO_EccPrivateKey *priv_key, |
291 | uint64_t last_fragment_id, | 329 | uint64_t next_fragment_id, |
292 | GNUNET_MULTICAST_JoinCallback join_cb, | 330 | GNUNET_MULTICAST_JoinCallback join_cb, |
293 | GNUNET_MULTICAST_MembershipTestCallback test_cb, | 331 | GNUNET_MULTICAST_MembershipTestCallback mem_test_cb, |
294 | GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb, | 332 | GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb, |
295 | GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb, | 333 | GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb, |
296 | GNUNET_MULTICAST_RequestCallback request_cb, | 334 | GNUNET_MULTICAST_RequestCallback request_cb, |
297 | GNUNET_MULTICAST_MessageCallback message_cb, | 335 | GNUNET_MULTICAST_MessageCallback message_cb, |
298 | void *cls) | 336 | void *cls) |
299 | { | 337 | { |
300 | return NULL; | 338 | struct GNUNET_MULTICAST_Origin *orig = GNUNET_malloc (sizeof (*orig)); |
339 | orig->priv_key = *priv_key; | ||
340 | orig->next_fragment_id = next_fragment_id; | ||
341 | orig->join_cb = join_cb; | ||
342 | orig->mem_test_cb = mem_test_cb; | ||
343 | orig->replay_frag_cb = replay_frag_cb; | ||
344 | orig->replay_msg_cb = replay_msg_cb; | ||
345 | orig->request_cb = request_cb; | ||
346 | orig->message_cb = message_cb; | ||
347 | orig->cls = cls; | ||
348 | return orig; | ||
301 | } | 349 | } |
302 | 350 | ||
303 | 351 | ||
304 | /** | 352 | /* FIXME: for now just send back to the client what it sent. */ |
305 | * Handle for a request to send a message to all multicast group members | 353 | static void |
306 | * (from the origin). | 354 | schedule_origin_to_all (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
307 | */ | ||
308 | struct GNUNET_MULTICAST_OriginMessageHandle | ||
309 | { | 355 | { |
310 | }; | 356 | struct GNUNET_MULTICAST_Origin *orig = cls; |
357 | struct GNUNET_MULTICAST_OriginMessageHandle *mh = &orig->msg_handle; | ||
358 | |||
359 | size_t buf_size = GNUNET_MULTICAST_FRAGMENT_MAX_SIZE; | ||
360 | struct GNUNET_MULTICAST_MessageHeader *msg | ||
361 | = GNUNET_malloc (sizeof (*msg) + buf_size); | ||
362 | int ret = mh->notify (mh->notify_cls, &buf_size, &msg[1]); | ||
363 | |||
364 | if (ret != GNUNET_YES || ret != GNUNET_NO) | ||
365 | { | ||
366 | /* FIXME: handle error */ | ||
367 | return; | ||
368 | } | ||
369 | |||
370 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE); | ||
371 | msg->header.size = htons (buf_size); | ||
372 | msg->message_id = mh->message_id; | ||
373 | msg->group_generation = mh->group_generation; | ||
374 | |||
375 | /* FIXME: add fragment ID and signature in the service */ | ||
376 | msg->fragment_id = orig->next_fragment_id++; | ||
377 | msg->fragment_offset = mh->fragment_offset; | ||
378 | mh->fragment_offset += buf_size; | ||
379 | msg->purpose.size = htonl (buf_size | ||
380 | - sizeof (msg->header) | ||
381 | - sizeof (msg->hop_counter) | ||
382 | - sizeof (msg->signature)); | ||
383 | msg->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_MULTICAST_MESSAGE); | ||
384 | |||
385 | if (GNUNET_OK != GNUNET_CRYPTO_ecc_sign (&orig->priv_key, &msg->purpose, | ||
386 | &msg->signature)) | ||
387 | { | ||
388 | /* FIXME: handle error */ | ||
389 | return; | ||
390 | } | ||
391 | |||
392 | /* FIXME: send msg to the service and only then call message_cb with the | ||
393 | * returned signed message. | ||
394 | * FIXME: Also send to local members in this group. | ||
395 | */ | ||
396 | orig->message_cb (orig->cls, msg); | ||
311 | 397 | ||
398 | if (GNUNET_NO == ret) | ||
399 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
400 | (GNUNET_TIME_UNIT_SECONDS, 1), | ||
401 | schedule_origin_to_all, mh); | ||
402 | |||
403 | } | ||
312 | 404 | ||
313 | /** | 405 | /** |
314 | * Send a message to the multicast group. | 406 | * Send a message to the multicast group. |
@@ -328,7 +420,16 @@ GNUNET_MULTICAST_origin_to_all (struct GNUNET_MULTICAST_Origin *origin, | |||
328 | GNUNET_MULTICAST_OriginTransmitNotify notify, | 420 | GNUNET_MULTICAST_OriginTransmitNotify notify, |
329 | void *notify_cls) | 421 | void *notify_cls) |
330 | { | 422 | { |
331 | return NULL; | 423 | struct GNUNET_MULTICAST_OriginMessageHandle *mh = &origin->msg_handle; |
424 | mh->message_id = message_id; | ||
425 | mh->group_generation = group_generation; | ||
426 | mh->notify = notify; | ||
427 | mh->notify_cls = notify_cls; | ||
428 | |||
429 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
430 | (GNUNET_TIME_UNIT_SECONDS, 1), | ||
431 | schedule_origin_to_all, origin); | ||
432 | return &origin->msg_handle; | ||
332 | } | 433 | } |
333 | 434 | ||
334 | 435 | ||
@@ -363,6 +464,7 @@ GNUNET_MULTICAST_origin_to_all_cancel (struct GNUNET_MULTICAST_OriginMessageHand | |||
363 | void | 464 | void |
364 | GNUNET_MULTICAST_origin_stop (struct GNUNET_MULTICAST_Origin *origin) | 465 | GNUNET_MULTICAST_origin_stop (struct GNUNET_MULTICAST_Origin *origin) |
365 | { | 466 | { |
467 | GNUNET_free (origin); | ||
366 | } | 468 | } |
367 | 469 | ||
368 | 470 | ||
@@ -422,7 +524,9 @@ GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
422 | GNUNET_MULTICAST_MessageCallback message_cb, | 524 | GNUNET_MULTICAST_MessageCallback message_cb, |
423 | void *cls) | 525 | void *cls) |
424 | { | 526 | { |
425 | return NULL; | 527 | struct GNUNET_MULTICAST_Member *mem = GNUNET_malloc (sizeof (*mem)); |
528 | |||
529 | return mem; | ||
426 | } | 530 | } |
427 | 531 | ||
428 | 532 | ||
@@ -508,18 +612,11 @@ GNUNET_MULTICAST_member_replay_cancel (struct GNUNET_MULTICAST_MemberReplayHandl | |||
508 | void | 612 | void |
509 | GNUNET_MULTICAST_member_part (struct GNUNET_MULTICAST_Member *member) | 613 | GNUNET_MULTICAST_member_part (struct GNUNET_MULTICAST_Member *member) |
510 | { | 614 | { |
615 | GNUNET_free (member); | ||
511 | } | 616 | } |
512 | 617 | ||
513 | 618 | ||
514 | /** | 619 | /** |
515 | * Handle for a message to be delivered from a member to the origin. | ||
516 | */ | ||
517 | struct GNUNET_MULTICAST_MemberRequestHandle | ||
518 | { | ||
519 | }; | ||
520 | |||
521 | |||
522 | /** | ||
523 | * Send a message to the origin of the multicast group. | 620 | * Send a message to the origin of the multicast group. |
524 | * | 621 | * |
525 | * @param member Membership handle. | 622 | * @param member Membership handle. |