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 server side dispatcher which dispatches a given client's data to their | 5 // A server side dispatcher which dispatches a given client's data to their |
6 // stream. | 6 // stream. |
7 | 7 |
8 #ifndef NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ | 8 #ifndef NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ |
9 #define NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ | 9 #define NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ |
10 | 10 |
11 #include <list> | 11 #include <list> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "net/base/ip_endpoint.h" | 16 #include "net/base/ip_endpoint.h" |
17 #include "net/base/linked_hash_map.h" | 17 #include "net/base/linked_hash_map.h" |
18 #include "net/quic/quic_blocked_writer_interface.h" | 18 #include "net/quic/quic_blocked_writer_interface.h" |
19 #include "net/quic/quic_packet_writer.h" | |
20 #include "net/quic/quic_protocol.h" | 19 #include "net/quic/quic_protocol.h" |
21 #include "net/tools/epoll_server/epoll_server.h" | 20 #include "net/tools/epoll_server/epoll_server.h" |
22 #include "net/tools/quic/quic_server_session.h" | 21 #include "net/tools/quic/quic_server_session.h" |
23 #include "net/tools/quic/quic_time_wait_list_manager.h" | 22 #include "net/tools/quic/quic_time_wait_list_manager.h" |
24 | 23 |
25 #if defined(COMPILER_GCC) | 24 #if defined(COMPILER_GCC) |
26 namespace BASE_HASH_NAMESPACE { | 25 namespace BASE_HASH_NAMESPACE { |
27 template<> | 26 template<> |
28 struct hash<net::QuicBlockedWriterInterface*> { | 27 struct hash<net::QuicBlockedWriterInterface*> { |
29 std::size_t operator()( | 28 std::size_t operator()( |
(...skipping 16 matching lines...) Expand all Loading... |
46 | 45 |
47 class QuicPacketWriterWrapper; | 46 class QuicPacketWriterWrapper; |
48 | 47 |
49 namespace test { | 48 namespace test { |
50 class QuicDispatcherPeer; | 49 class QuicDispatcherPeer; |
51 } // namespace test | 50 } // namespace test |
52 | 51 |
53 class DeleteSessionsAlarm; | 52 class DeleteSessionsAlarm; |
54 class QuicEpollConnectionHelper; | 53 class QuicEpollConnectionHelper; |
55 | 54 |
56 class QuicDispatcher : public QuicPacketWriter, | 55 class QuicDispatcher : public QuicServerSessionVisitor { |
57 public QuicServerSessionVisitor { | |
58 public: | 56 public: |
59 // Ideally we'd have a linked_hash_set: the boolean is unused. | 57 // Ideally we'd have a linked_hash_set: the boolean is unused. |
60 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; | 58 typedef linked_hash_map<QuicBlockedWriterInterface*, bool> WriteBlockedList; |
61 | 59 |
62 // Due to the way delete_sessions_closure_ is registered, the Dispatcher | 60 // Due to the way delete_sessions_closure_ is registered, the Dispatcher |
63 // must live until epoll_server Shutdown. |supported_versions| specifies the | 61 // must live until epoll_server Shutdown. |supported_versions| specifies the |
64 // list of supported QUIC versions. | 62 // list of supported QUIC versions. |
65 QuicDispatcher(const QuicConfig& config, | 63 QuicDispatcher(const QuicConfig& config, |
66 const QuicCryptoServerConfig& crypto_config, | 64 const QuicCryptoServerConfig& crypto_config, |
67 const QuicVersionVector& supported_versions, | 65 const QuicVersionVector& supported_versions, |
68 EpollServer* epoll_server); | 66 EpollServer* epoll_server); |
69 | 67 |
70 virtual ~QuicDispatcher(); | 68 virtual ~QuicDispatcher(); |
71 | 69 |
72 void Initialize(int fd); | 70 void Initialize(int fd); |
73 | 71 |
74 // QuicPacketWriter | |
75 virtual WriteResult WritePacket( | |
76 const char* buffer, size_t buf_len, | |
77 const IPAddressNumber& self_address, | |
78 const IPEndPoint& peer_address, | |
79 QuicBlockedWriterInterface* writer) OVERRIDE; | |
80 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE; | |
81 virtual bool IsWriteBlocked() const OVERRIDE; | |
82 virtual void SetWritable() OVERRIDE; | |
83 | |
84 // Process the incoming packet by creating a new session, passing it to | 72 // Process the incoming packet by creating a new session, passing it to |
85 // an existing session, or passing it to the TimeWaitListManager. | 73 // an existing session, or passing it to the TimeWaitListManager. |
86 virtual void ProcessPacket(const IPEndPoint& server_address, | 74 virtual void ProcessPacket(const IPEndPoint& server_address, |
87 const IPEndPoint& client_address, | 75 const IPEndPoint& client_address, |
88 const QuicEncryptedPacket& packet); | 76 const QuicEncryptedPacket& packet); |
89 | 77 |
90 // Called when the underyling connection becomes writable to allow | 78 // Called when the underyling connection becomes writable to allow |
91 // queued writes to happen. | 79 // queued writes to happen. |
92 // | 80 // |
93 // Returns true if more writes are possible, false otherwise. | 81 // Returns true if more writes are possible, false otherwise. |
94 virtual bool OnCanWrite(); | 82 virtual bool OnCanWrite(); |
95 | 83 |
96 // Sends ConnectionClose frames to all connected clients. | 84 // Sends ConnectionClose frames to all connected clients. |
97 void Shutdown(); | 85 void Shutdown(); |
98 | 86 |
99 // QuicServerSessionVisitor interface implementation: | 87 // QuicServerSessionVisitor interface implementation: |
100 // Ensure that the closed connection is cleaned up asynchronously. | 88 // Ensure that the closed connection is cleaned up asynchronously. |
101 virtual void OnConnectionClosed(QuicGuid guid, QuicErrorCode error) OVERRIDE; | 89 virtual void OnConnectionClosed(QuicGuid guid, QuicErrorCode error) OVERRIDE; |
102 | 90 |
103 // Queues the blocked writer for later resumption. | 91 // Queues the blocked writer for later resumption. |
104 virtual void OnWriteBlocked(QuicBlockedWriterInterface* writer) OVERRIDE; | 92 virtual void OnWriteBlocked(QuicBlockedWriterInterface* writer) OVERRIDE; |
105 | 93 |
106 typedef base::hash_map<QuicGuid, QuicSession*> SessionMap; | 94 typedef base::hash_map<QuicGuid, QuicSession*> SessionMap; |
107 | 95 |
108 virtual QuicSession* CreateQuicSession( | |
109 QuicGuid guid, | |
110 const IPEndPoint& server_address, | |
111 const IPEndPoint& client_address); | |
112 | |
113 // Deletes all sessions on the closed session list and clears the list. | 96 // Deletes all sessions on the closed session list and clears the list. |
114 void DeleteSessions(); | 97 void DeleteSessions(); |
115 | 98 |
116 const SessionMap& session_map() const { return session_map_; } | 99 const SessionMap& session_map() const { return session_map_; } |
117 | 100 |
118 WriteBlockedList* write_blocked_list() { return &write_blocked_list_; } | 101 WriteBlockedList* write_blocked_list() { return &write_blocked_list_; } |
119 | 102 |
120 protected: | 103 protected: |
121 // Instantiates a new low-level packet writer. Caller takes ownership of the | 104 // Instantiates a new low-level packet writer. Caller takes ownership of the |
122 // returned object. | 105 // returned object. |
123 QuicPacketWriter* CreateWriter(int fd); | 106 QuicPacketWriter* CreateWriter(int fd); |
124 | 107 |
125 // Instantiates a new top-level writer wrapper. Takes ownership of |writer|. | 108 // Instantiates a new top-level writer wrapper. Takes ownership of |writer|. |
126 // Caller takes ownership of the returned object. | 109 // Caller takes ownership of the returned object. |
127 virtual QuicPacketWriterWrapper* CreateWriterWrapper( | 110 virtual QuicPacketWriterWrapper* CreateWriterWrapper( |
128 QuicPacketWriter* writer); | 111 QuicPacketWriter* writer); |
129 | 112 |
| 113 virtual QuicSession* CreateQuicSession(QuicGuid guid, |
| 114 const IPEndPoint& server_address, |
| 115 const IPEndPoint& client_address); |
| 116 |
| 117 QuicConnection* CreateQuicConnection(QuicGuid guid, |
| 118 const IPEndPoint& server_address, |
| 119 const IPEndPoint& client_address); |
| 120 |
130 // Replaces the packet writer with |writer|. Takes ownership of |writer|. | 121 // Replaces the packet writer with |writer|. Takes ownership of |writer|. |
131 void set_writer(QuicPacketWriter* writer); | 122 void set_writer(QuicPacketWriter* writer); |
132 | 123 |
133 QuicTimeWaitListManager* time_wait_list_manager() { | 124 QuicTimeWaitListManager* time_wait_list_manager() { |
134 return time_wait_list_manager_.get(); | 125 return time_wait_list_manager_.get(); |
135 } | 126 } |
136 | 127 |
137 QuicEpollConnectionHelper* helper() { return helper_.get(); } | 128 QuicEpollConnectionHelper* helper() { return helper_.get(); } |
138 EpollServer* epoll_server() { return epoll_server_; } | 129 EpollServer* epoll_server() { return epoll_server_; } |
139 | 130 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 QuicFramer framer_; | 207 QuicFramer framer_; |
217 scoped_ptr<QuicFramerVisitor> framer_visitor_; | 208 scoped_ptr<QuicFramerVisitor> framer_visitor_; |
218 | 209 |
219 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); | 210 DISALLOW_COPY_AND_ASSIGN(QuicDispatcher); |
220 }; | 211 }; |
221 | 212 |
222 } // namespace tools | 213 } // namespace tools |
223 } // namespace net | 214 } // namespace net |
224 | 215 |
225 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ | 216 #endif // NET_TOOLS_QUIC_QUIC_DISPATCHER_H_ |
OLD | NEW |