selector

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDbFilter

func NewDbFilter(db Db, filterConfig *router.SelectorConfig_Filter,
	landHandlers []*xsqlite.OutboundHandler, createHandler i.HandlerFactory) *dbFilter

func NewOmFilter

func NewOmFilter(filterConfig *router.SelectorConfig_Filter, om *outbound.Manager) *omFilter

func TestHandler6

func TestHandler6(ctx context.Context, s Tester, item OutHandler)

func TestHandlerPing

func TestHandlerPing(ctx context.Context, s Tester, item OutHandler)

func TestHandlerSpeed

func TestHandlerSpeed(ctx context.Context, s Tester, item OutHandler, size uint32)

func TestHandlerUsable

func TestHandlerUsable(ctx context.Context, s Tester, item OutHandler)

used to test unusable handlers

Types

type Balancer

type Balancer interface {
	GetHandler(*session.Info) i.Outbound
	UpdateHandlers(handlers []i.HandlerWith6Info)
	Support6() bool
}

type Db

type Db interface {
	GetAllHandlers() ([]*xsqlite.OutboundHandler, error)
	GetHandlersByGroup(group string) ([]*xsqlite.OutboundHandler, error)
	GetBatchedHandlers(batchSize int, offset int) ([]*xsqlite.OutboundHandler, error)
	GetHandler(id int) *xsqlite.OutboundHandler
}

type FastRecoveryChangeNotifier added in v1.0.7

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

func (*FastRecoveryChangeNotifier) Notify added in v1.0.7

func (n *FastRecoveryChangeNotifier) Notify(isRecovery bool)

func (*FastRecoveryChangeNotifier) RegisterFastRevoceryObserver added in v1.0.7

func (n *FastRecoveryChangeNotifier) RegisterFastRevoceryObserver(observer FastRecoveryChangeObserver)

func (*FastRecoveryChangeNotifier) UnregisterFastRevoceryObserver added in v1.0.7

func (n *FastRecoveryChangeNotifier) UnregisterFastRevoceryObserver(observer FastRecoveryChangeObserver)

type FastRecoveryChangeObserver added in v1.0.7

type FastRecoveryChangeObserver interface {
	OnFastRecoveryChanged(isRecovery bool)
}

type Filter

type Filter interface {
	GetHandlers() ([]OutHandler, error)
}

type FilterUpdate added in v1.0.7

type FilterUpdate interface {
	UpdateFilterConfig(filterConfig *router.SelectorConfig_Filter)
}

type HandlerErrorChangeSubject

type HandlerErrorChangeSubject interface {
	AddHandlerErrorObserver(observer i.HandlerErrorObserver)
	RemoveHandlerErrorObserver(observer i.HandlerErrorObserver)
}

type HandlersBeingUsedUpdate

type HandlersBeingUsedUpdate func([]string)

type MemoryBalancer

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

func NewMemoryBalancer

func NewMemoryBalancer() *MemoryBalancer

func (*MemoryBalancer) GetHandler

func (b *MemoryBalancer) GetHandler(info *session.Info) i.Outbound

func (*MemoryBalancer) Support6

func (b *MemoryBalancer) Support6() bool

func (*MemoryBalancer) UpdateHandlers

func (b *MemoryBalancer) UpdateHandlers(handlers []i.HandlerWith6Info)

type OnFastRecoveryChangedFunc added in v1.0.7

type OnFastRecoveryChangedFunc func()

func (OnFastRecoveryChangedFunc) OnFastRecoveryChanged added in v1.0.7

func (f OnFastRecoveryChangedFunc) OnFastRecoveryChanged()

type OnSelectedHandlersChangedFunc added in v1.0.7

type OnSelectedHandlersChangedFunc func()

func (OnSelectedHandlersChangedFunc) OnSelectedHandlersChanged added in v1.0.7

func (f OnSelectedHandlersChangedFunc) OnSelectedHandlersChanged()

type OutHandler added in v1.2.4

type OutHandler interface {
	GetHandler() (i.Outbound, error)
	Name() string
	GetOk() int
	SetOk(ok int)
	GetPing() int
	SetPing(ping int)
	GetSpeed() int
	SetSpeed(speed int)
	GetSupport6() int
	SetSupport6(support6 int)
}

type RandomBanlancer

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

func NewRandomBanlancer

func NewRandomBanlancer() *RandomBanlancer

func (*RandomBanlancer) GetHandler

func (b *RandomBanlancer) GetHandler(info *session.Info) i.Outbound

func (*RandomBanlancer) Support6

func (b *RandomBanlancer) Support6() bool

func (*RandomBanlancer) UpdateHandlers

func (b *RandomBanlancer) UpdateHandlers(handlers []i.HandlerWith6Info)

type SelectedHandlersChangeNotifier added in v1.0.7

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

func (*SelectedHandlersChangeNotifier) NotifySelectedHandlersChanged added in v1.0.7

func (n *SelectedHandlersChangeNotifier) NotifySelectedHandlersChanged(tag string, handlers []string)

func (*SelectedHandlersChangeNotifier) RegisterSelectedHandlersChangeObserver added in v1.0.7

func (n *SelectedHandlersChangeNotifier) RegisterSelectedHandlersChangeObserver(observer SelectedHandlersChangeObserver)

func (*SelectedHandlersChangeNotifier) UnregisterSelectedHandlersChangeObserver added in v1.0.7

