dialer

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: AGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Init = 1 + iota
	NotAlive
)
View Source
const (
	AnnotationKey_AddLatency = "add_latency"
)
View Source
const Timeout = 10 * time.Second

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 SoMarkControl

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

func TproxyControl

func TproxyControl(c syscall.RawConn) error

func TransparentControl added in v0.4.0

func TransparentControl(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,
	dialersAnnotations []*Annotation,
	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.

func (*AliveDialerSet) SortingLatency added in v0.4.0

func (a *AliveDialerSet) SortingLatency(d *Dialer) time.Duration

type AliveDialerSetSet

type AliveDialerSetSet map[*AliveDialerSet]int

type Annotation added in v0.2.2

type Annotation struct {
	AddLatency time.Duration
}

func NewAnnotation added in v0.2.2

func NewAnnotation(annotation []*config_parser.Param) (*Annotation, error)

type CheckDnsOption

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

func ParseCheckDnsOption

func ParseCheckDnsOption(ctx context.Context, dnsHostPort []string, resolverNetwork string) (opt *CheckDnsOption, err error)

type CheckDnsOptionRaw

type CheckDnsOptionRaw struct {
	Raw             []string
	ResolverNetwork string
	Somark          uint32
	// 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
	InstanceOption
	netproxy.Dialer
	// contains filtered or unexported fields
}

func NewDialer

func NewDialer(dialer netproxy.Dialer, option *GlobalOption, iOption InstanceOption, property *Property) *Dialer

NewDialer is for register in general.

func NewFromLink(gOption *GlobalOption, iOption InstanceOption, link string, subscriptionTag string) (*Dialer, 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, network string) (ok bool, err error)

func (*Dialer) HttpCheck

func (d *Dialer) HttpCheck(ctx context.Context, u *netutils.URL, ip netip.Addr, method string, soMark uint32) (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 GlobalOption

type GlobalOption struct {
	D.ExtraOption
	Log               *logrus.Logger
	TcpCheckOptionRaw TcpCheckOptionRaw // Lazy parse
	CheckDnsOptionRaw CheckDnsOptionRaw // Lazy parse
	CheckInterval     time.Duration
	CheckTolerance    time.Duration
	CheckDnsTcp       bool
}

type InstanceOption

type InstanceOption struct {
	DisableCheck 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 {
	D.Property
	SubscriptionTag string
}

func NewBlockDialer

func NewBlockDialer(option *GlobalOption, dialCallback func()) (netproxy.Dialer, *Property)

func NewDirectDialer

func NewDirectDialer(option *GlobalOption, fullcone bool) (netproxy.Dialer, *Property)

type TcpCheckOption

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

func ParseTcpCheckOption

func ParseTcpCheckOption(ctx context.Context, rawURL []string, method string, resolverNetwork string) (opt *TcpCheckOption, err error)

type TcpCheckOptionRaw

type TcpCheckOptionRaw struct {
	Log             *logrus.Logger
	Raw             []string
	ResolverNetwork string
	Method          string
	// contains filtered or unexported fields
}

func (*TcpCheckOptionRaw) Option

func (c *TcpCheckOptionRaw) Option() (opt *TcpCheckOption, err error)

Jump to

Keyboard shortcuts

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