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) { |
fayang | 3a58dc4 | 2020-06-29 11:27:14 -0700 | [diff] [blame] | 54 | return connection->idle_network_detector_.idle_network_timeout_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 91 | void QuicConnectionPeer::SwapCrypters(QuicConnection* connection, |
| 92 | QuicFramer* framer) { |
| 93 | QuicFramerPeer::SwapCrypters(framer, &connection->framer_); |
| 94 | } |
| 95 | |
| 96 | // static |
QUICHE team | 6dcf6ab | 2019-12-11 10:10:51 -0800 | [diff] [blame] | 97 | void QuicConnectionPeer::SetCurrentPacket( |
| 98 | QuicConnection* connection, |
| 99 | quiche::QuicheStringPiece current_packet) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 100 | connection->current_packet_data_ = current_packet.data(); |
| 101 | connection->last_size_ = current_packet.size(); |
| 102 | } |
| 103 | |
| 104 | // static |
| 105 | QuicConnectionHelperInterface* QuicConnectionPeer::GetHelper( |
| 106 | QuicConnection* connection) { |
| 107 | return connection->helper_; |
| 108 | } |
| 109 | |
| 110 | // static |
| 111 | QuicAlarmFactory* QuicConnectionPeer::GetAlarmFactory( |
| 112 | QuicConnection* connection) { |
| 113 | return connection->alarm_factory_; |
| 114 | } |
| 115 | |
| 116 | // static |
| 117 | QuicFramer* QuicConnectionPeer::GetFramer(QuicConnection* connection) { |
| 118 | return &connection->framer_; |
| 119 | } |
| 120 | |
| 121 | // static |
| 122 | QuicAlarm* QuicConnectionPeer::GetAckAlarm(QuicConnection* connection) { |
| 123 | return connection->ack_alarm_.get(); |
| 124 | } |
| 125 | |
| 126 | // static |
| 127 | QuicAlarm* QuicConnectionPeer::GetPingAlarm(QuicConnection* connection) { |
| 128 | return connection->ping_alarm_.get(); |
| 129 | } |
| 130 | |
| 131 | // static |
| 132 | QuicAlarm* QuicConnectionPeer::GetRetransmissionAlarm( |
| 133 | QuicConnection* connection) { |
| 134 | return connection->retransmission_alarm_.get(); |
| 135 | } |
| 136 | |
| 137 | // static |
| 138 | QuicAlarm* QuicConnectionPeer::GetSendAlarm(QuicConnection* connection) { |
| 139 | return connection->send_alarm_.get(); |
| 140 | } |
| 141 | |
| 142 | // static |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 143 | QuicAlarm* QuicConnectionPeer::GetMtuDiscoveryAlarm( |
| 144 | QuicConnection* connection) { |
| 145 | return connection->mtu_discovery_alarm_.get(); |
| 146 | } |
| 147 | |
| 148 | // static |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 149 | QuicAlarm* QuicConnectionPeer::GetProcessUndecryptablePacketsAlarm( |
| 150 | QuicConnection* connection) { |
| 151 | return connection->process_undecryptable_packets_alarm_.get(); |
| 152 | } |
| 153 | |
| 154 | // static |
| 155 | QuicPacketWriter* QuicConnectionPeer::GetWriter(QuicConnection* connection) { |
| 156 | return connection->writer_; |
| 157 | } |
| 158 | |
| 159 | // static |
| 160 | void QuicConnectionPeer::SetWriter(QuicConnection* connection, |
| 161 | QuicPacketWriter* writer, |
| 162 | bool owns_writer) { |
| 163 | if (connection->owns_writer_) { |
| 164 | delete connection->writer_; |
| 165 | } |
| 166 | connection->writer_ = writer; |
| 167 | connection->owns_writer_ = owns_writer; |
| 168 | } |
| 169 | |
| 170 | // static |
| 171 | void QuicConnectionPeer::TearDownLocalConnectionState( |
| 172 | QuicConnection* connection) { |
| 173 | connection->connected_ = false; |
| 174 | } |
| 175 | |
| 176 | // static |
| 177 | QuicEncryptedPacket* QuicConnectionPeer::GetConnectionClosePacket( |
| 178 | QuicConnection* connection) { |
| 179 | if (connection->termination_packets_ == nullptr || |
| 180 | connection->termination_packets_->empty()) { |
| 181 | return nullptr; |
| 182 | } |
| 183 | return (*connection->termination_packets_)[0].get(); |
| 184 | } |
| 185 | |
| 186 | // static |
| 187 | QuicPacketHeader* QuicConnectionPeer::GetLastHeader( |
| 188 | QuicConnection* connection) { |
| 189 | return &connection->last_header_; |
| 190 | } |
| 191 | |
| 192 | // static |
| 193 | QuicConnectionStats* QuicConnectionPeer::GetStats(QuicConnection* connection) { |
| 194 | return &connection->stats_; |
| 195 | } |
| 196 | |
| 197 | // static |
| 198 | QuicPacketCount QuicConnectionPeer::GetPacketsBetweenMtuProbes( |
| 199 | QuicConnection* connection) { |
wub | 173916e | 2019-11-27 14:36:24 -0800 | [diff] [blame] | 200 | return connection->mtu_discoverer_.packets_between_probes(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | // static |
wub | f76cf2a | 2019-10-11 18:49:07 -0700 | [diff] [blame] | 204 | void QuicConnectionPeer::ReInitializeMtuDiscoverer( |
| 205 | QuicConnection* connection, |
| 206 | QuicPacketCount packets_between_probes_base, |
| 207 | QuicPacketNumber next_probe_at) { |
| 208 | connection->mtu_discoverer_ = |
| 209 | QuicConnectionMtuDiscoverer(packets_between_probes_base, next_probe_at); |
| 210 | } |
| 211 | |
| 212 | // static |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 213 | void QuicConnectionPeer::SetAckMode(QuicConnection* connection, |
| 214 | AckMode ack_mode) { |
fayang | 5f46430 | 2019-06-20 12:57:33 -0700 | [diff] [blame] | 215 | for (auto& received_packet_manager : |
| 216 | connection->uber_received_packet_manager_.received_packet_managers_) { |
| 217 | received_packet_manager.ack_mode_ = ack_mode; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
| 221 | // static |
| 222 | void QuicConnectionPeer::SetFastAckAfterQuiescence( |
| 223 | QuicConnection* connection, |
| 224 | bool fast_ack_after_quiescence) { |
fayang | 5f46430 | 2019-06-20 12:57:33 -0700 | [diff] [blame] | 225 | for (auto& received_packet_manager : |
| 226 | connection->uber_received_packet_manager_.received_packet_managers_) { |
| 227 | received_packet_manager.fast_ack_after_quiescence_ = |
fayang | f477f73 | 2019-06-20 07:03:06 -0700 | [diff] [blame] | 228 | fast_ack_after_quiescence; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
| 232 | // static |
| 233 | void QuicConnectionPeer::SetAckDecimationDelay(QuicConnection* connection, |
| 234 | float ack_decimation_delay) { |
fayang | 5f46430 | 2019-06-20 12:57:33 -0700 | [diff] [blame] | 235 | for (auto& received_packet_manager : |
| 236 | connection->uber_received_packet_manager_.received_packet_managers_) { |
| 237 | received_packet_manager.ack_decimation_delay_ = ack_decimation_delay; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
| 241 | // static |
| 242 | bool QuicConnectionPeer::HasRetransmittableFrames(QuicConnection* connection, |
| 243 | uint64_t packet_number) { |
| 244 | return QuicSentPacketManagerPeer::HasRetransmittableFrames( |
| 245 | GetSentPacketManager(connection), packet_number); |
| 246 | } |
| 247 | |
| 248 | // static |
| 249 | bool QuicConnectionPeer::GetNoStopWaitingFrames(QuicConnection* connection) { |
| 250 | return connection->no_stop_waiting_frames_; |
| 251 | } |
| 252 | |
| 253 | // static |
| 254 | void QuicConnectionPeer::SetNoStopWaitingFrames(QuicConnection* connection, |
| 255 | bool no_stop_waiting_frames) { |
| 256 | connection->no_stop_waiting_frames_ = no_stop_waiting_frames; |
| 257 | } |
| 258 | |
| 259 | // static |
| 260 | void QuicConnectionPeer::SetMaxTrackedPackets( |
| 261 | QuicConnection* connection, |
| 262 | QuicPacketCount max_tracked_packets) { |
| 263 | connection->max_tracked_packets_ = max_tracked_packets; |
| 264 | } |
| 265 | |
| 266 | // static |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 267 | void QuicConnectionPeer::SetNegotiatedVersion(QuicConnection* connection) { |
fayang | 8aba1ff | 2019-06-21 12:00:54 -0700 | [diff] [blame] | 268 | connection->version_negotiated_ = true; |
wub | 256b2d6 | 2019-11-25 08:46:55 -0800 | [diff] [blame] | 269 | if (connection->perspective() == Perspective::IS_SERVER && |
| 270 | !QuicFramerPeer::infer_packet_header_type_from_version( |
| 271 | &connection->framer_)) { |
| 272 | connection->framer_.InferPacketHeaderTypeFromVersion(); |
| 273 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | // static |
| 277 | void QuicConnectionPeer::SetMaxConsecutiveNumPacketsWithNoRetransmittableFrames( |
| 278 | QuicConnection* connection, |
| 279 | size_t new_value) { |
| 280 | connection->max_consecutive_num_packets_with_no_retransmittable_frames_ = |
| 281 | new_value; |
| 282 | } |
| 283 | |
| 284 | // static |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 285 | bool QuicConnectionPeer::SupportsReleaseTime(QuicConnection* connection) { |
| 286 | return connection->supports_release_time_; |
| 287 | } |
| 288 | |
| 289 | // static |
| 290 | QuicConnection::PacketContent QuicConnectionPeer::GetCurrentPacketContent( |
| 291 | QuicConnection* connection) { |
| 292 | return connection->current_packet_content_; |
| 293 | } |
| 294 | |
QUICHE team | 8c1daa2 | 2019-03-13 08:33:41 -0700 | [diff] [blame] | 295 | // static |
| 296 | void QuicConnectionPeer::SetLastHeaderFormat(QuicConnection* connection, |
| 297 | PacketHeaderFormat format) { |
| 298 | connection->last_header_.form = format; |
| 299 | } |
| 300 | |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 301 | // static |
| 302 | void QuicConnectionPeer::AddBytesReceived(QuicConnection* connection, |
| 303 | size_t length) { |
| 304 | if (connection->EnforceAntiAmplificationLimit()) { |
| 305 | connection->bytes_received_before_address_validation_ += length; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | // static |
| 310 | void QuicConnectionPeer::SetAddressValidated(QuicConnection* connection) { |
| 311 | connection->address_validated_ = true; |
| 312 | } |
| 313 | |
dschinazi | dce90b0 | 2019-10-14 18:19:54 -0700 | [diff] [blame] | 314 | // static |
| 315 | void QuicConnectionPeer::SendConnectionClosePacket(QuicConnection* connection, |
| 316 | QuicErrorCode error, |
| 317 | const std::string& details) { |
| 318 | connection->SendConnectionClosePacket(error, details); |
| 319 | } |
| 320 | |
rch | d672c6d | 2019-11-27 15:30:54 -0800 | [diff] [blame] | 321 | // static |
| 322 | size_t QuicConnectionPeer::GetNumEncryptionLevels(QuicConnection* connection) { |
| 323 | size_t count = 0; |
| 324 | for (EncryptionLevel level : |
| 325 | {ENCRYPTION_INITIAL, ENCRYPTION_HANDSHAKE, ENCRYPTION_ZERO_RTT, |
| 326 | ENCRYPTION_FORWARD_SECURE}) { |
| 327 | if (connection->framer_.HasEncrypterOfEncryptionLevel(level)) { |
| 328 | ++count; |
| 329 | } |
| 330 | } |
| 331 | return count; |
| 332 | } |
| 333 | |
fayang | b59c6f1 | 2020-03-23 15:06:14 -0700 | [diff] [blame] | 334 | // static |
| 335 | QuicNetworkBlackholeDetector& QuicConnectionPeer::GetBlackholeDetector( |
| 336 | QuicConnection* connection) { |
| 337 | return connection->blackhole_detector_; |
| 338 | } |
| 339 | |
| 340 | // static |
| 341 | QuicAlarm* QuicConnectionPeer::GetBlackholeDetectorAlarm( |
| 342 | QuicConnection* connection) { |
| 343 | return connection->blackhole_detector_.alarm_.get(); |
| 344 | } |
| 345 | |
| 346 | // static |
| 347 | QuicTime QuicConnectionPeer::GetPathDegradingDeadline( |
| 348 | QuicConnection* connection) { |
| 349 | return connection->blackhole_detector_.path_degrading_deadline_; |
| 350 | } |
| 351 | |
| 352 | // static |
| 353 | QuicTime QuicConnectionPeer::GetBlackholeDetectionDeadline( |
| 354 | QuicConnection* connection) { |
| 355 | return connection->blackhole_detector_.blackhole_deadline_; |
| 356 | } |
| 357 | |
fayang | b9c8844 | 2020-03-26 07:03:57 -0700 | [diff] [blame] | 358 | // static |
wub | 8add68a | 2020-07-27 12:07:38 -0700 | [diff] [blame] | 359 | QuicTime QuicConnectionPeer::GetPathMtuReductionDetectionDeadline( |
| 360 | QuicConnection* connection) { |
| 361 | return connection->blackhole_detector_.path_mtu_reduction_deadline_; |
| 362 | } |
| 363 | |
| 364 | // static |
fayang | 001c828 | 2020-07-29 12:39:29 -0700 | [diff] [blame^] | 365 | QuicTime QuicConnectionPeer::GetIdleNetworkDeadline( |
| 366 | QuicConnection* connection) { |
| 367 | return connection->idle_network_detector_.GetIdleNetworkDeadline(); |
| 368 | } |
| 369 | |
| 370 | // static |
fayang | b9c8844 | 2020-03-26 07:03:57 -0700 | [diff] [blame] | 371 | QuicAlarm* QuicConnectionPeer::GetIdleNetworkDetectorAlarm( |
| 372 | QuicConnection* connection) { |
| 373 | return connection->idle_network_detector_.alarm_.get(); |
| 374 | } |
| 375 | |
dschinazi | 39e5e55 | 2020-05-06 13:55:24 -0700 | [diff] [blame] | 376 | // static |
fayang | 001c828 | 2020-07-29 12:39:29 -0700 | [diff] [blame^] | 377 | QuicIdleNetworkDetector& QuicConnectionPeer::GetIdleNetworkDetector( |
| 378 | QuicConnection* connection) { |
| 379 | return connection->idle_network_detector_; |
| 380 | } |
| 381 | |
| 382 | // static |
dschinazi | 39e5e55 | 2020-05-06 13:55:24 -0700 | [diff] [blame] | 383 | void QuicConnectionPeer::SetServerConnectionId( |
| 384 | QuicConnection* connection, |
| 385 | const QuicConnectionId& server_connection_id) { |
| 386 | connection->server_connection_id_ = server_connection_id; |
| 387 | connection->InstallInitialCrypters(server_connection_id); |
| 388 | } |
| 389 | |
fayang | 750b54f | 2020-06-18 06:26:54 -0700 | [diff] [blame] | 390 | // static |
| 391 | size_t QuicConnectionPeer::NumUndecryptablePackets(QuicConnection* connection) { |
| 392 | return connection->undecryptable_packets_.size(); |
| 393 | } |
| 394 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 395 | } // namespace test |
| 396 | } // namespace quic |