gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r31518 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r31518 - gnunet/src/transport
Date: Wed, 18 Dec 2013 12:31:57 +0100

Author: wachs
Date: 2013-12-18 12:31:56 +0100 (Wed, 18 Dec 2013)
New Revision: 31518

Modified:
   gnunet/src/transport/gnunet-service-transport.c
   gnunet/src/transport/gnunet-service-transport_neighbours.c
   gnunet/src/transport/gnunet-service-transport_neighbours.h
   gnunet/src/transport/gnunet-service-transport_plugins.c
   gnunet/src/transport/plugin_transport_bluetooth.c
   gnunet/src/transport/plugin_transport_http_client.c
   gnunet/src/transport/plugin_transport_http_server.c
   gnunet/src/transport/plugin_transport_tcp.c
   gnunet/src/transport/plugin_transport_template.c
   gnunet/src/transport/plugin_transport_udp.c
   gnunet/src/transport/plugin_transport_unix.c
   gnunet/src/transport/plugin_transport_wlan.c
Log:
new timeout function and keep alives with nonces


Modified: gnunet/src/transport/gnunet-service-transport.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport.c     2013-12-18 11:31:29 UTC 
(rev 31517)
+++ gnunet/src/transport/gnunet-service-transport.c     2013-12-18 11:31:56 UTC 
(rev 31518)
@@ -384,10 +384,10 @@
     GST_neighbours_handle_disconnect_message (peer, message);
     break;
   case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
-    GST_neighbours_keepalive (peer);
+    GST_neighbours_keepalive (peer, message);
     break;
   case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE:
-    GST_neighbours_keepalive_response (peer);
+    GST_neighbours_keepalive_response (peer, message);
     break;
   default:
     /* should be payload */

Modified: gnunet/src/transport/gnunet-service-transport_neighbours.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_neighbours.c  2013-12-18 
11:31:29 UTC (rev 31517)
+++ gnunet/src/transport/gnunet-service-transport_neighbours.c  2013-12-18 
11:31:56 UTC (rev 31518)
@@ -117,6 +117,28 @@
 
 
 /**
+ * Message a peer sends to another when connected to indicate that a
+ * session is in use and the peer is still alive or to respond to a keep alive.
+ * A peer sends a message with type 
#GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE
+ * to request a message with 
#GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE.
+ * When the keep alive response with type is received, transport service
+ * will call the respective plugin to update the session timeout
+ */
+struct SessionKeepAliveMessage
+{
+  /**
+   * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE or
+   * #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE.
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * A nonce to identify the session the keep alive is used for
+   */
+  uint32_t nonce GNUNET_PACKED;
+};
+
+/**
  * Message we send to the other peer to notify him that we intentionally
  * are disconnecting (to reduce timeouts).  This is just a friendly
  * notification, peers must not rely on always receiving disconnect
@@ -410,6 +432,10 @@
    */
   int ats_active;
 
+  /**
+   * The current nonce sent in the last keep alive messages
+   */
+  uint32_t keep_alive_nonce;
 };
 
 
@@ -775,6 +801,7 @@
   }
 
   na->ats_active = GNUNET_NO;
