Skip to content

Commit

Permalink
Feature: add basic support for the VLESS protocol (#2891)
Browse files Browse the repository at this point in the history
  • Loading branch information
crwnet authored Aug 24, 2023
1 parent 651a369 commit 8a4c46a
Showing 16 changed files with 893 additions and 25 deletions.
10 changes: 10 additions & 0 deletions adapter/outbound/vless.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package outbound

type (
Vless = Vmess
VlessOption = VmessOption
)

func NewVless(option VlessOption) (*Vless, error) {
return newVmess(option, true)
}
19 changes: 16 additions & 3 deletions adapter/outbound/vmess.go
Original file line number Diff line number Diff line change
@@ -39,8 +39,8 @@ type VmessOption struct {
Server string `proxy:"server"`
Port int `proxy:"port"`
UUID string `proxy:"uuid"`
AlterID int `proxy:"alterId"`
Cipher string `proxy:"cipher"`
AlterID int `proxy:"alterId,omitempty"`
Cipher string `proxy:"cipher,omitempty"`
UDP bool `proxy:"udp,omitempty"`
Network string `proxy:"network,omitempty"`
TLS bool `proxy:"tls,omitempty"`
@@ -264,14 +264,22 @@ func (v *Vmess) ListenPacketContext(ctx context.Context, metadata *C.Metadata, o
}

func NewVmess(option VmessOption) (*Vmess, error) {
return newVmess(option, false)
}

func newVmess(option VmessOption, isVless bool) (*Vmess, error) {
security := strings.ToLower(option.Cipher)
if security == "" {
security = "auto"
}
client, err := vmess.NewClient(vmess.Config{
UUID: option.UUID,
AlterID: uint16(option.AlterID),
Security: security,
HostName: option.Server,
Port: strconv.Itoa(option.Port),
IsAead: option.AlterID == 0,
IsVless: isVless,
})
if err != nil {
return nil, err
@@ -284,11 +292,16 @@ func NewVmess(option VmessOption) (*Vmess, error) {
}
}

tp := C.Vmess
if isVless {
tp = C.Vless
}

v := &Vmess{
Base: &Base{
name: option.Name,
addr: net.JoinHostPort(option.Server, strconv.Itoa(option.Port)),
tp: C.Vmess,
tp: tp,
udp: option.UDP,
iface: option.Interface,
rmark: option.RoutingMark,
8 changes: 7 additions & 1 deletion adapter/parser.go
Original file line number Diff line number Diff line change
@@ -48,6 +48,8 @@ func ParseProxy(mapping map[string]any) (C.Proxy, error) {
break
}
proxy = outbound.NewHttp(*httpOption)
case "vless":
fallthrough
case "vmess":
vmessOption := &outbound.VmessOption{
HTTPOpts: outbound.HTTPOptions{
@@ -59,7 +61,11 @@ func ParseProxy(mapping map[string]any) (C.Proxy, error) {
if err != nil {
break
}
proxy, err = outbound.NewVmess(*vmessOption)
if proxyType == "vless" {
proxy, err = outbound.NewVless(*vmessOption)
} else {
proxy, err = outbound.NewVmess(*vmessOption)
}
case "snell":
snellOption := &outbound.SnellOption{}
err = decoder.Decode(mapping, snellOption)
3 changes: 3 additions & 0 deletions constant/adapters.go
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ const (
Snell
Socks5
Http
Vless
Vmess
Trojan

@@ -140,6 +141,8 @@ func (at AdapterType) String() string {
return "Socks5"
case Http:
return "Http"
case Vless:
return "Vless"
case Vmess:
return "Vmess"
case Trojan:
40 changes: 40 additions & 0 deletions test/config/vless-grpc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"inbounds": [
{
"port": 10002,
"listen": "0.0.0.0",
"protocol": "vless",
"settings": {
"clients": [
{
"id": "b831381d-6324-4d53-ad4f-8cda48b30811"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "grpc",
"security": "tls",
"tlsSettings": {
"certificates": [
{
"certificateFile": "/etc/ssl/v2ray/fullchain.pem",
"keyFile": "/etc/ssl/v2ray/privkey.pem"
}
]
},
"grpcSettings": {
"serviceName": "example!"
}
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
],
"log": {
"loglevel": "debug"
}
}
55 changes: 55 additions & 0 deletions test/config/vless-http.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"inbounds": [
{
"port": 10002,
"listen": "0.0.0.0",
"protocol": "vless",
"settings": {
"clients": [
{
"id": "b831381d-6324-4d53-ad4f-8cda48b30811"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"tcpSettings": {
"header": {
"type": "http",
"response": {
"version": "1.1",
"status": "200",
"reason": "OK",
"headers": {
"Content-Type": [
"application/octet-stream",
"video/mpeg",
"application/x-msdownload",
"text/html",
"application/x-shockwave-flash"
],
"Transfer-Encoding": [
"chunked"
],
"Connection": [
"keep-alive"
],
"Pragma": "no-cache"
}
}
}
},
"security": "none"
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
],
"log": {
"loglevel": "debug"
}
}
43 changes: 43 additions & 0 deletions test/config/vless-http2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"inbounds": [
{
"port": 10002,
"listen": "0.0.0.0",
"protocol": "vless",
"settings": {
"clients": [
{
"id": "b831381d-6324-4d53-ad4f-8cda48b30811"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "http",
"security": "tls",
"tlsSettings": {
"certificates": [
{
"certificateFile": "/etc/ssl/v2ray/fullchain.pem",
"keyFile": "/etc/ssl/v2ray/privkey.pem"
}
]
},
"httpSettings": {
"host": [
"example.org"
],
"path": "/test"
}
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
],
"log": {
"loglevel": "debug"
}
}
37 changes: 37 additions & 0 deletions test/config/vless-tls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"inbounds": [
{
"port": 10002,
"listen": "0.0.0.0",
"protocol": "vless",
"settings": {
"clients": [
{
"id": "b831381d-6324-4d53-ad4f-8cda48b30811"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "tls",
"tlsSettings": {
"certificates": [
{
"certificateFile": "/etc/ssl/v2ray/fullchain.pem",
"keyFile": "/etc/ssl/v2ray/privkey.pem"
}
]
}
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
],
"log": {
"loglevel": "debug"
}
}
30 changes: 30 additions & 0 deletions test/config/vless-ws-0rtt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"inbounds": [
{
"port": 10002,
"listen": "0.0.0.0",
"protocol": "vless",
"settings": {
"clients": [
{
"id": "b831381d-6324-4d53-ad4f-8cda48b30811"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "ws",
"security": "none",
"wsSettings": {
"maxEarlyData": 128,
"earlyDataHeaderName": "Sec-WebSocket-Protocol"
}
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
]
}
34 changes: 34 additions & 0 deletions test/config/vless-ws-tls-zero.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"inbounds": [
{
"port": 10002,
"listen": "0.0.0.0",
"protocol": "vless",
"settings": {
"clients": [
{
"id": "b831381d-6324-4d53-ad4f-8cda48b30811"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "ws",
"security": "tls",
"tlsSettings": {
"certificates": [
{
"certificateFile": "/etc/ssl/v2ray/fullchain.pem",
"keyFile": "/etc/ssl/v2ray/privkey.pem"
}
]
}
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
]
}
34 changes: 34 additions & 0 deletions test/config/vless-ws-tls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"inbounds": [
{
"port": 10002,
"listen": "0.0.0.0",
"protocol": "vless",
"settings": {
"clients": [
{
"id": "b831381d-6324-4d53-ad4f-8cda48b30811"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "ws",
"security": "tls",
"tlsSettings": {
"certificates": [
{
"certificateFile": "/etc/ssl/v2ray/fullchain.pem",
"keyFile": "/etc/ssl/v2ray/privkey.pem"
}
]
}
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
]
}
Loading

0 comments on commit 8a4c46a

Please sign in to comment.