spec

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuth                = errors.New("authentication failed! invalid/limited ToH key")
	ErrDNSTypeANotFound    = errors.New("type A record not found")
	ErrDNSTypeAAAANotFound = errors.New("type AAAA record not found")
	ErrDNSRecordNotFound   = errors.New("dns record not found")

	ErrUnsupportNetwork = errors.New("unsupport network")

	HeaderHandshakeKey   = "X-Toh-Key"
	HeaderHandshakeNet   = "X-Toh-Net"
	HeaderHandshakeAddr  = "X-Toh-Addr"
	HeaderHandshakeNonce = "X-Toh-Nonce"
	HeaderEstablishAddr  = "X-Toh-EstAddr"
	HeaderSessionID      = "X-Toh-SessionID"
	HeaderSourceIP       = "X-Toh-SourceIP"
	HeaderOP             = "X-Toh-OP"

	OPOverlayControl = "overlay-control"
	OPOverlayData    = "overlay-data"
)
View Source
var (
	Version, Commit string
)

Functions

func BytesToUint16

func BytesToUint16(bys []byte) uint16

func MustParseNonce added in v0.12.4

func MustParseNonce(nonce string) byte

func NewNonce added in v0.12.4

func NewNonce() string

func RealIP

func RealIP(r *http.Request) string

func SetDefaultLogger added in v0.13.0

func SetDefaultLogger(logger *slog.Logger)

func Uint16ToBytes

func Uint16ToBytes(n uint16) []byte

func Uint32ToBytes

func Uint32ToBytes(n uint32) []byte

Types

type ConfigFileWriter

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

ConfigFileWriter a writer that writes to both files and stdout

func NewConfigWriter

func NewConfigWriter(f *os.File) *ConfigFileWriter

func (*ConfigFileWriter) Write

func (w *ConfigFileWriter) Write(p []byte) (n int, err error)

type Conn added in v0.12.3

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

Conn tcp/udp connection based on StreamConn connection

func NewConn added in v0.12.3

func NewConn(conn StreamConn) *Conn

func (*Conn) Close added in v0.12.3

func (c *Conn) Close() error

Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.

func (*Conn) LocalAddr added in v0.12.3

func (c *Conn) LocalAddr() net.Addr

LocalAddr returns the local network address, if known.

func (*Conn) Read added in v0.12.3

func (c *Conn) Read(b []byte) (n int, err error)

Read reads data from the connection. Read can be made to time out and return an error after a fixed time limit; see SetDeadline and SetReadDeadline.

func (*Conn) RemoteAddr added in v0.12.3

func (c *Conn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address, if known.

func (*Conn) SetDeadline added in v0.12.3

func (c *Conn) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.

A deadline is an absolute time after which I/O operations fail instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to Read or Write. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future.

If the deadline is exceeded a call to Read or Write or to other I/O methods will return an error that wraps os.ErrDeadlineExceeded. This can be tested using errors.Is(err, os.ErrDeadlineExceeded). The error's Timeout method will return true, but note that there are other possible errors for which the Timeout method will return true even if the deadline has not been exceeded.

An idle timeout can be implemented by repeatedly extending the deadline after successful Read or Write calls.

A zero value for t means I/O operations will not time out.

func (*Conn) SetReadDeadline added in v0.12.3

func (c *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future Read calls and any currently-blocked Read call. A zero value for t means Read will not time out.

func (*Conn) SetWriteDeadline added in v0.12.3

func (c *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future Write calls and any currently-blocked Write call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means Write will not time out.

func (*Conn) Write added in v0.12.3

func (c *Conn) Write(b []byte) (n int, err error)

Write writes data to the connection. Write can be made to time out and return an error after a fixed time limit; see SetDeadline and SetWriteDeadline.

type ConnectParameters added in v0.13.2

type ConnectParameters struct {
	URL       *url.URL
	Key       string
	Network   string
	Addr      string
	Header    http.Header
	Keepalive time.Duration
}

type Dial

type Dial func(ctx context.Context, network, addr string) (net.Conn, error)

Dial describe the dial func

type LogField

type LogField int

LogField log filed

const (
	AppAddr LogField = iota
)

func (LogField) String

func (c LogField) String() string

type NetDialer added in v0.14.0

type NetDialer interface {
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

NetDialer dialer interface

type PacketConnWrapper

type PacketConnWrapper struct {
	net.Conn
	// contains filtered or unexported fields
}

PacketConnWrapper wrap UDP conn

func NewPacketConn added in v0.13.1

func NewPacketConn(wsConn StreamConn) *PacketConnWrapper

func (*PacketConnWrapper) ReadFrom

func (c *PacketConnWrapper) ReadFrom(b []byte) (int, net.Addr, error)

func (*PacketConnWrapper) WriteTo

func (c *PacketConnWrapper) WriteTo(b []byte, addr net.Addr) (int, error)

type PipeEngine

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

func NewPipeEngine

func NewPipeEngine() *PipeEngine

func (*PipeEngine) AddEventConsumer added in v0.9.12

func (s *PipeEngine) AddEventConsumer(c TrafficEventConsumer)

func (*PipeEngine) Pipe

func (s *PipeEngine) Pipe(dialerName string, conn, rConn net.Conn)

func (*PipeEngine) PubEvent

func (s *PipeEngine) PubEvent(e *TrafficEvent)

func (*PipeEngine) RunTrafficEventConsumeLoop

func (s *PipeEngine) RunTrafficEventConsumeLoop()

type StreamConn added in v0.12.3

type StreamConn interface {
	Read() ([]byte, error)
	Write(p []byte) error
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	Close(code int, reason string) error
	Nonce() byte
	SetReadDeadline(t time.Time) error
	SetWriteDeadline(t time.Time) error
}

StreamConn under layer transport connection. .i.e websocket

type StreamConnKeeper added in v0.13.2

type StreamConnKeeper interface {
	SetKeepalive(keepalive time.Duration)
	Keepalive()
}

StreamConnKeeper keep stream connection alive

type StreamConnListener added in v0.13.2

type StreamConnListener interface {
	SetOnClose(func())
	SetOnReadWrite(func())
}

StreamConnListener listen conn lifecycle

type TohClient

type TohClient interface {
	DialTCP(ctx context.Context, address string) (net.Conn, error)
	DialUDP(ctx context.Context, address string) (net.Conn, error)
	LookupIP(host string) (ips []net.IP, err error)
	LookupIP4(host string) (ips []net.IP, err error)
	LookupIP6(host string) (ips []net.IP, err error)
	NetDialer
}

TohClient the ToH client

type TrafficEvent

type TrafficEvent struct {
	DialerName, Network, RemoteAddr, LocalAddr string
	In, Out                                    int64
}

type TrafficEventConsumer

type TrafficEventConsumer func(e *TrafficEvent)

Jump to

Keyboard shortcuts

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