Skip to content

Commit

Permalink
Add QuicPskCache to FizzClientQuicHandshakeContext
Browse files Browse the repository at this point in the history
  • Loading branch information
deadalnix committed Feb 26, 2020
1 parent 37dfc0f commit bde83b2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
25 changes: 22 additions & 3 deletions quic/client/handshake/FizzClientQuicHandshakeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,34 @@ namespace quic {

FizzClientQuicHandshakeContext::FizzClientQuicHandshakeContext(
std::shared_ptr<const fizz::client::FizzClientContext> context,
std::shared_ptr<const fizz::CertificateVerifier> verifier)
: context_(std::move(context)), verifier_(std::move(verifier)) {}
std::shared_ptr<const fizz::CertificateVerifier> verifier,
std::shared_ptr<QuicPskCache> pskCache)
: context_(std::move(context)),
verifier_(std::move(verifier)),
pskCache_(std::move(pskCache)) {}

std::unique_ptr<ClientHandshake>
FizzClientQuicHandshakeContext::makeClientHandshake(
QuicClientConnectionState* conn) {
return std::make_unique<FizzClientHandshake>(conn, shared_from_this());
}

folly::Optional<QuicCachedPsk> FizzClientQuicHandshakeContext::getPsk(
const folly::Optional<std::string>& hostname) {
if (!hostname || !pskCache_) {
return folly::none;
}

return pskCache_->getPsk(*hostname);
}

void FizzClientQuicHandshakeContext::removePsk(
const folly::Optional<std::string>& hostname) {
if (hostname && pskCache_) {
pskCache_->removePsk(*hostname);
}
}

std::shared_ptr<FizzClientQuicHandshakeContext>
FizzClientQuicHandshakeContext::Builder::build() {
if (!context_) {
Expand All @@ -35,7 +54,7 @@ FizzClientQuicHandshakeContext::Builder::build() {

return std::shared_ptr<FizzClientQuicHandshakeContext>(
new FizzClientQuicHandshakeContext(
std::move(context_), std::move(verifier_)));
std::move(context_), std::move(verifier_), std::move(pskCache_)));
}

} // namespace quic
16 changes: 15 additions & 1 deletion quic/client/handshake/FizzClientQuicHandshakeContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <quic/client/handshake/ClientHandshakeFactory.h>

#include <quic/client/handshake/QuicPskCache.h>

#include <fizz/client/FizzClientContext.h>
#include <fizz/protocol/DefaultCertificateVerifier.h>

Expand All @@ -34,6 +36,10 @@ class FizzClientQuicHandshakeContext
return verifier_;
}

folly::Optional<QuicCachedPsk> getPsk(
const folly::Optional<std::string>& hostname);
void removePsk(const folly::Optional<std::string>& hostname);

private:
/**
* We make the constructor private so that users have to use the Builder
Expand All @@ -45,10 +51,12 @@ class FizzClientQuicHandshakeContext
*/
FizzClientQuicHandshakeContext(
std::shared_ptr<const fizz::client::FizzClientContext> context,
std::shared_ptr<const fizz::CertificateVerifier> verifier);
std::shared_ptr<const fizz::CertificateVerifier> verifier,
std::shared_ptr<QuicPskCache> pskCache);

std::shared_ptr<const fizz::client::FizzClientContext> context_;
std::shared_ptr<const fizz::CertificateVerifier> verifier_;
std::shared_ptr<QuicPskCache> pskCache_;

public:
class Builder {
Expand All @@ -65,11 +73,17 @@ class FizzClientQuicHandshakeContext
return *this;
}

Builder& setPskCache(std::shared_ptr<QuicPskCache> pskCache) {
pskCache_ = std::move(pskCache);
return *this;
}

std::shared_ptr<FizzClientQuicHandshakeContext> build();

private:
std::shared_ptr<const fizz::client::FizzClientContext> context_;
std::shared_ptr<const fizz::CertificateVerifier> verifier_;
std::shared_ptr<QuicPskCache> pskCache_;
};
};

Expand Down

0 comments on commit bde83b2

Please sign in to comment.