Skip to content

Commit

Permalink
Move core functionality to QuicTransportBaseLite [24/n]
Browse files Browse the repository at this point in the history
Summary:
There are many files in this diff, but the relevant ones are:
* quic/api/QuicSocket.h
* quic/api/QuicSocketLite.h
* quic/api/QuicTransportBase.h
* quic/api/QuicTransportBaseLite.cpp
* quic/observer/SocketObserverContainer.h

The purpose of this is to include the observer functionality within the Lite class. Ideally, we'd remove it from the Lite class, but that's going to require some more detailed changes to the interfaces we're using, because observers are used quite a lot within common code (for example, AckHandlers.cpp).

I'll make those changes some time after the QuicTransportBase split, as they're going to take a while.

Reviewed By: jbeshay, mjoras, kvtsoy

Differential Revision: D65685667

fbshipit-source-id: feb07bcf35d6af2e5c2b538ff463b01b67c6aff9
  • Loading branch information
Aman Sharma authored and facebook-github-bot committed Nov 14, 2024
1 parent 3f27fde commit 1cc00f7
Show file tree
Hide file tree
Showing 10 changed files with 471 additions and 363 deletions.
183 changes: 0 additions & 183 deletions quic/api/QuicSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,63 +33,6 @@ class DSRPacketizationRequestSender;

