constant

package
v1.18.4 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: GPL-3.0 Imports: 21 Imported by: 8

Documentation

Index

Constants

View Source
const (
	DefaultTCPTimeout = dialer.DefaultTCPTimeout
	DefaultUDPTimeout = dialer.DefaultUDPTimeout
	DefaultDropTime   = 12 * DefaultTCPTimeout
	DefaultTLSTimeout = DefaultTCPTimeout
	DefaultTestURL    = "https://www.gstatic.com/generate_204"
)
View Source
const (
	BpfFSPath = "/sys/fs/bpf/mihomo"

	TcpAutoRedirPort  = 't'<<8 | 'r'<<0
	MihomoTrafficMark = 'c'<<24 | 'l'<<16 | 't'<<8 | 'm'<<0
)
View Source
const Name = "mihomo"

Variables

View Source
var (
	ASNEnable         bool
	GeodataMode       bool
	GeoAutoUpdate     bool
	GeoUpdateInterval int
	GeoIpUrl          string
	MmdbUrl           string
	GeoSiteUrl        string
	ASNUrl            string
)
View Source
var (
	GeositeName = "GeoSite.dat"
	GeoipName   = "GeoIP.dat"
	ASNName     = "ASN.mmdb"
)
View Source
var (
	Meta       = true
	Version    = "1.10.0"
	BuildTime  = "unknown time"
	MihomoName = "mihomo"
)
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 ErrNotSupport = errors.New("no support")
View Source
var Path = func() *path {
	homeDir, err := os.UserHomeDir()
	if err != nil {
		homeDir, _ = os.Getwd()
	}
	allowUnsafePath, _ := strconv.ParseBool(os.Getenv("SKIP_SAFE_PATH_CHECK"))
	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", allowUnsafePath: allowUnsafePath}
}()

Path is used to get the configuration path

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

View Source
var StackTypeMapping = map[string]TUNStack{
	strings.ToLower(TunGvisor.String()): TunGvisor,
	strings.ToLower(TunSystem.String()): TunSystem,
	strings.ToLower(TunMixed.String()):  TunMixed,
}
View Source
var (
	UA string
)

Functions

func SetConfig added in v1.17.0

func SetConfig(file string)

SetConfig is used to set the configuration file

func SetHomeDir added in v1.17.0

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
	RejectDrop
	Compatible
	Pass
	Dns

	Relay
	Selector
	Fallback
	URLTest
	LoadBalance

	Shadowsocks
	ShadowsocksR
	Snell
	Socks5
	Http
	Vmess
	Vless
	Trojan
	Hysteria
	Hysteria2
	WireGuard
	Tuic
	Ssh
)

Adapter Type

func (AdapterType) String added in v0.5.0

func (at AdapterType) String() string

type Chain added in v1.17.0

type Chain []string

func (Chain) Last added in v1.17.0

func (c Chain) Last() string

func (Chain) String added in v1.17.0

func (c Chain) String() string

type Conn added in v1.17.0

type Conn interface {
	N.ExtendedConn
	Connection
}

type ConnContext added in v1.17.0

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

type Connection added in v1.17.0

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

type DNSMode added in v1.17.0

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

func (DNSMode) MarshalJSON added in v1.17.0

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

MarshalJSON serialize EnhancedMode with json

func (DNSMode) MarshalYAML added in v1.17.0

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

MarshalYAML serialize EnhancedMode with yaml

func (DNSMode) String added in v1.17.0

func (e DNSMode) String() string

func (*DNSMode) UnmarshalJSON added in v1.17.0

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

UnmarshalJSON unserialize EnhancedMode with json

func (*DNSMode) UnmarshalYAML added in v1.17.0

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

UnmarshalYAML unserialize EnhancedMode with yaml

type DNSPrefer added in v1.17.0

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

func NewDNSPrefer added in v1.17.0

func NewDNSPrefer(prefer string) DNSPrefer

func (DNSPrefer) String added in v1.17.0

func (d DNSPrefer) String() string

type DelayHistory added in v1.17.0

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

type DelayHistoryStoreType added in v1.17.0

type DelayHistoryStoreType int

type Dialer added in v1.17.0

type Dialer interface {
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
	ListenPacket(ctx context.Context, network, address string, rAddrPort netip.AddrPort) (net.PacketConn, error)
}

type EBpf added in v1.17.0

type EBpf interface {
	Start() error
	Close()
	Lookup(srcAddrPort netip.AddrPort) (socks5.Addr, error)
}

type Group added in v1.17.0

type Group interface {
	URLTest(ctx context.Context, url string, expectedStatus utils.IntRanges[uint16]) (mp map[string]uint16, err error)
	GetProxies(touch bool) []Proxy
	Touch()
}

type HTTPVersion added in v1.17.0

type HTTPVersion string
const (
	// HTTPVersion11 is HTTP/1.1.
	HTTPVersion11 HTTPVersion = "http/1.1"
	// HTTPVersion2 is HTTP/2.
	HTTPVersion2 HTTPVersion = "h2"
	// HTTPVersion3 is HTTP/3.
	HTTPVersion3 HTTPVersion = "h3"
)

