constant

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTCPTimeout = 5 * time.Second
	DefaultUDPTimeout = DefaultTCPTimeout
	DefaultTLSTimeout = DefaultTCPTimeout
)
View Source
const (
	TCP NetWork = iota
	UDP

	HTTP Type = iota
	HTTPCONNECT
	SOCKS4
	SOCKS5
	REDIR
	TPROXY
	TUNNEL
)

Socks addr type

Variables

View Source
var DNSModeMapping = map[string]DNSMode{
	DNSNormal.String(): DNSNormal,
	DNSFakeIP.String(): DNSFakeIP,
}

DNSModeMapping is a mapping for EnhancedMode enum

Functions

This section is empty.

Types

type AdapterType

type AdapterType int

AdapterType is enum of adapter type

const (
	Direct AdapterType = iota
	Reject

	Shadowsocks
	ShadowsocksR
	Snell
	Socks5
	Http
	Vmess
	Trojan
	Vless

	Relay
	Selector
	Fallback
	URLTest
	LoadBalance
)

Adapter Type

func (AdapterType) String

func (at AdapterType) String() string

type Chain

type Chain []string

func (Chain) Last

func (c Chain) Last() string

func (Chain) String

func (c Chain) String() string

type Conn

type Conn interface {
	net.Conn
	Connection
}

type Connection

type Connection interface {
	Chains() Chain
	AppendToChains(adapter ProxyAdapter)
}

type DNSMode

type DNSMode int
const (
	DNSNormal DNSMode = iota
	DNSFakeIP
	DNSMapping
)

func (DNSMode) MarshalJSON

func (e DNSMode) MarshalJSON() ([]byte, error)

MarshalJSON serialize EnhancedMode with json

func (DNSMode) MarshalYAML

func (e DNSMode) MarshalYAML() (interface{}, error)

MarshalYAML serialize EnhancedMode with yaml

func (DNSMode) String

func (e DNSMode) String() string

func (*DNSMode) UnmarshalJSON

func (e *DNSMode) UnmarshalJSON(data []byte) error

UnmarshalJSON unserialize EnhancedMode with json

func (*DNSMode) UnmarshalYAML

func (e *DNSMode) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unserialize EnhancedMode with yaml

type DNSPrefer added in v0.0.2

type DNSPrefer int
const (
	DualStack DNSPrefer = iota
	IPv4Only
	IPv6Only
	IPv4Prefer
	IPv6Prefer
)

func NewDNSPrefer added in v0.0.2

func NewDNSPrefer(prefer string) DNSPrefer

func (DNSPrefer) String added in v0.0.2

func (d DNSPrefer) String() string

type DelayHistory

type DelayHistory struct {
	Time      time.Time `json:"time"`
	Delay     uint16    `json:"delay"`
	MeanDelay uint16    `json:"meanDelay"`
}

type Metadata

type Metadata struct {
	NetWork      NetWork `json:"network"`
	Type         Type    `json:"type"`
	SrcIP        net.IP  `json:"sourceIP"`
	DstIP        net.IP  `json:"destinationIP"`
	SrcPort      Port    `json:"sourcePort"`
	DstPort      Port    `json:"destinationPort"`
	Host         string  `json:"host"`
	DNSMode      DNSMode `json:"dnsMode"`
	ProcessPath  string  `json:"processPath"`
	SpecialProxy string  `json:"specialProxy"`

	OriginDst netip.AddrPort `json:"-"`
}

Metadata is used to store connection address

func (*Metadata) AddrType

func (m *Metadata) AddrType() int

func (*Metadata) Pure

func (m *Metadata) Pure() *Metadata

Pure is used to solve unexpected behavior when dialing proxy connection in DNSMapping mode.

func (*Metadata) RemoteAddress

func (m *Metadata) RemoteAddress() string

func (*Metadata) Resolved

func (m *Metadata) Resolved() bool

func (*Metadata) SourceAddress

func (m *Metadata) SourceAddress() string

func (*Metadata) String

func (m *Metadata) String() string

func (*Metadata) UDPAddr

func (m *Metadata) UDPAddr() *net.UDPAddr

func (*Metadata) Valid

func (m *Metadata) Valid() bool

type NetWork

type NetWork int

func (NetWork) MarshalJSON

func (n NetWork) MarshalJSON() ([]byte, error)

func (NetWork) String

func (n NetWork) String() string

type PacketConn

type PacketConn interface {
	net.PacketConn
	Connection
}

type Port

type Port uint16

Port is used to compatible with old version

func (Port) MarshalJSON

func (n Port) MarshalJSON() ([]byte, error)

func (Port) String

func (n Port) String() string

type Proxy

type Proxy interface {
	ProxyAdapter
	Alive() bool
	DelayHistory() []DelayHistory
	LastDelay() uint16
	URLTest(ctx context.Context, url string) (uint16, uint16, error)

	// Deprecated: use DialContext instead.
	Dial(metadata *Metadata) (Conn, error)

	// Deprecated: use DialPacketConn instead.
	DialUDP(metadata *Metadata) (PacketConn, error)
}

type ProxyAdapter

type ProxyAdapter interface {
	Name() string
	Type() AdapterType
	Addr() string
	SupportUDP() bool
	MarshalJSON() ([]byte, error)

	// StreamConn wraps a protocol around net.Conn with Metadata.
	//
	// Examples:
	//	conn, _ := net.DialContext(context.Background(), "tcp", "host:port")
	//	conn, _ = adapter.StreamConn(conn, metadata)
	//
	// It returns a constant.Conn with protocol which start with
	// a new session (if any)
	StreamConn(c net.Conn, metadata *Metadata) (net.Conn, error)

	// DialContext return a constant.Conn with protocol which
	// contains multiplexing-related reuse logic (if any)
	DialContext(ctx context.Context, metadata *Metadata, opts ...dialer.Option) (Conn, error)
	ListenPacketContext(ctx context.Context, metadata *Metadata, opts ...dialer.Option) (PacketConn, error)

	// Unwrap extracts the proxy from a proxy-group. It returns nil when nothing to extract.
	Unwrap(metadata *Metadata) Proxy
}

type Type

type Type int

func (Type) MarshalJSON

func (t Type) MarshalJSON() ([]byte, error)

func (Type) String

func (t Type) String() string

type UDPPacket

type UDPPacket interface {
	// Data get the payload of UDP Packet
	Data() []byte

	// WriteBack writes the payload with source IP/Port equals addr
	// - variable source IP/Port is important to STUN
	// - if addr is not provided, WriteBack will write out UDP packet with SourceIP/Port equals to original Target,
	//   this is important when using Fake-IP.
	WriteBack(b []byte, addr net.Addr) (n int, err error)

	// Drop call after packet is used, could recycle buffer in this function.
	Drop()

	// LocalAddr returns the source IP/Port of packet
	LocalAddr() net.Addr
}

UDPPacket contains the data of UDP packet, and offers control/info of UDP packet's source

Jump to

Keyboard shortcuts

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