@@ -74,8 +74,13 @@ bool DataChannel::IsOpenMessage(message_ptr message) {
74
74
DataChannel::DataChannel (weak_ptr<PeerConnection> pc, string label, string protocol,
75
75
Reliability reliability)
76
76
: mPeerConnection (pc), mLabel (std::move(label)), mProtocol (std::move(protocol)),
77
- mReliability (std::make_shared<Reliability>(std::move(reliability))),
78
- mRecvQueue(RECV_QUEUE_LIMIT, message_size_func) {}
77
+ mRecvQueue (RECV_QUEUE_LIMIT, message_size_func) {
78
+
79
+ if (reliability.maxPacketLifeTime && reliability.maxRetransmits )
80
+ throw std::invalid_argument (" Both maxPacketLifeTime and maxRetransmits are set" );
81
+
82
+ mReliability = std::make_shared<Reliability>(std::move (reliability));
83
+ }
79
84
80
85
DataChannel::~DataChannel () {
81
86
PLOG_VERBOSE << " Destroying DataChannel" ;
@@ -247,22 +252,35 @@ void OutgoingDataChannel::open(shared_ptr<SctpTransport> transport) {
247
252
248
253
uint8_t channelType;
249
254
uint32_t reliabilityParameter;
250
- switch (mReliability ->type ) {
251
- case Reliability::Type::Rexmit:
255
+ if (mReliability ->maxPacketLifeTime ) {
256
+ channelType = CHANNEL_PARTIAL_RELIABLE_TIMED;
257
+ reliabilityParameter = uint32_t (mReliability ->maxPacketLifeTime ->count ());
258
+ } else if (mReliability ->maxRetransmits ) {
252
259
channelType = CHANNEL_PARTIAL_RELIABLE_REXMIT;
253
- reliabilityParameter = uint32_t (std::max (std::get<int >(mReliability ->rexmit ), 0 ));
254
- break ;
260
+ reliabilityParameter = uint32_t (*mReliability ->maxRetransmits );
261
+ }
262
+ // else {
263
+ // channelType = CHANNEL_RELIABLE;
264
+ // reliabilityParameter = 0;
265
+ // }
266
+ // Deprecated
267
+ else
268
+ switch (mReliability ->typeDeprecated ) {
269
+ case Reliability::Type::Rexmit:
270
+ channelType = CHANNEL_PARTIAL_RELIABLE_REXMIT;
271
+ reliabilityParameter = uint32_t (std::max (std::get<int >(mReliability ->rexmit ), 0 ));
272
+ break ;
255
273
256
- case Reliability::Type::Timed:
257
- channelType = CHANNEL_PARTIAL_RELIABLE_TIMED;
258
- reliabilityParameter = uint32_t (std::get<milliseconds>(mReliability ->rexmit ).count ());
259
- break ;
274
+ case Reliability::Type::Timed:
275
+ channelType = CHANNEL_PARTIAL_RELIABLE_TIMED;
276
+ reliabilityParameter = uint32_t (std::get<milliseconds>(mReliability ->rexmit ).count ());
277
+ break ;
260
278
261
- default :
262
- channelType = CHANNEL_RELIABLE;
263
- reliabilityParameter = 0 ;
264
- break ;
265
- }
279
+ default :
280
+ channelType = CHANNEL_RELIABLE;
281
+ reliabilityParameter = 0 ;
282
+ break ;
283
+ }
266
284
267
285
if (mReliability ->unordered )
268
286
channelType |= 0x80 ;
@@ -329,17 +347,31 @@ void IncomingDataChannel::processOpenMessage(message_ptr message) {
329
347
mProtocol .assign (end + open .labelLength , open .protocolLength );
330
348
331
349
mReliability ->unordered = (open .channelType & 0x80 ) != 0 ;
350
+ mReliability ->maxPacketLifeTime .reset ();
351
+ mReliability ->maxRetransmits .reset ();
352
+ switch (open .channelType & 0x7F ) {
353
+ case CHANNEL_PARTIAL_RELIABLE_REXMIT:
354
+ mReliability ->maxRetransmits .emplace (open .reliabilityParameter );
355
+ break ;
356
+ case CHANNEL_PARTIAL_RELIABLE_TIMED:
357
+ mReliability ->maxPacketLifeTime .emplace (milliseconds (open .reliabilityParameter ));
358
+ break ;
359
+ default :
360
+ break ;
361
+ }
362
+
363
+ // Deprecated
332
364
switch (open .channelType & 0x7F ) {
333
365
case CHANNEL_PARTIAL_RELIABLE_REXMIT:
334
- mReliability ->type = Reliability::Type::Rexmit;
366
+ mReliability ->typeDeprecated = Reliability::Type::Rexmit;
335
367
mReliability ->rexmit = int (open .reliabilityParameter );
336
368
break ;
337
369
case CHANNEL_PARTIAL_RELIABLE_TIMED:
338
- mReliability ->type = Reliability::Type::Timed;
370
+ mReliability ->typeDeprecated = Reliability::Type::Timed;
339
371
mReliability ->rexmit = milliseconds (open .reliabilityParameter );
340
372
break ;
341
373
default :
342
- mReliability ->type = Reliability::Type::Reliable;
374
+ mReliability ->typeDeprecated = Reliability::Type::Reliable;
343
375
mReliability ->rexmit = int (0 );
344
376
}
345
377
0 commit comments