Documentation ¶
Index ¶
- Constants
- Variables
- func BindControl(c syscall.RawConn, lAddrPort netip.AddrPort) error
- func FromLinkRegister(name string, creator FromLinkCreator)
- func SoMarkControl(c syscall.RawConn, mark int) error
- func TproxyControl(c syscall.RawConn) error
- type AliveDialerSet
- type AliveDialerSetSet
- type CheckDnsOption
- type CheckDnsOptionRaw
- type CheckOption
- type Dialer
- func NewBlockDialer(option *GlobalOption, dialCallback func()) *Dialer
- func NewDialer(dialer netproxy.Dialer, option *GlobalOption, iOption InstanceOption, ...) *Dialer
- func NewDirectDialer(option *GlobalOption, fullcone bool) *Dialer
- func NewFromLink(gOption *GlobalOption, iOption InstanceOption, link string) (dialer *Dialer, err error)
- func (d *Dialer) ActivateCheck()
- func (d *Dialer) Check(timeout time.Duration, opts *CheckOption) (ok bool, err error)
- func (d *Dialer) Close() error
- func (d *Dialer) DnsCheck(ctx context.Context, dns netip.AddrPort, tcp bool) (ok bool, err error)
- func (d *Dialer) HttpCheck(ctx context.Context, u *netutils.URL, ip netip.Addr) (ok bool, err error)
- func (d *Dialer) MustGetAlive(typ *NetworkType) bool
- func (d *Dialer) MustGetLatencies10(typ *NetworkType) *LatenciesN
- func (d *Dialer) NotifyCheck()
- func (d *Dialer) Property() Property
- func (d *Dialer) RegisterAliveDialerSet(a *AliveDialerSet)
- func (d *Dialer) UnregisterAliveDialerSet(a *AliveDialerSet)
- type FromLinkCreator
- type GlobalOption
- type InstanceOption
- type LatenciesN
- type NetworkType
- type Property
- type TcpCheckOption
- type TcpCheckOptionRaw
Constants ¶
View Source
const ( Init = 1 + iota NotAlive )
Variables ¶
View Source
var ( UnexpectedFieldErr = fmt.Errorf("unexpected field") InvalidParameterErr = fmt.Errorf("invalid parameters") )
Functions ¶
func FromLinkRegister ¶
func FromLinkRegister(name string, creator FromLinkCreator)
func TproxyControl ¶
Types ¶
type AliveDialerSet ¶
type AliveDialerSet struct { CheckTyp *NetworkType // contains filtered or unexported fields }
AliveDialerSet assumes mapping between index and dialer MUST remain unchanged.
It is thread-safe.
func NewAliveDialerSet ¶
func NewAliveDialerSet( log *logrus.Logger, dialerGroupName string, networkType *NetworkType, tolerance time.Duration, selectionPolicy consts.DialerSelectionPolicy, dialers []*Dialer, aliveChangeCallback func(alive bool), setAlive bool, ) *AliveDialerSet
func (*AliveDialerSet) GetMinLatency ¶
func (a *AliveDialerSet) GetMinLatency() (d *Dialer, latency time.Duration)
GetMinLatency acquires correct selectionPolicy.
func (*AliveDialerSet) GetRand ¶
func (a *AliveDialerSet) GetRand() *Dialer
func (*AliveDialerSet) NotifyLatencyChange ¶
func (a *AliveDialerSet) NotifyLatencyChange(dialer *Dialer, alive bool)
NotifyLatencyChange should be invoked when dialer every time latency and alive state changes.
type AliveDialerSetSet ¶
type AliveDialerSetSet map[*AliveDialerSet]int
type CheckDnsOption ¶
func ParseCheckDnsOption ¶
func ParseCheckDnsOption(ctx context.Context, dnsHostPort string) (opt *CheckDnsOption, err error)
type CheckDnsOptionRaw ¶
type CheckDnsOptionRaw struct { Raw string // contains filtered or unexported fields }
func (*CheckDnsOptionRaw) Option ¶
func (c *CheckDnsOptionRaw) Option() (opt *CheckDnsOption, err error)
type CheckOption ¶
type CheckOption struct { CheckFunc func(ctx context.Context, typ *NetworkType) (ok bool, err error) // contains filtered or unexported fields }
type Dialer ¶
type Dialer struct { *GlobalOption netproxy.Dialer // contains filtered or unexported fields }
func NewBlockDialer ¶
func NewBlockDialer(option *GlobalOption, dialCallback func()) *Dialer
func NewDialer ¶
func NewDialer(dialer netproxy.Dialer, option *GlobalOption, iOption InstanceOption, property Property) *Dialer
NewDialer is for register in general.
func NewDirectDialer ¶
func NewDirectDialer(option *GlobalOption, fullcone bool) *Dialer
func NewFromLink ¶
func NewFromLink(gOption *GlobalOption, iOption InstanceOption, link string) (dialer *Dialer, err error)
func (*Dialer) ActivateCheck ¶
func (d *Dialer) ActivateCheck()
func (*Dialer) MustGetAlive ¶
func (d *Dialer) MustGetAlive(typ *NetworkType) bool
func (*Dialer) MustGetLatencies10 ¶
func (d *Dialer) MustGetLatencies10(typ *NetworkType) *LatenciesN
func (*Dialer) NotifyCheck ¶
func (d *Dialer) NotifyCheck()
NotifyCheck will succeed only when CheckEnabled is true.
func (*Dialer) RegisterAliveDialerSet ¶
func (d *Dialer) RegisterAliveDialerSet(a *AliveDialerSet)
RegisterAliveDialerSet is thread-safe.
func (*Dialer) UnregisterAliveDialerSet ¶
func (d *Dialer) UnregisterAliveDialerSet(a *AliveDialerSet)
UnregisterAliveDialerSet is thread-safe.
type FromLinkCreator ¶
type FromLinkCreator func(gOption *GlobalOption, iOption InstanceOption, link string) (dialer *Dialer, err error)
type GlobalOption ¶
type GlobalOption struct { Log *logrus.Logger TcpCheckOptionRaw TcpCheckOptionRaw // Lazy parse CheckDnsOptionRaw CheckDnsOptionRaw // Lazy parse CheckInterval time.Duration CheckTolerance time.Duration CheckDnsTcp bool AllowInsecure bool }
type InstanceOption ¶
type InstanceOption struct {
CheckEnabled bool
}
type LatenciesN ¶
type LatenciesN struct { N int LastNLatencies *list.List SumNLatencies time.Duration // contains filtered or unexported fields }
func NewLatenciesN ¶
func NewLatenciesN(n int) *LatenciesN
func (*LatenciesN) AppendLatency ¶
func (ln *LatenciesN) AppendLatency(l time.Duration)
AppendLatency appends a new latency to the back and keep the number in the list. Appending a fixed duration for failed or timeout situation is recommended.
It is thread-safe.
func (*LatenciesN) AvgLatency ¶
func (ln *LatenciesN) AvgLatency() (time.Duration, bool)
func (*LatenciesN) LastLatency ¶
func (ln *LatenciesN) LastLatency() (time.Duration, bool)
type NetworkType ¶
type NetworkType struct { L4Proto consts.L4ProtoStr IpVersion consts.IpVersionStr IsDns bool }
func (*NetworkType) String ¶
func (t *NetworkType) String() string
func (*NetworkType) StringWithoutDns ¶
func (t *NetworkType) StringWithoutDns() string
type TcpCheckOption ¶
func ParseTcpCheckOption ¶
func ParseTcpCheckOption(ctx context.Context, rawURL string) (opt *TcpCheckOption, err error)
type TcpCheckOptionRaw ¶
type TcpCheckOptionRaw struct { Raw string // contains filtered or unexported fields }
func (*TcpCheckOptionRaw) Option ¶
func (c *TcpCheckOptionRaw) Option() (opt *TcpCheckOption, err error)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.