Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Sources/SwiftNetwork/QUIC/QUICConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,11 @@ public final class QUICConnection: ManyToManyApplicationStreamProtocol,
return
}

if state == .retrySent {
// The token was validated and is no longer needed.
self.initialToken = nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to line 1635?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hesitant to have it earlier because there seem to be two code paths that exit after the token validation but before the state transition. And if we drop the token, packetParser.retryTokenPresent(...) does not have the token anymore.

Are the following checks guaranteed to succeed in that case?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's ok the way it is.

}

// Change state from idle to initial received with key state = handshake
state.change(to: .initialReceived, logIDString: logPrefixer.logIDString)
keyState = .handshake
Expand Down
15 changes: 9 additions & 6 deletions Tests/SwiftNetworkTests/SwiftNetworkQUICRetryTokenTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ final class SwiftNetworkQUICRetryTokenTests: NetTestCase {
harness.state?.clientInstance.initialToken,
"Client should have an initial retry token"
)
XCTAssertNotNil(
// The server's token was reset after verifying the client token.
XCTAssertNil(
harness.state?.serverInstance.initialToken,
"Server should have an initial retry token"
"Server must discard the retry token once validated, so it is never sent in an INITIAL"
)
expectation.fulfill()
}
Expand Down Expand Up @@ -101,9 +102,10 @@ final class SwiftNetworkQUICRetryTokenTests: NetTestCase {
harness.state?.clientInstance.initialToken,
"Client should have an initial retry token"
)
XCTAssertNotNil(
// The server's token was reset after verifying the client token.
XCTAssertNil(
harness.state?.serverInstance.initialToken,
"Server should have an initial retry token"
"Server must discard the retry token once validated, so it is never sent in an INITIAL"
)
expectation.fulfill()
}
Expand All @@ -128,9 +130,10 @@ final class SwiftNetworkQUICRetryTokenTests: NetTestCase {
harness.state?.clientInstance.initialToken,
"Client should have an initial retry token"
)
XCTAssertNotNil(
// The server's token was reset after verifying the client token.
XCTAssertNil(
harness.state?.serverInstance.initialToken,
"Server should have an initial retry token"
"Server must discard the retry token once validated, so it is never sent in an INITIAL"
)
expectation.fulfill()
}
Expand Down
Loading