core

package
v1.13.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LWIP_ERR_OK int = iota
	LWIP_ERR_ABRT
	LWIP_ERR_CONN
)
View Source
const BufSize = 2 * 1024
View Source
const CHECK_TIMEOUTS_INTERVAL = 250 // in millisecond
View Source
const TCP_POLL_INTERVAL = 8 // poll every 4 seconds

Variables

View Source
var OutputFn func([]byte) (int, error)

Functions

func FreeBytes

func FreeBytes(b []byte)

func Input

func Input(pkt []byte) (int, error)

func NewBytes

func NewBytes(size int) []byte

func NewLWIPError

func NewLWIPError(code int) error

func ParseTCPAddr

func ParseTCPAddr(addr string, port uint16) net.Addr

func ParseUDPAddr

func ParseUDPAddr(addr string, port uint16) net.Addr

func RegisterOutputFn

func RegisterOutputFn(fn func([]byte) (int, error))

func RegisterTCPConnHandler added in v1.12.0

func RegisterTCPConnHandler(h TCPConnHandler)

func RegisterUDPConnHandler added in v1.12.0

func RegisterUDPConnHandler(h UDPConnHandler)

func SetBufferPool

func SetBufferPool(p *sync.Pool)

Types

type LWIPStack

type LWIPStack interface {
	Write([]byte) (int, error)
	Close() error
	RestartTimeouts()
}

func NewLWIPStack

func NewLWIPStack() LWIPStack

NewLWIPStack listens for any incoming connections/packets and registers corresponding accept/recv callback functions.

type TCPConn added in v1.12.0

type TCPConn interface {
	// RemoteAddr returns the destination network address.
	RemoteAddr() net.Addr

	// LocalAddr returns the local client network address.
	LocalAddr() net.Addr

	// Receive receives data from TUN.
	Receive(data []byte) error

	// Write writes data to TUN.
	Write(data []byte) (int, error)

	// Sent will be called when sent data has been acknowledged by clients.
	Sent(len uint16) error

	// Close closes the connection.
	Close() error

	// Abort aborts the connection to client by sending a RST segment.
	Abort()

	// Err will be called when a fatal error has occurred on the connection.
	Err(err error)

	// LocalDidClose will be called when local client has close the connection.
	LocalDidClose() error

	// Poll will be periodically called by timers.
	Poll() error
}

TCPConn abstracts a TCP connection comming from TUN. This connection should be handled by a registered TCP proxy handler.

type TCPConnHandler added in v1.12.0

type TCPConnHandler interface {
	// Connect connects the proxy server.
	Connect(conn TCPConn, target net.Addr) error

	// DidReceive will be called when data arrives from TUN.
	DidReceive(conn TCPConn, data []byte) error

	// DidClose will be called when the connection has been closed.
	DidClose(conn TCPConn)

	// LocalDidClose will be called when local client has close the connection.
	LocalDidClose(conn TCPConn)
}

TCPConnHandler handles TCP connections comming from TUN.

type UDPConn added in v1.12.0

type UDPConn interface {
	// LocalAddr returns the local client network address.
	LocalAddr() net.Addr

	// ReceiveTo receives data from TUN, and the received data should be sent to addr.
	ReceiveTo(data []byte, addr net.Addr) error

	// WriteFrom writes data to TUN, which was received from addr. addr will be set as
	// source address of IP packets that output to TUN.
	WriteFrom(data []byte, addr net.Addr) (int, error)

	// Close closes the connection.
	Close() error
}

TCPConn abstracts a UDP connection comming from TUN. This connection should be handled by a registered UDP proxy handler.

type UDPConnHandler added in v1.12.0

type UDPConnHandler interface {
	// Connect connects the proxy server. `target` can be nil.
	Connect(conn UDPConn, target net.Addr) error

	// DidReceive will be called when data arrives from TUN.
	DidReceiveTo(conn UDPConn, data []byte, addr net.Addr) error
}

UDPConnHandler handles UDP connections comming from TUN.

Jump to

Keyboard shortcuts

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