Repo created

This commit is contained in:
Fr4nz D13trich 2025-11-22 14:04:28 +01:00
parent 81b91f4139
commit f8c34fa5ee
22732 changed files with 4815320 additions and 2 deletions

View file

@ -0,0 +1,68 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "net/dcsctp/packet/parameter/add_incoming_streams_request_parameter.h"
#include <stdint.h>
#include <string>
#include <type_traits>
#include <vector>
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "net/dcsctp/common/internal_types.h"
#include "net/dcsctp/packet/bounded_byte_reader.h"
#include "net/dcsctp/packet/bounded_byte_writer.h"
#include "net/dcsctp/packet/tlv_trait.h"
#include "rtc_base/strings/string_builder.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc6525#section-4.6
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Parameter Type = 18 | Parameter Length = 12 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Re-configuration Request Sequence Number |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Number of new streams | Reserved |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
constexpr int AddIncomingStreamsRequestParameter::kType;
absl::optional<AddIncomingStreamsRequestParameter>
AddIncomingStreamsRequestParameter::Parse(rtc::ArrayView<const uint8_t> data) {
absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
if (!reader.has_value()) {
return absl::nullopt;
}
ReconfigRequestSN request_sequence_number(reader->Load32<4>());
uint16_t nbr_of_new_streams = reader->Load16<8>();
return AddIncomingStreamsRequestParameter(request_sequence_number,
nbr_of_new_streams);
}
void AddIncomingStreamsRequestParameter::SerializeTo(
std::vector<uint8_t>& out) const {
BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out);
writer.Store32<4>(*request_sequence_number_);
writer.Store16<8>(nbr_of_new_streams_);
}
std::string AddIncomingStreamsRequestParameter::ToString() const {
rtc::StringBuilder sb;
sb << "Add Incoming Streams Request, req_seq_nbr="
<< *request_sequence_number();
return sb.Release();
}
} // namespace dcsctp

View file

@ -0,0 +1,63 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef NET_DCSCTP_PACKET_PARAMETER_ADD_INCOMING_STREAMS_REQUEST_PARAMETER_H_
#define NET_DCSCTP_PACKET_PARAMETER_ADD_INCOMING_STREAMS_REQUEST_PARAMETER_H_
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "net/dcsctp/common/internal_types.h"
#include "net/dcsctp/packet/parameter/parameter.h"
#include "net/dcsctp/packet/tlv_trait.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc6525#section-4.6
struct AddIncomingStreamsRequestParameterConfig : ParameterConfig {
static constexpr int kType = 18;
static constexpr size_t kHeaderSize = 12;
static constexpr size_t kVariableLengthAlignment = 0;
};
class AddIncomingStreamsRequestParameter
: public Parameter,
public TLVTrait<AddIncomingStreamsRequestParameterConfig> {
public:
static constexpr int kType = AddIncomingStreamsRequestParameterConfig::kType;
explicit AddIncomingStreamsRequestParameter(
ReconfigRequestSN request_sequence_number,
uint16_t nbr_of_new_streams)
: request_sequence_number_(request_sequence_number),
nbr_of_new_streams_(nbr_of_new_streams) {}
static absl::optional<AddIncomingStreamsRequestParameter> Parse(
rtc::ArrayView<const uint8_t> data);
void SerializeTo(std::vector<uint8_t>& out) const override;
std::string ToString() const override;
ReconfigRequestSN request_sequence_number() const {
return request_sequence_number_;
}
uint16_t nbr_of_new_streams() const { return nbr_of_new_streams_; }
private:
ReconfigRequestSN request_sequence_number_;
uint16_t nbr_of_new_streams_;
};
} // namespace dcsctp
#endif // NET_DCSCTP_PACKET_PARAMETER_ADD_INCOMING_STREAMS_REQUEST_PARAMETER_H_

View file

@ -0,0 +1,67 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter.h"
#include <stdint.h>
#include <string>
#include <type_traits>
#include <vector>
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "net/dcsctp/packet/bounded_byte_reader.h"
#include "net/dcsctp/packet/bounded_byte_writer.h"
#include "net/dcsctp/packet/tlv_trait.h"
#include "rtc_base/strings/string_builder.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc6525#section-4.5
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Parameter Type = 17 | Parameter Length = 12 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Re-configuration Request Sequence Number |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Number of new streams | Reserved |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
constexpr int AddOutgoingStreamsRequestParameter::kType;
absl::optional<AddOutgoingStreamsRequestParameter>
AddOutgoingStreamsRequestParameter::Parse(rtc::ArrayView<const uint8_t> data) {
absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
if (!reader.has_value()) {
return absl::nullopt;
}
ReconfigRequestSN request_sequence_number(reader->Load32<4>());
uint16_t nbr_of_new_streams = reader->Load16<8>();
return AddOutgoingStreamsRequestParameter(request_sequence_number,
nbr_of_new_streams);
}
void AddOutgoingStreamsRequestParameter::SerializeTo(
std::vector<uint8_t>& out) const {
BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out);
writer.Store32<4>(*request_sequence_number_);
writer.Store16<8>(nbr_of_new_streams_);
}
std::string AddOutgoingStreamsRequestParameter::ToString() const {
rtc::StringBuilder sb;
sb << "Add Outgoing Streams Request, req_seq_nbr="
<< *request_sequence_number();
return sb.Release();
}
} // namespace dcsctp

View file

