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.
5 #include "net/quic/test_tools/quic_connection_peer.h"
7 #include "base/stl_util.h"
8 #include "net/quic/congestion_control/send_algorithm_interface.h"
9 #include "net/quic/quic_connection.h"
10 #include "net/quic/quic_packet_writer.h"
11 #include "net/quic/quic_received_packet_manager.h"
12 #include "net/quic/test_tools/quic_framer_peer.h"
13 #include "net/quic/test_tools/quic_packet_generator_peer.h"
14 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h"
20 void QuicConnectionPeer::SendAck(QuicConnection
* connection
) {
21 connection
->SendAck();
25 void QuicConnectionPeer::SetSendAlgorithm(
26 QuicConnection
* connection
,
27 SendAlgorithmInterface
* send_algorithm
) {
28 connection
->sent_packet_manager_
.send_algorithm_
.reset(send_algorithm
);
32 void QuicConnectionPeer::PopulateAckFrame(QuicConnection
* connection
,
34 connection
->PopulateAckFrame(ack
);
38 void QuicConnectionPeer::PopulateStopWaitingFrame(
39 QuicConnection
* connection
,
40 QuicStopWaitingFrame
* stop_waiting
) {
41 connection
->PopulateStopWaitingFrame(stop_waiting
);
45 QuicConnectionVisitorInterface
* QuicConnectionPeer::GetVisitor(
46 QuicConnection
* connection
) {
47 return connection
->visitor_
;
51 QuicPacketCreator
* QuicConnectionPeer::GetPacketCreator(
52 QuicConnection
* connection
) {
53 return QuicPacketGeneratorPeer::GetPacketCreator(
54 &connection
->packet_generator_
);
58 QuicPacketGenerator
* QuicConnectionPeer::GetPacketGenerator(
59 QuicConnection
* connection
) {
60 return &connection
->packet_generator_
;
64 QuicSentPacketManager
* QuicConnectionPeer::GetSentPacketManager(
65 QuicConnection
* connection
) {
66 return &connection
->sent_packet_manager_
;
70 QuicTime::Delta
QuicConnectionPeer::GetNetworkTimeout(
71 QuicConnection
* connection
) {
72 return connection
->idle_network_timeout_
;
76 // TODO(ianswett): Create a GetSentEntropyHash which accepts an AckFrame.
77 QuicPacketEntropyHash
QuicConnectionPeer::GetSentEntropyHash(
78 QuicConnection
* connection
,
79 QuicPacketNumber packet_number
) {
80 QuicSentEntropyManager::CumulativeEntropy last_entropy_copy
=
81 connection
->sent_entropy_manager_
.last_cumulative_entropy_
;
82 connection
->sent_entropy_manager_
.UpdateCumulativeEntropy(packet_number
,
84 return last_entropy_copy
.entropy
;
88 QuicPacketEntropyHash
QuicConnectionPeer::PacketEntropy(
89 QuicConnection
* connection
,
90 QuicPacketNumber packet_number
) {
91 return connection
->sent_entropy_manager_
.GetPacketEntropy(packet_number
);
95 QuicPacketEntropyHash
QuicConnectionPeer::ReceivedEntropyHash(
96 QuicConnection
* connection
,
97 QuicPacketNumber packet_number
) {
98 return connection
->received_packet_manager_
.EntropyHash(packet_number
);
102 void QuicConnectionPeer::SetPerspective(QuicConnection
* connection
,
103 Perspective perspective
) {
104 connection
->perspective_
= perspective
;
105 QuicFramerPeer::SetPerspective(&connection
->framer_
, perspective
);
109 void QuicConnectionPeer::SetSelfAddress(QuicConnection
* connection
,
110 const IPEndPoint
& self_address
) {
111 connection
->self_address_
= self_address
;
115 void QuicConnectionPeer::SetPeerAddress(QuicConnection
* connection
,
116 const IPEndPoint
& peer_address
) {
117 connection
->peer_address_
= peer_address
;
121 bool QuicConnectionPeer::IsSilentCloseEnabled(QuicConnection
* connection
) {
122 return connection
->silent_close_enabled_
;
126 void QuicConnectionPeer::SwapCrypters(QuicConnection
* connection
,
127 QuicFramer
* framer
) {
128 QuicFramerPeer::SwapCrypters(framer
, &connection
->framer_
);
132 QuicConnectionHelperInterface
* QuicConnectionPeer::GetHelper(
133 QuicConnection
* connection
) {
134 return connection
->helper_
;
138 QuicFramer
* QuicConnectionPeer::GetFramer(QuicConnection
* connection
) {
139 return &connection
->framer_
;
143 QuicFecGroup
* QuicConnectionPeer::GetFecGroup(QuicConnection
* connection
,
145 connection
->last_header_
.fec_group
= fec_group
;
146 return connection
->GetFecGroup();
150 QuicAlarm
* QuicConnectionPeer::GetAckAlarm(QuicConnection
* connection
) {
151 return connection
->ack_alarm_
.get();
155 QuicAlarm
* QuicConnectionPeer::GetPingAlarm(QuicConnection
* connection
) {
156 return connection
->ping_alarm_
.get();
160 QuicAlarm
* QuicConnectionPeer::GetFecAlarm(QuicConnection
* connection
) {
161 return connection
->fec_alarm_
.get();
165 QuicAlarm
* QuicConnectionPeer::GetResumeWritesAlarm(
166 QuicConnection
* connection
) {
167 return connection
->resume_writes_alarm_
.get();
171 QuicAlarm
* QuicConnectionPeer::GetRetransmissionAlarm(
172 QuicConnection
* connection
) {
173 return connection
->retransmission_alarm_
.get();
177 QuicAlarm
* QuicConnectionPeer::GetSendAlarm(QuicConnection
* connection
) {
178 return connection
->send_alarm_
.get();
182 QuicAlarm
* QuicConnectionPeer::GetTimeoutAlarm(QuicConnection
* connection
) {
183 return connection
->timeout_alarm_
.get();
187 QuicAlarm
* QuicConnectionPeer::GetMtuDiscoveryAlarm(
188 QuicConnection
* connection
) {
189 return connection
->mtu_discovery_alarm_
.get();
193 QuicPacketWriter
* QuicConnectionPeer::GetWriter(QuicConnection
* connection
) {
194 return connection
->writer_
;
198 void QuicConnectionPeer::SetWriter(QuicConnection
* connection
,
199 QuicPacketWriter
* writer
,
201 if (connection
->owns_writer_
) {
202 delete connection
->writer_
;
204 connection
->writer_
= writer
;
205 connection
->owns_writer_
= owns_writer
;
209 void QuicConnectionPeer::CloseConnection(QuicConnection
* connection
) {
210 connection
->connected_
= false;
214 QuicEncryptedPacket
* QuicConnectionPeer::GetConnectionClosePacket(
215 QuicConnection
* connection
) {
216 return connection
->connection_close_packet_
.get();
220 QuicPacketHeader
* QuicConnectionPeer::GetLastHeader(
221 QuicConnection
* connection
) {
222 return &connection
->last_header_
;
226 void QuicConnectionPeer::SetPacketNumberOfLastSentPacket(
227 QuicConnection
* connection
,
228 QuicPacketNumber number
) {
229 connection
->packet_number_of_last_sent_packet_
= number
;
233 QuicConnectionStats
* QuicConnectionPeer::GetStats(QuicConnection
* connection
) {
234 return &connection
->stats_
;
238 QuicPacketCount
QuicConnectionPeer::GetPacketsBetweenMtuProbes(
239 QuicConnection
* connection
) {
240 return connection
->packets_between_mtu_probes_
;
244 void QuicConnectionPeer::SetPacketsBetweenMtuProbes(QuicConnection
* connection
,
245 QuicPacketCount packets
) {
246 connection
->packets_between_mtu_probes_
= packets
;
250 void QuicConnectionPeer::SetNextMtuProbeAt(QuicConnection
* connection
,
251 QuicPacketNumber number
) {
252 connection
->next_mtu_probe_at_
= number
;