proxy

package
v0.3.1-rc.7 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 16 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 NewBlockError

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

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)
	// 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 cover return false
	WithResolver(_ dns.DNS, canCover bool) bool
	// OverrideHostname clone address(exclude Values) and change hostname
	OverrideHostname(string) Address
	OverridePort(Port) Address

	UDPAddr(context.Context) (*net.UDPAddr, error)
	TCPAddr(context.Context) (*net.TCPAddr, error)

	WithValue(key, value any)
	Value(key any) (any, bool)
	RangeValue(func(k, v any) 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

type CurrentKey

type CurrentKey struct{}

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

func (s DomainAddr) RangeValue(f func(k, v any) bool)

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

func (s DomainAddr) Value(key any) (any, bool)

func (DomainAddr) WithResolver

func (d DomainAddr) WithResolver(resolver dns.DNS, canCover bool) bool

func (DomainAddr) WithValue

func (s DomainAddr) WithValue(key, value any)

type EmptyDispatch

type EmptyDispatch struct{}

func (EmptyDispatch) Dispatch

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

type FakeIPKey

type FakeIPKey struct{}

func (FakeIPKey) String

func (FakeIPKey) String() string

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

func (s IPAddrPort) RangeValue(f func(k, v any) bool)

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

func (s IPAddrPort) Value(key any) (any, bool)

func (IPAddrPort) WithResolver

func (d IPAddrPort) WithResolver(resolver dns.DNS, canCover bool) bool

func (IPAddrPort) WithValue

func (s IPAddrPort) WithValue(key, value any)

type InboundKey

type InboundKey struct{}

func (InboundKey) String

func (InboundKey) String() string

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 SourceKey

type SourceKey struct{}

func (SourceKey) String

func (SourceKey) String() string

type StreamProxy

type StreamProxy interface {
	Conn(context.Context, Address) (net.Conn, 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