rule

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRuleMatchDropped = errors.New("rule matched dropped")
)

Functions

This section is empty.

Types

type Matcher

type Matcher interface {
	Match(*string) bool
	MatchedResult() *RuleItem
}

type RuleItem

type RuleItem struct {
	RuleMode
	RuleType
	Proxy   string
	Value   []string
	Resolve bool
	Accept  bool
}

type RuleMode

type RuleMode uint8
const (
	Global RuleMode = iota
	Direct
	Match
)

func (RuleMode) String

func (m RuleMode) String() string

type RuleType

type RuleType string
var (
	RuleDomain        RuleType = "DOMAIN"
	RuleDomainKeyword RuleType = "DOMAIN-KEYWORD"
	RuleDomainSuffix  RuleType = "DOMAIN-SUFFIX"
	RuleGeoIP         RuleType = "GEOIP"
	RuleIPCIDR        RuleType = "IP-CIDR"
	RuleOthers        RuleType = "OTHERS"

	IndexToRuleType = []RuleType{
		RuleDomain,
		RuleDomainKeyword,
		RuleDomainSuffix,
		RuleGeoIP,
		RuleIPCIDR,
		RuleOthers,
	}
)

type Ruler

type Ruler struct {
	RuleMode

	MS       []Matcher
	DirectTo string // direct connection strategy for MATCH mode
	GlobalTo string // global connection strategy for MATCH mode
	// contains filtered or unexported fields
}
var MatchRuler *Ruler

func NewRuler

func NewRuler(mode RuleMode, directTo, globalTo string, allRules [][]*RuleItem) *Ruler

func (*Ruler) Match

func (r *Ruler) Match(target *string) bool

Match global/direct/match the target value may be: 1. real ip address -> match 2. fake ip address -> domain name -> match 3. domain name -> match

func (*Ruler) MatcherResult

func (r *Ruler) MatcherResult() *RuleItem

func (*Ruler) Select

func (r *Ruler) Select() (proxy string, err error)

Select select a valid proxy node from the currently matched rules if err is not equal to nil, discard the request the returned proxy indicates whether the selected rule is global or direct connection if the proxy is empty, it means the proxy is directly connected

Jump to

Keyboard shortcuts

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