network

package
v0.6.0-alpha.19 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: GPL-2.0 Imports: 11 Imported by: 530

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 added in v0.2.5

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

func CastPacketWriter added in v0.2.5

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

func CastReader added in v0.2.5

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

func CastWriter added in v0.2.5

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

func CloseOnHandshakeFailure

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

func CloseRead added in v0.5.0

func CloseRead(reader any) error

func CloseWrite added in v0.5.0

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 added in v0.2.11

func ReportHandshakeFailure(reporter any, err error) error

func ReportHandshakeSuccess deprecated added in v0.2.11

func ReportHandshakeSuccess(reporter any) error

Deprecated: use ReportConnHandshakeSuccess/ReportPacketConnHandshakeSuccess instead

func ReportPacketConnHandshakeSuccess

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

func UnwrapCountPacketReader added in v0.2.5

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

func UnwrapCountPacketWriter added in v0.2.5

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 added in v0.2.5

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

func OnceClose

func OnceClose(onClose CloseHandlerFunc) CloseHandlerFunc

type ConnHandshakeSuccess

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

type CountFunc added in v0.2.5

type CountFunc func(n int64)

func UnwrapCountReader added in v0.2.5

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

func UnwrapCountWriter added in v0.2.5

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 added in v0.1.8

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 added in v0.2.11

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 added in v0.2.5

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 added in v0.2.5

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

type PacketReadWaitCreator added in v0.2.5

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

type PacketReadWaiter added in v0.2.5

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 added in v0.2.5

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 added in v0.5.0

type ReadCloser interface {
	CloseRead() error
}

type ReadCounter added in v0.2.5

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

type ReadWaitCreator added in v0.2.5

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

type ReadWaitOptions added in v0.3.0

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 added in v0.3.0

func (o ReadWaitOptions) NeedHeadroom() bool

func (ReadWaitOptions) NewBuffer added in v0.3.0

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

func (ReadWaitOptions) NewPacketBuffer added in v0.3.0

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

func (ReadWaitOptions) PostReturn added in v0.3.0

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

type ReadWaitable added in v0.3.0

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

type ReadWaiter added in v0.2.5

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 added in v0.5.0

type WriteCloser interface {
	CloseWrite() error
}

type WriteCounter added in v0.2.5

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