2021-07-01 14:49:29 +00:00
|
|
|
package vless
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
|
|
|
"github.com/gofrs/uuid"
|
|
|
|
)
|
|
|
|
|
2021-07-06 15:55:34 +00:00
|
|
|
const (
|
|
|
|
XRO = "xtls-rprx-origin"
|
|
|
|
XRD = "xtls-rprx-direct"
|
|
|
|
XRS = "xtls-rprx-splice"
|
|
|
|
|
|
|
|
Version byte = 0 // protocol version. preview version is 0
|
|
|
|
)
|
2021-07-01 14:49:29 +00:00
|
|
|
|
|
|
|
// Command types
|
|
|
|
const (
|
|
|
|
CommandTCP byte = 1
|
|
|
|
CommandUDP byte = 2
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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 uint
|
|
|
|
}
|
|
|
|
|
|
|
|
// Config of vless
|
|
|
|
type Config struct {
|
|
|
|
UUID string
|
|
|
|
AlterID uint16
|
|
|
|
Security string
|
|
|
|
Port string
|
|
|
|
HostName string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client is vless connection generator
|
|
|
|
type Client struct {
|
2021-07-06 15:55:34 +00:00
|
|
|
uuid *uuid.UUID
|
|
|
|
Addons *Addons
|
|
|
|
XTLSShow bool
|
2021-07-01 14:49:29 +00: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 15:55:34 +00:00
|
|
|
return newConn(conn, c, dst)
|
2021-07-01 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewClient return Client instance
|
2021-07-06 15:55:34 +00:00
|
|
|
func NewClient(uuidStr string, addons *Addons, xtlsShow bool) (*Client, error) {
|
2021-07-01 14:49:29 +00:00
|
|
|
uid, err := uuid.FromString(uuidStr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Client{
|
2021-07-06 15:55:34 +00:00
|
|
|
uuid: &uid,
|
|
|
|
Addons: addons,
|
|
|
|
XTLSShow: xtlsShow,
|
2021-07-01 14:49:29 +00:00
|
|
|
}, nil
|
|
|
|
}
|