Skip to content

Commit 2bff0f5

Browse files
authored
Fix dave commit failure mitigation and add linux x64 binaries to NetCord.Test (#340)
1 parent 273c61b commit 2bff0f5

10 files changed

Lines changed: 170 additions & 27 deletions

File tree

NetCord/Gateway/Voice/VoiceClient.DaveSession.cs

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public partial class VoiceClient
1515
{
1616
internal readonly ref struct DaveEncryptor(EncryptorHandle encryptor)
1717
{
18-
public readonly unsafe EncryptorResultCode Encrypt(MediaType mediaType, uint ssrc, ReadOnlySpan<byte> frame, Span<byte> encryptedFrame, out int bytesWritten)
18+
public readonly EncryptorResultCode Encrypt(MediaType mediaType, uint ssrc, ReadOnlySpan<byte> frame, Span<byte> encryptedFrame, out int bytesWritten)
1919
{
2020
var result = EncryptorEncrypt(encryptor, mediaType, ssrc, frame, (uint)frame.Length, encryptedFrame, (nuint)encryptedFrame.Length, out var rawBytesWritten);
2121

@@ -29,7 +29,7 @@ public readonly int GetMaxCiphertextSize(MediaType mediaType, int plaintextByteS
2929

3030
internal struct DaveDecryptor(DecryptorHandle decryptor)
3131
{
32-
public readonly unsafe DecryptorResultCode Decrypt(MediaType mediaType, uint ssrc, ReadOnlySpan<byte> encryptedFrame, Span<byte> frame, out int bytesWritten)
32+
public readonly DecryptorResultCode Decrypt(MediaType mediaType, uint ssrc, ReadOnlySpan<byte> encryptedFrame, Span<byte> frame, out int bytesWritten)
3333
{
3434
var result = DecryptorDecrypt(decryptor, mediaType, encryptedFrame, (nuint)encryptedFrame.Length, frame, (nuint)frame.Length, out var rawBytesWritten);
3535

@@ -79,7 +79,7 @@ private static unsafe void LogSink(LoggingSeverity severity, byte* file, int lin
7979
#if DEBUG
8080
var fileString = Marshal.PtrToStringUTF8((nint)file);
8181
var messageString = Marshal.PtrToStringUTF8((nint)message);
82-
System.Diagnostics.Debug.WriteLine($"Dave at {fileString}:{line}: {messageString}");
82+
Debug.WriteLine($"Dave at {fileString}:{line}: {messageString}");
8383
#endif
8484
}
8585

@@ -147,12 +147,12 @@ public ValueTask OnPrepareEpoch(ConnectionState connectionState, int epoch, usho
147147
return default;
148148
}
149149

150-
public unsafe void OnMlsExternalSender(ReadOnlySpan<byte> externalSender)
150+
public void OnMlsExternalSender(ReadOnlySpan<byte> externalSender)
151151
{
152152
SessionSetExternalSender(_session, externalSender, (nuint)externalSender.Length);
153153
}
154154

155-
public unsafe ValueTask OnMlsProposalsAsync(ConnectionState connectionState, ReadOnlySpan<byte> proposals)
155+
public ValueTask OnMlsProposalsAsync(ConnectionState connectionState, ReadOnlySpan<byte> proposals)
156156
{
157157
var recognizedUserIds = GetRecognizedUserIds(out var buffer);
158158

@@ -175,7 +175,23 @@ public ValueTask OnMlsPrepareCommitTransitionAsync(ConnectionState connectionSta
175175
if (CommitResultIsIgnored(commitResultHandle))
176176
return default;
177177

178-
return HandleRosterUpdatedAsync(connectionState, transitionId, CommitResultIsFailed(commitResultHandle));
178+
return ContinueAsync(connectionState, this, transitionId, CommitResultIsFailed(commitResultHandle));
179+
180+
static async ValueTask ContinueAsync(ConnectionState connectionState, DaveSession session, ushort transitionId, bool isFailed)
181+
{
182+
var joinedGroup = !isFailed;
183+
if (joinedGroup)
184+
{
185+
session.PrepareRatchets(transitionId, session.GetProtocolVersion());
186+
if (transitionId is not InitTransitionId)
187+
await session.SendTransitionReadyAsync(connectionState, transitionId).ConfigureAwait(false);
188+
}
189+
else
190+
{
191+
await session.SendMlsInvalidCommitWelcomeAsync(connectionState, transitionId).ConfigureAwait(false);
192+
await session.HandleInitAsync(connectionState, session.GetProtocolVersion()).ConfigureAwait(false);
193+
}
194+
}
179195
}
180196

181197
public ValueTask OnMlsWelcomeAsync(ConnectionState connectionState, ushort transitionId, ReadOnlySpan<byte> welcome)
@@ -186,7 +202,23 @@ public ValueTask OnMlsWelcomeAsync(ConnectionState connectionState, ushort trans
186202

187203
FreeRecognizedUserIdsBuffer(buffer);
188204

189-
return HandleRosterUpdatedAsync(connectionState, transitionId, welcomeResult.IsInvalid);
205+
return ContinueAsync(connectionState, this, transitionId, welcomeResult.IsInvalid);
206+
207+
static async ValueTask ContinueAsync(ConnectionState connectionState, DaveSession session, ushort transitionId, bool isFailed)
208+
{
209+
var joinedGroup = !isFailed;
210+
if (joinedGroup)
211+
{
212+
session.PrepareRatchets(transitionId, session.GetProtocolVersion());
213+
if (transitionId is not InitTransitionId)
214+
await session.SendTransitionReadyAsync(connectionState, transitionId).ConfigureAwait(false);
215+
}
216+
else
217+
{
218+
await session.SendMlsInvalidCommitWelcomeAsync(connectionState, transitionId).ConfigureAwait(false);
219+
await session.SendMlsKeyPackageAsync(connectionState).ConfigureAwait(false);
220+
}
221+
}
190222
}
191223

192224
private void SetDecryptorsPassthroughMode(bool passthroughMode)
@@ -195,22 +227,6 @@ private void SetDecryptorsPassthroughMode(bool passthroughMode)
195227
DecryptorTransitionToPassthroughMode(decryptor, passthroughMode);
196228
}
197229

198-
private async ValueTask HandleRosterUpdatedAsync(ConnectionState connectionState, ushort transitionId, bool isFailed)
199-
{
200-
var joinedGroup = !isFailed;
201-
if (joinedGroup)
202-
{
203-
PrepareRatchets(transitionId, GetProtocolVersion());
204-
if (transitionId is not InitTransitionId)
205-
await SendTransitionReadyAsync(connectionState, transitionId).ConfigureAwait(false);
206-
}
207-
else
208-
{
209-
await SendMlsInvalidCommitWelcomeAsync(connectionState, transitionId).ConfigureAwait(false);
210-
await SendMlsKeyPackageAsync(connectionState).ConfigureAwait(false);
211-
}
212-
}
213-
214230
private unsafe ReadOnlySpan<nint> GetRecognizedUserIds(out nint[] pointers)
215231
{
216232
var users = _client.Cache.Users;

Tests/NetCord.Test/NetCord.Test.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
<None Update="libdave.dll">
2424
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2525
</None>
26-
<None Update="libsodium.dll">
27-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
28-
</None>
29-
<None Update="opus.dll">
26+
<None Update="runtimes\**">
3027
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3128
</None>
3229
<None Update="Localizations\localization.pl.pl.pl.json">
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Discord
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
9.13 MB
Binary file not shown.
644 KB
Binary file not shown.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Copyright 2001-2023 Xiph.Org, Skype Limited, Octasic,
2+
Jean-Marc Valin, Timothy B. Terriberry,
3+
CSIRO, Gregory Maxwell, Mark Borgerding,
4+
Erik de Castro Lopo, Mozilla, Amazon
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions
8+
are met:
9+
10+
- Redistributions of source code must retain the above copyright
11+
notice, this list of conditions and the following disclaimer.
12+
13+
- Redistributions in binary form must reproduce the above copyright
14+
notice, this list of conditions and the following disclaimer in the
15+
documentation and/or other materials provided with the distribution.
16+
17+
- Neither the name of Internet Society, IETF or IETF Trust, nor the
18+
names of specific contributors, may be used to endorse or promote
19+
products derived from this software without specific prior written
20+
permission.
21+
22+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26+
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
34+
Opus is subject to the royalty-free patent licenses which are
35+
specified at:
36+
37+
Xiph.Org Foundation:
38+
https://datatracker.ietf.org/ipr/1524/
39+
40+
Microsoft Corporation:
41+
https://datatracker.ietf.org/ipr/1914/
42+
43+
Broadcom Corporation:
44+
https://datatracker.ietf.org/ipr/1526/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Discord
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Tests/NetCord.Test/libdave.dll renamed to Tests/NetCord.Test/runtimes/win-x64/native/libdave.dll

File renamed without changes.
443 KB
Binary file not shown.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Copyright 2001-2023 Xiph.Org, Skype Limited, Octasic,
2+
Jean-Marc Valin, Timothy B. Terriberry,
3+
CSIRO, Gregory Maxwell, Mark Borgerding,
4+
Erik de Castro Lopo, Mozilla, Amazon
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions
8+
are met:
9+
10+
- Redistributions of source code must retain the above copyright
11+
notice, this list of conditions and the following disclaimer.
12+
13+
- Redistributions in binary form must reproduce the above copyright
14+
notice, this list of conditions and the following disclaimer in the
15+
documentation and/or other materials provided with the distribution.
16+
17+
- Neither the name of Internet Society, IETF or IETF Trust, nor the
18+
names of specific contributors, may be used to endorse or promote
19+
products derived from this software without specific prior written
20+
permission.
21+
22+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26+
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
34+
Opus is subject to the royalty-free patent licenses which are
35+
specified at:
36+
37+
Xiph.Org Foundation:
38+
https://datatracker.ietf.org/ipr/1524/
39+
40+
Microsoft Corporation:
41+
https://datatracker.ietf.org/ipr/1914/
42+
43+
Broadcom Corporation:
44+
https://datatracker.ietf.org/ipr/1526/

0 commit comments

Comments
 (0)