github.com/metacubex/mihomo@v1.18.5/transport/vless/vless.go (about) 1 package vless 2 3 import ( 4 "net" 5 6 "github.com/metacubex/mihomo/common/utils" 7 8 "github.com/gofrs/uuid/v5" 9 ) 10 11 const ( 12 XRO = "xtls-rprx-origin" 13 XRD = "xtls-rprx-direct" 14 XRS = "xtls-rprx-splice" 15 XRV = "xtls-rprx-vision" 16 17 Version byte = 0 // protocol version. preview version is 0 18 ) 19 20 // Command types 21 const ( 22 CommandTCP byte = 1 23 CommandUDP byte = 2 24 CommandMux byte = 3 25 ) 26 27 // Addr types 28 const ( 29 AtypIPv4 byte = 1 30 AtypDomainName byte = 2 31 AtypIPv6 byte = 3 32 ) 33 34 // DstAddr store destination address 35 type DstAddr struct { 36 UDP bool 37 AddrType byte 38 Addr []byte 39 Port uint16 40 Mux bool // currently used for XUDP only 41 } 42 43 // Client is vless connection generator 44 type Client struct { 45 uuid *uuid.UUID 46 Addons *Addons 47 } 48 49 // StreamConn return a Conn with net.Conn and DstAddr 50 func (c *Client) StreamConn(conn net.Conn, dst *DstAddr) (net.Conn, error) { 51 return newConn(conn, c, dst) 52 } 53 54 // NewClient return Client instance 55 func NewClient(uuidStr string, addons *Addons) (*Client, error) { 56 uid, err := utils.UUIDMap(uuidStr) 57 if err != nil { 58 return nil, err 59 } 60 61 return &Client{ 62 uuid: &uid, 63 Addons: addons, 64 }, nil 65 }