Skip to content

Commit

Permalink
chore: remove tfo windows support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wwqgtxx committed May 30, 2024
1 parent 7eb70ae commit d3fea90
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 37 deletions.
14 changes: 1 addition & 13 deletions adapter/inbound/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 23 additions & 0 deletions adapter/inbound/listen_unix.go
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 15 additions & 0 deletions adapter/inbound/listen_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package inbound

import (
"net"
)

var (
lc = net.ListenConfig{}
)

func SetTfo(open bool) {}

func getListenConfig() *net.ListenConfig {
return &lc
}
17 changes: 0 additions & 17 deletions component/dialer/tfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ import (
"io"
"net"
"time"

"github.com/metacubex/tfo-go"
)

var DisableTFO = false

type tfoConn struct {
net.Conn
closed bool
Expand Down Expand Up @@ -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
}
25 changes: 25 additions & 0 deletions component/dialer/tfo_unix.go
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 8 additions & 7 deletions component/dialer/tfo_windows.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit d3fea90

Please sign in to comment.