2013-10-16 18:12:02 +00:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2013 The WebRTC project authors. All Rights Reserved.
|
2013-10-16 18:12:02 +00:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2013-10-16 18:12:02 +00:00
|
|
|
*/
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#ifndef PC_SCTP_UTILS_H_
|
|
|
|
|
#define PC_SCTP_UTILS_H_
|
2013-10-16 18:12:02 +00:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "api/data_channel_interface.h"
|
2019-09-25 10:00:34 +02:00
|
|
|
#include "api/transport/data_channel_transport_interface.h"
|
2019-09-23 14:53:54 -07:00
|
|
|
#include "media/base/media_channel.h"
|
2023-03-21 11:35:24 +01:00
|
|
|
#include "media/sctp/sctp_transport_internal.h"
|
2023-03-12 16:59:25 +01:00
|
|
|
#include "net/dcsctp/public/types.h"
|
2021-01-29 14:45:08 +00:00
|
|
|
#include "rtc_base/copy_on_write_buffer.h"
|
2023-03-12 16:59:25 +01:00
|
|
|
#include "rtc_base/ssl_stream_adapter.h" // For SSLRole
|
2014-01-14 10:00:58 +00:00
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
namespace rtc {
|
2016-03-20 06:15:43 -07:00
|
|
|
class CopyOnWriteBuffer;
|
2014-07-29 17:36:52 +00:00
|
|
|
} // namespace rtc
|
2013-10-16 18:12:02 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
struct DataChannelInit;
|
|
|
|
|
|
2023-03-12 16:59:25 +01:00
|
|
|
// Wraps the `uint16_t` sctp data channel stream id value and does range
|
|
|
|
|
// checking. The class interface is `int` based to ease with DataChannelInit
|
|
|
|
|
// compatibility and types used in `DataChannelController`'s interface. Going
|
|
|
|
|
// forward, `int` compatibility won't be needed and we can either just use
|
|
|
|
|
// this class or the internal dcsctp::StreamID type.
|
|
|
|
|
class StreamId {
|
|
|
|
|
public:
|
2023-03-21 11:35:24 +01:00
|
|
|
StreamId() = default;
|
|
|
|
|
explicit StreamId(int id)
|
|
|
|
|
: id_(id >= cricket::kMinSctpSid && id <= cricket::kSpecMaxSctpSid
|
|
|
|
|
? absl::optional<uint16_t>(static_cast<uint16_t>(id))
|
|
|
|
|
: absl::nullopt) {}
|
|
|
|
|
StreamId(const StreamId& sid) = default;
|
|
|
|
|
StreamId& operator=(const StreamId& sid) = default;
|
2023-03-12 16:59:25 +01:00
|
|
|
|
|
|
|
|
// Returns `true` if a valid stream id is contained, in the range of
|
|
|
|
|
// kMinSctpSid - kSpecMaxSctpSid ([0..0xffff]). Note that this
|
|
|
|
|
// is different than having `kMaxSctpSid` as the upper bound, which is
|
|
|
|
|
// the limit that is internally used by `SctpSidAllocator`. Sid values may
|
|
|
|
|
// be assigned to `StreamId` outside of `SctpSidAllocator` and have a higher
|
|
|
|
|
// id value than supplied by `SctpSidAllocator`, yet is still valid.
|
2023-03-21 11:35:24 +01:00
|
|
|
bool HasValue() const { return id_.has_value(); }
|
2023-03-12 16:59:25 +01:00
|
|
|
|
|
|
|
|
// Provided for compatibility with existing code that hasn't been updated
|
|
|
|
|
// to use `StreamId` directly. New code should not use 'int' for the stream
|
|
|
|
|
// id but rather `StreamId` directly.
|
2023-03-21 11:35:24 +01:00
|
|
|
int stream_id_int() const {
|
|
|
|
|
return id_.has_value() ? static_cast<int>(id_.value().value()) : -1;
|
|
|
|
|
}
|
2023-03-12 16:59:25 +01:00
|
|
|
|
2023-03-21 11:35:24 +01:00
|
|
|
void reset() { id_ = absl::nullopt; }
|
|
|
|
|
|
|
|
|
|
bool operator==(const StreamId& sid) const { return id_ == sid.id_; }
|
|
|
|
|
bool operator<(const StreamId& sid) const { return id_ < sid.id_; }
|
2023-03-12 16:59:25 +01:00
|
|
|
bool operator!=(const StreamId& sid) const { return !(operator==(sid)); }
|
|
|
|
|
|
|
|
|
|
private:
|
2023-03-21 11:35:24 +01:00
|
|
|
absl::optional<dcsctp::StreamID> id_;
|
2023-03-12 16:59:25 +01:00
|
|
|
};
|
|
|
|
|
|
2015-10-14 11:33:11 -07:00
|
|
|
// Read the message type and return true if it's an OPEN message.
|
2016-03-20 06:15:43 -07:00
|
|
|
bool IsOpenMessage(const rtc::CopyOnWriteBuffer& payload);
|
2015-10-14 11:33:11 -07:00
|
|
|
|
2016-03-20 06:15:43 -07:00
|
|
|
bool ParseDataChannelOpenMessage(const rtc::CopyOnWriteBuffer& payload,
|
2013-10-16 18:12:02 +00:00
|
|
|
std::string* label,
|
2014-01-14 10:00:58 +00:00
|
|
|
DataChannelInit* config);
|
|
|
|
|
|
2016-03-20 06:15:43 -07:00
|
|
|
bool ParseDataChannelOpenAckMessage(const rtc::CopyOnWriteBuffer& payload);
|
2013-10-16 18:12:02 +00:00
|
|
|
|
2023-03-12 16:59:25 +01:00
|
|
|
bool WriteDataChannelOpenMessage(const std::string& label,
|
|
|
|
|
const std::string& protocol,
|
|
|
|
|
absl::optional<Priority> priority,
|
|
|
|
|
bool ordered,
|
|
|
|
|
absl::optional<int> max_retransmits,
|
|
|
|
|
absl::optional<int> max_retransmit_time,
|
|
|
|
|
rtc::CopyOnWriteBuffer* payload);
|
2013-10-16 18:12:02 +00:00
|
|
|
bool WriteDataChannelOpenMessage(const std::string& label,
|
2014-01-14 10:00:58 +00:00
|
|
|
const DataChannelInit& config,
|
2016-03-20 06:15:43 -07:00
|
|
|
rtc::CopyOnWriteBuffer* payload);
|
|
|
|
|
void WriteDataChannelOpenAckMessage(rtc::CopyOnWriteBuffer* payload);
|
2019-09-23 14:53:54 -07:00
|
|
|
|
2014-01-14 10:00:58 +00:00
|
|
|
} // namespace webrtc
|
2013-10-16 18:12:02 +00:00
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#endif // PC_SCTP_UTILS_H_
|