- Simplified ping mechanism.
authorGuus Sliepen <guus@tinc-vpn.org>
Sat, 4 Nov 2000 20:44:28 +0000 (20:44 +0000)
committerGuus Sliepen <guus@tinc-vpn.org>
Sat, 4 Nov 2000 20:44:28 +0000 (20:44 +0000)
src/connlist.h
src/meta.c
src/net.c
src/protocol.c

index 0b9fa6b..2d66289 100644 (file)
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: connlist.h,v 1.1.2.11 2000/11/04 11:49:57 guus Exp $
+    $Id: connlist.h,v 1.1.2.12 2000/11/04 20:44:26 guus Exp $
 */
 
 #ifndef __TINC_CONNLIST_H__
 */
 
 #ifndef __TINC_CONNLIST_H__
@@ -31,7 +31,6 @@
 
 typedef struct status_bits_t {
   int pinged:1;                    /* sent ping */
 
 typedef struct status_bits_t {
   int pinged:1;                    /* sent ping */
-  int got_pong:1;                  /* received pong */
   int meta:1;                      /* meta connection exists */
   int active:1;                    /* 1 if active.. */
   int outgoing:1;                  /* I myself asked for this conn */
   int meta:1;                      /* meta connection exists */
   int active:1;                    /* 1 if active.. */
   int outgoing:1;                  /* I myself asked for this conn */
@@ -82,7 +81,6 @@ typedef struct conn_list_t {
   int allow_request;               /* defined if there's only one request possible */
 
   time_t last_ping_time;           /* last time we saw some activity from the other end */  
   int allow_request;               /* defined if there's only one request possible */
 
   time_t last_ping_time;           /* last time we saw some activity from the other end */  
-  int want_ping;                   /* 0 if there's no need to check for activity. Shouldn't this go into status? (GS) */
 
   char *mychallenge;               /* challenge we received from him */
   char *hischallenge;              /* challenge we sent to him */
 
   char *mychallenge;               /* challenge we received from him */
   char *hischallenge;              /* challenge we sent to him */
index 6b2a8e2..da09062 100644 (file)
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: meta.c,v 1.1.2.8 2000/10/29 22:55:14 guus Exp $
+    $Id: meta.c,v 1.1.2.9 2000/11/04 20:44:26 guus Exp $
 */
 
 #include "config.h"
 */
 
 #include "config.h"
@@ -169,7 +169,6 @@ cp
     }
 
   cl->last_ping_time = time(NULL);
     }
 
   cl->last_ping_time = time(NULL);
-  cl->want_ping = 0;
 cp  
   return 0;
 }
 cp  
   return 0;
 }
index 6e4fa66..dd692e8 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: net.c,v 1.35.4.65 2000/11/04 17:09:10 guus Exp $
+    $Id: net.c,v 1.35.4.66 2000/11/04 20:44:26 guus Exp $
 */
 
 #include "config.h"
 */
 
 #include "config.h"
@@ -160,8 +160,6 @@ cp
 
   total_socket_out += outlen;
 
 
   total_socket_out += outlen;
 
-  cl->want_ping = 1;
-
   if((send(cl->socket, (char *) &(outpkt.len), outlen, 0)) < 0)
     {
       syslog(LOG_ERR, _("Error sending packet to %s (%s): %m"),
   if((send(cl->socket, (char *) &(outpkt.len), outlen, 0)) < 0)
     {
       syslog(LOG_ERR, _("Error sending packet to %s (%s): %m"),
@@ -706,7 +704,6 @@ cp
   ncn->buffer = xmalloc(MAXBUFSIZE);
   ncn->buflen = 0;
   ncn->last_ping_time = time(NULL);
   ncn->buffer = xmalloc(MAXBUFSIZE);
   ncn->buflen = 0;
   ncn->last_ping_time = time(NULL);
-  ncn->want_ping = 0;
 
   conn_list_add(ncn);
 
 
   conn_list_add(ncn);
 
@@ -889,9 +886,15 @@ int setup_network_connections(void)
   config_t const *cfg;
 cp
   if((cfg = get_config_val(config, pingtimeout)) == NULL)
   config_t const *cfg;
 cp
   if((cfg = get_config_val(config, pingtimeout)) == NULL)
-    timeout = 5;
+    timeout = 60;
   else
   else
-    timeout = cfg->data.val;
+    {
+      timeout = cfg->data.val;
+      if(timeout < 1)
+        {
+          timeout = 86400;
+        }
+     }
 
   if(setup_tap_fd() < 0)
     return -1;
 
   if(setup_tap_fd() < 0)
     return -1;
@@ -1027,7 +1030,6 @@ cp
   p->buffer = xmalloc(MAXBUFSIZE);
   p->buflen = 0;
   p->last_ping_time = time(NULL);
   p->buffer = xmalloc(MAXBUFSIZE);
   p->buflen = 0;
   p->last_ping_time = time(NULL);
-  p->want_ping = 0;
   
   if(debug_lvl >= DEBUG_CONNECTIONS)
     syslog(LOG_NOTICE, _("Connection from %s port %d"),
   
   if(debug_lvl >= DEBUG_CONNECTIONS)
     syslog(LOG_NOTICE, _("Connection from %s port %d"),
@@ -1181,7 +1183,7 @@ cp
        {
           if(p->last_ping_time + timeout < now)
             {
        {
           if(p->last_ping_time + timeout < now)
             {
-              if(p->status.pinged && !p->status.got_pong)
+              if(p->status.pinged)
                 {
                   if(debug_lvl >= DEBUG_PROTOCOL)
                    syslog(LOG_INFO, _("%s (%s) didn't respond to PING"),
                 {
                   if(debug_lvl >= DEBUG_PROTOCOL)
                    syslog(LOG_INFO, _("%s (%s) didn't respond to PING"),
@@ -1189,12 +1191,9 @@ cp
                  p->status.timeout = 1;
                  terminate_connection(p);
                 }
                  p->status.timeout = 1;
                  terminate_connection(p);
                 }
-              else if(p->want_ping)
+              else
                 {
                   send_ping(p);
                 {
                   send_ping(p);
-                  p->last_ping_time = now;
-                  p->status.pinged = 1;
-                  p->status.got_pong = 0;
                 }
             }
        }
                 }
             }
        }
index 8d03cc0..0728ea1 100644 (file)
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: protocol.c,v 1.28.4.56 2000/11/04 16:54:21 guus Exp $
+    $Id: protocol.c,v 1.28.4.57 2000/11/04 20:44:28 guus Exp $
 */
 
 #include "config.h"
 */
 
 #include "config.h"
@@ -1037,7 +1037,9 @@ cp
 
 int send_ping(conn_list_t *cl)
 {
 
 int send_ping(conn_list_t *cl)
 {
+cp
   cl->status.pinged = 1;
   cl->status.pinged = 1;
+  cl->last_ping_time = time(NULL);
 cp
   return send_request(cl, "%d", PING);
 }
 cp
   return send_request(cl, "%d", PING);
 }
@@ -1057,7 +1059,7 @@ cp
 int pong_h(conn_list_t *cl)
 {
 cp
 int pong_h(conn_list_t *cl)
 {
 cp
-  cl->status.got_pong = 1;
+  cl->status.pinged = 0;
 cp
   return 0;
 }
 cp
   return 0;
 }