Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: net/tools/quic/quic_dispatcher.cc

Issue 467963002: Refactoring: Create per-connection packet writers in QuicDispatcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "net/tools/quic/quic_dispatcher.h" 5 #include "net/tools/quic/quic_dispatcher.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include "base/debug/stack_trace.h" 9 #include "base/debug/stack_trace.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "net/quic/quic_blocked_writer_interface.h" 12 #include "net/quic/quic_blocked_writer_interface.h"
13 #include "net/quic/quic_flags.h" 13 #include "net/quic/quic_flags.h"
14 #include "net/quic/quic_utils.h" 14 #include "net/quic/quic_utils.h"
15 #include "net/tools/epoll_server/epoll_server.h" 15 #include "net/tools/epoll_server/epoll_server.h"
16 #include "net/tools/quic/quic_default_packet_writer.h" 16 #include "net/tools/quic/quic_default_packet_writer.h"
17 #include "net/tools/quic/quic_epoll_connection_helper.h" 17 #include "net/tools/quic/quic_epoll_connection_helper.h"
18 #include "net/tools/quic/quic_per_connection_packet_writer.h"
18 #include "net/tools/quic/quic_socket_utils.h" 19 #include "net/tools/quic/quic_socket_utils.h"
19 #include "net/tools/quic/quic_time_wait_list_manager.h" 20 #include "net/tools/quic/quic_time_wait_list_manager.h"
20 21
21 namespace net { 22 namespace net {
22 23
23 namespace tools { 24 namespace tools {
24 25
25 using base::StringPiece; 26 using base::StringPiece;
26 using std::make_pair; 27 using std::make_pair;
27 28
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 DCHECK(false); 153 DCHECK(false);
153 } 154 }
154 155
155 private: 156 private:
156 QuicDispatcher* dispatcher_; 157 QuicDispatcher* dispatcher_;
157 158
158 // Latched in OnUnauthenticatedPublicHeader for use later. 159 // Latched in OnUnauthenticatedPublicHeader for use later.
159 QuicConnectionId connection_id_; 160 QuicConnectionId connection_id_;
160 }; 161 };
161 162
163 QuicPacketWriter* QuicDispatcher::DefaultPacketWriterFactory::Create(
164 QuicPacketWriter* writer,
165 QuicConnection* connection) {
166 return new QuicPerConnectionPacketWriter(writer, connection);
167 }
168
169 QuicDispatcher::PacketWriterFactoryAdapter::PacketWriterFactoryAdapter(
170 QuicDispatcher* dispatcher)
171 : dispatcher_(dispatcher) {}
172
173 QuicDispatcher::PacketWriterFactoryAdapter::~PacketWriterFactoryAdapter() {}
174
175 QuicPacketWriter* QuicDispatcher::PacketWriterFactoryAdapter::Create(
176 QuicConnection* connection) const {
177 return dispatcher_->packet_writer_factory_->Create(
178 dispatcher_->writer_.get(),
179 connection);
180 }
181
162 QuicDispatcher::QuicDispatcher(const QuicConfig& config, 182 QuicDispatcher::QuicDispatcher(const QuicConfig& config,
163 const QuicCryptoServerConfig& crypto_config, 183 const QuicCryptoServerConfig& crypto_config,
164 const QuicVersionVector& supported_versions, 184 const QuicVersionVector& supported_versions,
185 PacketWriterFactory* packet_writer_factory,
165 EpollServer* epoll_server) 186 EpollServer* epoll_server)
166 : config_(config), 187 : config_(config),
167 crypto_config_(crypto_config), 188 crypto_config_(crypto_config),
168 delete_sessions_alarm_(new DeleteSessionsAlarm(this)), 189 delete_sessions_alarm_(new DeleteSessionsAlarm(this)),
169 epoll_server_(epoll_server), 190 epoll_server_(epoll_server),
170 helper_(new QuicEpollConnectionHelper(epoll_server_)), 191 helper_(new QuicEpollConnectionHelper(epoll_server_)),
192 packet_writer_factory_(packet_writer_factory),
193 connection_writer_factory_(this),
171 supported_versions_(supported_versions), 194 supported_versions_(supported_versions),
172 current_packet_(NULL), 195 current_packet_(NULL),
173 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true), 196 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true),
174 framer_visitor_(new QuicFramerVisitor(this)) { 197 framer_visitor_(new QuicFramerVisitor(this)) {
175 framer_.set_visitor(framer_visitor_.get()); 198 framer_.set_visitor(framer_visitor_.get());
176 } 199 }
177 200
178 QuicDispatcher::~QuicDispatcher() { 201 QuicDispatcher::~QuicDispatcher() {
179 STLDeleteValues(&session_map_); 202 STLDeleteValues(&session_map_);
180 STLDeleteElements(&closed_session_list_); 203 STLDeleteElements(&closed_session_list_);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 return session; 382 return session;
360 } 383 }
361 384
362 QuicConnection* QuicDispatcher::CreateQuicConnection( 385 QuicConnection* QuicDispatcher::CreateQuicConnection(
363 QuicConnectionId connection_id, 386 QuicConnectionId connection_id,
364 const IPEndPoint& server_address, 387 const IPEndPoint& server_address,
365 const IPEndPoint& client_address) { 388 const IPEndPoint& client_address) {
366 return new QuicConnection(connection_id, 389 return new QuicConnection(connection_id,
367 client_address, 390 client_address,
368 helper_.get(), 391 helper_.get(),
369 writer_.get(), 392 connection_writer_factory_,
370 false /* owns_writer */, 393 /* owns_writer= */ true,
371 true /* is_server */, 394 /* is_server= */ true,
372 supported_versions_); 395 supported_versions_);
373 } 396 }
374 397
375 QuicTimeWaitListManager* QuicDispatcher::CreateQuicTimeWaitListManager() { 398 QuicTimeWaitListManager* QuicDispatcher::CreateQuicTimeWaitListManager() {
376 return new QuicTimeWaitListManager( 399 return new QuicTimeWaitListManager(
377 writer_.get(), this, epoll_server(), supported_versions()); 400 writer_.get(), this, epoll_server(), supported_versions());
378 } 401 }
379 402
380 bool QuicDispatcher::HandlePacketForTimeWait( 403 bool QuicDispatcher::HandlePacketForTimeWait(
381 const QuicPacketPublicHeader& header) { 404 const QuicPacketPublicHeader& header) {
382 if (header.reset_flag) { 405 if (header.reset_flag) {
383 // Public reset packets do not have sequence numbers, so ignore the packet. 406 // Public reset packets do not have sequence numbers, so ignore the packet.
384 return false; 407 return false;
385 } 408 }
386 409
387 // Switch the framer to the correct version, so that the sequence number can 410 // Switch the framer to the correct version, so that the sequence number can
388 // be parsed correctly. 411 // be parsed correctly.
389 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( 412 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId(
390 header.connection_id)); 413 header.connection_id));
391 414
392 // Continue parsing the packet to extract the sequence number. Then 415 // Continue parsing the packet to extract the sequence number. Then
393 // send it to the time wait manager in OnUnathenticatedHeader. 416 // send it to the time wait manager in OnUnathenticatedHeader.
394 return true; 417 return true;
395 } 418 }
396 419
397 } // namespace tools 420 } // namespace tools
398 } // namespace net 421 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698