OLD | NEW |
(Empty) | |
| 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 // A QuicSession, which demuxes a single connection to individual streams. |
| 6 |
| 7 #ifndef NET_QUIC_QUIC_SESSION_H_ |
| 8 #define NET_QUIC_QUIC_SESSION_H_ |
| 9 |
| 10 #include <vector> |
| 11 |
| 12 #include "base/compiler_specific.h" |
| 13 #include "base/hash_tables.h" |
| 14 #include "net/base/ip_endpoint.h" |
| 15 #include "net/quic/quic_connection.h" |
| 16 #include "net/quic/quic_crypto_stream.h" |
| 17 #include "net/quic/quic_packet_creator.h" |
| 18 #include "net/quic/quic_protocol.h" |
| 19 #include "net/quic/reliable_quic_stream.h" |
| 20 |
| 21 namespace net { |
| 22 |
| 23 class QuicSession : public QuicConnectionVisitorInterface { |
| 24 public: |
| 25 QuicSession(QuicConnection* connection, bool is_server); |
| 26 |
| 27 virtual ~QuicSession(); |
| 28 |
| 29 // QuicConnectionVisitorInterface methods: |
| 30 virtual bool OnPacket(const IPEndPoint& self_address, |
| 31 const IPEndPoint& peer_address, |
| 32 const QuicPacketHeader& header, |
| 33 const std::vector<QuicStreamFrame>& frame) OVERRIDE; |
| 34 virtual void OnRstStream(const QuicRstStreamFrame& frame) OVERRIDE; |
| 35 virtual void ConnectionClose(QuicErrorCode error, bool from_peer) OVERRIDE; |
| 36 // Not needed for HTTP. |
| 37 virtual void OnAck(AckedPackets acked_packets) OVERRIDE {} |
| 38 |
| 39 // Called by streams when they want to write data to the peer. |
| 40 virtual ssize_t WriteData(QuicStreamId id, base::StringPiece data, |
| 41 QuicStreamOffset offset, bool fin); |
| 42 // Called by streams when they want to close the stream in both directions. |
| 43 void SendRstStream(QuicStreamId id, |
| 44 QuicErrorCode error, |
| 45 QuicStreamOffset offset); |
| 46 |
| 47 // Removes the stream associated with 'stream_id' from the active stream map. |
| 48 virtual void CloseStream(QuicStreamId stream_id); |
| 49 |
| 50 // Returns true once the crypto handshake is complete. |
| 51 virtual bool IsHandshakeComplete(); |
| 52 |
| 53 QuicConnection* connection() { return connection_.get(); } |
| 54 size_t num_active_requests() const { return stream_map_.size(); } |
| 55 const IPEndPoint& peer_address() const { |
| 56 return connection_->peer_address(); |
| 57 } |
| 58 |
| 59 QuicPacketCreator::Options* options() { return connection()->options(); } |
| 60 |
| 61 // Returns the number of currently open streams, including those which have |
| 62 // been implicitly created. |
| 63 virtual size_t GetNumOpenStreams(); |
| 64 |
| 65 protected: |
| 66 // Creates a new stream, owned by the caller, to handle a peer-initiated |
| 67 // stream. Returns NULL if max streams have already been opened. |
| 68 virtual ReliableQuicStream* CreateIncomingReliableStream(QuicStreamId id) = 0; |
| 69 |
| 70 // Create a new stream, owned by the caller, to handle a locally-initiated |
| 71 // stream. Returns NULL if max streams have already been opened. |
| 72 virtual ReliableQuicStream* CreateOutgoingReliableStream() = 0; |
| 73 |
| 74 // Return the reserved crypto stream. |
| 75 virtual QuicCryptoStream* GetCryptoStream() = 0; |
| 76 |
| 77 // Adds 'stream' to the active stream map. |
| 78 void ActivateStream(ReliableQuicStream* stream); |
| 79 |
| 80 // Returns the stream id for a new stream. |
| 81 QuicStreamId GetNextStreamId(); |
| 82 |
| 83 // Returns true if the stream existed previously and has been closed. |
| 84 bool IsClosedStream(QuicStreamId id); |
| 85 |
| 86 ReliableQuicStream* GetIncomingReliableStream(QuicStreamId stream_id); |
| 87 |
| 88 size_t get_max_open_streams() const { |
| 89 return max_open_streams_; |
| 90 } |
| 91 |
| 92 private: |
| 93 friend class QuicSessionPeer; |
| 94 |
| 95 typedef base::hash_map<QuicStreamId, ReliableQuicStream*> ReliableStreamMap; |
| 96 |
| 97 ReliableQuicStream* GetStream(const QuicStreamId stream_id); |
| 98 |
| 99 scoped_ptr<QuicConnection> connection_; |
| 100 |
| 101 // Returns the maximum number of streams this connection can open. |
| 102 const size_t max_open_streams_; |
| 103 |
| 104 // Map from StreamId to pointers to streams that are owned by the caller. |
| 105 ReliableStreamMap stream_map_; |
| 106 QuicStreamId next_stream_id_; |
| 107 bool is_server_; |
| 108 |
| 109 // Set of stream ids that have been "implicitly created" by receipt |
| 110 // of a stream id larger than the next expected stream id. |
| 111 base::hash_set<QuicStreamId> implicitly_created_streams_; |
| 112 QuicStreamId largest_peer_created_stream_id_; |
| 113 }; |
| 114 |
| 115 } // namespace net |
| 116 |
| 117 #endif // NET_QUIC_QUIC_SESSION_H_ |
OLD | NEW |