introduce a protocol.StatelessResetToken

This commit is contained in:
Marten Seemann 2020-07-10 11:53:14 +07:00
parent a4679bc02e
commit a1bb39d6ab
28 changed files with 154 additions and 151 deletions

View file

@ -17,7 +17,7 @@ type connIDGenerator struct {
initialClientDestConnID protocol.ConnectionID initialClientDestConnID protocol.ConnectionID
addConnectionID func(protocol.ConnectionID) addConnectionID func(protocol.ConnectionID)
getStatelessResetToken func(protocol.ConnectionID) [16]byte getStatelessResetToken func(protocol.ConnectionID) protocol.StatelessResetToken
removeConnectionID func(protocol.ConnectionID) removeConnectionID func(protocol.ConnectionID)
retireConnectionID func(protocol.ConnectionID) retireConnectionID func(protocol.ConnectionID)
replaceWithClosed func(protocol.ConnectionID, packetHandler) replaceWithClosed func(protocol.ConnectionID, packetHandler)
@ -28,7 +28,7 @@ func newConnIDGenerator(
initialConnectionID protocol.ConnectionID, initialConnectionID protocol.ConnectionID,
initialClientDestConnID protocol.ConnectionID, // nil for the client initialClientDestConnID protocol.ConnectionID, // nil for the client
addConnectionID func(protocol.ConnectionID), addConnectionID func(protocol.ConnectionID),
getStatelessResetToken func(protocol.ConnectionID) [16]byte, getStatelessResetToken func(protocol.ConnectionID) protocol.StatelessResetToken,
removeConnectionID func(protocol.ConnectionID), removeConnectionID func(protocol.ConnectionID),
retireConnectionID func(protocol.ConnectionID), retireConnectionID func(protocol.ConnectionID),
replaceWithClosed func(protocol.ConnectionID, packetHandler), replaceWithClosed func(protocol.ConnectionID, packetHandler),

View file

@ -22,8 +22,8 @@ var _ = Describe("Connection ID Generator", func() {
initialConnID := protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7} initialConnID := protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7}
initialClientDestConnID := protocol.ConnectionID{0xa, 0xb, 0xc, 0xd, 0xe} initialClientDestConnID := protocol.ConnectionID{0xa, 0xb, 0xc, 0xd, 0xe}
connIDToToken := func(c protocol.ConnectionID) [16]byte { connIDToToken := func(c protocol.ConnectionID) protocol.StatelessResetToken {
return [16]byte{c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0]} return protocol.StatelessResetToken{c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0], c[0]}
} }
BeforeEach(func() { BeforeEach(func() {

View file

@ -18,7 +18,7 @@ type connIDManager struct {
activeSequenceNumber uint64 activeSequenceNumber uint64
highestRetired uint64 highestRetired uint64
activeConnectionID protocol.ConnectionID activeConnectionID protocol.ConnectionID
activeStatelessResetToken *[16]byte activeStatelessResetToken *protocol.StatelessResetToken
// We change the connection ID after sending on average // We change the connection ID after sending on average
// protocol.PacketsPerConnectionID packets. The actual value is randomized // protocol.PacketsPerConnectionID packets. The actual value is randomized
@ -27,17 +27,17 @@ type connIDManager struct {
rand *mrand.Rand rand *mrand.Rand
packetsPerConnectionID uint64 packetsPerConnectionID uint64
addStatelessResetToken func([16]byte) addStatelessResetToken func(protocol.StatelessResetToken)
removeStatelessResetToken func([16]byte) removeStatelessResetToken func(protocol.StatelessResetToken)
retireStatelessResetToken func([16]byte) retireStatelessResetToken func(protocol.StatelessResetToken)
queueControlFrame func(wire.Frame) queueControlFrame func(wire.Frame)
} }
func newConnIDManager( func newConnIDManager(
initialDestConnID protocol.ConnectionID, initialDestConnID protocol.ConnectionID,
addStatelessResetToken func([16]byte), addStatelessResetToken func(protocol.StatelessResetToken),
removeStatelessResetToken func([16]byte), removeStatelessResetToken func(protocol.StatelessResetToken),
retireStatelessResetToken func([16]byte), retireStatelessResetToken func(protocol.StatelessResetToken),
queueControlFrame func(wire.Frame), queueControlFrame func(wire.Frame),
) *connIDManager { ) *connIDManager {
b := make([]byte, 8) b := make([]byte, 8)
@ -53,7 +53,7 @@ func newConnIDManager(
} }
} }
func (h *connIDManager) AddFromPreferredAddress(connID protocol.ConnectionID, resetToken [16]byte) error { func (h *connIDManager) AddFromPreferredAddress(connID protocol.ConnectionID, resetToken protocol.StatelessResetToken) error {
return h.addConnectionID(1, connID, resetToken) return h.addConnectionID(1, connID, resetToken)
} }
@ -110,7 +110,7 @@ func (h *connIDManager) add(f *wire.NewConnectionIDFrame) error {
return nil return nil
} }
func (h *connIDManager) addConnectionID(seq uint64, connID protocol.ConnectionID, resetToken [16]byte) error { func (h *connIDManager) addConnectionID(seq uint64, connID protocol.ConnectionID, resetToken protocol.StatelessResetToken) error {
// insert a new element at the end // insert a new element at the end
if h.queue.Len() == 0 || h.queue.Back().Value.SequenceNumber < seq { if h.queue.Len() == 0 || h.queue.Back().Value.SequenceNumber < seq {
h.queue.PushBack(utils.NewConnectionID{ h.queue.PushBack(utils.NewConnectionID{
@ -177,7 +177,7 @@ func (h *connIDManager) ChangeInitialConnID(newConnID protocol.ConnectionID) {
} }
// is called when the server provides a stateless reset token in the transport parameters // is called when the server provides a stateless reset token in the transport parameters
func (h *connIDManager) SetStatelessResetToken(token [16]byte) { func (h *connIDManager) SetStatelessResetToken(token protocol.StatelessResetToken) {
if h.activeSequenceNumber != 0 { if h.activeSequenceNumber != 0 {
panic("expected first connection ID to have sequence number 0") panic("expected first connection ID to have sequence number 0")
} }

View file

@ -11,9 +11,9 @@ var _ = Describe("Connection ID Manager", func() {
var ( var (
m *connIDManager m *connIDManager
frameQueue []wire.Frame frameQueue []wire.Frame
tokenAdded *[16]byte tokenAdded *protocol.StatelessResetToken
retiredTokens [][16]byte retiredTokens []protocol.StatelessResetToken
removedTokens [][16]byte removedTokens []protocol.StatelessResetToken
) )
initialConnID := protocol.ConnectionID{0, 0, 0, 0} initialConnID := protocol.ConnectionID{0, 0, 0, 0}
@ -24,18 +24,18 @@ var _ = Describe("Connection ID Manager", func() {
removedTokens = nil removedTokens = nil
m = newConnIDManager( m = newConnIDManager(
initialConnID, initialConnID,
func(token [16]byte) { tokenAdded = &token }, func(token protocol.StatelessResetToken) { tokenAdded = &token },
func(token [16]byte) { removedTokens = append(removedTokens, token) }, func(token protocol.StatelessResetToken) { removedTokens = append(removedTokens, token) },
func(token [16]byte) { retiredTokens = append(retiredTokens, token) }, func(token protocol.StatelessResetToken) { retiredTokens = append(retiredTokens, token) },
func(f wire.Frame, func(f wire.Frame,
) { ) {
frameQueue = append(frameQueue, f) frameQueue = append(frameQueue, f)
}) })
}) })
get := func() (protocol.ConnectionID, [16]byte) { get := func() (protocol.ConnectionID, protocol.StatelessResetToken) {
if m.queue.Len() == 0 { if m.queue.Len() == 0 {
return nil, [16]byte{} return nil, protocol.StatelessResetToken{}
} }
val := m.queue.Remove(m.queue.Front()) val := m.queue.Remove(m.queue.Front())
return val.ConnectionID, val.StatelessResetToken return val.ConnectionID, val.StatelessResetToken
@ -51,7 +51,7 @@ var _ = Describe("Connection ID Manager", func() {
}) })
It("sets the token for the first connection ID", func() { It("sets the token for the first connection ID", func() {
token := [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} token := protocol.StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
m.SetStatelessResetToken(token) m.SetStatelessResetToken(token)
Expect(*m.activeStatelessResetToken).To(Equal(token)) Expect(*m.activeStatelessResetToken).To(Equal(token))
Expect(*tokenAdded).To(Equal(token)) Expect(*tokenAdded).To(Equal(token))
@ -61,19 +61,19 @@ var _ = Describe("Connection ID Manager", func() {
Expect(m.Add(&wire.NewConnectionIDFrame{ Expect(m.Add(&wire.NewConnectionIDFrame{
SequenceNumber: 10, SequenceNumber: 10,
ConnectionID: protocol.ConnectionID{2, 3, 4, 5}, ConnectionID: protocol.ConnectionID{2, 3, 4, 5},
StatelessResetToken: [16]byte{0xe, 0xd, 0xc, 0xb, 0xa, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, StatelessResetToken: protocol.StatelessResetToken{0xe, 0xd, 0xc, 0xb, 0xa, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
})).To(Succeed()) })).To(Succeed())
Expect(m.Add(&wire.NewConnectionIDFrame{ Expect(m.Add(&wire.NewConnectionIDFrame{
SequenceNumber: 4, SequenceNumber: 4,
ConnectionID: protocol.ConnectionID{1, 2, 3, 4}, ConnectionID: protocol.ConnectionID{1, 2, 3, 4},
StatelessResetToken: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe}, StatelessResetToken: protocol.StatelessResetToken{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe},
})).To(Succeed()) })).To(Succeed())
c1, rt1 := get() c1, rt1 := get()
Expect(c1).To(Equal(protocol.ConnectionID{1, 2, 3, 4})) Expect(c1).To(Equal(protocol.ConnectionID{1, 2, 3, 4}))
Expect(rt1).To(Equal([16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe})) Expect(rt1).To(Equal(protocol.StatelessResetToken{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe}))
c2, rt2 := get() c2, rt2 := get()
Expect(c2).To(Equal(protocol.ConnectionID{2, 3, 4, 5})) Expect(c2).To(Equal(protocol.ConnectionID{2, 3, 4, 5}))
Expect(rt2).To(Equal([16]byte{0xe, 0xd, 0xc, 0xb, 0xa, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0})) Expect(rt2).To(Equal(protocol.StatelessResetToken{0xe, 0xd, 0xc, 0xb, 0xa, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}))
c3, _ := get() c3, _ := get()
Expect(c3).To(BeNil()) Expect(c3).To(BeNil())
}) })
@ -82,18 +82,18 @@ var _ = Describe("Connection ID Manager", func() {
f1 := &wire.NewConnectionIDFrame{ f1 := &wire.NewConnectionIDFrame{
SequenceNumber: 1, SequenceNumber: 1,
ConnectionID: protocol.ConnectionID{1, 2, 3, 4}, ConnectionID: protocol.ConnectionID{1, 2, 3, 4},
StatelessResetToken: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe}, StatelessResetToken: protocol.StatelessResetToken{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe},
} }
f2 := &wire.NewConnectionIDFrame{ f2 := &wire.NewConnectionIDFrame{
SequenceNumber: 1, SequenceNumber: 1,
ConnectionID: protocol.ConnectionID{1, 2, 3, 4}, ConnectionID: protocol.ConnectionID{1, 2, 3, 4},
StatelessResetToken: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe}, StatelessResetToken: protocol.StatelessResetToken{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe},
} }
Expect(m.Add(f1)).To(Succeed()) Expect(m.Add(f1)).To(Succeed())
Expect(m.Add(f2)).To(Succeed()) Expect(m.Add(f2)).To(Succeed())
c1, rt1 := get() c1, rt1 := get()
Expect(c1).To(Equal(protocol.ConnectionID{1, 2, 3, 4})) Expect(c1).To(Equal(protocol.ConnectionID{1, 2, 3, 4}))
Expect(rt1).To(Equal([16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe})) Expect(rt1).To(Equal(protocol.StatelessResetToken{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe}))
c2, _ := get() c2, _ := get()
Expect(c2).To(BeNil()) Expect(c2).To(BeNil())
}) })
@ -102,7 +102,7 @@ var _ = Describe("Connection ID Manager", func() {
f := &wire.NewConnectionIDFrame{ f := &wire.NewConnectionIDFrame{
SequenceNumber: 1, SequenceNumber: 1,
ConnectionID: protocol.ConnectionID{1, 2, 3, 4}, ConnectionID: protocol.ConnectionID{1, 2, 3, 4},
StatelessResetToken: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe}, StatelessResetToken: protocol.StatelessResetToken{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe},
} }
Expect(m.Add(f)).To(Succeed()) Expect(m.Add(f)).To(Succeed())
Expect(m.Get()).To(Equal(protocol.ConnectionID{1, 2, 3, 4})) Expect(m.Get()).To(Equal(protocol.ConnectionID{1, 2, 3, 4}))
@ -129,12 +129,12 @@ var _ = Describe("Connection ID Manager", func() {
Expect(m.Add(&wire.NewConnectionIDFrame{ Expect(m.Add(&wire.NewConnectionIDFrame{
SequenceNumber: 42, SequenceNumber: 42,
ConnectionID: protocol.ConnectionID{1, 2, 3, 4}, ConnectionID: protocol.ConnectionID{1, 2, 3, 4},
StatelessResetToken: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe}, StatelessResetToken: protocol.StatelessResetToken{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe},
})).To(Succeed()) })).To(Succeed())
Expect(m.Add(&wire.NewConnectionIDFrame{ Expect(m.Add(&wire.NewConnectionIDFrame{
SequenceNumber: 42, SequenceNumber: 42,
ConnectionID: protocol.ConnectionID{1, 2, 3, 4}, ConnectionID: protocol.ConnectionID{1, 2, 3, 4},
StatelessResetToken: [16]byte{0xe, 0xd, 0xc, 0xb, 0xa, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, StatelessResetToken: protocol.StatelessResetToken{0xe, 0xd, 0xc, 0xb, 0xa, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
})).To(MatchError("received conflicting stateless reset tokens for sequence number 42")) })).To(MatchError("received conflicting stateless reset tokens for sequence number 42"))
}) })
@ -225,13 +225,13 @@ var _ = Describe("Connection ID Manager", func() {
Expect(m.Add(&wire.NewConnectionIDFrame{ Expect(m.Add(&wire.NewConnectionIDFrame{
SequenceNumber: uint64(i), SequenceNumber: uint64(i),
ConnectionID: protocol.ConnectionID{i, i, i, i}, ConnectionID: protocol.ConnectionID{i, i, i, i},
StatelessResetToken: [16]byte{i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i}, StatelessResetToken: protocol.StatelessResetToken{i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i},
})).To(Succeed()) })).To(Succeed())
} }
Expect(m.Add(&wire.NewConnectionIDFrame{ Expect(m.Add(&wire.NewConnectionIDFrame{
SequenceNumber: uint64(9999), SequenceNumber: uint64(9999),
ConnectionID: protocol.ConnectionID{1, 2, 3, 4}, ConnectionID: protocol.ConnectionID{1, 2, 3, 4},
StatelessResetToken: [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, StatelessResetToken: protocol.StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
})).To(MatchError("CONNECTION_ID_LIMIT_ERROR")) })).To(MatchError("CONNECTION_ID_LIMIT_ERROR"))
}) })
@ -240,7 +240,7 @@ var _ = Describe("Connection ID Manager", func() {
Expect(m.Add(&wire.NewConnectionIDFrame{ Expect(m.Add(&wire.NewConnectionIDFrame{
SequenceNumber: 1, SequenceNumber: 1,
ConnectionID: protocol.ConnectionID{1, 2, 3, 4}, ConnectionID: protocol.ConnectionID{1, 2, 3, 4},
StatelessResetToken: [16]byte{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, StatelessResetToken: protocol.StatelessResetToken{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1},
})).To(Succeed()) })).To(Succeed())
Expect(m.Get()).To(Equal(protocol.ConnectionID{1, 2, 3, 4})) Expect(m.Get()).To(Equal(protocol.ConnectionID{1, 2, 3, 4}))
@ -252,7 +252,7 @@ var _ = Describe("Connection ID Manager", func() {
Expect(m.Add(&wire.NewConnectionIDFrame{ Expect(m.Add(&wire.NewConnectionIDFrame{
SequenceNumber: uint64(s), SequenceNumber: uint64(s),
ConnectionID: protocol.ConnectionID{s, s, s, s}, ConnectionID: protocol.ConnectionID{s, s, s, s},
StatelessResetToken: [16]byte{s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s}, StatelessResetToken: protocol.StatelessResetToken{s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s},
})).To(Succeed()) })).To(Succeed())
} }
@ -272,7 +272,7 @@ var _ = Describe("Connection ID Manager", func() {
Expect(m.Add(&wire.NewConnectionIDFrame{ Expect(m.Add(&wire.NewConnectionIDFrame{
SequenceNumber: uint64(s), SequenceNumber: uint64(s),
ConnectionID: protocol.ConnectionID{s, s, s, s}, ConnectionID: protocol.ConnectionID{s, s, s, s},
StatelessResetToken: [16]byte{s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s}, StatelessResetToken: protocol.StatelessResetToken{s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s},
})).To(Succeed()) })).To(Succeed())
s++ s++
} }
@ -285,7 +285,7 @@ var _ = Describe("Connection ID Manager", func() {
Expect(m.Add(&wire.NewConnectionIDFrame{ Expect(m.Add(&wire.NewConnectionIDFrame{
SequenceNumber: uint64(s), SequenceNumber: uint64(s),
ConnectionID: protocol.ConnectionID{s, s, s, s}, ConnectionID: protocol.ConnectionID{s, s, s, s},
StatelessResetToken: [16]byte{s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s}, StatelessResetToken: protocol.StatelessResetToken{s, s, s, s, s, s, s, s, s, s, s, s, s, s, s, s},
})).To(Succeed()) })).To(Succeed())
} }
Expect(m.Get()).To(Equal(protocol.ConnectionID{10, 10, 10, 10})) Expect(m.Get()).To(Equal(protocol.ConnectionID{10, 10, 10, 10}))
@ -302,7 +302,7 @@ var _ = Describe("Connection ID Manager", func() {
Expect(m.Add(&wire.NewConnectionIDFrame{ Expect(m.Add(&wire.NewConnectionIDFrame{
SequenceNumber: uint64(5), SequenceNumber: uint64(5),
ConnectionID: protocol.ConnectionID{5, 5, 5, 5}, ConnectionID: protocol.ConnectionID{5, 5, 5, 5},
StatelessResetToken: [16]byte{5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, StatelessResetToken: protocol.StatelessResetToken{5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5},
})).To(Succeed()) })).To(Succeed())
Expect(m.queue.Front().Value.ConnectionID).To(Equal(protocol.ConnectionID{12, 12, 12, 12})) Expect(m.queue.Front().Value.ConnectionID).To(Equal(protocol.ConnectionID{12, 12, 12, 12}))
Expect(frameQueue).To(HaveLen(1)) Expect(frameQueue).To(HaveLen(1))
@ -314,7 +314,7 @@ var _ = Describe("Connection ID Manager", func() {
Expect(m.Add(&wire.NewConnectionIDFrame{ Expect(m.Add(&wire.NewConnectionIDFrame{
SequenceNumber: uint64(i), SequenceNumber: uint64(i),
ConnectionID: protocol.ConnectionID{i, i, i, i}, ConnectionID: protocol.ConnectionID{i, i, i, i},
StatelessResetToken: [16]byte{i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i}, StatelessResetToken: protocol.StatelessResetToken{i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i},
})).To(Succeed()) })).To(Succeed())
} }
Expect(m.Get()).To(Equal(protocol.ConnectionID{1, 1, 1, 1})) Expect(m.Get()).To(Equal(protocol.ConnectionID{1, 1, 1, 1}))
@ -328,7 +328,7 @@ var _ = Describe("Connection ID Manager", func() {
})).To(Succeed()) })).To(Succeed())
Expect(m.Get()).To(Equal(protocol.ConnectionID{2, 2, 2, 2})) Expect(m.Get()).To(Equal(protocol.ConnectionID{2, 2, 2, 2}))
Expect(retiredTokens).To(HaveLen(1)) Expect(retiredTokens).To(HaveLen(1))
Expect(retiredTokens[0]).To(Equal([16]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})) Expect(retiredTokens[0]).To(Equal(protocol.StatelessResetToken{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}))
}) })
It("removes the currently active stateless reset token when it is closed", func() { It("removes the currently active stateless reset token when it is closed", func() {
@ -338,12 +338,12 @@ var _ = Describe("Connection ID Manager", func() {
Expect(m.Add(&wire.NewConnectionIDFrame{ Expect(m.Add(&wire.NewConnectionIDFrame{
SequenceNumber: 1, SequenceNumber: 1,
ConnectionID: protocol.ConnectionID{1, 2, 3, 4}, ConnectionID: protocol.ConnectionID{1, 2, 3, 4},
StatelessResetToken: [16]byte{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, StatelessResetToken: protocol.StatelessResetToken{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1},
})).To(Succeed()) })).To(Succeed())
Expect(m.Get()).To(Equal(protocol.ConnectionID{1, 2, 3, 4})) Expect(m.Get()).To(Equal(protocol.ConnectionID{1, 2, 3, 4}))
m.Close() m.Close()
Expect(retiredTokens).To(BeEmpty()) Expect(retiredTokens).To(BeEmpty())
Expect(removedTokens).To(HaveLen(1)) Expect(removedTokens).To(HaveLen(1))
Expect(removedTokens[0]).To(Equal([16]byte{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1})) Expect(removedTokens[0]).To(Equal(protocol.StatelessResetToken{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}))
}) })
}) })

View file

@ -214,7 +214,7 @@ func getFrames() []wire.Frame {
seq1 := getRandomNumber() seq1 := getRandomNumber()
seq2 := getRandomNumber() seq2 := getRandomNumber()
var token1, token2 [16]byte var token1, token2 protocol.StatelessResetToken
copy(token1[:], getRandomData(16)) copy(token1[:], getRandomData(16))
copy(token2[:], getRandomData(16)) copy(token2[:], getRandomData(16))
frames = append(frames, []wire.Frame{ frames = append(frames, []wire.Frame{

View file

@ -88,7 +88,7 @@ var _ = Describe("Crypto Setup TLS", func() {
return &tls.Config{ServerName: ch.ServerName}, nil return &tls.Config{ServerName: ch.ServerName}, nil
}, },
} }
var token [16]byte var token protocol.StatelessResetToken
server := NewCryptoSetupServer( server := NewCryptoSetupServer(
&bytes.Buffer{}, &bytes.Buffer{},
&bytes.Buffer{}, &bytes.Buffer{},
@ -122,7 +122,7 @@ var _ = Describe("Crypto Setup TLS", func() {
runner := NewMockHandshakeRunner(mockCtrl) runner := NewMockHandshakeRunner(mockCtrl)
runner.EXPECT().OnError(gomock.Any()).Do(func(e error) { sErrChan <- e }) runner.EXPECT().OnError(gomock.Any()).Do(func(e error) { sErrChan <- e })
_, sInitialStream, sHandshakeStream := initStreams() _, sInitialStream, sHandshakeStream := initStreams()
var token [16]byte var token protocol.StatelessResetToken
server := NewCryptoSetupServer( server := NewCryptoSetupServer(
sInitialStream, sInitialStream,
sHandshakeStream, sHandshakeStream,
@ -162,7 +162,7 @@ var _ = Describe("Crypto Setup TLS", func() {
_, sInitialStream, sHandshakeStream := initStreams() _, sInitialStream, sHandshakeStream := initStreams()
runner := NewMockHandshakeRunner(mockCtrl) runner := NewMockHandshakeRunner(mockCtrl)
runner.EXPECT().OnError(gomock.Any()).Do(func(e error) { sErrChan <- e }) runner.EXPECT().OnError(gomock.Any()).Do(func(e error) { sErrChan <- e })
var token [16]byte var token protocol.StatelessResetToken
server := NewCryptoSetupServer( server := NewCryptoSetupServer(
sInitialStream, sInitialStream,
sHandshakeStream, sHandshakeStream,
@ -205,7 +205,7 @@ var _ = Describe("Crypto Setup TLS", func() {
_, sInitialStream, sHandshakeStream := initStreams() _, sInitialStream, sHandshakeStream := initStreams()
runner := NewMockHandshakeRunner(mockCtrl) runner := NewMockHandshakeRunner(mockCtrl)
runner.EXPECT().OnError(gomock.Any()).Do(func(e error) { sErrChan <- e }) runner.EXPECT().OnError(gomock.Any()).Do(func(e error) { sErrChan <- e })
var token [16]byte var token protocol.StatelessResetToken
server := NewCryptoSetupServer( server := NewCryptoSetupServer(
sInitialStream, sInitialStream,
sHandshakeStream, sHandshakeStream,
@ -241,7 +241,7 @@ var _ = Describe("Crypto Setup TLS", func() {
It("returns Handshake() when it is closed", func() { It("returns Handshake() when it is closed", func() {
_, sInitialStream, sHandshakeStream := initStreams() _, sInitialStream, sHandshakeStream := initStreams()
var token [16]byte var token protocol.StatelessResetToken
server := NewCryptoSetupServer( server := NewCryptoSetupServer(
sInitialStream, sInitialStream,
sHandshakeStream, sHandshakeStream,
@ -363,7 +363,7 @@ var _ = Describe("Crypto Setup TLS", func() {
sRunner.EXPECT().OnError(gomock.Any()).Do(func(e error) { sErrChan <- e }).MaxTimes(1) sRunner.EXPECT().OnError(gomock.Any()).Do(func(e error) { sErrChan <- e }).MaxTimes(1)
sRunner.EXPECT().OnHandshakeComplete().Do(func() { sHandshakeComplete = true }).MaxTimes(1) sRunner.EXPECT().OnHandshakeComplete().Do(func() { sHandshakeComplete = true }).MaxTimes(1)
if serverTransportParameters.StatelessResetToken == nil { if serverTransportParameters.StatelessResetToken == nil {
var token [16]byte var token protocol.StatelessResetToken
serverTransportParameters.StatelessResetToken = &token serverTransportParameters.StatelessResetToken = &token
} }
server := NewCryptoSetupServer( server := NewCryptoSetupServer(
@ -493,7 +493,7 @@ var _ = Describe("Crypto Setup TLS", func() {
) )
sChunkChan, sInitialStream, sHandshakeStream := initStreams() sChunkChan, sInitialStream, sHandshakeStream := initStreams()
var token [16]byte var token protocol.StatelessResetToken
sRunner := NewMockHandshakeRunner(mockCtrl) sRunner := NewMockHandshakeRunner(mockCtrl)
sRunner.EXPECT().OnReceivedParams(gomock.Any()).Do(func(tp *wire.TransportParameters) { cTransportParametersRcvd = tp }) sRunner.EXPECT().OnReceivedParams(gomock.Any()).Do(func(tp *wire.TransportParameters) { cTransportParametersRcvd = tp })
sRunner.EXPECT().OnHandshakeComplete() sRunner.EXPECT().OnHandshakeComplete()
@ -553,7 +553,7 @@ var _ = Describe("Crypto Setup TLS", func() {
sRunner := NewMockHandshakeRunner(mockCtrl) sRunner := NewMockHandshakeRunner(mockCtrl)
sRunner.EXPECT().OnReceivedParams(gomock.Any()) sRunner.EXPECT().OnReceivedParams(gomock.Any())
sRunner.EXPECT().OnHandshakeComplete() sRunner.EXPECT().OnHandshakeComplete()
var token [16]byte var token protocol.StatelessResetToken
server := NewCryptoSetupServer( server := NewCryptoSetupServer(
sInitialStream, sInitialStream,
sHandshakeStream, sHandshakeStream,
@ -613,7 +613,7 @@ var _ = Describe("Crypto Setup TLS", func() {
sRunner := NewMockHandshakeRunner(mockCtrl) sRunner := NewMockHandshakeRunner(mockCtrl)
sRunner.EXPECT().OnReceivedParams(gomock.Any()) sRunner.EXPECT().OnReceivedParams(gomock.Any())
sRunner.EXPECT().OnHandshakeComplete() sRunner.EXPECT().OnHandshakeComplete()
var token [16]byte var token protocol.StatelessResetToken
server := NewCryptoSetupServer( server := NewCryptoSetupServer(
sInitialStream, sInitialStream,
sHandshakeStream, sHandshakeStream,

View file

@ -43,6 +43,9 @@ const MaxByteCount = ByteCount(1<<62 - 1)
// An ApplicationErrorCode is an application-defined error code. // An ApplicationErrorCode is an application-defined error code.
type ApplicationErrorCode uint64 type ApplicationErrorCode uint64
// A StatelessResetToken is a stateless reset token.
type StatelessResetToken [16]byte
// MaxReceivePacketSize maximum packet size of any QUIC packet, based on // MaxReceivePacketSize 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, // 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. // UDP adds an additional 8 bytes. This is a total overhead of 48 bytes.

View file

@ -8,5 +8,5 @@ import (
type NewConnectionID struct { type NewConnectionID struct {
SequenceNumber uint64 SequenceNumber uint64
ConnectionID protocol.ConnectionID ConnectionID protocol.ConnectionID
StatelessResetToken [16]byte StatelessResetToken protocol.StatelessResetToken
} }

View file

@ -218,7 +218,7 @@ var _ = Describe("Frame parsing", func() {
f := &NewConnectionIDFrame{ f := &NewConnectionIDFrame{
SequenceNumber: 0x1337, SequenceNumber: 0x1337,
ConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef}, ConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
StatelessResetToken: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, StatelessResetToken: protocol.StatelessResetToken{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
} }
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
Expect(f.Write(buf, versionIETFFrames)).To(Succeed()) Expect(f.Write(buf, versionIETFFrames)).To(Succeed())

View file

@ -143,7 +143,7 @@ var _ = Describe("Frame logging", func() {
LogFrame(logger, &NewConnectionIDFrame{ LogFrame(logger, &NewConnectionIDFrame{
SequenceNumber: 42, SequenceNumber: 42,
ConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef}, ConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
StatelessResetToken: [16]byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10}, StatelessResetToken: protocol.StatelessResetToken{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10},
}, false) }, false)
Expect(buf.String()).To(ContainSubstring("\t<- &wire.NewConnectionIDFrame{SequenceNumber: 42, ConnectionID: 0xdeadbeef, StatelessResetToken: 0x0102030405060708090a0b0c0d0e0f10}")) Expect(buf.String()).To(ContainSubstring("\t<- &wire.NewConnectionIDFrame{SequenceNumber: 42, ConnectionID: 0xdeadbeef, StatelessResetToken: 0x0102030405060708090a0b0c0d0e0f10}"))
}) })

View file

@ -15,7 +15,7 @@ type NewConnectionIDFrame struct {
SequenceNumber uint64 SequenceNumber uint64
RetirePriorTo uint64 RetirePriorTo uint64
ConnectionID protocol.ConnectionID ConnectionID protocol.ConnectionID
StatelessResetToken [16]byte StatelessResetToken protocol.StatelessResetToken
} }
func parseNewConnectionIDFrame(r *bytes.Reader, _ protocol.VersionNumber) (*NewConnectionIDFrame, error) { func parseNewConnectionIDFrame(r *bytes.Reader, _ protocol.VersionNumber) (*NewConnectionIDFrame, error) {

View file

@ -70,7 +70,7 @@ var _ = Describe("NEW_CONNECTION_ID frame", func() {
Context("when writing", func() { Context("when writing", func() {
It("writes a sample frame", func() { It("writes a sample frame", func() {
token := [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} token := protocol.StatelessResetToken{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
frame := &NewConnectionIDFrame{ frame := &NewConnectionIDFrame{
SequenceNumber: 0x1337, SequenceNumber: 0x1337,
RetirePriorTo: 0x42, RetirePriorTo: 0x42,
@ -89,7 +89,7 @@ var _ = Describe("NEW_CONNECTION_ID frame", func() {
}) })
It("has the correct length", func() { It("has the correct length", func() {
token := [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} token := protocol.StatelessResetToken{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
frame := &NewConnectionIDFrame{ frame := &NewConnectionIDFrame{
SequenceNumber: 0xdecafbad, SequenceNumber: 0xdecafbad,
RetirePriorTo: 0xdeadbeefcafe, RetirePriorTo: 0xdeadbeefcafe,

View file

@ -24,8 +24,6 @@ var _ = Describe("Transport Parameters", func() {
rand.Seed(GinkgoRandomSeed()) rand.Seed(GinkgoRandomSeed())
}) })
var token [16]byte
addInitialSourceConnectionID := func(b *bytes.Buffer) { addInitialSourceConnectionID := func(b *bytes.Buffer) {
utils.WriteVarInt(b, uint64(initialSourceConnectionIDParameterID)) utils.WriteVarInt(b, uint64(initialSourceConnectionIDParameterID))
utils.WriteVarInt(b, 6) utils.WriteVarInt(b, 6)
@ -46,7 +44,7 @@ var _ = Describe("Transport Parameters", func() {
RetrySourceConnectionID: &protocol.ConnectionID{0xde, 0xad, 0xc0, 0xde}, RetrySourceConnectionID: &protocol.ConnectionID{0xde, 0xad, 0xc0, 0xde},
AckDelayExponent: 14, AckDelayExponent: 14,
MaxAckDelay: 37 * time.Millisecond, MaxAckDelay: 37 * time.Millisecond,
StatelessResetToken: &[16]byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00}, StatelessResetToken: &protocol.StatelessResetToken{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00},
ActiveConnectionIDLimit: 123, ActiveConnectionIDLimit: 123,
} }
Expect(p.String()).To(Equal("&wire.TransportParameters{OriginalDestinationConnectionID: 0xdeadbeef, InitialSourceConnectionID: 0xdecafbad, RetrySourceConnectionID: 0xdeadc0de, InitialMaxStreamDataBidiLocal: 1234, InitialMaxStreamDataBidiRemote: 2345, InitialMaxStreamDataUni: 3456, InitialMaxData: 4567, MaxBidiStreamNum: 1337, MaxUniStreamNum: 7331, MaxIdleTimeout: 42s, AckDelayExponent: 14, MaxAckDelay: 37ms, ActiveConnectionIDLimit: 123, StatelessResetToken: 0x112233445566778899aabbccddeeff00}")) Expect(p.String()).To(Equal("&wire.TransportParameters{OriginalDestinationConnectionID: 0xdeadbeef, InitialSourceConnectionID: 0xdecafbad, RetrySourceConnectionID: 0xdeadc0de, InitialMaxStreamDataBidiLocal: 1234, InitialMaxStreamDataBidiRemote: 2345, InitialMaxStreamDataUni: 3456, InitialMaxData: 4567, MaxBidiStreamNum: 1337, MaxUniStreamNum: 7331, MaxIdleTimeout: 42s, AckDelayExponent: 14, MaxAckDelay: 37ms, ActiveConnectionIDLimit: 123, StatelessResetToken: 0x112233445566778899aabbccddeeff00}"))
@ -71,7 +69,7 @@ var _ = Describe("Transport Parameters", func() {
}) })
It("marshals and unmarshals", func() { It("marshals and unmarshals", func() {
var token [16]byte var token protocol.StatelessResetToken
rand.Read(token[:]) rand.Read(token[:])
params := &TransportParameters{ params := &TransportParameters{
InitialMaxStreamDataBidiLocal: protocol.ByteCount(getRandomValue()), InitialMaxStreamDataBidiLocal: protocol.ByteCount(getRandomValue()),
@ -113,7 +111,7 @@ var _ = Describe("Transport Parameters", func() {
It("doesn't marshal a retry_source_connection_id, if no Retry was performed", func() { It("doesn't marshal a retry_source_connection_id, if no Retry was performed", func() {
data := (&TransportParameters{ data := (&TransportParameters{
StatelessResetToken: &token, StatelessResetToken: &protocol.StatelessResetToken{},
}).Marshal(protocol.PerspectiveServer) }).Marshal(protocol.PerspectiveServer)
p := &TransportParameters{} p := &TransportParameters{}
Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(Succeed()) Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(Succeed())
@ -123,7 +121,7 @@ var _ = Describe("Transport Parameters", func() {
It("marshals a zero-length retry_source_connection_id", func() { It("marshals a zero-length retry_source_connection_id", func() {
data := (&TransportParameters{ data := (&TransportParameters{
RetrySourceConnectionID: &protocol.ConnectionID{}, RetrySourceConnectionID: &protocol.ConnectionID{},
StatelessResetToken: &token, StatelessResetToken: &protocol.StatelessResetToken{},
}).Marshal(protocol.PerspectiveServer) }).Marshal(protocol.PerspectiveServer)
p := &TransportParameters{} p := &TransportParameters{}
Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(Succeed()) Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(Succeed())
@ -159,7 +157,7 @@ var _ = Describe("Transport Parameters", func() {
b := &bytes.Buffer{} b := &bytes.Buffer{}
utils.WriteVarInt(b, uint64(statelessResetTokenParameterID)) utils.WriteVarInt(b, uint64(statelessResetTokenParameterID))
utils.WriteVarInt(b, 16) utils.WriteVarInt(b, 16)
b.Write(token[:]) b.Write(make([]byte, 16))
addInitialSourceConnectionID(b) addInitialSourceConnectionID(b)
Expect((&TransportParameters{}).Unmarshal(b.Bytes(), protocol.PerspectiveServer)).To(MatchError("TRANSPORT_PARAMETER_ERROR: missing original_destination_connection_id")) Expect((&TransportParameters{}).Unmarshal(b.Bytes(), protocol.PerspectiveServer)).To(MatchError("TRANSPORT_PARAMETER_ERROR: missing original_destination_connection_id"))
}) })
@ -171,7 +169,7 @@ var _ = Describe("Transport Parameters", func() {
It("errors when the max_ack_delay is too large", func() { It("errors when the max_ack_delay is too large", func() {
data := (&TransportParameters{ data := (&TransportParameters{
MaxAckDelay: 1 << 14 * time.Millisecond, MaxAckDelay: 1 << 14 * time.Millisecond,
StatelessResetToken: &token, StatelessResetToken: &protocol.StatelessResetToken{},
}).Marshal(protocol.PerspectiveServer) }).Marshal(protocol.PerspectiveServer)
p := &TransportParameters{} p := &TransportParameters{}
Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(MatchError("TRANSPORT_PARAMETER_ERROR: invalid value for max_ack_delay: 16384ms (maximum 16383ms)")) Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(MatchError("TRANSPORT_PARAMETER_ERROR: invalid value for max_ack_delay: 16384ms (maximum 16383ms)"))
@ -185,12 +183,12 @@ var _ = Describe("Transport Parameters", func() {
for i := 0; i < num; i++ { for i := 0; i < num; i++ {
dataDefault := (&TransportParameters{ dataDefault := (&TransportParameters{
MaxAckDelay: protocol.DefaultMaxAckDelay, MaxAckDelay: protocol.DefaultMaxAckDelay,
StatelessResetToken: &token, StatelessResetToken: &protocol.StatelessResetToken{},
}).Marshal(protocol.PerspectiveServer) }).Marshal(protocol.PerspectiveServer)
defaultLen += len(dataDefault) defaultLen += len(dataDefault)
data := (&TransportParameters{ data := (&TransportParameters{
MaxAckDelay: maxAckDelay, MaxAckDelay: maxAckDelay,
StatelessResetToken: &token, StatelessResetToken: &protocol.StatelessResetToken{},
}).Marshal(protocol.PerspectiveServer) }).Marshal(protocol.PerspectiveServer)
dataLen += len(data) dataLen += len(data)
} }
@ -201,7 +199,7 @@ var _ = Describe("Transport Parameters", func() {
It("errors when the ack_delay_exponenent is too large", func() { It("errors when the ack_delay_exponenent is too large", func() {
data := (&TransportParameters{ data := (&TransportParameters{
AckDelayExponent: 21, AckDelayExponent: 21,
StatelessResetToken: &token, StatelessResetToken: &protocol.StatelessResetToken{},
}).Marshal(protocol.PerspectiveServer) }).Marshal(protocol.PerspectiveServer)
p := &TransportParameters{} p := &TransportParameters{}
Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(MatchError("TRANSPORT_PARAMETER_ERROR: invalid value for ack_delay_exponent: 21 (maximum 20)")) Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(MatchError("TRANSPORT_PARAMETER_ERROR: invalid value for ack_delay_exponent: 21 (maximum 20)"))
@ -214,12 +212,12 @@ var _ = Describe("Transport Parameters", func() {
for i := 0; i < num; i++ { for i := 0; i < num; i++ {
dataDefault := (&TransportParameters{ dataDefault := (&TransportParameters{
AckDelayExponent: protocol.DefaultAckDelayExponent, AckDelayExponent: protocol.DefaultAckDelayExponent,
StatelessResetToken: &token, StatelessResetToken: &protocol.StatelessResetToken{},
}).Marshal(protocol.PerspectiveServer) }).Marshal(protocol.PerspectiveServer)
defaultLen += len(dataDefault) defaultLen += len(dataDefault)
data := (&TransportParameters{ data := (&TransportParameters{
AckDelayExponent: protocol.DefaultAckDelayExponent + 1, AckDelayExponent: protocol.DefaultAckDelayExponent + 1,
StatelessResetToken: &token, StatelessResetToken: &protocol.StatelessResetToken{},
}).Marshal(protocol.PerspectiveServer) }).Marshal(protocol.PerspectiveServer)
dataLen += len(data) dataLen += len(data)
} }
@ -230,7 +228,7 @@ var _ = Describe("Transport Parameters", func() {
It("sets the default value for the ack_delay_exponent, when no value was sent", func() { It("sets the default value for the ack_delay_exponent, when no value was sent", func() {
data := (&TransportParameters{ data := (&TransportParameters{
AckDelayExponent: protocol.DefaultAckDelayExponent, AckDelayExponent: protocol.DefaultAckDelayExponent,
StatelessResetToken: &token, StatelessResetToken: &protocol.StatelessResetToken{},
}).Marshal(protocol.PerspectiveServer) }).Marshal(protocol.PerspectiveServer)
p := &TransportParameters{} p := &TransportParameters{}
Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(Succeed()) Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(Succeed())
@ -316,7 +314,7 @@ var _ = Describe("Transport Parameters", func() {
b := &bytes.Buffer{} b := &bytes.Buffer{}
utils.WriteVarInt(b, uint64(statelessResetTokenParameterID)) utils.WriteVarInt(b, uint64(statelessResetTokenParameterID))
utils.WriteVarInt(b, uint64(utils.VarIntLen(16))) utils.WriteVarInt(b, uint64(utils.VarIntLen(16)))
b.Write(token[:]) b.Write(make([]byte, 16))
Expect((&TransportParameters{}).Unmarshal(b.Bytes(), protocol.PerspectiveClient)).To(MatchError("TRANSPORT_PARAMETER_ERROR: client sent a stateless_reset_token")) Expect((&TransportParameters{}).Unmarshal(b.Bytes(), protocol.PerspectiveClient)).To(MatchError("TRANSPORT_PARAMETER_ERROR: client sent a stateless_reset_token"))
}) })
@ -338,14 +336,14 @@ var _ = Describe("Transport Parameters", func() {
IPv6: net.IP{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, IPv6: net.IP{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
IPv6Port: 13, IPv6Port: 13,
ConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef}, ConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
StatelessResetToken: [16]byte{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, StatelessResetToken: protocol.StatelessResetToken{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1},
} }
}) })
It("marshals and unmarshals", func() { It("marshals and unmarshals", func() {
data := (&TransportParameters{ data := (&TransportParameters{
PreferredAddress: pa, PreferredAddress: pa,
StatelessResetToken: &token, StatelessResetToken: &protocol.StatelessResetToken{},
}).Marshal(protocol.PerspectiveServer) }).Marshal(protocol.PerspectiveServer)
p := &TransportParameters{} p := &TransportParameters{}
Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(Succeed()) Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(Succeed())
@ -370,7 +368,7 @@ var _ = Describe("Transport Parameters", func() {
pa.ConnectionID = protocol.ConnectionID{} pa.ConnectionID = protocol.ConnectionID{}
data := (&TransportParameters{ data := (&TransportParameters{
PreferredAddress: pa, PreferredAddress: pa,
StatelessResetToken: &token, StatelessResetToken: &protocol.StatelessResetToken{},
}).Marshal(protocol.PerspectiveServer) }).Marshal(protocol.PerspectiveServer)
p := &TransportParameters{} p := &TransportParameters{}
Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(MatchError("TRANSPORT_PARAMETER_ERROR: invalid connection ID length: 0")) Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(MatchError("TRANSPORT_PARAMETER_ERROR: invalid connection ID length: 0"))
@ -381,7 +379,7 @@ var _ = Describe("Transport Parameters", func() {
Expect(pa.ConnectionID.Len()).To(BeNumerically(">", protocol.MaxConnIDLen)) Expect(pa.ConnectionID.Len()).To(BeNumerically(">", protocol.MaxConnIDLen))
data := (&TransportParameters{ data := (&TransportParameters{
PreferredAddress: pa, PreferredAddress: pa,
StatelessResetToken: &token, StatelessResetToken: &protocol.StatelessResetToken{},
}).Marshal(protocol.PerspectiveServer) }).Marshal(protocol.PerspectiveServer)
p := &TransportParameters{} p := &TransportParameters{}
Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(MatchError("TRANSPORT_PARAMETER_ERROR: invalid connection ID length: 21")) Expect(p.Unmarshal(data, protocol.PerspectiveServer)).To(MatchError("TRANSPORT_PARAMETER_ERROR: invalid connection ID length: 21"))

View file

@ -51,7 +51,7 @@ type PreferredAddress struct {
IPv6 net.IP IPv6 net.IP
IPv6Port uint16 IPv6Port uint16
ConnectionID protocol.ConnectionID ConnectionID protocol.ConnectionID
StatelessResetToken [16]byte StatelessResetToken protocol.StatelessResetToken
} }
// TransportParameters are parameters sent to the peer during the handshake // TransportParameters are parameters sent to the peer during the handshake
@ -79,7 +79,7 @@ type TransportParameters struct {
InitialSourceConnectionID protocol.ConnectionID InitialSourceConnectionID protocol.ConnectionID
RetrySourceConnectionID *protocol.ConnectionID // use a pointer here to distinguish zero-length connection IDs from missing transport parameters RetrySourceConnectionID *protocol.ConnectionID // use a pointer here to distinguish zero-length connection IDs from missing transport parameters
StatelessResetToken *[16]byte StatelessResetToken *protocol.StatelessResetToken
ActiveConnectionIDLimit uint64 ActiveConnectionIDLimit uint64
} }
@ -160,7 +160,7 @@ func (p *TransportParameters) unmarshal(r *bytes.Reader, sentBy protocol.Perspec
if paramLen != 16 { if paramLen != 16 {
return fmt.Errorf("wrong length for stateless_reset_token: %d (expected 16)", paramLen) return fmt.Errorf("wrong length for stateless_reset_token: %d (expected 16)", paramLen)
} }
var token [16]byte var token protocol.StatelessResetToken
r.Read(token[:]) r.Read(token[:])
p.StatelessResetToken = &token p.StatelessResetToken = &token
case originalDestinationConnectionIDParameterID: case originalDestinationConnectionIDParameterID:

View file

@ -12,7 +12,7 @@ type CloseReason struct {
transportError *TransportError transportError *TransportError
timeout *TimeoutReason timeout *TimeoutReason
statelessResetToken *[16]byte statelessResetToken *StatelessResetToken
} }
// NewApplicationCloseReason creates a new CloseReason for an application error. // NewApplicationCloseReason creates a new CloseReason for an application error.
@ -31,8 +31,8 @@ func NewTimeoutCloseReason(r TimeoutReason) CloseReason {
} }
// NewStatelessResetCloseReason creates a new CloseReason for a stateless reset. // NewStatelessResetCloseReason creates a new CloseReason for a stateless reset.
func NewStatelessResetCloseReason(token *[16]byte) CloseReason { func NewStatelessResetCloseReason(token StatelessResetToken) CloseReason {
return CloseReason{statelessResetToken: token} return CloseReason{statelessResetToken: &token}
} }
// ApplicationError gets the application error. // ApplicationError gets the application error.
@ -60,7 +60,7 @@ func (r *CloseReason) Timeout() (reason TimeoutReason, ok bool) {
} }
// StatelessReset gets the stateless reset token. // StatelessReset gets the stateless reset token.
func (r *CloseReason) StatelessReset() (token [16]byte, ok bool) { func (r *CloseReason) StatelessReset() (token StatelessResetToken, ok bool) {
if r.statelessResetToken == nil { if r.statelessResetToken == nil {
return return
} }

View file

@ -59,10 +59,10 @@ var _ = Describe("Close Reason", func() {
}) })
It("stateless resets", func() { It("stateless resets", func() {
r := NewStatelessResetCloseReason(&[16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}) r := NewStatelessResetCloseReason(StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})
token, ok := r.StatelessReset() token, ok := r.StatelessReset()
Expect(ok).To(BeTrue()) Expect(ok).To(BeTrue())
Expect(token).To(Equal([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})) Expect(token).To(Equal(StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}))
checkNotApplicationError(r) checkNotApplicationError(r)
checkNotTransportError(r) checkNotTransportError(r)
checkNotTimeout(r) checkNotTimeout(r)

View file

@ -25,6 +25,8 @@ type (
PacketNumber = protocol.PacketNumber PacketNumber = protocol.PacketNumber
// The Perspective is the role of a QUIC endpoint (client or server). // The Perspective is the role of a QUIC endpoint (client or server).
Perspective = protocol.Perspective Perspective = protocol.Perspective
// A StatelessResetToken is a stateless reset token.
StatelessResetToken = protocol.StatelessResetToken
// The StreamID is the stream ID. // The StreamID is the stream ID.
StreamID = protocol.StreamID StreamID = protocol.StreamID
// The StreamNum is the number of the stream. // The StreamNum is the number of the stream.

View file

@ -49,7 +49,7 @@ func (mr *MockPacketHandlerManagerMockRecorder) Add(arg0, arg1 interface{}) *gom
} }
// AddResetToken mocks base method // AddResetToken mocks base method
func (m *MockPacketHandlerManager) AddResetToken(arg0 [16]byte, arg1 packetHandler) { func (m *MockPacketHandlerManager) AddResetToken(arg0 protocol.StatelessResetToken, arg1 packetHandler) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
m.ctrl.Call(m, "AddResetToken", arg0, arg1) m.ctrl.Call(m, "AddResetToken", arg0, arg1)
} }
@ -101,10 +101,10 @@ func (mr *MockPacketHandlerManagerMockRecorder) Destroy() *gomock.Call {
} }
// GetStatelessResetToken mocks base method // GetStatelessResetToken mocks base method
func (m *MockPacketHandlerManager) GetStatelessResetToken(arg0 protocol.ConnectionID) [16]byte { func (m *MockPacketHandlerManager) GetStatelessResetToken(arg0 protocol.ConnectionID) protocol.StatelessResetToken {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetStatelessResetToken", arg0) ret := m.ctrl.Call(m, "GetStatelessResetToken", arg0)
ret0, _ := ret[0].([16]byte) ret0, _ := ret[0].(protocol.StatelessResetToken)
return ret0 return ret0
} }
@ -127,7 +127,7 @@ func (mr *MockPacketHandlerManagerMockRecorder) Remove(arg0 interface{}) *gomock
} }
// RemoveResetToken mocks base method // RemoveResetToken mocks base method
func (m *MockPacketHandlerManager) RemoveResetToken(arg0 [16]byte) { func (m *MockPacketHandlerManager) RemoveResetToken(arg0 protocol.StatelessResetToken) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
m.ctrl.Call(m, "RemoveResetToken", arg0) m.ctrl.Call(m, "RemoveResetToken", arg0)
} }
@ -163,7 +163,7 @@ func (mr *MockPacketHandlerManagerMockRecorder) Retire(arg0 interface{}) *gomock
} }
// RetireResetToken mocks base method // RetireResetToken mocks base method
func (m *MockPacketHandlerManager) RetireResetToken(arg0 [16]byte) { func (m *MockPacketHandlerManager) RetireResetToken(arg0 protocol.StatelessResetToken) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
m.ctrl.Call(m, "RetireResetToken", arg0) m.ctrl.Call(m, "RetireResetToken", arg0)
} }

View file

@ -49,7 +49,7 @@ func (mr *MockSessionRunnerMockRecorder) Add(arg0, arg1 interface{}) *gomock.Cal
} }
// AddResetToken mocks base method // AddResetToken mocks base method
func (m *MockSessionRunner) AddResetToken(arg0 [16]byte, arg1 packetHandler) { func (m *MockSessionRunner) AddResetToken(arg0 protocol.StatelessResetToken, arg1 packetHandler) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
m.ctrl.Call(m, "AddResetToken", arg0, arg1) m.ctrl.Call(m, "AddResetToken", arg0, arg1)
} }
@ -61,10 +61,10 @@ func (mr *MockSessionRunnerMockRecorder) AddResetToken(arg0, arg1 interface{}) *
} }
// GetStatelessResetToken mocks base method // GetStatelessResetToken mocks base method
func (m *MockSessionRunner) GetStatelessResetToken(arg0 protocol.ConnectionID) [16]byte { func (m *MockSessionRunner) GetStatelessResetToken(arg0 protocol.ConnectionID) protocol.StatelessResetToken {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetStatelessResetToken", arg0) ret := m.ctrl.Call(m, "GetStatelessResetToken", arg0)
ret0, _ := ret[0].([16]byte) ret0, _ := ret[0].(protocol.StatelessResetToken)
return ret0 return ret0
} }
@ -87,7 +87,7 @@ func (mr *MockSessionRunnerMockRecorder) Remove(arg0 interface{}) *gomock.Call {
} }
// RemoveResetToken mocks base method // RemoveResetToken mocks base method
func (m *MockSessionRunner) RemoveResetToken(arg0 [16]byte) { func (m *MockSessionRunner) RemoveResetToken(arg0 protocol.StatelessResetToken) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
m.ctrl.Call(m, "RemoveResetToken", arg0) m.ctrl.Call(m, "RemoveResetToken", arg0)
} }
@ -123,7 +123,7 @@ func (mr *MockSessionRunnerMockRecorder) Retire(arg0 interface{}) *gomock.Call {
} }
// RetireResetToken mocks base method // RetireResetToken mocks base method
func (m *MockSessionRunner) RetireResetToken(arg0 [16]byte) { func (m *MockSessionRunner) RetireResetToken(arg0 protocol.StatelessResetToken) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
m.ctrl.Call(m, "RetireResetToken", arg0) m.ctrl.Call(m, "RetireResetToken", arg0)
} }

View file

@ -16,7 +16,7 @@ import (
) )
type statelessResetErr struct { type statelessResetErr struct {
token [16]byte token protocol.StatelessResetToken
} }
func (e statelessResetErr) Error() string { func (e statelessResetErr) Error() string {
@ -34,7 +34,7 @@ type packetHandlerMap struct {
connIDLen int connIDLen int
handlers map[string] /* string(ConnectionID)*/ packetHandler handlers map[string] /* string(ConnectionID)*/ packetHandler
resetTokens map[[16]byte] /* stateless reset token */ packetHandler resetTokens map[protocol.StatelessResetToken] /* stateless reset token */ packetHandler
server unknownPacketHandler server unknownPacketHandler
listening chan struct{} // is closed when listen returns listening chan struct{} // is closed when listen returns
@ -62,7 +62,7 @@ func newPacketHandlerMap(
connIDLen: connIDLen, connIDLen: connIDLen,
listening: make(chan struct{}), listening: make(chan struct{}),
handlers: make(map[string]packetHandler), handlers: make(map[string]packetHandler),
resetTokens: make(map[[16]byte]packetHandler), resetTokens: make(map[protocol.StatelessResetToken]packetHandler),
deleteRetiredSessionsAfter: protocol.RetiredConnectionIDDeleteTimeout, deleteRetiredSessionsAfter: protocol.RetiredConnectionIDDeleteTimeout,
statelessResetEnabled: len(statelessResetKey) > 0, statelessResetEnabled: len(statelessResetKey) > 0,
statelessResetHasher: hmac.New(sha256.New, statelessResetKey), statelessResetHasher: hmac.New(sha256.New, statelessResetKey),
@ -167,19 +167,19 @@ func (h *packetHandlerMap) ReplaceWithClosed(id protocol.ConnectionID, handler p
}) })
} }
func (h *packetHandlerMap) AddResetToken(token [16]byte, handler packetHandler) { func (h *packetHandlerMap) AddResetToken(token protocol.StatelessResetToken, handler packetHandler) {
h.mutex.Lock() h.mutex.Lock()
h.resetTokens[token] = handler h.resetTokens[token] = handler
h.mutex.Unlock() h.mutex.Unlock()
} }
func (h *packetHandlerMap) RemoveResetToken(token [16]byte) { func (h *packetHandlerMap) RemoveResetToken(token protocol.StatelessResetToken) {
h.mutex.Lock() h.mutex.Lock()
delete(h.resetTokens, token) delete(h.resetTokens, token)
h.mutex.Unlock() h.mutex.Unlock()
} }
func (h *packetHandlerMap) RetireResetToken(token [16]byte) { func (h *packetHandlerMap) RetireResetToken(token protocol.StatelessResetToken) {
time.AfterFunc(h.deleteRetiredSessionsAfter, func() { time.AfterFunc(h.deleteRetiredSessionsAfter, func() {
h.mutex.Lock() h.mutex.Lock()
delete(h.resetTokens, token) delete(h.resetTokens, token)
@ -313,7 +313,7 @@ func (h *packetHandlerMap) maybeHandleStatelessReset(data []byte) bool {
return false return false
} }
var token [16]byte var token protocol.StatelessResetToken
copy(token[:], data[len(data)-16:]) copy(token[:], data[len(data)-16:])
if sess, ok := h.resetTokens[token]; ok { if sess, ok := h.resetTokens[token]; ok {
h.logger.Debugf("Received a stateless reset with token %#x. Closing session.", token) h.logger.Debugf("Received a stateless reset with token %#x. Closing session.", token)
@ -323,8 +323,8 @@ func (h *packetHandlerMap) maybeHandleStatelessReset(data []byte) bool {
return false return false
} }
func (h *packetHandlerMap) GetStatelessResetToken(connID protocol.ConnectionID) [16]byte { func (h *packetHandlerMap) GetStatelessResetToken(connID protocol.ConnectionID) protocol.StatelessResetToken {
var token [16]byte var token protocol.StatelessResetToken
if !h.statelessResetEnabled { if !h.statelessResetEnabled {
// Return a random stateless reset token. // Return a random stateless reset token.
// This token will be sent in the server's transport parameters. // This token will be sent in the server's transport parameters.

View file

@ -236,7 +236,7 @@ var _ = Describe("Packet Handler Map", func() {
Context("handling", func() { Context("handling", func() {
It("handles stateless resets", func() { It("handles stateless resets", func() {
packetHandler := NewMockPacketHandler(mockCtrl) packetHandler := NewMockPacketHandler(mockCtrl)
token := [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} token := protocol.StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
handler.AddResetToken(token, packetHandler) handler.AddResetToken(token, packetHandler)
packet := append([]byte{0x40} /* short header packet */, make([]byte, 50)...) packet := append([]byte{0x40} /* short header packet */, make([]byte, 50)...)
packet = append(packet, token[:]...) packet = append(packet, token[:]...)
@ -257,7 +257,7 @@ var _ = Describe("Packet Handler Map", func() {
It("handles stateless resets for 0-length connection IDs", func() { It("handles stateless resets for 0-length connection IDs", func() {
handler.connIDLen = 0 handler.connIDLen = 0
packetHandler := NewMockPacketHandler(mockCtrl) packetHandler := NewMockPacketHandler(mockCtrl)
token := [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} token := protocol.StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
handler.AddResetToken(token, packetHandler) handler.AddResetToken(token, packetHandler)
packet := append([]byte{0x40} /* short header packet */, make([]byte, 50)...) packet := append([]byte{0x40} /* short header packet */, make([]byte, 50)...)
packet = append(packet, token[:]...) packet = append(packet, token[:]...)
@ -280,7 +280,7 @@ var _ = Describe("Packet Handler Map", func() {
connID := protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0x42} connID := protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0x42}
packetHandler := NewMockPacketHandler(mockCtrl) packetHandler := NewMockPacketHandler(mockCtrl)
handler.Add(connID, packetHandler) handler.Add(connID, packetHandler)
token := [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} token := protocol.StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
handler.AddResetToken(token, NewMockPacketHandler(mockCtrl)) handler.AddResetToken(token, NewMockPacketHandler(mockCtrl))
handler.RetireResetToken(token) handler.RetireResetToken(token)
packetHandler.EXPECT().handlePacket(gomock.Any()) packetHandler.EXPECT().handlePacket(gomock.Any())
@ -295,7 +295,7 @@ var _ = Describe("Packet Handler Map", func() {
It("ignores packets too small to contain a stateless reset", func() { It("ignores packets too small to contain a stateless reset", func() {
handler.connIDLen = 0 handler.connIDLen = 0
packetHandler := NewMockPacketHandler(mockCtrl) packetHandler := NewMockPacketHandler(mockCtrl)
token := [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} token := protocol.StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
handler.AddResetToken(token, packetHandler) handler.AddResetToken(token, packetHandler)
packet := append([]byte{0x40} /* short header packet */, token[:15]...) packet := append([]byte{0x40} /* short header packet */, token[:15]...)
done := make(chan struct{}) done := make(chan struct{})

View file

@ -179,7 +179,7 @@ func (e eventVersionNegotiationReceived) MarshalJSONObject(enc *gojay.Encoder) {
} }
type eventStatelessResetReceived struct { type eventStatelessResetReceived struct {
Token [16]byte Token protocol.StatelessResetToken
} }
func (e eventStatelessResetReceived) Category() category { return categoryTransport } func (e eventStatelessResetReceived) Category() category { return categoryTransport }
@ -332,7 +332,7 @@ type eventTransportParameters struct {
InitialSourceConnectionID protocol.ConnectionID InitialSourceConnectionID protocol.ConnectionID
RetrySourceConnectionID *protocol.ConnectionID RetrySourceConnectionID *protocol.ConnectionID
StatelessResetToken *[16]byte StatelessResetToken *protocol.StatelessResetToken
DisableActiveMigration bool DisableActiveMigration bool
MaxIdleTimeout time.Duration MaxIdleTimeout time.Duration
MaxUDPPayloadSize protocol.ByteCount MaxUDPPayloadSize protocol.ByteCount

View file

@ -257,7 +257,7 @@ var _ = Describe("Frames", func() {
SequenceNumber: 42, SequenceNumber: 42,
RetirePriorTo: 24, RetirePriorTo: 24,
ConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef}, ConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
StatelessResetToken: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf}, StatelessResetToken: protocol.StatelessResetToken{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf},
}, },
map[string]interface{}{ map[string]interface{}{
"frame_type": "new_connection_id", "frame_type": "new_connection_id",

View file

@ -183,7 +183,7 @@ var _ = Describe("Tracing", func() {
}) })
It("records a received stateless reset packet", func() { It("records a received stateless reset packet", func() {
tracer.ClosedConnection(logging.NewStatelessResetCloseReason(&[16]byte{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff})) tracer.ClosedConnection(logging.NewStatelessResetCloseReason(logging.StatelessResetToken{0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}))
entry := exportAndParseSingle() entry := exportAndParseSingle()
Expect(entry.Time).To(BeTemporally("~", time.Now(), scaleDuration(10*time.Millisecond))) Expect(entry.Time).To(BeTemporally("~", time.Now(), scaleDuration(10*time.Millisecond)))
Expect(entry.Category).To(Equal("transport")) Expect(entry.Category).To(Equal("transport"))
@ -206,7 +206,7 @@ var _ = Describe("Tracing", func() {
DisableActiveMigration: true, DisableActiveMigration: true,
MaxUDPPayloadSize: 1234, MaxUDPPayloadSize: 1234,
MaxIdleTimeout: 321 * time.Millisecond, MaxIdleTimeout: 321 * time.Millisecond,
StatelessResetToken: &[16]byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00}, StatelessResetToken: &protocol.StatelessResetToken{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00},
OriginalDestinationConnectionID: protocol.ConnectionID{0xde, 0xad, 0xc0, 0xde}, OriginalDestinationConnectionID: protocol.ConnectionID{0xde, 0xad, 0xc0, 0xde},
InitialSourceConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef}, InitialSourceConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef},
RetrySourceConnectionID: &protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad}, RetrySourceConnectionID: &protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
@ -249,7 +249,7 @@ var _ = Describe("Tracing", func() {
It("records transport parameters without retry_source_connection_id", func() { It("records transport parameters without retry_source_connection_id", func() {
tracer.SentTransportParameters(&logging.TransportParameters{ tracer.SentTransportParameters(&logging.TransportParameters{
StatelessResetToken: &[16]byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00}, StatelessResetToken: &protocol.StatelessResetToken{0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00},
}) })
entry := exportAndParseSingle() entry := exportAndParseSingle()
Expect(entry.Time).To(BeTemporally("~", time.Now(), scaleDuration(10*time.Millisecond))) Expect(entry.Time).To(BeTemporally("~", time.Now(), scaleDuration(10*time.Millisecond)))

View file

@ -81,7 +81,7 @@ type baseServer struct {
protocol.ConnectionID, /* client dest connection ID */ protocol.ConnectionID, /* client dest connection ID */
protocol.ConnectionID, /* destination connection ID */ protocol.ConnectionID, /* destination connection ID */
protocol.ConnectionID, /* source connection ID */ protocol.ConnectionID, /* source connection ID */
[16]byte, protocol.StatelessResetToken,
*Config, *Config,
*tls.Config, *tls.Config,
*handshake.TokenGenerator, *handshake.TokenGenerator,

View file

@ -308,13 +308,13 @@ var _ = Describe("Server", func() {
} }
p := getPacket(hdr, make([]byte, protocol.MinInitialPacketSize)) p := getPacket(hdr, make([]byte, protocol.MinInitialPacketSize))
run := make(chan struct{}) run := make(chan struct{})
var token [16]byte var token protocol.StatelessResetToken
rand.Read(token[:]) rand.Read(token[:])
var newConnID protocol.ConnectionID var newConnID protocol.ConnectionID
phm.EXPECT().AddWithConnID(protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, gomock.Any(), gomock.Any()).DoAndReturn(func(_, c protocol.ConnectionID, fn func() packetHandler) bool { phm.EXPECT().AddWithConnID(protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, gomock.Any(), gomock.Any()).DoAndReturn(func(_, c protocol.ConnectionID, fn func() packetHandler) bool {
newConnID = c newConnID = c
phm.EXPECT().GetStatelessResetToken(gomock.Any()).DoAndReturn(func(c protocol.ConnectionID) [16]byte { phm.EXPECT().GetStatelessResetToken(gomock.Any()).DoAndReturn(func(c protocol.ConnectionID) protocol.StatelessResetToken {
newConnID = c newConnID = c
return token return token
}) })
@ -330,7 +330,7 @@ var _ = Describe("Server", func() {
clientDestConnID protocol.ConnectionID, clientDestConnID protocol.ConnectionID,
destConnID protocol.ConnectionID, destConnID protocol.ConnectionID,
srcConnID protocol.ConnectionID, srcConnID protocol.ConnectionID,
tokenP [16]byte, tokenP protocol.StatelessResetToken,
_ *Config, _ *Config,
_ *tls.Config, _ *tls.Config,
_ *handshake.TokenGenerator, _ *handshake.TokenGenerator,
@ -481,13 +481,13 @@ var _ = Describe("Server", func() {
} }
p := getPacket(hdr, make([]byte, protocol.MinInitialPacketSize)) p := getPacket(hdr, make([]byte, protocol.MinInitialPacketSize))
run := make(chan struct{}) run := make(chan struct{})
var token [16]byte var token protocol.StatelessResetToken
rand.Read(token[:]) rand.Read(token[:])
var newConnID protocol.ConnectionID var newConnID protocol.ConnectionID
phm.EXPECT().AddWithConnID(protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, gomock.Any(), gomock.Any()).DoAndReturn(func(_, c protocol.ConnectionID, fn func() packetHandler) bool { phm.EXPECT().AddWithConnID(protocol.ConnectionID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, gomock.Any(), gomock.Any()).DoAndReturn(func(_, c protocol.ConnectionID, fn func() packetHandler) bool {
newConnID = c newConnID = c
phm.EXPECT().GetStatelessResetToken(gomock.Any()).DoAndReturn(func(c protocol.ConnectionID) [16]byte { phm.EXPECT().GetStatelessResetToken(gomock.Any()).DoAndReturn(func(c protocol.ConnectionID) protocol.StatelessResetToken {
newConnID = c newConnID = c
return token return token
}) })
@ -504,7 +504,7 @@ var _ = Describe("Server", func() {
clientDestConnID protocol.ConnectionID, clientDestConnID protocol.ConnectionID,
destConnID protocol.ConnectionID, destConnID protocol.ConnectionID,
srcConnID protocol.ConnectionID, srcConnID protocol.ConnectionID,
tokenP [16]byte, tokenP protocol.StatelessResetToken,
_ *Config, _ *Config,
_ *tls.Config, _ *tls.Config,
_ *handshake.TokenGenerator, _ *handshake.TokenGenerator,
@ -571,7 +571,7 @@ var _ = Describe("Server", func() {
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ [16]byte, _ protocol.StatelessResetToken,
_ *Config, _ *Config,
_ *tls.Config, _ *tls.Config,
_ *handshake.TokenGenerator, _ *handshake.TokenGenerator,
@ -614,7 +614,7 @@ var _ = Describe("Server", func() {
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ [16]byte, _ protocol.StatelessResetToken,
_ *Config, _ *Config,
_ *tls.Config, _ *tls.Config,
_ *handshake.TokenGenerator, _ *handshake.TokenGenerator,
@ -665,7 +665,7 @@ var _ = Describe("Server", func() {
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ [16]byte, _ protocol.StatelessResetToken,
_ *Config, _ *Config,
_ *tls.Config, _ *tls.Config,
_ *handshake.TokenGenerator, _ *handshake.TokenGenerator,
@ -695,7 +695,7 @@ var _ = Describe("Server", func() {
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ [16]byte, _ protocol.StatelessResetToken,
_ *Config, _ *Config,
_ *tls.Config, _ *tls.Config,
_ *handshake.TokenGenerator, _ *handshake.TokenGenerator,
@ -760,7 +760,7 @@ var _ = Describe("Server", func() {
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ [16]byte, _ protocol.StatelessResetToken,
_ *Config, _ *Config,
_ *tls.Config, _ *tls.Config,
_ *handshake.TokenGenerator, _ *handshake.TokenGenerator,
@ -868,7 +868,7 @@ var _ = Describe("Server", func() {
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ [16]byte, _ protocol.StatelessResetToken,
_ *Config, _ *Config,
_ *tls.Config, _ *tls.Config,
_ *handshake.TokenGenerator, _ *handshake.TokenGenerator,
@ -935,7 +935,7 @@ var _ = Describe("Server", func() {
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ [16]byte, _ protocol.StatelessResetToken,
_ *Config, _ *Config,
_ *tls.Config, _ *tls.Config,
_ *handshake.TokenGenerator, _ *handshake.TokenGenerator,
@ -973,7 +973,7 @@ var _ = Describe("Server", func() {
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ [16]byte, _ protocol.StatelessResetToken,
_ *Config, _ *Config,
_ *tls.Config, _ *tls.Config,
_ *handshake.TokenGenerator, _ *handshake.TokenGenerator,
@ -1032,7 +1032,7 @@ var _ = Describe("Server", func() {
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ protocol.ConnectionID, _ protocol.ConnectionID,
_ [16]byte, _ protocol.StatelessResetToken,
_ *Config, _ *Config,
_ *tls.Config, _ *tls.Config,
_ *handshake.TokenGenerator, _ *handshake.TokenGenerator,

View file

@ -78,13 +78,13 @@ func (p *receivedPacket) Clone() *receivedPacket {
type sessionRunner interface { type sessionRunner interface {
Add(protocol.ConnectionID, packetHandler) bool Add(protocol.ConnectionID, packetHandler) bool
GetStatelessResetToken(protocol.ConnectionID) [16]byte GetStatelessResetToken(protocol.ConnectionID) protocol.StatelessResetToken
Retire(protocol.ConnectionID) Retire(protocol.ConnectionID)
Remove(protocol.ConnectionID) Remove(protocol.ConnectionID)
ReplaceWithClosed(protocol.ConnectionID, packetHandler) ReplaceWithClosed(protocol.ConnectionID, packetHandler)
AddResetToken([16]byte, packetHandler) AddResetToken(protocol.StatelessResetToken, packetHandler)
RemoveResetToken([16]byte) RemoveResetToken(protocol.StatelessResetToken)
RetireResetToken([16]byte) RetireResetToken(protocol.StatelessResetToken)
} }
type handshakeRunner struct { type handshakeRunner struct {
@ -221,7 +221,7 @@ var newSession = func(
clientDestConnID protocol.ConnectionID, clientDestConnID protocol.ConnectionID,
destConnID protocol.ConnectionID, destConnID protocol.ConnectionID,
srcConnID protocol.ConnectionID, srcConnID protocol.ConnectionID,
statelessResetToken [16]byte, statelessResetToken protocol.StatelessResetToken,
conf *Config, conf *Config,
tlsConf *tls.Config, tlsConf *tls.Config,
tokenGenerator *handshake.TokenGenerator, tokenGenerator *handshake.TokenGenerator,
@ -250,7 +250,7 @@ var newSession = func(
} }
s.connIDManager = newConnIDManager( s.connIDManager = newConnIDManager(
destConnID, destConnID,
func(token [16]byte) { runner.AddResetToken(token, s) }, func(token protocol.StatelessResetToken) { runner.AddResetToken(token, s) },
runner.RemoveResetToken, runner.RemoveResetToken,
runner.RetireResetToken, runner.RetireResetToken,
s.queueControlFrame, s.queueControlFrame,
@ -372,7 +372,7 @@ var newClientSession = func(
} }
s.connIDManager = newConnIDManager( s.connIDManager = newConnIDManager(
destConnID, destConnID,
func(token [16]byte) { runner.AddResetToken(token, s) }, func(token protocol.StatelessResetToken) { runner.AddResetToken(token, s) },
runner.RemoveResetToken, runner.RemoveResetToken,
runner.RetireResetToken, runner.RetireResetToken,
s.queueControlFrame, s.queueControlFrame,
@ -1301,7 +1301,7 @@ func (s *session) handleCloseError(closeErr closeError) {
if nerr, ok := closeErr.err.(net.Error); !ok || !nerr.Timeout() { if nerr, ok := closeErr.err.(net.Error); !ok || !nerr.Timeout() {
var resetErr statelessResetErr var resetErr statelessResetErr
if errors.As(closeErr.err, &resetErr) { if errors.As(closeErr.err, &resetErr) {
s.tracer.ClosedConnection(logging.NewStatelessResetCloseReason(&resetErr.token)) s.tracer.ClosedConnection(logging.NewStatelessResetCloseReason(resetErr.token))
} else if quicErr.IsApplicationError() { } else if quicErr.IsApplicationError() {
s.tracer.ClosedConnection(logging.NewApplicationCloseReason(quicErr.ErrorCode, closeErr.remote)) s.tracer.ClosedConnection(logging.NewApplicationCloseReason(quicErr.ErrorCode, closeErr.remote))
} else { } else {

View file

@ -99,7 +99,7 @@ var _ = Describe("Session", func() {
clientDestConnID, clientDestConnID,
destConnID, destConnID,
srcConnID, srcConnID,
[16]byte{}, protocol.StatelessResetToken{},
populateServerConfig(&Config{}), populateServerConfig(&Config{}),
nil, // tls.Config nil, // tls.Config
tokenGenerator, tokenGenerator,
@ -641,7 +641,7 @@ var _ = Describe("Session", func() {
}) })
It("closes due to a stateless reset", func() { It("closes due to a stateless reset", func() {
token := [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} token := protocol.StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
runSession() runSession()
gomock.InOrder( gomock.InOrder(
tracer.EXPECT().ClosedConnection(gomock.Any()).Do(func(reason logging.CloseReason) { tracer.EXPECT().ClosedConnection(gomock.Any()).Do(func(reason logging.CloseReason) {
@ -2452,7 +2452,7 @@ var _ = Describe("Client Session", func() {
IPv4: net.IPv4(127, 0, 0, 1), IPv4: net.IPv4(127, 0, 0, 1),
IPv6: net.IP{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, IPv6: net.IP{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
ConnectionID: protocol.ConnectionID{1, 2, 3, 4}, ConnectionID: protocol.ConnectionID{1, 2, 3, 4},
StatelessResetToken: [16]byte{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, StatelessResetToken: protocol.StatelessResetToken{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1},
}, },
} }
packer.EXPECT().HandleTransportParameters(gomock.Any()) packer.EXPECT().HandleTransportParameters(gomock.Any())
@ -2462,10 +2462,10 @@ var _ = Describe("Client Session", func() {
// make sure the connection ID is not retired // make sure the connection ID is not retired
cf, _ := sess.framer.AppendControlFrames(nil, protocol.MaxByteCount) cf, _ := sess.framer.AppendControlFrames(nil, protocol.MaxByteCount)
Expect(cf).To(BeEmpty()) Expect(cf).To(BeEmpty())
sessionRunner.EXPECT().AddResetToken([16]byte{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, sess) sessionRunner.EXPECT().AddResetToken(protocol.StatelessResetToken{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}, sess)
Expect(sess.connIDManager.Get()).To(Equal(protocol.ConnectionID{1, 2, 3, 4})) Expect(sess.connIDManager.Get()).To(Equal(protocol.ConnectionID{1, 2, 3, 4}))
// shut down // shut down
sessionRunner.EXPECT().RemoveResetToken([16]byte{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}) sessionRunner.EXPECT().RemoveResetToken(protocol.StatelessResetToken{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1})
expectClose() expectClose()
}) })
@ -2487,7 +2487,7 @@ var _ = Describe("Client Session", func() {
params := &wire.TransportParameters{ params := &wire.TransportParameters{
OriginalDestinationConnectionID: destConnID, OriginalDestinationConnectionID: destConnID,
InitialSourceConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad}, InitialSourceConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
StatelessResetToken: &[16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, StatelessResetToken: &protocol.StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
} }
expectClose() expectClose()
tracer.EXPECT().ReceivedTransportParameters(params) tracer.EXPECT().ReceivedTransportParameters(params)
@ -2500,7 +2500,7 @@ var _ = Describe("Client Session", func() {
params := &wire.TransportParameters{ params := &wire.TransportParameters{
OriginalDestinationConnectionID: destConnID, OriginalDestinationConnectionID: destConnID,
InitialSourceConnectionID: destConnID, InitialSourceConnectionID: destConnID,
StatelessResetToken: &[16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, StatelessResetToken: &protocol.StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
} }
expectClose() expectClose()
tracer.EXPECT().ReceivedTransportParameters(params) tracer.EXPECT().ReceivedTransportParameters(params)
@ -2514,7 +2514,7 @@ var _ = Describe("Client Session", func() {
OriginalDestinationConnectionID: destConnID, OriginalDestinationConnectionID: destConnID,
InitialSourceConnectionID: destConnID, InitialSourceConnectionID: destConnID,
RetrySourceConnectionID: &protocol.ConnectionID{0xde, 0xad, 0xc0, 0xde}, RetrySourceConnectionID: &protocol.ConnectionID{0xde, 0xad, 0xc0, 0xde},
StatelessResetToken: &[16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, StatelessResetToken: &protocol.StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
} }
expectClose() expectClose()
tracer.EXPECT().ReceivedTransportParameters(params) tracer.EXPECT().ReceivedTransportParameters(params)
@ -2527,7 +2527,7 @@ var _ = Describe("Client Session", func() {
OriginalDestinationConnectionID: destConnID, OriginalDestinationConnectionID: destConnID,
InitialSourceConnectionID: destConnID, InitialSourceConnectionID: destConnID,
RetrySourceConnectionID: &protocol.ConnectionID{0xde, 0xad, 0xc0, 0xde}, RetrySourceConnectionID: &protocol.ConnectionID{0xde, 0xad, 0xc0, 0xde},
StatelessResetToken: &[16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, StatelessResetToken: &protocol.StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
} }
expectClose() expectClose()
tracer.EXPECT().ReceivedTransportParameters(params) tracer.EXPECT().ReceivedTransportParameters(params)
@ -2540,7 +2540,7 @@ var _ = Describe("Client Session", func() {
params := &wire.TransportParameters{ params := &wire.TransportParameters{
OriginalDestinationConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad}, OriginalDestinationConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad},
InitialSourceConnectionID: sess.handshakeDestConnID, InitialSourceConnectionID: sess.handshakeDestConnID,
StatelessResetToken: &[16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, StatelessResetToken: &protocol.StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
} }
expectClose() expectClose()
tracer.EXPECT().ReceivedTransportParameters(params) tracer.EXPECT().ReceivedTransportParameters(params)