| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // A QuicSession, which demuxes a single connection to individual streams. | 5 // A QuicSession, which demuxes a single connection to individual streams. |
| 6 | 6 |
| 7 #ifndef NET_QUIC_QUIC_SESSION_H_ | 7 #ifndef NET_QUIC_QUIC_SESSION_H_ |
| 8 #define NET_QUIC_QUIC_SESSION_H_ | 8 #define NET_QUIC_QUIC_SESSION_H_ |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 QuicSession(QuicConnection* connection, bool is_server); | 33 QuicSession(QuicConnection* connection, bool is_server); |
| 34 | 34 |
| 35 virtual ~QuicSession(); | 35 virtual ~QuicSession(); |
| 36 | 36 |
| 37 // QuicConnectionVisitorInterface methods: | 37 // QuicConnectionVisitorInterface methods: |
| 38 virtual bool OnPacket(const IPEndPoint& self_address, | 38 virtual bool OnPacket(const IPEndPoint& self_address, |
| 39 const IPEndPoint& peer_address, | 39 const IPEndPoint& peer_address, |
| 40 const QuicPacketHeader& header, | 40 const QuicPacketHeader& header, |
| 41 const std::vector<QuicStreamFrame>& frame) OVERRIDE; | 41 const std::vector<QuicStreamFrame>& frame) OVERRIDE; |
| 42 virtual void OnRstStream(const QuicRstStreamFrame& frame) OVERRIDE; | 42 virtual void OnRstStream(const QuicRstStreamFrame& frame) OVERRIDE; |
| 43 virtual void OnGoAway(const QuicGoAwayFrame& frame) OVERRIDE; |
| 43 virtual void ConnectionClose(QuicErrorCode error, bool from_peer) OVERRIDE; | 44 virtual void ConnectionClose(QuicErrorCode error, bool from_peer) OVERRIDE; |
| 44 // Not needed for HTTP. | 45 // Not needed for HTTP. |
| 45 virtual void OnAck(AckedPackets acked_packets) OVERRIDE {} | 46 virtual void OnAck(const SequenceNumberSet& acked_packets) OVERRIDE {} |
| 46 virtual bool OnCanWrite() OVERRIDE; | 47 virtual bool OnCanWrite() OVERRIDE; |
| 47 | 48 |
| 48 // Called by streams when they want to write data to the peer. | 49 // Called by streams when they want to write data to the peer. |
| 49 // Returns a pair with the number of bytes consumed from data, and a boolean | 50 // Returns a pair with the number of bytes consumed from data, and a boolean |
| 50 // indicating if the fin bit was consumed. This does not indicate the data | 51 // indicating if the fin bit was consumed. This does not indicate the data |
| 51 // has been sent on the wire: it may have been turned into a packet and queued | 52 // has been sent on the wire: it may have been turned into a packet and queued |
| 52 // if the socket was unexpectedly blocked. | 53 // if the socket was unexpectedly blocked. |
| 53 virtual QuicConsumedData WriteData(QuicStreamId id, | 54 virtual QuicConsumedData WriteData(QuicStreamId id, |
| 54 base::StringPiece data, | 55 base::StringPiece data, |
| 55 QuicStreamOffset offset, | 56 QuicStreamOffset offset, |
| 56 bool fin); | 57 bool fin); |
| 57 // Called by streams when they want to close the stream in both directions. | 58 // Called by streams when they want to close the stream in both directions. |
| 58 void SendRstStream(QuicStreamId id, | 59 void SendRstStream(QuicStreamId id, |
| 59 QuicErrorCode error, | 60 QuicErrorCode error); |
| 60 QuicStreamOffset offset); | 61 |
| 62 // Called when the session wants to go away and not accept any new streams. |
| 63 void SendGoAway(QuicErrorCode error_code, const std::string& reason); |
| 61 | 64 |
| 62 // Removes the stream associated with 'stream_id' from the active stream map. | 65 // Removes the stream associated with 'stream_id' from the active stream map. |
| 63 virtual void CloseStream(QuicStreamId stream_id); | 66 virtual void CloseStream(QuicStreamId stream_id); |
| 64 | 67 |
| 65 // Returns true once the crypto handshake is complete. | 68 // Returns true once the crypto handshake is complete. |
| 66 virtual bool IsCryptoHandshakeComplete(); | 69 virtual bool IsCryptoHandshakeComplete(); |
| 67 | 70 |
| 68 // Called by the QuicCryptoStream when the handshake completes. | 71 // Called by the QuicCryptoStream when the handshake completes. |
| 69 // If |error| is QUIC_NO_ERROR then the handshake was succesful, | 72 // If |error| is QUIC_NO_ERROR then the handshake was succesful, |
| 70 // otherwise it failed. | 73 // otherwise it failed. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 83 QuicGuid guid() const { return connection_->guid(); } | 86 QuicGuid guid() const { return connection_->guid(); } |
| 84 | 87 |
| 85 QuicPacketCreator::Options* options() { return connection()->options(); } | 88 QuicPacketCreator::Options* options() { return connection()->options(); } |
| 86 | 89 |
| 87 // Returns the number of currently open streams, including those which have | 90 // Returns the number of currently open streams, including those which have |
| 88 // been implicitly created. | 91 // been implicitly created. |
| 89 virtual size_t GetNumOpenStreams() const; | 92 virtual size_t GetNumOpenStreams() const; |
| 90 | 93 |
| 91 void MarkWriteBlocked(QuicStreamId id); | 94 void MarkWriteBlocked(QuicStreamId id); |
| 92 | 95 |
| 96 bool goaway_received() const { |
| 97 return goaway_received_; |
| 98 } |
| 99 |
| 100 bool goaway_sent() const { |
| 101 return goaway_sent_; |
| 102 } |
| 103 |
| 93 protected: | 104 protected: |
| 94 // Creates a new stream, owned by the caller, to handle a peer-initiated | 105 // Creates a new stream, owned by the caller, to handle a peer-initiated |
| 95 // stream. Returns NULL and does error handling if the stream can not be | 106 // stream. Returns NULL and does error handling if the stream can not be |
| 96 // created. | 107 // created. |
| 97 virtual ReliableQuicStream* CreateIncomingReliableStream(QuicStreamId id) = 0; | 108 virtual ReliableQuicStream* CreateIncomingReliableStream(QuicStreamId id) = 0; |
| 98 | 109 |
| 99 // Create a new stream, owned by the caller, to handle a locally-initiated | 110 // Create a new stream, owned by the caller, to handle a locally-initiated |
| 100 // stream. Returns NULL if max streams have already been opened. | 111 // stream. Returns NULL if max streams have already been opened. |
| 101 virtual ReliableQuicStream* CreateOutgoingReliableStream() = 0; | 112 virtual ReliableQuicStream* CreateOutgoingReliableStream() = 0; |
| 102 | 113 |
| 103 // Return the reserved crypto stream. | 114 // Return the reserved crypto stream. |
| 104 virtual QuicCryptoStream* GetCryptoStream() = 0; | 115 virtual QuicCryptoStream* GetCryptoStream() = 0; |
| 105 | 116 |
| 106 // Adds 'stream' to the active stream map. | 117 // Adds 'stream' to the active stream map. |
| 107 virtual void ActivateStream(ReliableQuicStream* stream); | 118 virtual void ActivateStream(ReliableQuicStream* stream); |
| 108 | 119 |
| 109 // Returns the stream id for a new stream. | 120 // Returns the stream id for a new stream. |
| 110 QuicStreamId GetNextStreamId(); | 121 QuicStreamId GetNextStreamId(); |
| 111 | 122 |
| 112 ReliableQuicStream* GetIncomingReliableStream(QuicStreamId stream_id); | 123 ReliableQuicStream* GetIncomingReliableStream(QuicStreamId stream_id); |
| 113 | 124 |
| 114 size_t get_max_open_streams() const { | |
| 115 return max_open_streams_; | |
| 116 } | |
| 117 | |
| 118 protected: | |
| 119 // This is called after every call other than OnConnectionClose from the | 125 // This is called after every call other than OnConnectionClose from the |
| 120 // QuicConnectionVisitor to allow post-processing once the work has been done. | 126 // QuicConnectionVisitor to allow post-processing once the work has been done. |
| 121 // In this case, it deletes streams given that it's safe to do so (no other | 127 // In this case, it deletes streams given that it's safe to do so (no other |
| 122 // opterations are being done on the streams at this time) | 128 // operations are being done on the streams at this time) |
| 123 virtual void PostProcessAfterData(); | 129 virtual void PostProcessAfterData(); |
| 124 | 130 |
| 125 base::hash_map<QuicStreamId, ReliableQuicStream*>* streams() { | 131 base::hash_map<QuicStreamId, ReliableQuicStream*>* streams() { |
| 126 return &stream_map_; | 132 return &stream_map_; |
| 127 } | 133 } |
| 128 std::vector<ReliableQuicStream*>* closed_streams() { | 134 std::vector<ReliableQuicStream*>* closed_streams() { |
| 129 return &closed_streams_; | 135 return &closed_streams_; |
| 130 } | 136 } |
| 131 | 137 |
| 138 size_t get_max_open_streams() const { |
| 139 return max_open_streams_; |
| 140 } |
| 141 |
| 132 private: | 142 private: |
| 133 friend class test::QuicSessionPeer; | 143 friend class test::QuicSessionPeer; |
| 134 friend class VisitorShim; | 144 friend class VisitorShim; |
| 135 | 145 |
| 136 typedef base::hash_map<QuicStreamId, ReliableQuicStream*> ReliableStreamMap; | 146 typedef base::hash_map<QuicStreamId, ReliableQuicStream*> ReliableStreamMap; |
| 137 | 147 |
| 138 ReliableQuicStream* GetStream(const QuicStreamId stream_id); | 148 ReliableQuicStream* GetStream(const QuicStreamId stream_id); |
| 139 | 149 |
| 140 scoped_ptr<QuicConnection> connection_; | 150 scoped_ptr<QuicConnection> connection_; |
| 141 | 151 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 154 bool is_server_; | 164 bool is_server_; |
| 155 | 165 |
| 156 // Set of stream ids that have been "implicitly created" by receipt | 166 // Set of stream ids that have been "implicitly created" by receipt |
| 157 // of a stream id larger than the next expected stream id. | 167 // of a stream id larger than the next expected stream id. |
| 158 base::hash_set<QuicStreamId> implicitly_created_streams_; | 168 base::hash_set<QuicStreamId> implicitly_created_streams_; |
| 159 | 169 |
| 160 // A list of streams which need to write more data. | 170 // A list of streams which need to write more data. |
| 161 std::list<QuicStreamId> write_blocked_streams_; | 171 std::list<QuicStreamId> write_blocked_streams_; |
| 162 | 172 |
| 163 QuicStreamId largest_peer_created_stream_id_; | 173 QuicStreamId largest_peer_created_stream_id_; |
| 174 |
| 175 // Whether a GoAway has been received. |
| 176 bool goaway_received_; |
| 177 // Whether a GoAway has been sent. |
| 178 bool goaway_sent_; |
| 164 }; | 179 }; |
| 165 | 180 |
| 166 } // namespace net | 181 } // namespace net |
| 167 | 182 |
| 168 #endif // NET_QUIC_QUIC_SESSION_H_ | 183 #endif // NET_QUIC_QUIC_SESSION_H_ |
| OLD | NEW |