relay

package module
v0.0.0-...-f6a9ce0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FeatureUserAuth = 0x01
	FeatureAddr     = 0x02
)
View Source
const (
	AddrIPv4   uint8 = 1
	AddrDomain uint8 = 3
	AddrIPv6   uint8 = 4
)
View Source
const (
	CONNECT   uint8 = 0x01
	BIND      uint8 = 0x02
	ASSOCIATE uint8 = 0x03

	CmdMask uint8 = 0x0F
)

request commands

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

response status list

View Source
const (
	// FUDP is a flag indicating that the request is UDP-oriented.
	FUDP uint8 = 0x80
)
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 uint8
	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() uint8

type Feature

type Feature interface {
	Type() uint8
	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 uint8, data []byte) (f Feature, err error)

func ReadFeature

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

type Request

type Request struct {
	Version  uint8
	Flags    uint8
	Features []Feature
}

Request is a relay client request.

Protocol spec:

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

VER - protocol version, 1 byte.
FLAGS - flags, 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 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() uint8

Jump to

Keyboard shortcuts

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