Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / quic / test_tools / quic_connection_peer.cc
bloba14824918f855497761c24e744acb01de5f1cb03
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"
17 namespace net {
18 namespace test {
20 // static
21 void QuicConnectionPeer::SendAck(QuicConnection* connection) {
22 connection->SendAck();
25 // static
26 void QuicConnectionPeer::SetReceiveAlgorithm(
27 QuicConnection* connection,
28 ReceiveAlgorithmInterface* receive_algorithm) {
29 connection->received_packet_manager_.receive_algorithm_.reset(
30 receive_algorithm);
33 // static
34 void QuicConnectionPeer::SetSendAlgorithm(
35 QuicConnection* connection,
36 SendAlgorithmInterface* send_algorithm) {
37 connection->sent_packet_manager_.send_algorithm_.reset(send_algorithm);
40 // static
41 QuicAckFrame* QuicConnectionPeer::CreateAckFrame(QuicConnection* connection) {
42 return connection->CreateAckFrame();
45 // static
46 QuicStopWaitingFrame* QuicConnectionPeer::CreateStopWaitingFrame(
47 QuicConnection* connection) {
48 return connection->CreateStopWaitingFrame();
51 // static
52 QuicConnectionVisitorInterface* QuicConnectionPeer::GetVisitor(
53 QuicConnection* connection) {
54 return connection->visitor_;
57 // static
58 QuicPacketCreator* QuicConnectionPeer::GetPacketCreator(
59 QuicConnection* connection) {
60 return QuicPacketGeneratorPeer::GetPacketCreator(
61 &connection->packet_generator_);
64 // static
65 QuicPacketGenerator* QuicConnectionPeer::GetPacketGenerator(
66 QuicConnection* connection) {
67 return &connection->packet_generator_;
70 // static
71 QuicSentPacketManager* QuicConnectionPeer::GetSentPacketManager(
72 QuicConnection* connection) {
73 return &connection->sent_packet_manager_;
76 // static
77 QuicReceivedPacketManager* QuicConnectionPeer::GetReceivedPacketManager(
78 QuicConnection* connection) {
79 return &connection->received_packet_manager_;
82 // static
83 QuicTime::Delta QuicConnectionPeer::GetNetworkTimeout(
84 QuicConnection* connection) {
85 return connection->idle_network_timeout_;
88 // static
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(
94 sequence_number);
97 // static
98 bool QuicConnectionPeer::IsRetransmission(
99 QuicConnection* connection,
100 QuicPacketSequenceNumber sequence_number) {
101 return QuicSentPacketManagerPeer::IsRetransmission(
102 &connection->sent_packet_manager_, sequence_number);
105 // static
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,
113 &last_entropy_copy);
114 return last_entropy_copy.entropy;
117 // static
118 QuicPacketEntropyHash QuicConnectionPeer::PacketEntropy(
119 QuicConnection* connection,
120 QuicPacketSequenceNumber sequence_number) {
121 return connection->sent_entropy_manager_.GetPacketEntropy(sequence_number);
124 // static
125 QuicPacketEntropyHash QuicConnectionPeer::ReceivedEntropyHash(
126 QuicConnection* connection,
127 QuicPacketSequenceNumber sequence_number) {
128 return connection->received_packet_manager_.EntropyHash(
129 sequence_number);
132 // static
133 bool QuicConnectionPeer::IsServer(QuicConnection* connection) {
134 return connection->is_server_;
137 // static
138 void QuicConnectionPeer::SetIsServer(QuicConnection* connection,
139 bool is_server) {
140 connection->is_server_ = is_server;
141 QuicFramerPeer::SetIsServer(&connection->framer_, is_server);
144 // static
145 void QuicConnectionPeer::SetSelfAddress(QuicConnection* connection,
146 const IPEndPoint& self_address) {
147 connection->self_address_ = self_address;
150 // static
151 void QuicConnectionPeer::SetPeerAddress(QuicConnection* connection,
152 const IPEndPoint& peer_address) {
153 connection->peer_address_ = peer_address;
156 // static
157 void QuicConnectionPeer::SwapCrypters(QuicConnection* connection,
158 QuicFramer* framer) {
159 QuicFramerPeer::SwapCrypters(framer, &connection->framer_);
162 // static
163 QuicConnectionHelperInterface* QuicConnectionPeer::GetHelper(
164 QuicConnection* connection) {
165 return connection->helper_;
168 // static
169 QuicFramer* QuicConnectionPeer::GetFramer(QuicConnection* connection) {
170 return &connection->framer_;
173 // static
174 QuicFecGroup* QuicConnectionPeer::GetFecGroup(QuicConnection* connection,
175 int fec_group) {
176 connection->last_header_.fec_group = fec_group;
177 return connection->GetFecGroup();
180 // static
181 QuicAlarm* QuicConnectionPeer::GetAckAlarm(QuicConnection* connection) {
182 return connection->ack_alarm_.get();
185 // static
186 QuicAlarm* QuicConnectionPeer::GetPingAlarm(QuicConnection* connection) {
187 return connection->ping_alarm_.get();
190 // static
191 QuicAlarm* QuicConnectionPeer::GetResumeWritesAlarm(
192 QuicConnection* connection) {
193 return connection->resume_writes_alarm_.get();
196 // static
197 QuicAlarm* QuicConnectionPeer::GetRetransmissionAlarm(
198 QuicConnection* connection) {
199 return connection->retransmission_alarm_.get();
202 // static
203 QuicAlarm* QuicConnectionPeer::GetSendAlarm(QuicConnection* connection) {
204 return connection->send_alarm_.get();
207 // static
208 QuicAlarm* QuicConnectionPeer::GetTimeoutAlarm(QuicConnection* connection) {
209 return connection->timeout_alarm_.get();
212 // static
213 QuicPacketWriter* QuicConnectionPeer::GetWriter(QuicConnection* connection) {
214 return connection->writer_;
217 // static
218 void QuicConnectionPeer::SetWriter(QuicConnection* connection,
219 QuicPacketWriter* writer,
220 bool owns_writer) {
221 if (connection->owns_writer_) {
222 delete connection->writer_;
224 connection->writer_ = writer;
225 connection->owns_writer_ = owns_writer;
228 // static
229 void QuicConnectionPeer::CloseConnection(QuicConnection* connection) {
230 connection->connected_ = false;
233 // static
234 QuicEncryptedPacket* QuicConnectionPeer::GetConnectionClosePacket(
235 QuicConnection* connection) {
236 return connection->connection_close_packet_.get();
239 // static
240 void QuicConnectionPeer::SetSupportedVersions(QuicConnection* connection,
241 QuicVersionVector versions) {
242 connection->framer_.SetSupportedVersions(versions);
245 } // namespace test
246 } // namespace net