sing-box/route/rule_inbound.go

36 lines
746 B
Go
Raw Permalink Normal View History

2022-07-02 06:07:50 +00:00
package route
import (
"strings"
2022-07-06 07:01:09 +00:00
"github.com/sagernet/sing-box/adapter"
2022-07-08 15:03:57 +00:00
F "github.com/sagernet/sing/common/format"
2022-07-02 06:07:50 +00:00
)
2022-07-02 14:55:10 +00:00
var _ RuleItem = (*InboundItem)(nil)
2022-07-02 06:07:50 +00:00
2022-07-02 14:55:10 +00:00
type InboundItem struct {
2022-07-02 06:07:50 +00:00
inbounds []string
inboundMap map[string]bool
}
2022-07-02 14:55:10 +00:00
func NewInboundRule(inbounds []string) *InboundItem {
rule := &InboundItem{inbounds, make(map[string]bool)}
2022-07-02 06:07:50 +00:00
for _, inbound := range inbounds {
rule.inboundMap[inbound] = true
}
return rule
}
2022-07-02 14:55:10 +00:00
func (r *InboundItem) Match(metadata *adapter.InboundContext) bool {
2022-07-02 06:07:50 +00:00
return r.inboundMap[metadata.Inbound]
}
2022-07-02 14:55:10 +00:00
func (r *InboundItem) String() string {
2022-07-02 06:07:50 +00:00
if len(r.inbounds) == 1 {
return F.ToString("inbound=", r.inbounds[0])
} else {
return F.ToString("inbound=[", strings.Join(r.inbounds, " "), "]")
}
}