netapi

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyStore = &emptyStore{}
View Source
var ErrBlocked = errors.New("BLOCK")

Functions

func Get

func Get[T any](ctx context.Context, k any) (t T, _ bool)

func GetDefault

func GetDefault[T any](ctx context.Context, k any, Default T) T

func MergeBufioReaderConn added in v0.3.3

func MergeBufioReaderConn(c net.Conn, r *bufio.Reader) (net.Conn, error)

func NewBlockError

func NewBlockError(network statistic.Type, hostname string) error

func NewMultipleReaderConn

func NewMultipleReaderConn(c net.Conn, r io.Reader) net.Conn

func NewPrefixBytesConn

func NewPrefixBytesConn(c net.Conn, prefix ...*pool.Bytes) net.Conn

func NewStore

func NewStore(ctx context.Context) context.Context

func PaseNetwork

func PaseNetwork(s string) statistic.Type

Types

type Address

type Address interface {
	// Hostname return hostname of address, eg: www.example.com, 127.0.0.1, ff::ff
	Hostname() string
	IPs(context.Context) ([]net.IP, error)
	// IP return net.IP, if address is ip else resolve the domain and return one of ips
	IP(context.Context) (net.IP, error)
	AddrPort(context.Context) Result[netip.AddrPort]
	UDPAddr(context.Context) Result[*net.UDPAddr]
	TCPAddr(context.Context) Result[*net.TCPAddr]
	// Port return port of address
	Port() Port
	// Type return type of address, domain or ip
	Type() Type
	NetworkType() statistic.Type

	net.Addr

	SetSrc(AddressSrc)
	// SetResolver will use call IP(), IPHost(), UDPAddr(), TCPAddr()
	SetResolver(_ Resolver)
	PreferIPv6(b bool)
	// OverrideHostname clone address(exclude Values) and change hostname
	OverrideHostname(string) Address
	OverridePort(Port) Address

	IsFqdn() bool
}
var EmptyAddr Address = &emptyAddr{}

func ParseAddrPort

func ParseAddrPort(net statistic.Type, addrPort netip.AddrPort) Address

func ParseAddress

func ParseAddress(network statistic.Type, addr string) (ad Address, _ error)

func ParseAddressPort

func ParseAddressPort(network statistic.Type, addr string, port Port) (ad Address)

func ParseIPAddr

func ParseIPAddr(ad *net.IPAddr) Address

func ParseSysAddr

func ParseSysAddr(ad net.Addr) (Address, error)

func ParseTCPAddress

func ParseTCPAddress(ad *net.TCPAddr) Address

func ParseUDPAddr

func ParseUDPAddr(ad *net.UDPAddr) Address

func ParseUnixAddr

func ParseUnixAddr(ad *net.UnixAddr) Address

func ReadFrom added in v0.3.3

func ReadFrom(pc net.PacketConn) (*pool.Bytes, Address, error)

type AddressSrc added in v0.3.4

type AddressSrc int32
const (
	AddressSrcEmpty AddressSrc = 0
	AddressSrcDNS   AddressSrc = 1
)

type ChannelListener

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

func NewChannelListener

func NewChannelListener(addr net.Addr) *ChannelListener

func (*ChannelListener) Accept

func (c *ChannelListener) Accept() (net.Conn, error)

func (*ChannelListener) Addr

func (c *ChannelListener) Addr() net.Addr

func (*ChannelListener) Close

func (c *ChannelListener) Close() error

func (*ChannelListener) NewConn

func (c *ChannelListener) NewConn(conn net.Conn)

type ChannelProtocolServer added in v0.3.4

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

func NewChannelProtocolServer added in v0.3.4

func NewChannelProtocolServer() *ChannelProtocolServer

func (*ChannelProtocolServer) AcceptPacket added in v0.3.4

func (s *ChannelProtocolServer) AcceptPacket() (*Packet, error)

func (*ChannelProtocolServer) AcceptStream added in v0.3.4

func (s *ChannelProtocolServer) AcceptStream() (*StreamMeta, error)

func (*ChannelProtocolServer) Close added in v0.3.4

func (s *ChannelProtocolServer) Close() error

func (*ChannelProtocolServer) Context added in v0.3.4

