1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef QUICHE_QUIC_TEST_TOOLS_QUIC_CONNECTION_PEER_H_ 6 #define QUICHE_QUIC_TEST_TOOLS_QUIC_CONNECTION_PEER_H_ 7 8 #include <cstddef> 9 10 #include "absl/strings/string_view.h" 11 #include "quiche/quic/core/quic_connection.h" 12 #include "quiche/quic/core/quic_connection_id.h" 13 #include "quiche/quic/core/quic_connection_stats.h" 14 #include "quiche/quic/core/quic_packets.h" 15 #include "quiche/quic/core/quic_path_validator.h" 16 #include "quiche/quic/core/quic_types.h" 17 #include "quiche/quic/platform/api/quic_socket_address.h" 18 19 namespace quic { 20 21 struct QuicPacketHeader; 22 class QuicAlarm; 23 class QuicConnectionHelperInterface; 24 class QuicConnectionVisitorInterface; 25 class QuicEncryptedPacket; 26 class QuicFramer; 27 class QuicPacketCreator; 28 class QuicPacketWriter; 29 class QuicSentPacketManager; 30 class SendAlgorithmInterface; 31 32 namespace test { 33 34 // Peer to make public a number of otherwise private QuicConnection methods. 35 class QuicConnectionPeer { 36 public: 37 QuicConnectionPeer() = delete; 38 39 static void SetSendAlgorithm(QuicConnection* connection, 40 SendAlgorithmInterface* send_algorithm); 41 42 static void SetLossAlgorithm(QuicConnection* connection, 43 LossDetectionInterface* loss_algorithm); 44 45 static void PopulateStopWaitingFrame(QuicConnection* connection, 46 QuicStopWaitingFrame* stop_waiting); 47 48 static QuicPacketCreator* GetPacketCreator(QuicConnection* connection); 49 50 static QuicSentPacketManager* GetSentPacketManager( 51 QuicConnection* connection); 52 53 static QuicTime::Delta GetNetworkTimeout(QuicConnection* connection); 54 55 static QuicTime::Delta GetHandshakeTimeout(QuicConnection* connection); 56 57 static QuicTime::Delta GetBandwidthUpdateTimeout(QuicConnection* connection); 58 59 static void DisableBandwidthUpdate(QuicConnection* connection); 60 61 static void SetPerspective(QuicConnection* connection, 62 Perspective perspective); 63 64 static void SetSelfAddress(QuicConnection* connection, 65 const QuicSocketAddress& self_address); 66 67 static void SetPeerAddress(QuicConnection* connection, 68 const QuicSocketAddress& peer_address); 69 70 static void SetDirectPeerAddress( 71 QuicConnection* connection, const QuicSocketAddress& direct_peer_address); 72 73 static void SetEffectivePeerAddress( 74 QuicConnection* connection, 75 const QuicSocketAddress& effective_peer_address); 76 77 static void SwapCrypters(QuicConnection* connection, QuicFramer* framer); 78 79 static void SetCurrentPacket(QuicConnection* connection, 80 absl::string_view current_packet); 81 82 static QuicConnectionHelperInterface* GetHelper(QuicConnection* connection); 83 84 static QuicAlarmFactory* GetAlarmFactory(QuicConnection* connection); 85 86 static QuicFramer* GetFramer(QuicConnection* connection); 87 88 static QuicAlarm* GetAckAlarm(QuicConnection* connection); 89 static QuicAlarm* GetPingAlarm(QuicConnection* connection); 90 static QuicAlarm* GetRetransmissionAlarm(QuicConnection* connection); 91 static QuicAlarm* GetSendAlarm(QuicConnection* connection); 92 static QuicAlarm* GetMtuDiscoveryAlarm(QuicConnection* connection); 93 static QuicAlarm* GetProcessUndecryptablePacketsAlarm( 94 QuicConnection* connection); 95 static QuicAlarm* GetDiscardPreviousOneRttKeysAlarm( 96 QuicConnection* connection); 97 static QuicAlarm* GetDiscardZeroRttDecryptionKeysAlarm( 98 QuicConnection* connection); 99 static QuicAlarm* GetRetirePeerIssuedConnectionIdAlarm( 100 QuicConnection* connection); 101 static QuicAlarm* GetRetireSelfIssuedConnectionIdAlarm( 102 QuicConnection* connection); 103 104 static QuicPacketWriter* GetWriter(QuicConnection* connection); 105 // If |owns_writer| is true, takes ownership of |writer|. 106 static void SetWriter(QuicConnection* connection, QuicPacketWriter* writer, 107 bool owns_writer); 108 static void TearDownLocalConnectionState(QuicConnection* connection); 109 static QuicEncryptedPacket* GetConnectionClosePacket( 110 QuicConnection* connection); 111 112 static QuicPacketHeader* GetLastHeader(QuicConnection* connection); 113 114 static QuicConnectionStats* GetStats(QuicConnection* connection); 115 116 static QuicPacketCount GetPacketsBetweenMtuProbes(QuicConnection* connection); 117 118 static void ReInitializeMtuDiscoverer( 119 QuicConnection* connection, QuicPacketCount packets_between_probes_base, 120 QuicPacketNumber next_probe_at); 121 static void SetAckDecimationDelay(QuicConnection* connection, 122 float ack_decimation_delay); 123 static bool HasRetransmittableFrames(QuicConnection* connection, 124 uint64_t packet_number); 125 static bool GetNoStopWaitingFrames(QuicConnection* connection); 126 static void SetNoStopWaitingFrames(QuicConnection* connection, 127 bool no_stop_waiting_frames); 128 static void SetMaxTrackedPackets(QuicConnection* connection, 129 QuicPacketCount max_tracked_packets); 130 static void SetNegotiatedVersion(QuicConnection* connection); 131 static void SetMaxConsecutiveNumPacketsWithNoRetransmittableFrames( 132 QuicConnection* connection, size_t new_value); 133 static bool SupportsReleaseTime(QuicConnection* connection); 134 static QuicConnection::PacketContent GetCurrentPacketContent( 135 QuicConnection* connection); 136 static void AddBytesReceived(QuicConnection* connection, size_t length); 137 static void SetAddressValidated(QuicConnection* connection); 138 139 static void SendConnectionClosePacket(QuicConnection* connection, 140 QuicIetfTransportErrorCodes ietf_error, 141 QuicErrorCode error, 142 const std::string& details); 143 144 static size_t GetNumEncryptionLevels(QuicConnection* connection); 145 146 static QuicNetworkBlackholeDetector& GetBlackholeDetector( 147 QuicConnection* connection); 148 149 static QuicAlarm* GetBlackholeDetectorAlarm(QuicConnection* connection); 150 151 static QuicTime GetPathDegradingDeadline(QuicConnection* connection); 152 153 static QuicTime GetBlackholeDetectionDeadline(QuicConnection* connection); 154 155 static QuicTime GetPathMtuReductionDetectionDeadline( 156 QuicConnection* connection); 157 158 static QuicAlarm* GetIdleNetworkDetectorAlarm(QuicConnection* connection); 159 160 static QuicTime GetIdleNetworkDeadline(QuicConnection* connection); 161 162 static QuicIdleNetworkDetector& GetIdleNetworkDetector( 163 QuicConnection* connection); 164 165 static void SetServerConnectionId( 166 QuicConnection* connection, const QuicConnectionId& server_connection_id); 167 168 static size_t NumUndecryptablePackets(QuicConnection* connection); 169 170 static void SetConnectionClose(QuicConnection* connection); 171 172 static void SendPing(QuicConnection* connection); 173 174 static void SetLastPacketDestinationAddress(QuicConnection* connection, 175 const QuicSocketAddress& address); 176 177 static QuicPathValidator* path_validator(QuicConnection* connection); 178 179 static QuicByteCount BytesReceivedOnDefaultPath(QuicConnection* connection); 180 181 static QuicByteCount BytesSentOnAlternativePath(QuicConnection* connection); 182 183 static QuicByteCount BytesReceivedOnAlternativePath( 184 QuicConnection* connection); 185 186 static QuicConnectionId GetClientConnectionIdOnAlternativePath( 187 const QuicConnection* connection); 188 189 static QuicConnectionId GetServerConnectionIdOnAlternativePath( 190 const QuicConnection* connection); 191 192 static bool IsAlternativePath(QuicConnection* connection, 193 const QuicSocketAddress& self_address, 194 const QuicSocketAddress& peer_address); 195 196 static bool IsAlternativePathValidated(QuicConnection* connection); 197 198 static QuicByteCount BytesReceivedBeforeAddressValidation( 199 QuicConnection* connection); 200 201 static void ResetPeerIssuedConnectionIdManager(QuicConnection* connection); 202 203 static QuicConnection::PathState* GetDefaultPath(QuicConnection* connection); 204 205 static bool IsDefaultPath(QuicConnection* connection, 206 const QuicSocketAddress& self_address, 207 const QuicSocketAddress& peer_address); 208 209 static QuicConnection::PathState* GetAlternativePath( 210 QuicConnection* connection); 211 212 static void RetirePeerIssuedConnectionIdsNoLongerOnPath( 213 QuicConnection* connection); 214 215 static bool HasUnusedPeerIssuedConnectionId(const QuicConnection* connection); 216 217 static bool HasSelfIssuedConnectionIdToConsume( 218 const QuicConnection* connection); 219 220 static QuicSelfIssuedConnectionIdManager* GetSelfIssuedConnectionIdManager( 221 QuicConnection* connection); 222 223 static std::unique_ptr<QuicSelfIssuedConnectionIdManager> 224 MakeSelfIssuedConnectionIdManager(QuicConnection* connection); 225 226 static void SetLastDecryptedLevel(QuicConnection* connection, 227 EncryptionLevel level); 228 229 static QuicCoalescedPacket& GetCoalescedPacket(QuicConnection* connection); 230 231 static void FlushCoalescedPacket(QuicConnection* connection); 232 233 static QuicAlarm* GetMultiPortProbingAlarm(QuicConnection* connection); 234 235 static void SetInProbeTimeOut(QuicConnection* connection, bool value); 236 237 static QuicSocketAddress GetReceivedServerPreferredAddress( 238 QuicConnection* connection); 239 240 static QuicSocketAddress GetSentServerPreferredAddress( 241 QuicConnection* connection); 242 243 static bool TestLastReceivedPacketInfoDefaults(); 244 245 // Overrides restrictions on sending ECN for test purposes. 246 static void DisableEcnCodepointValidation(QuicConnection* connection); 247 }; 248 249 } // namespace test 250 251 } // namespace quic 252 253 #endif // QUICHE_QUIC_TEST_TOOLS_QUIC_CONNECTION_PEER_H_ 254