+  na->keep_alive_nonce = 0;
   if (NULL != na->address)
   {
     GNUNET_HELLO_address_free (na->address);
@@ -847,6 +874,7 @@
   na->bandwidth_out = bandwidth_out;
   na->session = session;
   na->ats_active = is_active;
+  na->keep_alive_nonce = 0;
   if (GNUNET_YES == is_active)
   {
     /* Telling ATS about new session */
@@ -1296,16 +1324,28 @@
 static void
 send_keepalive (struct NeighbourMapEntry *n)
 {
-  struct GNUNET_MessageHeader m;
+  struct SessionKeepAliveMessage m;
   struct GNUNET_TIME_Relative timeout;
+  uint32_t nonce;
 
   GNUNET_assert ((S_CONNECTED == n->state) ||
                  (S_CONNECTED_SWITCHING_BLACKLIST == n->state) ||
                  (S_CONNECTED_SWITCHING_CONNECT_SENT));
   if (GNUNET_TIME_absolute_get_remaining (n->keep_alive_time).rel_value_us > 0)
     return; /* no keepalive needed at this time */
-  m.size = htons (sizeof (struct GNUNET_MessageHeader));
-  m.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE);
+
+  nonce = 0; /* 0 indicates 'not set' */
+  while (0 == nonce)
+    nonce = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+      "Sending keep alive response to peer `%s' with nonce %u\n",
+      GNUNET_i2s (&n->id), nonce);
+
+  m.header.size = htons (sizeof (struct SessionKeepAliveMessage));
+  m.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE);
+  m.nonce = htonl (nonce);
+
   timeout = send_with_session (n,
                               (const void *) &m, sizeof (m),
                               UINT32_MAX /* priority */,
@@ -1313,9 +1353,11 @@
                               NULL, NULL);
   GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# keepalives sent"), 1,
                            GNUNET_NO);
+  n->primary_address.keep_alive_nonce = nonce;
   n->expect_latency_response = GNUNET_YES;
   n->last_keep_alive_time = GNUNET_TIME_absolute_get ();
   n->keep_alive_time = GNUNET_TIME_relative_to_absolute (timeout);
+
 }
 
 
@@ -1324,13 +1366,20 @@
  * we received a KEEPALIVE (or equivalent); send a response.
  *
  * @param neighbour neighbour to keep alive (by sending keep alive response)
+ * @param m the keep alive message containing the nonce to respond to
  */
 void
-GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour)
+GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour,
+    const struct GNUNET_MessageHeader *m)
 {
   struct NeighbourMapEntry *n;
-  struct GNUNET_MessageHeader m;
+  const struct SessionKeepAliveMessage *msg_in;
+  struct SessionKeepAliveMessage msg;
 
+  if (sizeof (struct SessionKeepAliveMessage) != ntohs (m->size))
+    return;
+
+  msg_in = (struct SessionKeepAliveMessage *) m;
   if (NULL == (n = lookup_neighbour (neighbour)))
   {
     GNUNET_STATISTICS_update (GST_stats,
@@ -1347,11 +1396,17 @@
                               1, GNUNET_NO);
     return;
   }
+
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+      "Received keep alive request from peer `%s' with nonce %u\n",
+      GNUNET_i2s (&n->id), ntohl (msg_in->nonce));
+
   /* 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);
+  msg.header.size = htons (sizeof (struct SessionKeepAliveMessage));
+  msg.header.type = htons 
(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE);
+  msg.nonce = msg_in->nonce;
   (void) send_with_session(n,
-                          (const void *) &m, sizeof (m),
+                          (const void *) &msg, sizeof (struct 
SessionKeepAliveMessage),
                           UINT32_MAX /* priority */,
                           GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES,
                           NULL, NULL);
@@ -1364,14 +1419,22 @@
  * plus calculated latency) to ATS.
  *
  * @param neighbour neighbour to keep alive
+ * @param m the message containing the keep alive response
  */
 void
-GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour)
+GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
+    const struct GNUNET_MessageHeader *m)
 {
   struct NeighbourMapEntry *n;
+  const struct SessionKeepAliveMessage *msg;
+  struct GNUNET_TRANSPORT_PluginFunctions *papi;
   uint32_t latency;
   struct GNUNET_ATS_Information ats;
 
+  if (sizeof (struct SessionKeepAliveMessage) != ntohs (m->size))
+    return;
+
+  msg = (const struct SessionKeepAliveMessage *) m;
   if (NULL == (n = lookup_neighbour (neighbour)))
   {
     GNUNET_STATISTICS_update (GST_stats,
@@ -1389,6 +1452,43 @@
                               1, GNUNET_NO);
     return;
   }
+  if (NULL == n->primary_address.address)
+  {
+    GNUNET_STATISTICS_update (GST_stats,
+                              gettext_noop
+                              ("# KEEPALIVE_RESPONSE messages discarded 
(address changed)"),
+                              1, GNUNET_NO);
+    return;
+  }
+  if (n->primary_address.keep_alive_nonce != ntohl (msg->nonce))
+  {
+    GNUNET_STATISTICS_update (GST_stats,
+                              gettext_noop
+                              ("# KEEPALIVE_RESPONSE messages discarded (wrong 
nonce)"),
+                              1, GNUNET_NO);
+    return;
+  }
+  else
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+        "Received keep alive response from peer `%s' for session %p\n",
+        GNUNET_i2s (&n->id), n->primary_address.session);
+
+  }
+
+  /* Update session timeout here */
+  if (NULL != (papi = GST_plugins_find 
(n->primary_address.address->transport_name)))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+        "Updating session for peer `%s' for session %p\n",
+        GNUNET_i2s (&n->id), n->primary_address.session);
+    papi->update_session_timeout (papi->cls, &n->id, 
n->primary_address.session);
+  }
+  else
+  {
+    GNUNET_break (0);
+  }
+
   n->expect_latency_response = GNUNET_NO;
   n->latency = GNUNET_TIME_absolute_get_duration (n->last_keep_alive_time);
   n->timeout = GNUNET_TIME_relative_to_absolute 
(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
@@ -1404,10 +1504,8 @@
   else
     latency = n->latency.rel_value_us;
   ats.value = htonl (latency);
-  GST_ats_update_metrics (&n->id,
-                                                                               
          n->primary_address.address,
-                                                                               
        n->primary_address.session,
-                                                                               
        &ats, 1);
+  GST_ats_update_metrics (&n->id, n->primary_address.address,
+      n->primary_address.session, &ats, 1);
 }
 
 

Modified: gnunet/src/transport/gnunet-service-transport_neighbours.h
===================================================================
--- gnunet/src/transport/gnunet-service-transport_neighbours.h  2013-12-18 
11:31:29 UTC (rev 31517)
+++ gnunet/src/transport/gnunet-service-transport_neighbours.h  2013-12-18 
11:31:56 UTC (rev 31518)
@@ -125,22 +125,27 @@
 
 /**
  * Keep the connection to the given neighbour alive longer,
- * we received a KEEPALIVE (or equivalent).
+ * we received a KEEPALIVE (or equivalent); send a response.
  *
- * @param neighbour neighbour to keep alive
+ * @param neighbour neighbour to keep alive (by sending keep alive response)
+ * @param m the keep alive message containing the nonce to respond to
  */
 void
-GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour);
+GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour,
+                          const struct GNUNET_MessageHeader *m);
 
 
 /**
- * We received a KEEP_ALIVE_RESPONSE message and use this to calculate latency
- * to this peer
+ * We received a KEEP_ALIVE_RESPONSE message and use this to calculate
+ * latency to this peer.  Pass the updated information (existing ats
+ * plus calculated latency) to ATS.
  *
  * @param neighbour neighbour to keep alive
+ * @param m the message containing the keep alive response
  */
 void
-GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity 
*neighbour);
+GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
+    const struct GNUNET_MessageHeader *m);
 
 
 /**

Modified: gnunet/src/transport/gnunet-service-transport_plugins.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_plugins.c     2013-12-18 
11:31:29 UTC (rev 31517)
+++ gnunet/src/transport/gnunet-service-transport_plugins.c     2013-12-18 
11:31:56 UTC (rev 31518)
@@ -245,6 +245,14 @@
                   "query_keepalive_factor",
                   plug->lib_name);
     }
+    if (NULL == plug->api->update_session_timeout)
+    {
+        fail = GNUNET_YES;
+      GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                  _("Missing function `%s' in transport plugin for `%s'\n"),
+                  "update_session_timeout",
+                  plug->lib_name);
+    }
     if (GNUNET_YES == fail)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,

Modified: gnunet/src/transport/plugin_transport_bluetooth.c
===================================================================
--- gnunet/src/transport/plugin_transport_bluetooth.c   2013-12-18 11:31:29 UTC 
(rev 31517)
+++ gnunet/src/transport/plugin_transport_bluetooth.c   2013-12-18 11:31:56 UTC 
(rev 31518)
@@ -1799,7 +1799,16 @@
   return GNUNET_OK;
 }
 
+static void
+bluetooth_plugin_update_session_timeout (void *cls,
+                                  const struct GNUNET_PeerIdentity *peer,
+                                  struct Session *session)
+{
 
+}
+
+
+
 /**
  * Entry point for the plugin.
  *
@@ -1933,6 +1942,7 @@
   api->address_to_string = &bluetooth_plugin_address_to_string;;
   api->string_to_address = &bluetooth_string_to_address;
   api->get_network = &bluetooth_get_network;
+  api->update_session_timeout = &blueooth_plugin_update_session_timeout;
 
   return api;
 }

Modified: gnunet/src/transport/plugin_transport_http_client.c
===================================================================
--- gnunet/src/transport/plugin_transport_http_client.c 2013-12-18 11:31:29 UTC 
(rev 31517)
+++ gnunet/src/transport/plugin_transport_http_client.c 2013-12-18 11:31:56 UTC 
(rev 31518)
@@ -1759,7 +1759,14 @@
   return http_common_plugin_address_to_string (cls, PLUGIN_NAME, addr, 
addrlen);
 }
 
+static void
+http_client_plugin_update_session_timeout (void *cls,
+                                  const struct GNUNET_PeerIdentity *peer,
+                                  struct Session *session)
+{
 
+}
+
 /**
  * Entry point for the plugin.
  */
@@ -1796,6 +1803,7 @@
   api->string_to_address = &http_common_plugin_string_to_address;
   api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
   api->get_network = &http_client_get_network;
+  api->update_session_timeout = &http_client_plugin_update_session_timeout;
 
 #if BUILD_HTTPS
   plugin->name = "transport-https_client";

Modified: gnunet/src/transport/plugin_transport_http_server.c
===================================================================
--- gnunet/src/transport/plugin_transport_http_server.c 2013-12-18 11:31:29 UTC 
(rev 31517)
+++ gnunet/src/transport/plugin_transport_http_server.c 2013-12-18 11:31:56 UTC 
(rev 31518)
@@ -900,7 +900,15 @@
   return 3;
 }
 
+static void
+http_server_plugin_update_session_timeout (void *cls,
+                                  const struct GNUNET_PeerIdentity *peer,
+                                  struct Session *session)
+{
 
+}
+
+
 /**
  * Tell MHD that the connection should timeout after @a to seconds.
  *
@@ -3121,7 +3129,7 @@
   api->string_to_address = &http_common_plugin_string_to_address;
   api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
   api->get_network = &http_server_get_network;
-
+  api->update_session_timeout = &http_server_plugin_update_session_timeout;
 #if BUILD_HTTPS
   plugin->name = "transport-https_server";
   plugin->protocol = "https";

Modified: gnunet/src/transport/plugin_transport_tcp.c
===================================================================
--- gnunet/src/transport/plugin_transport_tcp.c 2013-12-18 11:31:29 UTC (rev 
31517)
+++ gnunet/src/transport/plugin_transport_tcp.c 2013-12-18 11:31:56 UTC (rev 
31518)
@@ -1420,7 +1420,15 @@
                           session);
 }
 
+static void
+tcp_plugin_update_session_timeout (void *cls,
+                                  const struct GNUNET_PeerIdentity *peer,
+                                  struct Session *session)
+{
 
+}
+
+
 /**
  * Create a new session to transmit data to the target
  * This session will used to send data to this peer and the plugin will
@@ -2687,6 +2695,7 @@
   api->address_to_string = &tcp_address_to_string;
   api->string_to_address = &tcp_string_to_address;
   api->get_network = &tcp_get_network;
+  api->update_session_timeout = &tcp_plugin_update_session_timeout;
   plugin->service = service;
   if (NULL != service)
   {

Modified: gnunet/src/transport/plugin_transport_template.c
===================================================================
--- gnunet/src/transport/plugin_transport_template.c    2013-12-18 11:31:29 UTC 
(rev 31517)
+++ gnunet/src/transport/plugin_transport_template.c    2013-12-18 11:31:56 UTC 
(rev 31518)
@@ -378,7 +378,14 @@
   return NULL;
 }
 
+static void
+template_plugin_update_session_timeout (void *cls,
+                                  const struct GNUNET_PeerIdentity *peer,
+                                  struct Session *session)
+{
 
+}
+
 /**
  * Entry point for the plugin.
  */
