From 0665c08b880bb9aaac7a30c46d797159877f91bd Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sun, 27 Aug 2017 17:55:38 +0700 Subject: [PATCH] make PeekConnectionID a private method --- public_header.go | 4 ++-- public_header_test.go | 10 +++++----- server.go | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/public_header.go b/public_header.go index 8d440b80..9140fc8c 100644 --- a/public_header.go +++ b/public_header.go @@ -113,9 +113,9 @@ func (h *PublicHeader) Write(b *bytes.Buffer, version protocol.VersionNumber, pe return nil } -// PeekConnectionID parses the connection ID from a QUIC packet's public header. +// peekConnectionID parses the connection ID from a QUIC packet's public header. // If no error occurs, it restores the read position in the bytes.Reader. -func PeekConnectionID(b *bytes.Reader, packetSentBy protocol.Perspective) (protocol.ConnectionID, error) { +func peekConnectionID(b *bytes.Reader, packetSentBy protocol.Perspective) (protocol.ConnectionID, error) { var connectionID protocol.ConnectionID publicFlagByte, err := b.ReadByte() if err != nil { diff --git a/public_header_test.go b/public_header_test.go index e9b9ce40..6d151234 100644 --- a/public_header_test.go +++ b/public_header_test.go @@ -15,14 +15,14 @@ var _ = Describe("Public Header", func() { Context("parsing the connection ID", func() { It("does not accept truncated connection ID as a server", func() { b := bytes.NewReader([]byte{0x00, 0x01}) - _, err := PeekConnectionID(b, protocol.PerspectiveClient) + _, err := peekConnectionID(b, protocol.PerspectiveClient) Expect(err).To(MatchError(errReceivedTruncatedConnectionID)) }) It("gets the connection ID", func() { b := bytes.NewReader([]byte{0x09, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 0x51, 0x30, 0x33, 0x34, 0x01}) len := b.Len() - connID, err := PeekConnectionID(b, protocol.PerspectiveClient) + connID, err := peekConnectionID(b, protocol.PerspectiveClient) Expect(err).ToNot(HaveOccurred()) Expect(connID).To(Equal(protocol.ConnectionID(0x4cfa9f9b668619f6))) Expect(b.Len()).To(Equal(len)) @@ -30,20 +30,20 @@ var _ = Describe("Public Header", func() { It("errors if the Public Header is too short", func() { b := bytes.NewReader([]byte{0x09, 0xf6, 0x19, 0x86, 0x66, 0x9b}) - _, err := PeekConnectionID(b, protocol.PerspectiveClient) + _, err := peekConnectionID(b, protocol.PerspectiveClient) Expect(err).To(HaveOccurred()) }) It("errors if the Public Header is empty", func() { b := bytes.NewReader([]byte{}) - _, err := PeekConnectionID(b, protocol.PerspectiveClient) + _, err := peekConnectionID(b, protocol.PerspectiveClient) Expect(err).To(HaveOccurred()) }) It("accepts a truncated connection ID as a client", func() { b := bytes.NewReader([]byte{0x00, 0x01}) len := b.Len() - connID, err := PeekConnectionID(b, protocol.PerspectiveServer) + connID, err := peekConnectionID(b, protocol.PerspectiveServer) Expect(err).ToNot(HaveOccurred()) Expect(connID).To(BeZero()) Expect(b.Len()).To(Equal(len)) diff --git a/server.go b/server.go index 9ec3fc64..032a5757 100644 --- a/server.go +++ b/server.go @@ -206,7 +206,7 @@ func (s *server) handlePacket(pconn net.PacketConn, remoteAddr net.Addr, packet rcvTime := time.Now() r := bytes.NewReader(packet) - connID, err := PeekConnectionID(r, protocol.PerspectiveClient) + connID, err := peekConnectionID(r, protocol.PerspectiveClient) if err != nil { return qerr.Error(qerr.InvalidPacketHeader, err.Error()) }