sing-box/route/rule_inbound.go

36 lines
746 B
Go
Raw Normal View History

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