tor-browser

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

Http3ConnectUDPStream.h (3073B)


      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_Http3ConnectUDPStream_h
      7 #define mozilla_net_Http3ConnectUDPStream_h
      8 
      9 #include "Http3StreamBase.h"
     10 #include "Http3WebTransportSession.h"
     11 #include "mozilla/Queue.h"
     12 #include "mozilla/net/DNS.h"
     13 #include "nsASocketHandler.h"
     14 #include "nsIUDPSocket.h"
     15 
     16 namespace mozilla::net {
     17 
     18 class Http3WebTransportSession;
     19 class HttpConnectionUDP;
     20 
     21 class UDPPayload final {
     22 public:
     23  explicit UDPPayload(nsTArray<uint8_t>&& aData) : mData(std::move(aData)) {
     24    MOZ_COUNT_CTOR(UDPPayload);
     25  }
     26 
     27  MOZ_COUNTED_DTOR(UDPPayload)
     28 
     29  nsTArray<uint8_t> TakeData() { return std::move(mData); }
     30 
     31 private:
     32  nsTArray<uint8_t> mData;
     33 };
     34 
     35 class Http3ConnectUDPStream final : public Http3TunnelStreamBase,
     36                                    public nsASocketHandler,
     37                                    public nsIUDPSocket {
     38 public:
     39  NS_DECL_THREADSAFE_ISUPPORTS
     40  NS_DECL_NSIUDPSOCKET
     41 
     42  explicit Http3ConnectUDPStream(nsAHttpTransaction* aTrans,
     43                                 Http3SessionBase* aSession,
     44                                 nsIEventTarget* aTarget);
     45 
     46  Http3WebTransportSession* GetHttp3WebTransportSession() override {
     47    return nullptr;
     48  }
     49  Http3WebTransportStream* GetHttp3WebTransportStream() override {
     50    return nullptr;
     51  }
     52  Http3Stream* GetHttp3Stream() override { return nullptr; }
     53  Http3ConnectUDPStream* GetHttp3ConnectUDPStream() override { return this; }
     54  Http3StreamTunnel* GetHttp3StreamTunnel() override { return nullptr; }
     55 
     56  nsresult TryActivating() override;
     57 
     58  void SetPeerAddr(const NetAddr& addr) { mAddr = addr; }
     59 
     60  void Close(nsresult aResult) override;
     61 
     62  void OnDatagramReceived(nsTArray<uint8_t>&& aData) override;
     63 
     64  bool OnActivated() override;
     65 
     66  nsresult OnProcessDatagram() override;
     67 
     68  // nsASocketHandler methods:
     69  void OnSocketReady(PRFileDesc* fd, int16_t outFlags) override;
     70  void OnSocketDetached(PRFileDesc* fd) override;
     71  void IsLocal(bool* aIsLocal) override;
     72  nsresult GetRemoteAddr(NetAddr* addr) override;
     73 
     74  uint64_t ByteCountSent() override { return mByteWriteCount; }
     75  uint64_t ByteCountReceived() override { return mByteReadCount; }
     76 
     77  already_AddRefed<HttpConnectionUDP> CreateUDPConnection(
     78      nsIInterfaceRequestor* aCallbacks);
     79 
     80  void OnSessionClosed(bool aCleanly, uint32_t aStatus,
     81                       const nsACString& aReason);
     82 
     83 private:
     84  virtual ~Http3ConnectUDPStream();
     85  void OnClosePending() override {}
     86 
     87  NetAddr mAddr;
     88  nsCOMPtr<nsIUDPSocketSyncListener> mSyncListener;
     89 
     90  uint64_t mByteReadCount{0};
     91  uint64_t mByteWriteCount{0};
     92 
     93  nsCOMPtr<nsIEventTarget> mTarget;
     94  mozilla::Queue<UniquePtr<UDPPayload>> mReceivedData;
     95  mozilla::Queue<UniquePtr<UDPPayload>> mOutputData;
     96  uint64_t mTrackingId{1};
     97 };
     98 
     99 }  // namespace mozilla::net
    100 
    101 #endif  // mozilla_net_Http3ConnectUDPStream_h