@ -0,0 +1,63 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef NET_DCSCTP_PACKET_PARAMETER_ADD_OUTGOING_STREAMS_REQUEST_PARAMETER_H_
#define NET_DCSCTP_PACKET_PARAMETER_ADD_OUTGOING_STREAMS_REQUEST_PARAMETER_H_
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "net/dcsctp/common/internal_types.h"
#include "net/dcsctp/packet/parameter/parameter.h"
#include "net/dcsctp/packet/tlv_trait.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc6525#section-4.5
struct AddOutgoingStreamsRequestParameterConfig : ParameterConfig {
static constexpr int kType = 17;
static constexpr size_t kHeaderSize = 12;
static constexpr size_t kVariableLengthAlignment = 0;
};
class AddOutgoingStreamsRequestParameter
: public Parameter,
public TLVTrait<AddOutgoingStreamsRequestParameterConfig> {
public:
static constexpr int kType = AddOutgoingStreamsRequestParameterConfig::kType;
explicit AddOutgoingStreamsRequestParameter(
ReconfigRequestSN request_sequence_number,
uint16_t nbr_of_new_streams)
: request_sequence_number_(request_sequence_number),
nbr_of_new_streams_(nbr_of_new_streams) {}
static absl::optional<AddOutgoingStreamsRequestParameter> Parse(
rtc::ArrayView<const uint8_t> data);
void SerializeTo(std::vector<uint8_t>& out) const override;
std::string ToString() const override;
ReconfigRequestSN request_sequence_number() const {
return request_sequence_number_;
}
uint16_t nbr_of_new_streams() const { return nbr_of_new_streams_; }
private:
ReconfigRequestSN request_sequence_number_;
uint16_t nbr_of_new_streams_;
};
} // namespace dcsctp
#endif // NET_DCSCTP_PACKET_PARAMETER_ADD_OUTGOING_STREAMS_REQUEST_PARAMETER_H_

View file

@ -0,0 +1,45 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "net/dcsctp/packet/parameter/forward_tsn_supported_parameter.h"
#include <stdint.h>
#include <vector>
#include "absl/types/optional.h"
#include "api/array_view.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc3758#section-3.1
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Parameter Type = 49152 | Parameter Length = 4 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
constexpr int ForwardTsnSupportedParameter::kType;
absl::optional<ForwardTsnSupportedParameter>
ForwardTsnSupportedParameter::Parse(rtc::ArrayView<const uint8_t> data) {
if (!ParseTLV(data).has_value()) {
return absl::nullopt;
}
return ForwardTsnSupportedParameter();
}
void ForwardTsnSupportedParameter::SerializeTo(
std::vector<uint8_t>& out) const {
AllocateTLV(out);
}
std::string ForwardTsnSupportedParameter::ToString() const {
return "Forward TSN Supported";
}
} // namespace dcsctp

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef NET_DCSCTP_PACKET_PARAMETER_FORWARD_TSN_SUPPORTED_PARAMETER_H_
#define NET_DCSCTP_PACKET_PARAMETER_FORWARD_TSN_SUPPORTED_PARAMETER_H_
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "net/dcsctp/packet/parameter/parameter.h"
#include "net/dcsctp/packet/tlv_trait.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc3758#section-3.1
struct ForwardTsnSupportedParameterConfig : ParameterConfig {
static constexpr int kType = 49152;
static constexpr size_t kHeaderSize = 4;
static constexpr size_t kVariableLengthAlignment = 0;
};
class ForwardTsnSupportedParameter
: public Parameter,
public TLVTrait<ForwardTsnSupportedParameterConfig> {
public:
static constexpr int kType = ForwardTsnSupportedParameterConfig::kType;
ForwardTsnSupportedParameter() {}
static absl::optional<ForwardTsnSupportedParameter> Parse(
rtc::ArrayView<const uint8_t> data);
void SerializeTo(std::vector<uint8_t>& out) const override;
std::string ToString() const override;
};
} // namespace dcsctp
#endif // NET_DCSCTP_PACKET_PARAMETER_FORWARD_TSN_SUPPORTED_PARAMETER_H_

View file

@ -0,0 +1,60 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "net/dcsctp/packet/parameter/heartbeat_info_parameter.h"
#include <stdint.h>
#include <string>
#include <type_traits>
#include <vector>
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "net/dcsctp/packet/bounded_byte_reader.h"
#include "net/dcsctp/packet/bounded_byte_writer.h"
#include "net/dcsctp/packet/tlv_trait.h"
#include "rtc_base/strings/string_builder.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc4960#section-3.3.5
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Type = 4 | Chunk Flags | Heartbeat Length |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// \ \
// / Heartbeat Information TLV (Variable-Length) /
// \ \
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
constexpr int HeartbeatInfoParameter::kType;
absl::optional<HeartbeatInfoParameter> HeartbeatInfoParameter::Parse(
rtc::ArrayView<const uint8_t> data) {
absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
if (!reader.has_value()) {
return absl::nullopt;
}
return HeartbeatInfoParameter(reader->variable_data());
}
void HeartbeatInfoParameter::SerializeTo(std::vector<uint8_t>& out) const {
BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out, info_.size());
writer.CopyToVariableData(info_);
}
std::string HeartbeatInfoParameter::ToString() const {
rtc::StringBuilder sb;
sb << "Heartbeat Info parameter (info_length=" << info_.size() << ")";
return sb.Release();
}
} // namespace dcsctp

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef NET_DCSCTP_PACKET_PARAMETER_HEARTBEAT_INFO_PARAMETER_H_
#define NET_DCSCTP_PACKET_PARAMETER_HEARTBEAT_INFO_PARAMETER_H_
#include <stddef.h>
#include <cstdint>
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "net/dcsctp/packet/parameter/parameter.h"
#include "net/dcsctp/packet/tlv_trait.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc4960#section-3.3.5
struct HeartbeatInfoParameterConfig : ParameterConfig {
static constexpr int kType = 1;
static constexpr size_t kHeaderSize = 4;
static constexpr size_t kVariableLengthAlignment = 1;
};
class HeartbeatInfoParameter : public Parameter,
public TLVTrait<HeartbeatInfoParameterConfig> {
public:
static constexpr int kType = HeartbeatInfoParameterConfig::kType;
explicit HeartbeatInfoParameter(rtc::ArrayView<const uint8_t> info)
: info_(info.begin(), info.end()) {}
static absl::optional<HeartbeatInfoParameter> Parse(
rtc::ArrayView<const uint8_t> data);
void SerializeTo(std::vector<uint8_t>& out) const override;
std::string ToString() const override;
rtc::ArrayView<const uint8_t> info() const { return info_; }
private:
std::vector<uint8_t> info_;
};
} // namespace dcsctp
#endif // NET_DCSCTP_PACKET_PARAMETER_HEARTBEAT_INFO_PARAMETER_H_

