mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-06 05:37:36 +03:00
embed the Header in the ExtendedHeader
This commit is contained in:
parent
af157408de
commit
b740d57c61
12 changed files with 306 additions and 244 deletions
|
@ -50,7 +50,7 @@ var _ = Describe("Client", func() {
|
||||||
acceptClientVersionPacket := func(connID protocol.ConnectionID) []byte {
|
acceptClientVersionPacket := func(connID protocol.ConnectionID) []byte {
|
||||||
b := &bytes.Buffer{}
|
b := &bytes.Buffer{}
|
||||||
Expect((&wire.ExtendedHeader{
|
Expect((&wire.ExtendedHeader{
|
||||||
DestConnectionID: connID,
|
Header: wire.Header{DestConnectionID: connID},
|
||||||
PacketNumber: 1,
|
PacketNumber: 1,
|
||||||
PacketNumberLen: 1,
|
PacketNumberLen: 1,
|
||||||
}).Write(b, protocol.VersionWhatever)).To(Succeed())
|
}).Write(b, protocol.VersionWhatever)).To(Succeed())
|
||||||
|
@ -516,7 +516,7 @@ var _ = Describe("Client", func() {
|
||||||
DestConnectionID: id,
|
DestConnectionID: id,
|
||||||
},
|
},
|
||||||
extHdr: &wire.ExtendedHeader{
|
extHdr: &wire.ExtendedHeader{
|
||||||
IsLongHeader: true,
|
Header: wire.Header{IsLongHeader: true},
|
||||||
Type: protocol.PacketTypeRetry,
|
Type: protocol.PacketTypeRetry,
|
||||||
Token: []byte("foobar"),
|
Token: []byte("foobar"),
|
||||||
OrigDestConnectionID: connID,
|
OrigDestConnectionID: connID,
|
||||||
|
@ -580,11 +580,13 @@ var _ = Describe("Client", func() {
|
||||||
Version: cl.version,
|
Version: cl.version,
|
||||||
},
|
},
|
||||||
extHdr: &wire.ExtendedHeader{
|
extHdr: &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
|
Version: protocol.VersionTLS,
|
||||||
|
},
|
||||||
Type: protocol.PacketTypeRetry,
|
Type: protocol.PacketTypeRetry,
|
||||||
Token: []byte("foobar"),
|
Token: []byte("foobar"),
|
||||||
OrigDestConnectionID: connID,
|
OrigDestConnectionID: connID,
|
||||||
Version: protocol.VersionTLS,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}).AnyTimes()
|
}).AnyTimes()
|
||||||
|
|
|
@ -13,20 +13,19 @@ import (
|
||||||
|
|
||||||
// ExtendedHeader is the header of a QUIC packet.
|
// ExtendedHeader is the header of a QUIC packet.
|
||||||
type ExtendedHeader struct {
|
type ExtendedHeader struct {
|
||||||
|
Header
|
||||||
|
|
||||||
Raw []byte
|
Raw []byte
|
||||||
|
|
||||||
Version protocol.VersionNumber
|
|
||||||
|
|
||||||
DestConnectionID protocol.ConnectionID
|
|
||||||
SrcConnectionID protocol.ConnectionID
|
|
||||||
OrigDestConnectionID protocol.ConnectionID // only needed in the Retry packet
|
OrigDestConnectionID protocol.ConnectionID // only needed in the Retry packet
|
||||||
|
|
||||||
PacketNumberLen protocol.PacketNumberLen
|
PacketNumberLen protocol.PacketNumberLen
|
||||||
PacketNumber protocol.PacketNumber
|
PacketNumber protocol.PacketNumber
|
||||||
|
|
||||||
typeByte byte
|
IsVersionNegotiation bool
|
||||||
|
SupportedVersions []protocol.VersionNumber // Version Number sent in a Version Negotiation Packet by the server
|
||||||
|
|
||||||
Type protocol.PacketType
|
Type protocol.PacketType
|
||||||
IsLongHeader bool
|
|
||||||
KeyPhase int
|
KeyPhase int
|
||||||
Length protocol.ByteCount
|
Length protocol.ByteCount
|
||||||
Token []byte
|
Token []byte
|
||||||
|
|
|
@ -32,14 +32,16 @@ var _ = Describe("Header", func() {
|
||||||
|
|
||||||
It("writes", func() {
|
It("writes", func() {
|
||||||
Expect((&ExtendedHeader{
|
Expect((&ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Type: 0x5,
|
|
||||||
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe},
|
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe},
|
||||||
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad, 0x0, 0x0, 0x13, 0x37},
|
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad, 0x0, 0x0, 0x13, 0x37},
|
||||||
|
Version: 0x1020304,
|
||||||
|
},
|
||||||
Length: 0xcafe,
|
Length: 0xcafe,
|
||||||
|
Type: 0x5,
|
||||||
PacketNumber: 0xdecaf,
|
PacketNumber: 0xdecaf,
|
||||||
PacketNumberLen: protocol.PacketNumberLen4,
|
PacketNumberLen: protocol.PacketNumberLen4,
|
||||||
Version: 0x1020304,
|
|
||||||
}).Write(buf, versionIETFHeader)).To(Succeed())
|
}).Write(buf, versionIETFHeader)).To(Succeed())
|
||||||
expected := []byte{
|
expected := []byte{
|
||||||
0x80 ^ 0x5,
|
0x80 ^ 0x5,
|
||||||
|
@ -55,68 +57,77 @@ var _ = Describe("Header", func() {
|
||||||
|
|
||||||
It("refuses to write a header with a too short connection ID", func() {
|
It("refuses to write a header with a too short connection ID", func() {
|
||||||
err := (&ExtendedHeader{
|
err := (&ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Type: 0x5,
|
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
DestConnectionID: protocol.ConnectionID{1, 2, 3}, // connection IDs must be at least 4 bytes long
|
DestConnectionID: protocol.ConnectionID{1, 2, 3}, // connection IDs must be at least 4 bytes long
|
||||||
|
Version: 0x1020304,
|
||||||
|
},
|
||||||
|
Type: 0x5,
|
||||||
PacketNumber: 0xdecafbad,
|
PacketNumber: 0xdecafbad,
|
||||||
PacketNumberLen: protocol.PacketNumberLen4,
|
PacketNumberLen: protocol.PacketNumberLen4,
|
||||||
Version: 0x1020304,
|
|
||||||
}).Write(buf, versionIETFHeader)
|
}).Write(buf, versionIETFHeader)
|
||||||
Expect(err).To(MatchError("invalid connection ID length: 3 bytes"))
|
Expect(err).To(MatchError("invalid connection ID length: 3 bytes"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("refuses to write a header with a too long connection ID", func() {
|
It("refuses to write a header with a too long connection ID", func() {
|
||||||
err := (&ExtendedHeader{
|
err := (&ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Type: 0x5,
|
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, // connection IDs must be at most 18 bytes long
|
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, // connection IDs must be at most 18 bytes long
|
||||||
|
Version: 0x1020304,
|
||||||
|
},
|
||||||
|
Type: 0x5,
|
||||||
PacketNumber: 0xdecafbad,
|
PacketNumber: 0xdecafbad,
|
||||||
PacketNumberLen: protocol.PacketNumberLen4,
|
PacketNumberLen: protocol.PacketNumberLen4,
|
||||||
Version: 0x1020304,
|
|
||||||
}).Write(buf, versionIETFHeader)
|
}).Write(buf, versionIETFHeader)
|
||||||
Expect(err).To(MatchError("invalid connection ID length: 19 bytes"))
|
Expect(err).To(MatchError("invalid connection ID length: 19 bytes"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("writes a header with an 18 byte connection ID", func() {
|
It("writes a header with an 18 byte connection ID", func() {
|
||||||
Expect((&ExtendedHeader{
|
err := (&ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Type: 0x5,
|
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}, // connection IDs must be at most 18 bytes long
|
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}, // connection IDs must be at most 18 bytes long
|
||||||
|
Version: 0x1020304,
|
||||||
|
},
|
||||||
|
Type: 0x5,
|
||||||
PacketNumber: 0xdecafbad,
|
PacketNumber: 0xdecafbad,
|
||||||
PacketNumberLen: protocol.PacketNumberLen4,
|
PacketNumberLen: protocol.PacketNumberLen4,
|
||||||
Version: 0x1020304,
|
}).Write(buf, versionIETFHeader)
|
||||||
}).Write(buf, versionIETFHeader)).To(Succeed())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(buf.Bytes()).To(ContainSubstring(string([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18})))
|
Expect(buf.Bytes()).To(ContainSubstring(string([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18})))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("writes an Initial containing a token", func() {
|
It("writes an Initial containing a token", func() {
|
||||||
token := []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
|
token := []byte("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
|
||||||
err := (&ExtendedHeader{
|
Expect((&ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
|
Version: 0x1020304,
|
||||||
|
},
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
Token: token,
|
Token: token,
|
||||||
PacketNumber: 0xdecafbad,
|
PacketNumber: 0xdecafbad,
|
||||||
PacketNumberLen: protocol.PacketNumberLen4,
|
PacketNumberLen: protocol.PacketNumberLen4,
|
||||||
Version: 0x1020304,
|
}).Write(buf, versionIETFHeader)).To(Succeed())
|
||||||
}).Write(buf, versionIETFHeader)
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
expectedSubstring := append(encodeVarInt(uint64(len(token))), token...)
|
expectedSubstring := append(encodeVarInt(uint64(len(token))), token...)
|
||||||
Expect(buf.Bytes()).To(ContainSubstring(string(expectedSubstring)))
|
Expect(buf.Bytes()).To(ContainSubstring(string(expectedSubstring)))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("writes a Retry packet", func() {
|
It("writes a Retry packet", func() {
|
||||||
token := []byte("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")
|
token := []byte("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")
|
||||||
err := (&ExtendedHeader{
|
Expect((&ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
|
Version: 0x1020304,
|
||||||
|
},
|
||||||
Type: protocol.PacketTypeRetry,
|
Type: protocol.PacketTypeRetry,
|
||||||
Token: token,
|
Token: token,
|
||||||
OrigDestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9},
|
OrigDestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9},
|
||||||
Version: 0x1020304,
|
}).Write(buf, versionIETFHeader)).To(Succeed())
|
||||||
}).Write(buf, versionIETFHeader)
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
Expect(buf.Bytes()[:6]).To(Equal([]byte{
|
Expect(buf.Bytes()[:6]).To(Equal([]byte{
|
||||||
0x80 ^ uint8(protocol.PacketTypeRetry),
|
0x80 ^ uint8(protocol.PacketTypeRetry),
|
||||||
0x1, 0x2, 0x3, 0x4, // version number
|
0x1, 0x2, 0x3, 0x4, // version number
|
||||||
|
@ -129,11 +140,13 @@ var _ = Describe("Header", func() {
|
||||||
|
|
||||||
It("refuses to write a Retry packet with an invalid Orig Destination Connection ID length", func() {
|
It("refuses to write a Retry packet with an invalid Orig Destination Connection ID length", func() {
|
||||||
err := (&ExtendedHeader{
|
err := (&ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
|
Version: 0x1020304,
|
||||||
|
},
|
||||||
Type: protocol.PacketTypeRetry,
|
Type: protocol.PacketTypeRetry,
|
||||||
Token: []byte("foobar"),
|
Token: []byte("foobar"),
|
||||||
OrigDestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, // connection IDs must be at most 18 bytes long
|
OrigDestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, // connection IDs must be at most 18 bytes long
|
||||||
Version: 0x1020304,
|
|
||||||
}).Write(buf, versionIETFHeader)
|
}).Write(buf, versionIETFHeader)
|
||||||
Expect(err).To(MatchError("invalid connection ID length: 19 bytes"))
|
Expect(err).To(MatchError("invalid connection ID length: 19 bytes"))
|
||||||
})
|
})
|
||||||
|
@ -142,7 +155,9 @@ var _ = Describe("Header", func() {
|
||||||
Context("short header", func() {
|
Context("short header", func() {
|
||||||
It("writes a header with connection ID", func() {
|
It("writes a header with connection ID", func() {
|
||||||
Expect((&ExtendedHeader{
|
Expect((&ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37},
|
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37},
|
||||||
|
},
|
||||||
PacketNumberLen: protocol.PacketNumberLen1,
|
PacketNumberLen: protocol.PacketNumberLen1,
|
||||||
PacketNumber: 0x42,
|
PacketNumber: 0x42,
|
||||||
}).Write(buf, versionIETFHeader)).To(Succeed())
|
}).Write(buf, versionIETFHeader)).To(Succeed())
|
||||||
|
@ -215,10 +230,12 @@ var _ = Describe("Header", func() {
|
||||||
|
|
||||||
It("has the right length for the Long Header, for a short length", func() {
|
It("has the right length for the Long Header, for a short length", func() {
|
||||||
h := &ExtendedHeader{
|
h := &ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Length: 1,
|
|
||||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
||||||
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
||||||
|
},
|
||||||
|
Length: 1,
|
||||||
PacketNumberLen: protocol.PacketNumberLen1,
|
PacketNumberLen: protocol.PacketNumberLen1,
|
||||||
}
|
}
|
||||||
expectedLen := 1 /* type byte */ + 4 /* version */ + 1 /* conn ID len */ + 8 /* dest conn id */ + 8 /* src conn id */ + 1 /* short len */ + 1 /* packet number */
|
expectedLen := 1 /* type byte */ + 4 /* version */ + 1 /* conn ID len */ + 8 /* dest conn id */ + 8 /* src conn id */ + 1 /* short len */ + 1 /* packet number */
|
||||||
|
@ -229,10 +246,12 @@ var _ = Describe("Header", func() {
|
||||||
|
|
||||||
It("has the right length for the Long Header, for a long length", func() {
|
It("has the right length for the Long Header, for a long length", func() {
|
||||||
h := &ExtendedHeader{
|
h := &ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Length: 1500,
|
|
||||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
||||||
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
||||||
|
},
|
||||||
|
Length: 1500,
|
||||||
PacketNumberLen: protocol.PacketNumberLen2,
|
PacketNumberLen: protocol.PacketNumberLen2,
|
||||||
}
|
}
|
||||||
expectedLen := 1 /* type byte */ + 4 /* version */ + 1 /* conn ID len */ + 8 /* dest conn id */ + 8 /* src conn id */ + 2 /* long len */ + 2 /* packet number */
|
expectedLen := 1 /* type byte */ + 4 /* version */ + 1 /* conn ID len */ + 8 /* dest conn id */ + 8 /* src conn id */ + 2 /* long len */ + 2 /* packet number */
|
||||||
|
@ -243,11 +262,13 @@ var _ = Describe("Header", func() {
|
||||||
|
|
||||||
It("has the right length for an Initial not containing a Token", func() {
|
It("has the right length for an Initial not containing a Token", func() {
|
||||||
h := &ExtendedHeader{
|
h := &ExtendedHeader{
|
||||||
Type: protocol.PacketTypeInitial,
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Length: 1500,
|
|
||||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
||||||
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4},
|
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4},
|
||||||
|
},
|
||||||
|
Length: 1500,
|
||||||
|
Type: protocol.PacketTypeInitial,
|
||||||
PacketNumberLen: protocol.PacketNumberLen2,
|
PacketNumberLen: protocol.PacketNumberLen2,
|
||||||
}
|
}
|
||||||
expectedLen := 1 /* type byte */ + 4 /* version */ + 1 /* conn ID len */ + 8 /* dest conn id */ + 4 /* src conn id */ + 1 /* token length */ + 2 /* long len */ + 2 /* packet number */
|
expectedLen := 1 /* type byte */ + 4 /* version */ + 1 /* conn ID len */ + 8 /* dest conn id */ + 4 /* src conn id */ + 1 /* token length */ + 2 /* long len */ + 2 /* packet number */
|
||||||
|
@ -258,11 +279,13 @@ var _ = Describe("Header", func() {
|
||||||
|
|
||||||
It("has the right length for an Initial containing a Token", func() {
|
It("has the right length for an Initial containing a Token", func() {
|
||||||
h := &ExtendedHeader{
|
h := &ExtendedHeader{
|
||||||
Type: protocol.PacketTypeInitial,
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Length: 1500,
|
|
||||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
||||||
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4},
|
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4},
|
||||||
|
},
|
||||||
|
Type: protocol.PacketTypeInitial,
|
||||||
|
Length: 1500,
|
||||||
PacketNumberLen: protocol.PacketNumberLen2,
|
PacketNumberLen: protocol.PacketNumberLen2,
|
||||||
Token: []byte("foo"),
|
Token: []byte("foo"),
|
||||||
}
|
}
|
||||||
|
@ -274,8 +297,10 @@ var _ = Describe("Header", func() {
|
||||||
|
|
||||||
It("has the right length for a Short Header containing a connection ID", func() {
|
It("has the right length for a Short Header containing a connection ID", func() {
|
||||||
h := &ExtendedHeader{
|
h := &ExtendedHeader{
|
||||||
PacketNumberLen: protocol.PacketNumberLen1,
|
Header: Header{
|
||||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
||||||
|
},
|
||||||
|
PacketNumberLen: protocol.PacketNumberLen1,
|
||||||
}
|
}
|
||||||
Expect(h.GetLength(versionIETFHeader)).To(Equal(protocol.ByteCount(1 + 8 + 1)))
|
Expect(h.GetLength(versionIETFHeader)).To(Equal(protocol.ByteCount(1 + 8 + 1)))
|
||||||
Expect(h.Write(buf, versionIETFHeader)).To(Succeed())
|
Expect(h.Write(buf, versionIETFHeader)).To(Succeed())
|
||||||
|
@ -323,66 +348,76 @@ var _ = Describe("Header", func() {
|
||||||
|
|
||||||
It("logs Long Headers", func() {
|
It("logs Long Headers", func() {
|
||||||
(&ExtendedHeader{
|
(&ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
|
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37},
|
||||||
|
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad, 0x013, 0x37, 0x13, 0x37},
|
||||||
|
Version: 0xfeed,
|
||||||
|
},
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
PacketNumber: 0x1337,
|
PacketNumber: 0x1337,
|
||||||
PacketNumberLen: protocol.PacketNumberLen2,
|
PacketNumberLen: protocol.PacketNumberLen2,
|
||||||
Length: 54321,
|
Length: 54321,
|
||||||
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37},
|
|
||||||
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad, 0x013, 0x37, 0x13, 0x37},
|
|
||||||
Version: 0xfeed,
|
|
||||||
}).Log(logger)
|
}).Log(logger)
|
||||||
Expect(buf.String()).To(ContainSubstring("Long Header{Type: Handshake, DestConnectionID: 0xdeadbeefcafe1337, SrcConnectionID: 0xdecafbad13371337, PacketNumber: 0x1337, PacketNumberLen: 2, Length: 54321, Version: 0xfeed}"))
|
Expect(buf.String()).To(ContainSubstring("Long Header{Type: Handshake, DestConnectionID: 0xdeadbeefcafe1337, SrcConnectionID: 0xdecafbad13371337, PacketNumber: 0x1337, PacketNumberLen: 2, Length: 54321, Version: 0xfeed}"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("logs Initial Packets with a Token", func() {
|
It("logs Initial Packets with a Token", func() {
|
||||||
(&ExtendedHeader{
|
(&ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
|
DestConnectionID: protocol.ConnectionID{0xca, 0xfe, 0x13, 0x37},
|
||||||
|
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
|
||||||
|
Version: 0xfeed,
|
||||||
|
},
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
Token: []byte{0xde, 0xad, 0xbe, 0xef},
|
Token: []byte{0xde, 0xad, 0xbe, 0xef},
|
||||||
PacketNumber: 0x42,
|
PacketNumber: 0x42,
|
||||||
PacketNumberLen: protocol.PacketNumberLen2,
|
PacketNumberLen: protocol.PacketNumberLen2,
|
||||||
Length: 100,
|
Length: 100,
|
||||||
DestConnectionID: protocol.ConnectionID{0xca, 0xfe, 0x13, 0x37},
|
|
||||||
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
|
|
||||||
Version: 0xfeed,
|
|
||||||
}).Log(logger)
|
}).Log(logger)
|
||||||
Expect(buf.String()).To(ContainSubstring("Long Header{Type: Initial, DestConnectionID: 0xcafe1337, SrcConnectionID: 0xdecafbad, Token: 0xdeadbeef, PacketNumber: 0x42, PacketNumberLen: 2, Length: 100, Version: 0xfeed}"))
|
Expect(buf.String()).To(ContainSubstring("Long Header{Type: Initial, DestConnectionID: 0xcafe1337, SrcConnectionID: 0xdecafbad, Token: 0xdeadbeef, PacketNumber: 0x42, PacketNumberLen: 2, Length: 100, Version: 0xfeed}"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("logs Initial Packets without a Token", func() {
|
It("logs Initial Packets without a Token", func() {
|
||||||
(&ExtendedHeader{
|
(&ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
|
DestConnectionID: protocol.ConnectionID{0xca, 0xfe, 0x13, 0x37},
|
||||||
|
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
|
||||||
|
Version: 0xfeed,
|
||||||
|
},
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
PacketNumber: 0x42,
|
PacketNumber: 0x42,
|
||||||
PacketNumberLen: protocol.PacketNumberLen2,
|
PacketNumberLen: protocol.PacketNumberLen2,
|
||||||
Length: 100,
|
Length: 100,
|
||||||
DestConnectionID: protocol.ConnectionID{0xca, 0xfe, 0x13, 0x37},
|
|
||||||
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
|
|
||||||
Version: 0xfeed,
|
|
||||||
}).Log(logger)
|
}).Log(logger)
|
||||||
Expect(buf.String()).To(ContainSubstring("Long Header{Type: Initial, DestConnectionID: 0xcafe1337, SrcConnectionID: 0xdecafbad, Token: (empty), PacketNumber: 0x42, PacketNumberLen: 2, Length: 100, Version: 0xfeed}"))
|
Expect(buf.String()).To(ContainSubstring("Long Header{Type: Initial, DestConnectionID: 0xcafe1337, SrcConnectionID: 0xdecafbad, Token: (empty), PacketNumber: 0x42, PacketNumberLen: 2, Length: 100, Version: 0xfeed}"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("logs Initial Packets with a Token", func() {
|
It("logs Initial Packets with a Token", func() {
|
||||||
(&ExtendedHeader{
|
(&ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Type: protocol.PacketTypeRetry,
|
|
||||||
DestConnectionID: protocol.ConnectionID{0xca, 0xfe, 0x13, 0x37},
|
DestConnectionID: protocol.ConnectionID{0xca, 0xfe, 0x13, 0x37},
|
||||||
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
|
SrcConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
|
||||||
|
Version: 0xfeed,
|
||||||
|
},
|
||||||
|
Type: protocol.PacketTypeRetry,
|
||||||
OrigDestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
OrigDestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
||||||
Token: []byte{0x12, 0x34, 0x56},
|
Token: []byte{0x12, 0x34, 0x56},
|
||||||
Version: 0xfeed,
|
|
||||||
}).Log(logger)
|
}).Log(logger)
|
||||||
Expect(buf.String()).To(ContainSubstring("Long Header{Type: Retry, DestConnectionID: 0xcafe1337, SrcConnectionID: 0xdecafbad, Token: 0x123456, OrigDestConnectionID: 0xdeadbeef, Version: 0xfeed}"))
|
Expect(buf.String()).To(ContainSubstring("Long Header{Type: Retry, DestConnectionID: 0xcafe1337, SrcConnectionID: 0xdecafbad, Token: 0x123456, OrigDestConnectionID: 0xdeadbeef, Version: 0xfeed}"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("logs Short Headers containing a connection ID", func() {
|
It("logs Short Headers containing a connection ID", func() {
|
||||||
(&ExtendedHeader{
|
(&ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
|
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37},
|
||||||
|
},
|
||||||
KeyPhase: 1,
|
KeyPhase: 1,
|
||||||
PacketNumber: 0x1337,
|
PacketNumber: 0x1337,
|
||||||
PacketNumberLen: 4,
|
PacketNumberLen: 4,
|
||||||
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37},
|
|
||||||
}).Log(logger)
|
}).Log(logger)
|
||||||
Expect(buf.String()).To(ContainSubstring("Short Header{DestConnectionID: 0xdeadbeefcafe1337, PacketNumber: 0x1337, PacketNumberLen: 4, KeyPhase: 1}"))
|
Expect(buf.String()).To(ContainSubstring("Short Header{DestConnectionID: 0xdeadbeefcafe1337, PacketNumber: 0x1337, PacketNumberLen: 4, KeyPhase: 1}"))
|
||||||
})
|
})
|
||||||
|
|
|
@ -17,6 +17,7 @@ type Header struct {
|
||||||
|
|
||||||
SupportedVersions []protocol.VersionNumber // sent in a Version Negotiation Packet
|
SupportedVersions []protocol.VersionNumber // sent in a Version Negotiation Packet
|
||||||
|
|
||||||
|
IsLongHeader bool
|
||||||
typeByte byte
|
typeByte byte
|
||||||
len int // how many bytes were read while parsing this header
|
len int // how many bytes were read while parsing this header
|
||||||
}
|
}
|
||||||
|
@ -38,10 +39,12 @@ func parseHeaderImpl(b *bytes.Reader, shortHeaderConnIDLen int) (*Header, error)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
h := &Header{typeByte: typeByte}
|
h := &Header{
|
||||||
|
typeByte: typeByte,
|
||||||
|
IsLongHeader: typeByte&0x80 > 0,
|
||||||
|
}
|
||||||
|
|
||||||
// If this is not a Long Header, it could either be a Public Header or a Short Header.
|
if !h.IsLongHeader {
|
||||||
if !h.IsLongHeader() {
|
|
||||||
var err error
|
var err error
|
||||||
h.DestConnectionID, err = protocol.ReadConnectionID(b, shortHeaderConnIDLen)
|
h.DestConnectionID, err = protocol.ReadConnectionID(b, shortHeaderConnIDLen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -84,14 +87,9 @@ func parseHeaderImpl(b *bytes.Reader, shortHeaderConnIDLen int) (*Header, error)
|
||||||
return h, nil
|
return h, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsLongHeader says if this is a long header
|
|
||||||
func (h *Header) IsLongHeader() bool {
|
|
||||||
return h.typeByte&0x80 > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsVersionNegotiation says if this a version negotiation packet
|
// IsVersionNegotiation says if this a version negotiation packet
|
||||||
func (h *Header) IsVersionNegotiation() bool {
|
func (h *Header) IsVersionNegotiation() bool {
|
||||||
return h.IsLongHeader() && h.Version == 0
|
return h.IsLongHeader && h.Version == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseExtended parses the version dependent part of the header.
|
// ParseExtended parses the version dependent part of the header.
|
||||||
|
@ -104,11 +102,5 @@ func (h *Header) ParseExtended(b *bytes.Reader, ver protocol.VersionNumber) (*Ex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Header) toExtendedHeader() *ExtendedHeader {
|
func (h *Header) toExtendedHeader() *ExtendedHeader {
|
||||||
return &ExtendedHeader{
|
return &ExtendedHeader{Header: *h}
|
||||||
IsLongHeader: h.IsLongHeader(),
|
|
||||||
typeByte: h.typeByte,
|
|
||||||
DestConnectionID: h.DestConnectionID,
|
|
||||||
SrcConnectionID: h.SrcConnectionID,
|
|
||||||
Version: h.Version,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(hdr.DestConnectionID).To(Equal(destConnID))
|
Expect(hdr.DestConnectionID).To(Equal(destConnID))
|
||||||
Expect(hdr.SrcConnectionID).To(Equal(srcConnID))
|
Expect(hdr.SrcConnectionID).To(Equal(srcConnID))
|
||||||
Expect(hdr.IsLongHeader()).To(BeTrue())
|
Expect(hdr.IsLongHeader).To(BeTrue())
|
||||||
Expect(hdr.IsVersionNegotiation()).To(BeTrue())
|
Expect(hdr.IsVersionNegotiation()).To(BeTrue())
|
||||||
Expect(hdr.Version).To(BeZero())
|
Expect(hdr.Version).To(BeZero())
|
||||||
for _, v := range versions {
|
for _, v := range versions {
|
||||||
|
@ -80,7 +80,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
|
|
||||||
hdr, err := ParseHeader(bytes.NewReader(data), 0)
|
hdr, err := ParseHeader(bytes.NewReader(data), 0)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(hdr.IsLongHeader()).To(BeTrue())
|
Expect(hdr.IsLongHeader).To(BeTrue())
|
||||||
Expect(hdr.IsVersionNegotiation()).To(BeFalse())
|
Expect(hdr.IsVersionNegotiation()).To(BeFalse())
|
||||||
Expect(hdr.DestConnectionID).To(Equal(destConnID))
|
Expect(hdr.DestConnectionID).To(Equal(destConnID))
|
||||||
Expect(hdr.SrcConnectionID).To(Equal(srcConnID))
|
Expect(hdr.SrcConnectionID).To(Equal(srcConnID))
|
||||||
|
@ -173,10 +173,12 @@ var _ = Describe("Header Parsing", func() {
|
||||||
srcConnID := protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8}
|
srcConnID := protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8}
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
Expect((&ExtendedHeader{
|
Expect((&ExtendedHeader{
|
||||||
|
Header: Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Type: 42,
|
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
Version: 0x10203040,
|
Version: 0x10203040,
|
||||||
|
},
|
||||||
|
Type: 42,
|
||||||
PacketNumber: 1,
|
PacketNumber: 1,
|
||||||
PacketNumberLen: protocol.PacketNumberLen1,
|
PacketNumberLen: protocol.PacketNumberLen1,
|
||||||
}).Write(buf, protocol.VersionTLS)).To(Succeed())
|
}).Write(buf, protocol.VersionTLS)).To(Succeed())
|
||||||
|
@ -264,7 +266,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
data = appendPacketNumber(data, 0x42, protocol.PacketNumberLen1)
|
data = appendPacketNumber(data, 0x42, protocol.PacketNumberLen1)
|
||||||
hdr, err := ParseHeader(bytes.NewReader(data), 8)
|
hdr, err := ParseHeader(bytes.NewReader(data), 8)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(hdr.IsLongHeader()).To(BeFalse())
|
Expect(hdr.IsLongHeader).To(BeFalse())
|
||||||
Expect(hdr.IsVersionNegotiation()).To(BeFalse())
|
Expect(hdr.IsVersionNegotiation()).To(BeFalse())
|
||||||
Expect(hdr.DestConnectionID).To(Equal(connID))
|
Expect(hdr.DestConnectionID).To(Equal(connID))
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
|
@ -283,7 +285,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
data = appendPacketNumber(data, 0x42, protocol.PacketNumberLen1)
|
data = appendPacketNumber(data, 0x42, protocol.PacketNumberLen1)
|
||||||
hdr, err := ParseHeader(bytes.NewReader(data), 5)
|
hdr, err := ParseHeader(bytes.NewReader(data), 5)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(hdr.IsLongHeader()).To(BeFalse())
|
Expect(hdr.IsLongHeader).To(BeFalse())
|
||||||
Expect(hdr.DestConnectionID).To(Equal(connID))
|
Expect(hdr.DestConnectionID).To(Equal(connID))
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
extHdr, err := hdr.ParseExtended(b, versionIETFFrames)
|
extHdr, err := hdr.ParseExtended(b, versionIETFFrames)
|
||||||
|
@ -302,7 +304,7 @@ var _ = Describe("Header Parsing", func() {
|
||||||
data = appendPacketNumber(data, 11, protocol.PacketNumberLen1)
|
data = appendPacketNumber(data, 11, protocol.PacketNumberLen1)
|
||||||
hdr, err := ParseHeader(bytes.NewReader(data), 6)
|
hdr, err := ParseHeader(bytes.NewReader(data), 6)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(hdr.IsLongHeader()).To(BeFalse())
|
Expect(hdr.IsLongHeader).To(BeFalse())
|
||||||
b := bytes.NewReader(data)
|
b := bytes.NewReader(data)
|
||||||
extHdr, err := hdr.ParseExtended(b, versionIETFFrames)
|
extHdr, err := hdr.ParseExtended(b, versionIETFFrames)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
|
@ -183,7 +183,7 @@ func (h *packetHandlerMap) handlePacket(addr net.Addr, data []byte) error {
|
||||||
handlePacket = handler.handlePacket
|
handlePacket = handler.handlePacket
|
||||||
} else { // no session found
|
} else { // no session found
|
||||||
// this might be a stateless reset
|
// this might be a stateless reset
|
||||||
if !hdr.IsLongHeader() {
|
if !hdr.IsLongHeader {
|
||||||
if len(data) >= protocol.MinStatelessResetSize {
|
if len(data) >= protocol.MinStatelessResetSize {
|
||||||
var token [16]byte
|
var token [16]byte
|
||||||
copy(token[:], data[len(data)-16:])
|
copy(token[:], data[len(data)-16:])
|
||||||
|
@ -217,7 +217,7 @@ func (h *packetHandlerMap) handlePacket(addr net.Addr, data []byte) error {
|
||||||
extHdr.Raw = data[:len(data)-r.Len()]
|
extHdr.Raw = data[:len(data)-r.Len()]
|
||||||
packetData = data[len(data)-r.Len():]
|
packetData = data[len(data)-r.Len():]
|
||||||
|
|
||||||
if hdr.IsLongHeader() {
|
if hdr.IsLongHeader {
|
||||||
if extHdr.Length < protocol.ByteCount(extHdr.PacketNumberLen) {
|
if extHdr.Length < protocol.ByteCount(extHdr.PacketNumberLen) {
|
||||||
return fmt.Errorf("packet length (%d bytes) shorter than packet number (%d bytes)", extHdr.Length, extHdr.PacketNumberLen)
|
return fmt.Errorf("packet length (%d bytes) shorter than packet number (%d bytes)", extHdr.Length, extHdr.PacketNumberLen)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,14 @@ var _ = Describe("Packet Handler Map", func() {
|
||||||
getPacket := func(connID protocol.ConnectionID) []byte {
|
getPacket := func(connID protocol.ConnectionID) []byte {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
Expect((&wire.ExtendedHeader{
|
Expect((&wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Type: protocol.PacketTypeHandshake,
|
|
||||||
DestConnectionID: connID,
|
DestConnectionID: connID,
|
||||||
PacketNumberLen: protocol.PacketNumberLen1,
|
|
||||||
Length: 1,
|
|
||||||
Version: protocol.VersionWhatever,
|
Version: protocol.VersionWhatever,
|
||||||
|
},
|
||||||
|
Length: 1,
|
||||||
|
Type: protocol.PacketTypeHandshake,
|
||||||
|
PacketNumberLen: protocol.PacketNumberLen1,
|
||||||
}).Write(buf, protocol.VersionWhatever)).To(Succeed())
|
}).Write(buf, protocol.VersionWhatever)).To(Succeed())
|
||||||
return buf.Bytes()
|
return buf.Bytes()
|
||||||
}
|
}
|
||||||
|
@ -127,12 +129,14 @@ var _ = Describe("Packet Handler Map", func() {
|
||||||
packetHandler.EXPECT().GetVersion().Return(protocol.VersionWhatever)
|
packetHandler.EXPECT().GetVersion().Return(protocol.VersionWhatever)
|
||||||
handler.Add(connID, packetHandler)
|
handler.Add(connID, packetHandler)
|
||||||
hdr := &wire.ExtendedHeader{
|
hdr := &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
|
DestConnectionID: connID,
|
||||||
|
Version: protocol.VersionWhatever,
|
||||||
|
},
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
Length: 1000,
|
Length: 1000,
|
||||||
DestConnectionID: connID,
|
|
||||||
PacketNumberLen: protocol.PacketNumberLen2,
|
PacketNumberLen: protocol.PacketNumberLen2,
|
||||||
Version: protocol.VersionWhatever,
|
|
||||||
}
|
}
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
Expect(hdr.Write(buf, protocol.VersionWhatever)).To(Succeed())
|
Expect(hdr.Write(buf, protocol.VersionWhatever)).To(Succeed())
|
||||||
|
@ -148,12 +152,14 @@ var _ = Describe("Packet Handler Map", func() {
|
||||||
packetHandler.EXPECT().GetVersion().Return(protocol.VersionWhatever)
|
packetHandler.EXPECT().GetVersion().Return(protocol.VersionWhatever)
|
||||||
handler.Add(connID, packetHandler)
|
handler.Add(connID, packetHandler)
|
||||||
hdr := &wire.ExtendedHeader{
|
hdr := &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
|
DestConnectionID: connID,
|
||||||
|
Version: protocol.VersionWhatever,
|
||||||
|
},
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
Length: 3,
|
Length: 3,
|
||||||
DestConnectionID: connID,
|
|
||||||
PacketNumberLen: protocol.PacketNumberLen4,
|
PacketNumberLen: protocol.PacketNumberLen4,
|
||||||
Version: protocol.VersionWhatever,
|
|
||||||
}
|
}
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
Expect(hdr.Write(buf, protocol.VersionWhatever)).To(Succeed())
|
Expect(hdr.Write(buf, protocol.VersionWhatever)).To(Succeed())
|
||||||
|
@ -170,12 +176,14 @@ var _ = Describe("Packet Handler Map", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
hdr := &wire.ExtendedHeader{
|
hdr := &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
|
DestConnectionID: connID,
|
||||||
|
Version: protocol.VersionWhatever,
|
||||||
|
},
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
Length: 456,
|
Length: 456,
|
||||||
DestConnectionID: connID,
|
|
||||||
PacketNumberLen: protocol.PacketNumberLen1,
|
PacketNumberLen: protocol.PacketNumberLen1,
|
||||||
Version: protocol.VersionWhatever,
|
|
||||||
}
|
}
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
Expect(hdr.Write(buf, protocol.VersionWhatever)).To(Succeed())
|
Expect(hdr.Write(buf, protocol.VersionWhatever)).To(Succeed())
|
||||||
|
|
|
@ -399,12 +399,11 @@ func (p *packetPacker) composeNextPacket(
|
||||||
|
|
||||||
func (p *packetPacker) getHeader(encLevel protocol.EncryptionLevel) *wire.ExtendedHeader {
|
func (p *packetPacker) getHeader(encLevel protocol.EncryptionLevel) *wire.ExtendedHeader {
|
||||||
pn, pnLen := p.pnManager.PeekPacketNumber()
|
pn, pnLen := p.pnManager.PeekPacketNumber()
|
||||||
header := &wire.ExtendedHeader{
|
header := &wire.ExtendedHeader{}
|
||||||
PacketNumber: pn,
|
header.PacketNumber = pn
|
||||||
PacketNumberLen: pnLen,
|
header.PacketNumberLen = pnLen
|
||||||
Version: p.version,
|
header.Version = p.version
|
||||||
DestConnectionID: p.destConnID,
|
header.DestConnectionID = p.destConnID
|
||||||
}
|
|
||||||
|
|
||||||
if encLevel != protocol.Encryption1RTT {
|
if encLevel != protocol.Encryption1RTT {
|
||||||
header.IsLongHeader = true
|
header.IsLongHeader = true
|
||||||
|
|
17
server.go
17
server.go
|
@ -431,15 +431,14 @@ func (s *server) sendRetry(remoteAddr net.Addr, hdr *wire.ExtendedHeader) error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
replyHdr := &wire.ExtendedHeader{
|
replyHdr := &wire.ExtendedHeader{}
|
||||||
IsLongHeader: true,
|
replyHdr.IsLongHeader = true
|
||||||
Type: protocol.PacketTypeRetry,
|
replyHdr.Type = protocol.PacketTypeRetry
|
||||||
Version: hdr.Version,
|
replyHdr.Version = hdr.Version
|
||||||
SrcConnectionID: connID,
|
replyHdr.SrcConnectionID = connID
|
||||||
DestConnectionID: hdr.SrcConnectionID,
|
replyHdr.DestConnectionID = hdr.SrcConnectionID
|
||||||
OrigDestConnectionID: hdr.DestConnectionID,
|
replyHdr.OrigDestConnectionID = hdr.DestConnectionID
|
||||||
Token: token,
|
replyHdr.Token = token
|
||||||
}
|
|
||||||
s.logger.Debugf("Changing connection ID to %s.\n-> Sending Retry", connID)
|
s.logger.Debugf("Changing connection ID to %s.\n-> Sending Retry", connID)
|
||||||
replyHdr.Log(s.logger)
|
replyHdr.Log(s.logger)
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
|
|
|
@ -22,7 +22,9 @@ var _ = Describe("Server Session", func() {
|
||||||
|
|
||||||
It("handles packets", func() {
|
It("handles packets", func() {
|
||||||
p := &receivedPacket{
|
p := &receivedPacket{
|
||||||
extHdr: &wire.ExtendedHeader{DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5}},
|
extHdr: &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5}},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
qsess.EXPECT().handlePacket(p)
|
qsess.EXPECT().handlePacket(p)
|
||||||
sess.handlePacket(p)
|
sess.handlePacket(p)
|
||||||
|
@ -33,10 +35,12 @@ var _ = Describe("Server Session", func() {
|
||||||
// don't EXPECT any calls to handlePacket()
|
// don't EXPECT any calls to handlePacket()
|
||||||
p := &receivedPacket{
|
p := &receivedPacket{
|
||||||
extHdr: &wire.ExtendedHeader{
|
extHdr: &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Version: protocol.VersionNumber(123),
|
Version: protocol.VersionNumber(123),
|
||||||
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
err := sess.handlePacketImpl(p)
|
err := sess.handlePacketImpl(p)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@ -46,11 +50,13 @@ var _ = Describe("Server Session", func() {
|
||||||
qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
|
qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
|
||||||
p := &receivedPacket{
|
p := &receivedPacket{
|
||||||
extHdr: &wire.ExtendedHeader{
|
extHdr: &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Type: protocol.PacketTypeRetry,
|
|
||||||
Version: protocol.VersionNumber(100),
|
Version: protocol.VersionNumber(100),
|
||||||
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
||||||
},
|
},
|
||||||
|
Type: protocol.PacketTypeRetry,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
err := sess.handlePacketImpl(p)
|
err := sess.handlePacketImpl(p)
|
||||||
Expect(err).To(MatchError("Received unsupported packet type: Retry"))
|
Expect(err).To(MatchError("Received unsupported packet type: Retry"))
|
||||||
|
@ -59,11 +65,13 @@ var _ = Describe("Server Session", func() {
|
||||||
It("passes on Handshake packets", func() {
|
It("passes on Handshake packets", func() {
|
||||||
p := &receivedPacket{
|
p := &receivedPacket{
|
||||||
extHdr: &wire.ExtendedHeader{
|
extHdr: &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Type: protocol.PacketTypeHandshake,
|
|
||||||
Version: protocol.VersionNumber(100),
|
Version: protocol.VersionNumber(100),
|
||||||
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
DestConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
||||||
},
|
},
|
||||||
|
Type: protocol.PacketTypeHandshake,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
|
qsess.EXPECT().GetVersion().Return(protocol.VersionNumber(100))
|
||||||
qsess.EXPECT().handlePacket(p)
|
qsess.EXPECT().handlePacket(p)
|
||||||
|
|
|
@ -109,11 +109,13 @@ var _ = Describe("Server", func() {
|
||||||
It("drops Initial packets with a too short connection ID", func() {
|
It("drops Initial packets with a too short connection ID", func() {
|
||||||
serv.handlePacket(&receivedPacket{
|
serv.handlePacket(&receivedPacket{
|
||||||
extHdr: &wire.ExtendedHeader{
|
extHdr: &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Type: protocol.PacketTypeInitial,
|
|
||||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4},
|
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4},
|
||||||
Version: serv.config.Versions[0],
|
Version: serv.config.Versions[0],
|
||||||
},
|
},
|
||||||
|
Type: protocol.PacketTypeInitial,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
Expect(conn.dataWritten.Len()).To(BeZero())
|
Expect(conn.dataWritten.Len()).To(BeZero())
|
||||||
})
|
})
|
||||||
|
@ -121,11 +123,13 @@ var _ = Describe("Server", func() {
|
||||||
It("drops too small Initial", func() {
|
It("drops too small Initial", func() {
|
||||||
serv.handlePacket(&receivedPacket{
|
serv.handlePacket(&receivedPacket{
|
||||||
extHdr: &wire.ExtendedHeader{
|
extHdr: &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Type: protocol.PacketTypeInitial,
|
|
||||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
||||||
Version: serv.config.Versions[0],
|
Version: serv.config.Versions[0],
|
||||||
},
|
},
|
||||||
|
Type: protocol.PacketTypeInitial,
|
||||||
|
},
|
||||||
data: bytes.Repeat([]byte{0}, protocol.MinInitialPacketSize-100),
|
data: bytes.Repeat([]byte{0}, protocol.MinInitialPacketSize-100),
|
||||||
})
|
})
|
||||||
Consistently(conn.dataWritten.Len).Should(BeZero())
|
Consistently(conn.dataWritten.Len).Should(BeZero())
|
||||||
|
@ -133,11 +137,13 @@ var _ = Describe("Server", func() {
|
||||||
|
|
||||||
It("drops packets with a too short connection ID", func() {
|
It("drops packets with a too short connection ID", func() {
|
||||||
hdr := &wire.ExtendedHeader{
|
hdr := &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Type: protocol.PacketTypeInitial,
|
|
||||||
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
SrcConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8},
|
||||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4},
|
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4},
|
||||||
Version: serv.config.Versions[0],
|
Version: serv.config.Versions[0],
|
||||||
|
},
|
||||||
|
Type: protocol.PacketTypeInitial,
|
||||||
PacketNumberLen: protocol.PacketNumberLen1,
|
PacketNumberLen: protocol.PacketNumberLen1,
|
||||||
}
|
}
|
||||||
serv.handlePacket(&receivedPacket{
|
serv.handlePacket(&receivedPacket{
|
||||||
|
@ -151,8 +157,8 @@ var _ = Describe("Server", func() {
|
||||||
serv.logger.SetLogLevel(utils.LogLevelDebug)
|
serv.logger.SetLogLevel(utils.LogLevelDebug)
|
||||||
serv.handlePacket(&receivedPacket{
|
serv.handlePacket(&receivedPacket{
|
||||||
extHdr: &wire.ExtendedHeader{
|
extHdr: &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{Version: serv.config.Versions[0]},
|
||||||
Type: protocol.PacketTypeHandshake,
|
Type: protocol.PacketTypeHandshake,
|
||||||
Version: serv.config.Versions[0],
|
|
||||||
},
|
},
|
||||||
data: []byte("invalid"),
|
data: []byte("invalid"),
|
||||||
})
|
})
|
||||||
|
@ -175,9 +181,9 @@ var _ = Describe("Server", func() {
|
||||||
serv.handlePacket(&receivedPacket{
|
serv.handlePacket(&receivedPacket{
|
||||||
remoteAddr: raddr,
|
remoteAddr: raddr,
|
||||||
extHdr: &wire.ExtendedHeader{
|
extHdr: &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{Version: serv.config.Versions[0]},
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
Token: token,
|
Token: token,
|
||||||
Version: serv.config.Versions[0],
|
|
||||||
},
|
},
|
||||||
data: bytes.Repeat([]byte{0}, protocol.MinInitialPacketSize),
|
data: bytes.Repeat([]byte{0}, protocol.MinInitialPacketSize),
|
||||||
})
|
})
|
||||||
|
@ -199,9 +205,9 @@ var _ = Describe("Server", func() {
|
||||||
serv.handlePacket(&receivedPacket{
|
serv.handlePacket(&receivedPacket{
|
||||||
remoteAddr: raddr,
|
remoteAddr: raddr,
|
||||||
extHdr: &wire.ExtendedHeader{
|
extHdr: &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{Version: serv.config.Versions[0]},
|
||||||
Type: protocol.PacketTypeInitial,
|
Type: protocol.PacketTypeInitial,
|
||||||
Token: []byte("foobar"),
|
Token: []byte("foobar"),
|
||||||
Version: serv.config.Versions[0],
|
|
||||||
},
|
},
|
||||||
data: bytes.Repeat([]byte{0}, protocol.MinInitialPacketSize),
|
data: bytes.Repeat([]byte{0}, protocol.MinInitialPacketSize),
|
||||||
})
|
})
|
||||||
|
@ -213,12 +219,14 @@ var _ = Describe("Server", func() {
|
||||||
destConnID := protocol.ConnectionID{1, 2, 3, 4, 5, 6}
|
destConnID := protocol.ConnectionID{1, 2, 3, 4, 5, 6}
|
||||||
serv.handlePacket(&receivedPacket{
|
serv.handlePacket(&receivedPacket{
|
||||||
extHdr: &wire.ExtendedHeader{
|
extHdr: &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
SrcConnectionID: srcConnID,
|
SrcConnectionID: srcConnID,
|
||||||
DestConnectionID: destConnID,
|
DestConnectionID: destConnID,
|
||||||
Type: protocol.PacketTypeInitial,
|
|
||||||
Version: 0x42,
|
Version: 0x42,
|
||||||
},
|
},
|
||||||
|
Type: protocol.PacketTypeInitial,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
Expect(conn.dataWritten.Len()).ToNot(BeZero())
|
Expect(conn.dataWritten.Len()).ToNot(BeZero())
|
||||||
hdr, err := wire.ParseHeader(bytes.NewReader(conn.dataWritten.Bytes()), 0)
|
hdr, err := wire.ParseHeader(bytes.NewReader(conn.dataWritten.Bytes()), 0)
|
||||||
|
@ -232,10 +240,12 @@ var _ = Describe("Server", func() {
|
||||||
It("replies with a Retry packet, if a Cookie is required", func() {
|
It("replies with a Retry packet, if a Cookie is required", func() {
|
||||||
serv.config.AcceptCookie = func(_ net.Addr, _ *Cookie) bool { return false }
|
serv.config.AcceptCookie = func(_ net.Addr, _ *Cookie) bool { return false }
|
||||||
hdr := &wire.ExtendedHeader{
|
hdr := &wire.ExtendedHeader{
|
||||||
Type: protocol.PacketTypeInitial,
|
Header: wire.Header{
|
||||||
SrcConnectionID: protocol.ConnectionID{5, 4, 3, 2, 1},
|
SrcConnectionID: protocol.ConnectionID{5, 4, 3, 2, 1},
|
||||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
|
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
|
||||||
Version: protocol.VersionTLS,
|
Version: protocol.VersionTLS,
|
||||||
|
},
|
||||||
|
Type: protocol.PacketTypeInitial,
|
||||||
}
|
}
|
||||||
serv.handleInitial(&receivedPacket{
|
serv.handleInitial(&receivedPacket{
|
||||||
remoteAddr: &net.UDPAddr{},
|
remoteAddr: &net.UDPAddr{},
|
||||||
|
@ -254,10 +264,12 @@ var _ = Describe("Server", func() {
|
||||||
It("creates a session, if no Cookie is required", func() {
|
It("creates a session, if no Cookie is required", func() {
|
||||||
serv.config.AcceptCookie = func(_ net.Addr, _ *Cookie) bool { return true }
|
serv.config.AcceptCookie = func(_ net.Addr, _ *Cookie) bool { return true }
|
||||||
hdr := &wire.ExtendedHeader{
|
hdr := &wire.ExtendedHeader{
|
||||||
Type: protocol.PacketTypeInitial,
|
Header: wire.Header{
|
||||||
SrcConnectionID: protocol.ConnectionID{5, 4, 3, 2, 1},
|
SrcConnectionID: protocol.ConnectionID{5, 4, 3, 2, 1},
|
||||||
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
|
DestConnectionID: protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
|
||||||
Version: protocol.VersionTLS,
|
Version: protocol.VersionTLS,
|
||||||
|
},
|
||||||
|
Type: protocol.PacketTypeInitial,
|
||||||
}
|
}
|
||||||
p := &receivedPacket{
|
p := &receivedPacket{
|
||||||
extHdr: hdr,
|
extHdr: hdr,
|
||||||
|
|
|
@ -518,19 +518,23 @@ var _ = Describe("Session", func() {
|
||||||
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).Return(&unpackedPacket{}, nil)
|
unpacker.EXPECT().Unpack(gomock.Any(), gomock.Any(), gomock.Any()).Return(&unpackedPacket{}, nil)
|
||||||
err := sess.handlePacketImpl(&receivedPacket{
|
err := sess.handlePacketImpl(&receivedPacket{
|
||||||
extHdr: &wire.ExtendedHeader{
|
extHdr: &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
DestConnectionID: sess.destConnID,
|
DestConnectionID: sess.destConnID,
|
||||||
SrcConnectionID: sess.srcConnID,
|
SrcConnectionID: sess.srcConnID,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
// The next packet has to be ignored, since the source connection ID doesn't match.
|
// The next packet has to be ignored, since the source connection ID doesn't match.
|
||||||
err = sess.handlePacketImpl(&receivedPacket{
|
err = sess.handlePacketImpl(&receivedPacket{
|
||||||
extHdr: &wire.ExtendedHeader{
|
extHdr: &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
DestConnectionID: sess.destConnID,
|
DestConnectionID: sess.destConnID,
|
||||||
SrcConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
SrcConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
})
|
})
|
||||||
|
@ -1318,11 +1322,13 @@ var _ = Describe("Client Session", func() {
|
||||||
packer.EXPECT().ChangeDestConnectionID(newConnID)
|
packer.EXPECT().ChangeDestConnectionID(newConnID)
|
||||||
err := sess.handlePacketImpl(&receivedPacket{
|
err := sess.handlePacketImpl(&receivedPacket{
|
||||||
extHdr: &wire.ExtendedHeader{
|
extHdr: &wire.ExtendedHeader{
|
||||||
|
Header: wire.Header{
|
||||||
IsLongHeader: true,
|
IsLongHeader: true,
|
||||||
Type: protocol.PacketTypeHandshake,
|
|
||||||
SrcConnectionID: newConnID,
|
SrcConnectionID: newConnID,
|
||||||
DestConnectionID: sess.srcConnID,
|
DestConnectionID: sess.srcConnID,
|
||||||
},
|
},
|
||||||
|
Type: protocol.PacketTypeHandshake,
|
||||||
|
},
|
||||||
data: []byte{0},
|
data: []byte{0},
|
||||||
})
|
})
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue