QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 | #include "net/third_party/quiche/src/quic/test_tools/quic_connection_peer.h" |
| 6 | |
| 7 | #include "net/third_party/quiche/src/quic/core/congestion_control/send_algorithm_interface.h" |
| 8 | #include "net/third_party/quiche/src/quic/core/quic_packet_writer.h" |
| 9 | #include "net/third_party/quiche/src/quic/core/quic_received_packet_manager.h" |
| 10 | #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" |
| 11 | #include "net/third_party/quiche/src/quic/test_tools/quic_framer_peer.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12 | #include "net/third_party/quiche/src/quic/test_tools/quic_sent_packet_manager_peer.h" |
QUICHE team | 6dcf6ab | 2019-12-11 10:10:51 -0800 | [diff] [blame] | 13 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 14 | |
| 15 | namespace quic { |
| 16 | namespace test { |
| 17 | |
| 18 | // static |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 19 | void QuicConnectionPeer::SetSendAlgorithm( |
| 20 | QuicConnection* connection, |
| 21 | SendAlgorithmInterface* send_algorithm) { |
| 22 | GetSentPacketManager(connection)->SetSendAlgorithm(send_algorithm); |
| 23 | } |
| 24 | |
| 25 | // static |
| 26 | void QuicConnectionPeer::SetLossAlgorithm( |
| 27 | QuicConnection* connection, |
| 28 | LossDetectionInterface* loss_algorithm) { |
| 29 | GetSentPacketManager(connection)->loss_algorithm_ = loss_algorithm; |
| 30 | } |
| 31 | |
| 32 | // static |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 33 | void QuicConnectionPeer::PopulateStopWaitingFrame( |
| 34 | QuicConnection* connection, |
| 35 | QuicStopWaitingFrame* stop_waiting) { |
| 36 | connection->PopulateStopWaitingFrame(stop_waiting); |
| 37 | } |
| 38 | |
| 39 | // static |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 40 | QuicPacketCreator* QuicConnectionPeer::GetPacketCreator( |
| 41 | QuicConnection* connection) { |
fayang | 4245c21 | 2019-11-05 13:33:46 -0800 | [diff] [blame] | 42 | return &connection->packet_creator_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | // static |
| 46 | QuicSentPacketManager* QuicConnectionPeer::GetSentPacketManager( |
| 47 | QuicConnection* connection) { |
| 48 | return &connection->sent_packet_manager_; |
| 49 | } |
| 50 | |
| 51 | // static |
| 52 | QuicTime::Delta QuicConnectionPeer::GetNetworkTimeout( |
| 53 | QuicConnection* connection) { |
| 54 | return connection->idle_network_timeout_; |
| 55 | } |
| 56 | |
| 57 | // static |
| 58 | void QuicConnectionPeer::SetPerspective(QuicConnection* connection, |
| 59 | Perspective perspective) { |
| 60 | connection->perspective_ = perspective; |
| 61 | QuicFramerPeer::SetPerspective(&connection->framer_, perspective); |
| 62 | } |
| 63 | |
| 64 | // static |
| 65 | void QuicConnectionPeer::SetSelfAddress(QuicConnection* connection, |
| 66 | const QuicSocketAddress& self_address) { |
| 67 | connection->self_address_ = self_address; |
| 68 | } |
| 69 | |
| 70 | // static |
| 71 | void QuicConnectionPeer::SetPeerAddress(QuicConnection* connection, |
| 72 | const QuicSocketAddress& peer_address) { |
| 73 | connection->peer_address_ = peer_address; |
| 74 | } |
| 75 | |
| 76 | // static |
| 77 | void QuicConnectionPeer::SetDirectPeerAddress( |
| 78 | QuicConnection* connection, |
| 79 | const QuicSocketAddress& direct_peer_address) { |
| 80 | connection->direct_peer_address_ = direct_peer_address; |
| 81 | } |
| 82 | |
| 83 | // static |
| 84 | void QuicConnectionPeer::SetEffectivePeerAddress( |
| 85 | QuicConnection* connection, |
| 86 | const QuicSocketAddress& effective_peer_address) { |
| 87 | connection->effective_peer_address_ = effective_peer_address; |
| 88 | } |
| 89 | |
| 90 | // static |
| 91 | bool QuicConnectionPeer::IsSilentCloseEnabled(QuicConnection* connection) { |
| 92 | return connection->idle_timeout_connection_close_behavior_ == |
| 93 | ConnectionCloseBehavior::SILENT_CLOSE; |
| 94 | } |
| 95 | |
| 96 | // static |
| 97 | void QuicConnectionPeer::SwapCrypters(QuicConnection* connection, |
| 98 | QuicFramer* framer) { |
| 99 | QuicFramerPeer::SwapCrypters(framer, &connection->framer_); |
| 100 | } |
| 101 | |
| 102 | // static |
QUICHE team | 6dcf6ab | 2019-12-11 10:10:51 -0800 | [diff] [blame] | 103 | void QuicConnectionPeer::SetCurrentPacket( |
| 104 | QuicConnection* connection, |
| 105 | quiche::QuicheStringPiece current_packet) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 106 | connection->current_packet_data_ = current_packet.data(); |
| 107 | connection->last_size_ = current_packet.size(); |
| 108 | } |
| 109 | |
| 110 | // static |
| 111 | QuicConnectionHelperInterface* QuicConnectionPeer::GetHelper( |
| 112 | QuicConnection* connection) { |
| 113 | return connection->helper_; |
| 114 | } |
| 115 | |
| 116 | // static |
| 117 | QuicAlarmFactory* QuicConnectionPeer::GetAlarmFactory( |
| 118 | QuicConnection* connection) { |
| 119 | return connection->alarm_factory_; |
| 120 | } |
| 121 | |
| 122 | // static |
| 123 | QuicFramer* QuicConnectionPeer::GetFramer(QuicConnection* connection) { |
| 124 | return &connection->framer_; |
| 125 | } |
| 126 | |
| 127 | // static |
| 128 | QuicAlarm* QuicConnectionPeer::GetAckAlarm(QuicConnection* connection) { |
| 129 | return connection->ack_alarm_.get(); |
| 130 | } |
| 131 | |
| 132 | // static |
| 133 | QuicAlarm* QuicConnectionPeer::GetPingAlarm(QuicConnection* connection) { |
| 134 | return connection->ping_alarm_.get(); |
| 135 | } |
| 136 | |
| 137 | // static |
| 138 | QuicAlarm* QuicConnectionPeer::GetRetransmissionAlarm( |
| 139 | QuicConnection* connection) { |
| 140 | return connection->retransmission_alarm_.get(); |
| 141 | } |
| 142 | |
| 143 | // static |
| 144 | QuicAlarm* QuicConnectionPeer::GetSendAlarm(QuicConnection* connection) { |
| 145 | return connection->send_alarm_.get(); |
| 146 | } |
| 147 | |
| 148 | // static |
| 149 | QuicAlarm* QuicConnectionPeer::GetTimeoutAlarm(QuicConnection* connection) { |
| 150 | return connection->timeout_alarm_.get(); |
| 151 | } |
| 152 | |
| 153 | // static |
| 154 | QuicAlarm* QuicConnectionPeer::GetMtuDiscoveryAlarm( |
| 155 | QuicConnection* connection) { |
| 156 | return connection->mtu_discovery_alarm_.get(); |
| 157 | } |
| 158 | |
| 159 | // static |
| 160 | QuicAlarm* QuicConnectionPeer::GetPathDegradingAlarm( |
| 161 | QuicConnection* connection) { |
| 162 | return connection->path_degrading_alarm_.get(); |
| 163 | } |
| 164 | |
| 165 | // static |
| 166 | QuicAlarm* QuicConnectionPeer::GetProcessUndecryptablePacketsAlarm( |
| 167 | QuicConnection* connection) { |
| 168 | return connection->process_undecryptable_packets_alarm_.get(); |
| 169 | } |
| 170 | |
| 171 | // static |
| 172 | QuicPacketWriter* QuicConnectionPeer::GetWriter(QuicConnection* connection) { |
| 173 | return connection->writer_; |
| 174 | } |
| 175 | |
| 176 | // static |
| 177 | void QuicConnectionPeer::SetWriter(QuicConnection* connection, |
| 178 | QuicPacketWriter* writer, |
| 179 | bool owns_writer) { |
| 180 | if (connection->owns_writer_) { |
| 181 | delete connection->writer_; |
| 182 | } |
| 183 | connection->writer_ = writer; |
| 184 | connection->owns_writer_ = owns_writer; |
| 185 | } |
| 186 | |
| 187 | // static |
| 188 | void QuicConnectionPeer::TearDownLocalConnectionState( |
| 189 | QuicConnection* connection) { |
| 190 | connection->connected_ = false; |
| 191 | } |
| 192 | |
| 193 | // static |
| 194 | QuicEncryptedPacket* QuicConnectionPeer::GetConnectionClosePacket( |
| 195 | QuicConnection* connection) { |
| 196 | if (connection->termination_packets_ == nullptr || |
| 197 | connection->termination_packets_->empty()) { |
| 198 | return nullptr; |
| 199 | } |
| 200 | return (*connection->termination_packets_)[0].get(); |
| 201 | } |
| 202 | |
| 203 | // static |
| 204 | QuicPacketHeader* QuicConnectionPeer::GetLastHeader( |
| 205 | QuicConnection* connection) { |
| 206 | return &connection->last_header_; |
| 207 | } |
| 208 | |
| 209 | // static |
| 210 | QuicConnectionStats* QuicConnectionPeer::GetStats(QuicConnection* connection) { |
| 211 | return &connection->stats_; |
| 212 | } |
| 213 | |
| 214 | // static |
| 215 | QuicPacketCount QuicConnectionPeer::GetPacketsBetweenMtuProbes( |
| 216 | QuicConnection* connection) { |
wub | 173916e | 2019-11-27 14:36:24 -0800 | [diff] [blame] | 217 | return connection->mtu_discoverer_.packets_between_probes(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | // static |
wub | f76cf2a | 2019-10-11 18:49:07 -0700 | [diff] [blame] | 221 | void QuicConnectionPeer::ReInitializeMtuDiscoverer( |
| 222 | QuicConnection* connection, |
| 223 | QuicPacketCount packets_between_probes_base, |
| 224 | QuicPacketNumber next_probe_at) { |
| 225 | connection->mtu_discoverer_ = |
| 226 | QuicConnectionMtuDiscoverer(packets_between_probes_base, next_probe_at); |
| 227 | } |
| 228 | |
| 229 | // static |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 230 | void QuicConnectionPeer::SetAckMode(QuicConnection* connection, |
| 231 | AckMode ack_mode) { |
fayang | 5f46430 | 2019-06-20 12:57:33 -0700 | [diff] [blame] | 232 | for (auto& received_packet_manager : |
| 233 | connection->uber_received_packet_manager_.received_packet_managers_) { |
| 234 | received_packet_manager.ack_mode_ = ack_mode; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
| 238 | // static |
| 239 | void QuicConnectionPeer::SetFastAckAfterQuiescence( |
| 240 | QuicConnection* connection, |
| 241 | bool fast_ack_after_quiescence) { |
fayang | 5f46430 | 2019-06-20 12:57:33 -0700 | [diff] [blame] | 242 | for (auto& received_packet_manager : |
| 243 | connection->uber_received_packet_manager_.received_packet_managers_) { |
| 244 | received_packet_manager.fast_ack_after_quiescence_ = |
fayang | f477f73 | 2019-06-20 07:03:06 -0700 | [diff] [blame] | 245 | fast_ack_after_quiescence; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
| 249 | // static |
| 250 | void QuicConnectionPeer::SetAckDecimationDelay(QuicConnection* connection, |
| 251 | float ack_decimation_delay) { |
fayang | 5f46430 | 2019-06-20 12:57:33 -0700 | [diff] [blame] | 252 | for (auto& received_packet_manager : |
| 253 | connection->uber_received_packet_manager_.received_packet_managers_) { |
| 254 | received_packet_manager.ack_decimation_delay_ = ack_decimation_delay; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
| 258 | // static |
| 259 | bool QuicConnectionPeer::HasRetransmittableFrames(QuicConnection* connection, |
| 260 | uint64_t packet_number) { |
| 261 | return QuicSentPacketManagerPeer::HasRetransmittableFrames( |
| 262 | GetSentPacketManager(connection), packet_number); |
| 263 | } |
| 264 | |
| 265 | // static |
| 266 | bool QuicConnectionPeer::GetNoStopWaitingFrames(QuicConnection* connection) { |
| 267 | return connection->no_stop_waiting_frames_; |
| 268 | } |
| 269 | |
| 270 | // static |
| 271 | void QuicConnectionPeer::SetNoStopWaitingFrames(QuicConnection* connection, |
| 272 | bool no_stop_waiting_frames) { |
| 273 | connection->no_stop_waiting_frames_ = no_stop_waiting_frames; |
| 274 | } |
| 275 | |
| 276 | // static |
| 277 | void QuicConnectionPeer::SetMaxTrackedPackets( |
| 278 | QuicConnection* connection, |
| 279 | QuicPacketCount max_tracked_packets) { |
| 280 | connection->max_tracked_packets_ = max_tracked_packets; |
| 281 | } |
| 282 | |
| 283 | // static |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 284 | void QuicConnectionPeer::SetNegotiatedVersion(QuicConnection* connection) { |
fayang | 8aba1ff | 2019-06-21 12:00:54 -0700 | [diff] [blame] | 285 | connection->version_negotiated_ = true; |
wub | 256b2d6 | 2019-11-25 08:46:55 -0800 | [diff] [blame] | 286 | if (connection->perspective() == Perspective::IS_SERVER && |
| 287 | !QuicFramerPeer::infer_packet_header_type_from_version( |
| 288 | &connection->framer_)) { |
| 289 | connection->framer_.InferPacketHeaderTypeFromVersion(); |
| 290 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | // static |
| 294 | void QuicConnectionPeer::SetMaxConsecutiveNumPacketsWithNoRetransmittableFrames( |
| 295 | QuicConnection* connection, |
| 296 | size_t new_value) { |
| 297 | connection->max_consecutive_num_packets_with_no_retransmittable_frames_ = |
| 298 | new_value; |
| 299 | } |
| 300 | |
| 301 | // static |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 302 | bool QuicConnectionPeer::SupportsReleaseTime(QuicConnection* connection) { |
| 303 | return connection->supports_release_time_; |
| 304 | } |
| 305 | |
| 306 | // static |
| 307 | QuicConnection::PacketContent QuicConnectionPeer::GetCurrentPacketContent( |
| 308 | QuicConnection* connection) { |
| 309 | return connection->current_packet_content_; |
| 310 | } |
| 311 | |
QUICHE team | 8c1daa2 | 2019-03-13 08:33:41 -0700 | [diff] [blame] | 312 | // static |
| 313 | void QuicConnectionPeer::SetLastHeaderFormat(QuicConnection* connection, |
| 314 | PacketHeaderFormat format) { |
| 315 | connection->last_header_.form = format; |
| 316 | } |
| 317 | |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 318 | // static |
| 319 | void QuicConnectionPeer::AddBytesReceived(QuicConnection* connection, |
| 320 | size_t length) { |
| 321 | if (connection->EnforceAntiAmplificationLimit()) { |
| 322 | connection->bytes_received_before_address_validation_ += length; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | // static |
| 327 | void QuicConnectionPeer::SetAddressValidated(QuicConnection* connection) { |
| 328 | connection->address_validated_ = true; |
| 329 | } |
| 330 | |
dschinazi | dce90b0 | 2019-10-14 18:19:54 -0700 | [diff] [blame] | 331 | // static |
| 332 | void QuicConnectionPeer::SendConnectionClosePacket(QuicConnection* connection, |
| 333 | QuicErrorCode error, |
| 334 | const std::string& details) { |
| 335 | connection->SendConnectionClosePacket(error, details); |
| 336 | } |
| 337 | |
rch | d672c6d | 2019-11-27 15:30:54 -0800 | [diff] [blame] | 338 | // static |
| 339 | size_t QuicConnectionPeer::GetNumEncryptionLevels(QuicConnection* connection) { |
| 340 | size_t count = 0; |
| 341 | for (EncryptionLevel level : |
| 342 | {ENCRYPTION_INITIAL, ENCRYPTION_HANDSHAKE, ENCRYPTION_ZERO_RTT, |
| 343 | ENCRYPTION_FORWARD_SECURE}) { |
| 344 | if (connection->framer_.HasEncrypterOfEncryptionLevel(level)) { |
| 345 | ++count; |
| 346 | } |
| 347 | } |
| 348 | return count; |
| 349 | } |
| 350 | |
fayang | b59c6f1 | 2020-03-23 15:06:14 -0700 | [diff] [blame^] | 351 | // static |
| 352 | QuicNetworkBlackholeDetector& QuicConnectionPeer::GetBlackholeDetector( |
| 353 | QuicConnection* connection) { |
| 354 | return connection->blackhole_detector_; |
| 355 | } |
| 356 | |
| 357 | // static |
| 358 | QuicAlarm* QuicConnectionPeer::GetBlackholeDetectorAlarm( |
| 359 | QuicConnection* connection) { |
| 360 | return connection->blackhole_detector_.alarm_.get(); |
| 361 | } |
| 362 | |
| 363 | // static |
| 364 | QuicTime QuicConnectionPeer::GetPathDegradingDeadline( |
| 365 | QuicConnection* connection) { |
| 366 | return connection->blackhole_detector_.path_degrading_deadline_; |
| 367 | } |
| 368 | |
| 369 | // static |
| 370 | QuicTime QuicConnectionPeer::GetBlackholeDetectionDeadline( |
| 371 | QuicConnection* connection) { |
| 372 | return connection->blackhole_detector_.blackhole_deadline_; |
| 373 | } |
| 374 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 375 | } // namespace test |
| 376 | } // namespace quic |