network

package
v0.0.0-...-0f2c02b Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: GPL-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	NetworkIP     = "ip"
	NetworkTCP    = "tcp"
	NetworkUDP    = "udp"
	NetworkICMPv4 = "icmpv4"
	NetworkICMPv6 = "icmpv6"
)
View Source
const DefaultFallbackDelay = 300 * time.Millisecond
View Source
const DefaultHeadroom = 1024

Variables

View Source
var ErrUnknownNetwork = E.New("unknown network")

Functions

func CalculateFrontHeadroom

func CalculateFrontHeadroom(writer any) int

func CalculateMTU

func CalculateMTU(reader any, writer any) int

func CalculateRearHeadroom

func CalculateRearHeadroom(writer any) int

func CastPacketReader

func CastPacketReader[T PacketReader](reader PacketReader) (T, bool)

func CastPacketWriter

func CastPacketWriter[T PacketWriter](writer PacketWriter) (T, bool)

func CastReader

func CastReader[T io.Reader](reader io.Reader) (T, bool)

func CastWriter

func CastWriter[T io.Writer](writer io.Writer) (T, bool)

func CloseOnHandshakeFailure

func CloseOnHandshakeFailure(reporter any, onClose CloseHandlerFunc, err error) error

func CloseRead

func CloseRead(reader any) error

func CloseWrite

func CloseWrite(writer any) error

func DialParallel

func DialParallel(ctx context.Context, dialer Dialer, network string, destination M.Socksaddr, destinationAddresses []netip.Addr, preferIPv6 bool, fallbackDelay time.Duration) (net.Conn, error)

func DialSerial

func DialSerial(ctx context.Context, dialer Dialer, network string, destination M.Socksaddr, destinationAddresses []netip.Addr) (net.Conn, error)

func IsPublicAddr

func IsPublicAddr(addr netip.Addr) bool

func IsUnsafeWriter

func IsUnsafeWriter(writer any) bool

func IsVirtual

func IsVirtual(addr netip.Addr) bool

func ListenSerial

func ListenSerial(ctx context.Context, dialer Dialer, destination M.Socksaddr, destinationAddresses []netip.Addr) (net.PacketConn, netip.Addr, error)

func LocalAddrs

func LocalAddrs() ([]netip.Addr, error)

func LocalPublicAddrs

func LocalPublicAddrs() ([]netip.Addr, error)

func NetworkName

func NetworkName(network string) string

func PutPacketBuffer

func PutPacketBuffer(packet *PacketBuffer)

func ReleaseMultiPacketBuffer

func ReleaseMultiPacketBuffer(packetBuffers []*PacketBuffer)

func ReportConnHandshakeSuccess

func ReportConnHandshakeSuccess(reporter any, conn net.Conn) error

func ReportHandshakeFailure

func ReportHandshakeFailure(reporter any, err error) error

func ReportHandshakeSuccess deprecated

func ReportHandshakeSuccess(reporter any) error

Deprecated: use ReportConnHandshakeSuccess/ReportPacketConnHandshakeSuccess instead

func ReportPacketConnHandshakeSuccess

func ReportPacketConnHandshakeSuccess(reporter any, conn net.PacketConn) error

func UnwrapCountPacketReader

func UnwrapCountPacketReader(reader PacketReader, countFunc []CountFunc) (PacketReader, []CountFunc)

func UnwrapCountPacketWriter

func UnwrapCountPacketWriter(writer PacketWriter, countFunc []CountFunc) (PacketWriter, []CountFunc)

func UnwrapReader

func UnwrapReader(reader io.Reader) io.Reader

func UnwrapWriter

func UnwrapWriter(writer io.Writer) io.Writer

Types

type AbstractConn

type AbstractConn interface {
	Close() error
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	SetDeadline(t time.Time) error
	SetReadDeadline(t time.Time) error
	SetWriteDeadline(t time.Time) error
}

type BindPacketConn

type BindPacketConn interface {
	NetPacketConn
	net.Conn
}

type CachedPacketReader

type CachedPacketReader interface {
	ReadCachedPacket() *PacketBuffer
}

type CachedReader

type CachedReader interface {
	ReadCached() *buf.Buffer
}

type CloseHandlerFunc

type CloseHandlerFunc = func(it error)

func AppendClose

func AppendClose(parent CloseHandlerFunc, onClose CloseHandlerFunc) (CloseHandlerFunc, error)

func OnceClose

func OnceClose(onClose CloseHandlerFunc) CloseHandlerFunc

type ConnHandshakeSuccess

type ConnHandshakeSuccess interface {
	ConnHandshakeSuccess(conn net.Conn) error
}