type InboundConfig added in v1.17.0

type InboundConfig interface {
	Name() string
	Equal(config InboundConfig) bool
}

type InboundListener added in v1.17.0

type InboundListener interface {
	Name() string
	Listen(tunnel Tunnel) error
	Close() error
	Address() string
	RawAddress() string
	Config() InboundConfig
}

type Listener added in v1.17.0

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

type Metadata added in v1.17.0

type Metadata struct {
	NetWork      NetWork    `json:"network"`
	Type         Type       `json:"type"`
	SrcIP        netip.Addr `json:"sourceIP"`
	DstIP        netip.Addr `json:"destinationIP"`
	DstGeoIP     []string   `json:"destinationGeoIP"` // can be nil if never queried, empty slice if got no result
	DstIPASN     string     `json:"destinationIPASN"`
	SrcPort      uint16     `json:"sourcePort,string"`      // `,string` is used to compatible with old version json output
	DstPort      uint16     `json:"destinationPort,string"` // `,string` is used to compatible with old version json output
	InIP         netip.Addr `json:"inboundIP"`
	InPort       uint16     `json:"inboundPort,string"` // `,string` is used to compatible with old version json output
	InName       string     `json:"inboundName"`
	InUser       string     `json:"inboundUser"`
	Host         string     `json:"host"`
	DNSMode      DNSMode    `json:"dnsMode"`
	Uid          uint32     `json:"uid"`
	Process      string     `json:"process"`
	ProcessPath  string     `json:"processPath"`
	SpecialProxy string     `json:"specialProxy"`
	SpecialRules string     `json:"specialRules"`
	RemoteDst    string     `json:"remoteDestination"`
	DSCP         uint8      `json:"dscp"`

	RawSrcAddr net.Addr `json:"-"`
	RawDstAddr net.Addr `json:"-"`
	// Only domain rule
	SniffHost string `json:"sniffHost"`
}

Metadata is used to store connection address

func (*Metadata) AddrPort added in v1.17.0

func (m *Metadata) AddrPort() netip.AddrPort

func (*Metadata) AddrType added in v1.17.0

func (m *Metadata) AddrType() int

func (*Metadata) Pure added in v1.17.0

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.17.0

func (m *Metadata) RemoteAddress() string

func (*Metadata) Resolved added in v1.17.0

func (m *Metadata) Resolved() bool

func (*Metadata) RuleHost added in v1.17.0

func (m *Metadata) RuleHost() string

func (*Metadata) SetRemoteAddr added in v1.17.0

func (m *Metadata) SetRemoteAddr(addr net.Addr) error

func (*Metadata) SetRemoteAddress added in v1.17.0

func (m *Metadata) SetRemoteAddress(rawAddress string) error

func (*Metadata) SourceAddrPort added in v1.18.0

func (m *Metadata) SourceAddrPort() netip.AddrPort

func (*Metadata) SourceAddress added in v1.17.0

func (m *Metadata) SourceAddress() string

func (*Metadata) SourceDetail added in v1.17.0

func (m *Metadata) SourceDetail() string

func (*Metadata) SourceValid added in v1.17.0

func (m *Metadata) SourceValid() bool

func (*Metadata) String added in v1.17.0

func (m *Metadata) String() string

func (*Metadata) UDPAddr added in v1.17.0

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

func (*Metadata) Valid added in v1.17.0

func (m *Metadata) Valid() bool

type MultiAddrListener added in v1.17.0

type MultiAddrListener interface {
	Close() error
	Config() string
	AddrList() (addrList []net.Addr)
}

type NatTable added in v1.17.0

type NatTable interface {
	Set(key string, e PacketConn, w WriteBackProxy)

	Get(key string) (PacketConn, WriteBackProxy)

	GetOrCreateLock(key string) (*sync.Cond, bool)

	Delete(key string)

	DeleteLock(key string)

	GetForLocalConn(lAddr, rAddr string) *net.UDPConn

	AddForLocalConn(lAddr, rAddr string, conn *net.UDPConn) bool

	RangeForLocalConn(lAddr string, f func(key string, value *net.UDPConn) bool)

	GetOrCreateLockForLocalConn(lAddr string, key string) (*sync.Cond, bool)

	DeleteForLocalConn(lAddr, key string)

	DeleteLockForLocalConn(lAddr, key string)
}

type NetWork

type NetWork int
const (
	TCP NetWork = iota
	UDP
	ALLNet
	InvalidNet = 0xff
)

Socks addr type

func (NetWork) MarshalJSON added in v1.17.0

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

func (NetWork) String

func (n NetWork) String() string

type PacketAdapter added in v1.17.0

type PacketAdapter interface {
	UDPPacket
	Metadata() *Metadata
}

PacketAdapter is a UDP Packet adapter for socks/redir/tun

func NewPacketAdapter added in v1.17.0

func NewPacketAdapter(packet UDPPacket, metadata *Metadata) PacketAdapter

