adapter

package
v1.19.34-clash.3 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: GPL-3.0 Imports: 33 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	URLTestFailureTimeout  = "timeout"
	URLTestFailureCanceled = "canceled"
	URLTestFailureStatus   = "status"
	URLTestFailureUnknown  = "unknown"
)

Variables

View Source
var ErrNotLibraryNode = fmt.Errorf("the node stays in the configuration's proxies")
View Source
var ErrURLTestDeferred = errors.New("url test deferred: memory admission")
View Source
var UnifiedDelay = atomic.NewBool(false)

Functions

func AppendJSONString

func AppendJSONString(b []byte, s string) []byte

func AppendProxiesJSON

func AppendProxiesJSON(b []byte, proxies map[string]C.Proxy) ([]byte, error)

func AppendProxyJSON

func AppendProxyJSON(b []byte, proxy C.Proxy) ([]byte, error)

func AppendProxySummaryJSON

func AppendProxySummaryJSON(b []byte, proxy C.Proxy) ([]byte, error)

func BuildLibraryNode

func BuildLibraryNode(mapping map[string]any, options ...ProxyOption) (outbound.ProxyAdapter, string, error)

func ClashHealthCounts

func ClashHealthCounts(list C.ProxyList) (alive, dead int)

func ClashMappingNodeName

func ClashMappingNodeName(mapping map[string]any) (string, bool)

func ClashNodeName

func ClashNodeName(value any) (string, bool)

func ClashObserveParsedProxies

func ClashObserveParsedProxies(observer func(outbound.ProxyAdapter)) (stop func())

func CountBuilds

func CountBuilds(count func()) (restore func())

func HeldProxy

func HeldProxy(proxy C.Proxy) C.Proxy

func IsBackgroundProbe

func IsBackgroundProbe(ctx context.Context) bool

func IsLibraryNode

func IsLibraryNode(proxy C.Proxy) bool

func LibraryNodeConfig

func LibraryNodeConfig(mapping map[string]any) (string, error)

func NodeConfigMapping

func NodeConfigMapping(proxy C.Proxy) (mapping map[string]any, ok bool, err error)

func NodeHasRecord

func NodeHasRecord(proxy C.Proxy) bool

func NodeKeepsBuilt

func NodeKeepsBuilt(proxyType string) bool

func NodeLibraryProxies

func NodeLibraryProxies(library *outbound.NodeLibrary, options ...ProxyOption) []C.Proxy

func ParseProxy

func ParseProxy(mapping map[string]any, options ...ProxyOption) (C.Proxy, error)

func PinnedProxy

func PinnedProxy(proxy C.Proxy) C.Proxy

func RunAsProbe

func RunAsProbe(ctx context.Context, proxy C.Proxy, run func(ctx context.Context) error) error

func SetNodeCatalog

func SetNodeCatalog(on bool) (previous bool)

func SetNodeCatalogDirectory

func SetNodeCatalogDirectory(dir string)

func SetURLTestAdmission

func SetURLTestAdmission(f func(ctx context.Context) error)

func SetURLTestFinished

func SetURLTestFinished(f func(ctx context.Context, proxy *Proxy))

func SetURLTestGate

func SetURLTestGate(f func(ctx context.Context) (func(), error))

func WithBackgroundProbe

func WithBackgroundProbe(ctx context.Context) context.Context

func WithURLTestTimeout

func WithURLTestTimeout(ctx context.Context, timeout time.Duration) context.Context

func WriteProxiesJSON

func WriteProxiesJSON(w io.Writer, proxies map[string]C.Proxy, library C.ProxyLibrary) error

func WriteProxiesJSONPage

func WriteProxiesJSONPage(w io.Writer, proxies map[string]C.Proxy, library C.ProxyLibrary, after string, limit int) (string, error)

func WriteProxiesJSONPageFunc

func WriteProxiesJSONPageFunc(w io.Writer, proxies map[string]C.Proxy, library C.ProxyLibrary, after string, limit int,
	appendOne func(b []byte, proxy C.Proxy) ([]byte, error)) (string, error)

Types

type DelayRecords

type DelayRecords interface {
	LastDelay() (C.DelayHistory, bool)
	LastRecord() (record C.DelayHistory, failure *URLTestFailure, ok bool)
	AppendURLDelays(dst []URLDelay) []URLDelay
	DelaySnapshot(dst []URLDelay) (DelaySnapshot, []URLDelay)
}

type DelaySnapshot

type DelaySnapshot struct {
	Alive    bool
	Measured bool
	Record   C.DelayHistory
	Failure  *URLTestFailure
}

type LibraryNodes

type LibraryNodes struct {
	// contains filtered or unexported fields
}

func NewLibraryNodes

func NewLibraryNodes(library *outbound.NodeLibrary, options ...ProxyOption) *LibraryNodes

func (*LibraryNodes) At

func (l *LibraryNodes) At(i int) C.Proxy

func (*LibraryNodes) Group

func (l *LibraryNodes) Group(name string) ([]uint32, bool)

func (*LibraryNodes) Len

func (l *LibraryNodes) Len() int

func (*LibraryNodes) LiveCount

func (l *LibraryNodes) LiveCount() int

