tor-browser

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

sctp_transport_interface.h (4540B)


      1 /*
      2 *  Copyright 2019 The WebRTC project authors. All Rights Reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #ifndef API_SCTP_TRANSPORT_INTERFACE_H_
     12 #define API_SCTP_TRANSPORT_INTERFACE_H_
     13 
     14 #include <optional>
     15 
     16 #include "api/dtls_transport_interface.h"
     17 #include "api/ref_count.h"
     18 #include "api/scoped_refptr.h"
     19 #include "rtc_base/system/rtc_export.h"
     20 
     21 namespace webrtc {
     22 
     23 // States of a SCTP transport, corresponding to the JS API specification.
     24 // http://w3c.github.io/webrtc-pc/#dom-rtcsctptransportstate
     25 enum class SctpTransportState {
     26  kNew,         // Has not started negotiating yet. Non-standard state.
     27  kConnecting,  // In the process of negotiating an association.
     28  kConnected,   // Completed negotiation of an association.
     29  kClosed,      // Closed by local or remote party.
     30  kNumValues
     31 };
     32 
     33 // This object gives snapshot information about the changeable state of a
     34 // SctpTransport.
     35 // It reflects the readonly attributes of the object in the specification.
     36 // http://w3c.github.io/webrtc-pc/#rtcsctptransport-interface
     37 class RTC_EXPORT SctpTransportInformation {
     38 public:
     39  SctpTransportInformation() = default;
     40  SctpTransportInformation(const SctpTransportInformation&) = default;
     41  explicit SctpTransportInformation(SctpTransportState state);
     42  SctpTransportInformation(SctpTransportState state,
     43                           scoped_refptr<DtlsTransportInterface> dtls_transport,
     44                           std::optional<double> max_message_size,
     45                           std::optional<int> max_channels);
     46  ~SctpTransportInformation();
     47  // The DTLS transport that supports this SCTP transport.
     48  scoped_refptr<DtlsTransportInterface> dtls_transport() const {
     49    return dtls_transport_;
     50  }
     51  SctpTransportState state() const { return state_; }
     52  std::optional<double> MaxMessageSize() const { return max_message_size_; }
     53  std::optional<int> MaxChannels() const { return max_channels_; }
     54 
     55 private:
     56  SctpTransportState state_ = SctpTransportState::kNew;
     57  scoped_refptr<DtlsTransportInterface> dtls_transport_;
     58  std::optional<double> max_message_size_;
     59  std::optional<int> max_channels_;
     60 };
     61 
     62 class SctpTransportObserverInterface {
     63 public:
     64  // This callback carries information about the state of the transport.
     65  // The argument is a pass-by-value snapshot of the state.
     66  // The callback will be called on the network thread.
     67  virtual void OnStateChange(SctpTransportInformation info) = 0;
     68 
     69 protected:
     70  virtual ~SctpTransportObserverInterface() = default;
     71 };
     72 
     73 // A SCTP transport, as represented to the outside world.
     74 // This object is created on the network thread, and can only be
     75 // accessed on that thread, except for functions explicitly marked otherwise.
     76 // References can be held by other threads, and destruction can therefore
     77 // be initiated by other threads.
     78 class SctpTransportInterface : public RefCountInterface {
     79 public:
     80  // This function can be called from other threads.
     81  virtual scoped_refptr<DtlsTransportInterface> dtls_transport() const = 0;
     82  // Returns information on the state of the SctpTransport.
     83  // This function can be called from other threads.
     84  virtual SctpTransportInformation Information() const = 0;
     85  // Observer management.
     86  virtual void RegisterObserver(SctpTransportObserverInterface* observer) = 0;
     87  virtual void UnregisterObserver() = 0;
     88 };
     89 
     90 // The size of the SCTP association send buffer. 256kB, the usrsctp default.
     91 constexpr int kSctpSendBufferSize = 256 * 1024;
     92 
     93 // SCTP options negotiated in the SDP.
     94 struct SctpOptions {
     95  // https://www.rfc-editor.org/rfc/rfc8841.html#name-sctp-port
     96  // `local_port` and `remote_port` are passed along the wire and the
     97  // listener and connector must be using the same port. They are not related
     98  // to the ports at the IP level. If set to -1 we default to
     99  // kSctpDefaultPort.
    100  // TODO(bugs.webrtc.org/402429107): make these optional<uint16_t>.
    101  int local_port = -1;
    102  int remote_port = -1;
    103 
    104  // https://www.rfc-editor.org/rfc/rfc8841.html#name-max-message-size
    105  // `max_message_size` sets the maxium message size on the connection.
    106  // It must be smaller than or equal to kSctpSendBufferSize.
    107  int max_message_size = kSctpSendBufferSize;
    108 };
    109 
    110 }  // namespace webrtc
    111 
    112 #endif  // API_SCTP_TRANSPORT_INTERFACE_H_