From d3fea909e98c0645aa73cfc60f52cb9038e3ebfa Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Thu, 30 May 2024 10:39:17 +0800 Subject: [PATCH] chore: remove tfo windows support Golang officially decided not to open `internal/poll.execIO` to third-party libraries after 1.23 was released, so we can only choose to remove tfo support on the Windows platform. --- adapter/inbound/listen.go | 14 +------------- adapter/inbound/listen_unix.go | 23 +++++++++++++++++++++++ adapter/inbound/listen_windows.go | 15 +++++++++++++++ component/dialer/tfo.go | 17 ----------------- component/dialer/tfo_unix.go | 25 +++++++++++++++++++++++++ component/dialer/tfo_windows.go | 15 ++++++++------- 6 files changed, 72 insertions(+), 37 deletions(-) create mode 100644 adapter/inbound/listen_unix.go create mode 100644 adapter/inbound/listen_windows.go create mode 100644 component/dialer/tfo_unix.go diff --git a/adapter/inbound/listen.go b/adapter/inbound/listen.go index 18dc1bc242..edbccea70a 100644 --- a/adapter/inbound/listen.go +++ b/adapter/inbound/listen.go @@ -3,22 +3,10 @@ package inbound import ( "context" "net" - - "github.com/metacubex/tfo-go" -) - -var ( - lc = tfo.ListenConfig{ - DisableTFO: true, - } ) -func SetTfo(open bool) { - lc.DisableTFO = !open -} - func SetMPTCP(open bool) { - setMultiPathTCP(&lc.ListenConfig, open) + setMultiPathTCP(getListenConfig(), open) } func ListenContext(ctx context.Context, network, address string) (net.Listener, error) { diff --git a/adapter/inbound/listen_unix.go b/adapter/inbound/listen_unix.go new file mode 100644 index 0000000000..bb78adb222 --- /dev/null +++ b/adapter/inbound/listen_unix.go @@ -0,0 +1,23 @@ +//go:build unix + +package inbound + +import ( + "net" + + "github.com/metacubex/tfo-go" +) + +var ( + lc = tfo.ListenConfig{ + DisableTFO: true, + } +) + +func SetTfo(open bool) { + lc.DisableTFO = !open +} + +func getListenConfig() *net.ListenConfig { + return &lc.ListenConfig +} diff --git a/adapter/inbound/listen_windows.go b/adapter/inbound/listen_windows.go new file mode 100644 index 0000000000..a4223e2b58 --- /dev/null +++ b/adapter/inbound/listen_windows.go @@ -0,0 +1,15 @@ +package inbound + +import ( + "net" +) + +var ( + lc = net.ListenConfig{} +) + +func SetTfo(open bool) {} + +func getListenConfig() *net.ListenConfig { + return &lc +} diff --git a/component/dialer/tfo.go b/component/dialer/tfo.go index 76fe94d021..bc32b38a74 100644 --- a/component/dialer/tfo.go +++ b/component/dialer/tfo.go @@ -5,12 +5,8 @@ import ( "io" "net" "time" - - "github.com/metacubex/tfo-go" ) -var DisableTFO = false - type tfoConn struct { net.Conn closed bool @@ -124,16 +120,3 @@ func (c *tfoConn) ReaderReplaceable() bool { func (c *tfoConn) WriterReplaceable() bool { return c.Conn != nil } - -func dialTFO(ctx context.Context, netDialer net.Dialer, network, address string) (net.Conn, error) { - ctx, cancel := context.WithTimeout(context.Background(), DefaultTCPTimeout) - dialer := tfo.Dialer{Dialer: netDialer, DisableTFO: false} - return &tfoConn{ - dialed: make(chan bool, 1), - cancel: cancel, - ctx: ctx, - dialFn: func(ctx context.Context, earlyData []byte) (net.Conn, error) { - return dialer.DialContext(ctx, network, address, earlyData) - }, - }, nil -} diff --git a/component/dialer/tfo_unix.go b/component/dialer/tfo_unix.go new file mode 100644 index 0000000000..b8908849e8 --- /dev/null +++ b/component/dialer/tfo_unix.go @@ -0,0 +1,25 @@ +//go:build unix + +package dialer + +import ( + "context" + "net" + + "github.com/metacubex/tfo-go" +) + +const DisableTFO = false + +func dialTFO(ctx context.Context, netDialer net.Dialer, network, address string) (net.Conn, error) { + ctx, cancel := context.WithTimeout(context.Background(), DefaultTCPTimeout) + dialer := tfo.Dialer{Dialer: netDialer, DisableTFO: false} + return &tfoConn{ + dialed: make(chan bool, 1), + cancel: cancel, + ctx: ctx, + dialFn: func(ctx context.Context, earlyData []byte) (net.Conn, error) { + return dialer.DialContext(ctx, network, address, earlyData) + }, + }, nil +} diff --git a/component/dialer/tfo_windows.go b/component/dialer/tfo_windows.go index 632661186c..f1dddcf44e 100644 --- a/component/dialer/tfo_windows.go +++ b/component/dialer/tfo_windows.go @@ -1,11 +1,12 @@ package dialer -import "github.com/metacubex/mihomo/constant/features" +import ( + "context" + "net" +) -func init() { - // According to MSDN, this option is available since Windows 10, 1607 - // https://msdn.microsoft.com/en-us/library/windows/desktop/ms738596(v=vs.85).aspx - if features.WindowsMajorVersion < 10 || (features.WindowsMajorVersion == 10 && features.WindowsBuildNumber < 14393) { - DisableTFO = true - } +const DisableTFO = true + +func dialTFO(ctx context.Context, netDialer net.Dialer, network, address string) (net.Conn, error) { + return netDialer.DialContext(ctx, network, address) }