diff options
author | Gabor X Toth <*@tg-x.net> | 2015-09-27 21:04:34 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2015-09-27 21:04:34 +0000 |
commit | cab1b047ddcac497e14515fc11f097c4aac8ee27 (patch) | |
tree | 7f4e14a8c77d76bef07cb4bbf6b94adcce44d53c /src/multicast/gnunet-service-multicast.c | |
parent | 51f530b98232f7a9947f29008d161ed0d8e23af4 (diff) | |
download | gnunet-cab1b047ddcac497e14515fc11f097c4aac8ee27.tar.gz gnunet-cab1b047ddcac497e14515fc11f097c4aac8ee27.zip |
multicast/psyc/social: message acks & scheduling
Diffstat (limited to 'src/multicast/gnunet-service-multicast.c')
-rw-r--r-- | src/multicast/gnunet-service-multicast.c | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/src/multicast/gnunet-service-multicast.c b/src/multicast/gnunet-service-multicast.c index 9ebfa66da..4d2868669 100644 --- a/src/multicast/gnunet-service-multicast.c +++ b/src/multicast/gnunet-service-multicast.c | |||
@@ -181,6 +181,11 @@ struct Channel | |||
181 | int8_t join_status; | 181 | int8_t join_status; |
182 | 182 | ||
183 | /** | 183 | /** |
184 | * Number of messages waiting to be sent to CADET. | ||
185 | */ | ||
186 | uint8_t msgs_pending; | ||
187 | |||
188 | /** | ||
184 | * Channel direction. | 189 | * Channel direction. |
185 | * @see enum ChannelDirection | 190 | * @see enum ChannelDirection |
186 | */ | 191 | */ |
@@ -619,8 +624,10 @@ client_send_member_cb (void *cls, const struct GNUNET_HashCode *pub_key_hash, | |||
619 | /** | 624 | /** |
620 | * Send message to all origin and member clients connected to the group. | 625 | * Send message to all origin and member clients connected to the group. |
621 | * | 626 | * |
622 | * @param grp The group to send @a msg to. | 627 | * @param pub_key_hash |
623 | * @param msg Message to send. | 628 | * H(key_pub) of the group. |
629 | * @param msg | ||
630 | * Message to send. | ||
624 | */ | 631 | */ |
625 | static int | 632 | static int |
626 | client_send_all (struct GNUNET_HashCode *pub_key_hash, | 633 | client_send_all (struct GNUNET_HashCode *pub_key_hash, |
@@ -660,8 +667,10 @@ client_send_random (struct GNUNET_HashCode *pub_key_hash, | |||
660 | /** | 667 | /** |
661 | * Send message to all origin clients connected to the group. | 668 | * Send message to all origin clients connected to the group. |
662 | * | 669 | * |
663 | * @param grp The group to send @a msg to. | 670 | * @param pub_key_hash |
664 | * @param msg Message to send. | 671 | * H(key_pub) of the group. |
672 | * @param msg | ||
673 | * Message to send. | ||
665 | */ | 674 | */ |
666 | static int | 675 | static int |
667 | client_send_origin (struct GNUNET_HashCode *pub_key_hash, | 676 | client_send_origin (struct GNUNET_HashCode *pub_key_hash, |
@@ -676,6 +685,33 @@ client_send_origin (struct GNUNET_HashCode *pub_key_hash, | |||
676 | 685 | ||
677 | 686 | ||
678 | /** | 687 | /** |
688 | * Send fragment acknowledgement to all clients of the channel. | ||
689 | * | ||
690 | * @param pub_key_hash | ||
691 | * H(key_pub) of the group. | ||
692 | */ | ||
693 | static void | ||
694 | client_send_ack (struct GNUNET_HashCode *pub_key_hash) | ||
695 | { | ||
696 | static struct GNUNET_MessageHeader *msg = NULL; | ||
697 | if (NULL == msg) | ||
698 | { | ||
699 | msg = GNUNET_malloc (sizeof (*msg)); | ||
700 | msg->type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_FRAGMENT_ACK); | ||
701 | msg->size = htons (sizeof (*msg)); | ||
702 | } | ||
703 | client_send_all (pub_key_hash, msg); | ||
704 | } | ||
705 | |||
706 | |||
707 | struct CadetTransmitClosure | ||
708 | { | ||
709 | struct Channel *chn; | ||
710 | const struct GNUNET_MessageHeader *msg; | ||
711 | }; | ||
712 | |||
713 | |||
714 | /** | ||
679 | * CADET is ready to transmit a message. | 715 | * CADET is ready to transmit a message. |
680 | */ | 716 | */ |
681 | size_t | 717 | size_t |
@@ -686,10 +722,21 @@ cadet_notify_transmit_ready (void *cls, size_t buf_size, void *buf) | |||
686 | /* FIXME: connection closed */ | 722 | /* FIXME: connection closed */ |
687 | return 0; | 723 | return 0; |
688 | } | 724 | } |
689 | const struct GNUNET_MessageHeader *msg = cls; | 725 | struct CadetTransmitClosure *tcls = cls; |
690 | uint16_t msg_size = ntohs (msg->size); | 726 | struct Channel *chn = tcls->chn; |
727 | uint16_t msg_size = ntohs (tcls->msg->size); | ||
691 | GNUNET_assert (msg_size <= buf_size); | 728 | GNUNET_assert (msg_size <= buf_size); |
692 | memcpy (buf, msg, msg_size); | 729 | memcpy (buf, tcls->msg, msg_size); |
730 | GNUNET_free (tcls); | ||
731 | |||
732 | if (0 == chn->msgs_pending) | ||
733 | { | ||
734 | GNUNET_break (0); | ||
735 | } | ||
736 | else if (0 == --chn->msgs_pending) | ||
737 | { | ||
738 | client_send_ack (&chn->group_key_hash); | ||
739 | } | ||
693 | return msg_size; | 740 | return msg_size; |
694 | } | 741 | } |
695 | 742 | ||
@@ -703,6 +750,11 @@ cadet_notify_transmit_ready (void *cls, size_t buf_size, void *buf) | |||
703 | static void | 750 | static void |
704 | cadet_send_channel (struct Channel *chn, const struct GNUNET_MessageHeader *msg) | 751 | cadet_send_channel (struct Channel *chn, const struct GNUNET_MessageHeader *msg) |
705 | { | 752 | { |
753 | struct CadetTransmitClosure *tcls = GNUNET_malloc (sizeof (*tcls)); | ||
754 | tcls->chn = chn; | ||
755 | tcls->msg = msg; | ||
756 | |||
757 | chn->msgs_pending++; | ||
706 | chn->tmit_handle | 758 | chn->tmit_handle |
707 | = GNUNET_CADET_notify_transmit_ready (chn->channel, GNUNET_NO, | 759 | = GNUNET_CADET_notify_transmit_ready (chn->channel, GNUNET_NO, |
708 | GNUNET_TIME_UNIT_FOREVER_REL, | 760 | GNUNET_TIME_UNIT_FOREVER_REL, |
@@ -1132,7 +1184,10 @@ client_recv_multicast_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
1132 | } | 1184 | } |
1133 | 1185 | ||
1134 | client_send_all (&grp->pub_key_hash, &out->header); | 1186 | client_send_all (&grp->pub_key_hash, &out->header); |
1135 | cadet_send_children (&grp->pub_key_hash, &out->header); | 1187 | if (0 == cadet_send_children (&grp->pub_key_hash, &out->header)) |
1188 | { | ||
1189 | client_send_ack (&grp->pub_key_hash); | ||
1190 | } | ||
1136 | GNUNET_free (out); | 1191 | GNUNET_free (out); |
1137 | 1192 | ||
1138 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1193 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -1174,11 +1229,13 @@ client_recv_multicast_request (void *cls, struct GNUNET_SERVER_Client *client, | |||
1174 | GNUNET_assert (0); | 1229 | GNUNET_assert (0); |
1175 | } | 1230 | } |
1176 | 1231 | ||
1232 | uint8_t send_ack = GNUNET_YES; | ||
1177 | if (0 == client_send_origin (&grp->pub_key_hash, &out->header)) | 1233 | if (0 == client_send_origin (&grp->pub_key_hash, &out->header)) |
1178 | { /* No local origins, send to remote origin */ | 1234 | { /* No local origins, send to remote origin */ |
1179 | if (NULL != mem->origin_channel) | 1235 | if (NULL != mem->origin_channel) |
1180 | { | 1236 | { |
1181 | cadet_send_channel (mem->origin_channel, &out->header); | 1237 | cadet_send_channel (mem->origin_channel, &out->header); |
1238 | send_ack = GNUNET_NO; | ||
1182 | } | 1239 | } |
1183 | else | 1240 | else |
1184 | { | 1241 | { |
@@ -1188,6 +1245,10 @@ client_recv_multicast_request (void *cls, struct GNUNET_SERVER_Client *client, | |||
1188 | return; | 1245 | return; |
1189 | } | 1246 | } |
1190 | } | 1247 | } |
1248 | if (GNUNET_YES == send_ack) | ||
1249 | { | ||
1250 | client_send_ack (&grp->pub_key_hash); | ||
1251 | } | ||
1191 | GNUNET_free (out); | 1252 | GNUNET_free (out); |
1192 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1253 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1193 | } | 1254 | } |