Skip to content

Commit a2da994

Browse files
committed
merge
2 parents 129fe9f + 9de9f1e commit a2da994

File tree

26 files changed

+223
-108
lines changed

26 files changed

+223
-108
lines changed

adapter/adapter.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,17 @@ func (p *Proxy) MarshalJSON() ([]byte, error) {
163163
mapping["alive"] = p.alive.Load()
164164
mapping["name"] = p.Name()
165165
mapping["udp"] = p.SupportUDP()
166-
mapping["xudp"] = p.SupportXUDP()
167-
mapping["tfo"] = p.SupportTFO()
168-
mapping["mptcp"] = p.SupportMPTCP()
169-
mapping["smux"] = p.SupportSMUX()
166+
mapping["uot"] = p.SupportUOT()
167+
168+
proxyInfo := p.ProxyInfo()
169+
mapping["xudp"] = proxyInfo.XUDP
170+
mapping["tfo"] = proxyInfo.TFO
171+
mapping["mptcp"] = proxyInfo.MPTCP
172+
mapping["smux"] = proxyInfo.SMUX
173+
mapping["interface"] = proxyInfo.Interface
174+
mapping["dialer-proxy"] = proxyInfo.DialerProxy
175+
mapping["routing-mark"] = proxyInfo.RoutingMark
176+
170177
return json.Marshal(mapping)
171178
}
172179

adapter/inbound/listen.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package inbound
22

