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 #ifndef NET_QUIC_TEST_TOOLS_QUIC_CONNECTION_PEER_H_ 6 #define NET_QUIC_TEST_TOOLS_QUIC_CONNECTION_PEER_H_ 7 8 #include "base/basictypes.h" 9 #include "net/base/ip_endpoint.h" 10 #include "net/quic/quic_connection_stats.h" 11 #include "net/quic/quic_protocol.h" 12 13 namespace net { 14 15 struct QuicAckFrame; 16 struct QuicPacketHeader; 17 class QuicAlarm; 18 class QuicConnection; 19 class QuicConnectionHelperInterface; 20 class QuicConnectionVisitorInterface; 21 class QuicEncryptedPacket; 22 class QuicFecGroup; 23 class QuicFramer; 24 class QuicPacketCreator; 25 class QuicPacketGenerator; 26 class QuicPacketWriter; 27 class QuicReceivedPacketManager; 28 class QuicSentPacketManager; 29 class ReceiveAlgorithmInterface; 30 class SendAlgorithmInterface; 31 32 namespace test { 33 34 // Peer to make public a number of otherwise private QuicConnection methods. 35 class QuicConnectionPeer { 36 public: 37 static void SendAck(QuicConnection* connection); 38 39 static void SetReceiveAlgorithm(QuicConnection* connection, 40 ReceiveAlgorithmInterface* receive_algorithm); 41 42 static void SetSendAlgorithm(QuicConnection* connection, 43 SendAlgorithmInterface* send_algorithm); 44 45 static QuicAckFrame* CreateAckFrame(QuicConnection* connection); 46 47 static QuicStopWaitingFrame* CreateStopWaitingFrame( 48 QuicConnection* connection); 49 50 static QuicConnectionVisitorInterface* GetVisitor( 51 QuicConnection* connection); 52 53 static QuicPacketCreator* GetPacketCreator(QuicConnection* connection); 54 55 static QuicPacketGenerator* GetPacketGenerator(QuicConnection* connection); 56 57 static QuicSentPacketManager* GetSentPacketManager( 58 QuicConnection* connection); 59 60 static QuicReceivedPacketManager* GetReceivedPacketManager( 61 QuicConnection* connection); 62 63 static QuicTime::Delta GetNetworkTimeout(QuicConnection* connection); 64 65 static bool IsSavedForRetransmission( 66 QuicConnection* connection, 67 QuicPacketSequenceNumber sequence_number); 68 69 static bool IsRetransmission(QuicConnection* connection, 70 QuicPacketSequenceNumber sequence_number); 71 72 static QuicPacketEntropyHash GetSentEntropyHash( 73 QuicConnection* connection, 74 QuicPacketSequenceNumber sequence_number); 75 76 static QuicPacketEntropyHash PacketEntropy( 77 QuicConnection* connection, 78 QuicPacketSequenceNumber sequence_number); 79 80 static QuicPacketEntropyHash ReceivedEntropyHash( 81 QuicConnection* connection, 82 QuicPacketSequenceNumber sequence_number); 83 84 static bool IsServer(QuicConnection* connection); 85 86 static void SetIsServer(QuicConnection* connection, bool is_server); 87 88 static void SetSelfAddress(QuicConnection* connection, 89 const IPEndPoint& self_address); 90 91 static void SetPeerAddress(QuicConnection* connection, 92 const IPEndPoint& peer_address); 93 94 static void SwapCrypters(QuicConnection* connection, QuicFramer* framer); 95 96 static QuicConnectionHelperInterface* GetHelper(QuicConnection* connection); 97 98 static QuicFramer* GetFramer(QuicConnection* connection); 99 100 // Set last_header_->fec_group = fec_group and return connection->GetFecGroup 101 static QuicFecGroup* GetFecGroup(QuicConnection* connection, int fec_group); 102 103 static QuicAlarm* GetAckAlarm(QuicConnection* connection); 104 static QuicAlarm* GetPingAlarm(QuicConnection* connection); 105 static QuicAlarm* GetResumeWritesAlarm(QuicConnection* connection); 106 static QuicAlarm* GetRetransmissionAlarm(QuicConnection* connection); 107 static QuicAlarm* GetSendAlarm(QuicConnection* connection); 108 static QuicAlarm* GetTimeoutAlarm(QuicConnection* connection); 109 110 static QuicPacketWriter* GetWriter(QuicConnection* connection); 111 // If |owns_writer| is true, takes ownership of |writer|. 112 static void SetWriter(QuicConnection* connection, 113 QuicPacketWriter* writer, 114 bool owns_writer); 115 static void CloseConnection(QuicConnection* connection); 116 static QuicEncryptedPacket* GetConnectionClosePacket( 117 QuicConnection* connection); 118 119 static void SetSupportedVersions(QuicConnection* connection, 120 QuicVersionVector versions); 121 122 private: 123 DISALLOW_COPY_AND_ASSIGN(QuicConnectionPeer); 124 }; 125 126 } // namespace test 127 128 } // namespace net 129 130 #endif // NET_QUIC_TEST_TOOLS_QUIC_CONNECTION_PEER_H_ 131