func (s *ChannelProtocolServer) Context() context.Context

func (*ChannelProtocolServer) NewPacket added in v0.3.4

func (s *ChannelProtocolServer) NewPacket(packet *Packet) bool

func (*ChannelProtocolServer) NewStream added in v0.3.4

func (s *ChannelProtocolServer) NewStream(stream *StreamMeta) bool

type CurrentKey

type CurrentKey struct{}

type DNSErrCode added in v0.3.3

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

func NewDNSErrCode added in v0.3.3

func NewDNSErrCode(code dnsmessage.RCode) *DNSErrCode

func (*DNSErrCode) As added in v0.3.3

func (d *DNSErrCode) As(err any) bool

func (*DNSErrCode) Code added in v0.3.3

func (d *DNSErrCode) Code() dnsmessage.RCode

func (DNSErrCode) Error added in v0.3.3

func (d DNSErrCode) Error() string

type DNSHandler

type DNSHandler interface {
	Server
	HandleUDP(context.Context, net.PacketConn) error
	HandleTCP(context.Context, net.Conn) error
	Do(context.Context, *pool.Bytes, func([]byte) error) error
}
var EmptyDNSServer DNSHandler = &emptyHandler{}

type DestinationKey

type DestinationKey struct{}

func (DestinationKey) String

func (DestinationKey) String() string

type DomainAddr

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

func (*DomainAddr) AddrPort

func (d *DomainAddr) AddrPort(ctx context.Context) Result[netip.AddrPort]

func (*DomainAddr) Hostname

func (d *DomainAddr) Hostname() string

func (*DomainAddr) IP

func (d *DomainAddr) IP(ctx context.Context) (net.IP, error)

func (*DomainAddr) IPs added in v0.3.4

func (d *DomainAddr) IPs(ctx context.Context) ([]net.IP, error)

func (*DomainAddr) IsFqdn added in v0.3.4

func (d *DomainAddr) IsFqdn() bool

func (DomainAddr) Network

func (d DomainAddr) Network() string

func (DomainAddr) NetworkType

func (d DomainAddr) NetworkType() statistic.Type

func (*DomainAddr) OverrideHostname

func (d *DomainAddr) OverrideHostname(s string) Address

func (*DomainAddr) OverridePort

func (d *DomainAddr) OverridePort(p Port) Address

func (*DomainAddr) Port

func (d *DomainAddr) Port() Port

func (DomainAddr) PreferIPv6

func (d DomainAddr) PreferIPv6(b bool)

func (DomainAddr) Resolver

func (d DomainAddr) Resolver() Resolver

func (DomainAddr) SetResolver added in v0.3.4

func (d DomainAddr) SetResolver(resolver Resolver)

func (DomainAddr) SetSrc added in v0.3.4

func (d DomainAddr) SetSrc(src AddressSrc)

func (*DomainAddr) String

func (d *DomainAddr) String() string

func (*DomainAddr) TCPAddr

func (d *DomainAddr) TCPAddr(ctx context.Context) Result[*net.TCPAddr]

func (*DomainAddr) Type

func (d *DomainAddr) Type() Type

func (*DomainAddr) UDPAddr

func (d *DomainAddr) UDPAddr(ctx context.Context) Result[*net.UDPAddr]

type DropResolver added in v0.3.3

type DropResolver struct{}

func (DropResolver) Close added in v0.3.3

func (e DropResolver) Close() error

func (DropResolver) LookupIP added in v0.3.3

func (e DropResolver) LookupIP(_ context.Context, domain string, opts ...func(*LookupIPOption)) ([]net.IP, error)

func (DropResolver) Raw added in v0.3.3

type DynamicProxy

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

func NewDynamicProxy

func NewDynamicProxy(p Proxy) *DynamicProxy

func (*DynamicProxy) Conn

func (d *DynamicProxy) Conn(ctx context.Context, a Address) (net.Conn, error)

func (*DynamicProxy) Dispatch

func (d *DynamicProxy) Dispatch(ctx context.Context, a Address) (Address, error)

func (*DynamicProxy) PacketConn

func (d *DynamicProxy) PacketConn(ctx context.Context, a Address) (net.PacketConn, error)

func (*DynamicProxy) Set

