netapi

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: MIT Imports: 22 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DialHappyEyeballs added in v0.3.5

func DialHappyEyeballs(ctx context.Context, addr Address) (net.Conn, error)

func IsBlockError added in v0.3.6

func IsBlockError(err error) bool

func LogLevel added in v0.3.6

func LogLevel(err error) slog.Level

func LookupIP added in v0.3.6

func LookupIP(ctx context.Context, addr Address) ([]net.IP, error)

func MergeBufioReaderConn added in v0.3.3

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

func NewMultipleReaderConn

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

func NewPrefixBytesConn

func NewPrefixBytesConn(c net.Conn, onPop func([]byte), prefix ...[]byte) net.Conn

func ResolveTCPAddr added in v0.3.6

func ResolveTCPAddr(ctx context.Context, addr Address) (*net.TCPAddr, error)

func ResolveUDPAddr added in v0.3.6

func ResolveUDPAddr(ctx context.Context, addr Address) (*net.UDPAddr, error)

func ResolverAddrPort added in v0.3.6

func ResolverAddrPort(ctx context.Context, addr Address) (netip.AddrPort, error)

func ResolverIP added in v0.3.6

func ResolverIP(ctx context.Context, addr Address) (net.IP, error)

Types

type Accepter added in v0.3.5

type Accepter interface{ Server }

type Address

type Address interface {
	// Hostname return hostname of address, eg: www.example.com, 127.0.0.1, ff::ff
	Hostname() string
	// Port return port of address
	Port() uint16
	// IsFqdn return true if address is FQDN
	// not fqdn must impl [IPAddress]
	IsFqdn() bool
	net.Addr
}
var EmptyAddr Address = &DomainAddr{}

func ParseAddress

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

func ParseAddressPort

func ParseAddressPort(network string, addr string, port uint16) (ad Address)

func ParseDomainPort added in v0.3.5

func ParseDomainPort(network string, addr string, port uint16) (ad Address)

func ParseIPAddrPort added in v0.3.5

func ParseIPAddrPort(net string, ip net.IP, port uint16) Address

func ParseSysAddr

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

type ChannelStreamListener added in v0.3.6

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

func NewChannelStreamListener added in v0.3.6

func NewChannelStreamListener(addr net.Addr) *ChannelStreamListener

func (*ChannelStreamListener) Accept added in v0.3.6

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

func (*ChannelStreamListener) Addr added in v0.3.6

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

func (*ChannelStreamListener) Close added in v0.3.6

func (c *ChannelStreamListener) Close() error

func (*ChannelStreamListener) NewConn added in v0.3.6

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

type Context added in v0.3.6

type Context struct {
	Source      net.Addr `metrics:"Source"`
	Inbound     net.Addr `metrics:"Inbound"`
	Destination net.Addr `metrics:"Destination"`
	FakeIP      net.Addr `metrics:"FakeIP"`
	Hosts       net.Addr `metrics:"Hosts"`

	context.Context

	DomainString string `metrics:"DOMAIN"`
	IPString     string `metrics:"IP"`
	Tag          string `metrics:"Tag"`
	Hash         string `metrics:"Hash"`

	// sniffy
	Protocol      string `metrics:"Protocol"`
	Process       string `metrics:"Process"`
	TLSServerName string `metrics:"TLS Servername"`
	HTTPHost      string `metrics:"HTTP Host"`

	// dns resolver
	Component string `metrics:"Component"`

	Resolver ContextResolver `metrics:"-"`

	UDPMigrateID uint64 `metrics:"UDP MigrateID"`

	ForceMode bypass.Mode `metrics:"-"`
	SniffMode bypass.Mode `metrics:"-"`
	Mode      bypass.Mode `metrics:"MODE"`
	SkipRoute bool        `metrics:"-"`
}

func GetContext added in v0.3.6

func GetContext(ctx context.Context) *Context

func WithContext added in v0.3.6

func WithContext(ctx context.Context) *Context

func (*Context) Map added in v0.3.6

func (addr *Context) Map() map[string]string

func (*Context) SniffHost added in v0.3.6

func (c *Context) SniffHost() string

