gnutls-commit
[Top][All Lists]
Advanced

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

[SCM] GNU gnutls branch, master, updated. gnutls-3_0_12-216-g6d9b794


From: Nikos Mavrogiannopoulos
Subject: [SCM] GNU gnutls branch, master, updated. gnutls-3_0_12-216-g6d9b794
Date: Sun, 12 Feb 2012 09:37:33 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU gnutls".

http://git.savannah.gnu.org/cgit/gnutls.git/commit/?id=6d9b794ba08cc26efc2298c9009b0b52d14b7b91

The branch, master has been updated
       via  6d9b794ba08cc26efc2298c9009b0b52d14b7b91 (commit)
       via  82efb9248346a2faa005c758bd9ac1da0250b3a4 (commit)
       via  943d467c705725c77be192067f5668ea133c84d1 (commit)
       via  d48be90a0614700c075719ba9a8b24276af635a1 (commit)
       via  ce372826b3bb8d57c04df3708b634f7495a6a86d (commit)
      from  a2564518939e7982926302da42b8e9973fa6f2d3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 6d9b794ba08cc26efc2298c9009b0b52d14b7b91
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sun Feb 12 10:42:14 2012 +0100

    update and reset timers on final flight and print timeout value in 
debugging mode.

commit 82efb9248346a2faa005c758bd9ac1da0250b3a4
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sat Feb 11 20:35:08 2012 +0100

    tests with fork are disabled in windows

commit 943d467c705725c77be192067f5668ea133c84d1
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sat Feb 11 20:32:31 2012 +0100

    updated

commit d48be90a0614700c075719ba9a8b24276af635a1
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sat Feb 11 20:30:20 2012 +0100

    use subsecond granularity for DTLS packet retransmissions.

commit ce372826b3bb8d57c04df3708b634f7495a6a86d
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sat Feb 11 20:29:48 2012 +0100

    added test to check whether the DTLS timeout is within a reasonable time.

-----------------------------------------------------------------------

Summary of changes:
 .gitignore                              |    1 +
 lib/gnutls_dtls.c                       |   20 ++--
 lib/gnutls_dtls.h                       |   22 ++++-
 lib/gnutls_int.h                        |    6 +-
 lib/gnutls_state.c                      |    3 +-
 tests/Makefile.am                       |    3 +-
 tests/{mini-loss.c => mini-loss-time.c} |  169 +++++++-----------------------
 tests/mini-loss.c                       |   14 ++-
 8 files changed, 90 insertions(+), 148 deletions(-)
 copy tests/{mini-loss.c => mini-loss-time.c} (67%)

diff --git a/.gitignore b/.gitignore
index 0e054ee..c65f537 100644
--- a/.gitignore
+++ b/.gitignore
@@ -586,3 +586,4 @@ tests/x509signself
 gl/tests/test-base64
 tests/mini-loss2
 src/libopts/libopts.la
+tests/mini-loss-time
diff --git a/lib/gnutls_dtls.c b/lib/gnutls_dtls.c
index 1dd3ccb..694d2d0 100644
--- a/lib/gnutls_dtls.c
+++ b/lib/gnutls_dtls.c
@@ -34,7 +34,7 @@
 #include <gnutls_constate.h>
 #include <gnutls_state.h>
 #include <gnutls/dtls.h>
-
+#include <timespec.h>
 
 /* This function fragments and transmits a previously buffered
  * outgoing message. It accepts mtu_data which is a buffer to
@@ -183,7 +183,10 @@ unsigned int timeout;
     &session->internals.handshake_send_buffer;
   mbuffer_st *cur;
   gnutls_handshake_description_t last_type = 0;
-  time_t now = gnutls_time (0);
+  unsigned int diff;
+  struct timespec now;
+  
+  gettime(&now);
 
   /* If we have already sent a flight and we are operating in a 
    * non blocking way, check if it is time to retransmit or just
@@ -207,10 +210,8 @@ unsigned int timeout;
             {
               /* if no retransmission is required yet just return 
                */
-              if (1000*(now-session->internals.dtls.handshake_start_time) < 
-                  session->internals.dtls.actual_retrans_timeout_ms)
+              if (timespec_sub_ms(&now, 
&session->internals.dtls.handshake_start_time) < 
session->internals.dtls.actual_retrans_timeout_ms)
                 {
-                  session->internals.dtls.handshake_last_call = now;
                   gnutls_assert();
                   goto nb_timeout;
                 }
