1
0
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:
Darien Raymond
2018-07-16 13:47:00 +02:00
parent 8912e4eb90
commit c0e37ef34a
16 changed files with 363 additions and 532 deletions

View File

@@ -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
}