| 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 std::unique_ptr<QuicConnectionHelperInterface> helper, |
| 40 : QuicDispatcher(config, crypto_config, supported_versions, helper) {} | 40 std::unique_ptr<QuicAlarmFactory> alarm_factory) |
| 41 : QuicDispatcher(config, |
| 42 crypto_config, |
| 43 supported_versions, |
| 44 std::move(helper), |
| 45 std::move(alarm_factory)) {} |
| 41 | 46 |
| 42 protected: | 47 protected: |
| 43 QuicServerSessionBase* CreateQuicSession( | 48 QuicServerSessionBase* CreateQuicSession( |
| 44 QuicConnectionId connection_id, | 49 QuicConnectionId connection_id, |
| 45 const IPEndPoint& client_address) override { | 50 const IPEndPoint& client_address) override { |
| 46 QuicServerSessionBase* session = | 51 QuicServerSessionBase* session = |
| 47 QuicDispatcher::CreateQuicSession(connection_id, client_address); | 52 QuicDispatcher::CreateQuicSession(connection_id, client_address); |
| 48 static_cast<QuicSimplePerConnectionPacketWriter*>( | 53 static_cast<QuicSimplePerConnectionPacketWriter*>( |
| 49 session->connection()->writer()) | 54 session->connection()->writer()) |
| 50 ->set_connection(session->connection()); | 55 ->set_connection(session->connection()); |
| 51 return session; | 56 return session; |
| 52 } | 57 } |
| 53 | 58 |
| 54 QuicPacketWriter* CreatePerConnectionWriter() override { | 59 QuicPacketWriter* CreatePerConnectionWriter() override { |
| 55 return new QuicSimplePerConnectionPacketWriter( | 60 return new QuicSimplePerConnectionPacketWriter( |
| 56 static_cast<QuicSimpleServerPacketWriter*>(writer())); | 61 static_cast<QuicSimpleServerPacketWriter*>(writer())); |
| 57 } | 62 } |
| 58 }; | 63 }; |
| 59 | 64 |
| 60 } // namespace | 65 } // namespace |
| 61 | 66 |
| 62 QuicSimpleServer::QuicSimpleServer(ProofSource* proof_source, | 67 QuicSimpleServer::QuicSimpleServer(ProofSource* proof_source, |
| 63 const QuicConfig& config, | 68 const QuicConfig& config, |
| 64 const QuicVersionVector& supported_versions) | 69 const QuicVersionVector& supported_versions) |
| 65 : helper_( | 70 : helper_( |
| 66 new QuicChromiumConnectionHelper(base::ThreadTaskRunnerHandle::Get() | 71 new QuicChromiumConnectionHelper(&clock_, QuicRandom::GetInstance())), |
| 67 .get(), | 72 alarm_factory_(new QuicChromiumAlarmFactory( |
| 68 &clock_, | 73 base::ThreadTaskRunnerHandle::Get().get(), |
| 69 QuicRandom::GetInstance())), | 74 &clock_)), |
| 70 config_(config), | 75 config_(config), |
| 71 crypto_config_(kSourceAddressTokenSecret, | 76 crypto_config_(kSourceAddressTokenSecret, |
| 72 QuicRandom::GetInstance(), | 77 QuicRandom::GetInstance(), |
| 73 proof_source), | 78 proof_source), |
| 74 supported_versions_(supported_versions), | 79 supported_versions_(supported_versions), |
| 75 read_pending_(false), | 80 read_pending_(false), |
| 76 synchronous_read_count_(0), | 81 synchronous_read_count_(0), |
| 77 read_buffer_(new IOBufferWithSize(kReadBufferSize)), | 82 read_buffer_(new IOBufferWithSize(kReadBufferSize)), |
| 78 weak_factory_(this) { | 83 weak_factory_(this) { |
| 79 Initialize(); | 84 Initialize(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 rc = socket->GetLocalAddress(&server_address_); | 142 rc = socket->GetLocalAddress(&server_address_); |
| 138 if (rc < 0) { | 143 if (rc < 0) { |
| 139 LOG(ERROR) << "GetLocalAddress() failed: " << ErrorToString(rc); | 144 LOG(ERROR) << "GetLocalAddress() failed: " << ErrorToString(rc); |
| 140 return rc; | 145 return rc; |
| 141 } | 146 } |
| 142 | 147 |
| 143 DVLOG(1) << "Listening on " << server_address_.ToString(); | 148 DVLOG(1) << "Listening on " << server_address_.ToString(); |
| 144 | 149 |
| 145 socket_.swap(socket); | 150 socket_.swap(socket); |
| 146 | 151 |
| 147 dispatcher_.reset(new SimpleQuicDispatcher(config_, &crypto_config_, | 152 dispatcher_.reset(new SimpleQuicDispatcher( |
| 148 supported_versions_, helper_)); | 153 config_, &crypto_config_, supported_versions_, |
| 154 std::unique_ptr<QuicConnectionHelperInterface>(helper_), |
| 155 std::unique_ptr<QuicChromiumAlarmFactory>(alarm_factory_))); |
| 149 QuicSimpleServerPacketWriter* writer = | 156 QuicSimpleServerPacketWriter* writer = |
| 150 new QuicSimpleServerPacketWriter(socket_.get(), dispatcher_.get()); | 157 new QuicSimpleServerPacketWriter(socket_.get(), dispatcher_.get()); |
| 151 dispatcher_->InitializeWithWriter(writer); | 158 dispatcher_->InitializeWithWriter(writer); |
| 152 | 159 |
| 153 StartReading(); | 160 StartReading(); |
| 154 | 161 |
| 155 return OK; | 162 return OK; |
| 156 } | 163 } |
| 157 | 164 |
| 158 void QuicSimpleServer::Shutdown() { | 165 void QuicSimpleServer::Shutdown() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 210 } |
| 204 | 211 |
| 205 QuicReceivedPacket packet(read_buffer_->data(), result, | 212 QuicReceivedPacket packet(read_buffer_->data(), result, |
| 206 helper_->GetClock()->Now(), false); | 213 helper_->GetClock()->Now(), false); |
| 207 dispatcher_->ProcessPacket(server_address_, client_address_, packet); | 214 dispatcher_->ProcessPacket(server_address_, client_address_, packet); |
| 208 | 215 |
| 209 StartReading(); | 216 StartReading(); |
| 210 } | 217 } |
| 211 | 218 |
| 212 } // namespace net | 219 } // namespace net |
| OLD | NEW |