core

package
v0.0.0-...-8e6527b Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEndpoint

func NewEndpoint(dev Device, mtu int) stack.LinkEndpoint

NewEndpoint is ...

Types

type Device

type Device interface {
	// Reader is ...
	Reader
	// Writer is ...
	Writer
	// DeviceType is ...
	// give device type
	DeviceType() string
}

Device is a tun-like device for reading packets from system

type Endpoint

type Endpoint struct {
	// Endpoint is ...
	*channel.Endpoint
	// Reader is ...
	// read packets from tun device
	Reader Reader
	// Writer is ...
	// write packets to tun device
	Writer Writer
	// contains filtered or unexported fields
}

Endpoint is ...

func (*Endpoint) Attach

func (e *Endpoint) Attach(dispatcher stack.NetworkDispatcher)

Attach is to attach device to stack

func (*Endpoint) WriteNotify

func (e *Endpoint) WriteNotify()

WriteNotify is to write packets back to system

type Handler

type Handler interface {
	Handle(*TCPConn, *net.TCPAddr)
	HandlePacket(*UDPConn, *net.UDPAddr)
}

Handler is for handling incoming TCP and UDP connections

type Logger

type Logger interface {
	Error(string, ...interface{})
	Info(string, ...interface{})
	Debug(string, ...interface{})
}

Logger is for showing logs of netstack

type Packet

type Packet struct {
	// Addr is ...
	// target address
	Addr *net.UDPAddr
	// Byte is ...
	// packet payload
	Byte []byte
}

Packet is ...

type Reader

type Reader interface {
	Read([]byte, int) (int, error)
}

Reader is for unix tun reading with 4 bytes prefix for WinTun, there is no prefix

type Stack

type Stack struct {
	// Logger is ...
	Logger
	// Device is ...
	// layer 2 device for reading and writing packets
	Device Device
	// Handler is ...
	// handle tcp and udp connections
	Handler Handler
	// Stack is ...
	Stack *stack.Stack
	// contains filtered or unexported fields
}

Stack is ... pure go netstack provided by gvisor.dev

func (*Stack) Add

func (s *Stack) Add(k int, conn *UDPConn)

Add is to add *UDPConn

func (*Stack) Close

func (s *Stack) Close() error

Close is to close the stack

func (*Stack) Del

func (s *Stack) Del(k int)

Del is to delete *UDPConn

func (*Stack) Get

func (s *Stack) Get(k int) (*UDPConn, bool)

Get is to get *UDPConn

func (*Stack) HandlePacket

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

HandlePacket is to handle UDP connections

func (*Stack) HandleStream

func (s *Stack) HandleStream(r *tcp.ForwarderRequest)

HandleStream is to handle incoming TCP connections

func (*Stack) Start

func (s *Stack) Start(device Device, handler Handler, logger Logger, mtu int) (err error)

Start is to start the stack

type TCPConn

type TCPConn struct {
	gonet.TCPConn
}

TCPConn is ...

type UDPConn

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

UDPConn is ...

func NewUDPConn

func NewUDPConn(key int, id stack.TransportEndpointID, pkt *stack.PacketBuffer, s *Stack) *UDPConn

NewUDPConn is to create a new *UDPConn

func (*UDPConn) Close

func (conn *UDPConn) Close() error

Close close UDPConn

func (*UDPConn) HandlePacket

func (conn *UDPConn) HandlePacket(b []byte, addr *net.UDPAddr)

HandlePacket is to read packet to UDPConn

func (*UDPConn) LocalAddr

func (conn *UDPConn) LocalAddr() net.Addr

LocalAddr is net.PacketConn.LocalAddr

func (*UDPConn) ReadTo

func (conn *UDPConn) ReadTo(b []byte) (n int, addr net.Addr, err error)

ReadTo is ...

func (*UDPConn) RemoteAddr

func (conn *UDPConn) RemoteAddr() net.Addr

RemoteAddr is net.PacketConn.RemoteAddr

func (*UDPConn) SetDeadline

func (d *UDPConn) SetDeadline(t time.Time) error

SetDeadline implements net.Conn.SetDeadline and net.PacketConn.SetDeadline.

func (*UDPConn) SetReadDeadline

func (d *UDPConn) SetReadDeadline(t time.Time) error

SetReadDeadline implements net.Conn.SetReadDeadline and net.PacketConn.SetReadDeadline.

func (*UDPConn) SetWriteDeadline

func (d *UDPConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements net.Conn.SetWriteDeadline and net.PacketConn.SetWriteDeadline.

func (*UDPConn) WriteFrom

func (conn *UDPConn) WriteFrom(b []byte, addr net.Addr) (int, error)

WriteFrom is ...

type Writer

type Writer interface {
	// Write packets to tun device
	Write([]byte, int) (int, error)
}

Writer is for linux tun writing with 4 bytes prefix

Jump to

Keyboard shortcuts

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