aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-08-02 00:26:13 +0000
committerBart Polot <bart@net.in.tum.de>2013-08-02 00:26:13 +0000
commit8f6eee6bb300d2f19f31ec04f04d1685eb6ac598 (patch)
tree1db222fd481569538bf6a2e0c06de6a5fbd0affc /src
parent44fd45bf6dc1780f357a4c938d9a70de41cf08d1 (diff)
downloadgnunet-8f6eee6bb300d2f19f31ec04f04d1685eb6ac598.tar.gz
gnunet-8f6eee6bb300d2f19f31ec04f04d1685eb6ac598.zip
- connection, tunnel destroy
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh-enc.c110
1 files changed, 55 insertions, 55 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c
index c63649601..3094ddfa0 100644
--- a/src/mesh/gnunet-service-mesh-enc.c
+++ b/src/mesh/gnunet-service-mesh-enc.c
@@ -963,15 +963,12 @@ tunnel_destroy_empty (struct MeshTunnel2 *t);
963 * This function does not generate any warning traffic to clients or peers. 963 * This function does not generate any warning traffic to clients or peers.
964 * 964 *
965 * Tasks: 965 * Tasks:
966 * Remove the tunnel from peer_info's and clients' hashmaps.
967 * Cancel messages belonging to this tunnel queued to neighbors. 966 * Cancel messages belonging to this tunnel queued to neighbors.
968 * Free any allocated resources linked to the tunnel. 967 * Free any allocated resources linked to the tunnel.
969 * 968 *
970 * @param t the tunnel to destroy 969 * @param t The tunnel to destroy.
971 *
972 * @return GNUNET_OK on success
973 */ 970 */
974static int 971static void
975tunnel_destroy (struct MeshTunnel2 *t); 972tunnel_destroy (struct MeshTunnel2 *t);
976 973
977/** 974/**
@@ -2078,13 +2075,14 @@ peer_unlock_queue (GNUNET_PEER_Id peer_id)
2078 2075
2079 2076
2080/** 2077/**
2081 * Cancel all transmissions towards a neighbor that belong to a certain tunnel. 2078 * Cancel all transmissions towards a neighbor that belong to
2079 * a certain connection.
2082 * 2080 *
2083 * @param peer Neighbor to whom cancel the transmissions. 2081 * @param peer Neighbor to whom cancel the transmissions.
2084 * @param t Tunnel which to cancel. 2082 * @param c Connection which to cancel.
2085 */ 2083 */
2086static void 2084static void
2087peer_cancel_queues (struct MeshPeer *peer, struct MeshTunnel2 *t) 2085peer_cancel_queues (struct MeshPeer *peer, struct MeshConnection *c)
2088{ 2086{
2089 struct MeshPeerQueue *q; 2087 struct MeshPeerQueue *q;
2090 struct MeshPeerQueue *next; 2088 struct MeshPeerQueue *next;
@@ -2099,7 +2097,7 @@ peer_cancel_queues (struct MeshPeer *peer, struct MeshTunnel2 *t)
2099 for (q = fc->queue_head; NULL != q; q = next) 2097 for (q = fc->queue_head; NULL != q; q = next)
2100 { 2098 {
2101 next = q->next; 2099 next = q->next;
2102 if (q->peer->tunnel == t) 2100 if (q->c == c)
2103 { 2101 {
2104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2105 "peer_cancel_queue %s\n", 2103 "peer_cancel_queue %s\n",
@@ -3419,67 +3417,69 @@ channel_send_destroy (struct MeshChannel *ch)
3419} 3417}
3420 3418
3421 3419
3422static int 3420/**
3421 * Connection is no longer needed: destroy it and remove from tunnel.
3422 *
3423 * @param c Connection to destroy.
3424 */
3425static void
3426connection_destroy (struct MeshConnection *c)
3427{
3428 struct MeshPeer *peer;
3429
3430 if (NULL == c)
3431 return;
3432
3433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "destroying connection %s[%X]\n",
3434 GNUNET_i2s (GNUNET_PEER_resolve2 (c->t->peer->id)),
3435 c->id);
3436
3437 peer = connection_get_next_hop (c);
3438 if (NULL != peer)
3439 peer_cancel_queues (peer, c);
3440 peer = connection_get_prev_hop (c);
3441 if (NULL != peer)
3442 peer_cancel_queues (peer, c);
3443
3444 if (GNUNET_SCHEDULER_NO_TASK != c->fwd_maintenance_task)
3445 GNUNET_SCHEDULER_cancel (c->fwd_maintenance_task);
3446 if (GNUNET_SCHEDULER_NO_TASK != c->bck_maintenance_task)
3447 GNUNET_SCHEDULER_cancel (c->bck_maintenance_task);
3448
3449 GNUNET_CONTAINER_DLL_remove (c->t->connection_head, c->t->connection_tail, c);
3450
3451 GNUNET_STATISTICS_update (stats, "# connections", -1, GNUNET_NO);
3452 GNUNET_free (c);
3453}
3454
3455
3456static void
3423tunnel_destroy (struct MeshTunnel2 *t) 3457tunnel_destroy (struct MeshTunnel2 *t)
3424{ 3458{
3425 struct MeshClient *c; 3459 struct MeshConnection *c;
3426 struct GNUNET_HashCode hash; 3460 struct MeshConnection *next;
3427 int r;
3428 3461
3429 if (NULL == t) 3462 if (NULL == t)
3430 return GNUNET_OK; 3463 return;
3431
3432 r = GNUNET_OK;
3433 c = t->owner;
3434 3464
3435 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "destroying tunnel %s [%x]\n", 3465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "destroying tunnel %s\n",
3436 GNUNET_i2s (GNUNET_PEER_resolve2 (t->id.oid)), t->id.tid); 3466 GNUNET_i2s (GNUNET_PEER_resolve2 (c->t->peer->id)));
3437 if (NULL != c)
3438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
3439 3467
3440 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); 3468 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (tunnels, &t->id, t))
3441 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (tunnels, &hash, t))
3442 {
3443 GNUNET_break (0); 3469 GNUNET_break (0);
3444 r = GNUNET_SYSERR;
3445 }
3446 3470
3447 if (0 != t->prev_hop) 3471 for (c = t->connection_head; NULL != c; c = next)
3448 {
3449 peer_cancel_queues (t->prev_hop, t);
3450 GNUNET_PEER_change_rc (t->prev_hop, -1);
3451 }
3452 if (0 != t->next_hop)
3453 { 3472 {
3454 peer_cancel_queues (t->next_hop, t); 3473 next = c->next;
3455 GNUNET_PEER_change_rc (t->next_hop, -1); 3474 connection_destroy (c);
3456 }
3457 if (GNUNET_SCHEDULER_NO_TASK != t->next_fc.poll_task)
3458 {
3459 GNUNET_SCHEDULER_cancel (t->next_fc.poll_task);
3460 t->next_fc.poll_task = GNUNET_SCHEDULER_NO_TASK;
3461 }
3462 if (GNUNET_SCHEDULER_NO_TASK != t->prev_fc.poll_task)
3463 {
3464 GNUNET_SCHEDULER_cancel (t->prev_fc.poll_task);
3465 t->prev_fc.poll_task = GNUNET_SCHEDULER_NO_TASK;
3466 }
3467 if (0 != t->dest) {
3468 peer_remove_tunnel (peer_get_short (t->dest), t);
3469 } 3475 }
3470 3476
3471 if (GNUNET_SCHEDULER_NO_TASK != t->fwd_maintenance_task)
3472 GNUNET_SCHEDULER_cancel (t->fwd_maintenance_task);
3473 if (GNUNET_SCHEDULER_NO_TASK != t->bck_maintenance_task)
3474 GNUNET_SCHEDULER_cancel (t->bck_maintenance_task);
3475
3476 n_tunnels--;
3477 GNUNET_STATISTICS_update (stats, "# tunnels", -1, GNUNET_NO); 3477 GNUNET_STATISTICS_update (stats, "# tunnels", -1, GNUNET_NO);
3478 path_destroy (t->path); 3478
3479 GNUNET_free (t); 3479 GNUNET_free (t);
3480 return r;
3481} 3480}
3482 3481
3482
3483/** 3483/**
3484 * Tunnel is empty: destroy it. 3484 * Tunnel is empty: destroy it.
3485 * 3485 *