type CountFunc

type CountFunc func(n int64)

func UnwrapCountReader

func UnwrapCountReader(reader io.Reader, countFunc []CountFunc) (io.Reader, []CountFunc)

func UnwrapCountWriter

func UnwrapCountWriter(writer io.Writer, countFunc []CountFunc) (io.Writer, []CountFunc)

type DefaultDialer

type DefaultDialer struct {
	net.Dialer
	net.ListenConfig
}

func (*DefaultDialer) DialContext

func (d *DefaultDialer) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error)

func (*DefaultDialer) DialParallel

func (d *DefaultDialer) DialParallel(ctx context.Context, network string, destination M.Socksaddr, destinationAddresses []netip.Addr) (net.Conn, error)

func (*DefaultDialer) ListenPacket

func (d *DefaultDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error)

type Dialer

type Dialer interface {
	DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error)
	ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error)
}

type EarlyConn

type EarlyConn interface {
	NeedHandshake() bool
}

type ExtendedConn

type ExtendedConn interface {
	ExtendedReader
	ExtendedWriter
	net.Conn
}

type ExtendedReader

type ExtendedReader interface {
	io.Reader
	ReadBuffer(buffer *buf.Buffer) error
}

type ExtendedWriter

type ExtendedWriter interface {
	io.Writer
	WriteBuffer(buffer *buf.Buffer) error
}

type FrontHeadroom

type FrontHeadroom interface {
	FrontHeadroom() int
}

type HandshakeFailure

type HandshakeFailure interface {
	HandshakeFailure(err error) error
}

type HandshakeSuccess

type HandshakeSuccess interface {
	HandshakeSuccess() error
}

type LazyHeadroom

type LazyHeadroom interface {
	LazyHeadroom() bool
}

type NetPacketConn

type NetPacketConn interface {
	PacketConn
	NetPacketReader
	NetPacketWriter
}

type NetPacketReader

type NetPacketReader interface {
	PacketReader
	ReadFrom(p []byte) (n int, addr net.Addr, err error)
}

type NetPacketWriter

type NetPacketWriter interface {
	PacketWriter
	WriteTo(p []byte, addr net.Addr) (n int, err error)
}

type PacketBuffer

type PacketBuffer struct {
	Buffer      *buf.Buffer
	Destination M.Socksaddr
}

func NewPacketBuffer

func NewPacketBuffer() *PacketBuffer

type PacketConn

type PacketConn interface {
	PacketReader
	PacketWriter

	Close() error
	LocalAddr() net.Addr
	SetDeadline(t time.Time) error
	SetReadDeadline(t time.Time) error
	SetWriteDeadline(t time.Time) error
}

type PacketConnHandshakeSuccess

type PacketConnHandshakeSuccess interface {
	PacketConnHandshakeSuccess(conn net.PacketConn) error
}

type PacketReadCounter

type PacketReadCounter interface {
	PacketReader
	UnwrapPacketReader() (PacketReader, []CountFunc)
}

type PacketReadWaitCreator

type PacketReadWaitCreator interface {
	CreateReadWaiter() (PacketReadWaiter, bool)
}

type PacketReadWaiter

type PacketReadWaiter interface {
	ReadWaitable
	WaitReadPacket() (buffer *buf.Buffer, destination M.Socksaddr, err error)
}

type PacketReader

type PacketReader interface {
	ReadPacket(buffer *buf.Buffer) (destination M.Socksaddr, err error)
}

func UnwrapPacketReader

func UnwrapPacketReader(reader PacketReader) PacketReader

type PacketWriteCounter

type PacketWriteCounter interface {
	PacketWriter
	UnwrapPacketWriter() (PacketWriter, []CountFunc)
}

type PacketWriter

type PacketWriter interface {
	WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error
}

func UnwrapPacketWriter

func UnwrapPacketWriter(writer PacketWriter) PacketWriter

type ParallelDialer

type ParallelDialer interface {
	Dialer
	DialParallel(ctx context.Context, network string, destination M.Socksaddr, destinationAddresses []netip.Addr) (net.Conn, error)
}
var SystemDialer ParallelDialer = &DefaultDialer{}

type ReadCloser

type ReadCloser interface {
	CloseRead() error
}

type ReadCounter

type ReadCounter interface {
	io.Reader
	UnwrapReader() (io.Reader, []CountFunc)
}

type ReadWaitCreator

type ReadWaitCreator interface {
	CreateReadWaiter() (ReadWaiter, bool)
}

type ReadWaitOptions

type ReadWaitOptions struct {
	FrontHeadroom int
	RearHeadroom  int
	MTU           int
}

