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