mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-06-27 12:49:03 +03:00
Improve QUIC sniffer
This commit is contained in:
37
route/rule_item_client.go
Normal file
37
route/rule_item_client.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
F "github.com/sagernet/sing/common/format"
|
||||
)
|
||||
|
||||
var _ RuleItem = (*ClientItem)(nil)
|
||||
|
||||
type ClientItem struct {
|
||||
clients []string
|
||||
clientMap map[string]bool
|
||||
}
|
||||
|
||||
func NewClientItem(clients []string) *ClientItem {
|
||||
clientMap := make(map[string]bool)
|
||||
for _, client := range clients {
|
||||
clientMap[client] = true
|
||||
}
|
||||
return &ClientItem{
|
||||
clients: clients,
|
||||
clientMap: clientMap,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ClientItem) Match(metadata *adapter.InboundContext) bool {
|
||||
return r.clientMap[metadata.Client]
|
||||
}
|
||||
|
||||
func (r *ClientItem) String() string {
|
||||
if len(r.clients) == 1 {
|
||||
return F.ToString("client=", r.clients[0])
|
||||
}
|
||||
return F.ToString("client=[", strings.Join(r.clients, " "), "]")
|
||||
}
|
||||
Reference in New Issue
Block a user