aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2016-03-30 09:17:51 +0000
committerBart Polot <bart@net.in.tum.de>2016-03-30 09:17:51 +0000
commit6ae8817101148cb1780d964415d38d9f71c03b90 (patch)
tree747058bf0ccbef5ab19da2f3bfbdfc19d68b56b1
parent602bde3c0f4c48358dcc9a6788ae4ba1a1115103 (diff)
downloadgnunet-6ae8817101148cb1780d964415d38d9f71c03b90.tar.gz
gnunet-6ae8817101148cb1780d964415d38d9f71c03b90.zip
- refactor connection destroy handling, fix #4020
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index 9ec8202b3..e88185b55 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -464,6 +464,20 @@ connection_get (const struct GNUNET_CADET_Hash *cid)
464 464
465 465
466/** 466/**
467 * Mark a connection as "destroyed", to send all pending traffic and freeing
468 * all associated resources, without accepting new status changes on it.
469 *
470 * @param c Connection to mark as destroyed.
471 */
472static void
473mark_destroyed (struct CadetConnection *c)
474{
475 c->destroy = GNUNET_YES;
476 connection_change_state (c, CADET_CONNECTION_DESTROYED);
477}
478
479
480/**
467 * Change the connection state. Cannot change a connection marked as destroyed. 481 * Change the connection state. Cannot change a connection marked as destroyed.
468 * 482 *
469 * @param c Connection to change. 483 * @param c Connection to change.
@@ -1487,8 +1501,7 @@ resend_messages_and_destroy (struct CadetConnection *c, int fwd)
1487 int destroyed; 1501 int destroyed;
1488 1502
1489 GCC_check_connections (); 1503 GCC_check_connections ();
1490 c->state = CADET_CONNECTION_DESTROYED; 1504 mark_destroyed (c);
1491 c->destroy = GNUNET_YES;
1492 1505
1493 destroyed = GNUNET_NO; 1506 destroyed = GNUNET_NO;
1494 neighbor = get_hop (c, fwd); 1507 neighbor = get_hop (c, fwd);
@@ -1675,8 +1688,8 @@ check_path (void *cls, struct CadetConnection *c)
1675 && CADET_CONNECTION_DESTROYED != c->state 1688 && CADET_CONNECTION_DESTROYED != c->state
1676 && path_equivalent (path, c->path)) 1689 && path_equivalent (path, c->path))
1677 { 1690 {
1678 new_conn->destroy = GNUNET_YES; 1691 new_conn->destroy = GNUNET_YES; /* Do not mark_destroyed, */
1679 new_conn->path->c = c; 1692 new_conn->path->c = c; /* this is only a flag for the Iterator. */
1680 LOG (GNUNET_ERROR_TYPE_DEBUG, " MATCH!\n"); 1693 LOG (GNUNET_ERROR_TYPE_DEBUG, " MATCH!\n");
1681 } 1694 }
1682} 1695}
@@ -2291,7 +2304,7 @@ GCC_handle_broken (void* cls,
2291 t = c->t; 2304 t = c->t;
2292 2305
2293 fwd = is_fwd (c, id); 2306 fwd = is_fwd (c, id);
2294 c->destroy = GNUNET_YES; 2307 mark_destroyed (c);
2295 if (GCC_is_terminal (c, fwd)) 2308 if (GCC_is_terminal (c, fwd))
2296 { 2309 {
2297 struct CadetPeer *endpoint; 2310 struct CadetPeer *endpoint;
@@ -2384,8 +2397,7 @@ GCC_handle_destroy (void *cls,
2384 GCC_check_connections (); 2397 GCC_check_connections ();
2385 return GNUNET_OK; 2398 return GNUNET_OK;
2386 } 2399 }
2387 c->destroy = GNUNET_YES; 2400 mark_destroyed (c);
2388 c->state = CADET_CONNECTION_DESTROYED;
2389 if (NULL != c->t) 2401 if (NULL != c->t)
2390 { 2402 {
2391 GCT_remove_connection (c->t, c); 2403 GCT_remove_connection (c->t, c);
@@ -3366,8 +3378,7 @@ GCC_neighbor_disconnected (struct CadetConnection *c, struct CadetPeer *peer)
3366 /* Connection will have at least one pending message 3378 /* Connection will have at least one pending message
3367 * (the one we just scheduled), so delay destruction 3379 * (the one we just scheduled), so delay destruction
3368 * and remove from map so we don't use accidentally. */ 3380 * and remove from map so we don't use accidentally. */
3369 c->destroy = GNUNET_YES; 3381 mark_destroyed (c);
3370 c->state = CADET_CONNECTION_DESTROYED;
3371 GNUNET_assert (GNUNET_NO == c->was_removed); 3382 GNUNET_assert (GNUNET_NO == c->was_removed);
3372 c->was_removed = GNUNET_YES; 3383 c->was_removed = GNUNET_YES;
3373 GNUNET_break (GNUNET_YES == 3384 GNUNET_break (GNUNET_YES ==
@@ -3724,8 +3735,7 @@ GCC_send_destroy (struct CadetConnection *c)
3724 GNUNET_assert (NULL == GCC_send_prebuilt_message (&msg.header, UINT16_MAX, 3735 GNUNET_assert (NULL == GCC_send_prebuilt_message (&msg.header, UINT16_MAX,
3725 0, c, GNUNET_NO, 3736 0, c, GNUNET_NO,
3726 GNUNET_YES, NULL, NULL)); 3737 GNUNET_YES, NULL, NULL));
3727 c->destroy = GNUNET_YES; 3738 mark_destroyed (c);
3728 c->state = CADET_CONNECTION_DESTROYED;
3729 GCC_check_connections (); 3739 GCC_check_connections ();
3730} 3740}
3731 3741