OLD | NEW |
| (Empty) |
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 <string> | |
12 #include <vector> | |
13 | |
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_per_connection_packet_writer.h" | |
19 #include "net/quic/quic_protocol.h" | |
20 #include "net/quic/quic_session.h" | |
21 | |
22 namespace net { | |
23 | |
24 namespace test { | |
25 class QuicServerSessionPeer; | |
26 } // namespace test | |
27 | |
28 class QuicBlockedWriterInterface; | |
29 class QuicConfig; | |
30 class QuicConnection; | |
31 class QuicCryptoServerConfig; | |
32 class ReliableQuicStream; | |
33 | |
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, blocked, or added/removed from the time-wait list. | |
37 class QuicServerSessionVisitor { | |
38 public: | |
39 virtual ~QuicServerSessionVisitor() {} | |
40 | |
41 virtual void OnConnectionClosed(QuicConnectionId connection_id, | |
42 QuicErrorCode error) = 0; | |
43 virtual void OnWriteBlocked(QuicBlockedWriterInterface* blocked_writer) = 0; | |
44 // Called after the given connection is added to the time-wait list. | |
45 virtual void OnConnectionAddedToTimeWaitList(QuicConnectionId connection_id) { | |
46 } | |
47 // Called after the given connection is removed from the time-wait list. | |
48 virtual void OnConnectionRemovedFromTimeWaitList( | |
49 QuicConnectionId connection_id) {} | |
50 }; | |
51 | |
52 class QuicServerSession : public QuicSession { | |
53 public: | |
54 QuicServerSession(const QuicConfig& config, | |
55 QuicConnection* connection, | |
56 QuicServerSessionVisitor* visitor); | |
57 | |
58 // Override the base class to notify the owner of the connection close. | |
59 void OnConnectionClosed(QuicErrorCode error, bool from_peer) override; | |
60 void OnWriteBlocked() override; | |
61 | |
62 // Sends a server config update to the client, containing new bandwidth | |
63 // estimate. | |
64 void OnCongestionWindowChange(QuicTime now) override; | |
65 | |
66 ~QuicServerSession() override; | |
67 | |
68 virtual void InitializeSession(const QuicCryptoServerConfig& crypto_config); | |
69 | |
70 const QuicCryptoServerStream* crypto_stream() const { | |
71 return crypto_stream_.get(); | |
72 } | |
73 | |
74 // Override base class to process FEC config received from client. | |
75 void OnConfigNegotiated() override; | |
76 | |
77 void set_serving_region(std::string serving_region) { | |
78 serving_region_ = serving_region; | |
79 } | |
80 | |
81 protected: | |
82 // QuicSession methods: | |
83 QuicDataStream* CreateIncomingDataStream(QuicStreamId id) override; | |
84 QuicDataStream* CreateOutgoingDataStream() override; | |
85 QuicCryptoServerStream* GetCryptoStream() override; | |
86 | |
87 // If we should create an incoming stream, returns true. Otherwise | |
88 // does error handling, including communicating the error to the client and | |
89 // possibly closing the connection, and returns false. | |
90 virtual bool ShouldCreateIncomingDataStream(QuicStreamId id); | |
91 | |
92 virtual QuicCryptoServerStream* CreateQuicCryptoServerStream( | |
93 const QuicCryptoServerConfig& crypto_config); | |
94 | |
95 private: | |
96 friend class test::QuicServerSessionPeer; | |
97 | |
98 scoped_ptr<QuicCryptoServerStream> crypto_stream_; | |
99 QuicServerSessionVisitor* visitor_; | |
100 | |
101 // The most recent bandwidth estimate sent to the client. | |
102 QuicBandwidth bandwidth_estimate_sent_to_client_; | |
103 | |
104 // Text describing server location. Sent to the client as part of the bandwith | |
105 // estimate in the source-address token. Optional, can be left empty. | |
106 std::string serving_region_; | |
107 | |
108 // Time at which we send the last SCUP to the client. | |
109 QuicTime last_scup_time_; | |
110 | |
111 // Number of packets sent to the peer, at the time we last sent a SCUP. | |
112 int64 last_scup_sequence_number_; | |
113 | |
114 DISALLOW_COPY_AND_ASSIGN(QuicServerSession); | |
115 }; | |
116 | |
117 } // namespace net | |
118 | |
119 #endif // NET_QUIC_QUIC_SERVER_SESSION_H_ | |
OLD | NEW |