adapter

package
v1.11.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: GPL-2.0 Imports: 29 Imported by: 152

Documentation

Index

Constants

This section is empty.

Variables

Functions

func IsFinalAction

func IsFinalAction(action RuleAction) bool

func LegacyStart

func LegacyStart(starter any, stage StartStage) error

func OutboundTag

func OutboundTag(detour Outbound) string

func OverrideContext added in v1.8.13

func OverrideContext(ctx context.Context) context.Context

func Start

func Start(stage StartStage, services ...Lifecycle) error

func StartNamed

func StartNamed(stage StartStage, services []LifecycleService) error

func UpstreamMetadata deprecated

func UpstreamMetadata(metadata InboundContext) M.Metadata

Deprecated: removed

func WithContext

func WithContext(ctx context.Context, inboundContext *InboundContext) context.Context

Types

type CacheFile added in v1.8.0

type CacheFile interface {
	LifecycleService

	StoreFakeIP() bool
	FakeIPStorage

	StoreRDRC() bool
	dns.RDRCStore

	LoadMode() string
	StoreMode(mode string) error
	LoadSelected(group string) string
	StoreSelected(group string, selected string) error
	LoadGroupExpand(group string) (isExpand bool, loaded bool)
	StoreGroupExpand(group string, expand bool) error
	LoadRuleSet(tag string) *SavedRuleSet
	SaveRuleSet(tag string, set *SavedRuleSet) error
}

type ClashServer

type ClashServer interface {
	LifecycleService
	ConnectionTracker
	Mode() string
	ModeList() []string
	HistoryStorage() *urltest.HistoryStorage
}

type ConnectionHandler

type ConnectionHandler interface {
	NewConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
}

Deprecated

type ConnectionHandlerEx

type ConnectionHandlerEx interface {
	NewConnectionEx(ctx context.Context, conn net.Conn, metadata InboundContext, onClose N.CloseHandlerFunc)
}

type ConnectionHandlerFunc

type ConnectionHandlerFunc = func(ctx context.Context, conn net.Conn, metadata InboundContext) error

Deprecated

type ConnectionHandlerFuncEx

type ConnectionHandlerFuncEx = func(ctx context.Context, conn net.Conn, metadata InboundContext, onClose N.CloseHandlerFunc)

type ConnectionManager

type ConnectionManager interface {
	Lifecycle
	NewConnection(ctx context.Context, this N.Dialer, conn net.Conn, metadata InboundContext, onClose N.CloseHandlerFunc)
	NewPacketConnection(ctx context.Context, this N.Dialer, conn N.PacketConn, metadata InboundContext, onClose N.CloseHandlerFunc)
}

type ConnectionRouter deprecated added in v1.7.0

type ConnectionRouter interface {
	RouteConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
	RoutePacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
}

Deprecated: Use ConnectionRouterEx instead.

type ConnectionRouterEx

type ConnectionRouterEx interface {
	ConnectionRouter
	RouteConnectionEx(ctx context.Context, conn net.Conn, metadata InboundContext, onClose N.CloseHandlerFunc)
	RoutePacketConnectionEx(ctx context.Context, conn N.PacketConn, metadata InboundContext, onClose N.CloseHandlerFunc)
}

type ConnectionTracker

type ConnectionTracker interface {
	RoutedConnection(ctx context.Context, conn net.Conn, metadata InboundContext, matchedRule Rule, matchOutbound Outbound) net.Conn
	RoutedPacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext, matchedRule Rule, matchOutbound Outbound) N.PacketConn
}

type DNSRule

type DNSRule interface {
	Rule
	WithAddressLimit() bool
	MatchAddressLimit(metadata *InboundContext) bool
}

type Endpoint

type Endpoint interface {
	Lifecycle
	Type() string
	Tag() string
	Outbound
}

type EndpointManager

type EndpointManager interface {
	Lifecycle
	Endpoints() []Endpoint
	Get(tag string) (Endpoint, bool)
	Remove(tag string) error
	Create(ctx context.Context, router Router, logger log.ContextLogger, tag string, endpointType string, options any) error
}

type EndpointRegistry

type EndpointRegistry interface {
	option.EndpointOptionsRegistry
	Create(ctx context.Context, router Router, logger log.ContextLogger, tag string, endpointType string, options any) (Endpoint, error)
}

type FakeIPMetadata added in v1.3.0

type FakeIPMetadata struct {
	Inet4Range   netip.Prefix
	Inet6Range   netip.Prefix
	Inet4Current netip.Addr
	Inet6Current netip.Addr
}

func (*FakeIPMetadata) MarshalBinary added in v1.3.0

func (m *FakeIPMetadata) MarshalBinary() (data []byte, err error)

func (*FakeIPMetadata) UnmarshalBinary added in v1.3.0

func (m *FakeIPMetadata) UnmarshalBinary(data []byte) error

type FakeIPStorage added in v1.3.0

type FakeIPStorage interface {
	FakeIPMetadata() *FakeIPMetadata
	FakeIPSaveMetadata(metadata *FakeIPMetadata) error
	FakeIPSaveMetadataAsync(metadata *FakeIPMetadata)
	FakeIPStore(address netip.Addr, domain string) error
	FakeIPStoreAsync(address netip.Addr, domain string, logger logger.Logger)
	FakeIPLoad(address netip.Addr) (string, bool)
	FakeIPLoadDomain(domain string, isIPv6 bool) (netip.Addr, bool)
	FakeIPReset() error
}

type FakeIPStore added in v1.3.0

type FakeIPStore interface {
	Service
	Contains(address netip.Addr) bool
	Create(domain string, isIPv6 bool) (netip.Addr, error)
	Lookup(address netip.Addr) (string, bool)
	Reset() error
}

type FakeIPTransport added in v1.3.0

type FakeIPTransport interface {
	dns.Transport
	Store() FakeIPStore
}

type HTTPStartContext added in v1.10.2

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

func NewHTTPStartContext added in v1.10.2

func NewHTTPStartContext() *HTTPStartContext

func (*HTTPStartContext) Close added in v1.10.2

func (c *HTTPStartContext) Close()

func (*HTTPStartContext) HTTPClient added in v1.10.2

func (c *HTTPStartContext) HTTPClient(detour string, dialer N.Dialer) *http.Client

type HeadlessRule added in v1.8.0

type HeadlessRule interface {
	Match(metadata *InboundContext) bool
	String() string
}

type Inbound

type Inbound interface {
	Lifecycle
	Type() string
	Tag() string
}

type InboundContext

type InboundContext struct {
	Inbound     string
	InboundType string
	IPVersion   uint8
	Network     string
	Source      M.Socksaddr
	Destination M.Socksaddr
	User        string
	Outbound    string

	Protocol     string
	Domain       string
	Client       string
	SniffContext any

	// Deprecated: implement in rule action
	InboundDetour            string
	LastInbound              string
	OriginDestination        M.Socksaddr
	RouteOriginalDestination M.Socksaddr
	// Deprecated: to be removed
	//nolint:staticcheck
	InboundOptions            option.InboundOptions
	UDPDisableDomainUnmapping bool
	UDPConnect                bool
	UDPTimeout                time.Duration

	NetworkStrategy     C.NetworkStrategy
	NetworkType         []C.InterfaceType
	FallbackNetworkType []C.InterfaceType
	FallbackDelay       time.Duration

	DNSServer string

	DestinationAddresses []netip.Addr
	SourceGeoIPCode      string
	GeoIPCode            string
	ProcessInfo          *process.Info
	QueryType            uint16
	FakeIP               bool

	IPCIDRMatchSource bool
	IPCIDRAcceptEmpty bool

	SourceAddressMatch           bool
	SourcePortMatch              bool
	DestinationAddressMatch      bool
	DestinationPortMatch         bool
	DidMatch                     bool
	IgnoreDestinationIPCIDRMatch bool
}

func ContextFrom

func ContextFrom(ctx context.Context) *InboundContext

func ExtendContext added in v1.5.5

func ExtendContext(ctx context.Context) (context.Context, *InboundContext)

func (*InboundContext) ResetRuleCache added in v1.8.0

func (c *InboundContext) ResetRuleCache()

type InboundManager

type InboundManager interface {
	Lifecycle
	Inbounds() []Inbound
	Get(tag string) (Inbound, bool)
	Remove(tag string) error
	Create(ctx context.Context, router Router, logger log.ContextLogger, tag string, inboundType string, options any) error
}

type InboundRegistry

type InboundRegistry interface {
	option.InboundOptionsRegistry
	Create(ctx context.Context, router Router, logger log.ContextLogger, tag string, inboundType string, options any) (Inbound, error)
}

type InterfaceUpdateListener added in v1.1.0

type InterfaceUpdateListener interface {
	InterfaceUpdated()
}

type Lifecycle

type Lifecycle interface {
	Start(stage StartStage) error
	Close() error
}

type LifecycleService

type LifecycleService interface {
	Name() string
	Lifecycle
}

func NewLifecycleService

func NewLifecycleService(service Service, name string) LifecycleService

type NetworkInterface

type NetworkInterface struct {
	control.Interface
	Type        C.InterfaceType
	DNSServers  []string
	Expensive   bool
	Constrained bool
}

type NetworkManager

type NetworkManager interface {
	Lifecycle
	InterfaceFinder() control.InterfaceFinder
	UpdateInterfaces() error
	DefaultNetworkInterface() *NetworkInterface
	NetworkInterfaces() []NetworkInterface
	AutoDetectInterface() bool
	AutoDetectInterfaceFunc() control.Func
	ProtectFunc() control.Func
	DefaultOptions() NetworkOptions
	RegisterAutoRedirectOutputMark(mark uint32) error
	AutoRedirectOutputMark() uint32
	NetworkMonitor() tun.NetworkUpdateMonitor
	InterfaceMonitor() tun.DefaultInterfaceMonitor
	PackageManager() tun.PackageManager
	WIFIState() WIFIState
	ResetNetwork()
}

type NetworkOptions

type NetworkOptions struct {
	NetworkStrategy     C.NetworkStrategy
	NetworkType         []C.InterfaceType
	FallbackNetworkType []C.InterfaceType
	FallbackDelay       time.Duration
	BindInterface       string
	RoutingMark         uint32
}

type OOBPacketHandler deprecated

type OOBPacketHandler interface {
	NewPacket(ctx context.Context, conn N.PacketConn, buffer *buf.Buffer, oob []byte, metadata InboundContext) error
}

Deprecated: use OOBPacketHandlerEx instead

type OOBPacketHandlerEx

type OOBPacketHandlerEx interface {
	NewPacketEx(buffer *buf.Buffer, oob []byte, source M.Socksaddr)
}

type Outbound

type Outbound interface {
	Type() string
	Tag() string
	Network() []string
	Dependencies() []string
	N.Dialer
}

type OutboundGroup

type OutboundGroup interface {
	Outbound
	Now() string
	All() []string
}

type OutboundManager

type OutboundManager interface {
	Lifecycle
	Outbounds() []Outbound
	Outbound(tag string) (Outbound, bool)
	Default() Outbound
	Remove(tag string) error
	Create(ctx context.Context, router Router, logger log.ContextLogger, tag string, outboundType string, options any) error
}

type OutboundRegistry

type OutboundRegistry interface {
	option.OutboundOptionsRegistry
	CreateOutbound(ctx context.Context, router Router, logger log.ContextLogger, tag string, outboundType string, options any) (Outbound, error)
}

type PacketConnectionHandler

type PacketConnectionHandler interface {
	NewPacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
}

Deprecated

type PacketConnectionHandlerEx

type PacketConnectionHandlerEx interface {
	NewPacketConnectionEx(ctx context.Context, conn N.PacketConn, metadata InboundContext, onClose N.CloseHandlerFunc)
}

type PacketConnectionHandlerFunc

type PacketConnectionHandlerFunc = func(ctx context.Context, conn N.PacketConn, metadata InboundContext) error

Deprecated

type PacketConnectionHandlerFuncEx

type PacketConnectionHandlerFuncEx = func(ctx context.Context, conn N.PacketConn, metadata InboundContext, onClose N.CloseHandlerFunc)

type PacketHandler deprecated

type PacketHandler interface {
	NewPacket(ctx context.Context, conn N.PacketConn, buffer *buf.Buffer, metadata InboundContext) error
}

Deprecated: use PacketHandlerEx instead

type PacketHandlerEx

type PacketHandlerEx interface {
	NewPacketEx(buffer *buf.Buffer, source M.Socksaddr)
}

type Router

type Router interface {
	Lifecycle

	FakeIPStore() FakeIPStore

	ConnectionRouter
	PreMatch(metadata InboundContext) error
	ConnectionRouterEx

	GeoIPReader() *geoip.Reader
	LoadGeosite(code string) (Rule, error)
	RuleSet(tag string) (RuleSet, bool)
	NeedWIFIState() bool

	Exchange(ctx context.Context, message *mdns.Msg) (*mdns.Msg, error)
	Lookup(ctx context.Context, domain string, strategy dns.DomainStrategy) ([]netip.Addr, error)
	LookupDefault(ctx context.Context, domain string) ([]netip.Addr, error)
	ClearDNSCache()
	Rules() []Rule

	SetTracker(tracker ConnectionTracker)

	ResetNetwork()
}

type Rule

type Rule interface {
	HeadlessRule
	Service
	Type() string
	UpdateGeosite() error
	Action() RuleAction
}

type RuleAction

type RuleAction interface {
	Type() string
	String() string
}

type RuleSet added in v1.8.0

type RuleSet interface {
	Name() string
	StartContext(ctx context.Context, startContext *HTTPStartContext) error
	PostStart() error
	Metadata() RuleSetMetadata
	ExtractIPSet() []*netipx.IPSet
	IncRef()
	DecRef()
	Cleanup()
	RegisterCallback(callback RuleSetUpdateCallback) *list.Element[RuleSetUpdateCallback]
	UnregisterCallback(element *list.Element[RuleSetUpdateCallback])
	Close() error
	HeadlessRule
}

