rule

package
v0.0.0-...-2ebb81a Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2025 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListDir

func ListDir(dirPth string, suffix string) (files []string, err error)

ListDir returns file list named with suffix in dirPth.

Types

type Checker

type Checker interface {
	Check(fwdr *Forwarder) (elap time.Duration, err error)
}

Checker is a forwarder health checker.

type Config

type Config struct {
	RulePath string

	Forward  []string
	Strategy Strategy

	DNSServers []string
	IPSet      string

	Domain []string
	IP     []string
	CIDR   []string

	StatusServer string
}

Config is config of rule.

func NewConfFromFile

func NewConfFromFile(ruleFile string) (*Config, error)

NewConfFromFile returns a new config from file.

type Forwarder

type Forwarder struct {
	proxy.Dialer

	Inbytes  uint64
	Outbytes uint64
	// contains filtered or unexported fields
}

Forwarder associates with a `-forward` command, usually a dialer or a chain of dialers.

func DirectForwarder

func DirectForwarder(intface string, dialTimeout, relayTimeout time.Duration) (*Forwarder, error)

DirectForwarder returns a direct forwarder.

func ForwarderFromURL

func ForwarderFromURL(s, intface string, dialTimeout, relayTimeout time.Duration) (f *Forwarder, err error)

ForwarderFromURL parses `forward=` command value and returns a new forwarder.

func (*Forwarder) AddHandler

func (f *Forwarder) AddHandler(h StatusHandler)

AddHandler adds a custom handler to handle the status change event.

func (*Forwarder) AddInBytes

func (f *Forwarder) AddInBytes(v uint64)

add bytes

func (*Forwarder) AddOutBytes

func (f *Forwarder) AddOutBytes(v uint64)

func (*Forwarder) Addr

func (f *Forwarder) Addr() string

Addr returns the forwarder's addr. NOTE: addr returns for chained dialers: dialer1Addr,dialer2Addr,...

func (*Forwarder) ChkCount

func (f *Forwarder) ChkCount() uint32

get bytes

func (*Forwarder) Dial

func (f *Forwarder) Dial(network, addr string) (c net.Conn, err error)

Dial dials to addr and returns conn.

func (*Forwarder) Disable

func (f *Forwarder) Disable()

Disable the forwarder.

func (*Forwarder) Enable

func (f *Forwarder) Enable()

Enable the forwarder.

func (*Forwarder) Enabled

func (f *Forwarder) Enabled() bool

Enabled returns the status of forwarder.

func (*Forwarder) FID

func (f *Forwarder) FID() uint32

Failures returns the failuer count of forwarder.

func (*Forwarder) Failures

func (f *Forwarder) Failures() uint32

Failures returns the failuer count of forwarder.

func (*Forwarder) GetCheckNow

func (f *Forwarder) GetCheckNow() bool

get bytes

func (*Forwarder) InBytes

func (f *Forwarder) InBytes() uint64

get bytes

func (*Forwarder) IncChkCount

func (f *Forwarder) IncChkCount()

func (*Forwarder) IncFailures

func (f *Forwarder) IncFailures()

IncFailures increase the failuer count by 1.

func (*Forwarder) Latency

func (f *Forwarder) Latency() int64

Latency returns the latency of forwarder.

func (*Forwarder) Latency_ms

func (f *Forwarder) Latency_ms() int64

Latency returns the latency of forwarder.

func (*Forwarder) MDisable

func (f *Forwarder) MDisable()

Disable the forwarder.

func (*Forwarder) MDisabled

func (f *Forwarder) MDisabled() bool

Enabled returns the status of forwarder.

func (*Forwarder) MEnable

func (f *Forwarder) MEnable()

Enable the forwarder.

func (*Forwarder) MaxFailures

func (f *Forwarder) MaxFailures() uint32

MaxFailures returns the maxFailures of forwarder.

func (*Forwarder) OutBytes

func (f *Forwarder) OutBytes() uint64

func (*Forwarder) Priority

func (f *Forwarder) Priority() uint32

Priority returns the priority of forwarder.

func (*Forwarder) SetCheckNow

func (f *Forwarder) SetCheckNow()

func (*Forwarder) SetChkCount

func (f *Forwarder) SetChkCount(v uint32)

func (*Forwarder) SetFailures

func (f *Forwarder) SetFailures(v uint32)

Set Failures count by v.

func (*Forwarder) SetLatency

func (f *Forwarder) SetLatency(l int64)

SetLatency sets the latency of forwarder.

func (*Forwarder) SetMaxFailures

func (f *Forwarder) SetMaxFailures(l uint32)

SetMaxFailures sets the maxFailures of forwarder.

func (*Forwarder) SetPriority

func (f *Forwarder) SetPriority(l uint32)

SetPriority sets the priority of forwarder.

func (*Forwarder) SetTotalFails

func (f *Forwarder) SetTotalFails(v uint32)

func (*Forwarder) TotalFails

func (f *Forwarder) TotalFails() uint32

Failures returns the failuer count of forwarder.

