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 "quiche/quic/test_tools/quic_connection_peer.h"
6
7 #include "absl/strings/string_view.h"
8 #include "quiche/quic/core/congestion_control/send_algorithm_interface.h"
9 #include "quiche/quic/core/quic_packet_writer.h"
10 #include "quiche/quic/core/quic_received_packet_manager.h"
11 #include "quiche/quic/platform/api/quic_flags.h"
12 #include "quiche/quic/platform/api/quic_socket_address.h"
13 #include "quiche/quic/test_tools/quic_connection_id_manager_peer.h"
14 #include "quiche/quic/test_tools/quic_framer_peer.h"
15 #include "quiche/quic/test_tools/quic_sent_packet_manager_peer.h"
16
17 namespace quic {
18 namespace test {
19
20 // static
SetSendAlgorithm(QuicConnection * connection,SendAlgorithmInterface * send_algorithm)21 void QuicConnectionPeer::SetSendAlgorithm(
22 QuicConnection* connection, SendAlgorithmInterface* send_algorithm) {
23 GetSentPacketManager(connection)->SetSendAlgorithm(send_algorithm);
24 }
25
26 // static
SetLossAlgorithm(QuicConnection * connection,LossDetectionInterface * loss_algorithm)27 void QuicConnectionPeer::SetLossAlgorithm(
28 QuicConnection* connection, LossDetectionInterface* loss_algorithm) {
29 GetSentPacketManager(connection)->loss_algorithm_ = loss_algorithm;
30 }
31
32 // static
PopulateStopWaitingFrame(QuicConnection * connection,QuicStopWaitingFrame * stop_waiting)33 void QuicConnectionPeer::PopulateStopWaitingFrame(
34 QuicConnection* connection, QuicStopWaitingFrame* stop_waiting) {
35 connection->PopulateStopWaitingFrame(stop_waiting);
36 }
37
38 // static
GetPacketCreator(QuicConnection * connection)39 QuicPacketCreator* QuicConnectionPeer::GetPacketCreator(
40 QuicConnection* connection) {
41 return &connection->packet_creator_;
42 }
43
44 // static
GetSentPacketManager(QuicConnection * connection)45 QuicSentPacketManager* QuicConnectionPeer::GetSentPacketManager(
46 QuicConnection* connection) {
47 return &connection->sent_packet_manager_;
48 }
49
50 // static
GetNetworkTimeout(QuicConnection * connection)51 QuicTime::Delta QuicConnectionPeer::GetNetworkTimeout(
52 QuicConnection* connection) {
53 return connection->idle_network_detector_.idle_network_timeout_;
54 }
55
56 // static
GetHandshakeTimeout(QuicConnection * connection)57 QuicTime::Delta QuicConnectionPeer::GetHandshakeTimeout(
58 QuicConnection* connection) {
59 return connection->idle_network_detector_.handshake_timeout_;
60 }
61
62 // static
GetBandwidthUpdateTimeout(QuicConnection * connection)63 QuicTime::Delta QuicConnectionPeer::GetBandwidthUpdateTimeout(
64 QuicConnection* connection) {
65 return connection->idle_network_detector_.bandwidth_update_timeout_;
66 }
67
68 // static
DisableBandwidthUpdate(QuicConnection * connection)69 void QuicConnectionPeer::DisableBandwidthUpdate(QuicConnection* connection) {
70 if (connection->idle_network_detector_.bandwidth_update_timeout_
71 .IsInfinite()) {
72 return;
73 }
74 connection->idle_network_detector_.bandwidth_update_timeout_ =
75 QuicTime::Delta::Infinite();
76 connection->idle_network_detector_.SetAlarm();
77 }
78
79 // static
SetPerspective(QuicConnection * connection,Perspective perspective)80 void QuicConnectionPeer::SetPerspective(QuicConnection* connection,
81 Perspective perspective) {
82 connection->perspective_ = perspective;
83 QuicFramerPeer::SetPerspective(&connection->framer_, perspective);
84 connection->ping_manager_.perspective_ = perspective;
85 }
86
87 // static
SetSelfAddress(QuicConnection * connection,const QuicSocketAddress & self_address)88 void QuicConnectionPeer::SetSelfAddress(QuicConnection* connection,
89 const QuicSocketAddress& self_address) {
90 connection->default_path_.self_address = self_address;
91 }
92
93 // static
SetPeerAddress(QuicConnection * connection,const QuicSocketAddress & peer_address)94 void QuicConnectionPeer::SetPeerAddress(QuicConnection* connection,
95 const QuicSocketAddress& peer_address) {
96 connection->UpdatePeerAddress(peer_address);
97 }
98
99 // static
SetDirectPeerAddress(QuicConnection * connection,const QuicSocketAddress & direct_peer_address)100 void QuicConnectionPeer::SetDirectPeerAddress(
101 QuicConnection* connection, const QuicSocketAddress& direct_peer_address) {
102 connection->direct_peer_address_ = direct_peer_address;
103 }
104
105 // static
SetEffectivePeerAddress(QuicConnection * connection,const QuicSocketAddress & effective_peer_address)106 void QuicConnectionPeer::SetEffectivePeerAddress(
107 QuicConnection* connection,
108 const QuicSocketAddress& effective_peer_address) {
109 connection->default_path_.peer_address = effective_peer_address;
110 }
111
112 // static
SwapCrypters(QuicConnection * connection,QuicFramer * framer)113 void QuicConnectionPeer::SwapCrypters(QuicConnection* connection,
114 QuicFramer* framer) {
115 QuicFramerPeer::SwapCrypters(framer, &connection->framer_);
116 }
117
118 // static
SetCurrentPacket(QuicConnection * connection,absl::string_view current_packet)119 void QuicConnectionPeer::SetCurrentPacket(QuicConnection* connection,
120 absl::string_view current_packet) {
121 connection->current_packet_data_ = current_packet.data();
122 connection->last_received_packet_info_.length = current_packet.size();
123 }
124
125 // static
GetHelper(QuicConnection * connection)126 QuicConnectionHelperInterface* QuicConnectionPeer::GetHelper(
127 QuicConnection* connection) {
128 return connection->helper_;
129 }
130
131 // static
GetAlarmFactory(QuicConnection * connection)132 QuicAlarmFactory* QuicConnectionPeer::GetAlarmFactory(
133 QuicConnection* connection) {
134 return connection->alarm_factory_;
135 }
136
137 // static
GetFramer(QuicConnection * connection)138 QuicFramer* QuicConnectionPeer::GetFramer(QuicConnection* connection) {
139 return &connection->framer_;
140 }
141
142 // static
GetAckAlarm(QuicConnection * connection)143 QuicAlarm* QuicConnectionPeer::GetAckAlarm(QuicConnection* connection) {
144 return connection->ack_alarm_.get();
145 }
146
147 // static
GetPingAlarm(QuicConnection * connection)148 QuicAlarm* QuicConnectionPeer::GetPingAlarm(QuicConnection* connection) {
149 return connection->ping_manager_.alarm_.get();
150 }
151
152 // static
GetRetransmissionAlarm(QuicConnection * connection)153 QuicAlarm* QuicConnectionPeer::GetRetransmissionAlarm(
154 QuicConnection* connection) {
155 return connection->retransmission_alarm_.get();
156 }
157
158 // static
GetSendAlarm(QuicConnection * connection)159 QuicAlarm* QuicConnectionPeer::GetSendAlarm(QuicConnection* connection) {
160 return connection->send_alarm_.get();
161 }
162
163 // static
GetMtuDiscoveryAlarm(QuicConnection * connection)164 QuicAlarm* QuicConnectionPeer::GetMtuDiscoveryAlarm(
165 QuicConnection* connection) {
166 return connection->mtu_discovery_alarm_.get();
167 }
168
169 // static
GetProcessUndecryptablePacketsAlarm(QuicConnection * connection)170 QuicAlarm* QuicConnectionPeer::GetProcessUndecryptablePacketsAlarm(
171 QuicConnection* connection) {
172 return connection->process_undecryptable_packets_alarm_.get();
173 }
174
175 // static
GetDiscardPreviousOneRttKeysAlarm(QuicConnection * connection)176 QuicAlarm* QuicConnectionPeer::GetDiscardPreviousOneRttKeysAlarm(
177 QuicConnection* connection) {
178 return connection->discard_previous_one_rtt_keys_alarm_.get();
179 }
180
181 // static
GetDiscardZeroRttDecryptionKeysAlarm(QuicConnection * connection)182 QuicAlarm* QuicConnectionPeer::GetDiscardZeroRttDecryptionKeysAlarm(
183 QuicConnection* connection) {
184 return connection->discard_zero_rtt_decryption_keys_alarm_.get();
185 }
186
187 // static
GetRetirePeerIssuedConnectionIdAlarm(QuicConnection * connection)188 QuicAlarm* QuicConnectionPeer::GetRetirePeerIssuedConnectionIdAlarm(
189 QuicConnection* connection) {
190 if (connection->peer_issued_cid_manager_ == nullptr) {
191 return nullptr;
192 }
193 return QuicConnectionIdManagerPeer::GetRetirePeerIssuedConnectionIdAlarm(
194 connection->peer_issued_cid_manager_.get());
195 }
196 // static
GetRetireSelfIssuedConnectionIdAlarm(QuicConnection * connection)197 QuicAlarm* QuicConnectionPeer::GetRetireSelfIssuedConnectionIdAlarm(
198 QuicConnection* connection) {
199 if (connection->self_issued_cid_manager_ == nullptr) {
200 return nullptr;
201 }
202 return QuicConnectionIdManagerPeer::GetRetireSelfIssuedConnectionIdAlarm(
203 connection->self_issued_cid_manager_.get());
204 }
205
206 // static
GetWriter(QuicConnection * connection)207 QuicPacketWriter* QuicConnectionPeer::GetWriter(QuicConnection* connection) {
208 return connection->writer_;
209 }
210
211 // static
SetWriter(QuicConnection * connection,QuicPacketWriter * writer,bool owns_writer)212 void QuicConnectionPeer::SetWriter(QuicConnection* connection,
213 QuicPacketWriter* writer, bool owns_writer) {
214 if (connection->owns_writer_) {
215 delete connection->writer_;
216 }
217 connection->writer_ = writer;
218 connection->owns_writer_ = owns_writer;
219 }
220
221 // static
TearDownLocalConnectionState(QuicConnection * connection)222 void QuicConnectionPeer::TearDownLocalConnectionState(
223 QuicConnection* connection) {
224 connection->connected_ = false;
225 }
226
227 // static
GetConnectionClosePacket(QuicConnection * connection)228 QuicEncryptedPacket* QuicConnectionPeer::GetConnectionClosePacket(
229 QuicConnection* connection) {
230 if (connection->termination_packets_ == nullptr ||
231 connection->termination_packets_->empty()) {
232 return nullptr;
233 }
234 return (*connection->termination_packets_)[0].get();
235 }
236
237 // static
GetLastHeader(QuicConnection * connection)238 QuicPacketHeader* QuicConnectionPeer::GetLastHeader(
239 QuicConnection* connection) {
240 return &connection->last_received_packet_info_.header;
241 }
242
243 // static
GetStats(QuicConnection * connection)244 QuicConnectionStats* QuicConnectionPeer::GetStats(QuicConnection* connection) {
245 return &connection->stats_;
246 }
247
248 // static
GetPacketsBetweenMtuProbes(QuicConnection * connection)249 QuicPacketCount QuicConnectionPeer::GetPacketsBetweenMtuProbes(
250 QuicConnection* connection) {
251 return connection->mtu_discoverer_.packets_between_probes();
252 }
253
254 // static
ReInitializeMtuDiscoverer(QuicConnection * connection,QuicPacketCount packets_between_probes_base,QuicPacketNumber next_probe_at)255 void QuicConnectionPeer::ReInitializeMtuDiscoverer(
256 QuicConnection* connection, QuicPacketCount packets_between_probes_base,
257 QuicPacketNumber next_probe_at) {
258 connection->mtu_discoverer_ =
259 QuicConnectionMtuDiscoverer(packets_between_probes_base, next_probe_at);
260 }
261
262 // static
SetAckDecimationDelay(QuicConnection * connection,float ack_decimation_delay)263 void QuicConnectionPeer::SetAckDecimationDelay(QuicConnection* connection,
264 float ack_decimation_delay) {
265 for (auto& received_packet_manager :
266 connection->uber_received_packet_manager_.received_packet_managers_) {
267 received_packet_manager.ack_decimation_delay_ = ack_decimation_delay;
268 }
269 }
270
271 // static
HasRetransmittableFrames(QuicConnection * connection,uint64_t packet_number)272 bool QuicConnectionPeer::HasRetransmittableFrames(QuicConnection* connection,
273 uint64_t packet_number) {
274 return QuicSentPacketManagerPeer::HasRetransmittableFrames(
275 GetSentPacketManager(connection), packet_number);
276 }
277
278 // static
GetNoStopWaitingFrames(QuicConnection * connection)279 bool QuicConnectionPeer::GetNoStopWaitingFrames(QuicConnection* connection) {
280 return connection->no_stop_waiting_frames_;
281 }
282
283 // static
SetNoStopWaitingFrames(QuicConnection * connection,bool no_stop_waiting_frames)284 void QuicConnectionPeer::SetNoStopWaitingFrames(QuicConnection* connection,
285 bool no_stop_waiting_frames) {
286 connection->no_stop_waiting_frames_ = no_stop_waiting_frames;
287 }
288
289 // static
SetMaxTrackedPackets(QuicConnection * connection,QuicPacketCount max_tracked_packets)290 void QuicConnectionPeer::SetMaxTrackedPackets(
291 QuicConnection* connection, QuicPacketCount max_tracked_packets) {
292 connection->max_tracked_packets_ = max_tracked_packets;
293 }
294
295 // static
SetNegotiatedVersion(QuicConnection * connection)296 void QuicConnectionPeer::SetNegotiatedVersion(QuicConnection* connection) {
297 connection->version_negotiated_ = true;
298 if (connection->perspective() == Perspective::IS_SERVER &&
299 !QuicFramerPeer::infer_packet_header_type_from_version(
300 &connection->framer_)) {
301 connection->framer_.InferPacketHeaderTypeFromVersion();
302 }
303 }
304
305 // static
SetMaxConsecutiveNumPacketsWithNoRetransmittableFrames(QuicConnection * connection,size_t new_value)306 void QuicConnectionPeer::SetMaxConsecutiveNumPacketsWithNoRetransmittableFrames(
307 QuicConnection* connection, size_t new_value) {
308 connection->max_consecutive_num_packets_with_no_retransmittable_frames_ =
309 new_value;
310 }
311
312 // static
SupportsReleaseTime(QuicConnection * connection)313 bool QuicConnectionPeer::SupportsReleaseTime(QuicConnection* connection) {
314 return connection->supports_release_time_;
315 }
316
317 // static
GetCurrentPacketContent(QuicConnection * connection)318 QuicConnection::PacketContent QuicConnectionPeer::GetCurrentPacketContent(
319 QuicConnection* connection) {
320 return connection->current_packet_content_;
321 }
322
323 // static
AddBytesReceived(QuicConnection * connection,size_t length)324 void QuicConnectionPeer::AddBytesReceived(QuicConnection* connection,
325 size_t length) {
326 if (connection->EnforceAntiAmplificationLimit()) {
327 connection->default_path_.bytes_received_before_address_validation +=
328 length;
329 }
330 }
331
332 // static
SetAddressValidated(QuicConnection * connection)333 void QuicConnectionPeer::SetAddressValidated(QuicConnection* connection) {
334 connection->default_path_.validated = true;
335 }
336
337 // static
SendConnectionClosePacket(QuicConnection * connection,QuicIetfTransportErrorCodes ietf_error,QuicErrorCode error,const std::string & details)338 void QuicConnectionPeer::SendConnectionClosePacket(
339 QuicConnection* connection, QuicIetfTransportErrorCodes ietf_error,
340 QuicErrorCode error, const std::string& details) {
341 connection->SendConnectionClosePacket(error, ietf_error, details);
342 }
343
344 // static
GetNumEncryptionLevels(QuicConnection * connection)345 size_t QuicConnectionPeer::GetNumEncryptionLevels(QuicConnection* connection) {
346 size_t count = 0;
347 for (EncryptionLevel level :
348 {ENCRYPTION_INITIAL, ENCRYPTION_HANDSHAKE, ENCRYPTION_ZERO_RTT,
349 ENCRYPTION_FORWARD_SECURE}) {
350 if (connection->framer_.HasEncrypterOfEncryptionLevel(level)) {
351 ++count;
352 }
353 }
354 return count;
355 }
356
357 // static
GetBlackholeDetector(QuicConnection * connection)358 QuicNetworkBlackholeDetector& QuicConnectionPeer::GetBlackholeDetector(
359 QuicConnection* connection) {
360 return connection->blackhole_detector_;
361 }
362
363 // static
GetBlackholeDetectorAlarm(QuicConnection * connection)364 QuicAlarm* QuicConnectionPeer::GetBlackholeDetectorAlarm(
365 QuicConnection* connection) {
366 return connection->blackhole_detector_.alarm_.get();
367 }
368
369 // static
GetPathDegradingDeadline(QuicConnection * connection)370 QuicTime QuicConnectionPeer::GetPathDegradingDeadline(
371 QuicConnection* connection) {
372 return connection->blackhole_detector_.path_degrading_deadline_;
373 }
374
375 // static
GetBlackholeDetectionDeadline(QuicConnection * connection)376 QuicTime QuicConnectionPeer::GetBlackholeDetectionDeadline(
377 QuicConnection* connection) {
378 return connection->blackhole_detector_.blackhole_deadline_;
379 }
380
381 // static
GetPathMtuReductionDetectionDeadline(QuicConnection * connection)382 QuicTime QuicConnectionPeer::GetPathMtuReductionDetectionDeadline(
383 QuicConnection* connection) {
384 return connection->blackhole_detector_.path_mtu_reduction_deadline_;
385 }
386
387 // static
GetIdleNetworkDeadline(QuicConnection * connection)388 QuicTime QuicConnectionPeer::GetIdleNetworkDeadline(
389 QuicConnection* connection) {
390 return connection->idle_network_detector_.GetIdleNetworkDeadline();
391 }
392
393 // static
GetIdleNetworkDetectorAlarm(QuicConnection * connection)394 QuicAlarm* QuicConnectionPeer::GetIdleNetworkDetectorAlarm(
395 QuicConnection* connection) {
396 return connection->idle_network_detector_.alarm_.get();
397 }
398
399 // static
GetIdleNetworkDetector(QuicConnection * connection)400 QuicIdleNetworkDetector& QuicConnectionPeer::GetIdleNetworkDetector(
401 QuicConnection* connection) {
402 return connection->idle_network_detector_;
403 }
404
405 // static
GetMultiPortProbingAlarm(QuicConnection * connection)406 QuicAlarm* QuicConnectionPeer::GetMultiPortProbingAlarm(
407 QuicConnection* connection) {
408 return connection->multi_port_probing_alarm_.get();
409 }
410
411 // static
SetServerConnectionId(QuicConnection * connection,const QuicConnectionId & server_connection_id)412 void QuicConnectionPeer::SetServerConnectionId(
413 QuicConnection* connection, const QuicConnectionId& server_connection_id) {
414 connection->default_path_.server_connection_id = server_connection_id;
415 connection->InstallInitialCrypters(server_connection_id);
416 }
417
418 // static
NumUndecryptablePackets(QuicConnection * connection)419 size_t QuicConnectionPeer::NumUndecryptablePackets(QuicConnection* connection) {
420 return connection->undecryptable_packets_.size();
421 }
422
SetConnectionClose(QuicConnection * connection)423 void QuicConnectionPeer::SetConnectionClose(QuicConnection* connection) {
424 connection->connected_ = false;
425 }
426
427 // static
SendPing(QuicConnection * connection)428 void QuicConnectionPeer::SendPing(QuicConnection* connection) {
429 connection->SendPingAtLevel(connection->encryption_level());
430 }
431
432 // static
SetLastPacketDestinationAddress(QuicConnection * connection,const QuicSocketAddress & address)433 void QuicConnectionPeer::SetLastPacketDestinationAddress(
434 QuicConnection* connection, const QuicSocketAddress& address) {
435 connection->last_received_packet_info_.destination_address = address;
436 }
437
438 // static
path_validator(QuicConnection * connection)439 QuicPathValidator* QuicConnectionPeer::path_validator(
440 QuicConnection* connection) {
441 return &connection->path_validator_;
442 }
443
444 // static
BytesReceivedOnDefaultPath(QuicConnection * connection)445 QuicByteCount QuicConnectionPeer::BytesReceivedOnDefaultPath(
446 QuicConnection* connection) {
447 return connection->default_path_.bytes_received_before_address_validation;
448 }
449
450 // static
BytesSentOnAlternativePath(QuicConnection * connection)451 QuicByteCount QuicConnectionPeer::BytesSentOnAlternativePath(
452 QuicConnection* connection) {
453 return connection->alternative_path_.bytes_sent_before_address_validation;
454 }
455
456 // static
BytesReceivedOnAlternativePath(QuicConnection * connection)457 QuicByteCount QuicConnectionPeer::BytesReceivedOnAlternativePath(
458 QuicConnection* connection) {
459 return connection->alternative_path_.bytes_received_before_address_validation;
460 }
461
462 // static
GetClientConnectionIdOnAlternativePath(const QuicConnection * connection)463 QuicConnectionId QuicConnectionPeer::GetClientConnectionIdOnAlternativePath(
464 const QuicConnection* connection) {
465 return connection->alternative_path_.client_connection_id;
466 }
467
468 // static
GetServerConnectionIdOnAlternativePath(const QuicConnection * connection)469 QuicConnectionId QuicConnectionPeer::GetServerConnectionIdOnAlternativePath(
470 const QuicConnection* connection) {
471 return connection->alternative_path_.server_connection_id;
472 }
473
474 // static
IsAlternativePathValidated(QuicConnection * connection)475 bool QuicConnectionPeer::IsAlternativePathValidated(
476 QuicConnection* connection) {
477 return connection->alternative_path_.validated;
478 }
479
480 // static
IsAlternativePath(QuicConnection * connection,const QuicSocketAddress & self_address,const QuicSocketAddress & peer_address)481 bool QuicConnectionPeer::IsAlternativePath(
482 QuicConnection* connection, const QuicSocketAddress& self_address,
483 const QuicSocketAddress& peer_address) {
484 return connection->IsAlternativePath(self_address, peer_address);
485 }
486
487 // static
BytesReceivedBeforeAddressValidation(QuicConnection * connection)488 QuicByteCount QuicConnectionPeer::BytesReceivedBeforeAddressValidation(
489 QuicConnection* connection) {
490 return connection->default_path_.bytes_received_before_address_validation;
491 }
492
493 // static
ResetPeerIssuedConnectionIdManager(QuicConnection * connection)494 void QuicConnectionPeer::ResetPeerIssuedConnectionIdManager(
495 QuicConnection* connection) {
496 connection->peer_issued_cid_manager_ = nullptr;
497 }
498
499 // static
GetDefaultPath(QuicConnection * connection)500 QuicConnection::PathState* QuicConnectionPeer::GetDefaultPath(
501 QuicConnection* connection) {
502 return &connection->default_path_;
503 }
504
505 // static
IsDefaultPath(QuicConnection * connection,const QuicSocketAddress & self_address,const QuicSocketAddress & peer_address)506 bool QuicConnectionPeer::IsDefaultPath(QuicConnection* connection,
507 const QuicSocketAddress& self_address,
508 const QuicSocketAddress& peer_address) {
509 return connection->IsDefaultPath(self_address, peer_address);
510 }
511
512 // static
GetAlternativePath(QuicConnection * connection)513 QuicConnection::PathState* QuicConnectionPeer::GetAlternativePath(
514 QuicConnection* connection) {
515 return &connection->alternative_path_;
516 }
517
518 // static
RetirePeerIssuedConnectionIdsNoLongerOnPath(QuicConnection * connection)519 void QuicConnectionPeer::RetirePeerIssuedConnectionIdsNoLongerOnPath(
520 QuicConnection* connection) {
521 connection->RetirePeerIssuedConnectionIdsNoLongerOnPath();
522 }
523
524 // static
HasUnusedPeerIssuedConnectionId(const QuicConnection * connection)525 bool QuicConnectionPeer::HasUnusedPeerIssuedConnectionId(
526 const QuicConnection* connection) {
527 return connection->peer_issued_cid_manager_->HasUnusedConnectionId();
528 }
529
530 // static
HasSelfIssuedConnectionIdToConsume(const QuicConnection * connection)531 bool QuicConnectionPeer::HasSelfIssuedConnectionIdToConsume(
532 const QuicConnection* connection) {
533 return connection->self_issued_cid_manager_->HasConnectionIdToConsume();
534 }
535
536 // static
537 QuicSelfIssuedConnectionIdManager*
GetSelfIssuedConnectionIdManager(QuicConnection * connection)538 QuicConnectionPeer::GetSelfIssuedConnectionIdManager(
539 QuicConnection* connection) {
540 return connection->self_issued_cid_manager_.get();
541 }
542
543 // static
544 std::unique_ptr<QuicSelfIssuedConnectionIdManager>
MakeSelfIssuedConnectionIdManager(QuicConnection * connection)545 QuicConnectionPeer::MakeSelfIssuedConnectionIdManager(
546 QuicConnection* connection) {
547 return connection->MakeSelfIssuedConnectionIdManager();
548 }
549
550 // static
SetLastDecryptedLevel(QuicConnection * connection,EncryptionLevel level)551 void QuicConnectionPeer::SetLastDecryptedLevel(QuicConnection* connection,
552 EncryptionLevel level) {
553 connection->last_received_packet_info_.decrypted_level = level;
554 }
555
556 // static
GetCoalescedPacket(QuicConnection * connection)557 QuicCoalescedPacket& QuicConnectionPeer::GetCoalescedPacket(
558 QuicConnection* connection) {
559 return connection->coalesced_packet_;
560 }
561
562 // static
FlushCoalescedPacket(QuicConnection * connection)563 void QuicConnectionPeer::FlushCoalescedPacket(QuicConnection* connection) {
564 connection->FlushCoalescedPacket();
565 }
566
567 // static
SetInProbeTimeOut(QuicConnection * connection,bool value)568 void QuicConnectionPeer::SetInProbeTimeOut(QuicConnection* connection,
569 bool value) {
570 connection->in_probe_time_out_ = value;
571 }
572
573 // static
GetReceivedServerPreferredAddress(QuicConnection * connection)574 QuicSocketAddress QuicConnectionPeer::GetReceivedServerPreferredAddress(
575 QuicConnection* connection) {
576 return connection->received_server_preferred_address_;
577 }
578
579 // static
GetSentServerPreferredAddress(QuicConnection * connection)580 QuicSocketAddress QuicConnectionPeer::GetSentServerPreferredAddress(
581 QuicConnection* connection) {
582 return connection->sent_server_preferred_address_;
583 }
584
585 // static
TestLastReceivedPacketInfoDefaults()586 bool QuicConnectionPeer::TestLastReceivedPacketInfoDefaults() {
587 QuicConnection::ReceivedPacketInfo info{QuicTime::Zero()};
588 QUIC_DVLOG(2)
589 << "QuicConnectionPeer::TestLastReceivedPacketInfoDefaults"
590 << " dest_addr passed: "
591 << (info.destination_address == QuicSocketAddress())
592 << " source_addr passed: " << (info.source_address == QuicSocketAddress())
593 << " receipt_time passed: " << (info.receipt_time == QuicTime::Zero())
594 << " received_bytes_counted passed: " << !info.received_bytes_counted
595 << " destination_connection_id passed: "
596 << (info.destination_connection_id == QuicConnectionId())
597 << " length passed: " << (info.length == 0)
598 << " decrypted passed: " << !info.decrypted << " decrypted_level passed: "
599 << (info.decrypted_level == ENCRYPTION_INITIAL)
600 << " frames.empty passed: " << info.frames.empty()
601 << " ecn_codepoint passed: " << (info.ecn_codepoint == ECN_NOT_ECT)
602 << " sizeof(ReceivedPacketInfo) passed: "
603 << (sizeof(size_t) != 8 ||
604 sizeof(QuicConnection::ReceivedPacketInfo) == 280);
605 return info.destination_address == QuicSocketAddress() &&
606 info.source_address == QuicSocketAddress() &&
607 info.receipt_time == QuicTime::Zero() &&
608 !info.received_bytes_counted && info.length == 0 &&
609 info.destination_connection_id == QuicConnectionId() &&
610 !info.decrypted && info.decrypted_level == ENCRYPTION_INITIAL &&
611 // There's no simple way to compare all the values of QuicPacketHeader.
612 info.frames.empty() && info.ecn_codepoint == ECN_NOT_ECT &&
613 info.actual_destination_address == QuicSocketAddress() &&
614 // If the condition below fails, the contents of ReceivedPacketInfo
615 // have changed. Please add the relevant conditions and update the
616 // length below.
617 (sizeof(size_t) != 8 ||
618 sizeof(QuicConnection::ReceivedPacketInfo) == 280);
619 }
620
621 // static
DisableEcnCodepointValidation(QuicConnection * connection)622 void QuicConnectionPeer::DisableEcnCodepointValidation(
623 QuicConnection* connection) {
624 connection->disable_ecn_codepoint_validation_ = true;
625 }
626
627 } // namespace test
628 } // namespace quic
629