| OLD | NEW |
| 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/tools/quic/quic_simple_server.h" | 5 #include "net/tools/quic/quic_simple_server.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 // Allocate some extra space so we can send an error if the client goes over | 30 // Allocate some extra space so we can send an error if the client goes over |
| 31 // the limit. | 31 // the limit. |
| 32 const int kReadBufferSize = 2 * kMaxPacketSize; | 32 const int kReadBufferSize = 2 * kMaxPacketSize; |
| 33 | 33 |
| 34 class SimpleQuicDispatcher : public QuicDispatcher { | 34 class SimpleQuicDispatcher : public QuicDispatcher { |
| 35 public: | 35 public: |
| 36 SimpleQuicDispatcher(const QuicConfig& config, | 36 SimpleQuicDispatcher(const QuicConfig& config, |
| 37 const QuicCryptoServerConfig* crypto_config, | 37 const QuicCryptoServerConfig* crypto_config, |
| 38 const QuicVersionVector& supported_versions, | 38 const QuicVersionVector& supported_versions, |
| 39 QuicConnectionHelperInterface* helper) | 39 QuicConnectionHelperInterface* helper, |
| 40 QuicAlarmFactory* alarm_factory) |
| 40 : QuicDispatcher(config, crypto_config, supported_versions, | 41 : QuicDispatcher(config, crypto_config, supported_versions, |
| 41 std::unique_ptr<QuicConnectionHelperInterface>(helper)) {
} | 42 std::unique_ptr<QuicConnectionHelperInterface>(helper), |
| 43 std::unique_ptr<QuicAlarmFactory>(alarm_factory)) {} |
| 42 | 44 |
| 43 protected: | 45 protected: |
| 44 QuicServerSessionBase* CreateQuicSession( | 46 QuicServerSessionBase* CreateQuicSession( |
| 45 QuicConnectionId connection_id, | 47 QuicConnectionId connection_id, |
| 46 const IPEndPoint& client_address) override { | 48 const IPEndPoint& client_address) override { |
| 47 QuicServerSessionBase* session = | 49 QuicServerSessionBase* session = |
| 48 QuicDispatcher::CreateQuicSession(connection_id, client_address); | 50 QuicDispatcher::CreateQuicSession(connection_id, client_address); |
| 49 static_cast<QuicSimplePerConnectionPacketWriter*>( | 51 static_cast<QuicSimplePerConnectionPacketWriter*>( |
| 50 session->connection()->writer()) | 52 session->connection()->writer()) |
| 51 ->set_connection(session->connection()); | 53 ->set_connection(session->connection()); |
| 52 return session; | 54 return session; |
| 53 } | 55 } |
| 54 | 56 |
| 55 QuicPacketWriter* CreatePerConnectionWriter() override { | 57 QuicPacketWriter* CreatePerConnectionWriter() override { |
| 56 return new QuicSimplePerConnectionPacketWriter( | 58 return new QuicSimplePerConnectionPacketWriter( |
| 57 static_cast<QuicSimpleServerPacketWriter*>(writer())); | 59 static_cast<QuicSimpleServerPacketWriter*>(writer())); |
| 58 } | 60 } |
| 59 }; | 61 }; |
| 60 | 62 |
| 61 } // namespace | 63 } // namespace |
| 62 | 64 |
| 63 QuicSimpleServer::QuicSimpleServer(ProofSource* proof_source, | 65 QuicSimpleServer::QuicSimpleServer(ProofSource* proof_source, |
| 64 const QuicConfig& config, | 66 const QuicConfig& config, |
| 65 const QuicVersionVector& supported_versions) | 67 const QuicVersionVector& supported_versions) |
| 66 : helper_( | 68 : helper_( |
| 67 new QuicChromiumConnectionHelper(base::ThreadTaskRunnerHandle::Get() | 69 new QuicChromiumConnectionHelper(&clock_, |
| 68 .get(), | |
| 69 &clock_, | |
| 70 QuicRandom::GetInstance())), | 70 QuicRandom::GetInstance())), |
| 71 alarm_factory_( |
| 72 new QuicChromiumAlarmFactory(base::ThreadTaskRunnerHandle::Get().get()
, |
| 73 &clock_)), |
| 71 config_(config), | 74 config_(config), |
| 72 crypto_config_(kSourceAddressTokenSecret, | 75 crypto_config_(kSourceAddressTokenSecret, |
| 73 QuicRandom::GetInstance(), | 76 QuicRandom::GetInstance(), |
| 74 proof_source), | 77 proof_source), |
| 75 supported_versions_(supported_versions), | 78 supported_versions_(supported_versions), |
| 76 read_pending_(false), | 79 read_pending_(false), |
| 77 synchronous_read_count_(0), | 80 synchronous_read_count_(0), |
| 78 read_buffer_(new IOBufferWithSize(kReadBufferSize)), | 81 read_buffer_(new IOBufferWithSize(kReadBufferSize)), |
| 79 weak_factory_(this) { | 82 weak_factory_(this) { |
| 80 Initialize(); | 83 Initialize(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 if (rc < 0) { | 142 if (rc < 0) { |
| 140 LOG(ERROR) << "GetLocalAddress() failed: " << ErrorToString(rc); | 143 LOG(ERROR) << "GetLocalAddress() failed: " << ErrorToString(rc); |
| 141 return rc; | 144 return rc; |
| 142 } | 145 } |
| 143 | 146 |
| 144 DVLOG(1) << "Listening on " << server_address_.ToString(); | 147 DVLOG(1) << "Listening on " << server_address_.ToString(); |
| 145 | 148 |
| 146 socket_.swap(socket); | 149 socket_.swap(socket); |
| 147 | 150 |
| 148 dispatcher_.reset(new SimpleQuicDispatcher(config_, &crypto_config_, | 151 dispatcher_.reset(new SimpleQuicDispatcher(config_, &crypto_config_, |
| 149 supported_versions_, helper_)); | 152 supported_versions_, helper_, alarm
_factory_)); |
| 150 QuicSimpleServerPacketWriter* writer = | 153 QuicSimpleServerPacketWriter* writer = |
| 151 new QuicSimpleServerPacketWriter(socket_.get(), dispatcher_.get()); | 154 new QuicSimpleServerPacketWriter(socket_.get(), dispatcher_.get()); |
| 152 dispatcher_->InitializeWithWriter(writer); | 155 dispatcher_->InitializeWithWriter(writer); |
| 153 | 156 |
| 154 StartReading(); | 157 StartReading(); |
| 155 | 158 |
| 156 return OK; | 159 return OK; |
| 157 } | 160 } |
| 158 | 161 |
| 159 void QuicSimpleServer::Shutdown() { | 162 void QuicSimpleServer::Shutdown() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 207 } |
| 205 | 208 |
| 206 QuicReceivedPacket packet(read_buffer_->data(), result, | 209 QuicReceivedPacket packet(read_buffer_->data(), result, |
| 207 helper_->GetClock()->Now(), false); | 210 helper_->GetClock()->Now(), false); |
| 208 dispatcher_->ProcessPacket(server_address_, client_address_, packet); | 211 dispatcher_->ProcessPacket(server_address_, client_address_, packet); |
| 209 | 212 |
| 210 StartReading(); | 213 StartReading(); |
| 211 } | 214 } |
| 212 | 215 |
| 213 } // namespace net | 216 } // namespace net |
| OLD | NEW |