func (*Context) Value added in v0.3.6

func (c *Context) Value(key any) any

type ContextResolver added in v0.3.6

type ContextResolver struct {
	Resolver     Resolver
	ResolverSelf Resolver
	Mode         ResolverMode
	SkipResolve  bool `metrics:"-"`
	ForceFakeIP  bool `metrics:"-"`
}

func (ContextResolver) Opts added in v0.3.6

func (r ContextResolver) Opts(reverse bool) []func(*LookupIPOption)

type DNSRawRequest added in v0.3.6

type DNSRawRequest struct {
	WriteBack func([]byte) error
	Question  []byte
	Stream    bool
}

type DNSServer added in v0.3.5

type DNSServer interface {
	Server
	HandleUDP(context.Context, net.PacketConn) error
	HandleTCP(context.Context, net.Conn) error
	Do(context.Context, *DNSRawRequest) error
}
var EmptyDNSServer DNSServer = &emptyDNSServer{}

type DomainAddr

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

func (*DomainAddr) Hostname

func (d *DomainAddr) Hostname() string

func (*DomainAddr) IsFqdn added in v0.3.4

func (d *DomainAddr) IsFqdn() bool

func (*DomainAddr) Network

func (d *DomainAddr) Network() string

func (*DomainAddr) Port

func (d *DomainAddr) Port() uint16

func (*DomainAddr) String

func (d *DomainAddr) String() string

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 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 Handler

type Handler interface {
	HandleStream(*StreamMeta)
	HandlePacket(*Packet)
}

type IPAddr added in v0.3.5

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

func (*IPAddr) Hostname added in v0.3.5

func (d *IPAddr) Hostname() string

func (*IPAddr) IP added in v0.3.5

func (d *IPAddr) IP() net.IP

func (*IPAddr) IsFqdn added in v0.3.5

func (d *IPAddr) IsFqdn() bool

func (*IPAddr) Network added in v0.3.5

func (d *IPAddr) Network() string

func (*IPAddr) Port added in v0.3.5

func (d *IPAddr) Port() uint16

func (*IPAddr) String added in v0.3.5

func (d *IPAddr) String() string

func (*IPAddr) WithZone added in v0.3.6

func (d *IPAddr) WithZone(zone string)

type IPAddress added in v0.3.6

type IPAddress interface {
	Address
	IP() net.IP
	WithZone(zone string)
}

type Listener added in v0.3.3

type Listener interface {
	PacketListener
	StreamListener
	Server
}

func NewListener added in v0.3.6

func NewListener(s net.Listener, p PacketListener) 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 {
	Mode ResolverMode
}

type Packet

type Packet struct {
	Src       net.Addr
	Dst       Address
	WriteBack WriteBack
	Payload   []byte
	MigrateID uint64
}

func (*Packet) Clone added in v0.3.6

func (p *Packet) Clone() *Packet

type PacketListener added in v0.3.6

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

type PacketProxy

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

type PrefixBytesConn added in v0.3.6

type PrefixBytesConn struct {
	net.Conn
	// contains filtered or unexported fields
}

func (*PrefixBytesConn) Close added in v0.3.6

func (c *PrefixBytesConn) Close() error

type ProcessDumper added in v0.3.5

type ProcessDumper interface {
	ProcessName(network string, src, dst Address) (string, error)
}

type Proxy

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

func NewErrProxy

func NewErrProxy(err error) Proxy

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 = InternetResolver
var InternetResolver Resolver = NewSystemResolver("8.8.8.8:53", "1.1.1.1:53", "223.5.5.5:53", "114.114.114.114:53")

type ResolverMode added in v0.3.6

type ResolverMode int
const (
	ResolverModeNoSpecified ResolverMode = iota
	ResolverModePreferIPv6
	ResolverModePreferIPv4
)

type Server

type Server interface {
	io.Closer
}

type StreamListener added in v0.3.6

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

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 {
	// contains filtered or unexported fields
}

func NewSystemResolver added in v0.3.4

func NewSystemResolver(host ...string) *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 WriteBack added in v0.3.3

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

Jump to

Keyboard shortcuts

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