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.
5 // A server specific QuicSession subclass.
7 #ifndef NET_TOOLS_QUIC_QUIC_SERVER_SESSION_H_
8 #define NET_TOOLS_QUIC_QUIC_SERVER_SESSION_H_
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_protocol.h"
18 #include "net/quic/quic_session.h"
22 class QuicBlockedWriterInterface;
25 class QuicCryptoServerConfig;
26 class ReliableQuicStream;
31 class QuicServerSessionPeer;
34 // An interface from the session to the entity owning the session.
35 // This lets the session notify its owner (the Dispatcher) when the connection
36 // is closed or blocked.
37 class QuicServerSessionVisitor {
39 virtual ~QuicServerSessionVisitor() {}
41 virtual void OnConnectionClosed(QuicConnectionId connection_id,
42 QuicErrorCode error) = 0;
43 virtual void OnWriteBlocked(QuicBlockedWriterInterface* blocked_writer) = 0;
46 class QuicServerSession : public QuicSession {
48 QuicServerSession(const QuicConfig& config,
49 QuicConnection* connection,
50 QuicServerSessionVisitor* visitor);
52 // Override the base class to notify the owner of the connection close.
53 virtual void OnConnectionClosed(QuicErrorCode error, bool from_peer) OVERRIDE;
54 virtual void OnWriteBlocked() OVERRIDE;
56 // Sends a server config update to the client, containing new bandwidth
58 virtual void OnCongestionWindowChange(QuicTime now) OVERRIDE;
60 virtual ~QuicServerSession();
62 virtual void InitializeSession(const QuicCryptoServerConfig& crypto_config);
64 const QuicCryptoServerStream* crypto_stream() const {
65 return crypto_stream_.get();
68 // Override base class to process FEC config received from client.
69 virtual void OnConfigNegotiated() OVERRIDE;
71 void set_serving_region(string serving_region) {
72 serving_region_ = serving_region;
76 // QuicSession methods:
77 virtual QuicDataStream* CreateIncomingDataStream(QuicStreamId id) OVERRIDE;
78 virtual QuicDataStream* CreateOutgoingDataStream() OVERRIDE;
79 virtual QuicCryptoServerStream* GetCryptoStream() OVERRIDE;
81 // If we should create an incoming stream, returns true. Otherwise
82 // does error handling, including communicating the error to the client and
83 // possibly closing the connection, and returns false.
84 virtual bool ShouldCreateIncomingDataStream(QuicStreamId id);
86 virtual QuicCryptoServerStream* CreateQuicCryptoServerStream(
87 const QuicCryptoServerConfig& crypto_config);
90 friend class test::QuicServerSessionPeer;
92 scoped_ptr<QuicCryptoServerStream> crypto_stream_;
93 QuicServerSessionVisitor* visitor_;
95 // The most recent bandwidth estimate sent to the client.
96 QuicBandwidth bandwidth_estimate_sent_to_client_;
98 // Text describing server location. Sent to the client as part of the bandwith
99 // estimate in the source-address token. Optional, can be left empty.
100 string serving_region_;
102 // Time at which we send the last SCUP to the client.
103 QuicTime last_server_config_update_time_;
105 DISALLOW_COPY_AND_ASSIGN(QuicServerSession);
111 #endif // NET_TOOLS_QUIC_QUIC_SERVER_SESSION_H_