Skip to content

Commit 47794f2

Browse files
committed
1 parent 0130f8c commit 47794f2

31 files changed

+1285
-577
lines changed

subprojects/gst-plugins-bad/ext/sctp/dcsctp/absl/types/variant.h

Lines changed: 861 additions & 0 deletions
Large diffs are not rendered by default.

subprojects/gst-plugins-bad/ext/sctp/dcsctp/net/dcsctp/common/str_join.h

Lines changed: 0 additions & 56 deletions
This file was deleted.

subprojects/gst-plugins-bad/ext/sctp/dcsctp/net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter.cc

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,44 @@
1515

1616
#include "absl/types/optional.h"
1717
#include "api/array_view.h"
18+
#include "rtc_base/strings/string_builder.h"
1819

1920
namespace dcsctp {
2021

2122
// https://www.ietf.org/archive/id/draft-tuexen-tsvwg-sctp-zero-checksum-00.html#section-3
2223

23-
// 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
24-
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
25-
// | Type = 0x8001 | Length = 4 |
26-
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
24+
// 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
25+
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
26+
// | Type = 0x8001 (suggested) | Length = 8 |
27+
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28+
// | Error Detection Method Identifier (EDMID) |
29+
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
2730
constexpr int ZeroChecksumAcceptableChunkParameter::kType;
2831

2932
absl::optional<ZeroChecksumAcceptableChunkParameter>
3033
ZeroChecksumAcceptableChunkParameter::Parse(
3134
rtc::ArrayView<const uint8_t> data) {
32-
if (!ParseTLV(data).has_value()) {
35+
absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data);
36+
if (!reader.has_value()) {
3337
return absl::nullopt;
3438
}
35-
return ZeroChecksumAcceptableChunkParameter();
39+
40+
ZeroChecksumAlternateErrorDetectionMethod method(reader->Load32<4>());
41+
if (method == ZeroChecksumAlternateErrorDetectionMethod::None()) {
42+
return absl::nullopt;
43+
}
44+
return ZeroChecksumAcceptableChunkParameter(method);
3645
}
3746

3847
void ZeroChecksumAcceptableChunkParameter::SerializeTo(
3948
std::vector<uint8_t>& out) const {
40-
AllocateTLV(out);
49+
BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out);
50+
writer.Store32<4>(*error_detection_method_);
4151
}
4252

4353
std::string ZeroChecksumAcceptableChunkParameter::ToString() const {
44-
return "Zero Checksum Acceptable";
54+
rtc::StringBuilder sb;
55+
sb << "Zero Checksum Acceptable (" << *error_detection_method_ << ")";
56+
return sb.Release();
4557
}
4658
} // namespace dcsctp

subprojects/gst-plugins-bad/ext/sctp/dcsctp/net/dcsctp/packet/parameter/zero_checksum_acceptable_chunk_parameter.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
#include "api/array_view.h"
2020
#include "net/dcsctp/packet/parameter/parameter.h"
2121
#include "net/dcsctp/packet/tlv_trait.h"
22+
#include "net/dcsctp/public/types.h"
2223

2324
namespace dcsctp {
2425

25-
// https://datatracker.ietf.org/doc/draft-tuexen-tsvwg-sctp-zero-checksum/
26+
// https://datatracker.ietf.org/doc/draft-ietf-tsvwg-sctp-zero-checksum/
2627
struct ZeroChecksumAcceptableChunkParameterConfig : ParameterConfig {
2728
static constexpr int kType = 0x8001;
28-
static constexpr size_t kHeaderSize = 4;
29+
static constexpr size_t kHeaderSize = 8;
2930
static constexpr size_t kVariableLengthAlignment = 0;
3031
};
3132

@@ -36,13 +37,22 @@ class ZeroChecksumAcceptableChunkParameter
3637
static constexpr int kType =
3738
ZeroChecksumAcceptableChunkParameterConfig::kType;
3839

39-
ZeroChecksumAcceptableChunkParameter() {}
40+
explicit ZeroChecksumAcceptableChunkParameter(
41+
ZeroChecksumAlternateErrorDetectionMethod error_detection_method)
42+
: error_detection_method_(error_detection_method) {}
4043

4144
static absl::optional<ZeroChecksumAcceptableChunkParameter> Parse(
4245
rtc::ArrayView<const uint8_t> data);
4346

4447
void SerializeTo(std::vector<uint8_t>& out) const override;
4548
std::string ToString() const override;
49+
50+
ZeroChecksumAlternateErrorDetectionMethod error_detection_method() const {
51+
return error_detection_method_;
52+
}
53+
54+
private:
55+
ZeroChecksumAlternateErrorDetectionMethod error_detection_method_;
4656
};
4757

4858
} // namespace dcsctp