func (*LibraryNodes) Lookup

func (l *LibraryNodes) Lookup(name string) (C.Proxy, bool)

func (*LibraryNodes) Proxies

func (l *LibraryNodes) Proxies() []C.Proxy

func (*LibraryNodes) RangeLive

func (l *LibraryNodes) RangeLive(f func(C.Proxy) bool)

func (*LibraryNodes) Rank

func (l *LibraryNodes) Rank(name string) int

func (*LibraryNodes) Sorted

func (l *LibraryNodes) Sorted() C.ProxyList

func (*LibraryNodes) Sweep

func (l *LibraryNodes) Sweep()

type NodeCatalogSession

type NodeCatalogSession struct {
	// contains filtered or unexported fields
}

func NewNodeCatalogSession

func NewNodeCatalogSession() *NodeCatalogSession

func (*NodeCatalogSession) Seal

func (s *NodeCatalogSession) Seal() error

func (*NodeCatalogSession) Stored

func (s *NodeCatalogSession) Stored() (bytes int, mapped bool)

type Proxy

type Proxy struct {
	C.ProxyAdapter
	// contains filtered or unexported fields
}

func NewProxy

func NewProxy(adapter C.ProxyAdapter) *Proxy

func (*Proxy) Adapter

func (p *Proxy) Adapter() C.ProxyAdapter

Adapter implements C.Proxy

func (*Proxy) AliveForTestUrl

func (p *Proxy) AliveForTestUrl(url string) bool

AliveForTestUrl implements C.Proxy

func (*Proxy) AppendURLDelays

func (p *Proxy) AppendURLDelays(dst []URLDelay) []URLDelay

func (*Proxy) DelayHistory

func (p *Proxy) DelayHistory() []C.DelayHistory

DelayHistory implements C.Proxy

func (*Proxy) DelayHistoryForTestUrl

func (p *Proxy) DelayHistoryForTestUrl(url string) []C.DelayHistory

DelayHistoryForTestUrl implements C.Proxy

func (*Proxy) DelaySnapshot

func (p *Proxy) DelaySnapshot(dst []URLDelay) (DelaySnapshot, []URLDelay)

func (*Proxy) DialContext

func (p *Proxy) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, error)

DialContext implements C.ProxyAdapter

func (*Proxy) ExtraDelayHistories

func (p *Proxy) ExtraDelayHistories() map[string]C.ProxyState

ExtraDelayHistories return all delay histories for each test URL implements C.Proxy

func (*Proxy) LastDelay

func (p *Proxy) LastDelay() (record C.DelayHistory, ok bool)

func (*Proxy) LastDelayForTestUrl

func (p *Proxy) LastDelayForTestUrl(url string) (delay uint16)

LastDelayForTestUrl return last history record of the specified URL. if proxy is not alive, return the max value of uint16. implements C.Proxy

func (*Proxy) LastRecord

func (p *Proxy) LastRecord() (record C.DelayHistory, failure *URLTestFailure, ok bool)

func (*Proxy) LastURLTestRecord

func (p *Proxy) LastURLTestRecord(url string) (record C.DelayHistory, alive bool, expected string, ok bool)

func (*Proxy) ListenPacketContext

func (p *Proxy) ListenPacketContext(ctx context.Context, metadata *C.Metadata) (C.PacketConn, error)

ListenPacketContext implements C.ProxyAdapter

func (*Proxy) MarshalJSON

func (p *Proxy) MarshalJSON() ([]byte, error)

MarshalJSON implements C.ProxyAdapter

func (*Proxy) URLTest

func (p *Proxy) URLTest(ctx context.Context, url string, expectedStatus utils.IntRanges[uint16]) (t uint16, err error)

URLTest get the delay for the specified URL implements C.Proxy

func (*Proxy) URLTestOutcome

func (p *Proxy) URLTestOutcome(ctx context.Context, url string, expectedStatus utils.IntRanges[uint16]) (URLTestOutcome, error)

type ProxyOption

type ProxyOption func(opt *proxyOption)

func WithDialerForAPI

func WithDialerForAPI(dialer C.Dialer) ProxyOption

func WithNodeCatalogSession

func WithNodeCatalogSession(session *NodeCatalogSession) ProxyOption

func WithProviderName

func WithProviderName(name string) ProxyOption

func WithTunnelForAPI

func WithTunnelForAPI(tunnel C.Tunnel) ProxyOption

type URLDelay

type URLDelay struct {
	URL      string
	Alive    bool
	Recorded bool
	Record   C.DelayHistory
	Failure  *URLTestFailure
}

type URLTestFailure

type URLTestFailure struct {
	Kind       string
	Errno      string
	Message    string
	HTTPStatus int
	// contains filtered or unexported fields
}

func ClassifyURLTestFailure

func ClassifyURLTestFailure(err error, satisfied bool, status int) *URLTestFailure

type URLTestOutcome

type URLTestOutcome struct {
	Delay      uint16
	Satisfied  bool
	HTTPStatus int
}

type URLTestOutcomeProvider

type URLTestOutcomeProvider interface {
	URLTestOutcome(ctx context.Context, url string, expectedStatus utils.IntRanges[uint16]) (URLTestOutcome, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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