github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/route/rule_item_inbound.go (about)

     1  package route
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/inazumav/sing-box/adapter"
     7  	F "github.com/sagernet/sing/common/format"
     8  )
     9  
    10  var _ RuleItem = (*InboundItem)(nil)
    11  
    12  type InboundItem struct {
    13  	inbounds   []string
    14  	inboundMap map[string]bool
    15  }
    16  
    17  func NewInboundRule(inbounds []string) *InboundItem {
    18  	rule := &InboundItem{inbounds, make(map[string]bool)}
    19  	for _, inbound := range inbounds {
    20  		rule.inboundMap[inbound] = true
    21  	}
    22  	return rule
    23  }
    24  
    25  func (r *InboundItem) Match(metadata *adapter.InboundContext) bool {
    26  	return r.inboundMap[metadata.Inbound]
    27  }
    28  
    29  func (r *InboundItem) String() string {
    30  	if len(r.inbounds) == 1 {
    31  		return F.ToString("inbound=", r.inbounds[0])
    32  	} else {
    33  		return F.ToString("inbound=[", strings.Join(r.inbounds, " "), "]")
    34  	}
    35  }