func (d *DynamicProxy) Set(p Proxy)

type EmptyDispatch

type EmptyDispatch struct{}

func (EmptyDispatch) Dispatch

func (EmptyDispatch) Dispatch(_ context.Context, a Address) (Address, error)

type EmptyPacketListener added in v0.3.3

type EmptyPacketListener struct {
	net.Listener
}

func (EmptyPacketListener) Packet added in v0.3.3

func (*EmptyPacketListener) Stream added in v0.3.3

type ErrorResolver

type ErrorResolver func(domain string) error

func (ErrorResolver) Close

func (e ErrorResolver) Close() error

func (ErrorResolver) LookupIP

func (e ErrorResolver) LookupIP(_ context.Context, domain string, opts ...func(*LookupIPOption)) ([]net.IP, error)

func (ErrorResolver) Raw

type FakeIPKey

type FakeIPKey struct{}

func (FakeIPKey) String

func (FakeIPKey) String() string

type ForceFakeIP

type ForceFakeIP struct{}

type IPAddrPort

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

func (*IPAddrPort) AddrPort

func (*IPAddrPort) Hostname

func (d *IPAddrPort) Hostname() string

func (*IPAddrPort) IP

func (d *IPAddrPort) IP(context.Context) (net.IP, error)

func (*IPAddrPort) IPs added in v0.3.4

func (d *IPAddrPort) IPs(context.Context) ([]net.IP, error)

func (*IPAddrPort) IsFqdn added in v0.3.4

func (d *IPAddrPort) IsFqdn() bool

func (IPAddrPort) Network

func (d IPAddrPort) Network() string

func (IPAddrPort) NetworkType

func (d IPAddrPort) NetworkType() statistic.Type

func (*IPAddrPort) OverrideHostname

func (d *IPAddrPort) OverrideHostname(s string) Address

func (*IPAddrPort) OverridePort

func (d *IPAddrPort) OverridePort(p Port) Address

func (*IPAddrPort) Port

func (d *IPAddrPort) Port() Port

func (IPAddrPort) PreferIPv6

func (d IPAddrPort) PreferIPv6(b bool)

func (IPAddrPort) Resolver

func (d IPAddrPort) Resolver() Resolver

func (IPAddrPort) SetResolver added in v0.3.4

func (d IPAddrPort) SetResolver(resolver Resolver)

func (IPAddrPort) SetSrc added in v0.3.4

func (d IPAddrPort) SetSrc(src AddressSrc)

func (*IPAddrPort) String

func (d *IPAddrPort) String() string

func (*IPAddrPort) TCPAddr

func (d *IPAddrPort) TCPAddr(context.Context) Result[*net.TCPAddr]

func (*IPAddrPort) Type

func (d *IPAddrPort) Type() Type

func (*IPAddrPort) UDPAddr

func (d *IPAddrPort) UDPAddr(context.Context) Result[*net.UDPAddr]

type InboundKey

type InboundKey struct{}

func (InboundKey) String

func (InboundKey) String() string

type Listener added in v0.3.3

type Listener interface {
	Stream(context.Context) (net.Listener, error)
	Packet(context.Context) (net.PacketConn, error)
	Server
}

func NewEmptyPacketListener added in v0.3.3

func NewEmptyPacketListener(lis net.Listener) Listener

type LogConn

type LogConn struct {
	net.Conn
}

func (*LogConn) Read

func (l *LogConn) Read(b []byte) (int, error)

func (*LogConn) SetDeadline

func (l *LogConn) SetDeadline(t time.Time) error

func (*LogConn) SetReadDeadline

func (l *LogConn) SetReadDeadline(t time.Time) error

func (*LogConn) SetWriteDeadline

func (l *LogConn) SetWriteDeadline(t time.Time) error

func (*LogConn) Write

func (l *LogConn) Write(b []byte) (int, error)

type LookupIPOption added in v0.3.4

type LookupIPOption struct {
	OnlyAAAA bool
}

type Packet

type Packet struct {
	Src       net.Addr
	Dst       Address
	WriteBack WriteBack
	Payload   *pool.Bytes
}

type PacketProxy

type PacketProxy interface {
	PacketConn(context.Context, Address) (net.PacketConn, error)
}

type Port

