process keepalive, simplify PONGs
authorChristian Grothoff <christian@grothoff.org>
Sun, 14 Aug 2011 20:47:31 +0000 (20:47 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sun, 14 Aug 2011 20:47:31 +0000 (20:47 +0000)
src/include/gnunet_signatures.h
src/transport/gnunet-service-transport-new.c
src/transport/gnunet-service-transport_neighbours.c
src/transport/gnunet-service-transport_neighbours.h
src/transport/gnunet-service-transport_validation.c
src/transport/plugin_transport_udp.c

index 9b6a3d6b6a7f3f2ad811547a13259612d4790cef..c54df3e8546e7da3c5fca7e0fceb947079ec75c5 100644 (file)
@@ -49,7 +49,7 @@ extern "C"
 
 /**
  * Signature for confirming that this peer connected to another peer
- * using a particular address.
+ * using a particular address (LEGACY)
  */
 #define GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING 2
 
index 6bc3c25419850f7a47cca64f0742f3771b85363d..3cc1191fd1f74be094e730683526a9bb20eb923b 100644 (file)
@@ -226,6 +226,9 @@ plugin_env_receive_callback (void *cls,
             a fake disconnect message... */
          GST_neighbours_force_disconnect (peer);
          break;
+       case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
+         GST_neighbours_keepalive (peer);
+         break;
        default:   
          /* should be payload */
          do_forward = GNUNET_SYSERR;
index 211595b5144c2f4329171d97295db59883c5e84b..60411256090607914873cf800089c2a0838ccbb0 100644 (file)
@@ -815,10 +815,6 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender
          n->quota_violation_count--;
        }
     }
-  GNUNET_SCHEDULER_cancel (n->timeout_task);
-  n->timeout_task =
-    GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
-                                 &neighbour_timeout_task, n);
   if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
     {
       GNUNET_STATISTICS_update (GST_stats,
@@ -848,6 +844,33 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender
 }
 
 
+/**
+ * Keep the connection to the given neighbour alive longer,
+ * we received a KEEPALIVE (or equivalent).
+ *
+ * @param neighbour neighbour to keep alive
+ */
+void
+GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour)
+{
+  struct NeighbourMapEntry *n;
+
+  n = lookup_neighbour (neighbour);
+  if (NULL == n)
+    {
+      GNUNET_STATISTICS_update (GST_stats,
+                               gettext_noop ("# KEEPALIVE messages discarded (not connected)"),
+                               1,
+                               GNUNET_NO);
+      return;
+    }
+  GNUNET_SCHEDULER_cancel (n->timeout_task);
+  n->timeout_task =
+    GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+                                 &neighbour_timeout_task, n);  
+}
+
+
 /**
  * Change the incoming quota for the given peer.
  *
index 14f2238117ad00a1e4941b716d4eb3f0d0fc2876..a99cd1e968edbceedb99200808e6d7bc2732b75e 100644 (file)
@@ -121,6 +121,16 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender
                                        int *do_forward);
 
 
+/**
+ * Keep the connection to the given neighbour alive longer,
+ * we received a KEEPALIVE (or equivalent).
+ *
+ * @param neighbour neighbour to keep alive
+ */
+void
+GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour);
+
+
 /**
  * Change the incoming quota for the given peer.
  *
index e07ff7546b9b3b47b632e96d2a769ac66e41e74e..86c51c7290faffec7bcdd3f3b010d79f4fb0699c 100644 (file)
@@ -132,11 +132,8 @@ struct TransportPongMessage
   struct GNUNET_CRYPTO_RsaSignature signature;
 
   /**
-   * What are we signing and why?  Two possible reason codes can be here:
    * GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN to confirm that this is a
-   * plausible address for this peer (pid is set to identity of signer); or
-   * GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING to confirm that this is
-   * an address we used to connect to the peer with the given pid.
+   * plausible address for the signing peer.
    */
   struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
 
@@ -145,13 +142,6 @@ struct TransportPongMessage
    */
   struct GNUNET_TIME_AbsoluteNBO expiration;
 
-  /**
-   * Either the identity of the peer Who signed this message, or the
-   * identity of the peer that we're connected to using the given
-   * address (depending on purpose.type).
-   */
-  struct GNUNET_PeerIdentity pid;
-
   /**
    * Size of address appended to this message (part of what is
    * being signed, hence not redundant).
@@ -683,11 +673,10 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
     htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
           sizeof (uint32_t) +
           sizeof (struct GNUNET_TIME_AbsoluteNBO) +
-          sizeof (struct GNUNET_PeerIdentity) + alen + slen);
+          alen + slen);
   pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
   pong->challenge = ping->challenge;
   pong->addrlen = htonl(alen + slen);
-  pong->pid = GST_my_identity;
   memcpy (&pong[1], addr, slen);
   memcpy (&((char*)&pong[1])[slen], addrend, alen);
   if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value < PONG_SIGNATURE_LIFETIME.rel_value / 4)
@@ -993,13 +982,6 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
                            1,
                            GNUNET_NO);
   pong = (const struct TransportPongMessage *) hdr;
-  if (0 != memcmp (&pong->pid,
-                   sender,
-                   sizeof (struct GNUNET_PeerIdentity)))
-    {
-      GNUNET_break_op (0);
-      return;
-    }
   addr = (const char*) &pong[1];
   alen = ntohs (hdr->size) - sizeof (struct TransportPongMessage);
   addrend = memchr (addr, '\0', alen);
@@ -1025,6 +1007,14 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
       return;
     }
   /* now check that PONG is well-formed */
+  if (0 != memcmp (&ve->pid,
+                   sender,
+                   sizeof (struct GNUNET_PeerIdentity)))
+    {
+      GNUNET_break_op (0);
+      return;
+    }
+
   if (GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value == 0)
     {
       GNUNET_STATISTICS_update (GST_stats,
index e58d4312e3af5ec69c194f10b8d545b976705c25..7d8c1520f1d017b39f45520e9377204ff5cb56ff 100644 (file)
@@ -129,7 +129,8 @@ struct Plugin;
 
 
 /**
- * Session with another peer.
+ * Session with another peer.  FIXME: why not make this into
+ * a regular 'struct Session' and pass it around!?
  */
 struct PeerSession
 {