33
import (
44
"context"
5+
"fmt"
56
"net"
7+
"net/netip"
68
"sync"
79

810
"github.com/metacubex/mihomo/component/keepalive"
@@ -42,6 +44,27 @@ func MPTCP() bool {
4244
}
4345

4446
func ListenContext(ctx context.Context, network, address string) (net.Listener, error) {
47+
switch network { // like net.Resolver.internetAddrList but filter domain to avoid call net.Resolver.lookupIPAddr
48+
case "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6", "ip", "ip4", "ip6":
49+
if host, port, err := net.SplitHostPort(address); err == nil {
50+
switch host {
51+
case "localhost":
52+
switch network {
53+
case "tcp6", "udp6", "ip6":
54+
address = net.JoinHostPort("::1", port)
55+
default:
56+
address = net.JoinHostPort("127.0.0.1", port)
57+
}
58+
case "": // internetAddrList can handle this special case
59+
break
60+
default:
61+
if _, err := netip.ParseAddr(host); err != nil { // not ip
62+
return nil, fmt.Errorf("invalid network address: %s", address)
63+
}
64+
}
65+
}
66+
}
67+
4568
mutex.RLock()
4669
defer mutex.RUnlock()
4770
return lc.Listen(ctx, network, address)

adapter/outbound/base.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,15 @@ func (b *Base) SupportUDP() bool {
8585
return b.udp
8686
}
8787

88-
// SupportXUDP implements C.ProxyAdapter
89-
func (b *Base) SupportXUDP() bool {
90-
return b.xudp
91-
}
92-
93-
// SupportTFO implements C.ProxyAdapter
94-
func (b *Base) SupportTFO() bool {
95-
return b.tfo
96-
}
97-
98-
// SupportMPTCP implements C.ProxyAdapter
99-
func (b *Base) SupportMPTCP() bool {
100-
return b.mpTcp
101-
}
102-
103-
// SupportSMUX implements C.ProxyAdapter
104-
func (b *Base) SupportSMUX() bool {
105-
return false
88+
// ProxyInfo implements C.ProxyAdapter
89+
func (b *Base) ProxyInfo() (info C.ProxyInfo) {
90+
info.XUDP = b.xudp
91+
info.TFO = b.tfo
92+
info.MPTCP = b.mpTcp
93+
info.SMUX = false
94+
info.Interface = b.iface
95+
info.RoutingMark = b.rmark
96+
return
10697
}
10798

10899
// IsL3Protocol implements C.ProxyAdapter

adapter/outbound/http.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ func (h *Http) SupportWithDialer() C.NetWork {
9292
return C.TCP
9393
}
9494

95+
// ProxyInfo implements C.ProxyAdapter
96+
func (h *Http) ProxyInfo() C.ProxyInfo {
97+
info := h.Base.ProxyInfo()
98+
info.DialerProxy = h.option.DialerProxy
99+
return info
100+
}
101+
95102
func (h *Http) shakeHand(metadata *C.Metadata, rw io.ReadWriter) error {
96103
addr := metadata.RemoteAddress()
97104
HeaderString := "CONNECT " + addr + " HTTP/1.1\r\n"

adapter/outbound/hysteria.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ func (h *Hysteria) genHdc(ctx context.Context, opts ...dialer.Option) utils.Pack
8787
}
8888
}
8989

90+
// ProxyInfo implements C.ProxyAdapter
91+
func (h *Hysteria) ProxyInfo() C.ProxyInfo {
92+
info := h.Base.ProxyInfo()
93+
info.DialerProxy = h.option.DialerProxy
94+
return info
95+
}
96+
9097
type HysteriaOption struct {
9198
BasicOption
9299
Name string `proxy:"name"`

adapter/outbound/hysteria2.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ func closeHysteria2(h *Hysteria2) {
9696
}
9797
}
9898

99+
// ProxyInfo implements C.ProxyAdapter
100+
func (h *Hysteria2) ProxyInfo() C.ProxyInfo {
101+
info := h.Base.ProxyInfo()
102+
info.DialerProxy = h.option.DialerProxy
103+
return info
104+
}
105+
99106
func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) {
100107
addr := net.JoinHostPort(option.Server, strconv.Itoa(option.Port))
101108
var salamanderPassword string

adapter/outbound/mieru.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ func (m *Mieru) DialContext(ctx context.Context, metadata *C.Metadata, _ ...dial
6262
return NewConn(c, m), nil
6363
}
6464

65+
// ProxyInfo implements C.ProxyAdapter
66+
func (m *Mieru) ProxyInfo() C.ProxyInfo {
67+
info := m.Base.ProxyInfo()
68+
info.DialerProxy = m.option.DialerProxy
69+
return info
70+
}
71+
6572
func NewMieru(option MieruOption) (*Mieru, error) {
6673
config, err := buildMieruClientConfig(option)
6774
if err != nil {

adapter/outbound/shadowsocks.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ func (ss *ShadowSocks) SupportWithDialer() C.NetWork {
197197
return C.ALLNet
198198
}
199199

200+
// ProxyInfo implements C.ProxyAdapter
201+
func (ss *ShadowSocks) ProxyInfo() C.ProxyInfo {
202+
info := ss.Base.ProxyInfo()
203+
info.DialerProxy = ss.option.DialerProxy
204+
return info
205+
}
206+
200207
// ListenPacketOnStreamConn implements C.ProxyAdapter
201208
func (ss *ShadowSocks) ListenPacketOnStreamConn(ctx context.Context, c net.Conn, metadata *C.Metadata) (_ C.PacketConn, err error) {
202209
if ss.option.UDPOverTCP {

adapter/outbound/shadowsocksr.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ func (ssr *ShadowSocksR) SupportWithDialer() C.NetWork {
122122
return C.ALLNet
123123
}
124124

125+
// ProxyInfo implements C.ProxyAdapter
126+
func (ssr *ShadowSocksR) ProxyInfo() C.ProxyInfo {
127+
info := ssr.Base.ProxyInfo()
128+
info.DialerProxy = ssr.option.DialerProxy
129+
return info
130+
}
131+
125132
func NewShadowSocksR(option ShadowSocksROption) (*ShadowSocksR, error) {
126133
// SSR protocol compatibility
127134
// https://github.com/metacubex/mihomo/pull/2056

adapter/outbound/singmux.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ func (s *SingMux) SupportUOT() bool {
9797
return true
9898
}
9999

100-
func (s *SingMux) SupportSMUX() bool {
101-
return true
100+
func (s *SingMux) ProxyInfo() C.ProxyInfo {
101+
info := s.ProxyAdapter.ProxyInfo()
102+
info.SMUX = true
103+
return info
102104
}
103105

104106
func closeSingMux(s *SingMux) {

adapter/outbound/snell.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ func (s *Snell) SupportUOT() bool {
141141
return true
142142
}
143143

144+
// ProxyInfo implements C.ProxyAdapter
145+
func (s *Snell) ProxyInfo() C.ProxyInfo {
146+
info := s.Base.ProxyInfo()
147+
info.DialerProxy = s.option.DialerProxy
148+
return info
149+
}
150+
144151
func NewSnell(option SnellOption) (*Snell, error) {
145152
addr := net.JoinHostPort(option.Server, strconv.Itoa(option.Port))
146153
psk := []byte(option.Psk)
@@ -204,7 +211,7 @@ func NewSnell(option SnellOption) (*Snell, error) {
204211
if err != nil {
205212
return nil, err
206213
}
207-
214+
208215
return streamConn(c, streamOption{psk, option.Version, addr, obfsOption}), nil
209216
})
210217
}

adapter/outbound/socks5.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ func (ss *Socks5) ListenPacketContext(ctx context.Context, metadata *C.Metadata,
171171
return newPacketConn(&socksPacketConn{PacketConn: pc, rAddr: bindUDPAddr, tcpConn: c}, ss), nil
172172
}
173173

174+
// ProxyInfo implements C.ProxyAdapter
175+
func (ss *Socks5) ProxyInfo() C.ProxyInfo {
176+
info := ss.Base.ProxyInfo()
177+
info.DialerProxy = ss.option.DialerProxy
178+
return info
179+
}
180+
174181
func NewSocks5(option Socks5Option) (*Socks5, error) {
175182
var tlsConfig *tls.Config
176183
if option.TLS {

adapter/outbound/ssh.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ func closeSsh(s *Ssh) {
121121
_ = s.client.Close()
122122
}
123123

124+
// ProxyInfo implements C.ProxyAdapter
125+
func (s *Ssh) ProxyInfo() C.ProxyInfo {
126+
info := s.Base.ProxyInfo()
127+
info.DialerProxy = s.option.DialerProxy
128+
return info
129+
}
130+
124131
func NewSsh(option SshOption) (*Ssh, error) {
125132
addr := net.JoinHostPort(option.Server, strconv.Itoa(option.Port))
126133

adapter/outbound/trojan.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@ func (t *Trojan) SupportUOT() bool {
244244
return true
245245
}
246246

247+
// ProxyInfo implements C.ProxyAdapter
248+
func (t *Trojan) ProxyInfo() C.ProxyInfo {
249+
info := t.Base.ProxyInfo()
250+
info.DialerProxy = t.option.DialerProxy
251+
return info
252+
}
253+
247254
func NewTrojan(option TrojanOption) (*Trojan, error) {
248255
addr := net.JoinHostPort(option.Server, strconv.Itoa(option.Port))
249256

adapter/outbound/tuic.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ func (t *Tuic) dialWithDialer(ctx context.Context, dialer C.Dialer) (transport *
146146
return
147147
}
148148

149+
// ProxyInfo implements C.ProxyAdapter
150+
func (t *Tuic) ProxyInfo() C.ProxyInfo {
151+
info := t.Base.ProxyInfo()
152+
info.DialerProxy = t.option.DialerProxy
153+
return info
154+
}
155+
149156
func NewTuic(option TuicOption) (*Tuic, error) {
150157
addr := net.JoinHostPort(option.Server, strconv.Itoa(option.Port))
151158
serverName := option.Server

adapter/outbound/vless.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,13 @@ func (v *Vless) SupportUOT() bool {
378378
return true
379379
}
380380

381+
// ProxyInfo implements C.ProxyAdapter
382+
func (v *Vless) ProxyInfo() C.ProxyInfo {
383+
info := v.Base.ProxyInfo()
384+
info.DialerProxy = v.option.DialerProxy
385+
return info
386+
}
387+
381388
func parseVlessAddr(metadata *C.Metadata, xudp bool) *vless.DstAddr {
382389
var addrType byte
383390
var addr []byte

adapter/outbound/vmess.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,13 @@ func (v *Vmess) SupportWithDialer() C.NetWork {
388388
return C.ALLNet
389389
}
390390

391+
// ProxyInfo implements C.ProxyAdapter
392+
func (v *Vmess) ProxyInfo() C.ProxyInfo {
393+
info := v.Base.ProxyInfo()
394+
info.DialerProxy = v.option.DialerProxy
395+
return info
396+
}
397+
391398
// ListenPacketOnStreamConn implements C.ProxyAdapter
392399
func (v *Vmess) ListenPacketOnStreamConn(ctx context.Context, c net.Conn, metadata *C.Metadata) (_ C.PacketConn, err error) {
393400
// vmess use stream-oriented udp with a special address, so we need a net.UDPAddr

adapter/outbound/wireguard.go

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -611,32 +611,11 @@ func (r *refProxyAdapter) SupportUDP() bool {
611611
return false
612612
}
613613

614-
func (r *refProxyAdapter) SupportXUDP() bool {
614+
func (r *refProxyAdapter) ProxyInfo() C.ProxyInfo {
615615
if r.proxyAdapter != nil {
616-
return r.proxyAdapter.SupportXUDP()
616+
return r.proxyAdapter.ProxyInfo()
617617
}
618-
return false
619-
}
620-
621-
func (r *refProxyAdapter) SupportTFO() bool {
622-
if r.proxyAdapter != nil {
623-
return r.proxyAdapter.SupportTFO()
624-
}
625-
return false
626-
}
627-
628-
func (r *refProxyAdapter) SupportMPTCP() bool {
629-
if r.proxyAdapter != nil {
630-
return r.proxyAdapter.SupportMPTCP()
631-
}
632-
return false
633-
}
634-
635-
func (r *refProxyAdapter) SupportSMUX() bool {
636-
if r.proxyAdapter != nil {
637-
return r.proxyAdapter.SupportSMUX()
638-
}
639-
return false
618+
return C.ProxyInfo{}
640619
}
641620

642621
func (r *refProxyAdapter) MarshalJSON() ([]byte, error) {

adapter/provider/parser.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type proxyProviderSchema struct {
6666
ExcludeFilter string `provider:"exclude-filter,omitempty"`
6767
ExcludeType string `provider:"exclude-type,omitempty"`
6868
DialerProxy string `provider:"dialer-proxy,omitempty"`
69+
SizeLimit int64 `provider:"size-limit,omitempty"`
6970

7071
HealthCheck healthCheckSchema `provider:"health-check,omitempty"`
7172
Override OverrideSchema `provider:"override,omitempty"`
@@ -111,7 +112,7 @@ func ParseProxyProvider(name string, mapping map[string]any) (types.ProxyProvide
111112
return nil, fmt.Errorf("%w: %s", errSubPath, path)
112113
}
113114
}
114-
vehicle = resource.NewHTTPVehicle(schema.URL, path, schema.Proxy, schema.Header, resource.DefaultHttpTimeout)
115+
vehicle = resource.NewHTTPVehicle(schema.URL, path, schema.Proxy, schema.Header, resource.DefaultHttpTimeout, schema.SizeLimit)
115116
default:
116117
return nil, fmt.Errorf("%w: %s", errVehicleType, schema.Type)
117118
}

0 commit comments

Comments
 (0)