wub | f975eac | 2019-08-19 19:41:01 -0700 | [diff] [blame] | 1 | // Copyright (c) 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/qbone/qbone_stream.h" |
| 6 | |
| 7 | #include "net/third_party/quiche/src/quic/core/quic_data_reader.h" |
| 8 | #include "net/third_party/quiche/src/quic/core/quic_data_writer.h" |
| 9 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
wub | f975eac | 2019-08-19 19:41:01 -0700 | [diff] [blame] | 10 | #include "net/third_party/quiche/src/quic/qbone/qbone_constants.h" |
| 11 | #include "net/third_party/quiche/src/quic/qbone/qbone_session_base.h" |
dmcardle | d70b99e | 2019-12-12 09:52:39 -0800 | [diff] [blame] | 12 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
wub | f975eac | 2019-08-19 19:41:01 -0700 | [diff] [blame] | 13 | |
| 14 | namespace quic { |
| 15 | |
| 16 | QboneWriteOnlyStream::QboneWriteOnlyStream(QuicStreamId id, |
| 17 | QuicSession* session) |
| 18 | : QuicStream(id, session, /*is_static=*/false, WRITE_UNIDIRECTIONAL) { |
| 19 | // QBONE uses a LIFO queue to try to always make progress. An individual |
| 20 | // packet may persist for upto to 10 seconds in memory. |
| 21 | MaybeSetTtl(QuicTime::Delta::FromSeconds(10)); |
| 22 | } |
| 23 | |
dmcardle | d70b99e | 2019-12-12 09:52:39 -0800 | [diff] [blame] | 24 | void QboneWriteOnlyStream::WritePacketToQuicStream( |
| 25 | quiche::QuicheStringPiece packet) { |
wub | f975eac | 2019-08-19 19:41:01 -0700 | [diff] [blame] | 26 | // Streams are one way and ephemeral. This function should only be |
| 27 | // called once. |
| 28 | WriteOrBufferData(packet, /* fin= */ true, nullptr); |
| 29 | } |
| 30 | |
| 31 | QboneReadOnlyStream::QboneReadOnlyStream(QuicStreamId id, |
| 32 | QboneSessionBase* session) |
| 33 | : QuicStream(id, |
| 34 | session, |
| 35 | /*is_static=*/false, |
| 36 | READ_UNIDIRECTIONAL), |
| 37 | session_(session) { |
| 38 | // QBONE uses a LIFO queue to try to always make progress. An individual |
| 39 | // packet may persist for upto to 10 seconds in memory. |
| 40 | MaybeSetTtl(QuicTime::Delta::FromSeconds(10)); |
| 41 | } |
| 42 | |
| 43 | QboneReadOnlyStream::~QboneReadOnlyStream() {} |
| 44 | |
| 45 | void QboneReadOnlyStream::OnDataAvailable() { |
| 46 | // Read in data and buffer it, attempt to frame to see if there's a packet. |
| 47 | sequencer()->Read(&buffer_); |
| 48 | if (sequencer()->IsClosed()) { |
| 49 | session_->ProcessPacketFromPeer(buffer_); |
| 50 | OnFinRead(); |
| 51 | return; |
| 52 | } |
| 53 | if (buffer_.size() > QboneConstants::kMaxQbonePacketBytes) { |
| 54 | if (!rst_sent()) { |
| 55 | Reset(QUIC_BAD_APPLICATION_PAYLOAD); |
| 56 | } |
| 57 | StopReading(); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | } // namespace quic |