View file

@ -0,0 +1,89 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter.h"
#include <stddef.h>
#include <cstdint>
#include <string>
#include <utility>
#include <vector>
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "net/dcsctp/packet/bounded_byte_reader.h"
#include "net/dcsctp/packet/bounded_byte_writer.h"
#include "net/dcsctp/packet/tlv_trait.h"
#include "rtc_base/strings/string_builder.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc6525#section-4.2
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Parameter Type = 14 | Parameter Length = 8 + 2 * N |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Re-configuration Request Sequence Number |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Stream Number 1 (optional) | Stream Number 2 (optional) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// / ...... /
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Stream Number N-1 (optional) | Stream Number N (optional) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
constexpr int IncomingSSNResetRequestParameter::kType;
absl::optional<IncomingSSNResetRequestParameter>
IncomingSSNResetRequestParameter::Parse(rtc::ArrayView<const uint8_t> data) {
absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
if (!reader.has_value()) {
return absl::nullopt;
}
ReconfigRequestSN request_sequence_number(reader->Load32<4>());
size_t stream_count = reader->variable_data_size() / kStreamIdSize;
std::vector<StreamID> stream_ids;
stream_ids.reserve(stream_count);
for (size_t i = 0; i < stream_count; ++i) {
BoundedByteReader<kStreamIdSize> sub_reader =
reader->sub_reader<kStreamIdSize>(i * kStreamIdSize);
stream_ids.push_back(StreamID(sub_reader.Load16<0>()));
}
return IncomingSSNResetRequestParameter(request_sequence_number,
std::move(stream_ids));
}
void IncomingSSNResetRequestParameter::SerializeTo(
std::vector<uint8_t>& out) const {
size_t variable_size = stream_ids_.size() * kStreamIdSize;
BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out, variable_size);
writer.Store32<4>(*request_sequence_number_);
for (size_t i = 0; i < stream_ids_.size(); ++i) {
BoundedByteWriter<kStreamIdSize> sub_writer =
writer.sub_writer<kStreamIdSize>(i * kStreamIdSize);
sub_writer.Store16<0>(*stream_ids_[i]);
}
}
std::string IncomingSSNResetRequestParameter::ToString() const {
rtc::StringBuilder sb;
sb << "Incoming SSN Reset Request, req_seq_nbr="
<< *request_sequence_number();
return sb.Release();
}
} // namespace dcsctp

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef NET_DCSCTP_PACKET_PARAMETER_INCOMING_SSN_RESET_REQUEST_PARAMETER_H_
#define NET_DCSCTP_PACKET_PARAMETER_INCOMING_SSN_RESET_REQUEST_PARAMETER_H_
#include <stddef.h>
#include <cstdint>
#include <string>
#include <utility>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "net/dcsctp/common/internal_types.h"
#include "net/dcsctp/packet/parameter/parameter.h"
#include "net/dcsctp/public/types.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc6525#section-4.2
struct IncomingSSNResetRequestParameterConfig : ParameterConfig {
static constexpr int kType = 14;
static constexpr size_t kHeaderSize = 8;
static constexpr size_t kVariableLengthAlignment = 2;
};
class IncomingSSNResetRequestParameter
: public Parameter,
public TLVTrait<IncomingSSNResetRequestParameterConfig> {
public:
static constexpr int kType = IncomingSSNResetRequestParameterConfig::kType;
explicit IncomingSSNResetRequestParameter(
ReconfigRequestSN request_sequence_number,
std::vector<StreamID> stream_ids)
: request_sequence_number_(request_sequence_number),
stream_ids_(std::move(stream_ids)) {}
static absl::optional<IncomingSSNResetRequestParameter> Parse(
rtc::ArrayView<const uint8_t> data);
void SerializeTo(std::vector<uint8_t>& out) const override;
std::string ToString() const override;
ReconfigRequestSN request_sequence_number() const {
return request_sequence_number_;
}
rtc::ArrayView<const StreamID> stream_ids() const { return stream_ids_; }
private:
static constexpr size_t kStreamIdSize = sizeof(uint16_t);
ReconfigRequestSN request_sequence_number_;
std::vector<StreamID> stream_ids_;
};
} // namespace dcsctp
#endif // NET_DCSCTP_PACKET_PARAMETER_INCOMING_SSN_RESET_REQUEST_PARAMETER_H_

View file

