Skip to content

Commit 937d4ae

Browse files
authored
Refactor switch cases and clean up string interpolation for SCTP (#1667)
Refactor switch-case statements to use discard variable (_) for chunkType pattern matching in SctpAssociation.cs, improving clarity and modernizing syntax. Consolidate string interpolation in SctpTlvChunkParameter.cs for better readability.
1 parent f8b1518 commit 937d4ae

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

src/SIPSorcery/net/SCTP/Chunks/SctpTlvChunkParameter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ public ushort ParseFirstWord(byte[] buffer, int posn)
211211
// The buffer was not big enough to supply the specified chunk parameter.
212212
int bytesRequired = paramLen;
213213
int bytesAvailable = buffer.Length - posn;
214-
throw new ApplicationException($"The SCTP chunk parameter buffer was too short. " +
215-
$"Required {bytesRequired} bytes but only {bytesAvailable} available.");
214+
throw new ApplicationException($"The SCTP chunk parameter buffer was too short. Required {bytesRequired} bytes but only {bytesAvailable} available.");
216215
}
217216

218217
return paramLen;

src/SIPSorcery/net/SCTP/SctpAssociation.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,13 @@ internal void OnPacketReceived(SctpPacket packet)
400400
OnAbortReceived?.Invoke(abortReason);
401401
break;
402402

403-
case var ct when ct == SctpChunkType.COOKIE_ACK && State != SctpAssociationState.CookieEchoed:
403+
case var _ when chunkType == SctpChunkType.COOKIE_ACK && State != SctpAssociationState.CookieEchoed:
404404
// https://tools.ietf.org/html/rfc4960#section-5.2.5
405405
// At any state other than COOKIE-ECHOED, an endpoint should silently
406406
// discard a received COOKIE ACK chunk.
407407
break;
408408

409-
case var ct when ct == SctpChunkType.COOKIE_ACK && State == SctpAssociationState.CookieEchoed:
409+
case var _ when chunkType == SctpChunkType.COOKIE_ACK && State == SctpAssociationState.CookieEchoed:
410410
SetState(SctpAssociationState.Established);
411411
CancelTimers();
412412
_dataSender.StartSending();
@@ -468,13 +468,13 @@ internal void OnPacketReceived(SctpPacket packet)
468468
SendChunk(chunk);
469469
break;
470470

471-
case var ct when ct == SctpChunkType.INIT_ACK && State != SctpAssociationState.CookieWait:
471+
case var _ when chunkType == SctpChunkType.INIT_ACK && State != SctpAssociationState.CookieWait:
472472
// https://tools.ietf.org/html/rfc4960#section-5.2.3
473473
// If an INIT ACK is received by an endpoint in any state other than the
474474
// COOKIE - WAIT state, the endpoint should discard the INIT ACK chunk.
475475
break;
476476

477-
case var ct when ct == SctpChunkType.INIT_ACK && State == SctpAssociationState.CookieWait:
477+
case var _ when chunkType == SctpChunkType.INIT_ACK && State == SctpAssociationState.CookieWait:
478478

479479
if (_t1Init != null)
480480
{
@@ -528,23 +528,23 @@ internal void OnPacketReceived(SctpPacket packet)
528528
}
529529
break;
530530

531-
case var ct when ct == SctpChunkType.INIT_ACK && State != SctpAssociationState.CookieWait:
531+
case var _ when chunkType == SctpChunkType.INIT_ACK && State != SctpAssociationState.CookieWait:
532532
logger.LogWarning("SCTP association received INIT_ACK chunk in wrong state of {State}, ignoring.", State);
533533
break;
534534

535535
case SctpChunkType.SACK:
536536
_dataSender.GotSack(chunk as SctpSackChunk);
537537
break;
538538

539-
case var ct when ct == SctpChunkType.SHUTDOWN && State == SctpAssociationState.Established:
539+
case var _ when chunkType == SctpChunkType.SHUTDOWN && State == SctpAssociationState.Established:
540540
// TODO: Check outstanding data chunks.
541541
_dataSender?.Close();
542542
var shutdownAck = new SctpChunk(SctpChunkType.SHUTDOWN_ACK);
543543
SendChunk(shutdownAck);
544544
SetState(SctpAssociationState.ShutdownAckSent);
545545
break;
546546

547-
case var ct when ct == SctpChunkType.SHUTDOWN_ACK && State == SctpAssociationState.ShutdownSent:
547+
case var _ when chunkType == SctpChunkType.SHUTDOWN_ACK && State == SctpAssociationState.ShutdownSent:
548548
SetState(SctpAssociationState.Closed);
549549
var shutCompleteChunk = new SctpChunk(SctpChunkType.SHUTDOWN_COMPLETE,
550550
(byte)(_remoteVerificationTag != 0 ? SHUTDOWN_CHUNK_TBIT_FLAG : 0x00));

0 commit comments

Comments
 (0)