Skip to content

Commit

Permalink
fix: tfo not working with smux/yamux
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Jan 24, 2024
1 parent 1025101 commit 9bd70e1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions component/dialer/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import (
"github.com/metacubex/mihomo/constant/features"
)

const (
DefaultTCPTimeout = 5 * time.Second
DefaultUDPTimeout = DefaultTCPTimeout
)

type dialFunc func(ctx context.Context, network string, ips []netip.Addr, port string, opt *option) (net.Conn, error)

var (
Expand Down
9 changes: 5 additions & 4 deletions component/dialer/tfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package dialer

import (
"context"
"github.com/sagernet/tfo-go"
"io"
"net"
"time"

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

type tfoConn struct {
Expand Down Expand Up @@ -66,14 +67,14 @@ func (c *tfoConn) Close() error {

func (c *tfoConn) LocalAddr() net.Addr {
if c.Conn == nil {
return nil
return &net.TCPAddr{}
}
return c.Conn.LocalAddr()
}

func (c *tfoConn) RemoteAddr() net.Addr {
if c.Conn == nil {
return nil
return &net.TCPAddr{}
}
return c.Conn.RemoteAddr()
}
Expand Down Expand Up @@ -123,7 +124,7 @@ func (c *tfoConn) WriterReplaceable() bool {
}

func dialTFO(ctx context.Context, netDialer net.Dialer, network, address string) (net.Conn, error) {
ctx, cancel := context.WithCancel(ctx)
ctx, cancel := context.WithTimeout(context.Background(), DefaultTCPTimeout)
dialer := tfo.Dialer{Dialer: netDialer, DisableTFO: false}
return &tfoConn{
dialed: make(chan bool, 1),
Expand Down
4 changes: 2 additions & 2 deletions constant/adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const (
)

const (
DefaultTCPTimeout = 5 * time.Second
DefaultTCPTimeout = dialer.DefaultTCPTimeout
DefaultUDPTimeout = dialer.DefaultUDPTimeout
DefaultDropTime = 12 * DefaultTCPTimeout
DefaultUDPTimeout = DefaultTCPTimeout
DefaultTLSTimeout = DefaultTCPTimeout
DefaultTestURL = "https://www.gstatic.com/generate_204"
)
Expand Down

0 comments on commit 9bd70e1

Please sign in to comment.