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/receive_algorithm_interface.h"
9 #include "net/quic/congestion_control/send_algorithm_interface.h"
10 #include "net/quic/quic_connection.h"
11 #include "net/quic/quic_packet_writer.h"
12 #include "net/quic/quic_received_packet_manager.h"
13 #include "net/quic/test_tools/quic_framer_peer.h"
14 #include "net/quic/test_tools/quic_packet_generator_peer.h"
15 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h"
21 void QuicConnectionPeer::SendAck(QuicConnection
* connection
) {
22 connection
->SendAck();
26 void QuicConnectionPeer::SetReceiveAlgorithm(
27 QuicConnection
* connection
,
28 ReceiveAlgorithmInterface
* receive_algorithm
) {
29 connection
->received_packet_manager_
.receive_algorithm_
.reset(
34 void QuicConnectionPeer::SetSendAlgorithm(
35 QuicConnection
* connection
,
36 SendAlgorithmInterface
* send_algorithm
) {
37 connection
->sent_packet_manager_
.send_algorithm_
.reset(send_algorithm
);
41 QuicAckFrame
* QuicConnectionPeer::CreateAckFrame(QuicConnection
* connection
) {
42 return connection
->CreateAckFrame();
46 QuicStopWaitingFrame
* QuicConnectionPeer::CreateStopWaitingFrame(
47 QuicConnection
* connection
) {
48 return connection
->CreateStopWaitingFrame();
52 QuicConnectionVisitorInterface
* QuicConnectionPeer::GetVisitor(
53 QuicConnection
* connection
) {
54 return connection
->visitor_
;
58 QuicPacketCreator
* QuicConnectionPeer::GetPacketCreator(
59 QuicConnection
* connection
) {
60 return QuicPacketGeneratorPeer::GetPacketCreator(
61 &connection
->packet_generator_
);
65 QuicPacketGenerator
* QuicConnectionPeer::GetPacketGenerator(
66 QuicConnection
* connection
) {
67 return &connection
->packet_generator_
;
71 QuicSentPacketManager
* QuicConnectionPeer::GetSentPacketManager(
72 QuicConnection
* connection
) {
73 return &connection
->sent_packet_manager_
;
77 QuicReceivedPacketManager
* QuicConnectionPeer::GetReceivedPacketManager(
78 QuicConnection
* connection
) {
79 return &connection
->received_packet_manager_
;
83 QuicTime::Delta
QuicConnectionPeer::GetNetworkTimeout(
84 QuicConnection
* connection
) {
85 return connection
->idle_network_timeout_
;
89 bool QuicConnectionPeer::IsSavedForRetransmission(
90 QuicConnection
* connection
,
91 QuicPacketSequenceNumber sequence_number
) {
92 return connection
->sent_packet_manager_
.IsUnacked(sequence_number
) &&
93 connection
->sent_packet_manager_
.HasRetransmittableFrames(
98 bool QuicConnectionPeer::IsRetransmission(
99 QuicConnection
* connection
,
100 QuicPacketSequenceNumber sequence_number
) {
101 return QuicSentPacketManagerPeer::IsRetransmission(
102 &connection
->sent_packet_manager_
, sequence_number
);
106 // TODO(ianswett): Create a GetSentEntropyHash which accepts an AckFrame.
107 QuicPacketEntropyHash
QuicConnectionPeer::GetSentEntropyHash(
108 QuicConnection
* connection
,
109 QuicPacketSequenceNumber sequence_number
) {
110 QuicSentEntropyManager::CumulativeEntropy last_entropy_copy
=
111 connection
->sent_entropy_manager_
.last_cumulative_entropy_
;
112 connection
->sent_entropy_manager_
.UpdateCumulativeEntropy(sequence_number
,
114 return last_entropy_copy
.entropy
;
118 QuicPacketEntropyHash
QuicConnectionPeer::PacketEntropy(
119 QuicConnection
* connection
,
120 QuicPacketSequenceNumber sequence_number
) {
121 return connection
->sent_entropy_manager_
.GetPacketEntropy(sequence_number
);
125 QuicPacketEntropyHash
QuicConnectionPeer::ReceivedEntropyHash(
126 QuicConnection
* connection
,
127 QuicPacketSequenceNumber sequence_number
) {
128 return connection
->received_packet_manager_
.EntropyHash(
133 bool QuicConnectionPeer::IsServer(QuicConnection
* connection
) {
134 return connection
->is_server_
;
138 void QuicConnectionPeer::SetIsServer(QuicConnection
* connection
,
140 connection
->is_server_
= is_server
;
141 QuicFramerPeer::SetIsServer(&connection
->framer_
, is_server
);
145 void QuicConnectionPeer::SetSelfAddress(QuicConnection
* connection
,
146 const IPEndPoint
& self_address
) {
147 connection
->self_address_
= self_address
;
151 void QuicConnectionPeer::SetPeerAddress(QuicConnection
* connection
,
152 const IPEndPoint
& peer_address
) {
153 connection
->peer_address_
= peer_address
;
157 void QuicConnectionPeer::SwapCrypters(QuicConnection
* connection
,
158 QuicFramer
* framer
) {
159 QuicFramerPeer::SwapCrypters(framer
, &connection
->framer_
);
163 QuicConnectionHelperInterface
* QuicConnectionPeer::GetHelper(
164 QuicConnection
* connection
) {
165 return connection
->helper_
;
169 QuicFramer
* QuicConnectionPeer::GetFramer(QuicConnection
* connection
) {
170 return &connection
->framer_
;
174 QuicFecGroup
* QuicConnectionPeer::GetFecGroup(QuicConnection
* connection
,
176 connection
->last_header_
.fec_group
= fec_group
;
177 return connection
->GetFecGroup();
181 QuicAlarm
* QuicConnectionPeer::GetAckAlarm(QuicConnection
* connection
) {
182 return connection
->ack_alarm_
.get();
186 QuicAlarm
* QuicConnectionPeer::GetPingAlarm(QuicConnection
* connection
) {
187 return connection
->ping_alarm_
.get();
191 QuicAlarm
* QuicConnectionPeer::GetResumeWritesAlarm(
192 QuicConnection
* connection
) {
193 return connection
->resume_writes_alarm_
.get();
197 QuicAlarm
* QuicConnectionPeer::GetRetransmissionAlarm(
198 QuicConnection
* connection
) {
199 return connection
->retransmission_alarm_
.get();
203 QuicAlarm
* QuicConnectionPeer::GetSendAlarm(QuicConnection
* connection
) {
204 return connection
->send_alarm_
.get();
208 QuicAlarm
* QuicConnectionPeer::GetTimeoutAlarm(QuicConnection
* connection
) {
209 return connection
->timeout_alarm_
.get();
213 QuicPacketWriter
* QuicConnectionPeer::GetWriter(QuicConnection
* connection
) {
214 return connection
->writer_
;
218 void QuicConnectionPeer::SetWriter(QuicConnection
* connection
,
219 QuicPacketWriter
* writer
,
221 if (connection
->owns_writer_
) {
222 delete connection
->writer_
;
224 connection
->writer_
= writer
;
225 connection
->owns_writer_
= owns_writer
;
229 void QuicConnectionPeer::CloseConnection(QuicConnection
* connection
) {
230 connection
->connected_
= false;
234 QuicEncryptedPacket
* QuicConnectionPeer::GetConnectionClosePacket(
235 QuicConnection
* connection
) {
236 return connection
->connection_close_packet_
.get();
240 void QuicConnectionPeer::SetSupportedVersions(QuicConnection
* connection
,
241 QuicVersionVector versions
) {
242 connection
->framer_
.SetSupportedVersions(versions
);