clash/transport/vless/vless.go

68 lines
1.2 KiB
Go
Raw Normal View History

2021-07-01 14:49:29 +00:00
package vless
import (
"net"
"github.com/Dreamacro/clash/common/utils"
2023-04-09 07:40:17 +00:00
"github.com/gofrs/uuid/v5"
2021-07-01 14:49:29 +00:00
)
2021-07-06 15:55:34 +00:00
const (
XRO = "xtls-rprx-origin"
XRD = "xtls-rprx-direct"
XRS = "xtls-rprx-splice"
2023-02-25 05:12:19 +00:00
XRV = "xtls-rprx-vision"
2021-07-06 15:55:34 +00:00
Version byte = 0 // protocol version. preview version is 0
)
2021-07-01 14:49:29 +00:00
// Command types
const (
CommandTCP byte = 1
CommandUDP byte = 2
CommandMux byte = 3
2021-07-01 14:49:29 +00:00
)
// Addr types
const (
AtypIPv4 byte = 1
AtypDomainName byte = 2
AtypIPv6 byte = 3
)
// DstAddr store destination address
type DstAddr struct {
UDP bool
AddrType byte
Addr []byte
Port uint16
Mux bool // currently used for XUDP only
2021-07-01 14:49:29 +00:00
}
// Client is vless connection generator
type Client struct {
2021-07-06 15:55:34 +00:00
uuid *uuid.UUID
Addons *Addons
XTLSShow bool
2021-07-01 14:49:29 +00:00
}
// StreamConn return a Conn with net.Conn and DstAddr
func (c *Client) StreamConn(conn net.Conn, dst *DstAddr) (net.Conn, error) {
2021-07-06 15:55:34 +00:00
return newConn(conn, c, dst)
2021-07-01 14:49:29 +00:00
}
// NewClient return Client instance
2021-07-06 15:55:34 +00:00
func NewClient(uuidStr string, addons *Addons, xtlsShow bool) (*Client, error) {
uid, err := utils.UUIDMap(uuidStr)
2021-07-01 14:49:29 +00:00
if err != nil {
return nil, err
}
return &Client{
2021-07-06 15:55:34 +00:00
uuid: &uid,
Addons: addons,
XTLSShow: xtlsShow,
2021-07-01 14:49:29 +00:00
}, nil
}