1// Copyright 2014 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 server specific QuicSession subclass. 6 7#ifndef NET_QUIC_QUIC_SERVER_SESSION_H_ 8#define NET_QUIC_QUIC_SERVER_SESSION_H_ 9 10#include <set> 11#include <vector> 12 13#include "base/basictypes.h" 14#include "base/containers/hash_tables.h" 15#include "base/memory/scoped_ptr.h" 16#include "net/quic/quic_crypto_server_stream.h" 17#include "net/quic/quic_per_connection_packet_writer.h" 18#include "net/quic/quic_protocol.h" 19#include "net/quic/quic_session.h" 20 21namespace net { 22 23class QuicBlockedWriterInterface; 24class QuicConfig; 25class QuicConnection; 26class QuicCryptoServerConfig; 27class ReliableQuicStream; 28 29namespace test { 30class QuicServerSessionPeer; 31} // namespace test 32 33// An interface from the session to the entity owning the session. 34// This lets the session notify its owner (the Dispatcher) when the connection 35// is closed or blocked. 36class QuicServerSessionVisitor { 37 public: 38 virtual ~QuicServerSessionVisitor() {} 39 40 virtual void OnConnectionClosed(QuicConnectionId connection_id, 41 QuicErrorCode error) = 0; 42 virtual void OnWriteBlocked(QuicBlockedWriterInterface* blocked_writer) = 0; 43}; 44 45class QuicServerSession : public QuicSession { 46 public: 47 QuicServerSession(const QuicConfig& config, 48 QuicConnection* connection, 49 QuicServerSessionVisitor* visitor); 50 51 // Override the base class to notify the owner of the connection close. 52 virtual void OnConnectionClosed(QuicErrorCode error, bool from_peer) OVERRIDE; 53 virtual void OnWriteBlocked() OVERRIDE; 54 55 // Sends a server config update to the client, containing new bandwidth 56 // estimate. 57 virtual void OnCongestionWindowChange(QuicTime now) OVERRIDE; 58 59 virtual ~QuicServerSession(); 60 61 virtual void InitializeSession(const QuicCryptoServerConfig& crypto_config); 62 63 const QuicCryptoServerStream* crypto_stream() const { 64 return crypto_stream_.get(); 65 } 66 67 // Override base class to process FEC config received from client. 68 virtual void OnConfigNegotiated() OVERRIDE; 69 70 void set_serving_region(string serving_region) { 71 serving_region_ = serving_region; 72 } 73 74 protected: 75 // QuicSession methods: 76 virtual QuicDataStream* CreateIncomingDataStream(QuicStreamId id) OVERRIDE; 77 virtual QuicDataStream* CreateOutgoingDataStream() OVERRIDE; 78 virtual QuicCryptoServerStream* GetCryptoStream() OVERRIDE; 79 80 // If we should create an incoming stream, returns true. Otherwise 81 // does error handling, including communicating the error to the client and 82 // possibly closing the connection, and returns false. 83 virtual bool ShouldCreateIncomingDataStream(QuicStreamId id); 84 85 virtual QuicCryptoServerStream* CreateQuicCryptoServerStream( 86 const QuicCryptoServerConfig& crypto_config); 87 88 private: 89 friend class test::QuicServerSessionPeer; 90 91 scoped_ptr<QuicCryptoServerStream> crypto_stream_; 92 QuicServerSessionVisitor* visitor_; 93 94 // The most recent bandwidth estimate sent to the client. 95 QuicBandwidth bandwidth_estimate_sent_to_client_; 96 97 // Text describing server location. Sent to the client as part of the bandwith 98 // estimate in the source-address token. Optional, can be left empty. 99 string serving_region_; 100 101 // Time at which we send the last SCUP to the client. 102 QuicTime last_server_config_update_time_; 103 104 DISALLOW_COPY_AND_ASSIGN(QuicServerSession); 105}; 106 107} // namespace net 108 109#endif // NET_QUIC_QUIC_SERVER_SESSION_H_ 110