aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cadet/cadet_api.c3
-rw-r--r--src/conversation/gnunet-service-conversation.c74
-rw-r--r--src/include/gnunet_cadet_service.h4
-rw-r--r--src/set/gnunet-service-set.c31
-rw-r--r--src/set/gnunet-service-set.h9
-rw-r--r--src/set/gnunet-service-set_union.c7
6 files changed, 87 insertions, 41 deletions
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index 92dd39b97..e2ca461a5 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -1277,7 +1277,7 @@ GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p)
1277/** 1277/**
1278 * Destroy an existing channel. 1278 * Destroy an existing channel.
1279 * 1279 *
1280 * The existing end callback for the channel will be called immediately. 1280 * The existing end callback for the channel will NOT be called.
1281 * Any pending outgoing messages will be sent but no incoming messages will be 1281 * Any pending outgoing messages will be sent but no incoming messages will be
1282 * accepted and no data callbacks will be called. 1282 * accepted and no data callbacks will be called.
1283 * 1283 *
@@ -1300,6 +1300,7 @@ GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel)
1300 } 1300 }
1301 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1301 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1302 "Destroying channel due to GNUNET_CADET_channel_destroy()\n"); 1302 "Destroying channel due to GNUNET_CADET_channel_destroy()\n");
1303 channel->disconnects = NULL;
1303 destroy_channel (channel); 1304 destroy_channel (channel);
1304} 1305}
1305 1306
diff --git a/src/conversation/gnunet-service-conversation.c b/src/conversation/gnunet-service-conversation.c
index fb9eec26e..059bb158b 100644
--- a/src/conversation/gnunet-service-conversation.c
+++ b/src/conversation/gnunet-service-conversation.c
@@ -303,6 +303,47 @@ handle_client_pickup_message (void *cls,
303 303
304 304
305/** 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/**
306 * Destroy a channel. 347 * Destroy a channel.
307 * 348 *
308 * @param ch channel to destroy. 349 * @param ch channel to destroy.
@@ -313,7 +354,11 @@ destroy_line_cadet_channels (struct Channel *ch)
313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
314 "Destroying cadet channels\n"); 355 "Destroying cadet channels\n");
315 if (NULL != ch->channel) 356 if (NULL != ch->channel)
357 {
316 GNUNET_CADET_channel_destroy (ch->channel); 358 GNUNET_CADET_channel_destroy (ch->channel);
359 ch->channel = NULL;
360 }
361 clean_up_channel (ch);
317} 362}
318 363
319 364
@@ -1027,40 +1072,13 @@ inbound_end (void *cls,
1027 const struct GNUNET_CADET_Channel *channel) 1072 const struct GNUNET_CADET_Channel *channel)
1028{ 1073{
1029 struct Channel *ch = cls; 1074 struct Channel *ch = cls;
1030 struct Line *line = ch->line;
1031 struct GNUNET_MQ_Envelope *env;
1032 struct ClientPhoneHangupMessage *hup;
1033 1075
1034 GNUNET_assert (channel == ch->channel); 1076 GNUNET_assert (channel == ch->channel);
1035 ch->channel = NULL; 1077 ch->channel = NULL;
1036 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1037 "Channel destroyed by CADET in state %d\n", 1079 "Channel destroyed by CADET in state %d\n",
1038 ch->status); 1080 ch->status);
1039 switch (ch->status) 1081 clean_up_channel (ch);
1040 {
1041 case CS_CALLEE_INIT:
1042 case CS_CALLEE_SHUTDOWN:
1043 case CS_CALLER_SHUTDOWN:
1044 break;
1045 case CS_CALLEE_RINGING:
1046 case CS_CALLEE_CONNECTED:
1047 case CS_CALLER_CALLING:
1048 case CS_CALLER_CONNECTED:
1049 if (NULL != line)
1050 {
1051 env = GNUNET_MQ_msg (hup,
1052 GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP);
1053 hup->cid = ch->cid;
1054 GNUNET_MQ_send (line->mq,
1055 env);
1056 }
1057 break;
1058 }
1059 if (NULL != line)
1060 GNUNET_CONTAINER_DLL_remove (line->channel_head,
1061 line->channel_tail,
1062 ch);
1063 GNUNET_free (ch);
1064} 1082}
1065 1083
1066 1084
diff --git a/src/include/gnunet_cadet_service.h b/src/include/gnunet_cadet_service.h
index 552763055..276fe4dbc 100644
--- a/src/include/gnunet_cadet_service.h
+++ b/src/include/gnunet_cadet_service.h
@@ -151,7 +151,7 @@ typedef void *
151 151
152 152
153/** 153/**
154 * Function called whenever an MQ-channel is destroyed, even if the destruction 154 * Function called whenever an MQ-channel is destroyed, unless the destruction
155 * was requested by #GNUNET_CADET_channel_destroy. 155 * was requested by #GNUNET_CADET_channel_destroy.
156 * It must NOT call #GNUNET_CADET_channel_destroy on the channel. 156 * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
157 * 157 *
@@ -277,7 +277,7 @@ GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h,
277/** 277/**
278 * Destroy an existing channel. 278 * Destroy an existing channel.
279 * 279 *
280 * The existing end callback for the channel will be called immediately. 280 * The existing end callback for the channel will NOT be called.
281 * Any pending outgoing messages will be sent but no incoming messages will be 281 * Any pending outgoing messages will be sent but no incoming messages will be
282 * accepted and no data callbacks will be called. 282 * accepted and no data callbacks will be called.
283 * 283 *
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c
index 217b89d6d..75122395d 100644
--- a/src/set/gnunet-service-set.c
+++ b/src/set/gnunet-service-set.c
@@ -221,11 +221,7 @@ incoming_destroy (struct Operation *op)
221 GNUNET_SCHEDULER_cancel (op->timeout_task); 221 GNUNET_SCHEDULER_cancel (op->timeout_task);
222 op->timeout_task = NULL; 222 op->timeout_task = NULL;
223 } 223 }
224 if (NULL != (channel = op->channel)) 224 _GSS_operation_destroy2 (op);
225 {
226 op->channel = NULL;
227 GNUNET_CADET_channel_destroy (channel);
228 }
229} 225}
230 226
231 227
@@ -1199,9 +1195,30 @@ channel_end_cb (void *channel_ctx,
1199{ 1195{
1200 struct Operation *op = channel_ctx; 1196 struct Operation *op = channel_ctx;
1201 1197
1198 op->channel = NULL;
1199 _GSS_operation_destroy2 (op);
1200}
1201
1202
1203/**
1204 * This function probably should not exist
1205 * and be replaced by inlining more specific
1206 * logic in the various places where it is called.
1207 */
1208void
1209_GSS_operation_destroy2 (struct Operation *op)
1210{
1211 struct GNUNET_CADET_Channel *channel;
1212
1202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1203 "channel_end_cb called\n"); 1214 "channel_end_cb called\n");
1204 op->channel = NULL; 1215 if (NULL != (channel = op->channel))
1216 {
1217 /* This will free op; called conditionally as this helper function
1218 is also called from within the channel disconnect handler. */
1219 op->channel = NULL;
1220 GNUNET_CADET_channel_destroy (channel);
1221 }
1205 if (NULL != op->listener) 1222 if (NULL != op->listener)
1206 incoming_destroy (op); 1223 incoming_destroy (op);
1207 else if (NULL != op->set) 1224 else if (NULL != op->set)
@@ -1376,7 +1393,7 @@ handle_client_reject (void *cls,
1376 "Peer request (op %u, app %s) rejected by client\n", 1393 "Peer request (op %u, app %s) rejected by client\n",
1377 op->listener->operation, 1394 op->listener->operation,
1378 GNUNET_h2s (&cs->listener->app_id)); 1395 GNUNET_h2s (&cs->listener->app_id));
1379 GNUNET_CADET_channel_destroy (op->channel); 1396 _GSS_operation_destroy2 (op);
1380 GNUNET_SERVICE_client_continue (cs->client); 1397 GNUNET_SERVICE_client_continue (cs->client);
1381} 1398}
1382 1399
diff --git a/src/set/gnunet-service-set.h b/src/set/gnunet-service-set.h
index f7c262eac..a58b22995 100644
--- a/src/set/gnunet-service-set.h
+++ b/src/set/gnunet-service-set.h
@@ -630,6 +630,15 @@ _GSS_operation_destroy (struct Operation *op,
630 630
631 631
632/** 632/**
633 * This function probably should not exist
634 * and be replaced by inlining more specific
635 * logic in the various places where it is called.
636 */
637void
638_GSS_operation_destroy2 (struct Operation *op);
639
640
641/**
633 * Get the table with implementing functions for set union. 642 * Get the table with implementing functions for set union.
634 * 643 *
635 * @return the operation specific VTable 644 * @return the operation specific VTable
diff --git a/src/set/gnunet-service-set_union.c b/src/set/gnunet-service-set_union.c
index c1268948a..73d3f5c83 100644
--- a/src/set/gnunet-service-set_union.c
+++ b/src/set/gnunet-service-set_union.c
@@ -1399,7 +1399,8 @@ send_client_done (void *cls)
1399 struct GNUNET_MQ_Envelope *ev; 1399 struct GNUNET_MQ_Envelope *ev;
1400 struct GNUNET_SET_ResultMessage *rm; 1400 struct GNUNET_SET_ResultMessage *rm;
1401 1401
1402 if (GNUNET_YES == op->state->client_done_sent) { 1402 if (GNUNET_YES == op->state->client_done_sent)
1403 {
1403 return; 1404 return;
1404 } 1405 }
1405 1406
@@ -1476,7 +1477,7 @@ maybe_finish (struct Operation *op)
1476 { 1477 {
1477 op->state->phase = PHASE_DONE; 1478 op->state->phase = PHASE_DONE;
1478 send_client_done (op); 1479 send_client_done (op);
1479 destroy_channel (op); 1480 _GSS_operation_destroy2 (op);
1480 } 1481 }
1481 } 1482 }
1482} 1483}
@@ -1905,7 +1906,7 @@ handle_union_p2p_full_done (void *cls,
1905 op->state->phase = PHASE_DONE; 1906 op->state->phase = PHASE_DONE;
1906 GNUNET_CADET_receive_done (op->channel); 1907 GNUNET_CADET_receive_done (op->channel);
1907 send_client_done (op); 1908 send_client_done (op);
1908 destroy_channel (op); 1909 _GSS_operation_destroy2 (op);
1909 return; 1910 return;
1910 } 1911 }
1911 break; 1912 break;