tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Http3WebTransportStream.h (3949B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef mozilla_net_Http3WebTransportStream_h
      7 #define mozilla_net_Http3WebTransportStream_h
      8 
      9 #include <functional>
     10 
     11 #include "WebTransportStreamBase.h"
     12 #include "Http3StreamBase.h"
     13 #include "mozilla/Maybe.h"
     14 #include "mozilla/Result.h"
     15 #include "mozilla/ResultVariant.h"
     16 
     17 class nsIWebTransportSendStreamStats;
     18 class nsIWebTransportReceiveStreamStats;
     19 
     20 namespace mozilla::net {
     21 
     22 class Http3WebTransportSession;
     23 
     24 class Http3WebTransportStream final : public WebTransportStreamBase,
     25                                      public Http3StreamBase,
     26                                      public nsAHttpSegmentWriter,
     27                                      public nsAHttpSegmentReader {
     28 public:
     29  NS_DECL_THREADSAFE_ISUPPORTS
     30  NS_DECL_NSAHTTPSEGMENTWRITER
     31  NS_DECL_NSAHTTPSEGMENTREADER
     32  NS_DECL_NSIINPUTSTREAMCALLBACK
     33  NS_DECL_NSIOUTPUTSTREAMCALLBACK
     34 
     35  explicit Http3WebTransportStream(
     36      Http3SessionBase* aSession, uint64_t aSessionId,
     37      WebTransportStreamType aType,
     38      std::function<void(Result<RefPtr<WebTransportStreamBase>, nsresult>&&)>&&
     39          aCallback);
     40  explicit Http3WebTransportStream(Http3SessionBase* aSession,
     41                                   uint64_t aSessionId,
     42                                   WebTransportStreamType aType,
     43                                   uint64_t aStreamId);
     44 
     45  class StreamId WebTransportStreamId() const override;
     46  uint64_t GetStreamId() const override;
     47 
     48  Http3WebTransportSession* GetHttp3WebTransportSession() override {
     49    return nullptr;
     50  }
     51  Http3WebTransportStream* GetHttp3WebTransportStream() override {
     52    return this;
     53  }
     54  Http3Stream* GetHttp3Stream() override { return nullptr; }
     55  Http3ConnectUDPStream* GetHttp3ConnectUDPStream() override { return nullptr; }
     56  Http3StreamTunnel* GetHttp3StreamTunnel() override { return nullptr; }
     57 
     58  void SetSendOrder(Maybe<int64_t> aSendOrder) override;
     59 
     60  [[nodiscard]] nsresult ReadSegments() override;
     61  [[nodiscard]] nsresult WriteSegments() override;
     62 
     63  bool Done() const override;
     64  void Close(nsresult aResult) override;
     65 
     66  void SetResponseHeaders(nsTArray<uint8_t>& aResponseHeaders, bool fin,
     67                          bool interim) override {}
     68 
     69  uint64_t SessionId() const { return mSessionId; }
     70 
     71  void SendFin() override;
     72  void Reset(uint64_t aErrorCode) override;
     73  void SendStopSending(uint8_t aErrorCode) override;
     74 
     75  already_AddRefed<nsIWebTransportSendStreamStats> GetSendStreamStats()
     76      override;
     77  already_AddRefed<nsIWebTransportReceiveStreamStats> GetReceiveStreamStats()
     78      override;
     79 
     80  // When mRecvState is RECV_DONE, this means we already received the FIN.
     81  bool RecvDone() const override { return mRecvState == RECV_DONE; }
     82 
     83 private:
     84  friend class Http3WebTransportSession;
     85  virtual ~Http3WebTransportStream();
     86 
     87  nsresult TryActivating();
     88  static nsresult ReadRequestSegment(nsIInputStream*, void*, const char*,
     89                                     uint32_t, uint32_t, uint32_t*);
     90  static nsresult WritePipeSegment(nsIOutputStream*, void*, char*, uint32_t,
     91                                   uint32_t, uint32_t*);
     92 
     93  uint64_t mTotalSent = 0;
     94  uint64_t mTotalReceived = 0;
     95  // TODO: neqo doesn't expose this information for now.
     96  uint64_t mTotalAcknowledged = 0;
     97  bool mSendFin{false};
     98  // The error code used to reset the stream. Should be only set once.
     99  Maybe<uint64_t> mResetError;
    100  // The error code used for STOP_SENDING. Should be only set once.
    101  Maybe<uint8_t> mStopSendingError;
    102 
    103  // This is used when SendFin or Reset is called when mSendState is SENDING.
    104  nsTArray<std::function<void()>> mPendingTasks;
    105 };
    106 
    107 }  // namespace mozilla::net
    108 
    109 #endif  // mozilla_net_Http3WebTransportStream_h