Feature: add basic support for the VLESS protocol (#2891)

This commit is contained in:
crwnet
2023-08-24 13:24:45 +08:00
committed by GitHub
parent 651a36964e
commit 8a4c46ae77
16 changed files with 893 additions and 25 deletions

View File

@@ -56,6 +56,7 @@ type Client struct {
uuid *uuid.UUID
security Security
isAead bool
isVless bool
}
// Config of vmess
@@ -66,12 +67,13 @@ type Config struct {
Port string
HostName string
IsAead bool
IsVless bool
}
// StreamConn return a Conn with net.Conn and DstAddr
func (c *Client) StreamConn(conn net.Conn, dst *DstAddr) (net.Conn, error) {
r := rand.Intn(len(c.user))
return newConn(conn, c.user[r], dst, c.security, c.isAead)
return newConn(conn, c.user[r], dst, c.security, c.isAead, c.isVless)
}
// NewClient return Client instance
@@ -81,6 +83,11 @@ func NewClient(config Config) (*Client, error) {
return nil, err
}
if config.IsVless {
config.AlterID = 0
config.Security = "zero"
}
var security Security
switch config.Security {
case "aes-128-gcm":
@@ -105,5 +112,6 @@ func NewClient(config Config) (*Client, error) {
uuid: &uid,
security: security,
isAead: config.IsAead,
isVless: config.IsVless,
}, nil
}