netapi

package
v0.3.1-rc.11 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DiscardNetConn net.Conn = &DiscardConn{}
View Source
var DiscardNetPacketConn net.PacketConn = &DiscardPacketConn{}
View Source
var ErrBlocked = errors.New("BLOCK")

Functions

func Get

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

func NewBlockError

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

func NewStore

func NewStore(ctx context.Context) context.Context

func PaseNetwork

func PaseNetwork(s string) statistic.Type

func Value

func Value[T any](s interface{ Value(any) (any, bool) }, k any, Default T) T

Types

type Address

type Address interface {
	// Hostname return hostname of address, eg: www.example.com, 127.0.0.1, ff::ff
	Hostname() string
	// 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) (netip.AddrPort, error)
	UDPAddr(context.Context) (*net.UDPAddr, error)
	TCPAddr(context.Context) (*net.TCPAddr, error)
	// Port return port of address
	Port() Port
	// Type return type of address, domain or ip
	Type() Type
	NetworkType() statistic.Type

	net.Addr

	// WithResolver will use call IP(), IPHost(), UDPAddr(), TCPAddr()
	// return the current resolver is applied, if can't apply return false
	WithResolver(_ Resolver, canCover bool) bool
	PreferIPv6(b bool)
	// OverrideHostname clone address(exclude Values) and change hostname
	OverrideHostname(string) Address
	OverridePort(Port) Address
}
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

type CurrentKey

type CurrentKey struct{}

type DNSHandler

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

type DestinationKey

type DestinationKey struct{}

func (DestinationKey) String

func (DestinationKey) String() string

type Discard

type Discard struct{ EmptyDispatch }

func (Discard) Conn

func (Discard) PacketConn

func (Discard) PacketConn(context.Context, Address) (net.PacketConn, error)

type DiscardConn

type DiscardConn struct{}

func (*DiscardConn) Close

func (*DiscardConn) Close() error

func (*DiscardConn) LocalAddr

func (*DiscardConn) LocalAddr() net.Addr

func (*DiscardConn) Read

func (*DiscardConn) Read(b []byte) (n int, err error)

func (*DiscardConn) RemoteAddr

func (*DiscardConn) RemoteAddr() net.Addr

func (*DiscardConn) SetDeadline

func (*DiscardConn) SetDeadline(t time.Time) error

func (*DiscardConn) SetReadDeadline

func (*DiscardConn) SetReadDeadline(t time.Time) error

func (*DiscardConn) SetWriteDeadline

func (*DiscardConn) SetWriteDeadline(t time.Time) error

func (*DiscardConn) Write

func (*DiscardConn) Write(b []byte) (n int, err error)

type DiscardPacketConn

type DiscardPacketConn struct{}

func (*DiscardPacketConn) Close

func (*DiscardPacketConn) Close() error

func (*DiscardPacketConn) LocalAddr

func (*DiscardPacketConn) LocalAddr() net.Addr

func (*DiscardPacketConn) ReadFrom

func (*DiscardPacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)

func (*DiscardPacketConn) SetDeadline

func (*DiscardPacketConn) SetDeadline(t time.Time) error

func (*DiscardPacketConn) SetReadDeadline

func (*DiscardPacketConn) SetReadDeadline(t time.Time) error

func (*DiscardPacketConn) SetWriteDeadline

func (*DiscardPacketConn) SetWriteDeadline(t time.Time) error

func (*DiscardPacketConn) WriteTo

func (*DiscardPacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error)

type DomainAddr

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

func (*DomainAddr) AddrPort

func (d *DomainAddr) AddrPort(ctx context.Context) (netip.AddrPort, error)

func (*DomainAddr) Hostname

func (d *DomainAddr) Hostname() string

func (*DomainAddr) IP

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

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) String

func (d *DomainAddr) String() string

func (*DomainAddr) TCPAddr

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

func (*DomainAddr) Type

func (d *DomainAddr) Type() Type

func (*DomainAddr) UDPAddr

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

func (DomainAddr) WithResolver

func (d DomainAddr) WithResolver(resolver Resolver, canCover bool) bool

type EmptyDispatch

type EmptyDispatch struct{}

func (EmptyDispatch) Dispatch

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

type ErrorResolver

type ErrorResolver func(domain string) error

func (ErrorResolver) Close

func (e ErrorResolver) Close() error

func (ErrorResolver) Do

func (ErrorResolver) LookupIP

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

func (ErrorResolver) Record

func (e ErrorResolver) Record(_ context.Context, domain string, _ dnsmessage.Type) ([]net.IP, uint32, error)

type FakeIPKey

type FakeIPKey struct{}

func (FakeIPKey) String

func (FakeIPKey) String() string

type Handler

type Handler interface {
	StreamHandler
	PacketHandler
}

type IPAddrPort

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

func (*IPAddrPort) AddrPort

func (d *IPAddrPort) AddrPort(context.Context) (netip.AddrPort, error)

func (*IPAddrPort) Hostname

func (d *IPAddrPort) Hostname() string

func (*IPAddrPort) IP

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

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) String

func (d *IPAddrPort) String() string

func (*IPAddrPort) TCPAddr

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

func (*IPAddrPort) Type

func (d *IPAddrPort) Type() Type

func (*IPAddrPort) UDPAddr

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

func (IPAddrPort) WithResolver

func (d IPAddrPort) WithResolver(resolver Resolver, canCover bool) bool

type InboundKey

type InboundKey struct{}

func (InboundKey) String

func (InboundKey) String() string

type Packet

type Packet struct {
	Src       net.Addr
	Dst       Address
	WriteBack func(b []byte, addr net.Addr) (int, error)
	Payload   []byte
}

type PacketHandler

type PacketHandler interface {
	Packet(ctx context.Context, pack *Packet)
}

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 Proxy

type Proxy interface {
	StreamProxy
	PacketProxy
	Dispatch(context.Context, Address) (Address, error)
}
var DiscardProxy Proxy = &Discard{}

func NewErrProxy

func NewErrProxy(err error) Proxy

type Resolver

type Resolver interface {
	LookupIP(ctx context.Context, domain string) ([]net.IP, error)
	Record(ctx context.Context, domain string, _ dnsmessage.Type) (_ []net.IP, ttl uint32, err error)
	Do(ctx context.Context, domain string, raw []byte) ([]byte, error)
	io.Closer
}
var Bootstrap Resolver = &System{}

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 StreamHandler

type StreamHandler interface {
	Stream(ctx context.Context, _ *StreamMeta)
}

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 System

type System struct{ DisableIPv6 bool }

func (*System) Close

func (d *System) Close() error

func (*System) Do

func (d *System) Do(context.Context, string, []byte) ([]byte, error)

func (*System) LookupIP

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

func (*System) Record

func (d *System) Record(ctx context.Context, domain string, t dnsmessage.Type) ([]net.IP, uint32, error)

type Type

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

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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