aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/gnunet-service-conversation.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/conversation/gnunet-service-conversation.c')
-rw-r--r--src/conversation/gnunet-service-conversation.c415
1 files changed, 173 insertions, 242 deletions
diff --git a/src/conversation/gnunet-service-conversation.c b/src/conversation/gnunet-service-conversation.c
index ad449a309..3e531e202 100644
--- a/src/conversation/gnunet-service-conversation.c
+++ b/src/conversation/gnunet-service-conversation.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -150,7 +150,6 @@ struct Channel
150 * #GNUNET_YES if the channel was suspended by the local client. 150 * #GNUNET_YES if the channel was suspended by the local client.
151 */ 151 */
152 int8_t suspended_local; 152 int8_t suspended_local;
153
154}; 153};
155 154
156 155
@@ -194,7 +193,6 @@ struct Line
194 * Generator for channel IDs. 193 * Generator for channel IDs.
195 */ 194 */
196 uint32_t cid_gen; 195 uint32_t cid_gen;
197
198}; 196};
199 197
200 198
@@ -223,12 +221,9 @@ static struct GNUNET_PeerIdentity my_identity;
223 * @return NULL for not found 221 * @return NULL for not found
224 */ 222 */
225static struct Channel * 223static struct Channel *
226find_channel_by_line (struct Line *line, 224find_channel_by_line (struct Line *line, uint32_t cid)
227 uint32_t cid)
228{ 225{
229 for (struct Channel *ch = line->channel_head; 226 for (struct Channel *ch = line->channel_head; NULL != ch; ch = ch->next)
230 NULL != ch;
231 ch = ch->next)
232 if (cid == ch->cid) 227 if (cid == ch->cid)
233 return ch; 228 return ch;
234 return NULL; 229 return NULL;
@@ -263,9 +258,7 @@ handle_client_pickup_message (void *cls,
263 if (NULL == ch) 258 if (NULL == ch)
264 { 259 {
265 /* could have been destroyed asynchronously, ignore message */ 260 /* could have been destroyed asynchronously, ignore message */
266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid);
267 "Channel %u not found\n",
268 msg->cid);
269 GNUNET_SERVICE_client_continue (line->client); 262 GNUNET_SERVICE_client_continue (line->client);
270 return; 263 return;
271 } 264 }
@@ -294,12 +287,10 @@ handle_client_pickup_message (void *cls,
294 return; 287 return;
295 } 288 }
296 GNUNET_break (CS_CALLEE_CONNECTED == ch->status); 289 GNUNET_break (CS_CALLEE_CONNECTED == ch->status);
297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending PICK_UP message to cadet\n");
298 "Sending PICK_UP message to cadet\n"); 291 env =
299 env = GNUNET_MQ_msg (mppm, 292 GNUNET_MQ_msg (mppm, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP);
300 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP); 293 GNUNET_MQ_send (ch->mq, env);
301 GNUNET_MQ_send (ch->mq,
302 env);
303 GNUNET_SERVICE_client_continue (line->client); 294 GNUNET_SERVICE_client_continue (line->client);
304} 295}
305 296
@@ -329,18 +320,15 @@ clean_up_channel (struct Channel *ch)
329 case CS_CALLER_CONNECTED: 320 case CS_CALLER_CONNECTED:
330 if (NULL != line) 321 if (NULL != line)
331 { 322 {
332 env = GNUNET_MQ_msg (hup, 323 env =
333 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); 324 GNUNET_MQ_msg (hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
334 hup->cid = ch->cid; 325 hup->cid = ch->cid;
335 GNUNET_MQ_send (line->mq, 326 GNUNET_MQ_send (line->mq, env);
336 env);
337 } 327 }
338 break; 328 break;
339 } 329 }
340 if (NULL != line) 330 if (NULL != line)
341 GNUNET_CONTAINER_DLL_remove (line->channel_head, 331 GNUNET_CONTAINER_DLL_remove (line->channel_head, line->channel_tail, ch);
342 line->channel_tail,
343 ch);
344 GNUNET_free (ch); 332 GNUNET_free (ch);
345} 333}
346 334
@@ -353,8 +341,7 @@ clean_up_channel (struct Channel *ch)
353static void 341static void
354destroy_line_cadet_channels (struct Channel *ch) 342destroy_line_cadet_channels (struct Channel *ch)
355{ 343{
356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroying cadet channels\n");
357 "Destroying cadet channels\n");
358 if (NULL != ch->channel) 345 if (NULL != ch->channel)
359 { 346 {
360 GNUNET_CADET_channel_destroy (ch->channel); 347 GNUNET_CADET_channel_destroy (ch->channel);
@@ -423,9 +410,7 @@ handle_client_hangup_message (void *cls,
423 if (NULL == ch) 410 if (NULL == ch)
424 { 411 {
425 /* could have been destroyed asynchronously, ignore message */ 412 /* could have been destroyed asynchronously, ignore message */
426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid);
427 "Channel %u not found\n",
428 msg->cid);
429 GNUNET_SERVICE_client_continue (line->client); 414 GNUNET_SERVICE_client_continue (line->client);
430 return; 415 return;
431 } 416 }
@@ -460,15 +445,11 @@ handle_client_hangup_message (void *cls,
460 GNUNET_SERVICE_client_continue (line->client); 445 GNUNET_SERVICE_client_continue (line->client);
461 return; 446 return;
462 } 447 }
463 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending HANG_UP message via cadet\n");
464 "Sending HANG_UP message via cadet\n"); 449 e =
465 e = GNUNET_MQ_msg (mhum, 450 GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP);
466 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP); 451 GNUNET_MQ_notify_sent (e, &mq_done_finish_caller_shutdown, ch);
467 GNUNET_MQ_notify_sent (e, 452 GNUNET_MQ_send (ch->mq, e);
468 &mq_done_finish_caller_shutdown,
469 ch);
470 GNUNET_MQ_send (ch->mq,
471 e);
472 GNUNET_SERVICE_client_continue (line->client); 453 GNUNET_SERVICE_client_continue (line->client);
473} 454}
474 455
@@ -494,9 +475,7 @@ handle_client_suspend_message (void *cls,
494 if (NULL == ch) 475 if (NULL == ch)
495 { 476 {
496 /* could have been destroyed asynchronously, ignore message */ 477 /* could have been destroyed asynchronously, ignore message */
497 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid);
498 "Channel %u not found\n",
499 msg->cid);
500 GNUNET_SERVICE_client_continue (line->client); 479 GNUNET_SERVICE_client_continue (line->client);
501 return; 480 return;
502 } 481 }
@@ -539,12 +518,10 @@ handle_client_suspend_message (void *cls,
539 GNUNET_SERVICE_client_continue (line->client); 518 GNUNET_SERVICE_client_continue (line->client);
540 return; 519 return;
541 } 520 }
542 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUSPEND message via cadet\n");
543 "Sending SUSPEND message via cadet\n"); 522 e =
544 e = GNUNET_MQ_msg (mhum, 523 GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND);
545 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND); 524 GNUNET_MQ_send (ch->mq, e);
546 GNUNET_MQ_send (ch->mq,
547 e);
548 GNUNET_SERVICE_client_continue (line->client); 525 GNUNET_SERVICE_client_continue (line->client);
549} 526}
550 527
@@ -570,9 +547,7 @@ handle_client_resume_message (void *cls,
570 if (NULL == ch) 547 if (NULL == ch)
571 { 548 {
572 /* could have been destroyed asynchronously, ignore message */ 549 /* could have been destroyed asynchronously, ignore message */
573 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 550 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid);
574 "Channel %u not found\n",
575 msg->cid);
576 GNUNET_SERVICE_client_continue (line->client); 551 GNUNET_SERVICE_client_continue (line->client);
577 return; 552 return;
578 } 553 }
@@ -615,12 +590,9 @@ handle_client_resume_message (void *cls,
615 GNUNET_SERVICE_client_drop (line->client); 590 GNUNET_SERVICE_client_drop (line->client);
616 return; 591 return;
617 } 592 }
618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RESUME message via cadet\n");
619 "Sending RESUME message via cadet\n"); 594 e = GNUNET_MQ_msg (mhum, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME);
620 e = GNUNET_MQ_msg (mhum, 595 GNUNET_MQ_send (ch->mq, e);
621 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME);
622 GNUNET_MQ_send (ch->mq,
623 e);
624 GNUNET_SERVICE_client_continue (line->client); 596 GNUNET_SERVICE_client_continue (line->client);
625} 597}
626 598
@@ -647,8 +619,7 @@ channel_audio_sent_notify (void *cls)
647 * @return #GNUNET_OK (any data is ok) 619 * @return #GNUNET_OK (any data is ok)
648 */ 620 */
649static int 621static int
650check_client_audio_message (void *cls, 622check_client_audio_message (void *cls, const struct ClientAudioMessage *msg)
651 const struct ClientAudioMessage *msg)
652{ 623{
653 (void) cls; 624 (void) cls;
654 (void) msg; 625 (void) msg;
@@ -663,8 +634,7 @@ check_client_audio_message (void *cls,
663 * @param msg the message from the client 634 * @param msg the message from the client
664 */ 635 */
665static void 636static void
666handle_client_audio_message (void *cls, 637handle_client_audio_message (void *cls, const struct ClientAudioMessage *msg)
667 const struct ClientAudioMessage *msg)
668{ 638{
669 struct Line *line = cls; 639 struct Line *line = cls;
670 struct CadetAudioMessage *mam; 640 struct CadetAudioMessage *mam;
@@ -672,14 +642,11 @@ handle_client_audio_message (void *cls,
672 size_t size; 642 size_t size;
673 643
674 size = ntohs (msg->header.size) - sizeof (struct ClientAudioMessage); 644 size = ntohs (msg->header.size) - sizeof (struct ClientAudioMessage);
675 ch = find_channel_by_line (line, 645 ch = find_channel_by_line (line, msg->cid);
676 msg->cid);
677 if (NULL == ch) 646 if (NULL == ch)
678 { 647 {
679 /* could have been destroyed asynchronously, ignore message */ 648 /* could have been destroyed asynchronously, ignore message */
680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 649 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Channel %u not found\n", msg->cid);
681 "Channel %u not found\n",
682 msg->cid);
683 GNUNET_SERVICE_client_continue (line->client); 650 GNUNET_SERVICE_client_continue (line->client);
684 return; 651 return;
685 } 652 }
@@ -726,15 +693,10 @@ handle_client_audio_message (void *cls,
726 ch->env = GNUNET_MQ_msg_extra (mam, 693 ch->env = GNUNET_MQ_msg_extra (mam,
727 size, 694 size,
728 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO); 695 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO);
729 GNUNET_memcpy (&mam[1], 696 GNUNET_memcpy (&mam[1], &msg[1], size);
730 &msg[1],
731 size);
732 /* FIXME: set options for unreliable transmission */ 697 /* FIXME: set options for unreliable transmission */
733 GNUNET_MQ_notify_sent (ch->env, 698 GNUNET_MQ_notify_sent (ch->env, &channel_audio_sent_notify, ch);
734 &channel_audio_sent_notify, 699 GNUNET_MQ_send (ch->mq, ch->env);
735 ch);
736 GNUNET_MQ_send (ch->mq,
737 ch->env);
738 GNUNET_SERVICE_client_continue (line->client); 700 GNUNET_SERVICE_client_continue (line->client);
739} 701}
740 702
@@ -746,8 +708,7 @@ handle_client_audio_message (void *cls,
746 * @param msg the incoming message 708 * @param msg the incoming message
747 */ 709 */
748static void 710static void
749handle_cadet_ring_message (void *cls, 711handle_cadet_ring_message (void *cls, const struct CadetPhoneRingMessage *msg)
750 const struct CadetPhoneRingMessage *msg)
751{ 712{
752 struct Channel *ch = cls; 713 struct Channel *ch = cls;
753 struct Line *line = ch->line; 714 struct Line *line = ch->line;
@@ -771,7 +732,9 @@ handle_cadet_ring_message (void *cls,
771 destroy_line_cadet_channels (ch); 732 destroy_line_cadet_channels (ch);
772 return; 733 return;
773 } 734 }
774 if (0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (msg->expiration_time)).rel_value_us) 735 if (0 == GNUNET_TIME_absolute_get_remaining (
736 GNUNET_TIME_absolute_ntoh (msg->expiration_time))
737 .rel_value_us)
775 { 738 {
776 /* ancient call, replay? */ 739 /* ancient call, replay? */
777 GNUNET_break_op (0); 740 GNUNET_break_op (0);
@@ -789,15 +752,13 @@ handle_cadet_ring_message (void *cls,
789 } 752 }
790 GNUNET_CADET_receive_done (ch->channel); 753 GNUNET_CADET_receive_done (ch->channel);
791 ch->status = CS_CALLEE_RINGING; 754 ch->status = CS_CALLEE_RINGING;
792 env = GNUNET_MQ_msg (cring, 755 env = GNUNET_MQ_msg (cring, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING);
793 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING);
794 cring->cid = ch->cid; 756 cring->cid = ch->cid;
795 cring->caller_id = msg->caller_id; 757 cring->caller_id = msg->caller_id;
796 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
797 "Sending RING message to client. CID is %u\n", 759 "Sending RING message to client. CID is %u\n",
798 (unsigned int) ch->cid); 760 (unsigned int) ch->cid);
799 GNUNET_MQ_send (line->mq, 761 GNUNET_MQ_send (line->mq, env);
800 env);
801} 762}
802 763
803 764
@@ -839,13 +800,10 @@ handle_cadet_hangup_message (void *cls,
839 case CS_CALLER_SHUTDOWN: 800 case CS_CALLER_SHUTDOWN:
840 return; 801 return;
841 } 802 }
842 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending HANG UP message to client\n");
843 "Sending HANG UP message to client\n"); 804 env = GNUNET_MQ_msg (hup, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
844 env = GNUNET_MQ_msg (hup,
845 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
846 hup->cid = cid; 805 hup->cid = cid;
847 GNUNET_MQ_send (line->mq, 806 GNUNET_MQ_send (line->mq, env);
848 env);
849} 807}
850 808
851 809
@@ -889,13 +847,11 @@ handle_cadet_pickup_message (void *cls,
889 mq_done_finish_caller_shutdown (ch); 847 mq_done_finish_caller_shutdown (ch);
890 return; 848 return;
891 } 849 }
892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending PICKED UP message to client\n");
893 "Sending PICKED UP message to client\n"); 851 env =
894 env = GNUNET_MQ_msg (pick, 852 GNUNET_MQ_msg (pick, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP);
895 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICKED_UP);
896 pick->cid = ch->cid; 853 pick->cid = ch->cid;
897 GNUNET_MQ_send (line->mq, 854 GNUNET_MQ_send (line->mq, env);
898 env);
899} 855}
900 856
901 857
@@ -916,9 +872,7 @@ handle_cadet_suspend_message (void *cls,
916 872
917 (void) message; 873 (void) message;
918 GNUNET_CADET_receive_done (ch->channel); 874 GNUNET_CADET_receive_done (ch->channel);
919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Suspending channel CID: %u\n", ch->cid);
920 "Suspending channel CID: %u\n",
921 ch->cid);
922 switch (ch->status) 876 switch (ch->status)
923 { 877 {
924 case CS_CALLEE_INIT: 878 case CS_CALLEE_INIT:
@@ -941,11 +895,10 @@ handle_cadet_suspend_message (void *cls,
941 case CS_CALLER_SHUTDOWN: 895 case CS_CALLER_SHUTDOWN:
942 return; 896 return;
943 } 897 }
944 env = GNUNET_MQ_msg (suspend, 898 env =
945 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); 899 GNUNET_MQ_msg (suspend, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND);
946 suspend->cid = ch->cid; 900 suspend->cid = ch->cid;
947 GNUNET_MQ_send (line->mq, 901 GNUNET_MQ_send (line->mq, env);
948 env);
949} 902}
950 903
951 904
@@ -969,8 +922,9 @@ handle_cadet_resume_message (void *cls,
969 GNUNET_CADET_receive_done (ch->channel); 922 GNUNET_CADET_receive_done (ch->channel);
970 if (GNUNET_YES != ch->suspended_remote) 923 if (GNUNET_YES != ch->suspended_remote)
971 { 924 {
972 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 925 GNUNET_log (
973 "RESUME message received for non-suspended channel, dropping channel.\n"); 926 GNUNET_ERROR_TYPE_DEBUG,
927 "RESUME message received for non-suspended channel, dropping channel.\n");
974 destroy_line_cadet_channels (ch); 928 destroy_line_cadet_channels (ch);
975 return; 929 return;
976 } 930 }
@@ -996,11 +950,10 @@ handle_cadet_resume_message (void *cls,
996 case CS_CALLER_SHUTDOWN: 950 case CS_CALLER_SHUTDOWN:
997 return; 951 return;
998 } 952 }
999 env = GNUNET_MQ_msg (resume, 953 env =
1000 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); 954 GNUNET_MQ_msg (resume, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME);
1001 resume->cid = ch->cid; 955 resume->cid = ch->cid;
1002 GNUNET_MQ_send (line->mq, 956 GNUNET_MQ_send (line->mq, env);
1003 env);
1004} 957}
1005 958
1006 959
@@ -1012,8 +965,7 @@ handle_cadet_resume_message (void *cls,
1012 * @return #GNUNET_OK (always) 965 * @return #GNUNET_OK (always)
1013 */ 966 */
1014static int 967static int
1015check_cadet_audio_message (void *cls, 968check_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg)
1016 const struct CadetAudioMessage *msg)
1017{ 969{
1018 (void) cls; 970 (void) cls;
1019 (void) msg; 971 (void) msg;
@@ -1028,8 +980,7 @@ check_cadet_audio_message (void *cls,
1028 * @param msg the incoming message 980 * @param msg the incoming message
1029 */ 981 */
1030static void 982static void
1031handle_cadet_audio_message (void *cls, 983handle_cadet_audio_message (void *cls, const struct CadetAudioMessage *msg)
1032 const struct CadetAudioMessage *msg)
1033{ 984{
1034 struct Channel *ch = cls; 985 struct Channel *ch = cls;
1035 size_t msize = ntohs (msg->header.size) - sizeof (struct CadetAudioMessage); 986 size_t msize = ntohs (msg->header.size) - sizeof (struct CadetAudioMessage);
@@ -1037,28 +988,25 @@ handle_cadet_audio_message (void *cls,
1037 struct ClientAudioMessage *cam; 988 struct ClientAudioMessage *cam;
1038 989
1039 GNUNET_CADET_receive_done (ch->channel); 990 GNUNET_CADET_receive_done (ch->channel);
1040 if ( (GNUNET_YES == ch->suspended_local) || 991 if ((GNUNET_YES == ch->suspended_local) ||
1041 (GNUNET_YES == ch->suspended_remote) ) 992 (GNUNET_YES == ch->suspended_remote))
1042 { 993 {
1043 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 994 GNUNET_log (
1044 "Received %u bytes of AUDIO data on suspended channel CID %u; dropping\n", 995 GNUNET_ERROR_TYPE_DEBUG,
1045 (unsigned int) msize, 996 "Received %u bytes of AUDIO data on suspended channel CID %u; dropping\n",
1046 ch->cid); 997 (unsigned int) msize,
998 ch->cid);
1047 return; 999 return;
1048 } 1000 }
1049 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1001 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1050 "Forwarding %u bytes of AUDIO data to client CID %u\n", 1002 "Forwarding %u bytes of AUDIO data to client CID %u\n",
1051 (unsigned int) msize, 1003 (unsigned int) msize,
1052 ch->cid); 1004 ch->cid);
1053 env = GNUNET_MQ_msg_extra (cam, 1005 env =
1054 msize, 1006 GNUNET_MQ_msg_extra (cam, msize, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO);
1055 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO);
1056 cam->cid = ch->cid; 1007 cam->cid = ch->cid;
1057 GNUNET_memcpy (&cam[1], 1008 GNUNET_memcpy (&cam[1], &msg[1], msize);
1058 &msg[1], 1009 GNUNET_MQ_send (ch->line->mq, env);
1059 msize);
1060 GNUNET_MQ_send (ch->line->mq,
1061 env);
1062} 1010}
1063 1011
1064 1012
@@ -1070,15 +1018,14 @@ handle_cadet_audio_message (void *cls,
1070 * @param channel connection to the other end (henceforth invalid) 1018 * @param channel connection to the other end (henceforth invalid)
1071 */ 1019 */
1072static void 1020static void
1073inbound_end (void *cls, 1021inbound_end (void *cls, const struct GNUNET_CADET_Channel *channel)
1074 const struct GNUNET_CADET_Channel *channel)
1075{ 1022{
1076 struct Channel *ch = cls; 1023 struct Channel *ch = cls;
1077 1024
1078 GNUNET_assert (channel == ch->channel); 1025 GNUNET_assert (channel == ch->channel);
1079 ch->channel = NULL; 1026 ch->channel = NULL;
1080 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1027 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1081 "Channel destroyed by CADET in state %d\n", 1028 "Channel destroyed by CADET in state %d\n",
1082 ch->status); 1029 ch->status);
1083 clean_up_channel (ch); 1030 clean_up_channel (ch);
1084} 1031}
@@ -1091,34 +1038,32 @@ inbound_end (void *cls,
1091 * @param msg the message from the client 1038 * @param msg the message from the client
1092 */ 1039 */
1093static void 1040static void
1094handle_client_call_message (void *cls, 1041handle_client_call_message (void *cls, const struct ClientCallMessage *msg)
1095 const struct ClientCallMessage *msg)
1096{ 1042{
1097 struct Line *line = cls; 1043 struct Line *line = cls;
1098 struct Channel *ch = GNUNET_new (struct Channel); 1044 struct Channel *ch = GNUNET_new (struct Channel);
1099 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1045 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1100 GNUNET_MQ_hd_fixed_size (cadet_hangup_message, 1046 {GNUNET_MQ_hd_fixed_size (cadet_hangup_message,
1101 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, 1047 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP,
1102 struct CadetPhoneHangupMessage, 1048 struct CadetPhoneHangupMessage,
1103 ch), 1049 ch),
1104 GNUNET_MQ_hd_fixed_size (cadet_pickup_message, 1050 GNUNET_MQ_hd_fixed_size (cadet_pickup_message,
1105 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, 1051 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP,
1106 struct CadetPhonePickupMessage, 1052 struct CadetPhonePickupMessage,
1107 ch), 1053 ch),
1108 GNUNET_MQ_hd_fixed_size (cadet_suspend_message, 1054 GNUNET_MQ_hd_fixed_size (cadet_suspend_message,
1109 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, 1055 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND,
1110 struct CadetPhoneSuspendMessage, 1056 struct CadetPhoneSuspendMessage,
1111 ch), 1057 ch),
1112 GNUNET_MQ_hd_fixed_size (cadet_resume_message, 1058 GNUNET_MQ_hd_fixed_size (cadet_resume_message,
1113 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, 1059 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME,
1114 struct CadetPhoneResumeMessage, 1060 struct CadetPhoneResumeMessage,
1115 ch), 1061 ch),
1116 GNUNET_MQ_hd_var_size (cadet_audio_message, 1062 GNUNET_MQ_hd_var_size (cadet_audio_message,
1117 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, 1063 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO,
1118 struct CadetAudioMessage, 1064 struct CadetAudioMessage,
1119 ch), 1065 ch),
1120 GNUNET_MQ_handler_end () 1066 GNUNET_MQ_handler_end ()};
1121 };
1122 struct GNUNET_MQ_Envelope *e; 1067 struct GNUNET_MQ_Envelope *e;
1123 struct CadetPhoneRingMessage *ring; 1068 struct CadetPhoneRingMessage *ring;
1124 struct CadetPhoneRingInfoPS rs; 1069 struct CadetPhoneRingInfoPS rs;
@@ -1128,35 +1073,27 @@ handle_client_call_message (void *cls,
1128 rs.purpose.size = htonl (sizeof (struct CadetPhoneRingInfoPS)); 1073 rs.purpose.size = htonl (sizeof (struct CadetPhoneRingInfoPS));
1129 rs.line_port = line->line_port; 1074 rs.line_port = line->line_port;
1130 rs.target_peer = msg->target; 1075 rs.target_peer = msg->target;
1131 rs.expiration_time 1076 rs.expiration_time =
1132 = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (RING_TIMEOUT)); 1077 GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (RING_TIMEOUT));
1133 ch->line = line; 1078 ch->line = line;
1134 GNUNET_CONTAINER_DLL_insert (line->channel_head, 1079 GNUNET_CONTAINER_DLL_insert (line->channel_head, line->channel_tail, ch);
1135 line->channel_tail,
1136 ch);
1137 ch->status = CS_CALLER_CALLING; 1080 ch->status = CS_CALLER_CALLING;
1138 ch->channel = GNUNET_CADET_channel_create (cadet, 1081 ch->channel = GNUNET_CADET_channel_create (cadet,
1139 ch, 1082 ch,
1140 &msg->target, 1083 &msg->target,
1141 &msg->line_port, 1084 &msg->line_port,
1142 GNUNET_CADET_OPTION_RELIABLE,
1143 NULL, 1085 NULL,
1144 &inbound_end, 1086 &inbound_end,
1145 cadet_handlers); 1087 cadet_handlers);
1146 ch->mq = GNUNET_CADET_get_mq (ch->channel); 1088 ch->mq = GNUNET_CADET_get_mq (ch->channel);
1147 e = GNUNET_MQ_msg (ring, 1089 e = GNUNET_MQ_msg (ring, GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING);
1148 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING); 1090 GNUNET_CRYPTO_ecdsa_key_get_public (&msg->caller_id, &ring->caller_id);
1149 GNUNET_CRYPTO_ecdsa_key_get_public (&msg->caller_id,
1150 &ring->caller_id);
1151 ring->expiration_time = rs.expiration_time; 1091 ring->expiration_time = rs.expiration_time;
1152 GNUNET_assert (GNUNET_OK == 1092 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdsa_sign (&msg->caller_id,
1153 GNUNET_CRYPTO_ecdsa_sign (&msg->caller_id, 1093 &rs.purpose,
1154 &rs.purpose, 1094 &ring->signature));
1155 &ring->signature)); 1095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending RING message via CADET\n");
1156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1096 GNUNET_MQ_send (ch->mq, e);
1157 "Sending RING message via CADET\n");
1158 GNUNET_MQ_send (ch->mq,
1159 e);
1160 GNUNET_SERVICE_client_continue (line->client); 1097 GNUNET_SERVICE_client_continue (line->client);
1161} 1098}
1162 1099
@@ -1188,9 +1125,7 @@ inbound_channel (void *cls,
1188 ch->channel = channel; 1125 ch->channel = channel;
1189 ch->mq = GNUNET_CADET_get_mq (ch->channel); 1126 ch->mq = GNUNET_CADET_get_mq (ch->channel);
1190 ch->cid = line->cid_gen++; 1127 ch->cid = line->cid_gen++;
1191 GNUNET_CONTAINER_DLL_insert (line->channel_head, 1128 GNUNET_CONTAINER_DLL_insert (line->channel_head, line->channel_tail, ch);
1192 line->channel_tail,
1193 ch);
1194 return ch; 1129 return ch;
1195} 1130}
1196 1131
@@ -1235,8 +1170,7 @@ client_disconnect_cb (void *cls,
1235 1170
1236 (void) cls; 1171 (void) cls;
1237 (void) client; 1172 (void) client;
1238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected, closing line\n");
1239 "Client disconnected, closing line\n");
1240 if (NULL != line->port) 1174 if (NULL != line->port)
1241 { 1175 {
1242 GNUNET_CADET_close_port (line->port); 1176 GNUNET_CADET_close_port (line->port);
@@ -1263,33 +1197,32 @@ handle_client_register_message (void *cls,
1263 const struct ClientPhoneRegisterMessage *msg) 1197 const struct ClientPhoneRegisterMessage *msg)
1264{ 1198{
1265 struct Line *line = cls; 1199 struct Line *line = cls;
1266 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1200 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1267 GNUNET_MQ_hd_fixed_size (cadet_ring_message, 1201 {GNUNET_MQ_hd_fixed_size (cadet_ring_message,
1268 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING, 1202 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RING,
1269 struct CadetPhoneRingMessage, 1203 struct CadetPhoneRingMessage,
1270 NULL), 1204 NULL),
1271 GNUNET_MQ_hd_fixed_size (cadet_hangup_message, 1205 GNUNET_MQ_hd_fixed_size (cadet_hangup_message,
1272 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP, 1206 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_HANG_UP,
1273 struct CadetPhoneHangupMessage, 1207 struct CadetPhoneHangupMessage,
1274 NULL), 1208 NULL),
1275 GNUNET_MQ_hd_fixed_size (cadet_pickup_message, 1209 GNUNET_MQ_hd_fixed_size (cadet_pickup_message,
1276 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP, 1210 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_PICK_UP,
1277 struct CadetPhonePickupMessage, 1211 struct CadetPhonePickupMessage,
1278 NULL), 1212 NULL),
1279 GNUNET_MQ_hd_fixed_size (cadet_suspend_message, 1213 GNUNET_MQ_hd_fixed_size (cadet_suspend_message,
1280 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND, 1214 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_SUSPEND,
1281 struct CadetPhoneSuspendMessage, 1215 struct CadetPhoneSuspendMessage,
1282 NULL), 1216 NULL),
1283 GNUNET_MQ_hd_fixed_size (cadet_resume_message, 1217 GNUNET_MQ_hd_fixed_size (cadet_resume_message,
1284 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME, 1218 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_PHONE_RESUME,
1285 struct CadetPhoneResumeMessage, 1219 struct CadetPhoneResumeMessage,
1286 NULL), 1220 NULL),
1287 GNUNET_MQ_hd_var_size (cadet_audio_message, 1221 GNUNET_MQ_hd_var_size (cadet_audio_message,
1288 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO, 1222 GNUNET_MESSAGE_TYPE_CONVERSATION_CADET_AUDIO,
1289 struct CadetAudioMessage, 1223 struct CadetAudioMessage,
1290 NULL), 1224 NULL),
1291 GNUNET_MQ_handler_end () 1225 GNUNET_MQ_handler_end ()};
1292 };
1293 1226
1294 line->line_port = msg->line_port; 1227 line->line_port = msg->line_port;
1295 line->port = GNUNET_CADET_open_port (cadet, 1228 line->port = GNUNET_CADET_open_port (cadet,
@@ -1302,7 +1235,7 @@ handle_client_register_message (void *cls,
1302 if (NULL == line->port) 1235 if (NULL == line->port)
1303 { 1236 {
1304 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1237 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1305 _("Could not open line, port %s already in use!\n"), 1238 _ ("Could not open line, port %s already in use!\n"),
1306 GNUNET_h2s (&msg->line_port)); 1239 GNUNET_h2s (&msg->line_port));
1307 GNUNET_SERVICE_client_drop (line->client); 1240 GNUNET_SERVICE_client_drop (line->client);
1308 return; 1241 return;
@@ -1344,8 +1277,7 @@ run (void *cls,
1344 (void) service; 1277 (void) service;
1345 cfg = c; 1278 cfg = c;
1346 GNUNET_assert (GNUNET_OK == 1279 GNUNET_assert (GNUNET_OK ==
1347 GNUNET_CRYPTO_get_peer_identity (cfg, 1280 GNUNET_CRYPTO_get_peer_identity (cfg, &my_identity));
1348 &my_identity));
1349 cadet = GNUNET_CADET_connect (cfg); 1281 cadet = GNUNET_CADET_connect (cfg);
1350 if (NULL == cadet) 1282 if (NULL == cadet)
1351 { 1283 {
@@ -1353,50 +1285,49 @@ run (void *cls,
1353 GNUNET_SCHEDULER_shutdown (); 1285 GNUNET_SCHEDULER_shutdown ();
1354 return; 1286 return;
1355 } 1287 }
1356 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 1288 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
1357 NULL);
1358} 1289}
1359 1290
1360 1291
1361/** 1292/**
1362 * Define "main" method using service macro. 1293 * Define "main" method using service macro.
1363 */ 1294 */
1364GNUNET_SERVICE_MAIN 1295GNUNET_SERVICE_MAIN (
1365("conversation", 1296 "conversation",
1366 GNUNET_SERVICE_OPTION_NONE, 1297 GNUNET_SERVICE_OPTION_NONE,
1367 &run, 1298 &run,
1368 &client_connect_cb, 1299 &client_connect_cb,
1369 &client_disconnect_cb, 1300 &client_disconnect_cb,
1370 NULL, 1301 NULL,
1371 GNUNET_MQ_hd_fixed_size (client_register_message, 1302 GNUNET_MQ_hd_fixed_size (client_register_message,
1372 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER, 1303 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER,
1373 struct ClientPhoneRegisterMessage, 1304 struct ClientPhoneRegisterMessage,
1374 NULL), 1305 NULL),
1375 GNUNET_MQ_hd_fixed_size (client_pickup_message, 1306 GNUNET_MQ_hd_fixed_size (client_pickup_message,
1376 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP, 1307 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP,
1377 struct ClientPhonePickupMessage, 1308 struct ClientPhonePickupMessage,
1378 NULL), 1309 NULL),
1379 GNUNET_MQ_hd_fixed_size (client_suspend_message, 1310 GNUNET_MQ_hd_fixed_size (client_suspend_message,
1380 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, 1311 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND,
1381 struct ClientPhoneSuspendMessage, 1312 struct ClientPhoneSuspendMessage,
1382 NULL), 1313 NULL),
1383 GNUNET_MQ_hd_fixed_size (client_resume_message, 1314 GNUNET_MQ_hd_fixed_size (client_resume_message,
1384 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, 1315 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME,
1385 struct ClientPhoneResumeMessage, 1316 struct ClientPhoneResumeMessage,
1386 NULL), 1317 NULL),
1387 GNUNET_MQ_hd_fixed_size (client_hangup_message, 1318 GNUNET_MQ_hd_fixed_size (client_hangup_message,
1388 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, 1319 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP,
1389 struct ClientPhoneHangupMessage, 1320 struct ClientPhoneHangupMessage,
1390 NULL), 1321 NULL),
1391 GNUNET_MQ_hd_fixed_size (client_call_message, 1322 GNUNET_MQ_hd_fixed_size (client_call_message,
1392 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL, 1323 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_CALL,
1393 struct ClientCallMessage, 1324 struct ClientCallMessage,
1394 NULL), 1325 NULL),
1395 GNUNET_MQ_hd_var_size (client_audio_message, 1326 GNUNET_MQ_hd_var_size (client_audio_message,
1396 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, 1327 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO,
1397 struct ClientAudioMessage, 1328 struct ClientAudioMessage,
1398 NULL), 1329 NULL),
1399 GNUNET_MQ_handler_end ()); 1330 GNUNET_MQ_handler_end ());
1400 1331
1401 1332
1402/* end of gnunet-service-conversation.c */ 1333/* end of gnunet-service-conversation.c */