func NewReadWaitOptions

func NewReadWaitOptions(source any, destination any) ReadWaitOptions

func (ReadWaitOptions) Copy

func (o ReadWaitOptions) Copy(buffer *buf.Buffer) *buf.Buffer

func (ReadWaitOptions) NeedHeadroom

func (o ReadWaitOptions) NeedHeadroom() bool

func (ReadWaitOptions) NewBuffer

func (o ReadWaitOptions) NewBuffer() *buf.Buffer

func (ReadWaitOptions) NewPacketBuffer

func (o ReadWaitOptions) NewPacketBuffer() *buf.Buffer

func (ReadWaitOptions) PostReturn

func (o ReadWaitOptions) PostReturn(buffer *buf.Buffer)

type ReadWaitable

type ReadWaitable interface {
	InitializeReadWaiter(options ReadWaitOptions) (needCopy bool)
}

type ReadWaiter

type ReadWaiter interface {
	ReadWaitable
	WaitReadBuffer() (buffer *buf.Buffer, err error)
}

type ReaderWithMTU

type ReaderWithMTU interface {
	ReaderMTU() int
}

type ReaderWithUpstream

type ReaderWithUpstream interface {
	ReaderReplaceable() bool
}

type RearHeadroom

type RearHeadroom interface {
	RearHeadroom() int
}

type TCPConnectionHandler deprecated

type TCPConnectionHandler interface {
	NewConnection(ctx context.Context, conn net.Conn,

		metadata M.Metadata) error
}

Deprecated: Use TCPConnectionHandlerEx instead.

type TCPConnectionHandlerEx

type TCPConnectionHandlerEx interface {
	NewConnectionEx(ctx context.Context, conn net.Conn, source M.Socksaddr, destination M.Socksaddr, onClose CloseHandlerFunc)
}

type ThreadSafePacketReader deprecated

type ThreadSafePacketReader interface {
	ReadPacketThreadSafe() (buffer *buf.Buffer, addr M.Socksaddr, err error)
}

Deprecated: Use ReadWaiter interface instead.

func IsSafePacketReader deprecated

func IsSafePacketReader(reader any) ThreadSafePacketReader

Deprecated: Use ReadWaiter interface instead.

type ThreadSafeReader

type ThreadSafeReader interface {
	// Deprecated: Use ReadWaiter interface instead.
	ReadBufferThreadSafe() (buffer *buf.Buffer, err error)
}

func IsSafeReader deprecated

func IsSafeReader(reader any) ThreadSafeReader

Deprecated: Use ReadWaiter interface instead.

type ThreadUnsafeWriter

type ThreadUnsafeWriter interface {
	WriteIsThreadUnsafe()
}

type TimeoutPacketReader

type TimeoutPacketReader interface {
	PacketReader
	SetReadDeadline(t time.Time) error
}

type UDPConnectionHandler deprecated

type UDPConnectionHandler interface {
	NewPacketConnection(ctx context.Context, conn PacketConn,

		metadata M.Metadata) error
}

Deprecated: Use UDPConnectionHandlerEx instead.

type UDPConnectionHandlerEx

type UDPConnectionHandlerEx interface {
	NewPacketConnectionEx(ctx context.Context, conn PacketConn, source M.Socksaddr, destination M.Socksaddr, onClose CloseHandlerFunc)
}

type UDPHandler deprecated

type UDPHandler interface {
	NewPacket(ctx context.Context, conn PacketConn, buffer *buf.Buffer,

		metadata M.Metadata) error
}

Deprecated: Use UDPHandlerEx instead.

type UDPHandlerEx

type UDPHandlerEx interface {
	NewPacketEx(buffer *buf.Buffer, source M.Socksaddr)
}

type VectorisedPacketWriter

type VectorisedPacketWriter interface {
	WriteVectorisedPacket(buffers []*buf.Buffer, destination M.Socksaddr) error
}

type VectorisedWriter

type VectorisedWriter interface {
	WriteVectorised(buffers []*buf.Buffer) error
}

type WithUpstreamReader

type WithUpstreamReader interface {
	UpstreamReader() any
}

type WithUpstreamWriter

type WithUpstreamWriter interface {
	UpstreamWriter() any
}

type WriteCloser

type WriteCloser interface {
	CloseWrite() error
}

type WriteCounter

type WriteCounter interface {
	io.Writer
	UnwrapWriter() (io.Writer, []CountFunc)
}

type WriterWithMTU

type WriterWithMTU interface {
	WriterMTU() int
}

type WriterWithUpstream

type WriterWithUpstream interface {
	WriterReplaceable() bool
}

Jump to

Keyboard shortcuts

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