| 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 #include "net/tools/quic/quic_dispatcher.h" | 5 #include "net/tools/quic/quic_dispatcher.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "net/quic/core/crypto/crypto_protocol.h" | 10 #include "net/quic/core/crypto/crypto_protocol.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 // Not owned. | 45 // Not owned. |
| 46 QuicDispatcher* dispatcher_; | 46 QuicDispatcher* dispatcher_; |
| 47 | 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(DeleteSessionsAlarm); | 48 DISALLOW_COPY_AND_ASSIGN(DeleteSessionsAlarm); |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 // Collects packets serialized by a QuicPacketCreator in order | 51 // Collects packets serialized by a QuicPacketCreator in order |
| 52 // to be handed off to the time wait list manager. | 52 // to be handed off to the time wait list manager. |
| 53 class PacketCollector : public QuicPacketCreator::DelegateInterface { | 53 class PacketCollector : public QuicPacketCreator::DelegateInterface { |
| 54 public: | 54 public: |
| 55 explicit PacketCollector(QuicBufferAllocator* allocator) |
| 56 : send_buffer_(allocator) {} |
| 55 ~PacketCollector() override {} | 57 ~PacketCollector() override {} |
| 56 | 58 |
| 57 void OnSerializedPacket(SerializedPacket* serialized_packet) override { | 59 void OnSerializedPacket(SerializedPacket* serialized_packet) override { |
| 58 // Make a copy of the serialized packet to send later. | 60 // Make a copy of the serialized packet to send later. |
| 59 packets_.push_back(std::unique_ptr<QuicEncryptedPacket>( | 61 packets_.push_back(std::unique_ptr<QuicEncryptedPacket>( |
| 60 new QuicEncryptedPacket(CopyBuffer(*serialized_packet), | 62 new QuicEncryptedPacket(CopyBuffer(*serialized_packet), |
| 61 serialized_packet->encrypted_length, true))); | 63 serialized_packet->encrypted_length, true))); |
| 62 serialized_packet->encrypted_buffer = nullptr; | 64 serialized_packet->encrypted_buffer = nullptr; |
| 63 DeleteFrames(&(serialized_packet->retransmittable_frames)); | 65 DeleteFrames(&(serialized_packet->retransmittable_frames)); |
| 64 serialized_packet->retransmittable_frames.clear(); | 66 serialized_packet->retransmittable_frames.clear(); |
| 65 } | 67 } |
| 66 | 68 |
| 67 void OnUnrecoverableError(QuicErrorCode error, | 69 void OnUnrecoverableError(QuicErrorCode error, |
| 68 const string& error_details, | 70 const string& error_details, |
| 69 ConnectionCloseSource source) override {} | 71 ConnectionCloseSource source) override {} |
| 70 | 72 |
| 73 void SaveStreamData(QuicStreamId id, |
| 74 QuicIOVector iov, |
| 75 size_t iov_offset, |
| 76 QuicStreamOffset offset, |
| 77 QuicByteCount data_length) override { |
| 78 DCHECK_EQ(kCryptoStreamId, id); |
| 79 send_buffer_.SaveStreamData(iov, iov_offset, offset, data_length); |
| 80 } |
| 81 |
| 82 bool WriteStreamData(QuicStreamId id, |
| 83 QuicStreamOffset offset, |
| 84 QuicByteCount data_length, |
| 85 QuicDataWriter* writer) override { |
| 86 DCHECK_EQ(kCryptoStreamId, id); |
| 87 return send_buffer_.WriteStreamData(offset, data_length, writer); |
| 88 } |
| 89 |
| 71 std::vector<std::unique_ptr<QuicEncryptedPacket>>* packets() { | 90 std::vector<std::unique_ptr<QuicEncryptedPacket>>* packets() { |
| 72 return &packets_; | 91 return &packets_; |
| 73 } | 92 } |
| 74 | 93 |
| 75 private: | 94 private: |
| 76 std::vector<std::unique_ptr<QuicEncryptedPacket>> packets_; | 95 std::vector<std::unique_ptr<QuicEncryptedPacket>> packets_; |
| 96 // This is only needed until the packets are encrypted. Once packets are |
| 97 // encrypted, the stream data is no longer required. |
| 98 QuicStreamSendBuffer send_buffer_; |
| 77 }; | 99 }; |
| 78 | 100 |
| 79 // Helper for statelessly closing connections by generating the | 101 // Helper for statelessly closing connections by generating the |
| 80 // correct termination packets and adding the connection to the time wait | 102 // correct termination packets and adding the connection to the time wait |
| 81 // list manager. | 103 // list manager. |
| 82 class StatelessConnectionTerminator { | 104 class StatelessConnectionTerminator { |
| 83 public: | 105 public: |
| 84 StatelessConnectionTerminator(QuicConnectionId connection_id, | 106 StatelessConnectionTerminator(QuicConnectionId connection_id, |
| 85 QuicFramer* framer, | 107 QuicFramer* framer, |
| 86 QuicConnectionHelperInterface* helper, | 108 QuicConnectionHelperInterface* helper, |
| 87 QuicTimeWaitListManager* time_wait_list_manager) | 109 QuicTimeWaitListManager* time_wait_list_manager) |
| 88 : connection_id_(connection_id), | 110 : connection_id_(connection_id), |
| 89 framer_(framer), | 111 framer_(framer), |
| 112 collector_(helper->GetBufferAllocator()), |
| 90 creator_(connection_id, | 113 creator_(connection_id, |
| 91 framer, | 114 framer, |
| 92 helper->GetBufferAllocator(), | 115 helper->GetBufferAllocator(), |
| 93 &collector_), | 116 &collector_), |
| 94 time_wait_list_manager_(time_wait_list_manager) {} | 117 time_wait_list_manager_(time_wait_list_manager) {} |
| 95 | 118 |
| 96 // Generates a packet containing a CONNECTION_CLOSE frame specifying | 119 // Generates a packet containing a CONNECTION_CLOSE frame specifying |
| 97 // |error_code| and |error_details| and add the connection to time wait. | 120 // |error_code| and |error_details| and add the connection to time wait. |
| 98 void CloseConnection(QuicErrorCode error_code, | 121 void CloseConnection(QuicErrorCode error_code, |
| 99 const std::string& error_details) { | 122 const std::string& error_details) { |
| (...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 void QuicDispatcher::DeliverPacketsToSession( | 1016 void QuicDispatcher::DeliverPacketsToSession( |
| 994 const std::list<BufferedPacket>& packets, | 1017 const std::list<BufferedPacket>& packets, |
| 995 QuicSession* session) { | 1018 QuicSession* session) { |
| 996 for (const BufferedPacket& packet : packets) { | 1019 for (const BufferedPacket& packet : packets) { |
| 997 session->ProcessUdpPacket(packet.server_address, packet.client_address, | 1020 session->ProcessUdpPacket(packet.server_address, packet.client_address, |
| 998 *(packet.packet)); | 1021 *(packet.packet)); |
| 999 } | 1022 } |
| 1000 } | 1023 } |
| 1001 | 1024 |
| 1002 } // namespace net | 1025 } // namespace net |
| OLD | NEW |