constant

package
v1.19.8 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: GPL-3.0 Imports: 16 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

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,
}

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)

	if _, err = os.Stat(homeDir); err != nil {
		if configHome, ok := os.LookupEnv("XDG_CONFIG_HOME"); ok {
			homeDir = P.Join(configHome, Name)
		}
	}
	return &path{homeDir: homeDir, configFile: "config.yaml"}
}()

Path is used to get the configuration path

on Unix systems, `$HOME/.config/clash`. on Windows, `%USERPROFILE%/.config/clash`.

Functions

func SetConfig added in v1.19.7

func SetConfig(file string)

SetConfig is used to set the configuration file

func SetHomeDir added in v1.19.7

func SetHomeDir(root string)

SetHomeDir is used to set the configuration path

Types

type AdapterType added in v0.5.0

type AdapterType int

AdapterType is enum of adapter type

const (
	Direct AdapterType = iota
	Reject

	Shadowsocks
	ShadowsocksR
	Snell
	Socks5
	Http
	Vless
	Vmess
	Trojan

	Relay
	Selector
	Fallback
	URLTest
	LoadBalance
)

Adapter Type

func (AdapterType) String added in v0.5.0

func (at AdapterType) String() string

type Chain added in v1.19.7

type Chain []string

func (Chain) Last added in v1.19.7

func (c Chain) Last() string

func (Chain) String added in v1.19.7

func (c Chain) String() string

type Conn added in v1.19.7

type Conn interface {
	net.Conn
	Connection
}

type ConnContext added in v1.19.7

type ConnContext interface {
	PlainContext
	Metadata() *Metadata
	Conn() net.Conn
}

type Connection added in v1.19.7

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

type DNSMode added in v1.19.7

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

func (DNSMode) MarshalJSON added in v1.19.7

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

MarshalJSON serialize EnhancedMode with json

func (DNSMode) MarshalYAML added in v1.19.7

func (e DNSMode) MarshalYAML() (any, error)

MarshalYAML serialize EnhancedMode with yaml

func (DNSMode) String added in v1.19.7

func (e DNSMode) String() string

func (*DNSMode) UnmarshalJSON added in v1.19.7

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

UnmarshalJSON unserialize EnhancedMode with json

func (*DNSMode) UnmarshalYAML added in v1.19.7

func (e *DNSMode) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML unserialize EnhancedMode with yaml

type DelayHistory added in v1.19.7

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

type Inbound added in v1.19.7

type Inbound inbound

Inbound

func (*Inbound) ToAlias added in v1.19.7

func (i *Inbound) ToAlias() string

func (*Inbound) UnmarshalYAML added in v1.19.7

func (i *Inbound) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements yaml.Unmarshaler

type InboundType added in v1.19.7

type InboundType string
const (
	InboundTypeSocks  InboundType = "socks"
	InboundTypeRedir  InboundType = "redir"
	InboundTypeTproxy InboundType = "tproxy"
	InboundTypeHTTP   InboundType = "http"
	InboundTypeMixed  InboundType = "mixed"
)

type Listener added in v1.19.7

type Listener interface {
	RawAddress() string
	Address() string
	Close() error
}

type Metadata added in v1.19.7

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 added in v1.19.7

func (m *Metadata) AddrType() int

func (*Metadata) Pure added in v1.19.7

func (m *Metadata) Pure() *Metadata

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

func (*Metadata) RemoteAddress added in v1.19.7

func (m *Metadata) RemoteAddress() string

func (*Metadata) Resolved added in v1.19.7

func (m *Metadata) Resolved() bool

func (*Metadata) SourceAddress added in v1.19.7

func (m *Metadata) SourceAddress() string

func (*Metadata) String added in v1.19.7

func (m *Metadata) String() string

func (*Metadata) UDPAddr added in v1.19.7

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

func (*Metadata) Valid added in v1.19.7

func (m *Metadata) Valid() bool

type NetWork

type NetWork int

func (NetWork) MarshalJSON added in v1.19.7

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

func (NetWork) String

func (n NetWork) String() string

type PacketConn added in v1.19.7

type PacketConn interface {
	net.PacketConn
	Connection
}

type PacketConnContext added in v1.19.7

type PacketConnContext interface {
	PlainContext
	Metadata() *Metadata
	PacketConn() net.PacketConn
}

type PlainContext added in v1.19.7

type PlainContext interface {
	ID() uuid.UUID
}

type Port added in v1.19.7

type Port uint16

Port is used to compatible with old version

func (Port) MarshalJSON added in v1.19.7

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

func (Port) String added in v1.19.7

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

type Rule interface {
	RuleType() RuleType
	Match(metadata *Metadata) bool
	Adapter() string
	Payload() string
	ShouldResolveIP() bool
	ShouldFindProcess() bool
}

type RuleConfig added in v1.19.7

type RuleConfig string

Rule Config Type String represents a rule type in configuration files.

const (
	RuleConfigDomain        RuleConfig = "DOMAIN"
	RuleConfigDomainSuffix  RuleConfig = "DOMAIN-SUFFIX"
	RuleConfigDomainKeyword RuleConfig = "DOMAIN-KEYWORD"
	RuleConfigGeoIP         RuleConfig = "GEOIP"
	RuleConfigIPCIDR        RuleConfig = "IP-CIDR"
	RuleConfigIPCIDR6       RuleConfig = "IP-CIDR6"
	RuleConfigSrcIPCIDR     RuleConfig = "SRC-IP-CIDR"
	RuleConfigSrcPort       RuleConfig = "SRC-PORT"
	RuleConfigDstPort       RuleConfig = "DST-PORT"
	RuleConfigInboundPort   RuleConfig = "INBOUND-PORT"
	RuleConfigProcessName   RuleConfig = "PROCESS-NAME"
	RuleConfigProcessPath   RuleConfig = "PROCESS-PATH"
	RuleConfigIPSet         RuleConfig = "IPSET"
	RuleConfigRuleSet       RuleConfig = "RULE-SET"
	RuleConfigScript        RuleConfig = "SCRIPT"
	RuleConfigMatch         RuleConfig = "MATCH"
)

type RuleType

type RuleType int
const (
	Domain RuleType = iota
	DomainSuffix
	DomainKeyword
	GEOIP
	IPCIDR
	SrcIPCIDR
	SrcPort
	DstPort
	InboundPort
	Process
	ProcessPath
	IPSet
	MATCH
)

Rule Type

func (RuleType) String added in v0.5.0

func (rt RuleType) String() string

type Type added in v1.19.7

type Type int

func (Type) MarshalJSON added in v1.19.7

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

func (Type) String added in v1.19.7

func (t Type) String() string

type UDPPacket added in v1.19.7

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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