blob: d0c66defe7be2dd78992276156d641b477a7cf70 [file] [log] [blame]
wu@webrtc.org1d1ffc92013-10-16 18:12:021/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
wu@webrtc.org1d1ffc92013-10-16 18:12:023 *
kjellanderb24317b2016-02-10 15:54:434 * 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.
wu@webrtc.org1d1ffc92013-10-16 18:12:029 */
10
Steve Anton10542f22019-01-11 17:11:0011#ifndef PC_SCTP_UTILS_H_
12#define PC_SCTP_UTILS_H_
wu@webrtc.org1d1ffc92013-10-16 18:12:0213
14#include <string>
15
Steve Anton10542f22019-01-11 17:11:0016#include "api/data_channel_interface.h"
Tommi492296c2023-03-12 15:59:2517#include "api/sequence_checker.h"
Niels Möllerbfcec4c2019-09-25 08:00:3418#include "api/transport/data_channel_transport_interface.h"
Bjorn A Mellembc3eebc2019-09-23 21:53:5419#include "media/base/media_channel.h"
Tommi492296c2023-03-12 15:59:2520#include "net/dcsctp/public/types.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0821#include "rtc_base/copy_on_write_buffer.h"
Tommi492296c2023-03-12 15:59:2522#include "rtc_base/ssl_stream_adapter.h" // For SSLRole
23#include "rtc_base/system/no_unique_address.h"
henrika@webrtc.orgaebb1ad2014-01-14 10:00:5824
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5225namespace rtc {
jbaucheec21bd2016-03-20 13:15:4326class CopyOnWriteBuffer;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5227} // namespace rtc
wu@webrtc.org1d1ffc92013-10-16 18:12:0228
29namespace webrtc {
30struct DataChannelInit;
wu@webrtc.org1d1ffc92013-10-16 18:12:0231
Tommi492296c2023-03-12 15:59:2532// Wraps the `uint16_t` sctp data channel stream id value and does range
33// checking. The class interface is `int` based to ease with DataChannelInit
34// compatibility and types used in `DataChannelController`'s interface. Going
35// forward, `int` compatibility won't be needed and we can either just use
36// this class or the internal dcsctp::StreamID type.
37class StreamId {
38 public:
39 StreamId();
40 explicit StreamId(int id);
41 explicit StreamId(const StreamId& sid);
42
43 // Returns `true` if a valid stream id is contained, in the range of
44 // kMinSctpSid - kSpecMaxSctpSid ([0..0xffff]). Note that this
45 // is different than having `kMaxSctpSid` as the upper bound, which is
46 // the limit that is internally used by `SctpSidAllocator`. Sid values may
47 // be assigned to `StreamId` outside of `SctpSidAllocator` and have a higher
48 // id value than supplied by `SctpSidAllocator`, yet is still valid.
49 bool HasValue() const;
50
51 // Provided for compatibility with existing code that hasn't been updated
52 // to use `StreamId` directly. New code should not use 'int' for the stream
53 // id but rather `StreamId` directly.
54 int stream_id_int() const;
55 void reset();
56
57 StreamId& operator=(const StreamId& sid);
58 bool operator==(const StreamId& sid) const;
59 bool operator<(const StreamId& sid) const;
60 bool operator!=(const StreamId& sid) const { return !(operator==(sid)); }
61
62 private:
63 RTC_NO_UNIQUE_ADDRESS webrtc::SequenceChecker thread_checker_;
64 absl::optional<dcsctp::StreamID> id_ RTC_GUARDED_BY(thread_checker_);
65};
66
deadbeefab9b2d12015-10-14 18:33:1167// Read the message type and return true if it's an OPEN message.
jbaucheec21bd2016-03-20 13:15:4368bool IsOpenMessage(const rtc::CopyOnWriteBuffer& payload);
deadbeefab9b2d12015-10-14 18:33:1169
jbaucheec21bd2016-03-20 13:15:4370bool ParseDataChannelOpenMessage(const rtc::CopyOnWriteBuffer& payload,
wu@webrtc.org1d1ffc92013-10-16 18:12:0271 std::string* label,
henrika@webrtc.orgaebb1ad2014-01-14 10:00:5872 DataChannelInit* config);
73
jbaucheec21bd2016-03-20 13:15:4374bool ParseDataChannelOpenAckMessage(const rtc::CopyOnWriteBuffer& payload);
wu@webrtc.org1d1ffc92013-10-16 18:12:0275
76bool WriteDataChannelOpenMessage(const std::string& label,
Tommi492296c2023-03-12 15:59:2577 const std::string& protocol,
78 absl::optional<Priority> priority,
79 bool ordered,
80 absl::optional<int> max_retransmits,
81 absl::optional<int> max_retransmit_time,
82 rtc::CopyOnWriteBuffer* payload);
83bool WriteDataChannelOpenMessage(const std::string& label,
henrika@webrtc.orgaebb1ad2014-01-14 10:00:5884 const DataChannelInit& config,
jbaucheec21bd2016-03-20 13:15:4385 rtc::CopyOnWriteBuffer* payload);
jbaucheec21bd2016-03-20 13:15:4386void WriteDataChannelOpenAckMessage(rtc::CopyOnWriteBuffer* payload);
Bjorn A Mellembc3eebc2019-09-23 21:53:5487
henrika@webrtc.orgaebb1ad2014-01-14 10:00:5888} // namespace webrtc
wu@webrtc.org1d1ffc92013-10-16 18:12:0289
Steve Anton10542f22019-01-11 17:11:0090#endif // PC_SCTP_UTILS_H_