blob: c1bf23dd98affb47980b999b83a48d9e8bde216f [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"
Niels Möllerbfcec4c2019-09-25 08:00:3417#include "api/transport/data_channel_transport_interface.h"
Bjorn A Mellembc3eebc2019-09-23 21:53:5418#include "media/base/media_channel.h"
Tommi4c842222023-03-21 10:35:2419#include "media/sctp/sctp_transport_internal.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
henrika@webrtc.orgaebb1ad2014-01-14 10:00:5823
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5224namespace rtc {
jbaucheec21bd2016-03-20 13:15:4325class CopyOnWriteBuffer;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:5226} // namespace rtc
wu@webrtc.org1d1ffc92013-10-16 18:12:0227
28namespace webrtc {
29struct DataChannelInit;
wu@webrtc.org1d1ffc92013-10-16 18:12:0230
Tommi492296c2023-03-12 15:59:2531// Wraps the `uint16_t` sctp data channel stream id value and does range
32// checking. The class interface is `int` based to ease with DataChannelInit
33// compatibility and types used in `DataChannelController`'s interface. Going
34// forward, `int` compatibility won't be needed and we can either just use
35// this class or the internal dcsctp::StreamID type.
36class StreamId {
37 public:
Tommi4c842222023-03-21 10:35:2438 StreamId() = default;
Victor Boiviecd3d29b2024-03-09 20:50:4239 explicit StreamId(uint16_t id) : id_(id) {}
Tommi4c842222023-03-21 10:35:2440 StreamId(const StreamId& sid) = default;
41 StreamId& operator=(const StreamId& sid) = default;
Tommi492296c2023-03-12 15:59:2542 // Provided for compatibility with existing code that hasn't been updated
43 // to use `StreamId` directly. New code should not use 'int' for the stream
44 // id but rather `StreamId` directly.
Victor Boiviecd3d29b2024-03-09 20:50:4245 int stream_id_int() const { return static_cast<int>(id_.value()); }
Tommi4c842222023-03-21 10:35:2446
47 bool operator==(const StreamId& sid) const { return id_ == sid.id_; }
48 bool operator<(const StreamId& sid) const { return id_ < sid.id_; }
Tommi492296c2023-03-12 15:59:2549 bool operator!=(const StreamId& sid) const { return !(operator==(sid)); }
50
51 private:
Victor Boiviecd3d29b2024-03-09 20:50:4252 dcsctp::StreamID id_;
Tommi492296c2023-03-12 15:59:2553};
54
deadbeefab9b2d12015-10-14 18:33:1155// Read the message type and return true if it's an OPEN message.
jbaucheec21bd2016-03-20 13:15:4356bool IsOpenMessage(const rtc::CopyOnWriteBuffer& payload);
deadbeefab9b2d12015-10-14 18:33:1157
jbaucheec21bd2016-03-20 13:15:4358bool ParseDataChannelOpenMessage(const rtc::CopyOnWriteBuffer& payload,
wu@webrtc.org1d1ffc92013-10-16 18:12:0259 std::string* label,
henrika@webrtc.orgaebb1ad2014-01-14 10:00:5860 DataChannelInit* config);
61
jbaucheec21bd2016-03-20 13:15:4362bool ParseDataChannelOpenAckMessage(const rtc::CopyOnWriteBuffer& payload);
wu@webrtc.org1d1ffc92013-10-16 18:12:0263
64bool WriteDataChannelOpenMessage(const std::string& label,
Tommi492296c2023-03-12 15:59:2565 const std::string& protocol,
66 absl::optional<Priority> priority,
67 bool ordered,
68 absl::optional<int> max_retransmits,
69 absl::optional<int> max_retransmit_time,
70 rtc::CopyOnWriteBuffer* payload);
71bool WriteDataChannelOpenMessage(const std::string& label,
henrika@webrtc.orgaebb1ad2014-01-14 10:00:5872 const DataChannelInit& config,
jbaucheec21bd2016-03-20 13:15:4373 rtc::CopyOnWriteBuffer* payload);
jbaucheec21bd2016-03-20 13:15:4374void WriteDataChannelOpenAckMessage(rtc::CopyOnWriteBuffer* payload);
Bjorn A Mellembc3eebc2019-09-23 21:53:5475
henrika@webrtc.orgaebb1ad2014-01-14 10:00:5876} // namespace webrtc
wu@webrtc.org1d1ffc92013-10-16 18:12:0277
Steve Anton10542f22019-01-11 17:11:0078#endif // PC_SCTP_UTILS_H_