xnet

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AckCodeOK = iota + 1
	AckCodeUnknownError
	AckCodeNoSuchHost
	AckCodeResolveTimeout
	AckCodeConnectTimeout
	AckCodeUnknownProtocol
)
View Source
const (
	AddrTypeIP byte = iota
	AddrTypeHost
)
View Source
const (
	ProtocolTCP byte = iota
	ProtocolUDP
)

Variables

This section is empty.

Functions

func IsClosedConnectionError

func IsClosedConnectionError(err error) bool

func JoinHostPort

func JoinHostPort(host string, port uint16) string

func NewRequestID added in v0.0.6

func NewRequestID() string

func ProxyTCP

func ProxyTCP(reqID string, downConn, upConn *net.TCPConn)

ProxyTCP is excerpt from https://stackoverflow.com/a/27445109/4725840

func ProxyUDP

func ProxyUDP(reqID string, downConn *net.TCPConn, upConn net.Conn)

func ReadUDPFromStream

func ReadUDPFromStream(r io.Reader, buf []byte, timeout time.Duration) (n int, err error)

Types

type AckCode added in v0.0.6

type AckCode uint8

func (AckCode) Error added in v0.0.6

func (c AckCode) Error() string

type Acknowledgement added in v0.0.6

type Acknowledgement struct {
	Code AckCode
}

func (*Acknowledgement) FromReader added in v0.0.6

func (a *Acknowledgement) FromReader(r io.Reader) error

func (*Acknowledgement) Marshal added in v0.0.6

func (a *Acknowledgement) Marshal() []byte

type Addr

type Addr struct {
	// contains filtered or unexported fields
}

func AddrFromBytes

func AddrFromBytes(addrType byte, data []byte) Addr

func AddrFromHost

func AddrFromHost(host string) Addr

func AddrFromIP

func AddrFromIP(ipStr string) (Addr, error)

func (*Addr) IsZero added in v0.0.2

func (a *Addr) IsZero() bool

func (*Addr) Marshal

func (a *Addr) Marshal() []byte

func (*Addr) String

func (a *Addr) String() string
type Header struct {
	Version   byte
	RequestID string
	Protocol  byte
	Port      uint16
	Addr      Addr
}

func (*Header) FromReader

func (h *Header) FromReader(r io.Reader) error

func (*Header) Marshal

func (h *Header) Marshal() []byte

type UDPConn

type UDPConn struct {
	*net.UDPConn
}

UDPConn wraps a *net.UDPConn and overrides the Read and ReadFrom methods to automatically prepend the length of the packet.

func (*UDPConn) Read

func (c *UDPConn) Read(buf []byte) (n int, err error)

func (*UDPConn) ReadFrom

func (c *UDPConn) ReadFrom(buf []byte) (n int, addr net.Addr, err error)

Jump to

Keyboard shortcuts

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