make PeekConnectionID a private method

This commit is contained in:
Marten Seemann
2017-08-27 17:55:38 +07:00
parent 3390564e98
commit 0665c08b88
3 changed files with 8 additions and 8 deletions

View File

@@ -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 {

View File

@@ -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))

View File

@@ -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())
}