Implement route rules

This commit is contained in:
世界
2022-07-02 22:55:10 +08:00
parent 7c57eb70e8
commit 6eae8e361f
40 changed files with 1220 additions and 145 deletions

View File

@@ -7,26 +7,26 @@ import (
F "github.com/sagernet/sing/common/format"
)
var _ RuleItem = (*InboundRule)(nil)
var _ RuleItem = (*InboundItem)(nil)
type InboundRule struct {
type InboundItem struct {
inbounds []string
inboundMap map[string]bool
}
func NewInboundRule(inbounds []string) RuleItem {
rule := &InboundRule{inbounds, make(map[string]bool)}
func NewInboundRule(inbounds []string) *InboundItem {
rule := &InboundItem{inbounds, make(map[string]bool)}
for _, inbound := range inbounds {
rule.inboundMap[inbound] = true
}
return rule
}
func (r *InboundRule) Match(metadata adapter.InboundContext) bool {
func (r *InboundItem) Match(metadata *adapter.InboundContext) bool {
return r.inboundMap[metadata.Inbound]
}
func (r *InboundRule) String() string {
func (r *InboundItem) String() string {
if len(r.inbounds) == 1 {
return F.ToString("inbound=", r.inbounds[0])
} else {