ss and vmess inbound add tfo

This commit is contained in:
zhudan 2022-11-14 12:24:37 +08:00 committed by metacubex
parent 9c8e39827f
commit 0eecd11fdc
4 changed files with 22 additions and 9 deletions

View file

@ -280,7 +280,7 @@ func ReCreateShadowSocks(shadowSocksConfig string, tcpIn chan<- C.ConnContext, u
return return
} }
listener, err := sing_shadowsocks.New(shadowSocksConfig, tcpIn, udpIn) listener, err := sing_shadowsocks.New(shadowSocksConfig, inboundTfo, tcpIn, udpIn)
if err != nil { if err != nil {
return return
} }
@ -320,7 +320,7 @@ func ReCreateVmess(vmessConfig string, tcpIn chan<- C.ConnContext, udpIn chan<-
return return
} }
listener, err := sing_vmess.New(vmessConfig, tcpIn, udpIn) listener, err := sing_vmess.New(vmessConfig, inboundTfo, tcpIn, udpIn)
if err != nil { if err != nil {
return return
} }

View file

@ -1,6 +1,8 @@
package shadowsocks package shadowsocks
import ( import (
"context"
"github.com/database64128/tfo-go/v2"
"net" "net"
"strings" "strings"
@ -21,7 +23,7 @@ type Listener struct {
var _listener *Listener var _listener *Listener
func New(config string, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.PacketAdapter) (*Listener, error) { func New(config string, inboundTfo bool, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.PacketAdapter) (*Listener, error) {
addr, cipher, password, err := ParseSSURL(config) addr, cipher, password, err := ParseSSURL(config)
if err != nil { if err != nil {
return nil, err return nil, err
@ -46,7 +48,10 @@ func New(config string, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.Packet
sl.udpListeners = append(sl.udpListeners, ul) sl.udpListeners = append(sl.udpListeners, ul)
//TCP //TCP
l, err := net.Listen("tcp", addr) lc := tfo.ListenConfig{
DisableTFO: !inboundTfo,
}
l, err := lc.Listen(context.Background(), "tcp", addr)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -3,6 +3,7 @@ package sing_shadowsocks
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/database64128/tfo-go/v2"
"net" "net"
"strings" "strings"
@ -32,7 +33,7 @@ type Listener struct {
var _listener *Listener var _listener *Listener
func New(config string, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.PacketAdapter) (C.AdvanceListener, error) { func New(config string, inboundTfo bool, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.PacketAdapter) (C.AdvanceListener, error) {
addr, cipher, password, err := embedSS.ParseSSURL(config) addr, cipher, password, err := embedSS.ParseSSURL(config)
if err != nil { if err != nil {
return nil, err return nil, err
@ -56,7 +57,7 @@ func New(config string, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.Packet
sl.service, err = shadowaead_2022.NewServiceWithPassword(cipher, password, udpTimeout, h) sl.service, err = shadowaead_2022.NewServiceWithPassword(cipher, password, udpTimeout, h)
default: default:
err = fmt.Errorf("shadowsocks: unsupported method: %s", cipher) err = fmt.Errorf("shadowsocks: unsupported method: %s", cipher)
return embedSS.New(config, tcpIn, udpIn) return embedSS.New(config, inboundTfo, tcpIn, udpIn)
} }
if err != nil { if err != nil {
return nil, err return nil, err
@ -100,7 +101,10 @@ func New(config string, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.Packet
}() }()
//TCP //TCP
l, err := net.Listen("tcp", addr) lc := tfo.ListenConfig{
DisableTFO: !inboundTfo,
}
l, err := lc.Listen(context.Background(), "tcp", addr)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -2,6 +2,7 @@ package sing_vmess
import ( import (
"context" "context"
"github.com/database64128/tfo-go/v2"
"net" "net"
"net/url" "net/url"
"strings" "strings"
@ -24,7 +25,7 @@ type Listener struct {
var _listener *Listener var _listener *Listener
func New(config string, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.PacketAdapter) (*Listener, error) { func New(config string, inboundTfo bool, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.PacketAdapter) (*Listener, error) {
addr, username, password, err := parseVmessURL(config) addr, username, password, err := parseVmessURL(config)
if err != nil { if err != nil {
return nil, err return nil, err
@ -54,7 +55,10 @@ func New(config string, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.Packet
addr := addr addr := addr
//TCP //TCP
l, err := net.Listen("tcp", addr) lc := tfo.ListenConfig{
DisableTFO: !inboundTfo,
}
l, err := lc.Listen(context.Background(), "tcp", addr)
if err != nil { if err != nil {
return nil, err return nil, err
} }