Skip to content

Commit

Permalink
Fix(freebsd): ReadUDPMsg nil pointer
Browse files Browse the repository at this point in the history
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
arm64v8a committed Oct 11, 2022
1 parent db8b0dd commit 0340b12
Show file tree
Hide file tree
Showing 29 changed files with 766 additions and 342 deletions.
2 changes: 1 addition & 1 deletion app/observatory/burst/config.pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type HealthPingConfig struct {
unknownFields protoimpl.UnknownFields

// destination url, need 204 for success return
// default http://www.google.com/gen_204
// default https://connectivitycheck.gstatic.com/generate_204
Destination string `protobuf:"bytes,1,opt,name=destination,proto3" json:"destination,omitempty"`
// connectivity check url
Connectivity string `protobuf:"bytes,2,opt,name=connectivity,proto3" json:"connectivity,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions app/observatory/burst/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ message Config {

message HealthPingConfig {
// destination url, need 204 for success return
// default http://www.google.com/gen_204
// default https://connectivitycheck.gstatic.com/generate_204
string destination = 1;
// connectivity check url
string connectivity = 2;
Expand All @@ -31,4 +31,4 @@ message HealthPingConfig {
int32 samplingCount = 4;
// ping timeout, int64 values of time.Duration
int64 timeout = 5;
}
}
5 changes: 4 additions & 1 deletion app/observatory/burst/healthping.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ func NewHealthPing(ctx context.Context, config *HealthPingConfig) *HealthPing {
}
}
if settings.Destination == "" {
settings.Destination = "http://www.google.com/gen_204"
// Destination URL, need 204 for success return default to chromium
// https://github.com/chromium/chromium/blob/main/components/safety_check/url_constants.cc#L10
// https://chromium.googlesource.com/chromium/src/+/refs/heads/main/components/safety_check/url_constants.cc#10
settings.Destination = "https://connectivitycheck.gstatic.com/generate_204"
}
if settings.Interval == 0 {
settings.Interval = time.Duration(1) * time.Minute
Expand Down
20 changes: 12 additions & 8 deletions app/router/condition_geoip.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package router

import (
"inet.af/netaddr"
"net/netip"

"go4.org/netipx"

"github.com/v2fly/v2ray-core/v5/app/router/routercommon"
"github.com/v2fly/v2ray-core/v5/common/net"
Expand All @@ -10,18 +12,20 @@ import (
type GeoIPMatcher struct {
countryCode string
reverseMatch bool
ip4 *netaddr.IPSet
ip6 *netaddr.IPSet
ip4 *netipx.IPSet
ip6 *netipx.IPSet
}

func (m *GeoIPMatcher) Init(cidrs []*routercommon.CIDR) error {
var builder4, builder6 netaddr.IPSetBuilder
var builder4, builder6 netipx.IPSetBuilder
for _, cidr := range cidrs {
netaddrIP, ok := netaddr.FromStdIP(net.IP(cidr.GetIp()))
netaddrIP, ok := netip.AddrFromSlice(cidr.GetIp())
if !ok {
return newError("invalid IP address ", cidr)
}
ipPrefix := netaddr.IPPrefixFrom(netaddrIP, uint8(cidr.GetPrefix()))
netaddrIP = netaddrIP.Unmap()
ipPrefix := netip.PrefixFrom(netaddrIP, int(cidr.GetPrefix()))

switch {
case netaddrIP.Is4():
builder4.AddPrefix(ipPrefix)
Expand All @@ -48,15 +52,15 @@ func (m *GeoIPMatcher) SetReverseMatch(isReverseMatch bool) {
}

func (m *GeoIPMatcher) match4(ip net.IP) bool {
nip, ok := netaddr.FromStdIP(ip)
nip, ok := netipx.FromStdIP(ip)
if !ok {
return false
}
return m.ip4.Contains(nip)
}

func (m *GeoIPMatcher) match6(ip net.IP) bool {
nip, ok := netaddr.FromStdIP(ip)
nip, ok := netipx.FromStdIP(ip)
if !ok {
return false
}
Expand Down
5 changes: 3 additions & 2 deletions common/crypto/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package crypto

import (
"crypto/cipher"
"crypto/rand"
"io"
"math/rand"

"github.com/v2fly/v2ray-core/v5/common"
"github.com/v2fly/v2ray-core/v5/common/buf"
Expand Down Expand Up @@ -270,7 +270,8 @@ func (w *AuthenticationWriter) seal(b []byte) (*buf.Buffer, error) {
return nil, err
}
if paddingSize > 0 {
// With size of the chunk and padding length encrypted, the content of padding doesn't matter much.
// These paddings will send in clear text.
// To avoid leakage of PRNG internal state, a cryptographically secure PRNG should be used.
paddingBytes := eb.Extend(paddingSize)
common.Must2(rand.Read(paddingBytes))
}
Expand Down
58 changes: 58 additions & 0 deletions common/strmatcher/benchmark_indexmatcher_test.go
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})
})
})
}
149 changes: 149 additions & 0 deletions common/strmatcher/benchmark_matchers_test.go
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
}
Loading

0 comments on commit 0340b12

Please sign in to comment.