type PacketConn added in v1.17.0

type PacketConn interface {
	N.EnhancePacketConn
	Connection
}

type PacketConnContext added in v1.17.0

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

type PlainContext added in v1.17.0

type PlainContext interface {
	ID() uuid.UUID
}

type Proxy

type Proxy interface {
	ProxyAdapter
	AliveForTestUrl(url string) bool
	DelayHistory() []DelayHistory
	ExtraDelayHistories() map[string]ProxyState
	LastDelayForTestUrl(url string) uint16
	URLTest(ctx context.Context, url string, expectedStatus utils.IntRanges[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
	SupportXUDP() bool
	SupportTFO() bool
	MarshalJSON() ([]byte, error)

	// Deprecated: use DialContextWithDialer and ListenPacketWithDialer instead.
	// StreamConn wraps a protocol around net.Conn with Metadata.
	//
	// Examples:
	//	conn, _ := net.DialContext(context.Background(), "tcp", "host:port")
	//	conn, _ = adapter.StreamConnContext(context.Background(), conn, metadata)
	//
	// It returns a C.Conn with protocol which start with
	// a new session (if any)
	StreamConnContext(ctx context.Context, 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)

	// SupportUOT return UDP over TCP support
	SupportUOT() bool

	SupportWithDialer() NetWork
	DialContextWithDialer(ctx context.Context, dialer Dialer, metadata *Metadata) (Conn, error)
	ListenPacketWithDialer(ctx context.Context, dialer Dialer, metadata *Metadata) (PacketConn, error)

	// IsL3Protocol return ProxyAdapter working in L3 (tell dns module not pass the domain to avoid loopback)
	IsL3Protocol(metadata *Metadata) bool

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

type ProxyState added in v1.18.0

type ProxyState struct {
	Alive   bool           `json:"alive"`
	History []DelayHistory `json:"history"`
}

type Rule

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

type RuleGeoIP added in v1.17.0

type RuleGeoIP interface {
	GetIPMatcher() *router.GeoIPMatcher
}

type RuleGeoSite added in v1.17.0

type RuleGeoSite interface {
	GetDomainMatcher() router.DomainMatcher
}

type RuleGroup added in v1.17.0

type RuleGroup interface {
	GetRecodeSize() int
}

type RuleType

type RuleType int
const (
	Domain RuleType = iota
	DomainSuffix
	DomainKeyword
	DomainRegex
	GEOSITE
	GEOIP
	SrcGEOIP
	IPASN
	SrcIPASN
	IPCIDR
	SrcIPCIDR
	IPSuffix
	SrcIPSuffix
	SrcPort
	DstPort
	InPort
	DSCP
	InUser
	InName
	InType
	Process
	ProcessPath
	RuleSet
	Network
	Uid
	SubRules
	MATCH
	AND
	OR
	NOT
)

Rule Type

func (RuleType) String added in v0.5.0

func (rt RuleType) String() string

type TUNStack added in v1.17.0

type TUNStack int
const (
	TunGvisor TUNStack = iota
	TunSystem
	TunMixed
)

func (TUNStack) MarshalJSON added in v1.17.0

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

MarshalJSON serialize TUNStack with json

func (TUNStack) MarshalYAML added in v1.17.0

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

MarshalYAML serialize TUNStack with yaml

func (TUNStack) String added in v1.17.0

func (e TUNStack) String() string

func (*TUNStack) UnmarshalJSON added in v1.17.0

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

UnmarshalJSON unserialize TUNStack with json

func (*TUNStack) UnmarshalYAML added in v1.17.0

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

UnmarshalYAML unserialize TUNStack with yaml

type Tunnel added in v1.17.0

type Tunnel interface {
	// HandleTCPConn will handle a tcp connection blocking
	HandleTCPConn(conn net.Conn, metadata *Metadata)
	// HandleUDPPacket will handle a udp packet nonblocking
	HandleUDPPacket(packet UDPPacket, metadata *Metadata)
	// NatTable return nat table
	NatTable() NatTable
}

type Type added in v1.17.0

type Type int
const (
	HTTP Type = iota
	HTTPS
	SOCKS4
	SOCKS5
	SHADOWSOCKS
	VMESS
	REDIR
	TPROXY
	TUNNEL
	TUN
	TUIC
	HYSTERIA2
	INNER
)

func ParseType added in v1.17.0

func ParseType(t string) (*Type, error)

func (Type) MarshalJSON added in v1.17.0

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

func (Type) String added in v1.17.0

func (t Type) String() string

type UDPPacket added in v1.17.0

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

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

type UDPPacketInAddr added in v1.17.0

type UDPPacketInAddr interface {
	InAddr() net.Addr
}

type WriteBack added in v1.17.0

type WriteBack interface {
	WriteBack(b []byte, addr net.Addr) (n int, err error)
}

type WriteBackProxy added in v1.17.0

type WriteBackProxy interface {
	WriteBack
	UpdateWriteBack(wb WriteBack)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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