Skip to content

Commit b481eca

Browse files
committed
chore: allow vision with vless encryption
1 parent eb028b6 commit b481eca

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

adapter/outbound/vless.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package outbound
33
import (
44
"context"
55
"crypto/tls"
6-
"errors"
76
"fmt"
87
"net"
98
"net/http"
@@ -457,11 +456,6 @@ func NewVless(option VlessOption) (*Vless, error) {
457456
if err != nil {
458457
return nil, err
459458
}
460-
if v.encryption != nil {
461-
if option.Flow != "" {
462-
return nil, errors.New(`vless "encryption" doesn't support "flow" yet`)
463-
}
464-
}
465459

466460
v.realityConfig, err = v.option.RealityOpts.Parse()
467461
if err != nil {

listener/inbound/vless_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ func TestInboundVless_Encryption(t *testing.T) {
102102
Encryption: "8min-vless-mlkem768client-" + clientBase64,
103103
}
104104
testInboundVless(t, inboundOptions, outboundOptions)
105+
t.Run("xtls-rprx-vision", func(t *testing.T) {
106+
outboundOptions := outboundOptions
107+
outboundOptions.Flow = "xtls-rprx-vision"
108+
testInboundVless(t, inboundOptions, outboundOptions)
109+
})
105110
})
106111
t.Run("-xored-", func(t *testing.T) {
107112
inboundOptions := inbound.VlessOption{

listener/sing_vless/server.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ func init() {
4343
}
4444
return true, tlsConn.NetConn(), reflect.TypeOf(tlsConn.Conn).Elem(), unsafe.Pointer(tlsConn.Conn)
4545
})
46+
47+
vless.RegisterTLS(func(conn net.Conn) (loaded bool, netConn net.Conn, reflectType reflect.Type, reflectPointer unsafe.Pointer) {
48+
tlsConn, loaded := common.Cast[*encryption.ClientConn](conn)
49+
if !loaded {
50+
return
51+
}
52+
return true, tlsConn.Conn, reflect.TypeOf(tlsConn).Elem(), unsafe.Pointer(tlsConn)
53+
})
54+
55+
vless.RegisterTLS(func(conn net.Conn) (loaded bool, netConn net.Conn, reflectType reflect.Type, reflectPointer unsafe.Pointer) {
56+
tlsConn, loaded := common.Cast[*encryption.ServerConn](conn)
57+
if !loaded {
58+
return
59+
}
60+
return true, tlsConn.Conn, reflect.TypeOf(tlsConn).Elem(), unsafe.Pointer(tlsConn)
61+
})
4662
}
4763

4864
type Listener struct {

transport/vless/vision/vision.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
N "github.com/metacubex/mihomo/common/net"
1414
tlsC "github.com/metacubex/mihomo/component/tls"
15+
"github.com/metacubex/mihomo/transport/vless/encryption"
1516

1617
"github.com/gofrs/uuid/v5"
1718
"github.com/metacubex/sing/common"
@@ -58,6 +59,18 @@ func NewConn(conn connWithUpstream, userUUID *uuid.UUID) (*Conn, error) {
5859
t = reflect.TypeOf(underlying.Conn).Elem()
5960
//log.Debugln("t:%v", t)
6061
p = unsafe.Pointer(underlying.Conn)
62+
case *encryption.ClientConn:
63+
//log.Debugln("type *encryption.ClientConn")
64+
c.Conn = underlying.Conn
65+
c.tlsConn = underlying
66+
t = reflect.TypeOf(underlying).Elem()
67+
p = unsafe.Pointer(underlying)
68+
case *encryption.ServerConn:
69+
//log.Debugln("type *encryption.ServerConn")
70+
c.Conn = underlying.Conn
71+
c.tlsConn = underlying
72+
t = reflect.TypeOf(underlying).Elem()
73+
p = unsafe.Pointer(underlying)
6174
default:
6275
return nil, fmt.Errorf(`failed to use vision, maybe "security" is not "tls" or "utls"`)
6376
}

0 commit comments

Comments
 (0)