diff options
author | Gabor X Toth <*@tg-x.net> | 2014-05-22 23:05:27 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2014-05-22 23:05:27 +0000 |
commit | a7100389deab562e67d22ff68961b68a62341aec (patch) | |
tree | dbafc72c162df8627e639bd5e5190d8dc321d63d /src/multicast | |
parent | c3bc1d8ef6e78e543d0077a57b04ae480f1d7caf (diff) | |
download | gnunet-a7100389deab562e67d22ff68961b68a62341aec.tar.gz gnunet-a7100389deab562e67d22ff68961b68a62341aec.zip |
psyc, multicast: join decision
Diffstat (limited to 'src/multicast')
-rw-r--r-- | src/multicast/Makefile.am | 8 | ||||
-rw-r--r-- | src/multicast/gnunet-service-multicast.c | 126 | ||||
-rw-r--r-- | src/multicast/multicast.h | 49 | ||||
-rw-r--r-- | src/multicast/multicast_api.c | 77 | ||||
-rw-r--r-- | src/multicast/test_multicast.c (renamed from src/multicast/test_multicast_api.c) | 6 |
5 files changed, 215 insertions, 51 deletions
diff --git a/src/multicast/Makefile.am b/src/multicast/Makefile.am index 752736c49..b2c1702e4 100644 --- a/src/multicast/Makefile.am +++ b/src/multicast/Makefile.am | |||
@@ -54,15 +54,15 @@ gnunet_service_multicast_DEPENDENCIES = \ | |||
54 | 54 | ||
55 | 55 | ||
56 | check_PROGRAMS = \ | 56 | check_PROGRAMS = \ |
57 | test_multicast_api | 57 | test_multicast |
58 | 58 | ||
59 | if ENABLE_TEST_RUN | 59 | if ENABLE_TEST_RUN |
60 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; | 60 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; |
61 | TESTS = $(check_PROGRAMS) | 61 | TESTS = $(check_PROGRAMS) |
62 | endif | 62 | endif |
63 | 63 | ||
64 | test_multicast_api_SOURCES = \ | 64 | test_multicast_SOURCES = \ |
65 | test_multicast_api.c | 65 | test_multicast.c |
66 | test_multicast_api_LDADD = \ | 66 | test_multicast_LDADD = \ |
67 | $(top_builddir)/src/util/libgnunetutil.la | 67 | $(top_builddir)/src/util/libgnunetutil.la |
68 | 68 | ||
diff --git a/src/multicast/gnunet-service-multicast.c b/src/multicast/gnunet-service-multicast.c index 0394ee19e..bd6616589 100644 --- a/src/multicast/gnunet-service-multicast.c +++ b/src/multicast/gnunet-service-multicast.c | |||
@@ -147,7 +147,7 @@ struct Member | |||
147 | /** | 147 | /** |
148 | * Join request sent to the origin / members. | 148 | * Join request sent to the origin / members. |
149 | */ | 149 | */ |
150 | struct GNUNET_MULTICAST_JoinRequest *join_request; | 150 | struct MulticastJoinRequestMessage *join_request; |
151 | 151 | ||
152 | /** | 152 | /** |
153 | * Join decision sent in reply to our request. | 153 | * Join decision sent in reply to our request. |
@@ -206,6 +206,8 @@ cleanup_member (struct Member *mem) | |||
206 | grp_mem); | 206 | grp_mem); |
207 | GNUNET_CONTAINER_multihashmap_destroy (grp_mem); | 207 | GNUNET_CONTAINER_multihashmap_destroy (grp_mem); |
208 | } | 208 | } |
209 | if (NULL != mem->join_decision) | ||
210 | GNUNET_free (mem->join_decision); | ||
209 | GNUNET_CONTAINER_multihashmap_remove (members, &grp->pub_key_hash, mem); | 211 | GNUNET_CONTAINER_multihashmap_remove (members, &grp->pub_key_hash, mem); |
210 | } | 212 | } |
211 | 213 | ||
@@ -425,8 +427,8 @@ static void | |||
425 | handle_member_join (void *cls, struct GNUNET_SERVER_Client *client, | 427 | handle_member_join (void *cls, struct GNUNET_SERVER_Client *client, |
426 | const struct GNUNET_MessageHeader *m) | 428 | const struct GNUNET_MessageHeader *m) |
427 | { | 429 | { |
428 | struct MulticastMemberJoinMessage * | 430 | const struct MulticastMemberJoinMessage * |
429 | msg = (struct MulticastMemberJoinMessage *) m; | 431 | msg = (const struct MulticastMemberJoinMessage *) m; |
430 | 432 | ||
431 | struct GNUNET_CRYPTO_EddsaPublicKey mem_pub_key; | 433 | struct GNUNET_CRYPTO_EddsaPublicKey mem_pub_key; |
432 | struct GNUNET_HashCode pub_key_hash, mem_pub_key_hash; | 434 | struct GNUNET_HashCode pub_key_hash, mem_pub_key_hash; |
@@ -440,17 +442,10 @@ handle_member_join (void *cls, struct GNUNET_SERVER_Client *client, | |||
440 | struct Member *mem = NULL; | 442 | struct Member *mem = NULL; |
441 | struct Group *grp; | 443 | struct Group *grp; |
442 | 444 | ||
443 | if (NULL == grp_mem) | 445 | if (NULL != grp_mem) |
444 | { | ||
445 | grp_mem = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); | ||
446 | GNUNET_CONTAINER_multihashmap_put (group_members, &pub_key_hash, grp_mem, | ||
447 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
448 | } | ||
449 | else | ||
450 | { | 446 | { |
451 | mem = GNUNET_CONTAINER_multihashmap_get (grp_mem, &mem_pub_key_hash); | 447 | mem = GNUNET_CONTAINER_multihashmap_get (grp_mem, &mem_pub_key_hash); |
452 | } | 448 | } |
453 | |||
454 | if (NULL == mem) | 449 | if (NULL == mem) |
455 | { | 450 | { |
456 | mem = GNUNET_new (struct Member); | 451 | mem = GNUNET_new (struct Member); |
@@ -463,7 +458,13 @@ handle_member_join (void *cls, struct GNUNET_SERVER_Client *client, | |||
463 | grp->pub_key = msg->group_key; | 458 | grp->pub_key = msg->group_key; |
464 | grp->pub_key_hash = pub_key_hash; | 459 | grp->pub_key_hash = pub_key_hash; |
465 | 460 | ||
466 | GNUNET_CONTAINER_multihashmap_put (grp_mem, &mem_pub_key_hash, mem, | 461 | if (NULL == grp_mem) |
462 | { | ||
463 | grp_mem = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES); | ||
464 | GNUNET_CONTAINER_multihashmap_put (group_members, &grp->pub_key_hash, grp_mem, | ||
465 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
466 | } | ||
467 | GNUNET_CONTAINER_multihashmap_put (grp_mem, &mem->pub_key_hash, mem, | ||
467 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 468 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
468 | GNUNET_CONTAINER_multihashmap_put (members, &grp->pub_key_hash, mem, | 469 | GNUNET_CONTAINER_multihashmap_put (members, &grp->pub_key_hash, mem, |
469 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 470 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
@@ -478,8 +479,11 @@ handle_member_join (void *cls, struct GNUNET_SERVER_Client *client, | |||
478 | GNUNET_CONTAINER_DLL_insert (grp->clients_head, grp->clients_tail, cl); | 479 | GNUNET_CONTAINER_DLL_insert (grp->clients_head, grp->clients_tail, cl); |
479 | 480 | ||
480 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 481 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
481 | "%p Client connected as member to group %s.\n", | 482 | "%p Client connected to group %s..\n", |
482 | mem, GNUNET_h2s (&grp->pub_key_hash)); | 483 | mem, GNUNET_h2s (&grp->pub_key_hash)); |
484 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
485 | "%p ..as member %s.\n", | ||
486 | mem, GNUNET_h2s (&mem_pub_key_hash)); | ||
483 | 487 | ||
484 | GNUNET_SERVER_client_set_user_context (client, grp); | 488 | GNUNET_SERVER_client_set_user_context (client, grp); |
485 | 489 | ||
@@ -496,19 +500,19 @@ handle_member_join (void *cls, struct GNUNET_SERVER_Client *client, | |||
496 | struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &msg[1]; | 500 | struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &msg[1]; |
497 | uint32_t relay_count = ntohs (msg->relay_count); | 501 | uint32_t relay_count = ntohs (msg->relay_count); |
498 | struct GNUNET_MessageHeader * | 502 | struct GNUNET_MessageHeader * |
499 | join_req = ((struct GNUNET_MessageHeader *) | 503 | join_msg = ((struct GNUNET_MessageHeader *) |
500 | ((char *) &msg[1]) + relay_count * sizeof (*relays)); | 504 | ((char *) &msg[1]) + relay_count * sizeof (*relays)); |
501 | uint16_t join_req_size = ntohs (join_req->size); | 505 | uint16_t join_msg_size = ntohs (join_msg->size); |
502 | 506 | ||
503 | struct MulticastJoinRequestMessage * | 507 | struct MulticastJoinRequestMessage * |
504 | req = GNUNET_malloc (sizeof (*req) + join_req_size); | 508 | req = GNUNET_malloc (sizeof (*req) + join_msg_size); |
505 | req->header.size = htons (sizeof (*req) + join_req_size); | 509 | req->header.size = htons (sizeof (*req) + join_msg_size); |
506 | req->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST); | 510 | req->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST); |
507 | req->group_key = grp->pub_key; | 511 | req->group_key = grp->pub_key; |
508 | GNUNET_CRYPTO_eddsa_key_get_public (&mem->priv_key, &req->member_key); | 512 | GNUNET_CRYPTO_eddsa_key_get_public (&mem->priv_key, &req->member_key); |
509 | memcpy (&req[1], join_req, join_req_size); | 513 | memcpy (&req[1], join_msg, join_msg_size); |
510 | 514 | ||
511 | req->purpose.size = htonl (sizeof (*req) + join_req_size | 515 | req->purpose.size = htonl (sizeof (*req) + join_msg_size |
512 | - sizeof (req->header) | 516 | - sizeof (req->header) |
513 | - sizeof (req->signature)); | 517 | - sizeof (req->signature)); |
514 | req->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_MULTICAST_REQUEST); | 518 | req->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_MULTICAST_REQUEST); |
@@ -531,7 +535,7 @@ handle_member_join (void *cls, struct GNUNET_SERVER_Client *client, | |||
531 | } | 535 | } |
532 | else | 536 | else |
533 | { | 537 | { |
534 | /* FIXME: send join request to remote origin / members */ | 538 | /* FIXME: send join request to remote peers */ |
535 | } | 539 | } |
536 | } | 540 | } |
537 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 541 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -539,6 +543,85 @@ handle_member_join (void *cls, struct GNUNET_SERVER_Client *client, | |||
539 | 543 | ||
540 | 544 | ||
541 | /** | 545 | /** |
546 | * Join decision from client. | ||
547 | */ | ||
548 | static void | ||
549 | handle_join_decision (void *cls, struct GNUNET_SERVER_Client *client, | ||
550 | const struct GNUNET_MessageHeader *m) | ||
551 | { | ||
552 | struct Group * | ||
553 | grp = GNUNET_SERVER_client_get_user_context (client, struct Group); | ||
554 | const struct MulticastClientJoinDecisionMessage * | ||
555 | cl_dcsn = (const struct MulticastClientJoinDecisionMessage *) m; | ||
556 | |||
557 | struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &cl_dcsn[1]; | ||
558 | uint32_t relay_count = ntohs (cl_dcsn->relay_count); | ||
559 | |||
560 | struct GNUNET_MessageHeader *join_msg = NULL; | ||
561 | uint16_t join_msg_size = 0; | ||
562 | if (sizeof (*cl_dcsn) + relay_count * sizeof (*relays) + sizeof (*m) | ||
563 | <= ntohs (m->size)) | ||
564 | { | ||
565 | join_msg = ((struct GNUNET_MessageHeader *) | ||
566 | ((char *) &cl_dcsn[1]) + relay_count * sizeof (*relays)); | ||
567 | join_msg_size = ntohs (join_msg->size); | ||
568 | } | ||
569 | |||
570 | struct MulticastJoinDecisionMessage * | ||
571 | dcsn = GNUNET_malloc (sizeof (*dcsn) + join_msg_size); | ||
572 | dcsn->header.size = htons (sizeof (*dcsn) + join_msg_size); | ||
573 | dcsn->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION); | ||
574 | dcsn->is_admitted = cl_dcsn->is_admitted; | ||
575 | memcpy (&dcsn[1], join_msg, join_msg_size); | ||
576 | |||
577 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
578 | "%p Got join decision from client for group %s..\n", | ||
579 | grp, GNUNET_h2s (&grp->pub_key_hash)); | ||
580 | |||
581 | if (GNUNET_YES | ||
582 | == GNUNET_CONTAINER_multihashmap_contains (origins, &grp->pub_key_hash)) | ||
583 | { /* Local origin */ | ||
584 | struct GNUNET_CONTAINER_MultiHashMap * | ||
585 | grp_mem = GNUNET_CONTAINER_multihashmap_get (group_members, | ||
586 | &grp->pub_key_hash); | ||
587 | if (NULL != grp_mem) | ||
588 | { | ||
589 | struct GNUNET_HashCode member_key_hash; | ||
590 | GNUNET_CRYPTO_hash (&cl_dcsn->member_key, sizeof (cl_dcsn->member_key), | ||
591 | &member_key_hash); | ||
592 | struct Member * | ||
593 | mem = GNUNET_CONTAINER_multihashmap_get (grp_mem, &member_key_hash); | ||
594 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
595 | "%p ..and member %s: %p\n", | ||
596 | grp, GNUNET_h2s (&member_key_hash), mem); | ||
597 | if (NULL != mem) | ||
598 | { | ||
599 | message_to_clients (grp, (struct GNUNET_MessageHeader *) dcsn); | ||
600 | if (GNUNET_YES == dcsn->is_admitted) | ||
601 | { /* Member admitted, store join_decision. */ | ||
602 | mem->join_decision = dcsn; | ||
603 | } | ||
604 | else | ||
605 | { /* Refused entry, disconnect clients. */ | ||
606 | GNUNET_free (dcsn); | ||
607 | struct ClientList *cl = mem->grp.clients_head; | ||
608 | while (NULL != cl) | ||
609 | { | ||
610 | GNUNET_SERVER_client_disconnect (cl->client); | ||
611 | cl = cl->next; | ||
612 | } | ||
613 | } | ||
614 | } | ||
615 | } | ||
616 | } | ||
617 | else | ||
618 | { | ||
619 | /* FIXME: send join decision to remote peers */ | ||
620 | } | ||
621 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
622 | } | ||
623 | |||
624 | /** | ||
542 | * Incoming message from a client. | 625 | * Incoming message from a client. |
543 | */ | 626 | */ |
544 | static void | 627 | static void |
@@ -633,6 +716,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
633 | { &handle_member_join, NULL, | 716 | { &handle_member_join, NULL, |
634 | GNUNET_MESSAGE_TYPE_MULTICAST_MEMBER_JOIN, 0 }, | 717 | GNUNET_MESSAGE_TYPE_MULTICAST_MEMBER_JOIN, 0 }, |
635 | 718 | ||
719 | { &handle_join_decision, NULL, | ||
720 | GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION, 0 }, | ||
721 | |||
636 | { &handle_multicast_message, NULL, | 722 | { &handle_multicast_message, NULL, |
637 | GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE, 0 }, | 723 | GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE, 0 }, |
638 | 724 | ||
diff --git a/src/multicast/multicast.h b/src/multicast/multicast.h index 5b0fc647c..85c5714e6 100644 --- a/src/multicast/multicast.h +++ b/src/multicast/multicast.h | |||
@@ -36,11 +36,16 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
36 | struct MulticastJoinRequestMessage | 36 | struct MulticastJoinRequestMessage |
37 | { | 37 | { |
38 | /** | 38 | /** |
39 | * Header for the join request. | 39 | * Type: GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_REQUEST |
40 | */ | 40 | */ |
41 | struct GNUNET_MessageHeader header; | 41 | struct GNUNET_MessageHeader header; |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Always zero. | ||
45 | */ | ||
46 | uint32_t reserved; | ||
47 | |||
48 | /** | ||
44 | * ECC signature of the rest of the fields of the join request. | 49 | * ECC signature of the rest of the fields of the join request. |
45 | * | 50 | * |
46 | * Signature must match the public key of the joining member. | 51 | * Signature must match the public key of the joining member. |
@@ -72,31 +77,55 @@ struct MulticastJoinRequestMessage | |||
72 | 77 | ||
73 | 78 | ||
74 | /** | 79 | /** |
75 | * Message sent from the client to the service to notify the service | 80 | * Header of a join decision sent to a remote peer. |
76 | * about a join decision. | ||
77 | */ | 81 | */ |
78 | struct MulticastJoinDecisionMessage | 82 | struct MulticastJoinDecisionMessage |
79 | { | 83 | { |
80 | /** | 84 | /** |
81 | * | 85 | * Type: GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION |
82 | */ | 86 | */ |
83 | struct GNUNET_MessageHeader header; | 87 | struct GNUNET_MessageHeader header; |
84 | 88 | ||
85 | /** | 89 | /** |
86 | * Unique ID that identifies the associated join test. | 90 | * #GNUNET_YES if the peer was admitted. |
87 | */ | 91 | */ |
88 | uint32_t uid; | 92 | uint8_t is_admitted; |
89 | 93 | ||
94 | /* Followed by the join response message */ | ||
95 | }; | ||
96 | |||
97 | |||
98 | /** | ||
99 | * Message sent from the client to the service to notify the service | ||
100 | * about a join decision. | ||
101 | */ | ||
102 | struct MulticastClientJoinDecisionMessage | ||
103 | { | ||
90 | /** | 104 | /** |
91 | * #GNUNET_YES if the peer was admitted. | 105 | * Type: GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION |
92 | */ | 106 | */ |
93 | int32_t is_admitted; | 107 | struct GNUNET_MessageHeader header; |
94 | 108 | ||
95 | /** | 109 | /** |
96 | * Number of relays given. | 110 | * Number of relays given. |
97 | */ | 111 | */ |
98 | uint32_t relay_count; | 112 | uint32_t relay_count; |
99 | 113 | ||
114 | /** | ||
115 | * Public key of the joining member. | ||
116 | */ | ||
117 | struct GNUNET_CRYPTO_EddsaPublicKey member_key; | ||
118 | |||
119 | /** | ||
120 | * Peer identity of the joining member. | ||
121 | */ | ||
122 | struct GNUNET_PeerIdentity member_peer; | ||
123 | |||
124 | /** | ||
125 | * #GNUNET_YES if the peer was admitted. | ||
126 | */ | ||
127 | uint8_t is_admitted; | ||
128 | |||
100 | /* Followed by relay_count peer identities */ | 129 | /* Followed by relay_count peer identities */ |
101 | 130 | ||
102 | /* Followed by the join response message */ | 131 | /* Followed by the join response message */ |
@@ -108,11 +137,11 @@ struct MulticastJoinDecisionMessage | |||
108 | * Message sent from the client to the service to notify the service | 137 | * Message sent from the client to the service to notify the service |
109 | * about the result of a membership test. | 138 | * about the result of a membership test. |
110 | */ | 139 | */ |
111 | struct MulticastMembershipTestResponseMessage | 140 | struct MulticastMembershipTestResultMessage |
112 | { | 141 | { |
113 | 142 | ||
114 | /** | 143 | /** |
115 | * | 144 | * Type: GNUNET_MESSAGE_TYPE_MULTICAST_MEMBERSHIP_TEST_RESULT |
116 | */ | 145 | */ |
117 | struct GNUNET_MessageHeader header; | 146 | struct GNUNET_MessageHeader header; |
118 | 147 | ||
diff --git a/src/multicast/multicast_api.c b/src/multicast/multicast_api.c index 84dac0545..477cb1f2c 100644 --- a/src/multicast/multicast_api.c +++ b/src/multicast/multicast_api.c | |||
@@ -182,8 +182,6 @@ struct GNUNET_MULTICAST_Member | |||
182 | struct GNUNET_PeerIdentity relays; | 182 | struct GNUNET_PeerIdentity relays; |
183 | uint32_t relay_count; | 183 | uint32_t relay_count; |
184 | 184 | ||
185 | struct GNUNET_MessageHeader *join_request; | ||
186 | |||
187 | uint64_t next_fragment_id; | 185 | uint64_t next_fragment_id; |
188 | }; | 186 | }; |
189 | 187 | ||
@@ -501,7 +499,7 @@ join_request_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, | |||
501 | 499 | ||
502 | const struct GNUNET_MessageHeader *msg = NULL; | 500 | const struct GNUNET_MessageHeader *msg = NULL; |
503 | if (sizeof (*req) + sizeof (*msg) <= ntohs (req->header.size)) | 501 | if (sizeof (*req) + sizeof (*msg) <= ntohs (req->header.size)) |
504 | msg =(const struct GNUNET_MessageHeader *) &req[1]; | 502 | msg = (const struct GNUNET_MessageHeader *) &req[1]; |
505 | 503 | ||
506 | grp->join_cb (grp->cb_cls, &req->member_key, msg, jh); | 504 | grp->join_cb (grp->cb_cls, &req->member_key, msg, jh); |
507 | return GNUNET_YES; | 505 | return GNUNET_YES; |
@@ -509,6 +507,25 @@ join_request_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, | |||
509 | 507 | ||
510 | 508 | ||
511 | /** | 509 | /** |
510 | * Iterator callback for calling join decision callbacks of members. | ||
511 | */ | ||
512 | static int | ||
513 | join_decision_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, | ||
514 | void *member) | ||
515 | { | ||
516 | const struct MulticastJoinDecisionMessage *dcsn = cls; | ||
517 | struct GNUNET_MULTICAST_Member *mem = member; | ||
518 | struct GNUNET_MULTICAST_Group *grp = &mem->grp; | ||
519 | |||
520 | const struct GNUNET_MessageHeader *msg = NULL; | ||
521 | if (sizeof (*dcsn) + sizeof (*msg) <= ntohs (dcsn->header.size)) | ||
522 | msg = (const struct GNUNET_MessageHeader *) &dcsn[1]; | ||
523 | |||
524 | // FIXME: grp->join_decision_cb (grp->cb_cls, msg); | ||
525 | return GNUNET_YES; | ||
526 | } | ||
527 | |||
528 | /** | ||
512 | * Function called when we receive a message from the service. | 529 | * Function called when we receive a message from the service. |
513 | * | 530 | * |
514 | * @param cls struct GNUNET_MULTICAST_Group | 531 | * @param cls struct GNUNET_MULTICAST_Group |
@@ -549,6 +566,10 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
549 | size_min = sizeof (struct MulticastJoinRequestMessage); | 566 | size_min = sizeof (struct MulticastJoinRequestMessage); |
550 | break; | 567 | break; |
551 | 568 | ||
569 | case GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION: | ||
570 | size_min = sizeof (struct MulticastJoinDecisionMessage); | ||
571 | break; | ||
572 | |||
552 | default: | 573 | default: |
553 | GNUNET_break_op (0); | 574 | GNUNET_break_op (0); |
554 | type = 0; | 575 | type = 0; |
@@ -592,6 +613,15 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
592 | GNUNET_CONTAINER_multihashmap_get_multiple (members, &grp->pub_key_hash, | 613 | GNUNET_CONTAINER_multihashmap_get_multiple (members, &grp->pub_key_hash, |
593 | join_request_cb, (void *) msg); | 614 | join_request_cb, (void *) msg); |
594 | break; | 615 | break; |
616 | |||
617 | case GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION: | ||
618 | if (NULL != origins) | ||
619 | GNUNET_CONTAINER_multihashmap_get_multiple (origins, &grp->pub_key_hash, | ||
620 | join_decision_cb, (void *) msg); | ||
621 | if (NULL != members) | ||
622 | GNUNET_CONTAINER_multihashmap_get_multiple (members, &grp->pub_key_hash, | ||
623 | join_decision_cb, (void *) msg); | ||
624 | break; | ||
595 | } | 625 | } |
596 | 626 | ||
597 | if (NULL != grp->client) | 627 | if (NULL != grp->client) |
@@ -619,7 +649,7 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
619 | * be the multicast origin) is a good candidate for building the | 649 | * be the multicast origin) is a good candidate for building the |
620 | * multicast tree. Note that it is unnecessary to specify our own | 650 | * multicast tree. Note that it is unnecessary to specify our own |
621 | * peer identity in this array. | 651 | * peer identity in this array. |
622 | * @param join_response Message to send in response to the joining peer; | 652 | * @param join_resp Message to send in response to the joining peer; |
623 | * can also be used to redirect the peer to a different group at the | 653 | * can also be used to redirect the peer to a different group at the |
624 | * application layer; this response is to be transmitted to the | 654 | * application layer; this response is to be transmitted to the |
625 | * peer that issued the request even if admission is denied. | 655 | * peer that issued the request even if admission is denied. |
@@ -629,8 +659,29 @@ GNUNET_MULTICAST_join_decision (struct GNUNET_MULTICAST_JoinHandle *jh, | |||
629 | int is_admitted, | 659 | int is_admitted, |
630 | unsigned int relay_count, | 660 | unsigned int relay_count, |
631 | const struct GNUNET_PeerIdentity *relays, | 661 | const struct GNUNET_PeerIdentity *relays, |
632 | const struct GNUNET_MessageHeader *join_response) | 662 | const struct GNUNET_MessageHeader *join_resp) |
633 | { | 663 | { |
664 | struct GNUNET_MULTICAST_Group *grp = jh->group; | ||
665 | uint16_t join_resp_size = (NULL != join_resp) ? ntohs (join_resp->size) : 0; | ||
666 | uint16_t relay_size = relay_count * sizeof (*relays); | ||
667 | struct MulticastClientJoinDecisionMessage * dcsn; | ||
668 | struct MessageQueue * | ||
669 | mq = GNUNET_malloc (sizeof (*mq) + sizeof (*dcsn) | ||
670 | + relay_size + join_resp_size); | ||
671 | |||
672 | dcsn = (struct MulticastClientJoinDecisionMessage *) &mq[1]; | ||
673 | dcsn->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_JOIN_DECISION); | ||
674 | dcsn->header.size = htons (sizeof (*dcsn) + relay_size + join_resp_size); | ||
675 | dcsn->member_key = jh->member_key; | ||
676 | dcsn->member_peer = jh->member_peer; | ||
677 | dcsn->is_admitted = is_admitted; | ||
678 | dcsn->relay_count = relay_count; | ||
679 | memcpy (&dcsn[1], relays, relay_size); | ||
680 | memcpy (((char *) &dcsn[1]) + relay_size, join_resp, join_resp_size); | ||
681 | |||
682 | GNUNET_CONTAINER_DLL_insert_tail (grp->tmit_head, grp->tmit_tail, mq); | ||
683 | transmit_next (grp); | ||
684 | |||
634 | GNUNET_free (jh); | 685 | GNUNET_free (jh); |
635 | return NULL; | 686 | return NULL; |
636 | } | 687 | } |
@@ -908,10 +959,8 @@ GNUNET_MULTICAST_origin_to_all_cancel (struct GNUNET_MULTICAST_OriginTransmitHan | |||
908 | * @param relays Peer identities of members of the group, which serve as relays | 959 | * @param relays Peer identities of members of the group, which serve as relays |
909 | * and can be used to join the group at. and send the @a join_request to. | 960 | * and can be used to join the group at. and send the @a join_request to. |
910 | * If empty, the @a join_request is sent directly to the @a origin. | 961 | * If empty, the @a join_request is sent directly to the @a origin. |
911 | * @param join_req Application-dependent join request to be passed to the peer | 962 | * @param join_msg Application-dependent join message to be passed to the peer |
912 | * @a relay (might, for example, contain a user, bind user | 963 | * @a origin. |
913 | * identity/pseudonym to peer identity, application-level message to | ||
914 | * origin, etc.). | ||
915 | * @param join_cb Function called to approve / disapprove joining of a peer. | 964 | * @param join_cb Function called to approve / disapprove joining of a peer. |
916 | * @param member_test_cb Function multicast can use to test group membership. | 965 | * @param member_test_cb Function multicast can use to test group membership. |
917 | * @param replay_frag_cb Function that can be called to replay message fragments | 966 | * @param replay_frag_cb Function that can be called to replay message fragments |
@@ -933,7 +982,7 @@ GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
933 | const struct GNUNET_PeerIdentity *origin, | 982 | const struct GNUNET_PeerIdentity *origin, |
934 | uint32_t relay_count, | 983 | uint32_t relay_count, |
935 | const struct GNUNET_PeerIdentity *relays, | 984 | const struct GNUNET_PeerIdentity *relays, |
936 | const struct GNUNET_MessageHeader *join_req, | 985 | const struct GNUNET_MessageHeader *join_msg, |
937 | GNUNET_MULTICAST_JoinCallback join_cb, | 986 | GNUNET_MULTICAST_JoinCallback join_cb, |
938 | GNUNET_MULTICAST_MembershipTestCallback member_test_cb, | 987 | GNUNET_MULTICAST_MembershipTestCallback member_test_cb, |
939 | GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb, | 988 | GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb, |
@@ -945,16 +994,16 @@ GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
945 | struct GNUNET_MULTICAST_Group *grp = &mem->grp; | 994 | struct GNUNET_MULTICAST_Group *grp = &mem->grp; |
946 | 995 | ||
947 | uint16_t relay_size = relay_count * sizeof (*relays); | 996 | uint16_t relay_size = relay_count * sizeof (*relays); |
948 | uint16_t join_req_size = (NULL != join_req) ? ntohs (join_req->size) : 0; | 997 | uint16_t join_msg_size = (NULL != join_msg) ? ntohs (join_msg->size) : 0; |
949 | struct MulticastMemberJoinMessage * | 998 | struct MulticastMemberJoinMessage * |
950 | join = GNUNET_malloc (sizeof (*join) + relay_size + join_req_size); | 999 | join = GNUNET_malloc (sizeof (*join) + relay_size + join_msg_size); |
951 | join->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MEMBER_JOIN); | 1000 | join->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MEMBER_JOIN); |
952 | join->header.size = htons (sizeof (*join) + relay_size + join_req_size); | 1001 | join->header.size = htons (sizeof (*join) + relay_size + join_msg_size); |
953 | join->group_key = *group_key; | 1002 | join->group_key = *group_key; |
954 | join->member_key = *member_key; | 1003 | join->member_key = *member_key; |
955 | join->origin = *origin; | 1004 | join->origin = *origin; |
956 | memcpy (&join[1], relays, relay_size); | 1005 | memcpy (&join[1], relays, relay_size); |
957 | memcpy (((char *) &join[1]) + relay_size, join_req, join_req_size); | 1006 | memcpy (((char *) &join[1]) + relay_size, join_msg, join_msg_size); |
958 | 1007 | ||
959 | grp->reconnect_msg = (struct GNUNET_MessageHeader *) join; | 1008 | grp->reconnect_msg = (struct GNUNET_MessageHeader *) join; |
960 | grp->is_origin = GNUNET_NO; | 1009 | grp->is_origin = GNUNET_NO; |
diff --git a/src/multicast/test_multicast_api.c b/src/multicast/test_multicast.c index 25224f043..244634c64 100644 --- a/src/multicast/test_multicast_api.c +++ b/src/multicast/test_multicast.c | |||
@@ -18,8 +18,8 @@ | |||
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file multicast/test_multicast_api.c | 21 | * @file multicast/test_multicast.c |
22 | * @brief testcase for multicast.c | 22 | * @brief testcase for multicast_api.c |
23 | */ | 23 | */ |
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_util_lib.h" | 25 | #include "gnunet_util_lib.h" |
@@ -41,4 +41,4 @@ main (int argc, char *argv[]) | |||
41 | return ret; | 41 | return ret; |
42 | } | 42 | } |
43 | 43 | ||
44 | /* end of test_multicast_api.c */ | 44 | /* end of test_multicast.c */ |