-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: This class creates and holds a QuicSocket during a server handshake, and invokes a callback when it succeeds or fails. Reviewed By: kvtsoy Differential Revision: D48888347 fbshipit-source-id: f6be70d1413c2f3d71e26abbb2e9b57572fd6ab1
- Loading branch information
1 parent
8d12fa3
commit d070675
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <quic/api/QuicSocket.h> | ||
#include <quic/server/QuicServerTransport.h> | ||
|
||
namespace quic { | ||
|
||
class QuicHandshakeSocketHolder | ||
: public quic::QuicSocket::ConnectionSetupCallback { | ||
public: | ||
class Callback { | ||
public: | ||
virtual ~Callback() = default; | ||
virtual void onQuicTransportReady( | ||
std::shared_ptr<quic::QuicSocket> quicSocket) = 0; | ||
virtual void onConnectionSetupError( | ||
std::shared_ptr<quic::QuicSocket> quicSocket, | ||
quic::QuicError code) = 0; | ||
}; | ||
|
||
static QuicServerTransport::Ptr makeServerTransport( | ||
folly::EventBase* evb, | ||
std::unique_ptr<folly::AsyncUDPSocket> socket, | ||
std::shared_ptr<const fizz::server::FizzServerContext> ctx, | ||
Callback* callback) { | ||
auto acceptCb = std::make_unique<QuicHandshakeSocketHolder>(callback); | ||
auto transport = quic::QuicServerTransport::make( | ||
evb, std::move(socket), acceptCb.get(), nullptr, std::move(ctx)); | ||
acceptCb->quicSocket_ = transport; | ||
(void)acceptCb.release(); | ||
return transport; | ||
} | ||
|
||
// Please use static factory function | ||
explicit QuicHandshakeSocketHolder(Callback* callback) | ||
: callback_(callback) {} | ||
|
||
private: | ||
void onConnectionSetupError(quic::QuicError code) noexcept override { | ||
quicSocket_->setConnectionSetupCallback(nullptr); | ||
if (callback_) { | ||
callback_->onConnectionSetupError(std::move(quicSocket_), code); | ||
} | ||
delete this; | ||
} | ||
void onReplaySafe() noexcept override { | ||
// Unused for server | ||
} | ||
void onTransportReady() noexcept override { | ||
quicSocket_->setConnectionSetupCallback(nullptr); | ||
if (callback_) { | ||
// The callback needs to set a new connection callback on quicSocket, | ||
// otherwise it will have a null pointer. | ||
callback_->onQuicTransportReady(std::move(quicSocket_)); | ||
} | ||
delete this; | ||
} | ||
|
||
Callback* callback_{nullptr}; | ||
std::shared_ptr<quic::QuicSocket> quicSocket_; | ||
}; | ||
|
||
} // namespace quic |