core

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2023 License: MIT Imports: 38 Imported by: 2

Documentation

Index

Constants

View Source
const (
	MaxSize   = 1000
	MaxThread = 10
	MaxConn   = 1
)

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
View Source
var Server8422, _ = net.ResolveUDPAddr("udp", "localhost:8422")

Functions

func GvisorTCPListener added in v1.1.36

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

func GvisorUDPListener added in v1.1.36

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

func NewStack added in v1.1.36

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

func NewTunEndpoint added in v1.1.36

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

func ParseProxyInfo added in v1.1.36

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

ParseProxyInfo parse proxy info [20]byte

func TCPForwarder added in v1.1.36

func TCPForwarder(s *stack.Stack) func(stack.TransportEndpointID, *stack.PacketBuffer) bool

func TCPListener

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

func UDPForwarder added in v1.1.36

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

func WriteProxyInfo added in v1.1.36

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 added in v1.1.36

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

func (*ClientDevice) SetTunInboundHandler added in v1.1.36

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

func (*ClientDevice) Start added in v1.1.36

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

type Connector

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

func GvisorTCPTunnelConnector added in v1.1.36

func GvisorTCPTunnelConnector() Connector

func GvisorUDPOverTCPTunnelConnector added in v1.1.36

func GvisorUDPOverTCPTunnelConnector(endpointID stack.TransportEndpointID) Connector

func UDPOverTCPTunnelConnector

func UDPOverTCPTunnelConnector() Connector

type DataElem added in v1.1.22

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

func NewDataElem added in v1.1.36

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

func (*DataElem) Data added in v1.1.36

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

func (*DataElem) Length added in v1.1.36

func (d *DataElem) Length() int

type Device added in v1.1.22

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

func (*Device) Close added in v1.1.22

func (d *Device) Close()

func (*Device) SetTunInboundHandler added in v1.1.36

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

func (*Device) Start added in v1.1.22

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

type Handler

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

func GvisorTCPHandler added in v1.1.36

func GvisorTCPHandler() Handler

func GvisorUDPHandler added in v1.1.36

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 added in v1.1.22

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

func NewNAT added in v1.1.22

func NewNAT() *NAT

func (*NAT) LoadOrStore added in v1.1.22

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

func (*NAT) Range added in v1.1.22

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

func (*NAT) Remove added in v1.1.22

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

func (*NAT) RemoveAddr added in v1.1.22

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

func (*NAT) RouteTo added in v1.1.22

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 added in v1.1.22

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

func (*Peer) Close added in v1.1.22

func (p *Peer) Close()

func (*Peer) Start added in v1.1.22

func (p *Peer) Start()

type Route added in v1.1.22

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 added in v1.1.22

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

type Server

type Server struct {
	Listener net.Listener
	Handler  Handler
}

type TCPUDPacket added in v1.1.35

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