func (*Forwarder) URL

func (f *Forwarder) URL() string

URL returns the forwarder's full url.

type FwdrGroup

type FwdrGroup struct {
	Lweights []float64
	// contains filtered or unexported fields
}

FwdrGroup is a forwarder group.

func NewFwdrGroup

func NewFwdrGroup(rulePath string, s []string, c *Strategy) *FwdrGroup

NewFwdrGroup returns a new forward group.

func (*FwdrGroup) Check

func (p *FwdrGroup) Check()

Check runs the forwarder checks.

func (*FwdrGroup) Dial

func (p *FwdrGroup) Dial(network, addr string) (net.Conn, proxy.Dialer, error)

Dial connects to the address addr on the network net.

func (*FwdrGroup) DialUDP

func (p *FwdrGroup) DialUDP(network, addr string) (pc net.PacketConn, dialer proxy.UDPDialer, err error)

DialUDP connects to the given address.

func (*FwdrGroup) NextDialer

func (p *FwdrGroup) NextDialer(dstAddr string) proxy.Dialer

NextDialer returns the next dialer.

func (*FwdrGroup) Priority

func (p *FwdrGroup) Priority() uint32

Priority returns the active priority of dialer.

func (*FwdrGroup) SetPriority

func (p *FwdrGroup) SetPriority(pri uint32)

SetPriority sets the active priority of daler.

type Proxy

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

Proxy implements the proxy.Proxy interface with rule support.

func NewProxy

func NewProxy(mainForwarders []string, mainStrategy *Strategy, rules []*Config) *Proxy

NewProxy returns a new rule proxy.

func (*Proxy) AddDomainIP

func (p *Proxy) AddDomainIP(domain string, ip netip.Addr) error

AddDomainIP used to update ipMap rules according to domainMap rule.

func (*Proxy) Check

func (p *Proxy) Check()

Check checks availability of forwarders inside proxy.

func (*Proxy) Dial

func (p *Proxy) Dial(network, addr string) (net.Conn, proxy.Dialer, error)

Dial dials to targer addr and return a conn.

func (*Proxy) DialUDP

func (p *Proxy) DialUDP(network, addr string) (pc net.PacketConn, dialer proxy.UDPDialer, err error)

DialUDP connects to the given address via the proxy.

func (*Proxy) GetAvailStatus

func (p *Proxy) GetAvailStatus(index uint32, url, enabled string, prio int) []ProxyStatus

func (*Proxy) GetMainStatus

func (p *Proxy) GetMainStatus(index uint32, url, enabled string, prio int) []ProxyStatus

func (*Proxy) GetRateLimit

func (p *Proxy) GetRateLimit() int64

Record records result while using the dialer from proxy.

func (*Proxy) MatchRoutes

func (p *Proxy) MatchRoutes(target interface{}) string

func (*Proxy) NextDialer

func (p *Proxy) NextDialer(dstAddr string) proxy.Dialer

NextDialer returns next dialer according to rule.

func (*Proxy) OperateMain

func (p *Proxy) OperateMain(id uint32, url, enabled string, prio int, op, stat string) []ProxyStatus

func (*Proxy) Record

func (p *Proxy) Record(dialer proxy.Dialer, success bool)

Record records result while using the dialer from proxy.

func (*Proxy) SetCheckNow

func (p *Proxy) SetCheckNow(id uint32, url, enabled string, prio int)

func (*Proxy) SetRateLimit

func (p *Proxy) SetRateLimit(rate int64)

Record records result while using the dialer from proxy.

func (*Proxy) UpdateInOut

func (p *Proxy) UpdateInOut(dialer proxy.Dialer, inbytes, outbytes uint64)

Record records result while using the dialer from proxy.

type ProxyStatus

type ProxyStatus struct {
	ID            uint32 `json:"id"`
	URL           string `json:"url"`
	Priority      uint32 `json:"priority"`
	MaxFailures   uint32 `json:"max_failures"` // maxfailures to set to Disabled
	Enabled       bool   `json:"enabled"`
	ChkCount      uint32 `json:"chkcount"`
	MDisabled     bool   `json:"manualy_disabled"`
	TotalFails    uint32 `json:"failures"`
	Latency       int64  `json:"latency"`
	InBytes       uint64 `json:"inbytes"`
	OutBytes      uint64 `json:"outbytes"`
	Maps          string `json:"routemap"`
	GroupName     string `json:"groupname"`
	GroupStrategy string `json:"groupstrategy"`
}

type StatusHandler

type StatusHandler func(*Forwarder)

StatusHandler function will be called when the forwarder's status changed.

type Strategy

type Strategy struct {
	Strategy            string
	Check               string
	CheckInterval       int
	CheckTimeout        int
	PriorityStep        int
	CheckTolerance      int
	CheckLatencySamples int
	CheckDisabledOnly   bool
	CheckLowerPriority  bool
	MaxFailures         int
	DialTimeout         int
	RelayTimeout        int
	IntFace             string
}

Strategy configurations.

Jump to

Keyboard shortcuts

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