Documentation ¶
Index ¶
- Constants
- Variables
- func SetConfig(file string)
- func SetHomeDir(root string)
- type AdapterType
- type Chain
- type Conn
- type ConnContext
- type Connection
- type DNSMode
- type DelayHistory
- type Listener
- type Metadata
- type NetWork
- type PacketConn
- type PacketConnContext
- type PlainContext
- type Proxy
- type ProxyAdapter
- type Rule
- type RuleType
- type Type
- type UDPPacket
Constants ¶
View Source
const ( DefaultTCPTimeout = 5 * time.Second DefaultUDPTimeout = DefaultTCPTimeout )
View Source
const ( AtypIPv4 = 1 AtypDomainName = 3 AtypIPv6 = 4 TCP NetWork = iota UDP HTTP Type = iota HTTPCONNECT SOCKS4 SOCKS5 REDIR TPROXY )
Socks addr type
View Source
const Name = "clash"
Variables ¶
View Source
var ( Version = "unknown version" BuildTime = "unknown time" )
View Source
var DNSModeMapping = map[string]DNSMode{ DNSNormal.String(): DNSNormal, DNSFakeIP.String(): DNSFakeIP, DNSMapping.String(): DNSMapping, }
DNSModeMapping is a mapping for EnhancedMode enum
View Source
var Path = func() *path { homeDir, err := os.UserHomeDir() if err != nil { homeDir, _ = os.Getwd() } homeDir = P.Join(homeDir, ".config", Name) return &path{homeDir: homeDir, configFile: "config.yaml"} }()
Path is used to get the configuration path
Functions ¶
Types ¶
type AdapterType ¶
type AdapterType int
AdapterType is enum of adapter type
const ( Direct AdapterType = iota Reject Shadowsocks ShadowsocksR Snell Socks5 Http Vmess Trojan Relay Selector Fallback URLTest LoadBalance )
Adapter Type
func (AdapterType) String ¶
func (at AdapterType) String() string
type Conn ¶
type Conn interface { net.Conn Connection }
type ConnContext ¶
type ConnContext interface { PlainContext Metadata() *Metadata Conn() net.Conn }
type Connection ¶
type Connection interface { Chains() Chain AppendToChains(adapter ProxyAdapter) }
type DNSMode ¶
type DNSMode int
func (DNSMode) MarshalJSON ¶
MarshalJSON serialize EnhancedMode with json
func (DNSMode) MarshalYAML ¶
MarshalYAML serialize EnhancedMode with yaml
func (*DNSMode) UnmarshalJSON ¶
UnmarshalJSON unserialize EnhancedMode with json
func (*DNSMode) UnmarshalYAML ¶
UnmarshalYAML unserialize EnhancedMode with yaml
type DelayHistory ¶
type Metadata ¶
type Metadata struct { NetWork NetWork `json:"network"` Type Type `json:"type"` SrcIP net.IP `json:"sourceIP"` DstIP net.IP `json:"destinationIP"` SrcPort string `json:"sourcePort"` DstPort string `json:"destinationPort"` AddrType int `json:"-"` Host string `json:"host"` DNSMode DNSMode `json:"dnsMode"` }
Metadata is used to store connection address
func (*Metadata) Pure ¶
Pure is used to solve unexpected behavior when dialing proxy connection in DNSMapping mode.
func (*Metadata) RemoteAddress ¶
func (*Metadata) SourceAddress ¶
type PacketConn ¶
type PacketConn interface { net.PacketConn Connection }
type PacketConnContext ¶
type PacketConnContext interface { PlainContext Metadata() *Metadata PacketConn() net.PacketConn }
type PlainContext ¶
type Proxy ¶
type Proxy interface { ProxyAdapter Alive() bool DelayHistory() []DelayHistory LastDelay() uint16 URLTest(ctx context.Context, url string) (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 C.Conn with protocol which start with // a new session (if any) StreamConn(c net.Conn, metadata *Metadata) (net.Conn, error) // DialContext return a C.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 RuleType ¶
type RuleType int
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
Source Files ¶
Click to show internal directories.
Click to hide internal directories.