• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/quic/test_tools/quic_connection_peer.h"
6 
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"
16 
17 namespace net {
18 namespace test {
19 
20 // static
SendAck(QuicConnection * connection)21 void QuicConnectionPeer::SendAck(QuicConnection* connection) {
22   connection->SendAck();
23 }
24 
25 // static
SetReceiveAlgorithm(QuicConnection * connection,ReceiveAlgorithmInterface * receive_algorithm)26 void QuicConnectionPeer::SetReceiveAlgorithm(
27     QuicConnection* connection,
28     ReceiveAlgorithmInterface* receive_algorithm) {
29   connection->received_packet_manager_.receive_algorithm_.reset(
30       receive_algorithm);
31 }
32 
33 // static
SetSendAlgorithm(QuicConnection * connection,SendAlgorithmInterface * send_algorithm)34 void QuicConnectionPeer::SetSendAlgorithm(
35     QuicConnection* connection,
36     SendAlgorithmInterface* send_algorithm) {
37   connection->sent_packet_manager_.send_algorithm_.reset(send_algorithm);
38 }
39 
40 // static
CreateAckFrame(QuicConnection * connection)41 QuicAckFrame* QuicConnectionPeer::CreateAckFrame(QuicConnection* connection) {
42   return connection->CreateAckFrame();
43 }
44 
45 // static
CreateStopWaitingFrame(QuicConnection * connection)46 QuicStopWaitingFrame* QuicConnectionPeer::CreateStopWaitingFrame(
47     QuicConnection* connection) {
48   return connection->CreateStopWaitingFrame();
49 }
50 
51 // static
GetVisitor(QuicConnection * connection)52 QuicConnectionVisitorInterface* QuicConnectionPeer::GetVisitor(
53     QuicConnection* connection) {
54   return connection->visitor_;
55 }
56 
57 // static
GetPacketCreator(QuicConnection * connection)58 QuicPacketCreator* QuicConnectionPeer::GetPacketCreator(
59     QuicConnection* connection) {
60   return QuicPacketGeneratorPeer::GetPacketCreator(
61       &connection->packet_generator_);
62 }
63 
64 // static
GetPacketGenerator(QuicConnection * connection)65 QuicPacketGenerator* QuicConnectionPeer::GetPacketGenerator(
66     QuicConnection* connection) {
67   return &connection->packet_generator_;
68 }
69 
70 // static
GetSentPacketManager(QuicConnection * connection)71 QuicSentPacketManager* QuicConnectionPeer::GetSentPacketManager(
72     QuicConnection* connection) {
73   return &connection->sent_packet_manager_;
74 }
75 
76 // static
GetReceivedPacketManager(QuicConnection * connection)77 QuicReceivedPacketManager* QuicConnectionPeer::GetReceivedPacketManager(
78     QuicConnection* connection) {
79   return &connection->received_packet_manager_;
80 }
81 
82 // static
GetNetworkTimeout(QuicConnection * connection)83 QuicTime::Delta QuicConnectionPeer::GetNetworkTimeout(
84     QuicConnection* connection) {
85   return connection->idle_network_timeout_;
86 }
87 
88 // static
IsSavedForRetransmission(QuicConnection * connection,QuicPacketSequenceNumber sequence_number)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);
95 }
96 
97 // static
IsRetransmission(QuicConnection * connection,QuicPacketSequenceNumber sequence_number)98 bool QuicConnectionPeer::IsRetransmission(
99     QuicConnection* connection,
100     QuicPacketSequenceNumber sequence_number) {
101   return QuicSentPacketManagerPeer::IsRetransmission(
102       &connection->sent_packet_manager_, sequence_number);
103 }
104 
105 // static
106 // TODO(ianswett): Create a GetSentEntropyHash which accepts an AckFrame.
GetSentEntropyHash(QuicConnection * connection,QuicPacketSequenceNumber sequence_number)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;
115 }
116 
117 // static
PacketEntropy(QuicConnection * connection,QuicPacketSequenceNumber sequence_number)118 QuicPacketEntropyHash QuicConnectionPeer::PacketEntropy(
119     QuicConnection* connection,
120     QuicPacketSequenceNumber sequence_number) {
121   return connection->sent_entropy_manager_.GetPacketEntropy(sequence_number);
122 }
123 
124 // static
ReceivedEntropyHash(QuicConnection * connection,QuicPacketSequenceNumber sequence_number)125 QuicPacketEntropyHash QuicConnectionPeer::ReceivedEntropyHash(
126     QuicConnection* connection,
127     QuicPacketSequenceNumber sequence_number) {
128   return connection->received_packet_manager_.EntropyHash(
129       sequence_number);
130 }
131 
132 // static
IsServer(QuicConnection * connection)133 bool QuicConnectionPeer::IsServer(QuicConnection* connection) {
134   return connection->is_server_;
135 }
136 
137 // static
SetIsServer(QuicConnection * connection,bool is_server)138 void QuicConnectionPeer::SetIsServer(QuicConnection* connection,
139                                      bool is_server) {
140   connection->is_server_ = is_server;
141   QuicFramerPeer::SetIsServer(&connection->framer_, is_server);
142 }
143 
144 // static
SetSelfAddress(QuicConnection * connection,const IPEndPoint & self_address)145 void QuicConnectionPeer::SetSelfAddress(QuicConnection* connection,
146                                         const IPEndPoint& self_address) {
147   connection->self_address_ = self_address;
148 }
149 
150 // static
SetPeerAddress(QuicConnection * connection,const IPEndPoint & peer_address)151 void QuicConnectionPeer::SetPeerAddress(QuicConnection* connection,
152                                         const IPEndPoint& peer_address) {
153   connection->peer_address_ = peer_address;
154 }
155 
156 // static
SwapCrypters(QuicConnection * connection,QuicFramer * framer)157 void QuicConnectionPeer::SwapCrypters(QuicConnection* connection,
158                                       QuicFramer* framer) {
159   QuicFramerPeer::SwapCrypters(framer, &connection->framer_);
160 }
161 
162 // static
GetHelper(QuicConnection * connection)163 QuicConnectionHelperInterface* QuicConnectionPeer::GetHelper(
164     QuicConnection* connection) {
165   return connection->helper_;
166 }
167 
168 // static
GetFramer(QuicConnection * connection)169 QuicFramer* QuicConnectionPeer::GetFramer(QuicConnection* connection) {
170   return &connection->framer_;
171 }
172 
173 // static
GetFecGroup(QuicConnection * connection,int fec_group)174 QuicFecGroup* QuicConnectionPeer::GetFecGroup(QuicConnection* connection,
175                                               int fec_group) {
176   connection->last_header_.fec_group = fec_group;
177   return connection->GetFecGroup();
178 }
179 
180 // static
GetAckAlarm(QuicConnection * connection)181 QuicAlarm* QuicConnectionPeer::GetAckAlarm(QuicConnection* connection) {
182   return connection->ack_alarm_.get();
183 }
184 
185 // static
GetPingAlarm(QuicConnection * connection)186 QuicAlarm* QuicConnectionPeer::GetPingAlarm(QuicConnection* connection) {
187   return connection->ping_alarm_.get();
188 }
189 
190 // static
GetResumeWritesAlarm(QuicConnection * connection)191 QuicAlarm* QuicConnectionPeer::GetResumeWritesAlarm(
192     QuicConnection* connection) {
193   return connection->resume_writes_alarm_.get();
194 }
195 
196 // static
GetRetransmissionAlarm(QuicConnection * connection)197 QuicAlarm* QuicConnectionPeer::GetRetransmissionAlarm(
198     QuicConnection* connection) {
199   return connection->retransmission_alarm_.get();
200 }
201 
202 // static
GetSendAlarm(QuicConnection * connection)203 QuicAlarm* QuicConnectionPeer::GetSendAlarm(QuicConnection* connection) {
204   return connection->send_alarm_.get();
205 }
206 
207 // static
GetTimeoutAlarm(QuicConnection * connection)208 QuicAlarm* QuicConnectionPeer::GetTimeoutAlarm(QuicConnection* connection) {
209   return connection->timeout_alarm_.get();
210 }
211 
212 // static
GetWriter(QuicConnection * connection)213 QuicPacketWriter* QuicConnectionPeer::GetWriter(QuicConnection* connection) {
214   return connection->writer_;
215 }
216 
217 // static
SetWriter(QuicConnection * connection,QuicPacketWriter * writer,bool owns_writer)218 void QuicConnectionPeer::SetWriter(QuicConnection* connection,
219                                    QuicPacketWriter* writer,
220                                    bool owns_writer) {
221   if (connection->owns_writer_) {
222     delete connection->writer_;
223   }
224   connection->writer_ = writer;
225   connection->owns_writer_ = owns_writer;
226 }
227 
228 // static
CloseConnection(QuicConnection * connection)229 void QuicConnectionPeer::CloseConnection(QuicConnection* connection) {
230   connection->connected_ = false;
231 }
232 
233 // static
GetConnectionClosePacket(QuicConnection * connection)234 QuicEncryptedPacket* QuicConnectionPeer::GetConnectionClosePacket(
235     QuicConnection* connection) {
236   return connection->connection_close_packet_.get();
237 }
238 
239 // static
SetSupportedVersions(QuicConnection * connection,QuicVersionVector versions)240 void QuicConnectionPeer::SetSupportedVersions(QuicConnection* connection,
241                                               QuicVersionVector versions) {
242   connection->framer_.SetSupportedVersions(versions);
243 }
244 
245 }  // namespace test
246 }  // namespace net
247