aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-09-29 20:31:38 +0000
committerChristian Grothoff <christian@grothoff.org>2011-09-29 20:31:38 +0000
commit71d0fc63b13ca00097435052925ea80677c9e817 (patch)
tree5acbeadf047a41b78ad75da6f9c7fc08df47028a /src/transport
parent24a59107ad07045e59810eaed253d0b1d5ebb5e5 (diff)
downloadgnunet-71d0fc63b13ca00097435052925ea80677c9e817.tar.gz
gnunet-71d0fc63b13ca00097435052925ea80677c9e817.zip
fix disconnect message transmission, send keepalives
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c62
1 files changed, 56 insertions, 6 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index a391ff572..e35370ad7 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -45,6 +45,14 @@
45 */ 45 */
46#define QUOTA_VIOLATION_DROP_THRESHOLD 10 46#define QUOTA_VIOLATION_DROP_THRESHOLD 10
47 47
48/**
49 * How often do we send KEEPALIVE messages to each of our neighbours?
50 * (idle timeout is 5 minutes or 300 seconds, so with 90s interval we
51 * send 3 keepalives in each interval, so 3 messages would need to be
52 * lost in a row for a disconnect).
53 */
54#define KEEPALIVE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90)
55
48 56
49/** 57/**
50 * Entry in neighbours. 58 * Entry in neighbours.
@@ -229,6 +237,11 @@ struct NeighbourMapEntry
229 GNUNET_SCHEDULER_TaskIdentifier timeout_task; 237 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
230 238
231 /** 239 /**
240 * ID of task scheduled to send keepalives.
241 */
242 GNUNET_SCHEDULER_TaskIdentifier keepalive_task;
243
244 /**
232 * ID of task scheduled to run when we should try transmitting 245 * ID of task scheduled to run when we should try transmitting
233 * the head of the message queue. 246 * the head of the message queue.
234 */ 247 */
@@ -467,10 +480,11 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
467 if (GNUNET_YES == n->is_connected) 480 if (GNUNET_YES == n->is_connected)
468 { 481 {
469 n->is_connected = GNUNET_NO; 482 n->is_connected = GNUNET_NO;
470 483 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->keepalive_task);
484 GNUNET_SCHEDULER_cancel (n->keepalive_task);
485 n->keepalive_task = GNUNET_SCHEDULER_NO_TASK;
471 GNUNET_assert (neighbours_connected > 0); 486 GNUNET_assert (neighbours_connected > 0);
472 neighbours_connected--; 487 neighbours_connected--;
473
474 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), -1, 488 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), -1,
475 GNUNET_NO); 489 GNUNET_NO);
476 disconnect_notify_cb (callback_cls, &n->id); 490 disconnect_notify_cb (callback_cls, &n->id);
@@ -532,6 +546,41 @@ neighbour_timeout_task (void *cls,
532 546
533 547
534/** 548/**
549 * Send another keepalive message.
550 *
551 * @param cls the 'struct NeighbourMapEntry' of the neighbour that went idle
552 * @param tc scheduler context
553 */
554static void
555neighbour_keepalive_task (void *cls,
556 const struct GNUNET_SCHEDULER_TaskContext *tc)
557{
558 struct NeighbourMapEntry *n = cls;
559 struct GNUNET_MessageHeader m;
560 struct GNUNET_TRANSPORT_PluginFunctions *papi;
561
562 n->keepalive_task = GNUNET_SCHEDULER_NO_TASK;
563 GNUNET_assert (GNUNET_YES == n->is_connected);
564 GNUNET_STATISTICS_update (GST_stats,
565 gettext_noop ("# keepalives sent"), 1,
566 GNUNET_NO);
567 m.size = htons (sizeof (struct GNUNET_MessageHeader));
568 m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE);
569 papi = GST_plugins_find (n->plugin_name);
570 if (papi != NULL)
571 papi->send (papi->cls,
572 &n->id, (const void *) &m,
573 sizeof (m),
574 UINT32_MAX /* priority */ ,
575 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->addr, n->addrlen,
576 GNUNET_YES, NULL, NULL);
577 n->keepalive_task = GNUNET_SCHEDULER_add_delayed (KEEPALIVE_FREQUENCY,
578 &neighbour_keepalive_task,
579 n);
580}
581
582
583/**
535 * Disconnect from the given neighbour. 584 * Disconnect from the given neighbour.
536 * 585 *
537 * @param cls unused 586 * @param cls unused
@@ -674,7 +723,8 @@ try_connect_using_address (void *cls, const struct GNUNET_PeerIdentity *target,
674 ats_count); 723 ats_count);
675 if (GNUNET_YES == was_connected) 724 if (GNUNET_YES == was_connected)
676 return; 725 return;
677 726 n->keepalive_task = GNUNET_SCHEDULER_add_now (&neighbour_keepalive_task,
727 n);
678 neighbours_connected++; 728 neighbours_connected++;
679 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, 729 GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
680 GNUNET_NO); 730 GNUNET_NO);
@@ -796,12 +846,12 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
796 if (GNUNET_YES != n->is_connected) 846 if (GNUNET_YES != n->is_connected)
797 return; /* not connected anymore anyway, shouldn't matter */ 847 return; /* not connected anymore anyway, shouldn't matter */
798 848
799 /* we are not connected until ATS suggests a new address */
800 //n->is_connected = GNUNET_NO; 849 //n->is_connected = GNUNET_NO;
801 850
851 /* fast disconnect unless ATS suggests a new address */
802 GNUNET_SCHEDULER_cancel (n->timeout_task); 852 GNUNET_SCHEDULER_cancel (n->timeout_task);
803 n->timeout_task = 853 n->timeout_task =
804 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 854 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT,
805 &neighbour_timeout_task, n); 855 &neighbour_timeout_task, n);
806 /* try QUICKLY to re-establish a connection, reduce timeout! */ 856 /* try QUICKLY to re-establish a connection, reduce timeout! */
807 if (NULL != n->ats) 857 if (NULL != n->ats)
@@ -1131,7 +1181,7 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
1131 papi = GST_plugins_find (n->plugin_name); 1181 papi = GST_plugins_find (n->plugin_name);
1132 if (papi != NULL) 1182 if (papi != NULL)
1133 papi->send (papi->cls, target, (const void *) &disconnect_msg, 1183 papi->send (papi->cls, target, (const void *) &disconnect_msg,
1134 sizeof (struct GNUNET_MessageHeader), 1184 sizeof (disconnect_msg),
1135 UINT32_MAX /* priority */ , 1185 UINT32_MAX /* priority */ ,
1136 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->addr, n->addrlen, 1186 GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->addr, n->addrlen,
1137 GNUNET_YES, NULL, NULL); 1187 GNUNET_YES, NULL, NULL);