@ -0,0 +1,101 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h"
#include <stddef.h>
#include <cstdint>
#include <string>
#include <utility>
#include <vector>
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "net/dcsctp/common/internal_types.h"
#include "net/dcsctp/packet/bounded_byte_reader.h"
#include "net/dcsctp/packet/bounded_byte_writer.h"
#include "net/dcsctp/packet/tlv_trait.h"
#include "net/dcsctp/public/types.h"
#include "rtc_base/strings/string_builder.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc6525#section-4.1
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Parameter Type = 13 | Parameter Length = 16 + 2 * N |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Re-configuration Request Sequence Number |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Re-configuration Response Sequence Number |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Sender's Last Assigned TSN |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Stream Number 1 (optional) | Stream Number 2 (optional) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// / ...... /
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Stream Number N-1 (optional) | Stream Number N (optional) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
constexpr int OutgoingSSNResetRequestParameter::kType;
absl::optional<OutgoingSSNResetRequestParameter>
OutgoingSSNResetRequestParameter::Parse(rtc::ArrayView<const uint8_t> data) {
absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
if (!reader.has_value()) {
return absl::nullopt;
}
ReconfigRequestSN request_sequence_number(reader->Load32<4>());
ReconfigRequestSN response_sequence_number(reader->Load32<8>());
TSN sender_last_assigned_tsn(reader->Load32<12>());
size_t stream_count = reader->variable_data_size() / kStreamIdSize;
std::vector<StreamID> stream_ids;
stream_ids.reserve(stream_count);
for (size_t i = 0; i < stream_count; ++i) {
BoundedByteReader<kStreamIdSize> sub_reader =
reader->sub_reader<kStreamIdSize>(i * kStreamIdSize);
stream_ids.push_back(StreamID(sub_reader.Load16<0>()));
}
return OutgoingSSNResetRequestParameter(
request_sequence_number, response_sequence_number,
sender_last_assigned_tsn, std::move(stream_ids));
}
void OutgoingSSNResetRequestParameter::SerializeTo(
std::vector<uint8_t>& out) const {
size_t variable_size = stream_ids_.size() * kStreamIdSize;
BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out, variable_size);
writer.Store32<4>(*request_sequence_number_);
writer.Store32<8>(*response_sequence_number_);
writer.Store32<12>(*sender_last_assigned_tsn_);
for (size_t i = 0; i < stream_ids_.size(); ++i) {
BoundedByteWriter<kStreamIdSize> sub_writer =
writer.sub_writer<kStreamIdSize>(i * kStreamIdSize);
sub_writer.Store16<0>(*stream_ids_[i]);
}
}
std::string OutgoingSSNResetRequestParameter::ToString() const {
rtc::StringBuilder sb;
sb << "Outgoing SSN Reset Request, req_seq_nbr=" << *request_sequence_number()
<< ", resp_seq_nbr=" << *response_sequence_number()
<< ", sender_last_asg_tsn=" << *sender_last_assigned_tsn();
return sb.Release();
}
} // namespace dcsctp

View file

@ -0,0 +1,78 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef NET_DCSCTP_PACKET_PARAMETER_OUTGOING_SSN_RESET_REQUEST_PARAMETER_H_
#define NET_DCSCTP_PACKET_PARAMETER_OUTGOING_SSN_RESET_REQUEST_PARAMETER_H_
#include <stddef.h>
#include <stdint.h>
#include <cstdint>
#include <string>
#include <utility>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "net/dcsctp/common/internal_types.h"
#include "net/dcsctp/packet/parameter/parameter.h"
#include "net/dcsctp/packet/tlv_trait.h"
#include "net/dcsctp/public/types.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc6525#section-4.1
struct OutgoingSSNResetRequestParameterConfig : ParameterConfig {
static constexpr int kType = 13;
static constexpr size_t kHeaderSize = 16;
static constexpr size_t kVariableLengthAlignment = 2;
};
class OutgoingSSNResetRequestParameter
: public Parameter,
public TLVTrait<OutgoingSSNResetRequestParameterConfig> {
public:
static constexpr int kType = OutgoingSSNResetRequestParameterConfig::kType;
explicit OutgoingSSNResetRequestParameter(
ReconfigRequestSN request_sequence_number,
ReconfigRequestSN response_sequence_number,
TSN sender_last_assigned_tsn,
std::vector<StreamID> stream_ids)
: request_sequence_number_(request_sequence_number),
response_sequence_number_(response_sequence_number),
sender_last_assigned_tsn_(sender_last_assigned_tsn),
stream_ids_(std::move(stream_ids)) {}
static absl::optional<OutgoingSSNResetRequestParameter> Parse(
rtc::ArrayView<const uint8_t> data);
void SerializeTo(std::vector<uint8_t>& out) const override;
std::string ToString() const override;
ReconfigRequestSN request_sequence_number() const {
return request_sequence_number_;
}
ReconfigRequestSN response_sequence_number() const {
return response_sequence_number_;
}
TSN sender_last_assigned_tsn() const { return sender_last_assigned_tsn_; }
rtc::ArrayView<const StreamID> stream_ids() const { return stream_ids_; }
private:
static constexpr size_t kStreamIdSize = sizeof(uint16_t);
ReconfigRequestSN request_sequence_number_;
ReconfigRequestSN response_sequence_number_;
TSN sender_last_assigned_tsn_;
std::vector<StreamID> stream_ids_;
};
} // namespace dcsctp
#endif // NET_DCSCTP_PACKET_PARAMETER_OUTGOING_SSN_RESET_REQUEST_PARAMETER_H_

View file

