mihomo/transport/vless/vless.go

66 lines
1.1 KiB
Go
Raw Normal View History

2021-07-01 22:49:29 +08:00
package vless
import (
"net"
"github.com/Dreamacro/clash/common/utils"
2023-04-09 15:40:17 +08:00
"github.com/gofrs/uuid/v5"
2021-07-01 22:49:29 +08:00
)
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 {
uuid *uuid.UUID
Addons *Addons
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
func NewClient(uuidStr string, addons *Addons) (*Client, error) {
uid, err := utils.UUIDMap(uuidStr)
2021-07-01 22:49:29 +08:00
if err != nil {
return nil, err
}
return &Client{
uuid: &uid,
Addons: addons,
2021-07-01 22:49:29 +08:00
}, nil
}