summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2013-09-27 10:13:36 +0000
committerGabor X Toth <*@tg-x.net>2013-09-27 10:13:36 +0000
commit7bbbb8a1f5725497b1edf68cba59529d95fe585d (patch)
tree339f5f6797c3eeb58c6abeda6e13005270dcbd44 /src
parentbcdae74167d2e1f9d8dd9b01fb368bf8bcc2287d (diff)
downloadgnunet-7bbbb8a1f5725497b1edf68cba59529d95fe585d.tar.gz
gnunet-7bbbb8a1f5725497b1edf68cba59529d95fe585d.zip
multicast: simplistic origin_to_all() code to be able to test the psyc service
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_multicast_service.h24
-rw-r--r--src/include/gnunet_psyc_service.h3
-rw-r--r--src/include/gnunet_signatures.h4
-rw-r--r--src/multicast/multicast_api.c143
4 files changed, 133 insertions, 41 deletions
diff --git a/src/include/gnunet_multicast_service.h b/src/include/gnunet_multicast_service.h
index d8d2866a7..ec446a906 100644
--- a/src/include/gnunet_multicast_service.h
+++ b/src/include/gnunet_multicast_service.h
@@ -476,10 +476,10 @@ GNUNET_MULTICAST_replay_response2 (struct GNUNET_MULTICAST_ReplayHandle *rh,
476 * @param cfg Configuration to use. 476 * @param cfg Configuration to use.
477 * @param priv_key ECC key that will be used to sign messages for this 477 * @param priv_key ECC key that will be used to sign messages for this
478 * multicast session; public key is used to identify the multicast group; 478 * multicast session; public key is used to identify the multicast group;
479 * @param last_fragment_id Last fragment ID to continue counting fragments from 479 * @param next_fragment_id Next fragment ID to continue counting fragments from
480 * when restarting the origin. 0 for a new group. 480 * when restarting the origin. 1 for a new group.
481 * @param join_cb Function called to approve / disapprove joining of a peer. 481 * @param join_cb Function called to approve / disapprove joining of a peer.
482 * @param test_cb Function multicast can use to test group membership. 482 * @param mem_test_cb Function multicast can use to test group membership.
483 * @param replay_frag_cb Function that can be called to replay a message fragment. 483 * @param replay_frag_cb Function that can be called to replay a message fragment.
484 * @param replay_msg_cb Function that can be called to replay a message. 484 * @param replay_msg_cb Function that can be called to replay a message.
485 * @param request_cb Function called with message fragments from group members. 485 * @param request_cb Function called with message fragments from group members.
@@ -492,16 +492,16 @@ GNUNET_MULTICAST_replay_response2 (struct GNUNET_MULTICAST_ReplayHandle *rh,
492struct GNUNET_MULTICAST_Origin * 492struct GNUNET_MULTICAST_Origin *
493GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 493GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
494 const struct GNUNET_CRYPTO_EccPrivateKey *priv_key, 494 const struct GNUNET_CRYPTO_EccPrivateKey *priv_key,
495 uint64_t last_fragment_id, 495 uint64_t next_fragment_id,
496 GNUNET_MULTICAST_JoinCallback join_cb, 496 GNUNET_MULTICAST_JoinCallback join_cb,
497 GNUNET_MULTICAST_MembershipTestCallback test_cb, 497 GNUNET_MULTICAST_MembershipTestCallback mem_test_cb,
498 GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb, 498 GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb,
499 GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb, 499 GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb,
500 GNUNET_MULTICAST_RequestCallback request_cb, 500 GNUNET_MULTICAST_RequestCallback request_cb,
501 GNUNET_MULTICAST_MessageCallback message_cb, 501 GNUNET_MULTICAST_MessageCallback message_cb,
502 void *cls); 502 void *cls);
503 503
504/** 504/**
505 * Function called to provide data for a transmission from the origin to all 505 * Function called to provide data for a transmission from the origin to all
506 * members. 506 * members.
507 * 507 *
@@ -509,8 +509,6 @@ GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
509 * invalidates the respective transmission handle. 509 * invalidates the respective transmission handle.
510 * 510 *
511 * @param cls Closure. 511 * @param cls Closure.
512 * @param fragment_id Set to the unique fragment ID that was generated for
513 * this message.
514 * @param[in,out] data_size Initially set to the number of bytes available in 512 * @param[in,out] data_size Initially set to the number of bytes available in
515 * @a data, should be set to the number of bytes written to data. 513 * @a data, should be set to the number of bytes written to data.
516 * @param[out] data Where to write the body of the message to give to the 514 * @param[out] data Where to write the body of the message to give to the
@@ -524,7 +522,6 @@ GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
524 */ 522 */
525typedef int 523typedef int
526(*GNUNET_MULTICAST_OriginTransmitNotify) (void *cls, 524(*GNUNET_MULTICAST_OriginTransmitNotify) (void *cls,
527 uint64_t fragment_id,
528 size_t *data_size, 525 size_t *data_size,
529 void *data); 526 void *data);
530 527
@@ -591,7 +588,7 @@ GNUNET_MULTICAST_origin_stop (struct GNUNET_MULTICAST_Origin *origin);
591 * @a message_cb is invoked with a (failure) response and then with NULL. If 588 * @a message_cb is invoked with a (failure) response and then with NULL. If
592 * the join succeeds, outstanding (state) messages and ongoing multicast 589 * the join succeeds, outstanding (state) messages and ongoing multicast
593 * messages will be given to the @a message_cb until the member decides to part 590 * messages will be given to the @a message_cb until the member decides to part
594 * the group. The @a test_cb and @a replay_cb functions may be called at 591 * the group. The @a mem_test_cb and @a replay_cb functions may be called at
595 * anytime by the multicast service to support relaying messages to other 592 * anytime by the multicast service to support relaying messages to other
596 * members of the group. 593 * members of the group.
597 * 594 *
@@ -611,7 +608,7 @@ GNUNET_MULTICAST_origin_stop (struct GNUNET_MULTICAST_Origin *origin);
611 * identity/pseudonym to peer identity, application-level message to 608 * identity/pseudonym to peer identity, application-level message to
612 * origin, etc.). 609 * origin, etc.).
613 * @param join_cb Function called to approve / disapprove joining of a peer. 610 * @param join_cb Function called to approve / disapprove joining of a peer.
614 * @param test_cb Function multicast can use to test group membership. 611 * @param mem_test_cb Function multicast can use to test group membership.
615 * @param replay_frag_cb Function that can be called to replay message fragments 612 * @param replay_frag_cb Function that can be called to replay message fragments
616 * this peer already knows from this group. NULL if this 613 * this peer already knows from this group. NULL if this
617 * client is unable to support replay. 614 * client is unable to support replay.
@@ -633,7 +630,7 @@ GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
633 const struct GNUNET_PeerIdentity *relays, 630 const struct GNUNET_PeerIdentity *relays,
634 const struct GNUNET_MessageHeader *join_request, 631 const struct GNUNET_MessageHeader *join_request,
635 GNUNET_MULTICAST_JoinCallback join_cb, 632 GNUNET_MULTICAST_JoinCallback join_cb,
636 GNUNET_MULTICAST_MembershipTestCallback test_cb, 633 GNUNET_MULTICAST_MembershipTestCallback mem_test_cb,
637 GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb, 634 GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb,
638 GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb, 635 GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb,
639 GNUNET_MULTICAST_MessageCallback message_cb, 636 GNUNET_MULTICAST_MessageCallback message_cb,
@@ -719,8 +716,6 @@ GNUNET_MULTICAST_member_part (struct GNUNET_MULTICAST_Member *member);
719 * invalidates the respective transmission handle. 716 * invalidates the respective transmission handle.
720 * 717 *
721 * @param cls Closure. 718 * @param cls Closure.
722 * @param fragment_id Set to the unique fragment ID that was generated for
723 * this message.
724 * @param[in,out] data_size Initially set to the number of bytes available in 719 * @param[in,out] data_size Initially set to the number of bytes available in
725 * @a data, should be set to the number of bytes written to data. 720 * @a data, should be set to the number of bytes written to data.
726 * @param[out] data Where to write the body of the message to give to the 721 * @param[out] data Where to write the body of the message to give to the
@@ -734,7 +729,6 @@ GNUNET_MULTICAST_member_part (struct GNUNET_MULTICAST_Member *member);
734 */ 729 */
735typedef int 730typedef int
736(*GNUNET_MULTICAST_MemberTransmitNotify) (void *cls, 731(*GNUNET_MULTICAST_MemberTransmitNotify) (void *cls,
737 uint64_t fragment_id,
738 size_t *data_size, 732 size_t *data_size,
739 void *data); 733 void *data);
740 734
diff --git a/src/include/gnunet_psyc_service.h b/src/include/gnunet_psyc_service.h
index 9502b9fd2..6a20d93d7 100644
--- a/src/include/gnunet_psyc_service.h
+++ b/src/include/gnunet_psyc_service.h
@@ -436,8 +436,6 @@ GNUNET_PSYC_master_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
436 * invalidates the respective transmission handle. 436 * invalidates the respective transmission handle.
437 * 437 *
438 * @param cls Closure. 438 * @param cls Closure.
439 * @param message_id Set to the unique message ID that was generated for
440 * this message.
441 * @param[in,out] data_size Initially set to the number of bytes available in 439 * @param[in,out] data_size Initially set to the number of bytes available in
442 * @a data, should be set to the number of bytes written to data. 440 * @a data, should be set to the number of bytes written to data.
443 * @param[out] data Where to write the body of the message to give to the 441 * @param[out] data Where to write the body of the message to give to the
@@ -451,7 +449,6 @@ GNUNET_PSYC_master_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
451 */ 449 */
452typedef int 450typedef int
453(*GNUNET_PSYC_MasterTransmitNotify) (void *cls, 451(*GNUNET_PSYC_MasterTransmitNotify) (void *cls,
454 uint64_t message_id,
455 size_t *data_size, 452 size_t *data_size,
456 void *data); 453 void *data);
457 454
diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h
index 3dade4cdc..5ecc7830f 100644
--- a/src/include/gnunet_signatures.h
+++ b/src/include/gnunet_signatures.h
@@ -131,6 +131,10 @@ extern "C"
131 */ 131 */
132#define GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT 18 132#define GNUNET_SIGNATURE_PURPOSE_REGEX_ACCEPT 18
133 133
134/**
135 * Signature of a multicast message.
136 */
137#define GNUNET_SIGNATURE_PURPOSE_MULTICAST_MESSAGE 19
134 138
135 139
136#if 0 /* keep Emacsens' auto-indent happy */ 140#if 0 /* keep Emacsens' auto-indent happy */
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 */
33struct GNUNET_MULTICAST_Member 37struct 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 */
41struct GNUNET_MULTICAST_Origin 51struct 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 */
71struct GNUNET_MULTICAST_MemberRequestHandle
72{
73};
74
75
76/**
77 * Opaque handle for a multicast group member.
78 */
79struct 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,
288struct GNUNET_MULTICAST_Origin * 326struct GNUNET_MULTICAST_Origin *
289GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 327GNUNET_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 353static void
306 * (from the origin). 354schedule_origin_to_all (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
307 */
308struct 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
363void 464void
364GNUNET_MULTICAST_origin_stop (struct GNUNET_MULTICAST_Origin *origin) 465GNUNET_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
508void 612void
509GNUNET_MULTICAST_member_part (struct GNUNET_MULTICAST_Member *member) 613GNUNET_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 */
517struct 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.