@ -0,0 +1,96 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "net/dcsctp/packet/parameter/parameter.h"
#include <stddef.h>
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "absl/memory/memory.h"
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "net/dcsctp/common/math.h"
#include "net/dcsctp/packet/bounded_byte_reader.h"
#include "net/dcsctp/packet/parameter/add_incoming_streams_request_parameter.h"
#include "net/dcsctp/packet/parameter/add_outgoing_streams_request_parameter.h"
#include "net/dcsctp/packet/parameter/forward_tsn_supported_parameter.h"
#include "net/dcsctp/packet/parameter/heartbeat_info_parameter.h"
#include "net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter.h"
#include "net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h"
#include "net/dcsctp/packet/parameter/reconfiguration_response_parameter.h"
#include "net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter.h"
#include "net/dcsctp/packet/parameter/state_cookie_parameter.h"
#include "net/dcsctp/packet/parameter/supported_extensions_parameter.h"
#include "net/dcsctp/packet/tlv_trait.h"
#include "rtc_base/logging.h"
#include "rtc_base/strings/string_builder.h"
namespace dcsctp {
constexpr size_t kParameterHeaderSize = 4;
Parameters::Builder& Parameters::Builder::Add(const Parameter& p) {
// https://tools.ietf.org/html/rfc4960#section-3.2.1
// "If the length of the parameter is not a multiple of 4 bytes, the sender
// pads the parameter at the end (i.e., after the Parameter Value field) with
// all zero bytes."
if (data_.size() % 4 != 0) {
data_.resize(RoundUpTo4(data_.size()));
}
p.SerializeTo(data_);
return *this;
}
std::vector<ParameterDescriptor> Parameters::descriptors() const {
rtc::ArrayView<const uint8_t> span(data_);
std::vector<ParameterDescriptor> result;
while (!span.empty()) {
BoundedByteReader<kParameterHeaderSize> header(span);
uint16_t type = header.Load16<0>();
uint16_t length = header.Load16<2>();
result.emplace_back(type, span.subview(0, length));
size_t length_with_padding = RoundUpTo4(length);
if (length_with_padding > span.size()) {
break;
}
span = span.subview(length_with_padding);
}
return result;
}
absl::optional<Parameters> Parameters::Parse(
rtc::ArrayView<const uint8_t> data) {
// Validate the parameter descriptors
rtc::ArrayView<const uint8_t> span(data);
while (!span.empty()) {
if (span.size() < kParameterHeaderSize) {
RTC_DLOG(LS_WARNING) << "Insufficient parameter length";
return absl::nullopt;
}
BoundedByteReader<kParameterHeaderSize> header(span);
uint16_t length = header.Load16<2>();
if (length < kParameterHeaderSize || length > span.size()) {
RTC_DLOG(LS_WARNING) << "Invalid parameter length field";
return absl::nullopt;
}
size_t length_with_padding = RoundUpTo4(length);
if (length_with_padding > span.size()) {
break;
}
span = span.subview(length_with_padding);
}
return Parameters(std::vector<uint8_t>(data.begin(), data.end()));
}
} // namespace dcsctp

View file

@ -0,0 +1,96 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef NET_DCSCTP_PACKET_PARAMETER_PARAMETER_H_
#define NET_DCSCTP_PACKET_PARAMETER_PARAMETER_H_
#include <stddef.h>
#include <algorithm>
#include <cstdint>
#include <iterator>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include "absl/algorithm/container.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "net/dcsctp/packet/tlv_trait.h"
#include "rtc_base/strings/string_builder.h"
namespace dcsctp {
class Parameter {
public:
Parameter() {}
virtual ~Parameter() = default;
Parameter(const Parameter& other) = default;
Parameter& operator=(const Parameter& other) = default;
virtual void SerializeTo(std::vector<uint8_t>& out) const = 0;
virtual std::string ToString() const = 0;
};
struct ParameterDescriptor {
ParameterDescriptor(uint16_t type, rtc::ArrayView<const uint8_t> data)
: type(type), data(data) {}
uint16_t type;
rtc::ArrayView<const uint8_t> data;
};
class Parameters {
public:
class Builder {
public:
Builder() {}
Builder& Add(const Parameter& p);
Parameters Build() { return Parameters(std::move(data_)); }
private:
std::vector<uint8_t> data_;
};
static absl::optional<Parameters> Parse(rtc::ArrayView<const uint8_t> data);
Parameters() {}
Parameters(Parameters&& other) = default;
Parameters& operator=(Parameters&& other) = default;
rtc::ArrayView<const uint8_t> data() const { return data_; }
std::vector<ParameterDescriptor> descriptors() const;
template <typename P>
absl::optional<P> get() const {
static_assert(std::is_base_of<Parameter, P>::value,
"Template parameter not derived from Parameter");
for (const auto& p : descriptors()) {
if (p.type == P::kType) {
return P::Parse(p.data);
}
}
return absl::nullopt;
}
private:
explicit Parameters(std::vector<uint8_t> data) : data_(std::move(data)) {}
std::vector<uint8_t> data_;
};
struct ParameterConfig {
static constexpr int kTypeSizeInBytes = 2;
};
} // namespace dcsctp
#endif // NET_DCSCTP_PACKET_PARAMETER_PARAMETER_H_

View file

