1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00

optimize network matcher

This commit is contained in:
Darien Raymond 2018-11-20 12:25:56 +01:00
parent 120058310a
commit b9c8506c23
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -182,21 +182,23 @@ func (v *PortMatcher) Apply(ctx context.Context) bool {
} }
type NetworkMatcher struct { type NetworkMatcher struct {
network *net.NetworkList list [8]bool
} }
func NewNetworkMatcher(network *net.NetworkList) *NetworkMatcher { func NewNetworkMatcher(network *net.NetworkList) NetworkMatcher {
return &NetworkMatcher{ var matcher NetworkMatcher
network: network, for _, n := range network.Network {
matcher.list[int(n)] = true
} }
return matcher
} }
func (v *NetworkMatcher) Apply(ctx context.Context) bool { func (v NetworkMatcher) Apply(ctx context.Context) bool {
outbound := session.OutboundFromContext(ctx) outbound := session.OutboundFromContext(ctx)
if outbound == nil || !outbound.Target.IsValid() { if outbound == nil || !outbound.Target.IsValid() {
return false return false
} }
return v.network.HasNetwork(outbound.Target.Network) return v.list[int(outbound.Target.Network)]
} }
type UserMatcher struct { type UserMatcher struct {