class QuicSocket : virtual public QuicSocketLite {
public:
/**
* Information about the transport, similar to what TCP has.
*/
struct TransportInfo {
// Time when the connection started.
TimePoint connectionTime;
std::chrono::microseconds srtt{0us};
std::chrono::microseconds rttvar{0us};
std::chrono::microseconds lrtt{0us};
OptionalMicros maybeLrtt;
OptionalMicros maybeLrttAckDelay;
OptionalMicros maybeMinRtt;
OptionalMicros maybeMinRttNoAckDelay;
uint64_t mss{kDefaultUDPSendPacketLen};
CongestionControlType congestionControlType{CongestionControlType::None};
uint64_t writableBytes{0};
uint64_t congestionWindow{0};
uint64_t pacingBurstSize{0};
std::chrono::microseconds pacingInterval{0us};
uint32_t packetsRetransmitted{0};
uint32_t totalPacketsSent{0};
uint32_t totalAckElicitingPacketsSent{0};
uint32_t totalPacketsMarkedLost{0};
uint32_t totalPacketsMarkedLostByTimeout{0};
uint32_t totalPacketsMarkedLostByReorderingThreshold{0};
uint32_t totalPacketsSpuriouslyMarkedLost{0};
uint32_t timeoutBasedLoss{0};
std::chrono::microseconds pto{0us};
// Number of Bytes (packet header + body) that were sent
uint64_t bytesSent{0};
// Number of Bytes (packet header + body) that were acked
uint64_t bytesAcked{0};
// Number of Bytes (packet header + body) that were received
uint64_t bytesRecvd{0};
// Number of Bytes (packet header + body) that are in-flight
uint64_t bytesInFlight{0};
// Number of Bytes (packet header + body) that were retxed
uint64_t totalBytesRetransmitted{0};
// Number of Bytes (only the encoded packet's body) that were sent
uint64_t bodyBytesSent{0};
// Number of Bytes (only the encoded packet's body) that were acked
uint64_t bodyBytesAcked{0};
// Total number of stream bytes sent on this connection.
// Includes retransmissions of stream bytes.
uint64_t totalStreamBytesSent{0};
// Total number of 'new' stream bytes sent on this connection.
// Does not include retransmissions of stream bytes.
uint64_t totalNewStreamBytesSent{0};
uint32_t ptoCount{0};
uint32_t totalPTOCount{0};
Optional<PacketNum> largestPacketAckedByPeer;
Optional<PacketNum> largestPacketSent;
bool usedZeroRtt{false};
// State from congestion control module, if one is installed.
Optional<CongestionController::State> maybeCCState;
};

/**
* Sets the functions that mvfst will invoke to validate early data params
* and encode early data params to NewSessionTicket.
Expand Down Expand Up @@ -161,16 +104,6 @@ class QuicSocket : virtual public QuicSocketLite {
FOLLY_NODISCARD virtual Optional<ConnectionId>
getClientChosenDestConnectionId() const = 0;

/**
* Get the original peer socket address
*/
virtual const folly::SocketAddress& getOriginalPeerAddress() const = 0;

/**
* Get the local socket address
*/
virtual const folly::SocketAddress& getLocalAddress() const = 0;

virtual bool replaySafe() const = 0;

/**
Expand All @@ -193,11 +126,6 @@ class QuicSocket : virtual public QuicSocketLite {
virtual folly::Expected<size_t, LocalErrorCode> getStreamWriteBufferedBytes(
StreamId id) const = 0;

/**
* Get internal transport info similar to TCP information.
*/
virtual TransportInfo getTransportInfo() const = 0;

/**
* Returns the current flow control windows for the connection.
* Use getStreamFlowControl for stream flow control window.
Expand Down Expand Up @@ -226,13 +154,6 @@ class QuicSocket : virtual public QuicSocketLite {
virtual folly::Expected<folly::Unit, LocalErrorCode>
setStreamFlowControlWindow(StreamId id, uint64_t windowSize) = 0;

/**
* Sets the maximum pacing rate in Bytes per second to be used
* if pacing is enabled
*/
virtual folly::Expected<folly::Unit, LocalErrorCode> setMaxPacingRate(
uint64_t rateBytesPerSec) = 0;

/**
* Get stream priority.
*/
Expand Down Expand Up @@ -457,110 +378,6 @@ class QuicSocket : virtual public QuicSocketLite {
*/
virtual bool isDetachable() = 0;

/**
* Set a throttling signal provider
*/
virtual void setThrottlingSignalProvider(
std::shared_ptr<ThrottlingSignalProvider>) = 0;

using Observer = SocketObserverContainer::Observer;
using ManagedObserver = SocketObserverContainer::ManagedObserver;

/**
* Adds an observer.
*
* If the observer is already added, this is a no-op.
*
* @param observer Observer to add.
* @return Whether the observer was added (fails if no list).
*/
bool addObserver(Observer* observer) {
if (auto list = getSocketObserverContainer()) {
list->addObserver(observer);
return true;
}
return false;
}

/**
* Adds an observer.
*
* If the observer is already added, this is a no-op.
*
* @param observer Observer to add.
* @return Whether the observer was added (fails if no list).
*/
bool addObserver(std::shared_ptr<Observer> observer) {
if (auto list = getSocketObserverContainer()) {
list->addObserver(std::move(observer));
return true;
}
return false;
}

/**
* Removes an observer.
*
* @param observer Observer to remove.
* @return Whether the observer was found and removed.
*/
bool removeObserver(Observer* observer) {
if (auto list = getSocketObserverContainer()) {
return list->removeObserver(observer);
}
return false;
}

/**
* Removes an observer.
*
* @param observer Observer to remove.
* @return Whether the observer was found and removed.
*/
bool removeObserver(std::shared_ptr<Observer> observer) {
if (auto list = getSocketObserverContainer()) {
return list->removeObserver(std::move(observer));
}
return false;
}

/**
* Get number of observers.
*
* @return Number of observers.
*/
[[nodiscard]] size_t numObservers() const {
if (auto list = getSocketObserverContainer()) {
return list->numObservers();
}
return 0;
}

/**
* Returns list of attached observers.
*
* @return List of observers.
*/
std::vector<Observer*> getObservers() {
if (auto list = getSocketObserverContainer()) {
return list->getObservers();
}
return {};
}

/**
* Returns list of attached observers that are of type T.
*
* @return Attached observers of type T.
*/
template <typename T = Observer>
std::vector<T*> findObservers() {
if (auto list = getSocketObserverContainer()) {
return list->findObservers<T>();
}
return {};
}

/**
* ===== Datagram API =====
*
Expand Down
Loading

0 comments on commit 1cc00f7

Please sign in to comment.