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.c110
1 files changed, 70 insertions, 40 deletions
diff --git a/src/conversation/gnunet-service-conversation.c b/src/conversation/gnunet-service-conversation.c
index 7d319e51e..059bb158b 100644
--- a/src/conversation/gnunet-service-conversation.c
+++ b/src/conversation/gnunet-service-conversation.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2013, 2016, 2017 GNUnet e.V. 3 Copyright (C) 2013, 2016, 2017 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software: you can redistribute it and/or modify it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
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 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 General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/ 17*/
20/** 18/**
21 * @file conversation/gnunet-service-conversation.c 19 * @file conversation/gnunet-service-conversation.c
@@ -305,6 +303,47 @@ handle_client_pickup_message (void *cls,
305 303
306 304
307/** 305/**
306 * Channel went down, notify client and free data
307 * structure.
308 *
309 * @param ch channel that went down
310 */
311static void
312clean_up_channel (struct Channel *ch)
313{
314 struct Line *line = ch->line;
315 struct GNUNET_MQ_Envelope *env;
316 struct ClientPhoneHangupMessage *hup;
317
318 switch (ch->status)
319 {
320 case CS_CALLEE_INIT:
321 case CS_CALLEE_SHUTDOWN:
322 case CS_CALLER_SHUTDOWN:
323 break;
324 case CS_CALLEE_RINGING:
325 case CS_CALLEE_CONNECTED:
326 case CS_CALLER_CALLING:
327 case CS_CALLER_CONNECTED:
328 if (NULL != line)
329 {
330 env = GNUNET_MQ_msg (hup,
331 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
332 hup->cid = ch->cid;
333 GNUNET_MQ_send (line->mq,
334 env);
335 }
336 break;
337 }
338 if (NULL != line)
339 GNUNET_CONTAINER_DLL_remove (line->channel_head,
340 line->channel_tail,
341 ch);
342 GNUNET_free (ch);
343}
344
345
346/**
308 * Destroy a channel. 347 * Destroy a channel.
309 * 348 *
310 * @param ch channel to destroy. 349 * @param ch channel to destroy.
@@ -315,7 +354,11 @@ destroy_line_cadet_channels (struct Channel *ch)
315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
316 "Destroying cadet channels\n"); 355 "Destroying cadet channels\n");
317 if (NULL != ch->channel) 356 if (NULL != ch->channel)
357 {
318 GNUNET_CADET_channel_destroy (ch->channel); 358 GNUNET_CADET_channel_destroy (ch->channel);
359 ch->channel = NULL;
360 }
361 clean_up_channel (ch);
319} 362}
320 363
321 364
@@ -605,6 +648,8 @@ static int
605check_client_audio_message (void *cls, 648check_client_audio_message (void *cls,
606 const struct ClientAudioMessage *msg) 649 const struct ClientAudioMessage *msg)
607{ 650{
651 (void) cls;
652 (void) msg;
608 return GNUNET_OK; 653 return GNUNET_OK;
609} 654}
610 655
@@ -771,6 +816,7 @@ handle_cadet_hangup_message (void *cls,
771 enum ChannelStatus status; 816 enum ChannelStatus status;
772 uint32_t cid; 817 uint32_t cid;
773 818
819 (void) message;
774 GNUNET_CADET_receive_done (ch->channel); 820 GNUNET_CADET_receive_done (ch->channel);
775 cid = ch->cid; 821 cid = ch->cid;
776 status = ch->status; 822 status = ch->status;
@@ -816,6 +862,7 @@ handle_cadet_pickup_message (void *cls,
816 struct GNUNET_MQ_Envelope *env; 862 struct GNUNET_MQ_Envelope *env;
817 struct ClientPhonePickedupMessage *pick; 863 struct ClientPhonePickedupMessage *pick;
818 864
865 (void) message;
819 GNUNET_CADET_receive_done (ch->channel); 866 GNUNET_CADET_receive_done (ch->channel);
820 switch (ch->status) 867 switch (ch->status)
821 { 868 {
@@ -865,6 +912,7 @@ handle_cadet_suspend_message (void *cls,
865 struct GNUNET_MQ_Envelope *env; 912 struct GNUNET_MQ_Envelope *env;
866 struct ClientPhoneSuspendMessage *suspend; 913 struct ClientPhoneSuspendMessage *suspend;
867 914
915 (void) message;
868 GNUNET_CADET_receive_done (ch->channel); 916 GNUNET_CADET_receive_done (ch->channel);
869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 917 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
870 "Suspending channel CID: %u\n", 918 "Suspending channel CID: %u\n",
@@ -914,6 +962,7 @@ handle_cadet_resume_message (void *cls,
914 struct GNUNET_MQ_Envelope *env; 962 struct GNUNET_MQ_Envelope *env;
915 struct ClientPhoneResumeMessage *resume; 963 struct ClientPhoneResumeMessage *resume;
916 964
965 (void) msg;
917 line = ch->line; 966 line = ch->line;
918 GNUNET_CADET_receive_done (ch->channel); 967 GNUNET_CADET_receive_done (ch->channel);
919 if (GNUNET_YES != ch->suspended_remote) 968 if (GNUNET_YES != ch->suspended_remote)
@@ -964,6 +1013,8 @@ static int
964check_cadet_audio_message (void *cls, 1013check_cadet_audio_message (void *cls,
965 const struct CadetAudioMessage *msg) 1014 const struct CadetAudioMessage *msg)
966{ 1015{
1016 (void) cls;
1017 (void) msg;
967 return GNUNET_OK; /* any payload is fine */ 1018 return GNUNET_OK; /* any payload is fine */
968} 1019}
969 1020
@@ -1021,40 +1072,13 @@ inbound_end (void *cls,
1021 const struct GNUNET_CADET_Channel *channel) 1072 const struct GNUNET_CADET_Channel *channel)
1022{ 1073{
1023 struct Channel *ch = cls; 1074 struct Channel *ch = cls;
1024 struct Line *line = ch->line;
1025 struct GNUNET_MQ_Envelope *env;
1026 struct ClientPhoneHangupMessage *hup;
1027 1075
1028 GNUNET_assert (channel == ch->channel); 1076 GNUNET_assert (channel == ch->channel);
1029 ch->channel = NULL; 1077 ch->channel = NULL;
1030 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1031 "Channel destroyed by CADET in state %d\n", 1079 "Channel destroyed by CADET in state %d\n",
1032 ch->status); 1080 ch->status);
1033 switch (ch->status) 1081 clean_up_channel (ch);
1034 {
1035 case CS_CALLEE_INIT:
1036 case CS_CALLEE_SHUTDOWN:
1037 case CS_CALLER_SHUTDOWN:
1038 break;
1039 case CS_CALLEE_RINGING:
1040 case CS_CALLEE_CONNECTED:
1041 case CS_CALLER_CALLING:
1042 case CS_CALLER_CONNECTED:
1043 if (NULL != line)
1044 {
1045 env = GNUNET_MQ_msg (hup,
1046 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
1047 hup->cid = ch->cid;
1048 GNUNET_MQ_send (line->mq,
1049 env);
1050 }
1051 break;
1052 }
1053 if (NULL != line)
1054 GNUNET_CONTAINER_DLL_remove (line->channel_head,
1055 line->channel_tail,
1056 ch);
1057 GNUNET_free (ch);
1058} 1082}
1059 1083
1060 1084
@@ -1152,6 +1176,7 @@ inbound_channel (void *cls,
1152 struct Line *line = cls; 1176 struct Line *line = cls;
1153 struct Channel *ch; 1177 struct Channel *ch;
1154 1178
1179 (void) initiator;
1155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1156 "Received incoming cadet channel on line %p\n", 1181 "Received incoming cadet channel on line %p\n",
1157 line); 1182 line);
@@ -1183,6 +1208,7 @@ client_connect_cb (void *cls,
1183{ 1208{
1184 struct Line *line; 1209 struct Line *line;
1185 1210
1211 (void) cls;
1186 line = GNUNET_new (struct Line); 1212 line = GNUNET_new (struct Line);
1187 line->client = client; 1213 line->client = client;
1188 line->mq = mq; 1214 line->mq = mq;
@@ -1203,9 +1229,10 @@ client_disconnect_cb (void *cls,
1203 void *app_ctx) 1229 void *app_ctx)
1204{ 1230{
1205 struct Line *line = app_ctx; 1231 struct Line *line = app_ctx;
1206 struct Channel *ch;
1207 struct Channel *chn; 1232 struct Channel *chn;
1208 1233
1234 (void) cls;
1235 (void) client;
1209 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1210 "Client disconnected, closing line\n"); 1237 "Client disconnected, closing line\n");
1211 if (NULL != line->port) 1238 if (NULL != line->port)
@@ -1213,7 +1240,7 @@ client_disconnect_cb (void *cls,
1213 GNUNET_CADET_close_port (line->port); 1240 GNUNET_CADET_close_port (line->port);
1214 line->port = NULL; 1241 line->port = NULL;
1215 } 1242 }
1216 for (ch = line->channel_head; NULL != ch; ch = chn) 1243 for (struct Channel *ch = line->channel_head; NULL != ch; ch = chn)
1217 { 1244 {
1218 chn = ch->next; 1245 chn = ch->next;
1219 ch->line = NULL; 1246 ch->line = NULL;
@@ -1290,6 +1317,7 @@ handle_client_register_message (void *cls,
1290static void 1317static void
1291do_shutdown (void *cls) 1318do_shutdown (void *cls)
1292{ 1319{
1320 (void) cls;
1293 if (NULL != cadet) 1321 if (NULL != cadet)
1294 { 1322 {
1295 GNUNET_CADET_disconnect (cadet); 1323 GNUNET_CADET_disconnect (cadet);
@@ -1310,6 +1338,8 @@ run (void *cls,
1310 const struct GNUNET_CONFIGURATION_Handle *c, 1338 const struct GNUNET_CONFIGURATION_Handle *c,
1311 struct GNUNET_SERVICE_Handle *service) 1339 struct GNUNET_SERVICE_Handle *service)
1312{ 1340{
1341 (void) cls;
1342 (void) service;
1313 cfg = c; 1343 cfg = c;
1314 GNUNET_assert (GNUNET_OK == 1344 GNUNET_assert (GNUNET_OK ==
1315 GNUNET_CRYPTO_get_peer_identity (cfg, 1345 GNUNET_CRYPTO_get_peer_identity (cfg,