Skip to content

Commit 779e278

Browse files
authored
SCTP part 8 (#1770)
1 parent e69f1b8 commit 779e278

31 files changed

Lines changed: 822 additions & 269 deletions

worker/include/RTC/SCTP/TODO_SCTP.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
- In `Association::FillBuffer()` we should not pass `this->sctpOptions.maxOutboundStreams/maxInboundStreams` but the current values (they may have been modified via "reconfig").
1818

19-
- Probably remove those `MS_DEBUG_TAG(sctp, "xxxx timer has expired")` and make it be `MS_DEBUG_DEV()` instead.
20-
2119
- Test Chrome with I-DATA (message interleaving):
2220

2321
```
@@ -27,8 +25,3 @@
2725
```
2826

2927
- Look for "TODO: SCTP" and `MS_SCTP_STACK` everywhere.
30-
31-
## Related to dcsctp
32-
33-
- Investigate `DcSctpSocket::HandleTimeout()` which is only called from `media/sctp/dcsctp_transport.cc`.
34-
- Update: This is the entry point when a timer expires. It's the same as our `OnTimer()`.

worker/include/RTC/SCTP/association/Association.hpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -374,64 +374,64 @@ namespace RTC
374374

375375
bool ValidateReceivedPacket(const Packet* receivedPacket);
376376

377-
bool ProcessReceivedChunk(const Packet* receivedPacket, const Chunk* receivedChunk);
377+
bool HandleReceivedChunk(const Packet* receivedPacket, const Chunk* receivedChunk);
378378

379-
void ProcessReceivedInitChunk(const Packet* receivedPacket, const InitChunk* receivedInitChunk);
379+
void HandleReceivedInitChunk(const Packet* receivedPacket, const InitChunk* receivedInitChunk);
380380

381-
void ProcessReceivedInitAckChunk(
381+
void HandleReceivedInitAckChunk(
382382
const Packet* receivedPacket, const InitAckChunk* receivedInitAckChunk);
383383

384-
void ProcessReceivedCookieEchoChunk(
384+
void HandleReceivedCookieEchoChunk(
385385
const Packet* receivedPacket, const CookieEchoChunk* receivedCookieEchoChunk);
386386

387-
bool ProcessReceivedCookieEchoChunkWithTcb(const Packet* receivedPacket, const StateCookie* cookie);
387+
bool HandleReceivedCookieEchoChunkWithTcb(const Packet* receivedPacket, const StateCookie* cookie);
388388

389-
void ProcessReceivedCookieAckChunk(
389+
void HandleReceivedCookieAckChunk(
390390
const Packet* receivedPacket, const CookieAckChunk* receivedCookieAckChunk);
391391

392-
void ProcessReceivedShutdownChunk(
392+
void HandleReceivedShutdownChunk(
393393
const Packet* receivedPacket, const ShutdownChunk* receivedShutdownChunk);
394394

395-
void ProcessReceivedShutdownAckChunk(
395+
void HandleReceivedShutdownAckChunk(
396396
const Packet* receivedPacket, const ShutdownAckChunk* receivedShutdownAckChunk);
397397

398-
void ProcessReceivedShutdownCompleteChunk(
398+
void HandleReceivedShutdownCompleteChunk(
399399
const Packet* receivedPacket, const ShutdownCompleteChunk* receivedShutdownCompleteChunk);
400400

401-
void ProcessReceivedOperationErrorChunk(
401+
void HandleReceivedOperationErrorChunk(
402402
const Packet* receivedPacket, const OperationErrorChunk* receivedOperationErrorChunk);
403403

404-
void ProcessReceivedAbortAssociationChunk(
404+
void HandleReceivedAbortAssociationChunk(
405405
const Packet* receivedPacket, const AbortAssociationChunk* receivedAbortAssociationChunk);
406406

407-
void ProcessReceivedHeartbeatRequestChunk(
407+
void HandleReceivedHeartbeatRequestChunk(
408408
const Packet* receivedPacket, const HeartbeatRequestChunk* receivedHeartbeatRequestChunk);
409409

410-
void ProcessReceivedHeartbeatAckChunk(
410+
void HandleReceivedHeartbeatAckChunk(
411411
const Packet* receivedPacket, const HeartbeatAckChunk* receivedHeartbeatAckChunk);
412412

413-
void ProcessReceivedReConfigChunk(
413+
void HandleReceivedReConfigChunk(
414414
const Packet* receivedPacket, const ReConfigChunk* receivedReConfigChunk);
415415

416-
void ProcessReceivedForwardTsnChunk(
416+
void HandleReceivedForwardTsnChunk(
417417
const Packet* receivedPacket, const ForwardTsnChunk* receivedForwardTsnChunk);
418418

419-
void ProcessReceivedIForwardTsnChunk(
419+
void HandleReceivedIForwardTsnChunk(
420420
const Packet* receivedPacket, const IForwardTsnChunk* receivedIForwardTsnChunk);
421421

422-
void ProcessReceivedAnyForwardTsnChunk(
422+
void HandleReceivedAnyForwardTsnChunk(
423423
const Packet* receivedPacket, const AnyForwardTsnChunk* receivedAnyForwardTsnChunk);
424424

425-
void ProcessReceivedDataChunk(const Packet* receivedPacket, const DataChunk* receivedDataChunk);
425+
void HandleReceivedDataChunk(const Packet* receivedPacket, const DataChunk* receivedDataChunk);
426426

427-
void ProcessReceivedIDataChunk(const Packet* receivedPacket, const IDataChunk* receivedIDataChunk);
427+
void HandleReceivedIDataChunk(const Packet* receivedPacket, const IDataChunk* receivedIDataChunk);
428428

429-
void ProcessReceivedAnyDataChunk(
429+
void HandleReceivedAnyDataChunk(
430430
const Packet* receivedPacket, const AnyDataChunk* receivedAnyDataChunk);
431431

432-
void ProcessReceivedSackChunk(const Packet* receivedPacket, const SackChunk* receivedSackChunk);
432+
void HandleReceivedSackChunk(const Packet* receivedPacket, const SackChunk* receivedSackChunk);
433433

434-
bool ProcessReceivedUnknownChunk(
434+
bool HandleReceivedUnknownChunk(
435435
const Packet* receivedPacket, const UnknownChunk* receivedUnknownChunk);
436436

437437
void OnT1InitTimer(uint64_t& baseTimeoutMs, bool& stop);

worker/include/RTC/SCTP/association/HeartbeatHandler.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ namespace RTC
4242
/**
4343
* Called on received HEARTBEAT_REQUEST Chunk.
4444
*/
45-
void ProcessReceivedHeartbeatRequestChunk(
45+
void HandleReceivedHeartbeatRequestChunk(
4646
const HeartbeatRequestChunk* receivedHeartbeatRequestChunk);
4747

4848
/**
4949
* Called on received HEARTBEAT_ACK Chunk.
5050
*/
51-
void ProcessReceivedHeartbeatAckChunk(const HeartbeatAckChunk* receivedHeartbeatAckChunk);
51+
void HandleReceivedHeartbeatAckChunk(const HeartbeatAckChunk* receivedHeartbeatAckChunk);
5252

5353
private:
5454
void OnIntervalTimer(uint64_t& baseTimeoutMs, bool& stop);

worker/include/RTC/SCTP/association/StreamResetHandler.hpp

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
#include "common.hpp"
55
#include "RTC/SCTP/association/TCBContext.hpp"
66
#include "RTC/SCTP/common/UnwrappedSequenceNumber.hpp"
7+
#include "RTC/SCTP/packet/Packet.hpp"
78
#include "RTC/SCTP/packet/chunks/ReConfigChunk.hpp"
9+
#include "RTC/SCTP/packet/parameters/IncomingSsnResetRequestParameter.hpp"
10+
#include "RTC/SCTP/packet/parameters/OutgoingSsnResetRequestParameter.hpp"
811
#include "RTC/SCTP/packet/parameters/ReconfigurationResponseParameter.hpp"
912
#include "RTC/SCTP/public/AssociationListener.hpp"
1013
#include "handles/BackoffTimerHandle.hpp"
@@ -53,7 +56,7 @@ namespace RTC
5356
{
5457
VALID,
5558
RETRANSMISSION,
56-
BADSEQUENCE_NUMBER,
59+
BAD_SEQUENCE_NUMBER,
5760
};
5861

5962
/**
@@ -156,6 +159,9 @@ namespace RTC
156159
bool isDeferred{ false };
157160
};
158161

162+
private:
163+
using UnwrappedReConfigRequestSn = UnwrappedSequenceNumber<uint32_t>;
164+
159165
public:
160166
StreamResetHandler(
161167
AssociationListener& associationListener, TCBContext* tcbContext
@@ -177,23 +183,66 @@ namespace RTC
177183
*/
178184
void ResetStreams(std::span<const uint16_t> outgoingStreamIds);
179185

186+
/**
187+
* Called when handling and incoming RE-CONFIG chunk. Processes a stream
188+
* reconfiguration chunk and may send a RE-CONFIG back to the peer with
189+
* either 1 or 2 responses.
190+
*/
191+
void HandleReceivedReConfigChunk(const ReConfigChunk* receivedReConfigChunk);
192+
193+
private:
194+
/**
195+
* Called to validate a received RE-CONFIG chunk.
196+
*/
197+
bool ValidateReceivedReConfigChunk(const ReConfigChunk* receivedReConfigChunk);
198+
180199
/**
181200
* Creates a Reset Streams request that must be sent if returned. Will
182201
* start the reconfig timer. Will return `nullptr` if there is no need
183202
* to create a request (no streams to reset) or if there already is an
184203
* ongoing stream reset request that hasn't completed yet.
185204
*/
186-
// TODO: SCTP: Do we really want to return a Chunk? Maybe we should pass
187-
// a Packet to use BuilChunkInPlace().
188-
ReConfigChunk* MakeStreamResetRequest();
205+
ReConfigChunk* CreateStreamResetRequest();
189206

190207
/**
191-
* Called when handling and incoming RE-CONFIG chunk.
208+
* Creates the actual RE-CONFIG chunk. A request (which set
209+
* `currentRequest`) must have been created prior.
192210
*/
193-
void ProcessReceivedReConfigChunk(const ReConfigChunk* receivedReConfigChunk);
211+
ReConfigChunk* CreateReconfigChunk();
194212

195-
private:
196-
void OnReconfigTimer(uint64_t& baseTimeoutMs, bool& stop);
213+
/**
214+
* Called to validate the `reqSeqNbr`, that it's the next in sequence.
215+
*/
216+
ReqSeqNbrValidationResult ValidateReqSeqNbr(UnwrappedReConfigRequestSn reqSeqNbr);
217+
218+
/**
219+
* Called when this Association receives an outgoing stream reset request.
220+
* It might either be performed straight away, or have to be deferred, and
221+
* the result of that will be put in `responses`.
222+
*/
223+
void HandleReceivedOutgoingSsnResetRequestParameter(
224+
const OutgoingSsnResetRequestParameter* receivedOutgoingSsnResetRequestParameter,
225+
ReConfigChunk* reConfigChunk);
226+
227+
/**
228+
* Called when this Association receives an incoming stream reset request.
229+
* This isn't really supported, but a successful response is put in
230+
* `responses`.
231+
*/
232+
void HandleReceivedIncomingSsnResetRequestParameter(
233+
const IncomingSsnResetRequestParameter* receivedIncomingSsnResetRequestParameter,
234+
ReConfigChunk* reConfigChunk);
235+
236+
/**
237+
* Called when receiving a response to an outgoing stream reset request.
238+
* It will either commit the stream resetting, if the operation was
239+
* successful, or will schedule a retry if it was deferred. And if it
240+
* failed, the operation will be rolled back.
241+
*/
242+
void HandleReceivedReconfigurationResponseParameter(
243+
const ReconfigurationResponseParameter* receivedReconfigurationResponseParameter);
244+
245+
void OnReConfigTimer(uint64_t& baseTimeoutMs, bool& stop);
197246

198247
/* Pure virtual methods inherited from BackoffTimerHandle::Listener. */
199248
public:
@@ -206,14 +255,14 @@ namespace RTC
206255
// DataTracker* dataTracker{ nullptr };,
207256
// ReassemblyQueue* reassemblyQueue{ nullptr };,
208257
// RetransmissionQueue* retransmissionQueue{ nullptr };
209-
UnwrappedSequenceNumber<uint32_t>::Unwrapper incomingReconfigRequestSnUnwrapper;
210-
const std::unique_ptr<BackoffTimerHandle> reconfigTimer;
258+
UnwrappedReConfigRequestSn::Unwrapper incomingReConfigRequestSnUnwrapper;
259+
const std::unique_ptr<BackoffTimerHandle> reConfigTimer;
211260
// The next sequence number for outgoing stream requests.
212261
uint32_t nextOutgoingReqSeqNbr{ 0 };
213262
// The current stream request operation.
214263
std::optional<CurrentRequest> currentRequest;
215264
// For incoming requests. Last processed request sequence number.
216-
UnwrappedSequenceNumber<uint32_t> lastProcessedReqSeqNbr;
265+
UnwrappedReConfigRequestSn lastProcessedReqSeqNbr;
217266
// The result from last processed incoming request.
218267
ReconfigurationResponseParameter::Result lastProcessedReqResult;
219268
};

worker/include/RTC/SCTP/packet/UserData.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ namespace RTC
105105
*/
106106
std::vector<uint8_t> ReleasePayload() &&
107107
{
108+
// NOLINTNEXTLINE(clang-analyzer-cplusplus.Move)
108109
return std::move(this->payload);
109110
}
110111

worker/include/RTC/SCTP/packet/parameters/IncomingSsnResetRequestParameter.hpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "common.hpp"
55
#include "Utils.hpp"
66
#include "RTC/SCTP/packet/Parameter.hpp"
7+
#include <vector>
78

89
namespace RTC
910
{
@@ -88,17 +89,9 @@ namespace RTC
8889

8990
void SetReconfigurationRequestSequenceNumber(uint32_t value);
9091

91-
uint16_t GetNumberOfStreams() const
92-
{
93-
return GetVariableLengthValueLength() / 2;
94-
}
95-
96-
uint16_t GetStreamAt(uint16_t idx) const
97-
{
98-
return Utils::Byte::Get2Bytes(GetVariableLengthValuePointer(), (idx * 2));
99-
}
92+
std::vector<uint16_t> GetStreamIds() const;
10093

101-
void AddStream(uint16_t stream);
94+
void AddStreamId(uint16_t streamId);
10295

10396
protected:
10497
IncomingSsnResetRequestParameter* SoftClone(const uint8_t* buffer) const final;
@@ -111,6 +104,17 @@ namespace RTC
111104
{
112105
return IncomingSsnResetRequestParameter::IncomingSsnResetRequestParameterHeaderLength;
113106
}
107+
108+
private:
109+
uint16_t GetNumberOfStreams() const
110+
{
111+
return GetVariableLengthValueLength() / 2;
112+
}
113+
114+
uint16_t GetStreamAt(uint16_t idx) const
115+
{
116+
return Utils::Byte::Get2Bytes(GetVariableLengthValuePointer(), (idx * 2));
117+
}
114118
};
115119
} // namespace SCTP
116120
} // namespace RTC

worker/include/RTC/SCTP/packet/parameters/OutgoingSsnResetRequestParameter.hpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "common.hpp"
55
#include "Utils.hpp"
66
#include "RTC/SCTP/packet/Parameter.hpp"
7+
#include <vector>
78

89
namespace RTC
910
{
@@ -106,17 +107,9 @@ namespace RTC
106107

107108
void SetSenderLastAssignedTsn(uint32_t value);
108109

109-
uint16_t GetNumberOfStreams() const
110-
{
111-
return GetVariableLengthValueLength() / 2;
112-
}
113-
114-
uint16_t GetStreamAt(uint16_t idx) const
115-
{
116-
return Utils::Byte::Get2Bytes(GetVariableLengthValuePointer(), (idx * 2));
117-
}
110+
std::vector<uint16_t> GetStreamIds() const;
118111

119-
void AddStream(uint16_t stream);
112+
void AddStreamId(uint16_t streamId);
120113

121114
protected:
122115
OutgoingSsnResetRequestParameter* SoftClone(const uint8_t* buffer) const final;
@@ -129,6 +122,17 @@ namespace RTC
129122
{
130123
return OutgoingSsnResetRequestParameter::OutgoingSsnResetRequestParameterHeaderLength;
131124
}
125+
126+
private:
127+
uint16_t GetNumberOfStreams() const
128+
{
129+
return GetVariableLengthValueLength() / 2;
130+
}
131+
132+
uint16_t GetStreamAt(uint16_t idx) const
133+
{
134+
return Utils::Byte::Get2Bytes(GetVariableLengthValuePointer(), (idx * 2));
135+
}
132136
};
133137
} // namespace SCTP
134138
} // namespace RTC

worker/include/RTC/SCTP/packet/parameters/ZeroChecksumAcceptableParameter.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace RTC
4242
enum class AlternateErrorDetectionMethod : uint32_t
4343
{
4444
NONE = 0x0000,
45-
SCTP_OVER_DTLS = 0x0001
45+
SCTP_OVER_DTLS = 0x0001,
4646
};
4747

4848
public:
@@ -96,7 +96,18 @@ namespace RTC
9696

9797
AlternateErrorDetectionMethod GetAlternateErrorDetectionMethod() const
9898
{
99-
return static_cast<AlternateErrorDetectionMethod>(Utils::Byte::Get4Bytes(GetBuffer(), 4));
99+
const auto method = Utils::Byte::Get4Bytes(GetBuffer(), 4);
100+
101+
if (
102+
method == static_cast<uint32_t>(AlternateErrorDetectionMethod::NONE) ||
103+
method == static_cast<uint32_t>(AlternateErrorDetectionMethod::SCTP_OVER_DTLS))
104+
{
105+
return static_cast<AlternateErrorDetectionMethod>(method);
106+
}
107+
else
108+
{
109+
return AlternateErrorDetectionMethod::NONE;
110+
}
100111
}
101112

102113
void SetAlternateErrorDetectionMethod(AlternateErrorDetectionMethod alternateErrorDetectionMethod);

worker/include/RTC/SCTP/public/Message.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ namespace RTC
7171
*/
7272
std::vector<uint8_t> ReleasePayload() &&
7373
{
74+
// NOLINTNEXTLINE(clang-analyzer-cplusplus.Move)
7475
return std::move(this->payload);
7576
}
7677

0 commit comments

Comments
 (0)