diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-08-02 01:01:25 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-08-02 01:01:25 +0000 |
commit | c102d47688b6292519ad762b0ca83606ec79e98b (patch) | |
tree | 265b5c76d9eda453573d75b700418ccc12f5bb93 /src | |
parent | abb29a80b038b2f73bbc74621285865db4a6e7d5 (diff) | |
download | gnunet-c102d47688b6292519ad762b0ca83606ec79e98b.tar.gz gnunet-c102d47688b6292519ad762b0ca83606ec79e98b.zip |
- connection timeout management
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh-enc.c | 94 |
1 files changed, 55 insertions, 39 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c index 3ae0c1f9c..e1bcc686d 100644 --- a/src/mesh/gnunet-service-mesh-enc.c +++ b/src/mesh/gnunet-service-mesh-enc.c | |||
@@ -421,6 +421,12 @@ struct MeshChannel | |||
421 | struct MeshTunnel2 *t; | 421 | struct MeshTunnel2 *t; |
422 | 422 | ||
423 | /** | 423 | /** |
424 | * Double linked list. | ||
425 | */ | ||
426 | struct MeshChannel *next; | ||
427 | struct MeshChannel *prev; | ||
428 | |||
429 | /** | ||
424 | * Destination port of the channel. | 430 | * Destination port of the channel. |
425 | */ | 431 | */ |
426 | uint32_t port; | 432 | uint32_t port; |
@@ -3700,11 +3706,11 @@ channel_destroy_iterator (void *cls, | |||
3700 | 3706 | ||
3701 | 3707 | ||
3702 | /** | 3708 | /** |
3703 | * remove client's ports from the global hashmap on diconnect. | 3709 | * Remove client's ports from the global hashmap on disconnect. |
3704 | * | 3710 | * |
3705 | * @param cls Closure (unused). | 3711 | * @param cls Closure (unused). |
3706 | * @param key Port. | 3712 | * @param key Port. |
3707 | * @param value ThClient structure. | 3713 | * @param value Client structure. |
3708 | * | 3714 | * |
3709 | * @return GNUNET_OK, keep iterating. | 3715 | * @return GNUNET_OK, keep iterating. |
3710 | */ | 3716 | */ |
@@ -3726,91 +3732,101 @@ client_release_ports (void *cls, | |||
3726 | return GNUNET_OK; | 3732 | return GNUNET_OK; |
3727 | } | 3733 | } |
3728 | 3734 | ||
3735 | |||
3729 | /** | 3736 | /** |
3730 | * Timeout function due to lack of keepalive/traffic from the owner. | 3737 | * Timeout function due to lack of keepalive/traffic from the owner. |
3731 | * Destroys tunnel if called. | 3738 | * Destroys connection if called. |
3732 | * | 3739 | * |
3733 | * @param cls Closure (tunnel to destroy). | 3740 | * @param cls Closure (connection to destroy). |
3734 | * @param tc TaskContext | 3741 | * @param tc TaskContext. |
3735 | */ | 3742 | */ |
3736 | static void | 3743 | static void |
3737 | tunnel_fwd_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3744 | connection_fwd_timeout (void *cls, |
3745 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
3738 | { | 3746 | { |
3739 | struct MeshTunnel *t = cls; | 3747 | struct MeshConnection *c = cls; |
3740 | 3748 | ||
3741 | t->fwd_maintenance_task = GNUNET_SCHEDULER_NO_TASK; | 3749 | c->fwd_maintenance_task = GNUNET_SCHEDULER_NO_TASK; |
3742 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 3750 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
3743 | return; | 3751 | return; |
3744 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3752 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3745 | "Tunnel %s [%X] FWD timed out. Destroying.\n", | 3753 | "Connection %s[%X] FWD timed out. Destroying.\n", |
3746 | GNUNET_i2s(GNUNET_PEER_resolve2 (t->id.oid)), t->id.tid); | 3754 | GNUNET_i2s(GNUNET_PEER_resolve2 (c->t->peer->id)), |
3747 | if (NULL != t->client) | 3755 | c->id); |
3748 | send_local_tunnel_destroy (t, GNUNET_YES); | 3756 | |
3749 | tunnel_destroy (t); /* Do not notify other */ | 3757 | if (NULL != c->t->channel_head) /* If local, leave TODO review */ |
3758 | return; | ||
3759 | |||
3760 | connection_destroy (c); | ||
3750 | } | 3761 | } |
3751 | 3762 | ||
3752 | 3763 | ||
3753 | /** | 3764 | /** |
3754 | * Timeout function due to lack of keepalive/traffic from the destination. | 3765 | * Timeout function due to lack of keepalive/traffic from the destination. |
3755 | * Destroys tunnel if called. | 3766 | * Destroys connection if called. |
3756 | * | 3767 | * |
3757 | * @param cls Closure (tunnel to destroy). | 3768 | * @param cls Closure (connection to destroy). |
3758 | * @param tc TaskContext | 3769 | * @param tc TaskContext |
3759 | */ | 3770 | */ |
3760 | static void | 3771 | static void |
3761 | tunnel_bck_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 3772 | connection_bck_timeout (void *cls, |
3773 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
3762 | { | 3774 | { |
3763 | struct MeshTunnel *t = cls; | 3775 | struct MeshConnection *c = cls; |
3764 | 3776 | ||
3765 | t->bck_maintenance_task = GNUNET_SCHEDULER_NO_TASK; | 3777 | c->bck_maintenance_task = GNUNET_SCHEDULER_NO_TASK; |
3766 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 3778 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
3767 | return; | 3779 | return; |
3780 | |||
3768 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3781 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3769 | "Tunnel %s [%X] BCK timed out. Destroying.\n", | 3782 | "Connection %s[%X] FWD timed out. Destroying.\n", |
3770 | GNUNET_i2s(GNUNET_PEER_resolve2 (t->id.oid)), t->id.tid); | 3783 | GNUNET_i2s(GNUNET_PEER_resolve2 (c->t->peer->id)), |
3771 | if (NULL != t->owner) | 3784 | c->id); |
3772 | send_local_tunnel_destroy (t, GNUNET_NO); | 3785 | |
3773 | tunnel_destroy (t); /* Do not notify other */ | 3786 | if (NULL != c->t->channel_head) /* If local, leave TODO review */ |
3787 | return; | ||
3788 | |||
3789 | connection_destroy (c); | ||
3774 | } | 3790 | } |
3775 | 3791 | ||
3776 | 3792 | ||
3777 | /** | 3793 | /** |
3778 | * Resets the tunnel timeout task, some other message has done the task's job. | 3794 | * Resets the connection timeout task, some other message has done the |
3795 | * task's job. | ||
3779 | * - For the first peer on the direction this means to send | 3796 | * - For the first peer on the direction this means to send |
3780 | * a keepalive or a path confirmation message (either create or ACK). | 3797 | * a keepalive or a path confirmation message (either create or ACK). |
3781 | * - For all other peers, this means to destroy the tunnel, | 3798 | * - For all other peers, this means to destroy the connection, |
3782 | * due to lack of activity. | 3799 | * due to lack of activity. |
3783 | * Starts the tiemout if no timeout was running (tunnel just created). | 3800 | * Starts the tiemout if no timeout was running (connection just created). |
3784 | * | 3801 | * |
3785 | * @param t Tunnel whose timeout to reset. | 3802 | * @param c Connection whose timeout to reset. |
3786 | * @param fwd Is this forward? | 3803 | * @param fwd Is this forward? |
3787 | * | 3804 | * |
3788 | * TODO use heap to improve efficiency of scheduler. | 3805 | * TODO use heap to improve efficiency of scheduler. |
3789 | */ | 3806 | */ |
3790 | static void | 3807 | static void |
3791 | tunnel_reset_timeout (struct MeshTunnel *t, int fwd) | 3808 | connection_reset_timeout (struct MeshConnection *c, int fwd) |
3792 | { | 3809 | { |
3793 | GNUNET_SCHEDULER_TaskIdentifier *ti; | 3810 | GNUNET_SCHEDULER_TaskIdentifier *ti; |
3794 | GNUNET_SCHEDULER_Task f; | 3811 | GNUNET_SCHEDULER_Task f; |
3795 | struct MeshClient *c; | ||
3796 | 3812 | ||
3797 | ti = fwd ? &t->fwd_maintenance_task : &t->bck_maintenance_task; | 3813 | ti = fwd ? &c->fwd_maintenance_task : &c->bck_maintenance_task; |
3798 | c = fwd ? t->owner : t->client; | ||
3799 | 3814 | ||
3800 | if (GNUNET_SCHEDULER_NO_TASK != *ti) | 3815 | if (GNUNET_SCHEDULER_NO_TASK != *ti) |
3801 | GNUNET_SCHEDULER_cancel (*ti); | 3816 | GNUNET_SCHEDULER_cancel (*ti); |
3802 | 3817 | ||
3803 | if (NULL != c) | 3818 | if (NULL != c->t->channel_head) /* Endpoint */ |
3804 | { | 3819 | { |
3805 | f = fwd ? &tunnel_fwd_keepalive : &tunnel_bck_keepalive; | 3820 | f = fwd ? &connection_fwd_keepalive : &connection_bck_keepalive; |
3806 | *ti = GNUNET_SCHEDULER_add_delayed (refresh_connection_time, f, t); | 3821 | *ti = GNUNET_SCHEDULER_add_delayed (refresh_connection_time, f, c); |
3807 | } | 3822 | } |
3808 | else | 3823 | else /* Relay */ |
3809 | { | 3824 | { |
3810 | f = fwd ? &tunnel_fwd_timeout : &tunnel_bck_timeout; | 3825 | struct GNUNET_TIME_Relative delay; |
3811 | *ti = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 3826 | |
3812 | (refresh_connection_time, 4), | 3827 | delay = GNUNET_TIME_relative_multiply (refresh_connection_time, 4); |
3813 | f, t); | 3828 | f = fwd ? &connection_fwd_timeout : &connection_bck_timeout; |
3829 | *ti = GNUNET_SCHEDULER_add_delayed (delay, f, c); | ||
3814 | } | 3830 | } |
3815 | } | 3831 | } |
3816 | 3832 | ||