subprojects/gst-plugins-bad/ext/sctp/dcsctp/net/dcsctp/packet/sctp_packet.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ absl::optional<SctpPacket> SctpPacket::Parse(rtc::ArrayView<const uint8_t> data,
126126
std::vector<uint8_t>(data.begin(), data.end());
127127

128128
if (options.disable_checksum_verification ||
129-
(options.enable_zero_checksum && common_header.checksum == 0u)) {
129+
(options.zero_checksum_alternate_error_detection_method !=
130+
ZeroChecksumAlternateErrorDetectionMethod::None() &&
131+
common_header.checksum == 0u)) {
130132
// https://www.ietf.org/archive/id/draft-tuexen-tsvwg-sctp-zero-checksum-01.html#section-4.3:
131133
// If an end point has sent the Zero Checksum Acceptable Chunk Parameter in
132134
// an INIT or INIT ACK chunk, it MUST accept SCTP packets using an incorrect

subprojects/gst-plugins-bad/ext/sctp/dcsctp/net/dcsctp/public/dcsctp_options.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,14 @@ struct DcSctpOptions {
8585
// buffer is fully utilized.
8686
size_t max_receiver_window_buffer_size = 5 * 1024 * 1024;
8787

88-
// Maximum send buffer size. It will not be possible to queue more data than
89-
// this before sending it.
88+
// Send queue total size limit. It will not be possible to queue more data if
89+
// the queue size is larger than this number.
9090
size_t max_send_buffer_size = 2'000'000;
9191

92+
// Per stream send queue size limit. Similar to `max_send_buffer_size`, but
93+
// limiting the size of individual streams.
94+
size_t per_stream_send_queue_limit = 2'000'000;
95+
9296
// A threshold that, when the amount of data in the send buffer goes below
9397
// this value, will trigger `DcSctpCallbacks::OnTotalBufferedAmountLow`.
9498
size_t total_buffered_amount_low_threshold = 1'800'000;
@@ -144,8 +148,11 @@ struct DcSctpOptions {
144148
// processing time of received packets and the clock granularity when setting
145149
// the delayed ack timer on the peer.
146150
//
147-
// This is described for TCP in
151+
// This is defined as "G" in the algorithm for TCP in
148152
// https://datatracker.ietf.org/doc/html/rfc6298#section-4.
153+
//
154+
// Note that this value will be further adjusted by scaling factors, so if you
155+
// intend to change this, do it incrementally and measure the results.
149156
DurationMs min_rtt_variance = DurationMs(220);
150157

151158
// The initial congestion window size, in number of MTUs.
@@ -196,14 +203,13 @@ struct DcSctpOptions {
196203
// Disables SCTP packet crc32 verification. For fuzzers only!
197204
bool disable_checksum_verification = false;
198205

199-
// Controls the acceptance of zero checksum, as defined in
200-
// https://datatracker.ietf.org/doc/draft-tuexen-tsvwg-sctp-zero-checksum/
201-
// This should only be enabled if the packet integrity can be ensured by lower
202-
// layers, which DTLS will do in WebRTC, as defined by RFC8261.
203-
//
204-
// This will also enable sending packets without a checksum value (set to 0)
205-
// once both peers have negotiated this feature.
206-
bool enable_zero_checksum = false;
206+
// Controls the "zero checksum option" feature, as defined in
207+
// https://www.ietf.org/archive/id/draft-ietf-tsvwg-sctp-zero-checksum-06.html.
208+
// To have this feature enabled, both peers must be configured to use the
209+
// same (defined, not "none") alternate error detection method.
210+
ZeroChecksumAlternateErrorDetectionMethod
211+
zero_checksum_alternate_error_detection_method =
212+
ZeroChecksumAlternateErrorDetectionMethod::None();
207213
};
208214
} // namespace dcsctp
209215

subprojects/gst-plugins-bad/ext/sctp/dcsctp/net/dcsctp/public/dcsctp_socket.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <cstdint>
1414
#include <memory>
1515
#include <utility>
16+
#include <vector>
1617

1718
#include "absl/strings/string_view.h"
1819
#include "absl/types/optional.h"
@@ -577,6 +578,16 @@ class DcSctpSocketInterface {
577578
virtual SendStatus Send(DcSctpMessage message,
578579
const SendOptions& send_options) = 0;
579580

581+
// Sends the messages `messages` using the provided send options.
582+
// Sending a message is an asynchronous operation, and the `OnError` callback
583+
// may be invoked to indicate any errors in sending the message.
584+
//
585+
// This has identical semantics to Send, except that it may coalesce many
586+
// messages into a single SCTP packet if they would fit.
587+
virtual std::vector<SendStatus> SendMany(
588+
rtc::ArrayView<DcSctpMessage> messages,
589+
const SendOptions& send_options) = 0;
590+
580591
// Resetting streams is an asynchronous operation and the results will
581592
// be notified using `DcSctpSocketCallbacks::OnStreamsResetDone()` on success
582593
// and `DcSctpSocketCallbacks::OnStreamsResetFailed()` on failure. Note that

subprojects/gst-plugins-bad/ext/sctp/dcsctp/net/dcsctp/public/types.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,27 @@ class LifecycleId : public webrtc::StrongAlias<class LifecycleIdTag, uint64_t> {
151151

152152
static constexpr LifecycleId NotSet() { return LifecycleId(0); }
153153
};
154+
155+
// To enable zero checksum feature, both peers must agree on which alternate
156+
// error detection method that is used. See
157+
// https://www.ietf.org/archive/id/draft-ietf-tsvwg-sctp-zero-checksum-06.html.
158+
class ZeroChecksumAlternateErrorDetectionMethod
159+
: public webrtc::StrongAlias<
160+
class ZeroChecksumAlternateErrorDetectionMethodTag,
161+
uint32_t> {
162+
public:
163+
constexpr explicit ZeroChecksumAlternateErrorDetectionMethod(
164+
const UnderlyingType& v)
165+
: webrtc::StrongAlias<class ZeroChecksumAlternateErrorDetectionMethodTag,
166+
uint32_t>(v) {}
167+
168+
static constexpr ZeroChecksumAlternateErrorDetectionMethod None() {
169+
return ZeroChecksumAlternateErrorDetectionMethod(0);
170+
}
171+
static constexpr ZeroChecksumAlternateErrorDetectionMethod LowerLayerDtls() {
172+
return ZeroChecksumAlternateErrorDetectionMethod(1);
173+
}
174+
};
154175
} // namespace dcsctp
155176

156177
#endif // NET_DCSCTP_PUBLIC_TYPES_H_

subprojects/gst-plugins-bad/ext/sctp/dcsctp/net/dcsctp/rx/reassembly_queue.cc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "net/dcsctp/packet/data.h"
2828
#include "net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h"
2929
#include "net/dcsctp/packet/parameter/reconfiguration_response_parameter.h"
30+
#include "net/dcsctp/public/dcsctp_handover_state.h"
3031
#include "net/dcsctp/public/dcsctp_message.h"
3132
#include "net/dcsctp/public/types.h"
3233
#include "net/dcsctp/rx/interleaved_reassembly_streams.h"
@@ -51,13 +52,11 @@ std::unique_ptr<ReassemblyStreams> CreateStreams(
5152
} // namespace
5253

5354
ReassemblyQueue::ReassemblyQueue(absl::string_view log_prefix,
54-
TSN peer_initial_tsn,
5555
size_t max_size_bytes,
5656
bool use_message_interleaving)
5757
: log_prefix_(log_prefix),
5858
max_size_bytes_(max_size_bytes),
5959
watermark_bytes_(max_size_bytes * kHighWatermarkLimit),
60-
last_completed_reset_req_seq_nbr_(ReconfigRequestSN(0)),
6160
streams_(CreateStreams(
6261
log_prefix_,
6362
[this](rtc::ArrayView<const UnwrappedTSN> tsns,
@@ -222,17 +221,10 @@ HandoverReadinessStatus ReassemblyQueue::GetHandoverReadiness() const {
222221
}
223222

224223
void ReassemblyQueue::AddHandoverState(DcSctpSocketHandoverState& state) {
225-
state.rx.last_completed_deferred_reset_req_sn =
226-
last_completed_reset_req_seq_nbr_.value();
227224
streams_->AddHandoverState(state);
228225
}
229226

230227
void ReassemblyQueue::RestoreFromState(const DcSctpSocketHandoverState& state) {
231-
// Validate that the component is in pristine state.
232-
RTC_DCHECK(last_completed_reset_req_seq_nbr_ == ReconfigRequestSN(0));
233-
234-
last_completed_reset_req_seq_nbr_ =
235-
ReconfigRequestSN(state.rx.last_completed_deferred_reset_req_sn);
236228
streams_->RestoreFromState(state);
237229
}
238230
} // namespace dcsctp

subprojects/gst-plugins-bad/ext/sctp/dcsctp/net/dcsctp/rx/reassembly_queue.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "net/dcsctp/packet/data.h"
2929
#include "net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h"
3030
#include "net/dcsctp/packet/parameter/reconfiguration_response_parameter.h"
31-
#include "net/dcsctp/public/dcsctp_handover_state.h"
3231
#include "net/dcsctp/public/dcsctp_message.h"
3332
#include "net/dcsctp/rx/reassembly_streams.h"
3433
#include "rtc_base/containers/flat_set.h"
@@ -72,7 +71,6 @@ class ReassemblyQueue {
7271
static constexpr float kHighWatermarkLimit = 0.9;
7372

7473
ReassemblyQueue(absl::string_view log_prefix,
75-
TSN peer_initial_tsn,
7674
size_t max_size_bytes,
7775
bool use_message_interleaving = false);
7876

@@ -155,10 +153,6 @@ class ReassemblyQueue {
155153
// If present, "deferred reset processing" mode is active.
156154
absl::optional<DeferredResetStreams> deferred_reset_streams_;
157155

158-
// Contains the last request sequence number of the
159-
// OutgoingSSNResetRequestParameter that was performed.
160-
ReconfigRequestSN last_completed_reset_req_seq_nbr_;
161-
162156
// The number of "payload bytes" that are in this queue, in total.
163157
size_t queued_bytes_ = 0;
164158

subprojects/gst-plugins-bad/ext/sctp/dcsctp/net/dcsctp/rx/reassembly_streams.cc

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)