aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-01-07 12:55:53 +0000
committerBart Polot <bart@net.in.tum.de>2014-01-07 12:55:53 +0000
commit5aa336fc12d2ffdfe9cb2c6c877b1c72175cea18 (patch)
tree40977423c12304923a087cbe440c0f5db828b52e /src
parent4a353b58aec4670b2ac4477571ce9e28d5e8ea9a (diff)
downloadgnunet-5aa336fc12d2ffdfe9cb2c6c877b1c72175cea18.tar.gz
gnunet-5aa336fc12d2ffdfe9cb2c6c877b1c72175cea18.zip
- do exponential backoff for connection creation
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh_connection.c69
1 files changed, 63 insertions, 6 deletions
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c
index 3b526afeb..a4cf1e4ee 100644
--- a/src/mesh/gnunet-service-mesh_connection.c
+++ b/src/mesh/gnunet-service-mesh_connection.c
@@ -202,6 +202,17 @@ struct MeshConnection
202 GNUNET_SCHEDULER_TaskIdentifier bck_maintenance_task; 202 GNUNET_SCHEDULER_TaskIdentifier bck_maintenance_task;
203 203
204 /** 204 /**
205 * Queue handle for maintainance traffic. One handle for FWD and BCK since
206 * one peer never needs to maintain both directions (no loopback connections).
207 */
208 struct MeshPeerQueue *maintenance_q;
209
210 /**
211 * Counter to do exponential backoff when creating a connection (max 64).
212 */
213 unsigned short create_retry;
214
215 /**
205 * Pending message count. 216 * Pending message count.
206 */ 217 */
207 int pending_messages; 218 int pending_messages;
@@ -396,6 +407,8 @@ connection_change_state (struct MeshConnection* c,
396 "Connection %s state is now %s\n", 407 "Connection %s state is now %s\n",
397 GMC_2s (c), GMC_state2s (state)); 408 GMC_2s (c), GMC_state2s (state));
398 c->state = state; 409 c->state = state;
410 if (MESH_CONNECTION_READY == state)
411 c->create_retry = 1;
399} 412}
400 413
401 414
@@ -903,8 +916,18 @@ connection_maintain (struct MeshConnection *c, int fwd)
903} 916}
904 917
905 918
919/**
920 * Keep the connection alive in the FWD direction.
921 *
922 * Call connection_maintain do to the work and schedule the next execution,
923 * taking in consideration the connection state and number of retries.
924 *
925 * @param cls Closure (connection to keepalive).
926 * @param tc TaskContext.
927 */
906static void 928static void
907connection_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 929connection_fwd_keepalive (void *cls,
930 const struct GNUNET_SCHEDULER_TaskContext *tc)
908{ 931{
909 struct MeshConnection *c = cls; 932 struct MeshConnection *c = cls;
910 struct GNUNET_TIME_Relative delay; 933 struct GNUNET_TIME_Relative delay;
@@ -914,16 +937,39 @@ connection_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *
914 return; 937 return;
915 938
916 connection_maintain (c, GNUNET_YES); 939 connection_maintain (c, GNUNET_YES);
917 delay = c->state == MESH_CONNECTION_READY ? 940 if (MESH_CONNECTION_READY == c->state)
918 refresh_connection_time : create_connection_time; 941 {
942 delay = refresh_connection_time;
943 }
944 else
945 {
946 if (1 > c->create_retry)
947 c->create_retry = 1;
948 delay = GNUNET_TIME_relative_multiply (create_connection_time,
949 c->create_retry);
950 if (c->create_retry < 64)
951 c->create_retry *= 2;
952 }
919 c->fwd_maintenance_task = GNUNET_SCHEDULER_add_delayed (delay, 953 c->fwd_maintenance_task = GNUNET_SCHEDULER_add_delayed (delay,
920 &connection_fwd_keepalive, 954 &connection_fwd_keepalive,
921 c); 955 c);
922} 956}
923 957
924 958
959/**
960 * Keep the connection alive in the BCK direction.
961 *
962 * Call connection_maintain do to the work and schedule the next execution,
963 * taking in consideration the connection state and number of retries.
964 *
965 * TODO refactor and merge with connection_fwd_keepalive.
966 *
967 * @param cls Closure (connection to keepalive).
968 * @param tc TaskContext.
969 */
925static void 970static void
926connection_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 971connection_bck_keepalive (void *cls,
972 const struct GNUNET_SCHEDULER_TaskContext *tc)
927{ 973{
928 struct MeshConnection *c = cls; 974 struct MeshConnection *c = cls;
929 struct GNUNET_TIME_Relative delay; 975 struct GNUNET_TIME_Relative delay;
@@ -933,8 +979,19 @@ connection_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *
933 return; 979 return;
934 980
935 connection_maintain (c, GNUNET_NO); 981 connection_maintain (c, GNUNET_NO);
936 delay = c->state == MESH_CONNECTION_READY ? 982 if (MESH_CONNECTION_READY == c->state)
937 refresh_connection_time : create_connection_time; 983 {
984 delay = refresh_connection_time;
985 }
986 else
987 {
988 if (1 > c->create_retry)
989 c->create_retry = 1;
990 delay = GNUNET_TIME_relative_multiply (create_connection_time,
991 c->create_retry);
992 if (c->create_retry < 64)
993 c->create_retry *= 2;
994 }
938 c->bck_maintenance_task = GNUNET_SCHEDULER_add_delayed (delay, 995 c->bck_maintenance_task = GNUNET_SCHEDULER_add_delayed (delay,
939 &connection_bck_keepalive, 996 &connection_bck_keepalive,
940 c); 997 c);