@@ -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 ;
0 commit comments