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