Browse Source

Revert: cli tcp-wait-timeout option

This reverts commit 2c51a65685.
pull/248/head
xjasonlyu 2 years ago
parent
commit
20499c6432
  1. 4
      engine/engine.go
  2. 3
      engine/key.go
  3. 1
      main.go
  4. 14
      tunnel/tcp.go

4
engine/engine.go

@ -123,10 +123,6 @@ func general(k *Key) error {
log.Infof("[DIALER] set fwmark: %#x", k.Mark)
}
if k.TCPWaitTimeout > 0 {
tunnel.SetTCPWaitTimeout(k.TCPWaitTimeout)
}
if k.UDPTimeout > 0 {
if k.UDPTimeout < time.Second {
return errors.New("invalid udp timeout value")

3
engine/key.go

@ -13,8 +13,7 @@ type Key struct {
TCPModerateReceiveBuffer bool `yaml:"tcp-moderate-receive-buffer"`
TCPSendBufferSize string `yaml:"tcp-send-buffer-size"`
TCPReceiveBufferSize string `yaml:"tcp-receive-buffer-size"`
TCPWaitTimeout time.Duration `yaml:"tcp-wait-timeout"`
UDPTimeout time.Duration `yaml:"udp-timeout"`
TUNPreUp string `yaml:"tun-pre-up"`
TUNPostUp string `yaml:"tun-post-up"`
UDPTimeout time.Duration `yaml:"udp-timeout"`
}

1
main.go

@ -36,7 +36,6 @@ func init() {
flag.StringVar(&key.TCPSendBufferSize, "tcp-sndbuf", "", "Set TCP send buffer size for netstack")
flag.StringVar(&key.TCPReceiveBufferSize, "tcp-rcvbuf", "", "Set TCP receive buffer size for netstack")
flag.BoolVar(&key.TCPModerateReceiveBuffer, "tcp-auto-tuning", false, "Enable TCP receive buffer auto-tuning")
flag.DurationVar(&key.TCPWaitTimeout, "tcp-wait-timeout", 0, "Set timeout before closing each TCP connection")
flag.StringVar(&key.TUNPreUp, "tun-pre-up", "", "Execute a command before TUN device setup")
flag.StringVar(&key.TUNPostUp, "tun-post-up", "", "Execute a command after TUN device setup")
flag.BoolVar(&versionFlag, "version", false, "Show version and then quit")

14
tunnel/tcp.go

@ -15,12 +15,10 @@ import (
"github.com/xjasonlyu/tun2socks/v2/tunnel/statistic"
)
// _tcpWaitTimeout is the default timeout to wait after closing each TCP connection.
var _tcpWaitTimeout = 5 * time.Second
func SetTCPWaitTimeout(t time.Duration) {
_tcpWaitTimeout = t
}
const (
// tcpWaitTimeout implements a TCP half-close timeout.
tcpWaitTimeout = 60 * time.Second
)
func handleTCPConn(originConn adapter.TCPConn) {
defer originConn.Close()
@ -62,7 +60,7 @@ func pipe(origin, remote net.Conn) error {
if err := copyBuffer(remote, origin); err != nil {
leftErr = errors.Join(leftErr, err)
}
remote.SetReadDeadline(time.Now().Add(_tcpWaitTimeout))
remote.SetReadDeadline(time.Now().Add(tcpWaitTimeout))
}()
go func() {
@ -70,7 +68,7 @@ func pipe(origin, remote net.Conn) error {
if err := copyBuffer(origin, remote); err != nil {
rightErr = errors.Join(rightErr, err)
}
origin.SetReadDeadline(time.Now().Add(_tcpWaitTimeout))
origin.SetReadDeadline(time.Now().Add(tcpWaitTimeout))
}()
wg.Wait()

Loading…
Cancel
Save