type Port interface {
	Port() uint16
	String() string
}
var EmptyPort Port = PortUint16(0)

func ParsePort

func ParsePort[T constraints.Integer](p T) Port

func ParsePortStr

func ParsePortStr(p string) (Port, error)

type PortUint16

type PortUint16 uint16

func (PortUint16) Port

func (p PortUint16) Port() uint16

func (PortUint16) String

func (p PortUint16) String() string

type PreferIPv6

type PreferIPv6 struct{}

type ProtocolServer added in v0.3.3

type ProtocolServer interface {
	Server
	AcceptStream() (*StreamMeta, error)
	AcceptPacket() (*Packet, error)
}

type Proxy

type Proxy interface {
	StreamProxy
	PacketProxy
	Dispatch(context.Context, Address) (Address, error)
}

func NewErrProxy

func NewErrProxy(err error) Proxy

type Reader added in v0.3.3

type Reader struct {
	io.Reader
}

func NewReader added in v0.3.3

func NewReader(r io.Reader) *Reader

func (*Reader) ReadByte added in v0.3.3

func (r *Reader) ReadByte() (byte, error)

func (*Reader) ReadBytes added in v0.3.3

func (r *Reader) ReadBytes(n int) ([]byte, error)

type Resolver

type Resolver interface {
	LookupIP(ctx context.Context, domain string, opts ...func(*LookupIPOption)) ([]net.IP, error)
	Raw(ctx context.Context, req dnsmessage.Question) (dnsmessage.Message, error)
	io.Closer
}
var Bootstrap Resolver = &SystemResolver{}

type Result added in v0.3.4

type Result[T any] struct {
	V   T
	Err error
}

func NewErrResult added in v0.3.4

func NewErrResult[T any](err error) Result[T]

func NewResult added in v0.3.4

func NewResult[T any](v T) Result[T]

type Server

type Server interface {
	io.Closer
}

type SourceKey

type SourceKey struct{}

func (SourceKey) String

func (SourceKey) String() string

type Store

type Store interface {
	Add(k, v any) Store
	Get(k any) (any, bool)
	Range(func(k, v any) bool)
	Map() map[any]any
}

func StoreFromContext

func StoreFromContext(ctx context.Context) Store

type StreamMeta

type StreamMeta struct {
	Source      net.Addr
	Destination net.Addr
	Inbound     net.Addr

	Src     net.Conn
	Address Address
}

type StreamProxy

type StreamProxy interface {
	Conn(context.Context, Address) (net.Conn, error)
}

type SystemResolver added in v0.3.4

type SystemResolver struct{ DisableIPv6 bool }

func NewSystemResolver added in v0.3.4

func NewSystemResolver(ipv6 bool) *SystemResolver

func (*SystemResolver) Close added in v0.3.4

func (d *SystemResolver) Close() error

func (*SystemResolver) LookupIP added in v0.3.4

func (d *SystemResolver) LookupIP(ctx context.Context, domain string, opts ...func(*LookupIPOption)) ([]net.IP, error)

func (*SystemResolver) Raw added in v0.3.4

type Type

type Type uint8
const (
	FQDN  Type = 1
	IP    Type = 2
	UNIX  Type = 3
	EMPTY Type = 4
)

func (Type) String

func (t Type) String() string

type WrapListener added in v0.3.3

type WrapListener struct {
	Listener
	// contains filtered or unexported fields
}

func ListenWrap added in v0.3.3

func ListenWrap(lis net.Listener, inbound Listener) *WrapListener

func (*WrapListener) Close added in v0.3.3

func (w *WrapListener) Close() error

func (*WrapListener) Stream added in v0.3.3

func (w *WrapListener) Stream(ctx context.Context) (net.Listener, error)

type WriteBack added in v0.3.3

type WriteBack func(b []byte, addr net.Addr) (int, error)

type Writer added in v0.3.3

type Writer struct {
	io.Writer
}

func NewWriter added in v0.3.3

func NewWriter(w io.Writer) *Writer

func (*Writer) WriteByte added in v0.3.3

func (w *Writer) WriteByte(b byte) error

func (*Writer) WriteString added in v0.3.3

func (w *Writer) WriteString(b string) (int, error)

Jump to

Keyboard shortcuts

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