@ -0,0 +1,152 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "net/dcsctp/packet/parameter/reconfiguration_response_parameter.h"
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <type_traits>
#include <vector>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "net/dcsctp/packet/bounded_byte_reader.h"
#include "net/dcsctp/packet/bounded_byte_writer.h"
#include "net/dcsctp/packet/tlv_trait.h"
#include "rtc_base/logging.h"
#include "rtc_base/strings/string_builder.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc6525#section-4.4
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Parameter Type = 16 | Parameter Length |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Re-configuration Response Sequence Number |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Result |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Sender's Next TSN (optional) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Receiver's Next TSN (optional) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
constexpr int ReconfigurationResponseParameter::kType;
absl::string_view ToString(ReconfigurationResponseParameter::Result result) {
switch (result) {
case ReconfigurationResponseParameter::Result::kSuccessNothingToDo:
return "Success: nothing to do";
case ReconfigurationResponseParameter::Result::kSuccessPerformed:
return "Success: performed";
case ReconfigurationResponseParameter::Result::kDenied:
return "Denied";
case ReconfigurationResponseParameter::Result::kErrorWrongSSN:
return "Error: wrong ssn";
case ReconfigurationResponseParameter::Result::
kErrorRequestAlreadyInProgress:
return "Error: request already in progress";
case ReconfigurationResponseParameter::Result::kErrorBadSequenceNumber:
return "Error: bad sequence number";
case ReconfigurationResponseParameter::Result::kInProgress:
return "In progress";
}
}
absl::optional<ReconfigurationResponseParameter>
ReconfigurationResponseParameter::Parse(rtc::ArrayView<const uint8_t> data) {
absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
if (!reader.has_value()) {
return absl::nullopt;
}
ReconfigRequestSN response_sequence_number(reader->Load32<4>());
Result result;
uint32_t result_nbr = reader->Load32<8>();
switch (result_nbr) {
case 0:
result = ReconfigurationResponseParameter::Result::kSuccessNothingToDo;
break;
case 1:
result = ReconfigurationResponseParameter::Result::kSuccessPerformed;
break;
case 2:
result = ReconfigurationResponseParameter::Result::kDenied;
break;
case 3:
result = ReconfigurationResponseParameter::Result::kErrorWrongSSN;
break;
case 4:
result = ReconfigurationResponseParameter::Result::
kErrorRequestAlreadyInProgress;
break;
case 5:
result =
ReconfigurationResponseParameter::Result::kErrorBadSequenceNumber;
break;
case 6:
result = ReconfigurationResponseParameter::Result::kInProgress;
break;
default:
RTC_DLOG(LS_WARNING) << "Invalid reconfig response result: "
<< result_nbr;
return absl::nullopt;
}
if (reader->variable_data().empty()) {
return ReconfigurationResponseParameter(response_sequence_number, result);
} else if (reader->variable_data_size() != kNextTsnHeaderSize) {
RTC_DLOG(LS_WARNING) << "Invalid parameter size";
return absl::nullopt;
}
BoundedByteReader<kNextTsnHeaderSize> sub_reader =
reader->sub_reader<kNextTsnHeaderSize>(0);
TSN sender_next_tsn(sub_reader.Load32<0>());
TSN receiver_next_tsn(sub_reader.Load32<4>());
return ReconfigurationResponseParameter(response_sequence_number, result,
sender_next_tsn, receiver_next_tsn);
}
void ReconfigurationResponseParameter::SerializeTo(
std::vector<uint8_t>& out) const {
size_t variable_size =
(sender_next_tsn().has_value() ? kNextTsnHeaderSize : 0);
BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out, variable_size);
writer.Store32<4>(*response_sequence_number_);
uint32_t result_nbr =
static_cast<std::underlying_type<Result>::type>(result_);
writer.Store32<8>(result_nbr);
if (sender_next_tsn().has_value()) {
BoundedByteWriter<kNextTsnHeaderSize> sub_writer =
writer.sub_writer<kNextTsnHeaderSize>(0);
sub_writer.Store32<0>(sender_next_tsn_.has_value() ? **sender_next_tsn_
: 0);
sub_writer.Store32<4>(receiver_next_tsn_.has_value() ? **receiver_next_tsn_
: 0);
}
}
std::string ReconfigurationResponseParameter::ToString() const {
rtc::StringBuilder sb;
sb << "Re-configuration Response, resp_seq_nbr="
<< *response_sequence_number();
return sb.Release();
}
} // namespace dcsctp

View file

@ -0,0 +1,92 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef NET_DCSCTP_PACKET_PARAMETER_RECONFIGURATION_RESPONSE_PARAMETER_H_
#define NET_DCSCTP_PACKET_PARAMETER_RECONFIGURATION_RESPONSE_PARAMETER_H_
#include <stddef.h>
#include <cstdint>
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "net/dcsctp/common/internal_types.h"
#include "net/dcsctp/packet/parameter/parameter.h"
#include "net/dcsctp/packet/tlv_trait.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc6525#section-4.4
struct ReconfigurationResponseParameterConfig : ParameterConfig {
static constexpr int kType = 16;
static constexpr size_t kHeaderSize = 12;
static constexpr size_t kVariableLengthAlignment = 4;
};
class ReconfigurationResponseParameter
: public Parameter,
public TLVTrait<ReconfigurationResponseParameterConfig> {
public:
static constexpr int kType = ReconfigurationResponseParameterConfig::kType;
enum class Result {
kSuccessNothingToDo = 0,
kSuccessPerformed = 1,
kDenied = 2,
kErrorWrongSSN = 3,
kErrorRequestAlreadyInProgress = 4,
kErrorBadSequenceNumber = 5,
kInProgress = 6,
};
ReconfigurationResponseParameter(ReconfigRequestSN response_sequence_number,
Result result)
: response_sequence_number_(response_sequence_number),
result_(result),
sender_next_tsn_(absl::nullopt),
receiver_next_tsn_(absl::nullopt) {}
explicit ReconfigurationResponseParameter(
ReconfigRequestSN response_sequence_number,
Result result,
TSN sender_next_tsn,
TSN receiver_next_tsn)
: response_sequence_number_(response_sequence_number),
result_(result),
sender_next_tsn_(sender_next_tsn),
receiver_next_tsn_(receiver_next_tsn) {}
static absl::optional<ReconfigurationResponseParameter> Parse(
rtc::ArrayView<const uint8_t> data);
void SerializeTo(std::vector<uint8_t>& out) const override;
std::string ToString() const override;
ReconfigRequestSN response_sequence_number() const {
return response_sequence_number_;
}
Result result() const { return result_; }
absl::optional<TSN> sender_next_tsn() const { return sender_next_tsn_; }
absl::optional<TSN> receiver_next_tsn() const { return receiver_next_tsn_; }
private:
static constexpr size_t kNextTsnHeaderSize = 8;
ReconfigRequestSN response_sequence_number_;
Result result_;
absl::optional<TSN> sender_next_tsn_;
absl::optional<TSN> receiver_next_tsn_;
};
absl::string_view ToString(ReconfigurationResponseParameter::Result result);
} // namespace dcsctp
#endif // NET_DCSCTP_PACKET_PARAMETER_RECONFIGURATION_RESPONSE_PARAMETER_H_

View file