@@ -227,8 +228,10 @@ unsigned int timeout;
 
   do 
     {
-      if (1000*(now-session->internals.dtls.handshake_start_time) >= 
session->internals.dtls.total_timeout_ms) 
+      diff = timespec_sub_ms(&now, 
&session->internals.dtls.handshake_start_time);
+      if (diff >= session->internals.dtls.total_timeout_ms) 
         {
+          _gnutls_dtls_log("Session timeout: %u ms\n", diff);
           ret = gnutls_assert_val(GNUTLS_E_TIMEDOUT);
           goto end_flight;
         }
@@ -251,7 +254,6 @@ unsigned int timeout;
       if (session->internals.dtls.flight_init == 0)
         {
           session->internals.dtls.flight_init = 1;
-          session->internals.dtls.handshake_last_call = now;
           RESET_TIMER;
           timeout = session->internals.dtls.actual_retrans_timeout_ms;
 
@@ -304,7 +306,7 @@ unsigned int timeout;
             }
         }
 
-      now = gnutls_time (0);
+      gettime(&now);
     } while(ret == GNUTLS_E_TIMEDOUT);
 
   if (ret < 0)
@@ -350,6 +352,7 @@ int ret;
 
   if (ret == GNUTLS_E_TIMEDOUT)
     {
+      UPDATE_TIMER;
       ret = _dtls_retransmit(session);
       if (ret == 0)
         {
@@ -359,6 +362,7 @@ int ret;
         return gnutls_assert_val(ret);
     }
 
+  RESET_TIMER;
   return 0;
 }
 
diff --git a/lib/gnutls_dtls.h b/lib/gnutls_dtls.h
index 3c8754f..b910d3d 100644
--- a/lib/gnutls_dtls.h
+++ b/lib/gnutls_dtls.h
@@ -23,9 +23,11 @@
 #ifndef DTLS_H
 # define DTLS_H
 
+#include <config.h>
 #include "gnutls_int.h"
 #include "gnutls_buffers.h"
 #include "gnutls_mbuffers.h"
+#include <timespec.h>
 
 int _dtls_transmit(gnutls_session_t session);
 int _dtls_retransmit(gnutls_session_t session);
@@ -33,10 +35,24 @@ int _dtls_record_check(gnutls_session_t session, uint64 * 
_seq);
 
 #define MAX_DTLS_TIMEOUT 60000
 
+/* returns a-b in ms */
+inline static unsigned int timespec_sub_ms(struct timespec *a, struct timespec 
*b)
+{
+  return (a->tv_sec * 1000 + a->tv_nsec / (1000 * 1000) -
+          (b->tv_sec * 1000 + b->tv_nsec / (1000 * 1000)));
+}
+
 #define RETURN_DTLS_EAGAIN_OR_TIMEOUT(session) { \
-  if (gnutls_time(0) - session->internals.dtls.handshake_start_time > \
-      session->internals.dtls.total_timeout_ms/1000) \
-    return gnutls_assert_val(GNUTLS_E_TIMEDOUT); \
+  struct timespec now; \
+  unsigned int diff; \
+  gettime(&now); \
+   \
+  diff = timespec_sub_ms(&now, &session->internals.dtls.handshake_start_time); 
\
+  if (diff > session->internals.dtls.total_timeout_ms) \
+    { \
+      _gnutls_dtls_log("Session timeout: %u ms\n", diff); \
+      return gnutls_assert_val(GNUTLS_E_TIMEDOUT); \
+    } \
   else \
     { \
       if (session->internals.dtls.blocking != 0) \
diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h
index d993544..578e355 100644
--- a/lib/gnutls_int.h
+++ b/lib/gnutls_int.h
@@ -625,10 +625,8 @@ typedef struct
 
   /* non blocking stuff variables */
   unsigned int blocking:1;
-  /* starting time of current handshake - seconds since epoch */
-  time_t handshake_start_time;
-  /* time in seconds of the last handshake call */
-  time_t handshake_last_call;
+  /* starting time of current handshake */
+  struct timespec handshake_start_time;
 
   /* The actual retrans_timeout for the next message (e.g. doubled or so) 
    */
diff --git a/lib/gnutls_state.c b/lib/gnutls_state.c
index e5790dd..3588d2e 100644
--- a/lib/gnutls_state.c
+++ b/lib/gnutls_state.c
@@ -46,6 +46,7 @@
 #include <gnutls_extensions.h>
 #include <system.h>
 #include <gnutls/dtls.h>
+#include <timespec.h>
 
 /* These should really be static, but src/tests.c calls them.  Make
    them public functions?  */
@@ -263,7 +264,7 @@ _gnutls_handshake_internal_state_init (gnutls_session_t 
session)
   
   session->internals.dtls.hsk_read_seq = 0;
   session->internals.dtls.hsk_write_seq = 0;
-  session->internals.dtls.handshake_start_time = gnutls_time(0);
+  gettime(&session->internals.dtls.handshake_start_time);
 }
 
 void
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 99532d3..c168152 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -66,7 +66,8 @@ ctests = mini-deflate simple gc set_pkcs12_cred certder 
certuniqueid  \
         crq_apis init_roundtrip pkcs12_s2k_pem dn2 mini-eagain         \
         nul-in-x509-names x509_altname pkcs12_encode mini-x509         \
         mini-x509-rehandshake rng-fork mini-eagain-dtls mini-loss      \
