mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-12-25 19:55:38 +08:00
a82745f544
* chore: Remove legacy XTLS support * chore: Rename function
66 lines
1.1 KiB
Go
66 lines
1.1 KiB
Go
package vless
|
|
|
|
import (
|
|
"net"
|
|
|
|
"github.com/Dreamacro/clash/common/utils"
|
|
|
|
"github.com/gofrs/uuid/v5"
|
|
)
|
|
|
|
const (
|
|
XRO = "xtls-rprx-origin"
|
|
XRD = "xtls-rprx-direct"
|
|
XRS = "xtls-rprx-splice"
|
|
XRV = "xtls-rprx-vision"
|
|
|
|
Version byte = 0 // protocol version. preview version is 0
|
|
)
|
|
|
|
// Command types
|
|
const (
|
|
CommandTCP byte = 1
|
|
CommandUDP byte = 2
|
|
CommandMux byte = 3
|
|
)
|
|
|
|
// 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
|
|
}
|
|
|
|
// Client is vless connection generator
|
|
type Client struct {
|
|
uuid *uuid.UUID
|
|
Addons *Addons
|
|
}
|
|
|
|
// StreamConn return a Conn with net.Conn and DstAddr
|
|
func (c *Client) StreamConn(conn net.Conn, dst *DstAddr) (net.Conn, error) {
|
|
return newConn(conn, c, dst)
|
|
}
|
|
|
|
// NewClient return Client instance
|
|
func NewClient(uuidStr string, addons *Addons) (*Client, error) {
|
|
uid, err := utils.UUIDMap(uuidStr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Client{
|
|
uuid: &uid,
|
|
Addons: addons,
|
|
}, nil
|
|
}
|