core

package
v2.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 38 Imported by: 2

Documentation

Index

Constants

View Source
const (
	MaxSize = 1000
)

Variables

View Source
var (
	// RouteNAT Globe route table for inner ip
	RouteNAT = NewNAT()
	// RouteConnNAT map[srcIP]net.Conn
	RouteConnNAT = &sync.Map{}
	// Chan tcp connects
	Chan = make(chan *datagramPacket, MaxSize)
)
View Source
var (
	// ErrorEmptyChain is an error that implies the chain is empty.
	ErrorEmptyChain = errors.New("empty chain")
)
View Source
var (
	ErrorInvalidNode = errors.New("invalid node")
)
View Source
var GvisorTCPForwardAddr string
View Source
var GvisorUDPForwardAddr string

Functions

func GvisorTCPListener

func GvisorTCPListener(addr string) (net.Listener, error)

func GvisorUDPListener

func GvisorUDPListener(addr string) (net.Listener, error)

func NewStack

func NewStack(ctx context.Context, tun stack.LinkEndpoint) *stack.Stack

func NewTunEndpoint

func NewTunEndpoint(ctx context.Context, tun net.Conn, mtu uint32, engine config.Engine, in chan<- *DataElem, out chan *DataElem) stack.LinkEndpoint

func ParseProxyInfo

func ParseProxyInfo(conn net.Conn) (id stack.TransportEndpointID, err error)

ParseProxyInfo parse proxy info [20]byte

func TCPListener

func TCPListener(addr string) (net.Listener, error)

func UDPForwarder

func UDPForwarder(s *stack.Stack) func(id stack.TransportEndpointID, pkt *stack.PacketBuffer) bool

func WriteProxyInfo

func WriteProxyInfo(conn net.Conn, id stack.TransportEndpointID) error

Types

type Chain

type Chain struct {
	Retries int
	// contains filtered or unexported fields
}

func NewChain

func NewChain(retry int, node *Node) *Chain

func (*Chain) DialContext

func (c *Chain) DialContext(ctx context.Context) (conn net.Conn, err error)

func (*Chain) IsEmpty

func (c *Chain) IsEmpty() bool

func (*Chain) Node

func (c *Chain) Node() *Node

type Client

type Client struct {
	Connector
	Transporter
}

type ClientDevice

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

func (*ClientDevice) SetTunInboundHandler

func (d *ClientDevice) SetTunInboundHandler(handler func(tunInbound <-chan *DataElem, tunOutbound chan<- *DataElem))

func (*ClientDevice) Start

func (d *ClientDevice) Start(ctx context.Context)

type Connector

type Connector interface {
	ConnectContext(ctx context.Context, conn net.Conn) (net.Conn, error)
}

func GvisorTCPTunnelConnector

func GvisorTCPTunnelConnector() Connector

func GvisorUDPOverTCPTunnelConnector

func GvisorUDPOverTCPTunnelConnector(endpointID stack.TransportEndpointID) Connector

func UDPOverTCPTunnelConnector

func UDPOverTCPTunnelConnector() Connector

type DataElem

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

func NewDataElem

func NewDataElem(data []byte, length int, src net.IP, dst net.IP) *DataElem

func (*DataElem) Data

func (d *DataElem) Data() []byte

func (*DataElem) Length

func (d *DataElem) Length() int

type Device

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

func (*Device) Close

func (d *Device) Close()

func (*Device) SetTunInboundHandler

func (d *Device) SetTunInboundHandler(handler func(tunInbound <-chan *DataElem, tunOutbound chan<- *DataElem))

func (*Device) Start

func (d *Device) Start(ctx context.Context)

type Handler

type Handler interface {
	Handle(ctx context.Context, conn net.Conn)
}

func GvisorTCPHandler

func GvisorTCPHandler() Handler

func GvisorUDPHandler

func GvisorUDPHandler() Handler

func TCPHandler

func TCPHandler() Handler

func TunHandler

func TunHandler(chain *Chain, node *Node) Handler

TunHandler creates a handler for tun tunnel.

type NAT

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

func NewNAT

func NewNAT() *NAT

func (*NAT) LoadOrStore

func (n *NAT) LoadOrStore(to net.IP, addr net.Addr) (result net.Addr, load bool)

func (*NAT) Range

func (n *NAT) Range(f func(key string, v []net.Addr))

func (*NAT) Remove

func (n *NAT) Remove(ip net.IP, addr net.Addr)

func (*NAT) RemoveAddr

func (n *NAT) RemoveAddr(addr net.Addr) (count int)

func (*NAT) RouteTo

func (n *NAT) RouteTo(ip net.IP) net.Addr

type Node

type Node struct {
	Addr     string
	Protocol string
	Remote   string // remote address, used by tcp/udp port forwarding
	Values   url.Values
	Client   *Client
}

func ParseNode

func ParseNode(s string) (*Node, error)

ParseNode pattern is [scheme://][user:pass@host]:port.

func (*Node) Get

func (node *Node) Get(key string) string

Get returns node parameter specified by key.

func (*Node) GetInt

func (node *Node) GetInt(key string) int

GetInt converts node parameter value to int.

type Peer

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

func (*Peer) Close

func (p *Peer) Close()

func (*Peer) Start

func (p *Peer) Start()

type Route

type Route struct {
	ServeNodes []string // -L tun
	ChainNode  string   // -F tcp
	Retries    int
}

Route example: -L "tcp://:10800" -L "tun://:8422?net=223.254.0.100/16" -L "tun:/10.233.24.133:8422?net=223.254.0.102/16&route=223.254.0.0/16" -L "tun:/127.0.0.1:8422?net=223.254.0.102/16&route=223.254.0.0/16,10.233.0.0/16" -F "tcp://127.0.0.1:10800"

func (*Route) GenerateServers

func (r *Route) GenerateServers() ([]Server, error)

type Server

type Server struct {
	Listener net.Listener
	Handler  Handler
}

type TCPUDPacket

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

type Transporter

type Transporter interface {
	Dial(ctx context.Context, addr string) (net.Conn, error)
}

func TCPTransporter

func TCPTransporter() Transporter

Jump to

Keyboard shortcuts

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