tor-browser

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

JsepTransport.h (2366B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef _JSEPTRANSPORT_H_
      6 #define _JSEPTRANSPORT_H_
      7 
      8 #include <mozilla/RefPtr.h>
      9 #include <mozilla/UniquePtr.h>
     10 
     11 #include <string>
     12 #include <vector>
     13 
     14 #include "nsISupportsImpl.h"
     15 #include "sdp/SdpAttribute.h"
     16 
     17 namespace mozilla {
     18 
     19 class JsepDtlsTransport {
     20 public:
     21  JsepDtlsTransport() : mRole(kJsepDtlsInvalidRole) {}
     22 
     23  virtual ~JsepDtlsTransport() {}
     24 
     25  enum Role { kJsepDtlsClient, kJsepDtlsServer, kJsepDtlsInvalidRole };
     26 
     27  virtual const SdpFingerprintAttributeList& GetFingerprints() const {
     28    return mFingerprints;
     29  }
     30 
     31  virtual Role GetRole() const { return mRole; }
     32 
     33 private:
     34  friend class JsepSessionImpl;
     35 
     36  SdpFingerprintAttributeList mFingerprints;
     37  Role mRole;
     38 };
     39 
     40 class JsepIceTransport {
     41 public:
     42  JsepIceTransport() {}
     43 
     44  virtual ~JsepIceTransport() {}
     45 
     46  const std::string& GetUfrag() const { return mUfrag; }
     47  const std::string& GetPassword() const { return mPwd; }
     48  const std::vector<std::string>& GetCandidates() const { return mCandidates; }
     49 
     50 private:
     51  friend class JsepSessionImpl;
     52 
     53  std::string mUfrag;
     54  std::string mPwd;
     55  std::vector<std::string> mCandidates;
     56 };
     57 
     58 class JsepTransport {
     59 public:
     60  JsepTransport() : mComponents(0) {}
     61 
     62  JsepTransport(const JsepTransport& orig) { *this = orig; }
     63 
     64  ~JsepTransport() {}
     65 
     66  JsepTransport& operator=(const JsepTransport& orig) {
     67    if (this != &orig) {
     68      mIce.reset(orig.mIce ? new JsepIceTransport(*orig.mIce) : nullptr);
     69      mDtls.reset(orig.mDtls ? new JsepDtlsTransport(*orig.mDtls) : nullptr);
     70      mTransportId = orig.mTransportId;
     71      mComponents = orig.mComponents;
     72      mLocalUfrag = orig.mLocalUfrag;
     73      mLocalPwd = orig.mLocalPwd;
     74    }
     75    return *this;
     76  }
     77 
     78  void Close() {
     79    mComponents = 0;
     80    mTransportId.clear();
     81    mIce.reset();
     82    mDtls.reset();
     83    mLocalUfrag.clear();
     84    mLocalPwd.clear();
     85  }
     86 
     87  // Unique identifier for this transport within this call. Group?
     88  std::string mTransportId;
     89 
     90  // ICE stuff.
     91  UniquePtr<JsepIceTransport> mIce;
     92  UniquePtr<JsepDtlsTransport> mDtls;
     93 
     94  // Number of required components.
     95  size_t mComponents;
     96  std::string mLocalUfrag;
     97  std::string mLocalPwd;
     98 };
     99 
    100 }  // namespace mozilla
    101 
    102 #endif