dialer

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Init = 1 + iota
	NotAlive
)

Variables

View Source
var (
	UnexpectedFieldErr  = fmt.Errorf("unexpected field")
	InvalidParameterErr = fmt.Errorf("invalid parameters")
)

Functions

func BindControl

func BindControl(c syscall.RawConn, lAddrPort netip.AddrPort) error

func FromLinkRegister

func FromLinkRegister(name string, creator FromLinkCreator)

func SoMarkControl

func SoMarkControl(c syscall.RawConn, mark int) error

func TproxyControl

func TproxyControl(c syscall.RawConn) error

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

type CheckDnsOption struct {
	DnsHost string
	DnsPort uint16
	*netutils.Ip46
}

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(gOption *GlobalOption, iOption InstanceOption, link string) (dialer *Dialer, err error)

func (*Dialer) ActivateCheck

func (d *Dialer) ActivateCheck()

func (*Dialer) Check

func (d *Dialer) Check(timeout time.Duration,
	opts *CheckOption,
) (ok bool, err error)

func (*Dialer) Close

func (d *Dialer) Close() error

func (*Dialer) DnsCheck

func (d *Dialer) DnsCheck(ctx context.Context, dns netip.AddrPort, tcp bool) (ok bool, err error)

func (*Dialer) HttpCheck

func (d *Dialer) HttpCheck(ctx context.Context, u *netutils.URL, ip netip.Addr) (ok bool, err error)

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

func (d *Dialer) Property() Property

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 Property

type Property struct {
	Name     string
	Address  string
	Protocol string
	Link     string
}

type TcpCheckOption

type TcpCheckOption struct {
	Url *netutils.URL
	*netutils.Ip46
}

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)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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