mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-01-05 08:45:22 -05:00
prototype for new sniffing mechanism
This commit is contained in:
@@ -2,9 +2,11 @@ package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"v2ray.com/core/app/dispatcher"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/strmatcher"
|
||||
@@ -372,3 +374,38 @@ func (v *InboundTagMatcher) Apply(ctx context.Context) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type ProtocolMatcher struct {
|
||||
protocols []string
|
||||
}
|
||||
|
||||
func NewProtocolMatcher(protocols []string) *ProtocolMatcher {
|
||||
pCopy := make([]string, 0, len(protocols))
|
||||
|
||||
for _, p := range protocols {
|
||||
if len(p) > 0 {
|
||||
pCopy = append(pCopy, p)
|
||||
}
|
||||
}
|
||||
|
||||
return &ProtocolMatcher{
|
||||
protocols: pCopy,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *ProtocolMatcher) Apply(ctx context.Context) bool {
|
||||
result := dispatcher.SniffingResultFromContext(ctx)
|
||||
|
||||
if result == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
protocol := result.Protocol()
|
||||
for _, p := range m.protocols {
|
||||
if strings.HasPrefix(protocol, p) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user