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

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

Issue 475113005: Refactoring: Create per-connection packet writers in QuicDispatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add new files to net/BUILD.gn 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_dispatcher.h ('k') | net/quic/quic_http_stream_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/quic/quic_dispatcher.h" 5 #include "net/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_connection_helper.h" 13 #include "net/quic/quic_connection_helper.h"
14 #include "net/quic/quic_flags.h" 14 #include "net/quic/quic_flags.h"
15 #include "net/quic/quic_per_connection_packet_writer.h"
15 #include "net/quic/quic_time_wait_list_manager.h" 16 #include "net/quic/quic_time_wait_list_manager.h"
16 #include "net/quic/quic_utils.h" 17 #include "net/quic/quic_utils.h"
17 18
18 namespace net { 19 namespace net {
19 20
20 using base::StringPiece; 21 using base::StringPiece;
21 using std::make_pair; 22 using std::make_pair;
22 using std::find; 23 using std::find;
23 24
24 class DeleteSessionsAlarm : public QuicAlarm::Delegate { 25 class DeleteSessionsAlarm : public QuicAlarm::Delegate {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 DCHECK(false); 148 DCHECK(false);
148 } 149 }
149 150
150 private: 151 private:
151 QuicDispatcher* dispatcher_; 152 QuicDispatcher* dispatcher_;
152 153
153 // Latched in OnUnauthenticatedPublicHeader for use later. 154 // Latched in OnUnauthenticatedPublicHeader for use later.
154 QuicConnectionId connection_id_; 155 QuicConnectionId connection_id_;
155 }; 156 };
156 157
158 QuicPacketWriter* QuicDispatcher::DefaultPacketWriterFactory::Create(
159 QuicServerPacketWriter* writer,
160 QuicConnection* connection) {
161 return new QuicPerConnectionPacketWriter(writer, connection);
162 }
163
164 QuicDispatcher::PacketWriterFactoryAdapter::PacketWriterFactoryAdapter(
165 QuicDispatcher* dispatcher)
166 : dispatcher_(dispatcher) {}
167
168 QuicDispatcher::PacketWriterFactoryAdapter::~PacketWriterFactoryAdapter() {}
169
170 QuicPacketWriter* QuicDispatcher::PacketWriterFactoryAdapter::Create(
171 QuicConnection* connection) const {
172 return dispatcher_->packet_writer_factory_->Create(
173 dispatcher_->writer_.get(),
174 connection);
175 }
176
157 QuicDispatcher::QuicDispatcher(const QuicConfig& config, 177 QuicDispatcher::QuicDispatcher(const QuicConfig& config,
158 const QuicCryptoServerConfig& crypto_config, 178 const QuicCryptoServerConfig& crypto_config,
159 const QuicVersionVector& supported_versions, 179 const QuicVersionVector& supported_versions,
180 PacketWriterFactory* packet_writer_factory,
160 QuicConnectionHelperInterface* helper) 181 QuicConnectionHelperInterface* helper)
161 : config_(config), 182 : config_(config),
162 crypto_config_(crypto_config), 183 crypto_config_(crypto_config),
163 helper_(helper), 184 helper_(helper),
164 delete_sessions_alarm_( 185 delete_sessions_alarm_(
165 helper_->CreateAlarm(new DeleteSessionsAlarm(this))), 186 helper_->CreateAlarm(new DeleteSessionsAlarm(this))),
187 packet_writer_factory_(packet_writer_factory),
188 connection_writer_factory_(this),
166 supported_versions_(supported_versions), 189 supported_versions_(supported_versions),
167 current_packet_(NULL), 190 current_packet_(NULL),
168 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true), 191 framer_(supported_versions, /*unused*/ QuicTime::Zero(), true),
169 framer_visitor_(new QuicFramerVisitor(this)) { 192 framer_visitor_(new QuicFramerVisitor(this)) {
170 framer_.set_visitor(framer_visitor_.get()); 193 framer_.set_visitor(framer_visitor_.get());
171 } 194 }
172 195
173 QuicDispatcher::~QuicDispatcher() { 196 QuicDispatcher::~QuicDispatcher() {
174 STLDeleteValues(&session_map_); 197 STLDeleteValues(&session_map_);
175 STLDeleteElements(&closed_session_list_); 198 STLDeleteElements(&closed_session_list_);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 // infinite loops in OnCanWrite. 355 // infinite loops in OnCanWrite.
333 return; 356 return;
334 } 357 }
335 write_blocked_list_.insert(make_pair(blocked_writer, true)); 358 write_blocked_list_.insert(make_pair(blocked_writer, true));
336 } 359 }
337 360
338 QuicSession* QuicDispatcher::CreateQuicSession( 361 QuicSession* QuicDispatcher::CreateQuicSession(
339 QuicConnectionId connection_id, 362 QuicConnectionId connection_id,
340 const IPEndPoint& server_address, 363 const IPEndPoint& server_address,
341 const IPEndPoint& client_address) { 364 const IPEndPoint& client_address) {
342 QuicPerConnectionPacketWriter* per_connection_packet_writer =
343 new QuicPerConnectionPacketWriter(writer_.get());
344 QuicConnection* connection =
345 CreateQuicConnection(connection_id,
346 server_address,
347 client_address,
348 per_connection_packet_writer);
349 QuicServerSession* session = new QuicServerSession( 365 QuicServerSession* session = new QuicServerSession(
350 config_, 366 config_,
351 connection, 367 CreateQuicConnection(connection_id, server_address, client_address),
352 per_connection_packet_writer,
353 this); 368 this);
354 session->InitializeSession(crypto_config_); 369 session->InitializeSession(crypto_config_);
355 return session; 370 return session;
356 } 371 }
357 372
358 QuicConnection* QuicDispatcher::CreateQuicConnection( 373 QuicConnection* QuicDispatcher::CreateQuicConnection(
359 QuicConnectionId connection_id, 374 QuicConnectionId connection_id,
360 const IPEndPoint& server_address, 375 const IPEndPoint& server_address,
361 const IPEndPoint& client_address, 376 const IPEndPoint& client_address) {
362 QuicPerConnectionPacketWriter* writer) { 377 return new QuicConnection(connection_id,
363 QuicConnection* connection; 378 client_address,
364 connection = new QuicConnection( 379 helper_,
365 connection_id, 380 connection_writer_factory_,
366 client_address, 381 /* owns_writer= */ true,
367 helper_, 382 /* is_server= */ true,
368 writer, 383 supported_versions_);
369 false /* owns_writer */,
370 true /* is_server */,
371 supported_versions_);
372 writer->set_connection(connection);
373 return connection;
374 } 384 }
375 385
376 QuicTimeWaitListManager* QuicDispatcher::CreateQuicTimeWaitListManager() { 386 QuicTimeWaitListManager* QuicDispatcher::CreateQuicTimeWaitListManager() {
377 return new QuicTimeWaitListManager( 387 return new QuicTimeWaitListManager(
378 writer_.get(), this, helper_, supported_versions()); 388 writer_.get(), this, helper_, supported_versions());
379 } 389 }
380 390
381 bool QuicDispatcher::HandlePacketForTimeWait( 391 bool QuicDispatcher::HandlePacketForTimeWait(
382 const QuicPacketPublicHeader& header) { 392 const QuicPacketPublicHeader& header) {
383 if (header.reset_flag) { 393 if (header.reset_flag) {
384 // Public reset packets do not have sequence numbers, so ignore the packet. 394 // Public reset packets do not have sequence numbers, so ignore the packet.
385 return false; 395 return false;
386 } 396 }
387 397
388 // Switch the framer to the correct version, so that the sequence number can 398 // Switch the framer to the correct version, so that the sequence number can
389 // be parsed correctly. 399 // be parsed correctly.
390 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId( 400 framer_.set_version(time_wait_list_manager_->GetQuicVersionFromConnectionId(
391 header.connection_id)); 401 header.connection_id));
392 402
393 // Continue parsing the packet to extract the sequence number. Then 403 // Continue parsing the packet to extract the sequence number. Then
394 // send it to the time wait manager in OnUnathenticatedHeader. 404 // send it to the time wait manager in OnUnathenticatedHeader.
395 return true; 405 return true;
396 } 406 }
397 407
398 } // namespace net 408 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_dispatcher.h ('k') | net/quic/quic_http_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698