Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance and bugfixes used by Borg #1192

Open
wants to merge 92 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
d0e8baf
update bouncycastle 1.9.0 -> 2.2.1
camnewnham Jun 27, 2023
715075d
clean
camnewnham Jun 28, 2023
acd814b
Merge remote-tracking branch 'bc2/bouncycastle-2' into borg/bc2
lostmsu Oct 20, 2023
2efbb12
bumped minimum protocol to DTLSv12
lostmsu Oct 20, 2023
26964c9
updated version to v7.0.0-bc2-23.10.19
lostmsu Oct 20, 2023
f70ba52
dropped .NET Core 3.1 and .NET 5.0 which are out of support
lostmsu Oct 20, 2023
a105659
handle STUN messages that end abruptly
lostmsu Oct 22, 2023
f1be4e7
improve handling of abruptly ending STUN messages
lostmsu Oct 22, 2023
ac69ecb
fixed DTLS alert handling
lostmsu Oct 22, 2023
0c6aff5
Receive to Span was not really implemented
lostmsu Oct 22, 2023
04b9faf
23.10.21.4
lostmsu Oct 22, 2023
6608c1d
handle chunks larger than destination buffer
lostmsu Oct 22, 2023
0f9f931
added data channel bandwidth test
lostmsu Oct 22, 2023
210fc71
limit the size of SctpDataSender send queue
lostmsu Oct 24, 2023
7dd5375
assume server supports client ECC
lostmsu Dec 29, 2023
1c416fb
23.12.28.2
lostmsu Dec 29, 2023
49140a8
improved bandwidth test logging
lostmsu Jan 9, 2024
a4664f5
rewrote most of the processing to use spans
lostmsu Jan 10, 2024
90e09e4
use Environment.TickCount instead of DateTime for timestamping
lostmsu Jan 10, 2024
582b3a2
minor performance improvements
lostmsu Jan 12, 2024
d4a2e88
reduce allocations across the project and use SSE for CRC32C when ava…
lostmsu Jan 12, 2024
a63097b
partially replaced SctpPacket with SctpPacketView on receive
lostmsu Jan 12, 2024
4b08420
use allocation for rare complex chunks
lostmsu Jan 12, 2024
267e82d
fixed bad format string for enum
lostmsu Jan 13, 2024
0123c67
fixed chunk value offset and validation
lostmsu Jan 13, 2024
d8bc3a1
fixed BorrowedArray.Set for preallocated array
lostmsu Jan 13, 2024
082d476
updated Small package to fix critical issue with stack-allocated lists
lostmsu Jan 13, 2024
81f31c8
fixed SctpTsnGapBlock processing
lostmsu Jan 13, 2024
ea5a2f7
avoid micro allocations on receive in DatagramReceiver
lostmsu Jan 13, 2024
a7a7694
data channel send takes ReadOnlySpan instead of array
lostmsu Jan 13, 2024
2829150
label data channel bandwidth test threads
lostmsu Jan 13, 2024
5dc6420
avoid allocation when submitting data chunks
lostmsu Jan 13, 2024
d6f8cd0
avoid allocations in bandwidth test itself
lostmsu Jan 13, 2024
23402ef
improved receive and send socket allocations by using SendToAsync ove…
lostmsu Jan 13, 2024
805f1f8
got rid of many unnecessary allocations in DoSend
lostmsu Jan 15, 2024
5b16e22
fixed unnecessary string interpolation in logging in SctpAssociation.…
lostmsu Jan 16, 2024
abe7cd3
SackChunk lists don't need heap allocation when small
lostmsu Jan 16, 2024
6007cd0
avoid buffer allocation in RTPChannel.Send
lostmsu Jan 16, 2024
ac2a069
removed logging allocations from SctpDataSender.GotSack and
lostmsu Jan 16, 2024
a6e1179
cache _outstandingBytes
lostmsu Jan 16, 2024
e292a9c
bandwidth test program improvements
lostmsu Jan 16, 2024
d089f19
label data channel bandwidth test threads
lostmsu Jan 13, 2024
05a419a
v7.0.0-PacketView-24.3.19.1
lostmsu Mar 19, 2024
8e6b5c7
bandwidth test program improvements
lostmsu Jan 16, 2024
64a8ff1
merge v6.2.1 changes from upstream
lostmsu Mar 19, 2024
dd510b2
forward merge of v6.2.1 via borg/master
lostmsu Mar 19, 2024
05a2a9d
v7.0.0-PacketView-24.3.19.2
lostmsu Mar 19, 2024
bf1be64
v7.0.0-PacketView-24.3.19.3 - include symbols into package
lostmsu Mar 19, 2024
3c6a816
avoid allocation in RTCSctpTransport background thread
lostmsu Mar 19, 2024
b41852e
bumped framework of data channel bandwidth test
lostmsu Mar 19, 2024
41b3013
added more synchronization to ICE checklists
lostmsu Mar 19, 2024
5ae95a1
don't generate package on every build pfff
lostmsu Mar 19, 2024
b050051
monkey patched SCTP congestion avoidance
lostmsu Mar 20, 2024
f4e3a3c
style
lostmsu Mar 20, 2024
e4293cc
low-pri fix for log message formatting
lostmsu Mar 20, 2024
acefa08
v7.0.0-PacketView-24.3.20.1 - slowing patch
lostmsu Mar 20, 2024
805b195
updated BouncyCastle
lostmsu Mar 20, 2024
8113b7a
v7.0.0-PacketView-24.3.20.2 - debug
lostmsu Mar 20, 2024
577b647
revert what seems to be a debugging change in DtlsSrtpTransport that …
lostmsu Mar 20, 2024
2728e4a
v7.0.0-PacketView-24.3.20.3
lostmsu Mar 20, 2024
444384d
oops accidentally turned off Retransmit mode
lostmsu Mar 21, 2024
6eb572d
Interlocked retransmit mode
lostmsu Mar 21, 2024
fd2583f
v7.0.0-PacketView-24.3.20.4
lostmsu Mar 21, 2024
84a484c
Interlocked fast recovery mode
lostmsu Mar 21, 2024
257fa9c
v7.0.0-PacketView-24.3.20.5
lostmsu Mar 21, 2024
50cc1dd
Interlocked TSN
lostmsu Mar 21, 2024
c5cf5e3
reenabled unit tests; fixed ReceptionReportSample parsing
lostmsu Mar 21, 2024
b5f91e5
Interlocked _lastAckedDataChunkSize
lostmsu Mar 21, 2024
8d3e058
fixed DtlsSrtpTransport getting stuck in Close
lostmsu Mar 21, 2024
81c761a
RTPSession atomic IsClosed and IsStarted
lostmsu Mar 21, 2024
0b98718
reenabled integration tests
lostmsu Mar 21, 2024
a040a6b
v7.0.0-PacketView-24.3.20.6
lostmsu Mar 21, 2024
43a9234
workaround for Chrome sending SSRC=1 instead of real SSRC
lostmsu Apr 25, 2024
ee04da5
v7.0.0-PacketView-24.4.20.0
lostmsu Apr 25, 2024
1b2ed30
better info on EndSendTo failures; stop spamming exception traces
lostmsu May 3, 2024
1e12271
v7.0.0-PacketView-24.5.3.0
lostmsu May 3, 2024
b24193d
handle unmatched RTCP_RR_NOSTREAM_SSRC 0xFA17FA17
lostmsu May 5, 2024
e394f0e
v7.0.0-PacketView-24.5.4.0
lostmsu May 5, 2024
e3e80d1
updated BouncyCastle.Cryptography due to a security vulnerability
lostmsu May 28, 2024
cf38d0d
createDataChannel supports explicit CancellationToken
lostmsu May 28, 2024
f3d4389
don't balk on error chunks just because we don't know how to validate…
lostmsu May 28, 2024
833ba4c
v7.0.0-PacketView-24.5.28.0
lostmsu May 28, 2024
a94a8b1
breaking: RTCDataChannel.send fails with InvalidOperationException wh…
lostmsu May 29, 2024
4157fe4
v7.0.0-PacketView-24.5.29.0
lostmsu May 29, 2024
86898a9
reduce verbosity of initial binding failures during candidate probing
lostmsu May 31, 2024
9f00eda
minor optimization
lostmsu May 31, 2024
aeb9546
v7.0.0-PacketView-24.5.30.0
lostmsu May 31, 2024
a4814c0
reduce verbosity of the "old data chunk" message
lostmsu Jun 2, 2024
68c534b
reduced logging level of user initiated SCTP abort
lostmsu Jun 3, 2024
569b81c
don't report timeout on a closed media stream
lostmsu Aug 22, 2024
9b9b887
allow modifying timeout on RTCPSession
lostmsu Aug 22, 2024
ace3ecd
merge upstream/master
lostmsu Oct 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup Condition=" '$(Framework)' != 'NET461'">
<LangVersion>8.0</LangVersion>
<PropertyGroup>
<LangVersion>12.0</LangVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ void SendRecv(RTCDataChannel channel, ref long received,
{
Interlocked.Add(ref received, stream.Read(buffer));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>12</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
26 changes: 15 additions & 11 deletions examples/WebRTCScenarios/DataChannelBandwidth/DataChannelStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DataChannelStream : Stream
{
readonly RTCDataChannel channel;
int currentMessageOffset;
byte[] message = [];
ArraySegment<byte> message = Array.Empty<byte>();
readonly CancellationTokenSource closed = new();
readonly SemaphoreSlim messageNeeded = new(0, 1);
readonly SemaphoreSlim messageAvailable = new(0, maxCount: 1);
Expand Down Expand Up @@ -75,7 +75,7 @@ or RTCPeerConnectionState.disconnected
}

int messages;
void OnMessage(RTCDataChannel _, DataChannelPayloadProtocols protocol, byte[] data)
void OnMessage(RTCDataChannel _, DataChannelPayloadProtocols protocol, ReadOnlySpan<byte> data)
{
int seq = Interlocked.Increment(ref messages);
log?.LogDebug("{Seq} received", seq);
Expand All @@ -84,7 +84,11 @@ void OnMessage(RTCDataChannel _, DataChannelPayloadProtocols protocol, byte[] da
messageNeeded.Wait();
lock (sync)
{
message = data;
if (message.Array is not null)
{
ArrayPool<byte>.Shared.Return(message.Array);
}
message = data.ToArraySegment(ArrayPool<byte>.Shared);
currentMessageOffset = 0;
}
messageAvailable.Release();
Expand Down Expand Up @@ -139,7 +143,7 @@ public override int Read(Span<byte> buffer)

lock (sync)
{
int remaining = message.Length - currentMessageOffset;
int remaining = message.Count - currentMessageOffset;
int toCopy = Math.Min(remaining, buffer.Length);
message.AsSpan(currentMessageOffset, toCopy).CopyTo(buffer);
currentMessageOffset += toCopy;
Expand Down Expand Up @@ -193,7 +197,7 @@ public override async ValueTask<int> ReadAsync(Memory<byte> buffer,

lock (sync)
{
int remaining = message.Length - currentMessageOffset;
int remaining = message.Count - currentMessageOffset;
int toCopy = Math.Min(remaining, buffer.Length);
message.AsSpan(currentMessageOffset, toCopy).CopyTo(buffer.Span);
currentMessageOffset += toCopy;
Expand All @@ -208,7 +212,7 @@ public override async ValueTask<int> ReadAsync(Memory<byte> buffer,
}
long totalRead;

bool MessageNeeded() => message.Length - currentMessageOffset == 0;
bool MessageNeeded() => message.Count - currentMessageOffset == 0;

public override void Write(byte[] buffer, int offset, int count)
{
Expand All @@ -235,13 +239,13 @@ public override async ValueTask WriteAsync(ReadOnlyMemory<byte> buffer,
{
cancellationToken.ThrowIfCancellationRequested();
var packet = buffer[..MaxSendBytes];
await Task.Run(() => Send(packet.Span.ToArray()), cancellationToken)
await Task.Run(() => Send(packet.Span), cancellationToken)
.ConfigureAwait(false);
buffer = buffer[MaxSendBytes..];
}
cancellationToken.ThrowIfCancellationRequested();
if (buffer.Length > 0)
Send(buffer.Span.ToArray());
Send(buffer.Span);
}
finally
{
Expand All @@ -250,7 +254,7 @@ await Task.Run(() => Send(packet.Span.ToArray()), cancellationToken)
}

long totalSent;
void Send(byte[] buffer)
void Send(ReadOnlySpan<byte> buffer)
{
channel.send(buffer);
Interlocked.Add(ref totalSent, buffer.Length);
Expand All @@ -264,11 +268,11 @@ public override void Write(ReadOnlySpan<byte> buffer)
while (buffer.Length > MaxSendBytes)
{
var packet = buffer[..MaxSendBytes];
Send(packet.ToArray());
Send(packet);
buffer = buffer[MaxSendBytes..];
}
if (buffer.Length > 0)
Send(buffer.ToArray());
Send(buffer);
}
finally
{
Expand Down
13 changes: 13 additions & 0 deletions examples/WebRTCScenarios/DataChannelBandwidth/SpanExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Buffers;

namespace DataChannelBandwidth;

static class SpanExtensions
{
public static ArraySegment<T> ToArraySegment<T>(this ReadOnlySpan<T> span, ArrayPool<T> pool)
{
var result = pool.Rent(span.Length);
span.CopyTo(result);
return new ArraySegment<T>(result, 0, span.Length);
}
}
17 changes: 9 additions & 8 deletions src/SIPSorcery.csproj
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
<PackageReference Include="DnsClient" Version="1.7.0" />
<PackageReference Include="SIPSorcery.WebSocketSharp" Version="0.0.1" />
<PackageReference Include="SIPSorceryMedia.Abstractions" Version="1.2.1" />
<PackageReference Include="Small" Version="0.0.2" />
<PackageReference Include="System.Net.WebSockets.Client" Version="4.3.2" />
</ItemGroup>

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net461;net5.0;net6.0;net8.0</TargetFrameworks>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TargetFrameworks>netstandard2.0;net461;net6.0;net8.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);SYSLIB0050</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- Disable warning for missing XML doc comments. -->
Expand All @@ -41,7 +42,6 @@
<Company>SIP Sorcery PTY LTD</Company>
<Product>SIPSorcery</Product>
<PackageId>SIPSorcery</PackageId>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageProjectUrl>https://sipsorcery-org.github.io/sipsorcery/</PackageProjectUrl>
<PackageIconUrl>http://www.sipsorcery.com/mainsite/favicon.ico</PackageIconUrl>
<PackageIcon>icon.png</PackageIcon>
Expand All @@ -50,6 +50,7 @@
<RepositoryBranch>master</RepositoryBranch>
<PackageTags>SIP WebRTC VoIP RTP SDP STUN ICE SIPSorcery</PackageTags>
<PackageReleaseNotes>-v8.0.0: RTP header extension improvements (thanks to @ChristopheI). Major version to 8 to reflect highest .net runtime supported.
-v7.0.0: upgraded BouncyCastle to v2. Set minimal supported DTLS to 1.2, and enabled 1.3.
-v6.2.4: WebRTC fix for DTLS change in Chrome v124.
-v6.2.3: Bug fixes.
-v6.2.1: Bug fixes.
Expand All @@ -67,9 +68,9 @@
-v6.0.2: Set .net6 targetted version as stable.
-v6.0.1-pre: Added .net6 target.</PackageReleaseNotes>
<NeutralLanguage>en</NeutralLanguage>
<Version>8.0.0</Version>
<AssemblyVersion>8.0.0</AssemblyVersion>
<FileVersion>8.0.0</FileVersion>
<Version>9.0.0-PacketView-24.7.10.0</Version>
<AssemblyVersion>9.0.0</AssemblyVersion>
<FileVersion>9.0.0</FileVersion>
</PropertyGroup>

<PropertyGroup Label="SourceLink">
Expand All @@ -80,8 +81,8 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>

<!-- Optional: Build symbol package (.snupkg) to distribute the PDB containing Source Link -->
<DebugType>Embedded</DebugType>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<ContinuousIntegrationBuild Condition="'$(CI)' == 'true'">true</ContinuousIntegrationBuild>
</PropertyGroup>

Expand Down
Loading