Skip to content

Commit

Permalink
fix issuing of connection IDs when dialing a 0-RTT connections
Browse files Browse the repository at this point in the history
When dialing a 0-RTT connection, the client first restores the transport
parameters from the original connection, and then applies the transport
parameters provided by the server on the new connections.
  • Loading branch information
marten-seemann committed Mar 3, 2021
1 parent 2c45f2b commit 42b48c1
Show file tree
Hide file tree
Showing 3 changed files with 394 additions and 356 deletions.
2 changes: 1 addition & 1 deletion conn_id_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (m *connIDGenerator) SetMaxActiveConnIDs(limit uint64) error {
// transport parameter.
// We currently don't send the preferred_address transport parameter,
// so we can issue (limit - 1) connection IDs.
for i := uint64(1); i < utils.MinUint64(limit, protocol.MaxIssuedConnectionIDs); i++ {
for i := uint64(len(m.activeSrcConnIDs)); i < utils.MinUint64(limit, protocol.MaxIssuedConnectionIDs); i++ {
if err := m.issueNewConnID(); err != nil {
return err
}
Expand Down
31 changes: 31 additions & 0 deletions conn_id_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,37 @@ var _ = Describe("Connection ID Generator", func() {
Expect(queuedFrames).To(HaveLen(protocol.MaxIssuedConnectionIDs - 1))
})

// SetMaxActiveConnIDs is called twice when we dialing a 0-RTT connection:
// once for the restored from the old connections, once when we receive the transport parameters
Context("dealing with 0-RTT", func() {
It("doesn't issue new connection IDs when SetMaxActiveConnIDs is called with the same value", func() {
Expect(g.SetMaxActiveConnIDs(4)).To(Succeed())
Expect(queuedFrames).To(HaveLen(3))
queuedFrames = nil
Expect(g.SetMaxActiveConnIDs(4)).To(Succeed())
Expect(queuedFrames).To(BeEmpty())
})

It("issues more connection IDs if the server allows a higher limit on the resumed connection", func() {
Expect(g.SetMaxActiveConnIDs(3)).To(Succeed())
Expect(queuedFrames).To(HaveLen(2))
queuedFrames = nil
Expect(g.SetMaxActiveConnIDs(6)).To(Succeed())
Expect(queuedFrames).To(HaveLen(3))
})

It("issues more connection IDs if the server allows a higher limit on the resumed connection, when connection IDs were retired in between", func() {
Expect(g.SetMaxActiveConnIDs(3)).To(Succeed())
Expect(queuedFrames).To(HaveLen(2))
queuedFrames = nil
g.Retire(1, protocol.ConnectionID{})
Expect(queuedFrames).To(HaveLen(1))
queuedFrames = nil
Expect(g.SetMaxActiveConnIDs(6)).To(Succeed())
Expect(queuedFrames).To(HaveLen(3))
})
})

It("errors if the peers tries to retire a connection ID that wasn't yet issued", func() {
Expect(g.Retire(1, protocol.ConnectionID{})).To(MatchError("PROTOCOL_VIOLATION: tried to retire connection ID 1. Highest issued: 0"))
})
Expand Down
Loading

0 comments on commit 42b48c1

Please sign in to comment.