func (n *SelectedHandlersChangeNotifier) UnregisterSelectedHandlersChangeObserver(observer SelectedHandlersChangeObserver)

type SelectedHandlersChangeObserver added in v1.0.7

type SelectedHandlersChangeObserver interface {
	OnSelectedHandlersChanged(tag string, handlers []string)
}

type Selector

type Selector struct {
	FastRecoveryChangeNotifier

	util.IPv6SupportChangeNotifier
	// contains filtered or unexported fields
}

func NewSelector

func NewSelector(config SelectorConfig) *Selector

func (*Selector) Close

func (s *Selector) Close() error

func (*Selector) GetFilter added in v1.0.7

func (s *Selector) GetFilter() Filter

func (*Selector) GetHandler

func (s *Selector) GetHandler(info *session.Info) i.Outbound

func (*Selector) GetHandlersBeingUsed added in v1.2.1

func (s *Selector) GetHandlersBeingUsed() []string

func (*Selector) Load

func (s *Selector) Load()

reload handlers

func (*Selector) OnHandlerChanged

func (s *Selector) OnHandlerChanged()

func (*Selector) OnHandlerError

func (s *Selector) OnHandlerError(tag string, err error)

func (*Selector) OnHandlerSpeedChanged

func (s *Selector) OnHandlerSpeedChanged(tag string, speed int32)

func (*Selector) ResetTestAllUnusableInterval added in v1.2.3

func (s *Selector) ResetTestAllUnusableInterval(interval time.Duration)

func (*Selector) Start

func (s *Selector) Start() error

func (*Selector) Tag

func (s *Selector) Tag() string

func (*Selector) TestAllUnusable

func (s *Selector) TestAllUnusable()

func (*Selector) TestPingAll

func (s *Selector) TestPingAll()

func (*Selector) TestSpeedAll

func (s *Selector) TestSpeedAll()

func (*Selector) UpdateBalancer

func (s *Selector) UpdateBalancer(balancer Balancer)

func (*Selector) UpdateFilter

func (s *Selector) UpdateFilter(filter Filter)

type SelectorConfig

type SelectorConfig struct {
	*router.SelectorConfig
	CreateHandler             i.HandlerFactory
	HandlerErrorChangeSubject HandlerErrorChangeSubject
	Tester                    Tester
	Filter                    Filter
	OnHandlerBeingUsedChange  HandlersBeingUsedUpdate
	HandlerInfo               handlerInfo
	SelectStrategy            selectStrategy
}

type Selectors

type Selectors struct {

	// notify listeners when any selector's ipv6 support changed or any selector is added or removed
	i.IPv6SupportChangeSubject
	SelectedHandlersChangeNotifier
	// contains filtered or unexported fields
}

func NewSelectors

func NewSelectors() *Selectors

func (*Selectors) AddSelector

func (s *Selectors) AddSelector(selector *Selector)

func (*Selectors) Close

func (s *Selectors) Close() error

func (*Selectors) GetAllSelectors

func (s *Selectors) GetAllSelectors() []*Selector

func (*Selectors) GetSelector

func (s *Selectors) GetSelector(tag string) *Selector

func (*Selectors) OnHandlerChanged

func (s *Selectors) OnHandlerChanged()

func (*Selectors) OnHandlerSpeedChanged

func (s *Selectors) OnHandlerSpeedChanged(tag string, speed int32)

func (*Selectors) OnIPv6SupportChanged

func (s *Selectors) OnIPv6SupportChanged()

func (*Selectors) RemoveAllSelectors

func (s *Selectors) RemoveAllSelectors()

func (*Selectors) RemoveSelector

func (s *Selectors) RemoveSelector(tag string)

func (*Selectors) Start

func (s *Selectors) Start() error

type Tester

type Tester interface {
	// test speed with given size and retry
	TestSpeed(ctx context.Context, outbound i.Outbound, size uint32, retry bool) int64
	TestUsable(ctx context.Context, outbound i.Outbound, retry bool) bool
	TestIPv6(context.Context, i.Outbound) bool
	TestPing(context.Context, i.Outbound) int
}

type TopPingStrategy added in v1.2.4

type TopPingStrategy struct{}

TopPingStrategy selects all nodes within 30% of the least ping (e.g. min 100ms -> select all with ping <= 130ms).

func (*TopPingStrategy) Ping added in v1.2.4

func (s *TopPingStrategy) Ping() bool

func (*TopPingStrategy) Select added in v1.2.4

func (s *TopPingStrategy) Select(handlers []OutHandler) []OutHandler

func (*TopPingStrategy) Speed added in v1.2.4

func (s *TopPingStrategy) Speed() bool

func (*TopPingStrategy) Usable added in v1.2.4

func (s *TopPingStrategy) Usable() bool

type TopThroughputStrategy added in v1.2.4

type TopThroughputStrategy struct{}

TopThroughputStrategy selects all nodes with throughput >= 70% of the highest (e.g. max 100 -> select all with speed >= 70).

func (*TopThroughputStrategy) Ping added in v1.2.4

func (s *TopThroughputStrategy) Ping() bool

func (*TopThroughputStrategy) Select added in v1.2.4

func (s *TopThroughputStrategy) Select(handlers []OutHandler) []OutHandler

func (*TopThroughputStrategy) Speed added in v1.2.4

func (s *TopThroughputStrategy) Speed() bool

func (*TopThroughputStrategy) Usable added in v1.2.4

func (s *TopThroughputStrategy) Usable() bool

Jump to

Keyboard shortcuts

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