-        x509cert x509cert-tl infoaccess rsa-encrypt-decrypt
+        x509cert x509cert-tl infoaccess rsa-encrypt-decrypt \
+        mini-loss-time
 
 if ENABLE_OCSP
 ctests += ocsp
diff --git a/tests/mini-loss.c b/tests/mini-loss-time.c
similarity index 67%
copy from tests/mini-loss.c
copy to tests/mini-loss-time.c
index be8b8fe..f1aa3e4 100644
--- a/tests/mini-loss.c
+++ b/tests/mini-loss-time.c
@@ -27,16 +27,25 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
+#if defined(_WIN32)
+
+int main()
+{
+  exit(77);
+}
+
+#else
+
 #include <sys/types.h>
 #include <netinet/in.h>
 #include <sys/socket.h>
-#if !defined(_WIN32)
 #include <sys/wait.h>
 #include <arpa/inet.h>
-#endif
 #include <unistd.h>
 #include <gnutls/gnutls.h>
 #include <gnutls/dtls.h>
+#include <signal.h>
 
 #include "utils.h"
 
@@ -87,9 +96,6 @@ client_log_func (int level, const char *str)
 /* A very basic TLS client, with anonymous authentication.
  */
 
-#define MAX_BUF 1024
-#define MSG "Hello TLS"
-
 static int counter;
 static int packet_to_lose;
 gnutls_session_t session;
@@ -107,6 +113,9 @@ int fd = (long int)tr;
         fprintf(stderr, "Discarding packet %d: ", counter);
         print_type(data, len);
       }
+      
+    packet_to_lose = 1;
+    counter = 0;
     return len;
   }
   return send(fd, data, len, 0);
@@ -115,8 +124,7 @@ int fd = (long int)tr;
 static void
 client (int fd, int packet)
 {
-  int ret, ii;
-  char buffer[MAX_BUF + 1];
+  int ret;
   gnutls_anon_client_credentials_t anoncred;
   /* Need to enable anonymous KX specifically. */
 
@@ -158,6 +166,7 @@ client (int fd, int packet)
 
   if (ret < 0)
     {
+      if (ret == GNUTLS_E_TIMEDOUT) return;
       fail ("client: Handshake failed\n");
       gnutls_perror (ret);
       exit(1);
@@ -168,52 +177,7 @@ client (int fd, int packet)
         success ("client: Handshake was completed\n");
     }
 
-  if (debug)
-    success ("client: TLS version is: %s\n",
-             gnutls_protocol_get_name (gnutls_protocol_get_version
-                                       (session)));
-
-  do {
-    ret = gnutls_record_send (session, MSG, strlen (MSG));
-  } while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
-
-  do {
-    ret = gnutls_record_recv (session, buffer, MAX_BUF);
-  } while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
-
-  if (ret == 0)
-    {
-      if (debug)
-        success ("client: Peer has closed the TLS connection\n");
-      goto end;
-    }
-  else if (ret < 0)
-    {
-      fail ("client: Error: %s\n", gnutls_strerror (ret));
-      exit(1);
-    }
-
-  if (debug)
-    {
-      printf ("- Received %d bytes: ", ret);
-      for (ii = 0; ii < ret; ii++)
-        {
-          fputc (buffer[ii], stdout);
-        }
-      fputs ("\n", stdout);
-    }
-
-  gnutls_bye (session, GNUTLS_SHUT_RDWR);
-
-end:
-
-  close (fd);
-
-  gnutls_deinit (session);
-
-  gnutls_anon_free_client_credentials (anoncred);
-
-  gnutls_global_deinit ();
+  exit(1);
 }
 
 
