aboutsummaryrefslogtreecommitdiff
path: root/src/conversation
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-04 18:42:26 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-04 18:42:26 +0000
commit4a57008695b2840dbb18fb48031719d29d7a910c (patch)
tree73e01b6d978cc6d7eee7d24a8e5acbd473095e34 /src/conversation
parent1c2c08b45a80d047927b8925c52f1cf50e08a055 (diff)
downloadgnunet-4a57008695b2840dbb18fb48031719d29d7a910c.tar.gz
gnunet-4a57008695b2840dbb18fb48031719d29d7a910c.zip
-finish first draft of conversation service
Diffstat (limited to 'src/conversation')
-rw-r--r--src/conversation/gnunet-service-conversation-new.c109
1 files changed, 108 insertions, 1 deletions
diff --git a/src/conversation/gnunet-service-conversation-new.c b/src/conversation/gnunet-service-conversation-new.c
index e669f6f82..d379931f7 100644
--- a/src/conversation/gnunet-service-conversation-new.c
+++ b/src/conversation/gnunet-service-conversation-new.c
@@ -132,6 +132,16 @@ struct Line
132 struct GNUNET_PeerIdentity target; 132 struct GNUNET_PeerIdentity target;
133 133
134 /** 134 /**
135 * Temporary buffer for audio data.
136 */
137 void *audio_data;
138
139 /**
140 * Number of bytes in @e audio_data.
141 */
142 size_t audio_size;
143
144 /**
135 * Our line number. 145 * Our line number.
136 */ 146 */
137 uint32_t local_line; 147 uint32_t local_line;
@@ -306,6 +316,11 @@ destroy_line_mesh_tunnels (struct Line *line)
306 GNUNET_MQ_destroy (line->reliable_mq); 316 GNUNET_MQ_destroy (line->reliable_mq);
307 line->reliable_mq = NULL; 317 line->reliable_mq = NULL;
308 } 318 }
319 if (NULL != line->unreliable_mth)
320 {
321 GNUNET_MESH_notify_transmit_ready_cancel (line->unreliable_mth);
322 line->unreliable_mth = NULL;
323 }
309 if (NULL != line->tunnel_unreliable) 324 if (NULL != line->tunnel_unreliable)
310 { 325 {
311 GNUNET_MESH_tunnel_destroy (line->tunnel_unreliable); 326 GNUNET_MESH_tunnel_destroy (line->tunnel_unreliable);
@@ -356,6 +371,7 @@ mq_done_finish_caller_shutdown (void *cls)
356 GNUNET_CONTAINER_DLL_remove (lines_head, 371 GNUNET_CONTAINER_DLL_remove (lines_head,
357 lines_tail, 372 lines_tail,
358 line); 373 line);
374 GNUNET_free_non_null (line->audio_data);
359 GNUNET_free (line); 375 GNUNET_free (line);
360 break; 376 break;
361 } 377 }
@@ -457,6 +473,7 @@ handle_client_call_message (void *cls,
457 line = GNUNET_SERVER_client_get_user_context (client, struct Line); 473 line = GNUNET_SERVER_client_get_user_context (client, struct Line);
458 if (NULL != line) 474 if (NULL != line)
459 { 475 {
476 GNUNET_break (0);
460 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 477 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
461 return; 478 return;
462 } 479 }
@@ -498,6 +515,39 @@ handle_client_call_message (void *cls,
498 515
499 516
500/** 517/**
518 * Transmit audio data via unreliable mesh channel.
519 *
520 * @param cls the `struct Line` we are transmitting for
521 * @param size number of bytes available in @a buf
522 * @param buf where to copy the data
523 * @return number of bytes copied to @buf
524 */
525static size_t
526transmit_line_audio (void *cls,
527 size_t size,
528 void *buf)
529{
530 struct Line *line = cls;
531 struct MeshAudioMessage *mam = buf;
532
533 line->unreliable_mth = NULL;
534 if ( (NULL == buf) ||
535 (size < sizeof (struct MeshAudioMessage) + line->audio_size) )
536 {
537 /* eh, other error handling? */
538 return 0;
539 }
540 mam->header.size = htons (sizeof (struct MeshAudioMessage) + line->audio_size);
541 mam->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_MESH_AUDIO);
542 mam->remote_line = htonl (line->remote_line);
543 memcpy (&mam[1], line->audio_data, line->audio_size);
544 GNUNET_free (line->audio_data);
545 line->audio_data = NULL;
546 return sizeof (struct MeshAudioMessage) + line->audio_size;
547}
548
549
550/**
501 * Function to handle audio data from the client 551 * Function to handle audio data from the client
502 * 552 *
503 * @param cls closure, NULL 553 * @param cls closure, NULL
@@ -510,9 +560,65 @@ handle_client_audio_message (void *cls,
510 const struct GNUNET_MessageHeader *message) 560 const struct GNUNET_MessageHeader *message)
511{ 561{
512 const struct ClientAudioMessage *msg; 562 const struct ClientAudioMessage *msg;
563 struct Line *line;
564 size_t size;
513 565
566 size = ntohs (message->size) - sizeof (struct ClientAudioMessage);
514 msg = (struct ClientAudioMessage *) message; 567 msg = (struct ClientAudioMessage *) message;
515 GNUNET_break (0); // FIXME 568 line = GNUNET_SERVER_client_get_user_context (client, struct Line);
569 if (NULL == line)
570 {
571 GNUNET_break (0);
572 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
573 return;
574 }
575 switch (line->status)
576 {
577 case LS_CALLEE_LISTEN:
578 case LS_CALLEE_RINGING:
579 case LS_CALLER_CALLING:
580 GNUNET_break (0);
581 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
582 return;
583 case LS_CALLEE_CONNECTED:
584 case LS_CALLER_CONNECTED:
585 /* common case, handled below */
586 break;
587 case LS_CALLEE_SHUTDOWN:
588 case LS_CALLER_SHUTDOWN:
589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
590 "Mesh audio channel in shutdown; audio data dropped\n");
591 GNUNET_SERVER_receive_done (client, GNUNET_OK);
592 return;
593 }
594 if (NULL == line->tunnel_unreliable)
595 {
596 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
597 _("Mesh audio channel not ready; audio data dropped\n"));
598 GNUNET_SERVER_receive_done (client, GNUNET_OK);
599 return;
600 }
601 if (NULL != line->unreliable_mth)
602 {
603 /* NOTE: we may want to not do this and instead combine the data */
604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
605 "Dropping previous audio data segment with %u bytes\n",
606 line->audio_size);
607 GNUNET_MESH_notify_transmit_ready_cancel (line->unreliable_mth);
608 GNUNET_free (line->audio_data);
609 }
610 line->audio_size = size;
611 line->audio_data = GNUNET_malloc (line->audio_size);
612 memcpy (line->audio_data,
613 &msg[1],
614 size);
615 line->unreliable_mth = GNUNET_MESH_notify_transmit_ready (line->tunnel_unreliable,
616 GNUNET_NO,
617 GNUNET_TIME_UNIT_FOREVER_REL,
618 sizeof (struct MeshAudioMessage)
619 + line->audio_size,
620 &transmit_line_audio,
621 line);
516 GNUNET_SERVER_receive_done (client, GNUNET_OK); 622 GNUNET_SERVER_receive_done (client, GNUNET_OK);
517} 623}
518 624
@@ -961,6 +1067,7 @@ inbound_end (void *cls,
961 GNUNET_CONTAINER_DLL_remove (lines_head, 1067 GNUNET_CONTAINER_DLL_remove (lines_head,
962 lines_tail, 1068 lines_tail,
963 line); 1069 line);
1070 GNUNET_free_non_null (line->audio_data);
964 GNUNET_free (line); 1071 GNUNET_free (line);
965 break; 1072 break;
966 case LS_CALLER_SHUTDOWN: 1073 case LS_CALLER_SHUTDOWN: