Skip to content

Commit

Permalink
feat: add mptcp for all proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Aug 9, 2023
1 parent e2e0fd4 commit cc42d78
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 0 deletions.
8 changes: 8 additions & 0 deletions adapter/outbound/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Base struct {
udp bool
xudp bool
tfo bool
mpTcp bool
rmark int
id string
prefer C.DNSPrefer
Expand Down Expand Up @@ -143,11 +144,16 @@ func (b *Base) DialOptions(opts ...dialer.Option) []dialer.Option {
opts = append(opts, dialer.WithTFO(true))
}

if b.mpTcp {
opts = append(opts, dialer.WithMPTCP(true))
}

return opts
}

type BasicOption struct {
TFO bool `proxy:"tfo,omitempty" group:"tfo,omitempty"`
MPTCP bool `proxy:"mptcp,omitempty" group:"mptcp,omitempty"`
Interface string `proxy:"interface-name,omitempty" group:"interface-name,omitempty"`
RoutingMark int `proxy:"routing-mark,omitempty" group:"routing-mark,omitempty"`
IPVersion string `proxy:"ip-version,omitempty" group:"ip-version,omitempty"`
Expand All @@ -161,6 +167,7 @@ type BaseOption struct {
UDP bool
XUDP bool
TFO bool
MPTCP bool
Interface string
RoutingMark int
Prefer C.DNSPrefer
Expand All @@ -174,6 +181,7 @@ func NewBase(opt BaseOption) *Base {
udp: opt.UDP,
xudp: opt.XUDP,
tfo: opt.TFO,
mpTcp: opt.MPTCP,
iface: opt.Interface,
rmark: opt.RoutingMark,
prefer: opt.Prefer,
Expand Down
1 change: 1 addition & 0 deletions adapter/outbound/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func NewHttp(option HttpOption) (*Http, error) {
addr: net.JoinHostPort(option.Server, strconv.Itoa(option.Port)),
tp: C.Http,
tfo: option.TFO,
mpTcp: option.MPTCP,
iface: option.Interface,
rmark: option.RoutingMark,
prefer: C.NewDNSPrefer(option.IPVersion),
Expand Down
1 change: 1 addition & 0 deletions adapter/outbound/shadowsocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ func NewShadowSocks(option ShadowSocksOption) (*ShadowSocks, error) {
tp: C.Shadowsocks,
udp: option.UDP,
tfo: option.TFO,
mpTcp: option.MPTCP,
iface: option.Interface,
rmark: option.RoutingMark,
prefer: C.NewDNSPrefer(option.IPVersion),
Expand Down
1 change: 1 addition & 0 deletions adapter/outbound/shadowsocksr.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func NewShadowSocksR(option ShadowSocksROption) (*ShadowSocksR, error) {
tp: C.ShadowsocksR,
udp: option.UDP,
tfo: option.TFO,
mpTcp: option.MPTCP,
iface: option.Interface,
rmark: option.RoutingMark,
prefer: C.NewDNSPrefer(option.IPVersion),
Expand Down
1 change: 1 addition & 0 deletions adapter/outbound/snell.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func NewSnell(option SnellOption) (*Snell, error) {
tp: C.Snell,
udp: option.UDP,
tfo: option.TFO,
mpTcp: option.MPTCP,
iface: option.Interface,
rmark: option.RoutingMark,
prefer: C.NewDNSPrefer(option.IPVersion),
Expand Down
1 change: 1 addition & 0 deletions adapter/outbound/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func NewSocks5(option Socks5Option) (*Socks5, error) {
tp: C.Socks5,
udp: option.UDP,
tfo: option.TFO,
mpTcp: option.MPTCP,
iface: option.Interface,
rmark: option.RoutingMark,
prefer: C.NewDNSPrefer(option.IPVersion),
Expand Down
1 change: 1 addition & 0 deletions adapter/outbound/trojan.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func NewTrojan(option TrojanOption) (*Trojan, error) {
tp: C.Trojan,
udp: option.UDP,
tfo: option.TFO,
mpTcp: option.MPTCP,
iface: option.Interface,
rmark: option.RoutingMark,
prefer: C.NewDNSPrefer(option.IPVersion),
Expand Down
1 change: 1 addition & 0 deletions adapter/outbound/vless.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ func NewVless(option VlessOption) (*Vless, error) {
udp: option.UDP,
xudp: option.XUDP,
tfo: option.TFO,
mpTcp: option.MPTCP,
iface: option.Interface,
rmark: option.RoutingMark,
prefer: C.NewDNSPrefer(option.IPVersion),
Expand Down
1 change: 1 addition & 0 deletions adapter/outbound/vmess.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ func NewVmess(option VmessOption) (*Vmess, error) {
udp: option.UDP,
xudp: option.XUDP,
tfo: option.TFO,
mpTcp: option.MPTCP,
iface: option.Interface,
rmark: option.RoutingMark,
prefer: C.NewDNSPrefer(option.IPVersion),
Expand Down
3 changes: 3 additions & 0 deletions component/dialer/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func dialContext(ctx context.Context, network string, destination netip.Addr, po
if opt.routingMark != 0 {
bindMarkToDialer(opt.routingMark, dialer, network, destination)
}
if opt.mpTcp {
setMultiPathTCP(dialer)
}
if opt.tfo {
return dialTFO(ctx, *dialer, network, address)
}
Expand Down
12 changes: 12 additions & 0 deletions component/dialer/mptcp_go120.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !go1.21

package dialer

import (
"net"
)

const multipathTCPAvailable = false

func setMultiPathTCP(dialer *net.Dialer) {
}
11 changes: 11 additions & 0 deletions component/dialer/mptcp_go121.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build go1.21

package dialer

import "net"

const multipathTCPAvailable = true

func setMultiPathTCP(dialer *net.Dialer) {
dialer.SetMultipathTCP(true)
}
7 changes: 7 additions & 0 deletions component/dialer/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type option struct {
network int
prefer int
tfo bool
mpTcp bool
resolver resolver.Resolver
netDialer NetDialer
}
Expand Down Expand Up @@ -83,6 +84,12 @@ func WithTFO(tfo bool) Option {
}
}

func WithMPTCP(mpTcp bool) Option {
return func(opt *option) {
opt.mpTcp = mpTcp
}
}

func WithNetDialer(netDialer NetDialer) Option {
return func(opt *option) {
opt.netDialer = netDialer
Expand Down

0 comments on commit cc42d78

Please sign in to comment.