relay

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2023 License: MIT Imports: 7 Imported by: 53

Documentation

Index

Constants

View Source
const (
	StatusOK                  = 0x00
	StatusBadRequest          = 0x01
	StatusUnauthorized        = 0x02
	StatusForbidden           = 0x03
	StatusTimeout             = 0x04
	StatusServiceUnavailable  = 0x05
	StatusHostUnreachable     = 0x06
	StatusNetworkUnreachable  = 0x07
	StatusInternalServerError = 0x08
)

response status list

View Source
const (
	Version1 = 0x01
)

Variables

View Source
var (
	ErrShortBuffer = errors.New("short buffer")
	ErrBadAddrType = errors.New("bad address type")
)
View Source
var (
	ErrBadVersion = errors.New("bad version")
)

Functions

This section is empty.

Types

type AddrFeature

type AddrFeature struct {
	AType AddrType
	Host  string
	Port  uint16
}

AddrFeature is a relay feature,

Protocol spec:

+------+----------+----------+
| ATYP |   ADDR   |   PORT   |
+------+----------+----------+
|  1   | Variable |    2     |
+------+----------+----------+

ATYP - address type, 0x01 - IPv4, 0x03 - domain name, 0x04 - IPv6. 1 byte.
ADDR - host address, IPv4 (4 bytes), IPV6 (16 bytes) or doman name based on ATYP. For domain name, the first byte is the length of the domain name.
PORT - port number, 2 bytes.

func (*AddrFeature) Decode

func (f *AddrFeature) Decode(b []byte) error

func (*AddrFeature) Encode

func (f *AddrFeature) Encode() ([]byte, error)

func (*AddrFeature) ParseFrom

func (f *AddrFeature) ParseFrom(address string) error

func (*AddrFeature) Type

func (f *AddrFeature) Type() FeatureType

type AddrType

type AddrType uint8
const (
	AddrIPv4   AddrType = 1
	AddrDomain AddrType = 3
	AddrIPv6   AddrType = 4
)

type CmdType

type CmdType uint8
const (
	CmdConnect   CmdType = 0x01
	CmdBind      CmdType = 0x02
	CmdAssociate CmdType = 0x03
	CmdMask      CmdType = 0x0F

	// FUDP is a command flag indicating that the request is UDP-oriented.
	FUDP CmdType = 0x80
)

request commands

type ConnectorID

type ConnectorID = TunnelID

type Feature

type Feature interface {
	Type() FeatureType
	Encode() ([]byte, error)
	Decode([]byte) error
}

Feature represents a feature the client or server owned.

Protocol spec:

+------+----------+------+
| TYPE |  LEN  | FEATURE |
+------+-------+---------+
|  1   |   2   |   VAR   |
+------+-------+---------+

TYPE - feature type, 1 byte.
LEN - length of feature data, 2 bytes.
FEATURE - feature data.

func NewFeature

func NewFeature(t FeatureType, data []byte) (f Feature, err error)

func ReadFeature

func ReadFeature(r io.Reader) (Feature, error)

type FeatureType

type FeatureType uint8
const (
	FeatureUserAuth FeatureType = 0x01
	FeatureAddr     FeatureType = 0x02
	FeatureTunnel   FeatureType = 0x03
)

type Request

type Request struct {
	Version  uint8
	Cmd      CmdType
	Features []Feature
}

Request is a relay client request.

Protocol spec:

+-----+-------------+----+---+-----+----+
| VER |  CMD/FLAGS  | FEALEN | FEATURES |
+-----+-------------+----+---+-----+----+
|  1  |      1      |    2   |    VAR   |
+-----+-------------+--------+----------+

VER - protocol version, 1 byte.
CMD/FLAGS - command (low 4-bit) and flags (high 4-bit), 1 byte.
FEALEN - length of features, 2 bytes.
FEATURES - feature list.

func (*Request) ReadFrom

func (req *Request) ReadFrom(r io.Reader) (n int64, err error)

func (*Request) WriteTo

func (req *Request) WriteTo(w io.Writer) (n int64, err error)

type Response

type Response struct {
	Version  uint8
	Status   uint8
	Features []Feature
}

Response is a relay server response.

Protocol spec:

+-----+--------+----+---+-----+----+
| VER | STATUS | FEALEN | FEATURES |
+-----+--------+----+---+-----+----+
|  1  |    1   |    2   |    VAR   |
+-----+--------+--------+----------+

VER - protocol version, 1 byte.
STATUS - server status, 1 byte.
FEALEN - length of features, 2 bytes.
FEATURES - feature list.

func (*Response) ReadFrom

func (resp *Response) ReadFrom(r io.Reader) (n int64, err error)

func (*Response) WriteTo

func (resp *Response) WriteTo(w io.Writer) (n int64, err error)

type TunnelFeature

type TunnelFeature struct {
	ID TunnelID
}

TunnelFeature is a relay feature,

Protocol spec:

+---------------------+
| TUNNEL/CONNECTOR ID |
+---------------------+
|          16         |
+---------------------+

ID - 16-byte tunnel ID for request or connector ID for response.

func (*TunnelFeature) Decode

func (f *TunnelFeature) Decode(b []byte) error

func (*TunnelFeature) Encode

func (f *TunnelFeature) Encode() ([]byte, error)

func (*TunnelFeature) Type

func (f *TunnelFeature) Type() FeatureType

type TunnelID

type TunnelID [16]byte

func (TunnelID) IsZero

func (tid TunnelID) IsZero() bool

func (TunnelID) String

func (tid TunnelID) String() string

type UserAuthFeature

type UserAuthFeature struct {
	Username string
	Password string
}

UserAuthFeature is a relay feature, it contains the username and password for user authentication on server side.

Protocol spec:

+------+----------+------+----------+
| ULEN |  UNAME   | PLEN |  PASSWD  |
+------+----------+------+----------+
|  1   | 0 to 255 |  1   | 1 to 255 |
+------+----------+------+----------+

ULEN - length of username field, 1 byte.
UNAME - username, variable length, 0 to 255 bytes, 0 means no username.
PLEN - length of password field, 1 byte.
PASSWD - password, variable length, 0 to 255 bytes, 0 means no password.

func (*UserAuthFeature) Decode

func (f *UserAuthFeature) Decode(b []byte) error

func (*UserAuthFeature) Encode

func (f *UserAuthFeature) Encode() ([]byte, error)

func (*UserAuthFeature) Type

func (f *UserAuthFeature) Type() FeatureType

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL