adapter

package
v0.0.0-...-6478c7e Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: GPL-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithRouter

func ContextWithRouter(ctx context.Context, router Router) context.Context

func OutboundTag

func OutboundTag(detour Outbound) string

func OverrideContext

func OverrideContext(ctx context.Context) context.Context

func UpstreamMetadata

func UpstreamMetadata(metadata InboundContext) M.Metadata

func WithContext

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

Types

type CacheFile

type CacheFile interface {
	Service
	PreStarter

	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 {
	Service
	PreStarter
	Mode() string
	ModeList() []string
	HistoryStorage() *urltest.HistoryStorage
	RoutedConnection(ctx context.Context, conn net.Conn, metadata InboundContext, matchedRule Rule) (net.Conn, Tracker)
	RoutedPacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext, matchedRule Rule) (N.PacketConn, Tracker)
}

type ConnectionHandler

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

type ConnectionHandlerFunc

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

type ConnectionRouter

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

type DNSRule

type DNSRule interface {
	Rule
	DisableCache() bool
	RewriteTTL() *uint32
	ClientSubnet() *netip.Prefix
	WithAddressLimit() bool
	MatchAddressLimit(metadata *InboundContext) bool
}

type FakeIPMetadata

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

func (*FakeIPMetadata) MarshalBinary

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

func (*FakeIPMetadata) UnmarshalBinary

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

type FakeIPStorage

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

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

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

type HeadlessRule

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

type Inbound

type Inbound interface {
	Service
	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

	InboundDetour        string
	LastInbound          string
	OriginDestination    M.Socksaddr
	InboundOptions       option.InboundOptions
	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 AppendContext

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

func ContextFrom

func ContextFrom(ctx context.Context) *InboundContext

func ExtendContext

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

func (*InboundContext) ResetRuleCache

func (c *InboundContext) ResetRuleCache()

type InjectableInbound

type InjectableInbound interface {
	Inbound
	Network() []string
	NewConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
	NewPacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
}

type InterfaceUpdateListener

type InterfaceUpdateListener interface {
	InterfaceUpdated()
}

type OOBPacketHandler

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

type Outbound

type Outbound interface {
	Type() string
	Tag() string
	Network() []string
	Dependencies() []string
	N.Dialer
	NewConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
	NewPacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
}

type OutboundGroup

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

type PacketConnectionHandler

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

type PacketConnectionHandlerFunc

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

type PacketHandler

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

type PostStarter

type PostStarter interface {
	PostStart() error
}

type PreStarter

type PreStarter interface {
	PreStart() error
}

type Router

type Router interface {
	Service
	PreStarter
	PostStarter
	Cleanup() error

	Outbounds() []Outbound
	Outbound(tag string) (Outbound, bool)
	DefaultOutbound(network string) (Outbound, error)

	FakeIPStore() FakeIPStore

	ConnectionRouter

	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()

	InterfaceFinder() control.InterfaceFinder
	UpdateInterfaces() error
	DefaultInterface() string
	AutoDetectInterface() bool
	AutoDetectInterfaceFunc() control.Func
	DefaultMark() uint32
	RegisterAutoRedirectOutputMark(mark uint32) error
	AutoRedirectOutputMark() uint32
	NetworkMonitor() tun.NetworkUpdateMonitor
	InterfaceMonitor() tun.DefaultInterfaceMonitor
	PackageManager() tun.PackageManager
	WIFIState() WIFIState
	Rules() []Rule

	ClashServer() ClashServer
	SetClashServer(server ClashServer)

	V2RayServer() V2RayServer
	SetV2RayServer(server V2RayServer)

	ResetNetwork() error
}

func RouterFromContext

func RouterFromContext(ctx context.Context) Router

type Rule

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

type RuleSet

type RuleSet interface {
	Name() string
	StartContext(ctx context.Context, startContext RuleSetStartContext) 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

type RuleSetMetadata struct {
	ContainsProcessRule bool
	ContainsWIFIRule    bool
	ContainsIPCIDRRule  bool
}

type RuleSetStartContext

type RuleSetStartContext interface {
	HTTPClient(detour string, dialer N.Dialer) *http.Client
	Close()
}

type RuleSetUpdateCallback

type RuleSetUpdateCallback func(it RuleSet)

type SavedRuleSet

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

func (*SavedRuleSet) MarshalBinary

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

func (*SavedRuleSet) UnmarshalBinary

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

type Service

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

type TimeService

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

type Tracker

type Tracker interface {
	Leave()
}

type URLTestGroup

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

type UpstreamHandlerAdapter

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

func NewRouteContextHandler

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

func NewRouteHandler

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

func NewUpstreamContextHandler

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

func NewUpstreamHandler

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

type V2RayClientTransport

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

type V2RayServer

type V2RayServer interface {
	Service
	StatsService() V2RayStatsService
}

type V2RayServerTransport

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

type V2RayServerTransportHandler

type V2RayServerTransportHandler interface {
	N.TCPConnectionHandler
	E.Handler
}

type V2RayStatsService

type V2RayStatsService interface {
	RoutedConnection(inbound string, outbound string, user string, conn net.Conn) net.Conn
	RoutedPacketConnection(inbound string, outbound string, user string, conn N.PacketConn) N.PacketConn
}

type WIFIState

type WIFIState struct {
	SSID  string
	BSSID string
}

Jump to

Keyboard shortcuts

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