diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-08-09 16:35:32 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-08-09 16:35:32 +0200 |
commit | 7caba06019ecc5775d3dbb513b70f52f620affb5 (patch) | |
tree | 93696c0ab1a31e3744fc375015fb0b6dbd95003d /src | |
parent | 1ded1c1bb3bcb16d1770f03b299fcaa0a0c2d813 (diff) | |
download | gnunet-7caba06019ecc5775d3dbb513b70f52f620affb5.tar.gz gnunet-7caba06019ecc5775d3dbb513b70f52f620affb5.zip |
change CADET channel destroy API to not call the callback if the client initiated the channel's destruction
Diffstat (limited to 'src')
-rw-r--r-- | src/cadet/cadet_api.c | 3 | ||||
-rw-r--r-- | src/conversation/gnunet-service-conversation.c | 74 | ||||
-rw-r--r-- | src/include/gnunet_cadet_service.h | 4 | ||||
-rw-r--r-- | src/set/gnunet-service-set.c | 31 | ||||
-rw-r--r-- | src/set/gnunet-service-set.h | 9 | ||||
-rw-r--r-- | src/set/gnunet-service-set_union.c | 23 |
6 files changed, 85 insertions, 59 deletions
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c index 85a8be522..980b9abbf 100644 --- a/src/cadet/cadet_api.c +++ b/src/cadet/cadet_api.c | |||
@@ -1273,7 +1273,7 @@ GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p) | |||
1273 | /** | 1273 | /** |
1274 | * Destroy an existing channel. | 1274 | * Destroy an existing channel. |
1275 | * | 1275 | * |
1276 | * The existing end callback for the channel will be called immediately. | 1276 | * The existing end callback for the channel will NOT be called. |
1277 | * Any pending outgoing messages will be sent but no incoming messages will be | 1277 | * Any pending outgoing messages will be sent but no incoming messages will be |
1278 | * accepted and no data callbacks will be called. | 1278 | * accepted and no data callbacks will be called. |
1279 | * | 1279 | * |
@@ -1296,6 +1296,7 @@ GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel) | |||
1296 | } | 1296 | } |
1297 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1297 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1298 | "Destroying channel due to GNUNET_CADET_channel_destroy()\n"); | 1298 | "Destroying channel due to GNUNET_CADET_channel_destroy()\n"); |
1299 | channel->disconnects = NULL; | ||
1299 | destroy_channel (channel); | 1300 | destroy_channel (channel); |
1300 | } | 1301 | } |
1301 | 1302 | ||
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 | */ | ||
311 | static void | ||
312 | clean_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 | */ | ||
1208 | void | ||
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 | */ | ||
637 | void | ||
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 c3c14f1ba..8c0c52d64 100644 --- a/src/set/gnunet-service-set_union.c +++ b/src/set/gnunet-service-set_union.c | |||
@@ -1367,25 +1367,6 @@ send_client_element (struct Operation *op, | |||
1367 | 1367 | ||
1368 | 1368 | ||
1369 | /** | 1369 | /** |
1370 | * Destroy remote channel. | ||
1371 | * | ||
1372 | * @param op operation | ||
1373 | */ | ||
1374 | void destroy_channel (struct Operation *op) | ||
1375 | { | ||
1376 | struct GNUNET_CADET_Channel *channel; | ||
1377 | |||
1378 | if (NULL != (channel = op->channel)) | ||
1379 | { | ||
1380 | /* This will free op; called conditionally as this helper function | ||
1381 | is also called from within the channel disconnect handler. */ | ||
1382 | op->channel = NULL; | ||
1383 | GNUNET_CADET_channel_destroy (channel); | ||
1384 | } | ||
1385 | } | ||
1386 | |||
1387 | |||
1388 | /** | ||
1389 | * Signal to the client that the operation has finished and | 1370 | * Signal to the client that the operation has finished and |
1390 | * destroy the operation. | 1371 | * destroy the operation. |
1391 | * | 1372 | * |
@@ -1467,7 +1448,7 @@ maybe_finish (struct Operation *op) | |||
1467 | { | 1448 | { |
1468 | op->state->phase = PHASE_DONE; | 1449 | op->state->phase = PHASE_DONE; |
1469 | send_client_done (op); | 1450 | send_client_done (op); |
1470 | destroy_channel (op); | 1451 | _GSS_operation_destroy2 (op); |
1471 | } | 1452 | } |
1472 | } | 1453 | } |
1473 | } | 1454 | } |
@@ -1896,7 +1877,7 @@ handle_union_p2p_full_done (void *cls, | |||
1896 | op->state->phase = PHASE_DONE; | 1877 | op->state->phase = PHASE_DONE; |
1897 | GNUNET_CADET_receive_done (op->channel); | 1878 | GNUNET_CADET_receive_done (op->channel); |
1898 | send_client_done (op); | 1879 | send_client_done (op); |
1899 | destroy_channel (op); | 1880 | _GSS_operation_destroy2 (op); |
1900 | return; | 1881 | return; |
1901 | } | 1882 | } |
1902 | break; | 1883 | break; |