Clash.Meta/transport/vless/vless.go

68 lines
1.2 KiB
Go
Raw Normal View History

2021-07-01 22:49:29 +08:00
package vless
import (
"net"
"github.com/Dreamacro/clash/common/utils"
2021-07-01 22:49:29 +08:00
"github.com/gofrs/uuid"
)
2021-07-06 23:55:34 +08:00
const (
XRO = "xtls-rprx-origin"
XRD = "xtls-rprx-direct"
XRS = "xtls-rprx-splice"
2023-02-25 13:12:19 +08:00
XRV = "xtls-rprx-vision"
2021-07-06 23:55:34 +08:00
Version byte = 0 // protocol version. preview version is 0
)
2021-07-01 22:49:29 +08:00
// Command types
const (
CommandTCP byte = 1
CommandUDP byte = 2
CommandMux byte = 3
2021-07-01 22:49:29 +08: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 22:49:29 +08:00
}
// Client is vless connection generator
type Client struct {
2021-07-06 23:55:34 +08:00
uuid *uuid.UUID
Addons *Addons
XTLSShow bool
2021-07-01 22:49:29 +08: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 23:55:34 +08:00
return newConn(conn, c, dst)
2021-07-01 22:49:29 +08:00
}
// NewClient return Client instance
2021-07-06 23:55:34 +08:00
func NewClient(uuidStr string, addons *Addons, xtlsShow bool) (*Client, error) {
uid, err := utils.UUIDMap(uuidStr)
2021-07-01 22:49:29 +08:00
if err != nil {
return nil, err
}
return &Client{
2021-07-06 23:55:34 +08:00
uuid: &uid,
Addons: addons,
XTLSShow: xtlsShow,
2021-07-01 22:49:29 +08:00
}, nil
}