Skip to content

Commit

Permalink
Make a getPeerTransportParams function
Browse files Browse the repository at this point in the history
Summary: I'm putting this up to get some initial feedback. I'm writing a function to get the peer transport parameters so that we can get them in the HQSession and set the QUIC fingerprint.

Reviewed By: hanidamlaj

Differential Revision: D54399572

fbshipit-source-id: 594294c26a5b34bc99a8d286a66be9cdbe7fff02
  • Loading branch information
Aman Sharma authored and facebook-github-bot committed Apr 9, 2024
1 parent 940d4a7 commit 875bca1
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 2 deletions.
6 changes: 6 additions & 0 deletions quic/api/QuicSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <quic/common/events/QuicEventBase.h>
#include <quic/common/udpsocket/QuicAsyncUDPSocket.h>
#include <quic/congestion_control/Bandwidth.h>
#include <quic/handshake/TransportParameters.h>
#include <quic/observer/SocketObserverContainer.h>
#include <quic/observer/SocketObserverTypes.h>
#include <quic/state/QuicConnectionStats.h>
Expand Down Expand Up @@ -277,6 +278,11 @@ class QuicSocket {
folly::Optional<QuicErrorCode> streamWriteError;
};

// Returns folly::none before the handshake is complete, otherwise is always
// non-empty.
virtual folly::Optional<std::vector<TransportParameter>>
getPeerTransportParams() const = 0;

/**
* Sets connection setup callback. This callback must be set before using the
* socket.
Expand Down
5 changes: 5 additions & 0 deletions quic/api/test/MockQuicSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class MockQuicSocket : public QuicSocket {
MOCK_METHOD(const folly::SocketAddress&, getPeerAddress, (), (const));
MOCK_METHOD(const folly::SocketAddress&, getOriginalPeerAddress, (), (const));
MOCK_METHOD(const folly::SocketAddress&, getLocalAddress, (), (const));
MOCK_METHOD(
folly::Optional<std::vector<TransportParameter>>,
getPeerTransportParams,
(),
(const));
MOCK_METHOD(std::shared_ptr<QuicEventBase>, getEventBase, (), (const));
MOCK_METHOD(
(folly::Expected<size_t, LocalErrorCode>),
Expand Down
5 changes: 5 additions & 0 deletions quic/api/test/QuicTransportBaseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ class TestQuicTransport
closeUdpSocket();
}

folly::Optional<std::vector<TransportParameter>> getPeerTransportParams()
const override {
return folly::none;
}

std::chrono::milliseconds getLossTimeoutRemainingTime() {
return lossTimeout_.getTimerCallbackTimeRemaining();
}
Expand Down
5 changes: 5 additions & 0 deletions quic/api/test/TestQuicTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class TestQuicTransport
closeUdpSocket();
}

folly::Optional<std::vector<TransportParameter>> getPeerTransportParams()
const override {
return folly::none;
}

QuicVersion getVersion() {
auto& conn = getConnectionState();
return conn.version.value_or(*conn.originalVersion);
Expand Down
12 changes: 12 additions & 0 deletions quic/client/QuicClientTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,18 @@ void QuicClientTransport::maybeSendTransportKnobs() {
}
}

folly::Optional<std::vector<TransportParameter>>
QuicClientTransport::getPeerTransportParams() const {
if (clientConn_ && clientConn_->clientHandshakeLayer) {
auto maybeParams =
clientConn_->clientHandshakeLayer->getServerTransportParams();
if (maybeParams) {
return maybeParams->parameters;
}
}
return folly::none;
}

void QuicClientTransport::RecvmmsgStorage::resize(size_t numPackets) {
if (msgs.size() != numPackets) {
msgs.resize(numPackets);
Expand Down
3 changes: 3 additions & 0 deletions quic/client/QuicClientTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ class QuicClientTransport
conn_->bufAccessor = bufAccessor_.get();
}

folly::Optional<std::vector<TransportParameter>> getPeerTransportParams()
const override;

class HappyEyeballsConnAttemptDelayTimeout : public QuicTimerCallback {
public:
explicit HappyEyeballsConnAttemptDelayTimeout(
Expand Down
12 changes: 12 additions & 0 deletions quic/server/QuicServerTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,4 +1201,16 @@ void QuicServerTransport::logTimeBasedStats() const {
}
}

folly::Optional<std::vector<TransportParameter>>
QuicServerTransport::getPeerTransportParams() const {
if (serverConn_ && serverConn_->serverHandshakeLayer) {
auto maybeParams =
serverConn_->serverHandshakeLayer->getClientTransportParams();
if (maybeParams) {
return maybeParams->parameters;
}
}
return folly::none;
}

} // namespace quic
3 changes: 3 additions & 0 deletions quic/server/QuicServerTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ class QuicServerTransport
*/
void logTimeBasedStats() const;

folly::Optional<std::vector<TransportParameter>> getPeerTransportParams()
const override;

protected:
// From QuicSocket
SocketObserverContainer* getSocketObserverContainer() const override {
Expand Down
4 changes: 2 additions & 2 deletions quic/server/handshake/ServerTransportParametersExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class ServerTransportParametersExtension : public fizz::ServerExtensions {
return exts;
}

folly::Optional<ClientTransportParameters> getClientTransportParams() {
return std::move(clientTransportParameters_);
const folly::Optional<ClientTransportParameters>& getClientTransportParams() {
return clientTransportParameters_;
}

private:
Expand Down

0 comments on commit 875bca1

Please sign in to comment.