@ -0,0 +1,60 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "net/dcsctp/packet/parameter/ssn_tsn_reset_request_parameter.h"
#include <stdint.h>
#include <string>
#include <type_traits>
#include <vector>
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "net/dcsctp/packet/bounded_byte_reader.h"
#include "net/dcsctp/packet/bounded_byte_writer.h"
#include "net/dcsctp/packet/tlv_trait.h"
#include "rtc_base/strings/string_builder.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc6525#section-4.3
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Parameter Type = 15 | Parameter Length = 8 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Re-configuration Request Sequence Number |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
constexpr int SSNTSNResetRequestParameter::kType;
absl::optional<SSNTSNResetRequestParameter> SSNTSNResetRequestParameter::Parse(
rtc::ArrayView<const uint8_t> data) {
absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
if (!reader.has_value()) {
return absl::nullopt;
}
ReconfigRequestSN request_sequence_number(reader->Load32<4>());
return SSNTSNResetRequestParameter(request_sequence_number);
}
void SSNTSNResetRequestParameter::SerializeTo(std::vector<uint8_t>& out) const {
BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out);
writer.Store32<4>(*request_sequence_number_);
}
std::string SSNTSNResetRequestParameter::ToString() const {
rtc::StringBuilder sb;
sb << "SSN/TSN Reset Request, req_seq_nbr=" << *request_sequence_number();
return sb.Release();
}
} // namespace dcsctp

View file

@ -0,0 +1,59 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef NET_DCSCTP_PACKET_PARAMETER_SSN_TSN_RESET_REQUEST_PARAMETER_H_
#define NET_DCSCTP_PACKET_PARAMETER_SSN_TSN_RESET_REQUEST_PARAMETER_H_
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "net/dcsctp/common/internal_types.h"
#include "net/dcsctp/packet/parameter/parameter.h"
#include "net/dcsctp/packet/tlv_trait.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc6525#section-4.3
struct SSNTSNResetRequestParameterConfig : ParameterConfig {
static constexpr int kType = 15;
static constexpr size_t kHeaderSize = 8;
static constexpr size_t kVariableLengthAlignment = 0;
};
class SSNTSNResetRequestParameter
: public Parameter,
public TLVTrait<SSNTSNResetRequestParameterConfig> {
public:
static constexpr int kType = SSNTSNResetRequestParameterConfig::kType;
explicit SSNTSNResetRequestParameter(
ReconfigRequestSN request_sequence_number)
: request_sequence_number_(request_sequence_number) {}
static absl::optional<SSNTSNResetRequestParameter> Parse(
rtc::ArrayView<const uint8_t> data);
void SerializeTo(std::vector<uint8_t>& out) const override;
std::string ToString() const override;
ReconfigRequestSN request_sequence_number() const {
return request_sequence_number_;
}
private:
ReconfigRequestSN request_sequence_number_;
};
} // namespace dcsctp
#endif // NET_DCSCTP_PACKET_PARAMETER_SSN_TSN_RESET_REQUEST_PARAMETER_H_

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "net/dcsctp/packet/parameter/state_cookie_parameter.h"
#include <stdint.h>
#include <string>
#include <type_traits>
#include <vector>
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "net/dcsctp/packet/bounded_byte_reader.h"
#include "net/dcsctp/packet/bounded_byte_writer.h"
#include "net/dcsctp/packet/tlv_trait.h"
#include "rtc_base/strings/string_builder.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc4960#section-3.3.3.1
constexpr int StateCookieParameter::kType;
absl::optional<StateCookieParameter> StateCookieParameter::Parse(
rtc::ArrayView<const uint8_t> data) {
absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
if (!reader.has_value()) {
return absl::nullopt;
}
return StateCookieParameter(reader->variable_data());
}
void StateCookieParameter::SerializeTo(std::vector<uint8_t>& out) const {
BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out, data_.size());
writer.CopyToVariableData(data_);
}
std::string StateCookieParameter::ToString() const {
rtc::StringBuilder sb;
sb << "State Cookie parameter (cookie_length=" << data_.size() << ")";
return sb.Release();
}
} // namespace dcsctp

View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef NET_DCSCTP_PACKET_PARAMETER_STATE_COOKIE_PARAMETER_H_
#define NET_DCSCTP_PACKET_PARAMETER_STATE_COOKIE_PARAMETER_H_
#include <stddef.h>
#include <stdint.h>
#include <cstdint>
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "net/dcsctp/packet/parameter/parameter.h"
#include "net/dcsctp/packet/tlv_trait.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc4960#section-3.3.3.1
struct StateCookieParameterConfig : ParameterConfig {
static constexpr int kType = 7;
static constexpr size_t kHeaderSize = 4;
static constexpr size_t kVariableLengthAlignment = 1;
};
class StateCookieParameter : public Parameter,
public TLVTrait<StateCookieParameterConfig> {
public:
static constexpr int kType = StateCookieParameterConfig::kType;
explicit StateCookieParameter(rtc::ArrayView<const uint8_t> data)
: data_(data.begin(), data.end()) {}
static absl::optional<StateCookieParameter> Parse(
rtc::ArrayView<const uint8_t> data);
void SerializeTo(std::vector<uint8_t>& out) const override;
std::string ToString() const override;
rtc::ArrayView<const uint8_t> data() const { return data_; }
private:
std::vector<uint8_t> data_;
};
} // namespace dcsctp
#endif // NET_DCSCTP_PACKET_PARAMETER_STATE_COOKIE_PARAMETER_H_

View file

@ -0,0 +1,65 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "net/dcsctp/packet/parameter/supported_extensions_parameter.h"
#include <cstdint>
#include <string>
#include <utility>
#include <vector>
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "net/dcsctp/packet/bounded_byte_reader.h"
#include "net/dcsctp/packet/bounded_byte_writer.h"
#include "net/dcsctp/packet/tlv_trait.h"
#include "rtc_base/strings/str_join.h"
#include "rtc_base/strings/string_builder.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc5061#section-4.2.7
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Parameter Type = 0x8008 | Parameter Length |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | CHUNK TYPE 1 | CHUNK TYPE 2 | CHUNK TYPE 3 | CHUNK TYPE 4 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | .... |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | CHUNK TYPE N | PAD | PAD | PAD |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
constexpr int SupportedExtensionsParameter::kType;
absl::optional<SupportedExtensionsParameter>
SupportedExtensionsParameter::Parse(rtc::ArrayView<const uint8_t> data) {
absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
if (!reader.has_value()) {
return absl::nullopt;
}
std::vector<uint8_t> chunk_types(reader->variable_data().begin(),
reader->variable_data().end());
return SupportedExtensionsParameter(std::move(chunk_types));
}
void SupportedExtensionsParameter::SerializeTo(
std::vector<uint8_t>& out) const {
BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out, chunk_types_.size());
writer.CopyToVariableData(chunk_types_);
}
std::string SupportedExtensionsParameter::ToString() const {
rtc::StringBuilder sb;
sb << "Supported Extensions (" << webrtc::StrJoin(chunk_types_, ", ") << ")";
return sb.Release();
}
} // namespace dcsctp