@@ -415,6 +422,7 @@
   api->string_to_address = &template_plugin_string_to_address;
   api->get_session = &template_plugin_get_session;
   api->get_network = &template_plugin_get_network;
+  api->update_session_timeout = &template_plugin_update_session_timeout;
   LOG (GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n");
   return api;
 }

Modified: gnunet/src/transport/plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp.c 2013-12-18 11:31:29 UTC (rev 
31517)
+++ gnunet/src/transport/plugin_transport_udp.c 2013-12-18 11:31:56 UTC (rev 
31518)
@@ -1673,7 +1673,14 @@
   return s;
 }
 
+static void
+udp_plugin_update_session_timeout (void *cls,
+                                  const struct GNUNET_PeerIdentity *peer,
+                                  struct Session *session)
+{
 
+}
+
 /**
  * Creates a new outbound session the transport service will use to send data 
to the
  * peer
@@ -3197,7 +3204,7 @@
   api->get_session = &udp_plugin_get_session;
   api->send = &udp_plugin_send;
   api->get_network = &udp_get_network;
-
+  api->update_session_timeout = &udp_plugin_update_session_timeout;
   return api;
 }
 

Modified: gnunet/src/transport/plugin_transport_unix.c
===================================================================
--- gnunet/src/transport/plugin_transport_unix.c        2013-12-18 11:31:29 UTC 
(rev 31517)
+++ gnunet/src/transport/plugin_transport_unix.c        2013-12-18 11:31:56 UTC 
(rev 31518)
@@ -906,7 +906,14 @@
   return s;
 }
 
+static void
+unix_plugin_update_session_timeout (void *cls,
+                                  const struct GNUNET_PeerIdentity *peer,
+                                  struct Session *session)
+{
 
+}
+
 /**
  * Function that can be used by the transport service to transmit
  * a message using the plugin.   Note that in the case of a
@@ -1635,6 +1642,7 @@
   api->check_address = &unix_check_address;
   api->string_to_address = &unix_string_to_address;
   api->get_network = &unix_get_network;
+  api->update_session_timeout = &unix_plugin_update_session_timeout;
   sockets_created = unix_transport_server_start (plugin);
   if (0 == sockets_created)
     LOG (GNUNET_ERROR_TYPE_WARNING,

Modified: gnunet/src/transport/plugin_transport_wlan.c
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.c        2013-12-18 11:31:29 UTC 
(rev 31517)
+++ gnunet/src/transport/plugin_transport_wlan.c        2013-12-18 11:31:56 UTC 
(rev 31518)
@@ -1856,6 +1856,14 @@
 }
 
 
+static void
+wlan_plugin_update_session_timeout (void *cls,
+                                  const struct GNUNET_PeerIdentity *peer,
+                                  struct Session *session)
+{
+
+}
+
 /**
  * Entry point for the plugin.
  *
@@ -1989,6 +1997,7 @@
   api->address_to_string = &wlan_plugin_address_to_string;
   api->string_to_address = &wlan_string_to_address;
   api->get_network = &wlan_get_network;
+  api->update_session_timeout = &wlan_plugin_update_session_timeout;
   return api;
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]