@@ -239,20 +203,10 @@ initialize_tls_session (void)
   return session;
 }
 
-static void terminate(void)
-{
-int status;
-
-  kill(child, SIGTERM);
-  wait(&status);
-  exit(1);
-}
-
 static void
 server (int fd, int packet)
 {
 int ret;
-char buffer[MAX_BUF + 1];
   /* this must be called once in the program
    */
   gnutls_global_init ();
@@ -282,61 +236,8 @@ char buffer[MAX_BUF + 1];
     {
       close (fd);
       gnutls_deinit (session);
-      fail ("server: Handshake has failed (%s)\n\n", gnutls_strerror (ret));
-      terminate();
-    }
-  if (debug)
-    success ("server: Handshake was completed\n");
-
-  if (debug)
-    success ("server: TLS version is: %s\n",
-             gnutls_protocol_get_name (gnutls_protocol_get_version
-                                       (session)));
-
-  /* see the Getting peer's information example */
-  /* print_info(session); */
-
-  for (;;)
-    {
-      memset (buffer, 0, MAX_BUF + 1);
-      
-      do {
-        ret = gnutls_record_recv (session, buffer, MAX_BUF);
-      } while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
-
-      if (ret == 0)
-        {
-          if (debug)
-            success ("server: Peer has closed the GnuTLS connection\n");
-          break;
-        }
-      else if (ret < 0)
-        {
-          fail ("server: Received corrupted data(%d). Closing...\n", ret);
-          terminate();
-        }
-      else if (ret > 0)
-        {
-          /* echo data back to the client
-           */
-          do {
-            ret = gnutls_record_send (session, buffer, strlen (buffer));
-          } while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
-        }
+      return;
     }
-  /* do not wait for the peer to close the connection.
-   */
-  gnutls_bye (session, GNUTLS_SHUT_WR);
-
-  close (fd);
-  gnutls_deinit (session);
-
-  gnutls_anon_free_server_credentials (anoncred);
-
-  gnutls_global_deinit ();
-
-  if (debug)
-    success ("server: finished\n");
 }
 
 static void start (int server_packet, int client_packet)
@@ -365,12 +266,8 @@ static void start (int server_packet, int client_packet)
 
   if (child)
     {
-      int status;
       /* parent */
       server (fd[0], server_packet);
-      wait (&status);
-      if (WEXITSTATUS(status) != 0)
-        fail("Child died with status %d\n", WEXITSTATUS(status));
     }
   else 
     {
@@ -379,17 +276,31 @@ static void start (int server_packet, int client_packet)
     }
 }
 
+static void ch_handler(int sig)
+{
+int status;
+  wait(&status);
+  if (WEXITSTATUS(status) != 0)
+    fail("Child died with status %d\n", WEXITSTATUS(status));
+  return;
+}
+
 void
 doit (void)
 {
-  start(-1, 1);
-  start(-1, 2);
-  start(-1, 3);
-  start(-1, 4);
+time_t tstart, tstop;
 
-  start(1, -1);
+  signal(SIGCHLD, ch_handler);
+
+  tstart = time(0);
   start(2, -1);
-  start(3, -1);
-  start(4, -1);
-  start(5, -1);
+
+  tstop = time(0);
+  
+  tstop = tstop - tstart;
+
+  if (!(tstop < 70 && tstop > 55))
+    fail("Time difference: %u\n", (unsigned)tstop);
 }
+
+#endif /* _WIN32 */
diff --git a/tests/mini-loss.c b/tests/mini-loss.c
index be8b8fe..a541c29 100644
--- a/tests/mini-loss.c
+++ b/tests/mini-loss.c
@@ -26,14 +26,22 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+
+#if defined(_WIN32)
+
+int main()
+{
+  exit(77);
+}
+
+#else
+
 #include <string.h>
 #include <sys/types.h>
 #include <netinet/in.h>
 #include <sys/socket.h>
-#if !defined(_WIN32)
 #include <sys/wait.h>
 #include <arpa/inet.h>
-#endif
 #include <unistd.h>
 #include <gnutls/gnutls.h>
 #include <gnutls/dtls.h>
@@ -393,3 +401,5 @@ doit (void)
   start(4, -1);
   start(5, -1);
 }
+
+#endif /* _WIN32 */


hooks/post-receive
-- 
GNU gnutls



reply via email to

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