wire: optimize generation of Version Negotiation packets (#4278)

* wire: optimize generation of Version Negotiation packets

* protocol: optimize adding greased version numbers
This commit is contained in:
Marten Seemann
2024-02-01 14:54:04 +07:00
committed by GitHub
parent fbaa941ea1
commit 0582e931a5
3 changed files with 39 additions and 22 deletions

View File

@@ -2,6 +2,7 @@ package wire
import (
"encoding/binary"
"testing"
"golang.org/x/exp/rand"
@@ -91,3 +92,13 @@ var _ = Describe("Version Negotiation Packets", func() {
Expect(reservedVersion&0x0f0f0f0f == 0x0a0a0a0a).To(BeTrue()) // check that it's a greased version number
})
})
func BenchmarkComposeVersionNegotiationPacket(b *testing.B) {
b.ReportAllocs()
supportedVersions := []protocol.Version{protocol.Version2, protocol.Version1, 0x1337}
destConnID := protocol.ArbitraryLenConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0xa, 0xb, 0xc, 0xd}
srcConnID := protocol.ArbitraryLenConnectionID{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}
for i := 0; i < b.N; i++ {
ComposeVersionNegotiation(destConnID, srcConnID, supportedVersions)
}
}