View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef NET_DCSCTP_PACKET_PARAMETER_SUPPORTED_EXTENSIONS_PARAMETER_H_
#define NET_DCSCTP_PACKET_PARAMETER_SUPPORTED_EXTENSIONS_PARAMETER_H_
#include <stddef.h>
#include <algorithm>
#include <cstdint>
#include <iterator>
#include <string>
#include <utility>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "net/dcsctp/packet/parameter/parameter.h"
#include "net/dcsctp/packet/tlv_trait.h"
namespace dcsctp {
// https://tools.ietf.org/html/rfc5061#section-4.2.7
struct SupportedExtensionsParameterConfig : ParameterConfig {
static constexpr int kType = 0x8008;
static constexpr size_t kHeaderSize = 4;
static constexpr size_t kVariableLengthAlignment = 1;
};
class SupportedExtensionsParameter
: public Parameter,
public TLVTrait<SupportedExtensionsParameterConfig> {
public:
static constexpr int kType = SupportedExtensionsParameterConfig::kType;
explicit SupportedExtensionsParameter(std::vector<uint8_t> chunk_types)
: chunk_types_(std::move(chunk_types)) {}
static absl::optional<SupportedExtensionsParameter> Parse(
rtc::ArrayView<const uint8_t> data);
void SerializeTo(std::vector<uint8_t>& out) const override;
std::string ToString() const override;
bool supports(uint8_t chunk_type) const {
return std::find(chunk_types_.begin(), chunk_types_.end(), chunk_type) !=
chunk_types_.end();
}
rtc::ArrayView<const uint8_t> chunk_types() const { return chunk_types_; }
private:
std::vector<uint8_t> chunk_types_;
};
} // namespace dcsctp
#endif // NET_DCSCTP_PACKET_PARAMETER_SUPPORTED_EXTENSIONS_PARAMETER_H_

View file

@ -0,0 +1,58 @@
/*
* Copyright (c) 2023 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter.h"
#include <stdint.h>
#include <vector>
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "rtc_base/strings/string_builder.h"
namespace dcsctp {
// https://www.ietf.org/archive/id/draft-tuexen-tsvwg-sctp-zero-checksum-00.html#section-3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Type = 0x8001 (suggested) | Length = 8 |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Error Detection Method Identifier (EDMID) |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
constexpr int ZeroChecksumAcceptableChunkParameter::kType;
absl::optional<ZeroChecksumAcceptableChunkParameter>
ZeroChecksumAcceptableChunkParameter::Parse(
rtc::ArrayView<const uint8_t> data) {
absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
if (!reader.has_value()) {
return absl::nullopt;
}
ZeroChecksumAlternateErrorDetectionMethod method(reader->Load32<4>());
if (method == ZeroChecksumAlternateErrorDetectionMethod::None()) {
return absl::nullopt;
}
return ZeroChecksumAcceptableChunkParameter(method);
}
void ZeroChecksumAcceptableChunkParameter::SerializeTo(
std::vector<uint8_t>& out) const {
BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out);
writer.Store32<4>(*error_detection_method_);
}
std::string ZeroChecksumAcceptableChunkParameter::ToString() const {
rtc::StringBuilder sb;
sb << "Zero Checksum Acceptable (" << *error_detection_method_ << ")";
return sb.Release();
}
} // namespace dcsctp

View file

@ -0,0 +1,60 @@
/*
* Copyright (c) 2023 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#ifndef NET_DCSCTP_PACKET_PARAMETER_ZERO_CHECKSUM_ACCEPTABLE_CHUNK_PARAMETER_H_
#define NET_DCSCTP_PACKET_PARAMETER_ZERO_CHECKSUM_ACCEPTABLE_CHUNK_PARAMETER_H_
#include <stddef.h>
#include <stdint.h>
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "net/dcsctp/packet/parameter/parameter.h"
#include "net/dcsctp/packet/tlv_trait.h"
#include "net/dcsctp/public/types.h"
namespace dcsctp {
// https://datatracker.ietf.org/doc/draft-ietf-tsvwg-sctp-zero-checksum/
struct ZeroChecksumAcceptableChunkParameterConfig : ParameterConfig {
static constexpr int kType = 0x8001;
static constexpr size_t kHeaderSize = 8;
static constexpr size_t kVariableLengthAlignment = 0;
};
class ZeroChecksumAcceptableChunkParameter
: public Parameter,
public TLVTrait<ZeroChecksumAcceptableChunkParameterConfig> {
public:
static constexpr int kType =
ZeroChecksumAcceptableChunkParameterConfig::kType;
explicit ZeroChecksumAcceptableChunkParameter(
ZeroChecksumAlternateErrorDetectionMethod error_detection_method)
: error_detection_method_(error_detection_method) {}
static absl::optional<ZeroChecksumAcceptableChunkParameter> Parse(
rtc::ArrayView<const uint8_t> data);
void SerializeTo(std::vector<uint8_t>& out) const override;
std::string ToString() const override;
ZeroChecksumAlternateErrorDetectionMethod error_detection_method() const {
return error_detection_method_;
}
private:
ZeroChecksumAlternateErrorDetectionMethod error_detection_method_;
};
} // namespace dcsctp
#endif // NET_DCSCTP_PACKET_PARAMETER_ZERO_CHECKSUM_ACCEPTABLE_CHUNK_PARAMETER_H_