mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-08-05 21:35:15 +03:00
Add tunnel
This commit is contained in:
35
route/rule/rule_item_tunnel_destination.go
Normal file
35
route/rule/rule_item_tunnel_destination.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package rule
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
F "github.com/sagernet/sing/common/format"
|
||||
)
|
||||
|
||||
var _ RuleItem = (*TunnelDestinationItem)(nil)
|
||||
|
||||
type TunnelDestinationItem struct {
|
||||
destinations []string
|
||||
destinationMap map[string]bool
|
||||
}
|
||||
|
||||
func NewTunnelDestinationItem(destinations []string) *TunnelDestinationItem {
|
||||
rule := &TunnelDestinationItem{destinations, make(map[string]bool)}
|
||||
for _, destination := range destinations {
|
||||
rule.destinationMap[destination] = true
|
||||
}
|
||||
return rule
|
||||
}
|
||||
|
||||
func (r *TunnelDestinationItem) Match(metadata *adapter.InboundContext) bool {
|
||||
return r.destinationMap[metadata.TunnelDestination]
|
||||
}
|
||||
|
||||
func (r *TunnelDestinationItem) String() string {
|
||||
if len(r.destinations) == 1 {
|
||||
return F.ToString("tunnel_destination=", r.destinations[0])
|
||||
} else {
|
||||
return F.ToString("tunnel_destination=[", strings.Join(r.destinations, " "), "]")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user