type RuleSetMetadata added in v1.8.0

type RuleSetMetadata struct {
	ContainsProcessRule bool
	ContainsWIFIRule    bool
	ContainsIPCIDRRule  bool
}

type RuleSetUpdateCallback added in v1.10.0

type RuleSetUpdateCallback func(it RuleSet)

type SavedRuleSet added in v1.8.0

type SavedRuleSet struct {
	Content     []byte
	LastUpdated time.Time
	LastEtag    string
}

func (*SavedRuleSet) MarshalBinary added in v1.8.0

func (s *SavedRuleSet) MarshalBinary() ([]byte, error)

func (*SavedRuleSet) UnmarshalBinary added in v1.8.0

func (s *SavedRuleSet) UnmarshalBinary(data []byte) error

type Service

type Service interface {
	Start() error
	Close() error
}

type StartStage

type StartStage uint8
const (
	StartStateInitialize StartStage = iota
	StartStateStart
	StartStatePostStart
	StartStateStarted
)

func (StartStage) String

func (s StartStage) String() string

type TCPInjectableInbound

type TCPInjectableInbound interface {
	Inbound
	ConnectionHandlerEx
}

type TimeService added in v1.2.0

type TimeService interface {
	Service
	TimeFunc() func() time.Time
}

type UDPInjectableInbound

type UDPInjectableInbound interface {
	Inbound
	PacketConnectionHandlerEx
}

type URLTestGroup added in v1.3.0

type URLTestGroup interface {
	OutboundGroup
	URLTest(ctx context.Context) (map[string]uint16, error)
}

type UpstreamHandlerAdapter deprecated

type UpstreamHandlerAdapter interface {
	N.TCPConnectionHandler
	N.UDPConnectionHandler
	E.Handler
}

Deprecated: use TCPConnectionHandlerEx instead

func NewRouteContextHandler deprecated added in v1.7.0

func NewRouteContextHandler(
	router ConnectionRouter,
	logger logger.ContextLogger,
) UpstreamHandlerAdapter

Deprecated: Use ConnectionRouterEx instead.

func NewRouteHandler deprecated added in v1.7.0

func NewRouteHandler(
	metadata InboundContext,
	router ConnectionRouter,
	logger logger.ContextLogger,
) UpstreamHandlerAdapter

Deprecated: Use ConnectionRouterEx instead.

func NewUpstreamContextHandler deprecated

func NewUpstreamContextHandler(
	connectionHandler ConnectionHandlerFunc,
	packetHandler PacketConnectionHandlerFunc,
	errorHandler E.Handler,
) UpstreamHandlerAdapter

Deprecated: Use NewUpstreamContextHandlerEx instead.

func NewUpstreamHandler

func NewUpstreamHandler(
	metadata InboundContext,
	connectionHandler ConnectionHandlerFunc,
	packetHandler PacketConnectionHandlerFunc,
	errorHandler E.Handler,
) UpstreamHandlerAdapter

Deprecated

type UpstreamHandlerAdapterEx

type UpstreamHandlerAdapterEx interface {
	N.TCPConnectionHandlerEx
	N.UDPConnectionHandlerEx
}

func NewRouteContextHandlerEx

func NewRouteContextHandlerEx(
	router ConnectionRouterEx,
) UpstreamHandlerAdapterEx

func NewRouteHandlerEx

func NewRouteHandlerEx(
	metadata InboundContext,
	router ConnectionRouterEx,
) UpstreamHandlerAdapterEx

func NewUpstreamContextHandlerEx

func NewUpstreamContextHandlerEx(
	connectionHandler ConnectionHandlerFuncEx,
	packetHandler PacketConnectionHandlerFuncEx,
) UpstreamHandlerAdapterEx

func NewUpstreamHandlerEx

func NewUpstreamHandlerEx(
	metadata InboundContext,
	connectionHandler ConnectionHandlerFuncEx,
	packetHandler PacketConnectionHandlerFuncEx,
) UpstreamHandlerAdapterEx

type V2RayClientTransport added in v1.0.1

type V2RayClientTransport interface {
	DialContext(ctx context.Context) (net.Conn, error)
	Close() error
}

type V2RayServer added in v1.1.0

type V2RayServer interface {
	LifecycleService
	StatsService() ConnectionTracker
}

type V2RayServerTransport added in v1.0.1

type V2RayServerTransport interface {
	Network() []string
	Serve(listener net.Listener) error
	ServePacket(listener net.PacketConn) error
	Close() error
}

type V2RayServerTransportHandler added in v1.2.0

type V2RayServerTransportHandler interface {
	N.TCPConnectionHandlerEx
}

type WIFIState added in v1.7.0

type WIFIState struct {
	SSID  string
	BSSID string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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