From 82ac6dcf6d3caf71f908c245405b84cbae5dea92 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 25 Jan 2021 16:46:35 +0800 Subject: [PATCH] rename MaxReceivePacketSize to MaxPacketBufferSize We use the same buffer size for sending and receiving packets. --- buffer_pool.go | 4 ++-- buffer_pool_test.go | 2 +- conn.go | 4 ++-- conn_ecn.go | 4 ++-- conn_test.go | 2 +- integrationtests/tools/proxy/proxy.go | 4 ++-- integrationtests/tools/proxy/proxy_test.go | 8 ++++---- internal/protocol/protocol.go | 4 ++-- internal/wire/pool.go | 4 ++-- internal/wire/stream_frame_test.go | 6 +++--- internal/wire/transport_parameters.go | 2 +- send_stream.go | 2 +- send_stream_test.go | 4 ++-- session_test.go | 2 +- 14 files changed, 26 insertions(+), 26 deletions(-) diff --git a/buffer_pool.go b/buffer_pool.go index 721677e2..c0b7067d 100644 --- a/buffer_pool.go +++ b/buffer_pool.go @@ -56,7 +56,7 @@ func (b *packetBuffer) Len() protocol.ByteCount { } func (b *packetBuffer) putBack() { - if cap(b.Data) != int(protocol.MaxReceivePacketSize) { + if cap(b.Data) != int(protocol.MaxPacketBufferSize) { panic("putPacketBuffer called with packet of wrong size!") } bufferPool.Put(b) @@ -74,7 +74,7 @@ func getPacketBuffer() *packetBuffer { func init() { bufferPool.New = func() interface{} { return &packetBuffer{ - Data: make([]byte, 0, protocol.MaxReceivePacketSize), + Data: make([]byte, 0, protocol.MaxPacketBufferSize), } } } diff --git a/buffer_pool_test.go b/buffer_pool_test.go index 7aafbc46..54f4d225 100644 --- a/buffer_pool_test.go +++ b/buffer_pool_test.go @@ -10,7 +10,7 @@ import ( var _ = Describe("Buffer Pool", func() { It("returns buffers of cap", func() { buf := getPacketBuffer() - Expect(buf.Data).To(HaveCap(int(protocol.MaxReceivePacketSize))) + Expect(buf.Data).To(HaveCap(int(protocol.MaxPacketBufferSize))) }) It("releases buffers", func() { diff --git a/conn.go b/conn.go index f4506a47..f085f738 100644 --- a/conn.go +++ b/conn.go @@ -44,9 +44,9 @@ var _ connection = &basicConn{} func (c *basicConn) ReadPacket() (*receivedPacket, error) { buffer := getPacketBuffer() - // The packet size should not exceed protocol.MaxReceivePacketSize bytes + // The packet size should not exceed protocol.MaxPacketBufferSize bytes // If it does, we only read a truncated packet, which will then end up undecryptable - buffer.Data = buffer.Data[:protocol.MaxReceivePacketSize] + buffer.Data = buffer.Data[:protocol.MaxPacketBufferSize] n, addr, err := c.PacketConn.ReadFrom(buffer.Data) if err != nil { return nil, err diff --git a/conn_ecn.go b/conn_ecn.go index 5f8d6d87..a115895e 100644 --- a/conn_ecn.go +++ b/conn_ecn.go @@ -82,9 +82,9 @@ func newConn(c ECNCapablePacketConn) (*ecnConn, error) { func (c *ecnConn) ReadPacket() (*receivedPacket, error) { buffer := getPacketBuffer() - // The packet size should not exceed protocol.MaxReceivePacketSize bytes + // The packet size should not exceed protocol.MaxPacketBufferSize bytes // If it does, we only read a truncated packet, which will then end up undecryptable - buffer.Data = buffer.Data[:protocol.MaxReceivePacketSize] + buffer.Data = buffer.Data[:protocol.MaxPacketBufferSize] c.oobBuffer = c.oobBuffer[:cap(c.oobBuffer)] n, oobn, _, addr, err := c.ECNCapablePacketConn.ReadMsgUDP(buffer.Data, c.oobBuffer) if err != nil { diff --git a/conn_test.go b/conn_test.go index b4b39ae1..43afff61 100644 --- a/conn_test.go +++ b/conn_test.go @@ -18,7 +18,7 @@ var _ = Describe("Basic Conn Test", func() { addr := &net.UDPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 1234} c.EXPECT().ReadFrom(gomock.Any()).DoAndReturn(func(b []byte) (int, net.Addr, error) { data := []byte("foobar") - Expect(b).To(HaveLen(int(protocol.MaxReceivePacketSize))) + Expect(b).To(HaveLen(int(protocol.MaxPacketBufferSize))) return copy(b, data), addr, nil }) diff --git a/integrationtests/tools/proxy/proxy.go b/integrationtests/tools/proxy/proxy.go index 1e5c90ec..110b1805 100644 --- a/integrationtests/tools/proxy/proxy.go +++ b/integrationtests/tools/proxy/proxy.go @@ -241,7 +241,7 @@ func (p *QuicProxy) newConnection(cliAddr *net.UDPAddr) (*connection, error) { // runProxy listens on the proxy address and handles incoming packets. func (p *QuicProxy) runProxy() error { for { - buffer := make([]byte, protocol.MaxReceivePacketSize) + buffer := make([]byte, protocol.MaxPacketBufferSize) n, cliaddr, err := p.conn.ReadFromUDP(buffer) if err != nil { return err @@ -294,7 +294,7 @@ func (p *QuicProxy) runOutgoingConnection(conn *connection) error { outgoingPackets := make(chan packetEntry, 10) go func() { for { - buffer := make([]byte, protocol.MaxReceivePacketSize) + buffer := make([]byte, protocol.MaxPacketBufferSize) n, err := conn.ServerConn.Read(buffer) if err != nil { return diff --git a/integrationtests/tools/proxy/proxy_test.go b/integrationtests/tools/proxy/proxy_test.go index ca6f2a08..fb3f8528 100644 --- a/integrationtests/tools/proxy/proxy_test.go +++ b/integrationtests/tools/proxy/proxy_test.go @@ -169,7 +169,7 @@ var _ = Describe("QUIC Proxy", func() { defer GinkgoRecover() defer close(stoppedReading) for { - buf := make([]byte, protocol.MaxReceivePacketSize) + buf := make([]byte, protocol.MaxPacketBufferSize) // the ReadFromUDP will error as soon as the UDP conn is closed n, addr, err2 := serverConn.ReadFromUDP(buf) if err2 != nil { @@ -221,7 +221,7 @@ var _ = Describe("QUIC Proxy", func() { // receive the packets echoed by the server on client side go func() { for { - buf := make([]byte, protocol.MaxReceivePacketSize) + buf := make([]byte, protocol.MaxPacketBufferSize) // the ReadFromUDP will error as soon as the UDP conn is closed n, _, err2 := clientConn.ReadFromUDP(buf) if err2 != nil { @@ -280,7 +280,7 @@ var _ = Describe("QUIC Proxy", func() { // receive the packets echoed by the server on client side go func() { for { - buf := make([]byte, protocol.MaxReceivePacketSize) + buf := make([]byte, protocol.MaxPacketBufferSize) // the ReadFromUDP will error as soon as the UDP conn is closed n, _, err2 := clientConn.ReadFromUDP(buf) if err2 != nil { @@ -424,7 +424,7 @@ var _ = Describe("QUIC Proxy", func() { // receive the packets echoed by the server on client side go func() { for { - buf := make([]byte, protocol.MaxReceivePacketSize) + buf := make([]byte, protocol.MaxPacketBufferSize) // the ReadFromUDP will error as soon as the UDP conn is closed n, _, err2 := clientConn.ReadFromUDP(buf) if err2 != nil { diff --git a/internal/protocol/protocol.go b/internal/protocol/protocol.go index 74e9e98c..1aa5f9f2 100644 --- a/internal/protocol/protocol.go +++ b/internal/protocol/protocol.go @@ -58,11 +58,11 @@ type ApplicationErrorCode uint64 // A StatelessResetToken is a stateless reset token. type StatelessResetToken [16]byte -// MaxReceivePacketSize maximum packet size of any QUIC packet, based on +// MaxPacketBufferSize maximum packet size of any QUIC packet, based on // ethernet's max size, minus the IP and UDP headers. IPv6 has a 40 byte header, // UDP adds an additional 8 bytes. This is a total overhead of 48 bytes. // Ethernet's max packet size is 1500 bytes, 1500 - 48 = 1452. -const MaxReceivePacketSize ByteCount = 1452 +const MaxPacketBufferSize ByteCount = 1452 // MinInitialPacketSize is the minimum size an Initial packet is required to have. const MinInitialPacketSize = 1200 diff --git a/internal/wire/pool.go b/internal/wire/pool.go index 334b79b3..c057395e 100644 --- a/internal/wire/pool.go +++ b/internal/wire/pool.go @@ -11,7 +11,7 @@ var pool sync.Pool func init() { pool.New = func() interface{} { return &StreamFrame{ - Data: make([]byte, 0, protocol.MaxReceivePacketSize), + Data: make([]byte, 0, protocol.MaxPacketBufferSize), fromPool: true, } } @@ -26,7 +26,7 @@ func putStreamFrame(f *StreamFrame) { if !f.fromPool { return } - if protocol.ByteCount(cap(f.Data)) != protocol.MaxReceivePacketSize { + if protocol.ByteCount(cap(f.Data)) != protocol.MaxPacketBufferSize { panic("wire.PutStreamFrame called with packet of wrong size!") } pool.Put(f) diff --git a/internal/wire/stream_frame_test.go b/internal/wire/stream_frame_test.go index 62e825bd..6d4fef68 100644 --- a/internal/wire/stream_frame_test.go +++ b/internal/wire/stream_frame_test.go @@ -82,9 +82,9 @@ var _ = Describe("STREAM frame", func() { It("rejects frames that claim to be longer than the packet size", func() { data := []byte{0x8 ^ 0x2} - data = append(data, encodeVarInt(0x12345)...) // stream ID - data = append(data, encodeVarInt(uint64(protocol.MaxReceivePacketSize)+1)...) // data length - data = append(data, make([]byte, protocol.MaxReceivePacketSize+1)...) + data = append(data, encodeVarInt(0x12345)...) // stream ID + data = append(data, encodeVarInt(uint64(protocol.MaxPacketBufferSize)+1)...) // data length + data = append(data, make([]byte, protocol.MaxPacketBufferSize+1)...) r := bytes.NewReader(data) _, err := parseStreamFrame(r, versionIETFFrames) Expect(err).To(Equal(io.EOF)) diff --git a/internal/wire/transport_parameters.go b/internal/wire/transport_parameters.go index 14724a7e..e0fb7b04 100644 --- a/internal/wire/transport_parameters.go +++ b/internal/wire/transport_parameters.go @@ -335,7 +335,7 @@ func (p *TransportParameters) Marshal(pers protocol.Perspective) []byte { // idle_timeout p.marshalVarintParam(b, maxIdleTimeoutParameterID, uint64(p.MaxIdleTimeout/time.Millisecond)) // max_packet_size - p.marshalVarintParam(b, maxUDPPayloadSizeParameterID, uint64(protocol.MaxReceivePacketSize)) + p.marshalVarintParam(b, maxUDPPayloadSizeParameterID, uint64(protocol.MaxPacketBufferSize)) // max_ack_delay // Only send it if is different from the default value. if p.MaxAckDelay != protocol.DefaultMaxAckDelay { diff --git a/send_stream.go b/send_stream.go index 885ed7a9..32366683 100644 --- a/send_stream.go +++ b/send_stream.go @@ -191,7 +191,7 @@ func (s *sendStream) canBufferStreamFrame() bool { if s.nextFrame != nil { l = s.nextFrame.DataLen() } - return l+protocol.ByteCount(len(s.dataForWriting)) <= protocol.MaxReceivePacketSize + return l+protocol.ByteCount(len(s.dataForWriting)) <= protocol.MaxPacketBufferSize } // popStreamFrame returns the next STREAM frame that is supposed to be sent on this stream diff --git a/send_stream_test.go b/send_stream_test.go index ec7bed00..a0d70545 100644 --- a/send_stream_test.go +++ b/send_stream_test.go @@ -180,7 +180,7 @@ var _ = Describe("Send Stream", func() { defer GinkgoRecover() defer close(done) mockSender.EXPECT().onHasStreamData(streamID) - _, err := strWithTimeout.Write(getData(protocol.MaxReceivePacketSize + 3)) + _, err := strWithTimeout.Write(getData(protocol.MaxPacketBufferSize + 3)) Expect(err).ToNot(HaveOccurred()) }() waitForWrite() @@ -208,7 +208,7 @@ var _ = Describe("Send Stream", func() { defer GinkgoRecover() defer close(done) mockSender.EXPECT().onHasStreamData(streamID) - _, err := str.Write(getData(protocol.MaxReceivePacketSize)) + _, err := str.Write(getData(protocol.MaxPacketBufferSize)) Expect(err).ToNot(HaveOccurred()) }() waitForWrite() diff --git a/session_test.go b/session_test.go index 5e8cb97b..abde2f8a 100644 --- a/session_test.go +++ b/session_test.go @@ -2052,7 +2052,7 @@ var _ = Describe("Session", func() { InitialMaxData: 0x5000, ActiveConnectionIDLimit: 3, // marshaling always sets it to this value - MaxUDPPayloadSize: protocol.MaxReceivePacketSize, + MaxUDPPayloadSize: protocol.MaxPacketBufferSize, InitialSourceConnectionID: destConnID, } streamManager.EXPECT().UpdateLimits(params)