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_
14 #include "base/basictypes.h"
15 #include "base/containers/hash_tables.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "net/quic/quic_crypto_server_stream.h"
18 #include "net/quic/quic_protocol.h"
19 #include "net/quic/quic_session.h"
23 class QuicBlockedWriterInterface
;
26 class QuicCryptoServerConfig
;
27 class ReliableQuicStream
;
32 class QuicServerSessionPeer
;
35 // An interface from the session to the entity owning the session.
36 // This lets the session notify its owner (the Dispatcher) when the connection
37 // is closed or blocked.
38 class QuicServerSessionVisitor
{
40 virtual ~QuicServerSessionVisitor() {}
42 virtual void OnConnectionClosed(QuicConnectionId connection_id
,
43 QuicErrorCode error
) = 0;
44 virtual void OnWriteBlocked(QuicBlockedWriterInterface
* blocked_writer
) = 0;
47 class QuicServerSession
: public QuicSession
{
49 QuicServerSession(const QuicConfig
& config
,
50 QuicConnection
* connection
,
51 QuicServerSessionVisitor
* visitor
);
53 // Override the base class to notify the owner of the connection close.
54 void OnConnectionClosed(QuicErrorCode error
, bool from_peer
) override
;
55 void OnWriteBlocked() override
;
57 // Sends a server config update to the client, containing new bandwidth
59 void OnCongestionWindowChange(QuicTime now
) override
;
61 ~QuicServerSession() override
;
63 virtual void InitializeSession(const QuicCryptoServerConfig
& crypto_config
);
65 const QuicCryptoServerStream
* crypto_stream() const {
66 return crypto_stream_
.get();
69 // Override base class to process FEC config received from client.
70 void OnConfigNegotiated() override
;
72 void set_serving_region(std::string serving_region
) {
73 serving_region_
= serving_region
;
77 // QuicSession methods:
78 QuicDataStream
* CreateIncomingDataStream(QuicStreamId id
) override
;
79 QuicDataStream
* CreateOutgoingDataStream() override
;
80 QuicCryptoServerStream
* GetCryptoStream() override
;
82 // If we should create an incoming stream, returns true. Otherwise
83 // does error handling, including communicating the error to the client and
84 // possibly closing the connection, and returns false.
85 virtual bool ShouldCreateIncomingDataStream(QuicStreamId id
);
87 virtual QuicCryptoServerStream
* CreateQuicCryptoServerStream(
88 const QuicCryptoServerConfig
& crypto_config
);
91 friend class test::QuicServerSessionPeer
;
93 scoped_ptr
<QuicCryptoServerStream
> crypto_stream_
;
94 QuicServerSessionVisitor
* visitor_
;
96 // The most recent bandwidth estimate sent to the client.
97 QuicBandwidth bandwidth_estimate_sent_to_client_
;
99 // Text describing server location. Sent to the client as part of the bandwith
100 // estimate in the source-address token. Optional, can be left empty.
101 std::string serving_region_
;
103 // Time at which we send the last SCUP to the client.
104 QuicTime last_scup_time_
;
106 // Number of packets sent to the peer, at the time we last sent a SCUP.
107 int64 last_scup_sequence_number_
;
109 DISALLOW_COPY_AND_ASSIGN(QuicServerSession
);
115 #endif // NET_TOOLS_QUIC_QUIC_SERVER_SESSION_H_