forked from v2fly/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix(freebsd): ReadUDPMsg nil pointer
Co-authored-by: ksco.he <ksco.he@ponyft.com> Co-authored-by: 秋のかえで <autmaple@protonmail.com> Chore: bump google.golang.org/grpc from 1.49.0 to 1.50.0 (v2fly#2046) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> fix: socks4/4a client handshake (v2fly#1971) Feat: add transport original name to listen unix (v2fly#2048) Feat: add bind to device to Windows and Darwin (v2fly#1972) fix: Replace "math/rand" with "crypto/rand" in padding generation(v2fly#2032) Chore: github.com/lucas-clemente/quic-go from 0.29.0 to 0.29.1 (v2fly#2010) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> feat: Replace default Health Ping URL to HTTPS (v2fly#1991) Chore: update dependencies (v2fly#1995) Refactor: replace netaddr package with netipx (v2fly#1994) Fix: remove v2ctl from debian/rules (v2fly#1954) * Remove v2ctl from debian/rules It seems to be left over from v2fly#488 * Chore: use Go v1.19 to build debian package Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Chore: bump google.golang.org/grpc from 1.48.0 to 1.49.0 (v2fly#1935) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Chore: bump github.com/google/go-cmp from 0.5.8 to 0.5.9 (v2fly#1959) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Chore: bump github.com/jhump/protoreflect from 1.12.0 to 1.13.0 (v2fly#1982) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> feat: Implement Match and MatchAny for all MatcherGroup, IndexMatcher [common/strmatcher] Implement Match and MatchAny for all MatcherGroup and IndexMatcher
- Loading branch information
Showing
29 changed files
with
766 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package strmatcher_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/v2fly/v2ray-core/v5/common/strmatcher" | ||
) | ||
|
||
func BenchmarkLinearIndexMatcher(b *testing.B) { | ||
benchmarkIndexMatcher(b, func() IndexMatcher { | ||
return NewLinearIndexMatcher() | ||
}) | ||
} | ||
|
||
func BenchmarkMphIndexMatcher(b *testing.B) { | ||
benchmarkIndexMatcher(b, func() IndexMatcher { | ||
return NewMphIndexMatcher() | ||
}) | ||
} | ||
|
||
func benchmarkIndexMatcher(b *testing.B, ctor func() IndexMatcher) { | ||
b.Run("Match", func(b *testing.B) { | ||
b.Run("Domain------------", func(b *testing.B) { | ||
benchmarkMatch(b, ctor(), map[Type]bool{Domain: true}) | ||
}) | ||
b.Run("Domain+Full-------", func(b *testing.B) { | ||
benchmarkMatch(b, ctor(), map[Type]bool{Domain: true, Full: true}) | ||
}) | ||
b.Run("Domain+Full+Substr", func(b *testing.B) { | ||
benchmarkMatch(b, ctor(), map[Type]bool{Domain: true, Full: true, Substr: true}) | ||
}) | ||
b.Run("All-Fail----------", func(b *testing.B) { | ||
benchmarkMatch(b, ctor(), map[Type]bool{Domain: false, Full: false, Substr: false}) | ||
}) | ||
}) | ||
b.Run("Match/Dotless", func(b *testing.B) { // Dotless domain matcher automatically inserted in DNS app when "localhost" DNS is used. | ||
b.Run("All-Succ", func(b *testing.B) { | ||
benchmarkMatch(b, ctor(), map[Type]bool{Domain: true, Full: true, Substr: true, Regex: true}) | ||
}) | ||
b.Run("All-Fail", func(b *testing.B) { | ||
benchmarkMatch(b, ctor(), map[Type]bool{Domain: false, Full: false, Substr: false, Regex: false}) | ||
}) | ||
}) | ||
b.Run("MatchAny", func(b *testing.B) { | ||
b.Run("First-Full--", func(b *testing.B) { | ||
benchmarkMatchAny(b, ctor(), map[Type]bool{Full: true, Domain: true, Substr: true}) | ||
}) | ||
b.Run("First-Domain", func(b *testing.B) { | ||
benchmarkMatchAny(b, ctor(), map[Type]bool{Full: false, Domain: true, Substr: true}) | ||
}) | ||
b.Run("First-Substr", func(b *testing.B) { | ||
benchmarkMatchAny(b, ctor(), map[Type]bool{Full: false, Domain: false, Substr: true}) | ||
}) | ||
b.Run("All-Fail----", func(b *testing.B) { | ||
benchmarkMatchAny(b, ctor(), map[Type]bool{Full: false, Domain: false, Substr: false}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package strmatcher_test | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/v2fly/v2ray-core/v5/common" | ||
. "github.com/v2fly/v2ray-core/v5/common/strmatcher" | ||
) | ||
|
||
func BenchmarkFullMatcher(b *testing.B) { | ||
b.Run("SimpleMatcherGroup------", func(b *testing.B) { | ||
benchmarkMatcherType(b, Full, func() MatcherGroup { | ||
return new(SimpleMatcherGroup) | ||
}) | ||
}) | ||
b.Run("FullMatcherGroup--------", func(b *testing.B) { | ||
benchmarkMatcherType(b, Full, func() MatcherGroup { | ||
return NewFullMatcherGroup() | ||
}) | ||
}) | ||
b.Run("ACAutomationMatcherGroup", func(b *testing.B) { | ||
benchmarkMatcherType(b, Full, func() MatcherGroup { | ||
return NewACAutomatonMatcherGroup() | ||
}) | ||
}) | ||
b.Run("MphMatcherGroup---------", func(b *testing.B) { | ||
benchmarkMatcherType(b, Full, func() MatcherGroup { | ||
return NewMphMatcherGroup() | ||
}) | ||
}) | ||
} | ||
|
||
func BenchmarkDomainMatcher(b *testing.B) { | ||
b.Run("SimpleMatcherGroup------", func(b *testing.B) { | ||
benchmarkMatcherType(b, Domain, func() MatcherGroup { | ||
return new(SimpleMatcherGroup) | ||
}) | ||
}) | ||
b.Run("DomainMatcherGroup------", func(b *testing.B) { | ||
benchmarkMatcherType(b, Domain, func() MatcherGroup { | ||
return NewDomainMatcherGroup() | ||
}) | ||
}) | ||
b.Run("ACAutomationMatcherGroup", func(b *testing.B) { | ||
benchmarkMatcherType(b, Domain, func() MatcherGroup { | ||
return NewACAutomatonMatcherGroup() | ||
}) | ||
}) | ||
b.Run("MphMatcherGroup---------", func(b *testing.B) { | ||
benchmarkMatcherType(b, Domain, func() MatcherGroup { | ||
return NewMphMatcherGroup() | ||
}) | ||
}) | ||
} | ||
|
||
func BenchmarkSubstrMatcher(b *testing.B) { | ||
b.Run("SimpleMatcherGroup------", func(b *testing.B) { | ||
benchmarkMatcherType(b, Substr, func() MatcherGroup { | ||
return new(SimpleMatcherGroup) | ||
}) | ||
}) | ||
b.Run("SubstrMatcherGroup------", func(b *testing.B) { | ||
benchmarkMatcherType(b, Substr, func() MatcherGroup { | ||
return new(SubstrMatcherGroup) | ||
}) | ||
}) | ||
b.Run("ACAutomationMatcherGroup", func(b *testing.B) { | ||
benchmarkMatcherType(b, Substr, func() MatcherGroup { | ||
return NewACAutomatonMatcherGroup() | ||
}) | ||
}) | ||
} | ||
|
||
// Utility functions for benchmark | ||
|
||
func benchmarkMatcherType(b *testing.B, t Type, ctor func() MatcherGroup) { | ||
b.Run("Match", func(b *testing.B) { | ||
b.Run("Succ", func(b *testing.B) { | ||
benchmarkMatch(b, ctor(), map[Type]bool{t: true}) | ||
}) | ||
b.Run("Fail", func(b *testing.B) { | ||
benchmarkMatch(b, ctor(), map[Type]bool{t: false}) | ||
}) | ||
}) | ||
b.Run("MatchAny", func(b *testing.B) { | ||
b.Run("Succ", func(b *testing.B) { | ||
benchmarkMatchAny(b, ctor(), map[Type]bool{t: true}) | ||
}) | ||
b.Run("Fail", func(b *testing.B) { | ||
benchmarkMatchAny(b, ctor(), map[Type]bool{t: false}) | ||
}) | ||
}) | ||
} | ||
|
||
func benchmarkMatch(b *testing.B, g MatcherGroup, enabledTypes map[Type]bool) { | ||
prepareMatchers(g, enabledTypes) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_ = g.Match("0.v2fly.org") | ||
} | ||
} | ||
|
||
func benchmarkMatchAny(b *testing.B, g MatcherGroup, enabledTypes map[Type]bool) { | ||
prepareMatchers(g, enabledTypes) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_ = g.MatchAny("0.v2fly.org") | ||
} | ||
} | ||
|
||
func prepareMatchers(g MatcherGroup, enabledTypes map[Type]bool) { | ||
for matcherType, hasMatch := range enabledTypes { | ||
switch matcherType { | ||
case Domain: | ||
if hasMatch { | ||
AddMatcherToGroup(g, DomainMatcher("v2fly.org"), 0) | ||
} | ||
for i := 1; i < 1024; i++ { | ||
AddMatcherToGroup(g, DomainMatcher(strconv.Itoa(i)+".v2fly.org"), uint32(i)) | ||
} | ||
case Full: | ||
if hasMatch { | ||
AddMatcherToGroup(g, FullMatcher("0.v2fly.org"), 0) | ||
} | ||
for i := 1; i < 64; i++ { | ||
AddMatcherToGroup(g, FullMatcher(strconv.Itoa(i)+".v2fly.org"), uint32(i)) | ||
} | ||
case Substr: | ||
if hasMatch { | ||
AddMatcherToGroup(g, SubstrMatcher("v2fly.org"), 0) | ||
} | ||
for i := 1; i < 4; i++ { | ||
AddMatcherToGroup(g, SubstrMatcher(strconv.Itoa(i)+".v2fly.org"), uint32(i)) | ||
} | ||
case Regex: | ||
matcher, err := Regex.New("^[^.]*$") // Dotless domain matcher automatically inserted in DNS app when "localhost" DNS is used. | ||
common.Must(err) | ||
AddMatcherToGroup(g, matcher, 0) | ||
} | ||
} | ||
if g, ok := g.(buildable); ok { | ||
common.Must(g.Build()) | ||
} | ||
} | ||
|
||
type buildable interface { | ||
Build() error | ||
} |
Oops, something went wrong.