diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-08-02 00:38:01 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-08-02 00:38:01 +0000 |
commit | 3f6149fffcc47f1ce9f6cb6a13dc520be6789c7d (patch) | |
tree | a23fd2f417f6e324af0b2c65f44b97038a5f78a8 /src | |
parent | 8f6eee6bb300d2f19f31ec04f04d1685eb6ac598 (diff) | |
download | gnunet-3f6149fffcc47f1ce9f6cb6a13dc520be6789c7d.tar.gz gnunet-3f6149fffcc47f1ce9f6cb6a13dc520be6789c7d.zip |
- tunnel, connection destroy
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh-enc.c | 75 |
1 files changed, 59 insertions, 16 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c index 3094ddfa0..7f81dee26 100644 --- a/src/mesh/gnunet-service-mesh-enc.c +++ b/src/mesh/gnunet-service-mesh-enc.c | |||
@@ -532,6 +532,16 @@ struct MeshConnection | |||
532 | * time tunnel out on all the other peers. | 532 | * time tunnel out on all the other peers. |
533 | */ | 533 | */ |
534 | GNUNET_SCHEDULER_TaskIdentifier bck_maintenance_task; | 534 | GNUNET_SCHEDULER_TaskIdentifier bck_maintenance_task; |
535 | |||
536 | /** | ||
537 | * Pending message count. | ||
538 | */ | ||
539 | int pending_messages; | ||
540 | |||
541 | /** | ||
542 | * Destroy flag: if true, destroy on last message. | ||
543 | */ | ||
544 | int destroy; | ||
535 | }; | 545 | }; |
536 | 546 | ||
537 | 547 | ||
@@ -606,6 +616,16 @@ struct MeshTunnel2 | |||
606 | * Channel ID for the next incoming tunnel. | 616 | * Channel ID for the next incoming tunnel. |
607 | */ | 617 | */ |
608 | MESH_ChannelNumber next_local_chid; | 618 | MESH_ChannelNumber next_local_chid; |
619 | |||
620 | /** | ||
621 | * Pending message count. | ||
622 | */ | ||
623 | int pending_messages; | ||
624 | |||
625 | /** | ||
626 | * Destroy flag: if true, destroy on last message. | ||
627 | */ | ||
628 | int destroy; | ||
609 | }; | 629 | }; |
610 | 630 | ||
611 | 631 | ||
@@ -3482,33 +3502,44 @@ tunnel_destroy (struct MeshTunnel2 *t) | |||
3482 | 3502 | ||
3483 | /** | 3503 | /** |
3484 | * Tunnel is empty: destroy it. | 3504 | * Tunnel is empty: destroy it. |
3485 | * | 3505 | * |
3486 | * Notifies all participants (peers, cleints) about the destruction. | 3506 | * Notifies all connections about the destruction. |
3487 | * | 3507 | * |
3488 | * @param t Tunnel to destroy. | 3508 | * @param t Tunnel to destroy. |
3489 | */ | 3509 | */ |
3490 | static void | 3510 | static void |
3491 | tunnel_destroy_empty (struct MeshTunnel *t) | 3511 | tunnel_destroy_empty (struct MeshTunnel2 *t) |
3492 | { | 3512 | { |
3493 | #if MESH_DEBUG | 3513 | struct MeshConnection *c; |
3494 | { | ||
3495 | struct GNUNET_PeerIdentity id; | ||
3496 | 3514 | ||
3497 | GNUNET_PEER_resolve (t->id.oid, &id); | 3515 | for (c = t->connection_head; NULL != c; c = c->next) |
3498 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3516 | { |
3499 | "executing destruction of empty tunnel %s [%X]\n", | 3517 | if (GNUNET_NO == c->destroy) |
3500 | GNUNET_i2s (&id), t->id.tid); | 3518 | connection_send_destroy (c); |
3501 | } | 3519 | } |
3502 | #endif | ||
3503 | 3520 | ||
3504 | if (GNUNET_NO == t->destroy) | ||
3505 | tunnel_send_destroy (t); | ||
3506 | if (0 == t->pending_messages) | 3521 | if (0 == t->pending_messages) |
3507 | tunnel_destroy (t); | 3522 | tunnel_destroy (t); |
3508 | else | 3523 | else |
3509 | t->destroy = GNUNET_YES; | 3524 | t->destroy = GNUNET_YES; |
3510 | } | 3525 | } |
3511 | 3526 | ||
3527 | |||
3528 | /** | ||
3529 | * Destroy tunnel if empty (no more channels). | ||
3530 | * | ||
3531 | * @param t Tunnel to destroy if empty. | ||
3532 | */ | ||
3533 | static void | ||
3534 | tunnel_destroy_if_empty (struct MeshTunnel2 *t) | ||
3535 | { | ||
3536 | if (NULL != t->channel_head) | ||
3537 | return; | ||
3538 | |||
3539 | tunnel_destroy_empty (t); | ||
3540 | } | ||
3541 | |||
3542 | |||
3512 | /** | 3543 | /** |
3513 | * Initialize a Flow Control structure to the initial state. | 3544 | * Initialize a Flow Control structure to the initial state. |
3514 | * | 3545 | * |
@@ -3598,7 +3629,7 @@ channel_new (struct MeshClient *owner, | |||
3598 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 3629 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
3599 | { | 3630 | { |
3600 | GNUNET_break (0); | 3631 | GNUNET_break (0); |
3601 | channel_destroy (t); | 3632 | channel_destroy (ch); |
3602 | if (NULL != client) | 3633 | if (NULL != client) |
3603 | { | 3634 | { |
3604 | GNUNET_break (0); | 3635 | GNUNET_break (0); |
@@ -3950,6 +3981,7 @@ queue_send (void *cls, size_t size, void *buf) | |||
3950 | struct MeshTunnel2 *t; | 3981 | struct MeshTunnel2 *t; |
3951 | struct GNUNET_PeerIdentity *dst_id; | 3982 | struct GNUNET_PeerIdentity *dst_id; |
3952 | struct MeshFlowControl *fc; | 3983 | struct MeshFlowControl *fc; |
3984 | struct MeshConnection *c; | ||
3953 | size_t data_size; | 3985 | size_t data_size; |
3954 | uint32_t pid; | 3986 | uint32_t pid; |
3955 | uint16_t type; | 3987 | uint16_t type; |
@@ -4004,7 +4036,8 @@ queue_send (void *cls, size_t size, void *buf) | |||
4004 | } | 4036 | } |
4005 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* size ok\n"); | 4037 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* size ok\n"); |
4006 | 4038 | ||
4007 | t = queue->peer->tunnel; | 4039 | c = queue->c; |
4040 | t = c->t; | ||
4008 | type = 0; | 4041 | type = 0; |
4009 | 4042 | ||
4010 | /* Fill buf */ | 4043 | /* Fill buf */ |
@@ -4135,6 +4168,14 @@ queue_send (void *cls, size_t size, void *buf) | |||
4135 | fc->poll_task = GNUNET_SCHEDULER_NO_TASK; | 4168 | fc->poll_task = GNUNET_SCHEDULER_NO_TASK; |
4136 | } | 4169 | } |
4137 | } | 4170 | } |
4171 | c->pending_messages--; | ||
4172 | if (GNUNET_YES == c->destroy && 0 == c->pending_messages) | ||
4173 | { | ||
4174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* destroying connection!\n"); | ||
4175 | connection_destroy (c); | ||
4176 | } | ||
4177 | |||
4178 | t->pending_messages--; | ||
4138 | if (GNUNET_YES == t->destroy && 0 == t->pending_messages) | 4179 | if (GNUNET_YES == t->destroy && 0 == t->pending_messages) |
4139 | { | 4180 | { |
4140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* destroying tunnel!\n"); | 4181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* destroying tunnel!\n"); |
@@ -4235,6 +4276,8 @@ queue_add (void *cls, uint16_t type, size_t size, | |||
4235 | &queue_send, | 4276 | &queue_send, |
4236 | dst); | 4277 | dst); |
4237 | } | 4278 | } |
4279 | c->pending_messages++; | ||
4280 | c->t->pending_messages++; | ||
4238 | } | 4281 | } |
4239 | 4282 | ||
4240 | 4283 | ||