Add BlockingTCP option, useful when using TCPOnly on slow or congested links.
authorGuus Sliepen <guus@tinc-vpn.org>
Wed, 10 Nov 2004 21:56:31 +0000 (21:56 +0000)
committerGuus Sliepen <guus@tinc-vpn.org>
Wed, 10 Nov 2004 21:56:31 +0000 (21:56 +0000)
doc/tinc.conf.5.in
src/net.h
src/net_setup.c
src/net_socket.c

index 9e2e270..1797aa7 100644 (file)
@@ -120,6 +120,13 @@ will by default listen on all of them for incoming connections.
 It is possible to bind only to a single interface with this variable.
 .Pp
 This option may not work on all platforms.
 It is possible to bind only to a single interface with this variable.
 .Pp
 This option may not work on all platforms.
+.It Va BlockingTCP Li = yes | no Po no Pc Bq experimental
+This options selects whether TCP connections, when established, should use blocking writes.
+When turned off, tinc will never block when a TCP connection becomes congested, but will have to terminate that connection instead.
+If turned on, tinc will not terminate connections but will block, thereby unable to process data to/from other connections.
+Turn this option on if you also use
+.Va TCPOnly
+and tinc terminates connections frequently.
 .It Va ConnectTo Li = Ar name
 Specifies which other tinc daemon to connect to on startup.
 Multiple
 .It Va ConnectTo Li = Ar name
 Specifies which other tinc daemon to connect to on startup.
 Multiple
index b5692ef..b82ca83 100644 (file)
--- a/src/net.h
+++ b/src/net.h
@@ -117,6 +117,7 @@ typedef struct outgoing_t {
 extern int maxtimeout;
 extern int seconds_till_retry;
 extern int addressfamily;
 extern int maxtimeout;
 extern int seconds_till_retry;
 extern int addressfamily;
+extern bool blockingtcp;
 
 extern listen_socket_t listen_socket[MAXSOCKETS];
 extern int listen_sockets;
 
 extern listen_socket_t listen_socket[MAXSOCKETS];
 extern int listen_sockets;
index 7896add..0c9f27c 100644 (file)
@@ -286,6 +286,8 @@ bool setup_myself(void)
        if(get_config_bool(lookup_config(myself->connection->config_tree, "TCPOnly"), &choice) && choice)
                myself->options |= OPTION_TCPONLY;
 
        if(get_config_bool(lookup_config(myself->connection->config_tree, "TCPOnly"), &choice) && choice)
                myself->options |= OPTION_TCPONLY;
 
+       get_config_bool(lookup_config(config_tree, "BlockingTCP"), &blockingtcp);
+
        if(get_config_bool(lookup_config(myself->connection->config_tree, "PMTUDiscovery"), &choice) && choice)
                myself->options |= OPTION_PMTU_DISCOVERY;
 
        if(get_config_bool(lookup_config(myself->connection->config_tree, "PMTUDiscovery"), &choice) && choice)
                myself->options |= OPTION_PMTU_DISCOVERY;
 
index efa0f55..9095d57 100644 (file)
@@ -41,6 +41,7 @@
 int addressfamily = AF_UNSPEC;
 int maxtimeout = 900;
 int seconds_till_retry = 5;
 int addressfamily = AF_UNSPEC;
 int maxtimeout = 900;
 int seconds_till_retry = 5;
+bool blockingtcp = false;
 
 listen_socket_t listen_socket[MAXSOCKETS];
 int listen_sockets;
 
 listen_socket_t listen_socket[MAXSOCKETS];
 int listen_sockets;
@@ -240,6 +241,16 @@ void finish_connecting(connection_t *c)
 
        ifdebug(CONNECTIONS) logger(LOG_INFO, _("Connected to %s (%s)"), c->name, c->hostname);
 
 
        ifdebug(CONNECTIONS) logger(LOG_INFO, _("Connected to %s (%s)"), c->name, c->hostname);
 
+#ifdef O_NONBLOCK
+       if(blockingtcp) {
+               int flags = fcntl(c->socket, F_GETFL);
+
+               if(fcntl(c->socket, F_SETFL, flags & ~O_NONBLOCK) < 0) {
+                       logger(LOG_ERR, _("fcntl for %s: %s"), c->hostname, strerror(errno));
+               }
+       }
+#endif
+
        c->last_ping_time = now;
 
        send_id(c);
        c->last_ping_time = now;
 
        send_id(c);
@@ -425,6 +436,16 @@ bool handle_new_meta_connection(int sock)
 
        ifdebug(CONNECTIONS) logger(LOG_NOTICE, _("Connection from %s"), c->hostname);
 
 
        ifdebug(CONNECTIONS) logger(LOG_NOTICE, _("Connection from %s"), c->hostname);
 
+#ifdef O_NONBLOCK
+       if(blockingtcp) {
+               int flags = fcntl(c->socket, F_GETFL);
+
+               if(fcntl(c->socket, F_SETFL, flags & ~O_NONBLOCK) < 0) {
+                       logger(LOG_ERR, _("fcntl for %s: %s"), c->hostname, strerror(errno));
+               }
+       }
+#endif
+
        connection_add(c);
 
        c->allow_request = ID;
        connection_add(c);
 
        c->allow_request = ID;