github.com/yaling888/clash@v1.53.0/transport/vless/vless.go (about) 1 package vless 2 3 import ( 4 "net" 5 6 "github.com/yaling888/clash/common/uuid" 7 ) 8 9 // Version of vmess 10 const Version byte = 0 11 12 // Command types 13 const ( 14 CommandTCP byte = 1 15 CommandUDP byte = 2 16 ) 17 18 // Addr types 19 const ( 20 AtypIPv4 byte = 1 21 AtypDomainName byte = 2 22 AtypIPv6 byte = 3 23 ) 24 25 // DstAddr store destination address 26 type DstAddr struct { 27 UDP bool 28 AddrType byte 29 Addr []byte 30 Port uint 31 } 32 33 // Client is vless connection generator 34 type Client struct { 35 uuid uuid.UUID 36 } 37 38 // StreamConn return a Conn with net.Conn and DstAddr 39 func (c *Client) StreamConn(conn net.Conn, dst *DstAddr) (net.Conn, error) { 40 return newConn(conn, c, dst) 41 } 42 43 // NewClient return Client instance 44 func NewClient(uuidStr string) (*Client, error) { 45 uid, err := uuid.ParseStd(uuidStr) 46 if err != nil { 47 return nil, err 48 } 49 50 return &Client{ 51 uuid: uid, 52 }, nil 53 }