From 4e67f0c94b70b5c84502080485fee34d546a76cf Mon Sep 17 00:00:00 2001 From: LRN Date: Sun, 15 Dec 2013 01:56:00 +0000 Subject: Non-uniform keepalive timeout for different plugins --- src/include/gnunet_transport_plugin.h | 18 +++++++ .../gnunet-service-transport_neighbours.c | 63 +++++++++++----------- src/transport/plugin_transport_bluetooth.c | 16 ++++++ src/transport/plugin_transport_http_client.c | 16 ++++++ src/transport/plugin_transport_http_server.c | 16 ++++++ src/transport/plugin_transport_tcp.c | 16 ++++++ src/transport/plugin_transport_template.c | 16 ++++++ src/transport/plugin_transport_udp.c | 16 ++++++ src/transport/plugin_transport_unix.c | 16 ++++++ src/transport/plugin_transport_wlan.c | 16 ++++++ 10 files changed, 178 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h index 6bf365243..f05048e96 100644 --- a/src/include/gnunet_transport_plugin.h +++ b/src/include/gnunet_transport_plugin.h @@ -390,6 +390,17 @@ typedef int (*GNUNET_TRANSPORT_DisconnectSessionFunction) (void *cls, struct Session *session); +/** + * Function that is called to get the keepalive factor. + * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to + * calculate the interval between keepalive packets. + * + * @param cls closure with the `struct Plugin` + * @return keepalive factor + */ +typedef unsigned int +(*GNUNET_TRANSPORT_QueryKeepaliveFactorFunction) (void *cls); + /** * Function that can be called to force a disconnect from the @@ -564,6 +575,13 @@ struct GNUNET_TRANSPORT_PluginFunctions */ GNUNET_TRANSPORT_DisconnectSessionFunction disconnect_session; + /** + * Function that is used to query keepalive factor. + * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to + * calculate the interval between keepalive packets. + */ + GNUNET_TRANSPORT_QueryKeepaliveFactorFunction query_keepalive_factor; + /** * Function to pretty-print addresses. NOTE: this function is not * yet used by transport-service, but will be used in the future diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index eb3ad1d07..c4d4677b1 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c @@ -54,15 +54,6 @@ */ #define QUOTA_VIOLATION_DROP_THRESHOLD 10 -/** - * How often do we send KEEPALIVE messages to each of our neighbours and measure - * the latency with this neighbour? - * (idle timeout is 5 minutes or 300 seconds, so with 100s interval we - * send 3 keepalives in each interval, so 3 messages would need to be - * lost in a row for a disconnect). - */ -#define KEEPALIVE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) - /** * How long are we willing to wait for a response from ATS before timing out? */ @@ -963,18 +954,24 @@ free_neighbour (struct NeighbourMapEntry *n, * @param msgbuf_size number of bytes in @a msgbuf buffer * @param priority transmission priority * @param timeout transmission timeout + * @param use_keepalive_timeout #GNUNET_YES to use plugin-specific keep-alive + * timeout (@a timeout is ignored in that case), #GNUNET_NO otherwise * @param cont continuation to call when finished (can be NULL) * @param cont_cls closure for @a cont + * @return timeout (copy of @a timeout or a calculated one if + * @a use_keepalive_timeout is #GNUNET_YES. */ -static void +static struct GNUNET_TIME_Relative send_with_session (struct NeighbourMapEntry *n, const char *msgbuf, size_t msgbuf_size, uint32_t priority, struct GNUNET_TIME_Relative timeout, + unsigned int use_keepalive_timeout, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) { struct GNUNET_TRANSPORT_PluginFunctions *papi; + struct GNUNET_TIME_Relative result = GNUNET_TIME_UNIT_FOREVER_REL; GNUNET_assert (n->primary_address.session != NULL); if ( ((NULL == (papi = GST_plugins_find (n->primary_address.address->transport_name)) || @@ -982,13 +979,16 @@ send_with_session (struct NeighbourMapEntry *n, n->primary_address.session, msgbuf, msgbuf_size, priority, - timeout, + (result = (GNUNET_NO == use_keepalive_timeout) ? timeout : + GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, + papi->query_keepalive_factor (papi->cls))), cont, cont_cls)))) && (NULL != cont)) cont (cont_cls, &n->id, GNUNET_SYSERR, msgbuf_size, 0); GST_neighbours_notify_data_sent (&n->id, n->primary_address.address, n->primary_address.session, msgbuf_size); GNUNET_break (NULL != papi); + return result; } @@ -1063,10 +1063,10 @@ send_disconnect (struct NeighbourMapEntry *n) &disconnect_msg.purpose, &disconnect_msg.signature)); - send_with_session (n, - (const char *) &disconnect_msg, sizeof (disconnect_msg), - UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, - &send_disconnect_cont, NULL); + (void) send_with_session (n, + (const char *) &disconnect_msg, sizeof (disconnect_msg), + UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_NO, &send_disconnect_cont, NULL); GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# DISCONNECT messages sent"), 1, @@ -1278,10 +1278,10 @@ try_transmission_to_peer (struct NeighbourMapEntry *n) return; /* no more messages */ GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq); n->is_active = mq; - send_with_session (n, - mq->message_buf, mq->message_buf_size, - 0 /* priority */, timeout, - &transmit_send_continuation, mq); + (void) send_with_session (n, + mq->message_buf, mq->message_buf_size, + 0 /* priority */, timeout, GNUNET_NO, + &transmit_send_continuation, mq); } @@ -1297,6 +1297,7 @@ static void send_keepalive (struct NeighbourMapEntry *n) { struct GNUNET_MessageHeader m; + struct GNUNET_TIME_Relative timeout; GNUNET_assert ((S_CONNECTED == n->state) || (S_CONNECTED_SWITCHING_BLACKLIST == n->state) || @@ -1305,16 +1306,16 @@ send_keepalive (struct NeighbourMapEntry *n) return; /* no keepalive needed at this time */ m.size = htons (sizeof (struct GNUNET_MessageHeader)); m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE); - send_with_session (n, - (const void *) &m, sizeof (m), - UINT32_MAX /* priority */, - KEEPALIVE_FREQUENCY, - NULL, NULL); + timeout = send_with_session (n, + (const void *) &m, sizeof (m), + UINT32_MAX /* priority */, + GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, + NULL, NULL); GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# keepalives sent"), 1, GNUNET_NO); n->expect_latency_response = GNUNET_YES; n->last_keep_alive_time = GNUNET_TIME_absolute_get (); - n->keep_alive_time = GNUNET_TIME_relative_to_absolute (KEEPALIVE_FREQUENCY); + n->keep_alive_time = GNUNET_TIME_relative_to_absolute (timeout); } @@ -1349,11 +1350,11 @@ GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour) /* send reply to allow neighbour to measure latency */ m.size = htons (sizeof (struct GNUNET_MessageHeader)); m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE); - send_with_session(n, - (const void *) &m, sizeof (m), - UINT32_MAX /* priority */, - KEEPALIVE_FREQUENCY, - NULL, NULL); + (void) send_with_session(n, + (const void *) &m, sizeof (m), + UINT32_MAX /* priority */, + GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, + NULL, NULL); } @@ -2769,7 +2770,7 @@ send_session_ack_message (struct NeighbourMapEntry *n) msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK); (void) send_with_session(n, (const char *) &msg, sizeof (struct GNUNET_MessageHeader), - UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, + UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_NO, NULL, NULL); } diff --git a/src/transport/plugin_transport_bluetooth.c b/src/transport/plugin_transport_bluetooth.c index 87130feec..7fbdbcfa9 100644 --- a/src/transport/plugin_transport_bluetooth.c +++ b/src/transport/plugin_transport_bluetooth.c @@ -1119,6 +1119,21 @@ bluetooth_plugin_disconnect_session (void *cls, } +/** + * Function that is called to get the keepalive factor. + * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to + * calculate the interval between keepalive packets. + * + * @param cls closure with the `struct Plugin` + * @return keepalive factor + */ +static unsigned int +bluetooth_query_keepalive_factor (void *cls) +{ + return 3; +} + + /** * Function that can be used by the transport service to transmit * a message using the plugin. Note that in the case of a @@ -1912,6 +1927,7 @@ libgnunet_plugin_transport_bluetooth_init (void *cls) api->get_session = &bluetooth_plugin_get_session; api->disconnect_peer = &bluetooth_plugin_disconnect_peer; api->disconnect_session = &bluetooth_plugin_disconnect_session; + api->query_keepalive_factor = &bluetooth_query_keepalive_factor; api->address_pretty_printer = &bluetooth_plugin_address_pretty_printer; api->check_address = &bluetooth_plugin_address_suggested; api->address_to_string = &bluetooth_plugin_address_to_string;; diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index 78f973574..b2bb5d513 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c @@ -699,6 +699,21 @@ http_client_session_disconnect (void *cls, } +/** + * Function that is called to get the keepalive factor. + * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to + * calculate the interval between keepalive packets. + * + * @param cls closure with the `struct Plugin` + * @return keepalive factor + */ +static unsigned int +http_client_query_keepalive_factor (void *cls) +{ + return 3; +} + + /** * Function that can be used to force the plugin to disconnect * from the given peer and cancel all previous transmissions @@ -1773,6 +1788,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) api->cls = plugin; api->send = &http_client_plugin_send; api->disconnect_session = &http_client_session_disconnect; + api->query_keepalive_factor = &http_client_query_keepalive_factor; api->disconnect_peer = &http_client_peer_disconnect; api->check_address = &http_client_plugin_address_suggested; api->get_session = &http_client_plugin_get_session; diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index ca6c0febc..19fd632b8 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c @@ -886,6 +886,21 @@ http_server_plugin_disconnect_session (void *cls, } +/** + * Function that is called to get the keepalive factor. + * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to + * calculate the interval between keepalive packets. + * + * @param cls closure with the `struct Plugin` + * @return keepalive factor + */ +static unsigned int +http_server_query_keepalive_factor (void *cls) +{ + return 3; +} + + /** * Tell MHD that the connection should timeout after @a to seconds. * @@ -3098,6 +3113,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) api->send = &http_server_plugin_send; api->disconnect_peer = &http_server_plugin_disconnect_peer; api->disconnect_session = &http_server_plugin_disconnect_session; + api->query_keepalive_factor = &http_server_query_keepalive_factor; api->check_address = &http_server_plugin_address_suggested; api->get_session = &http_server_plugin_get_session; diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index e22e01cee..992729911 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -864,6 +864,21 @@ tcp_disconnect_session (void *cls, } +/** + * Function that is called to get the keepalive factor. + * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to + * calculate the interval between keepalive packets. + * + * @param cls closure with the `struct Plugin` + * @return keepalive factor + */ +static unsigned int +tcp_query_keepalive_factor (void *cls) +{ + return 3; +} + + /** * Session was idle, so disconnect it * @@ -2665,6 +2680,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) api->get_session = &tcp_plugin_get_session; api->disconnect_session = &tcp_disconnect_session; + api->query_keepalive_factor = &tcp_query_keepalive_factor; api->disconnect_peer = &tcp_plugin_disconnect; api->address_pretty_printer = &tcp_plugin_address_pretty_printer; api->check_address = &tcp_plugin_check_address; diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c index feb0802d9..abcae5111 100644 --- a/src/transport/plugin_transport_template.c +++ b/src/transport/plugin_transport_template.c @@ -223,6 +223,21 @@ template_plugin_disconnect_session (void *cls, } +/** + * Function that is called to get the keepalive factor. + * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to + * calculate the interval between keepalive packets. + * + * @param cls closure with the `struct Plugin` + * @return keepalive factor + */ +static unsigned int +template_plugin_query_keepalive_factor (void *cls) +{ + return 3; +} + + /** * Function obtain the network type for a session * @@ -393,6 +408,7 @@ libgnunet_plugin_transport_template_init (void *cls) api->send = &template_plugin_send; api->disconnect_peer = &template_plugin_disconnect_peer; api->disconnect_session = &template_plugin_disconnect_session; + api->query_keepalive_factor = &template_plugin_query_keepalive_factor; api->address_pretty_printer = &template_plugin_address_pretty_printer; api->check_address = &template_plugin_address_suggested; api->address_to_string = &template_plugin_address_to_string; diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 904473ace..fb08e4349 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -1313,6 +1313,21 @@ udp_disconnect_session (void *cls, } +/** + * Function that is called to get the keepalive factor. + * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to + * calculate the interval between keepalive packets. + * + * @param cls closure with the `struct Plugin` + * @return keepalive factor + */ +static unsigned int +udp_query_keepalive_factor (void *cls) +{ + return 15; +} + + /** * Destroy a session, plugin is being unloaded. * @@ -3169,6 +3184,7 @@ libgnunet_plugin_transport_udp_init (void *cls) api->cls = p; api->send = NULL; api->disconnect_session = &udp_disconnect_session; + api->query_keepalive_factor = &udp_query_keepalive_factor; api->disconnect_peer = &udp_disconnect; api->address_pretty_printer = &udp_plugin_address_pretty_printer; api->address_to_string = &udp_address_to_string; diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 3d6ac4d23..906cf9997 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c @@ -599,6 +599,21 @@ unix_session_disconnect (void *cls, } +/** + * Function that is called to get the keepalive factor. + * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to + * calculate the interval between keepalive packets. + * + * @param cls closure with the `struct Plugin` + * @return keepalive factor + */ +static unsigned int +unix_query_keepalive_factor (void *cls) +{ + return 3; +} + + /** * Actually send out the message, assume we've got the address and * send_handle squared away! @@ -1614,6 +1629,7 @@ libgnunet_plugin_transport_unix_init (void *cls) api->send = &unix_plugin_send; api->disconnect_peer = &unix_peer_disconnect; api->disconnect_session = &unix_session_disconnect; + api->query_keepalive_factor = &unix_query_keepalive_factor; api->address_pretty_printer = &unix_plugin_address_pretty_printer; api->address_to_string = &unix_address_to_string; api->check_address = &unix_check_address; diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 3e1a6396c..916998dcc 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c @@ -695,6 +695,21 @@ wlan_plugin_disconnect_session (void *cls, } +/** + * Function that is called to get the keepalive factor. + * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to + * calculate the interval between keepalive packets. + * + * @param cls closure with the `struct Plugin` + * @return keepalive factor + */ +static unsigned int +wlan_plugin_query_keepalive_factor (void *cls) +{ + return 3; +} + + /** * A session is timing out. Clean up. * @@ -1968,6 +1983,7 @@ libgnunet_plugin_transport_wlan_init (void *cls) api->get_session = &wlan_plugin_get_session; api->disconnect_peer = &wlan_plugin_disconnect_peer; api->disconnect_session = &wlan_plugin_disconnect_session; + api->query_keepalive_factor = &wlan_plugin_query_keepalive_factor; api->address_pretty_printer = &wlan_plugin_address_pretty_printer; api->check_address = &wlan_plugin_address_suggested; api->address_to_string = &wlan_plugin_address_to_string; -- cgit v1.2.3