@@ -105,7 +105,8 @@ impl Bob {
105
105
) -> Result < StartedProtocolVariant , JoinError > {
106
106
let mut guard = self . inner . lock ( ) . await ;
107
107
if guard. is_some ( ) {
108
- return Err ( JoinError :: AlreadyRunning ) ;
108
+ warn ! ( context, "The new securejoin will replace the ongoing one." ) ;
109
+ * guard = None ;
109
110
}
110
111
let variant = match invite {
111
112
QrInvite :: Group { ref grpid, .. } => {
@@ -248,19 +249,22 @@ async fn get_self_fingerprint(context: &Context) -> Option<Fingerprint> {
248
249
pub enum JoinError {
249
250
#[ error( "Unknown QR-code: {0}" ) ]
250
251
QrCode ( #[ from] QrError ) ,
251
- #[ error( "A setup-contact/secure-join protocol is already running" ) ]
252
- AlreadyRunning ,
252
+
253
253
#[ error( "An \" ongoing\" process is already running" ) ]
254
254
OngoingRunning ,
255
+
255
256
#[ error( "Failed to send handshake message: {0}" ) ]
256
257
SendMessage ( #[ from] SendMsgError ) ,
258
+
257
259
// Note that this can currently only occur if there is a bug in the QR/Lot code as this
258
260
// is supposed to create a contact for us.
259
261
#[ error( "Unknown contact (this is a bug): {0}" ) ]
260
262
UnknownContact ( #[ source] anyhow:: Error ) ,
263
+
261
264
// Note that this can only occur if we failed to create the chat correctly.
262
265
#[ error( "Ongoing sender dropped (this is a bug)" ) ]
263
266
OngoingSenderDropped ,
267
+
264
268
#[ error( "Other" ) ]
265
269
Other ( #[ from] anyhow:: Error ) ,
266
270
}
@@ -945,6 +949,7 @@ mod tests {
945
949
946
950
use crate :: chat;
947
951
use crate :: chat:: ProtectionStatus ;
952
+ use crate :: constants:: Chattype ;
948
953
use crate :: events:: Event ;
949
954
use crate :: peerstate:: Peerstate ;
950
955
use crate :: test_utils:: TestContext ;
@@ -1285,6 +1290,36 @@ mod tests {
1285
1290
Ok ( ( ) )
1286
1291
}
1287
1292
1293
+ #[ async_std:: test]
1294
+ async fn test_setup_contact_concurrent_calls ( ) -> Result < ( ) > {
1295
+ let alice = TestContext :: new_alice ( ) . await ;
1296
+ let bob = TestContext :: new_bob ( ) . await ;
1297
+
1298
+ // do a scan that is not working as claire is never responding
1299
+ let qr_stale = "OPENPGP4FPR:1234567890123456789012345678901234567890#a=claire%40foo.de&n=&i=12345678901&s=23456789012" ;
1300
+ let claire_id = dc_join_securejoin ( & bob, qr_stale) . await ?;
1301
+ let chat = Chat :: load_from_db ( & bob, claire_id) . await ?;
1302
+ assert ! ( !claire_id. is_special( ) ) ;
1303
+ assert_eq ! ( chat. typ, Chattype :: Single ) ;
1304
+ assert ! ( bob
. pop_sent_msg
( ) . await . payload
( ) . contains
( "[email protected] " ) ) ;
1305
+
1306
+ // subsequent scans shall abort existing ones or run concurrently -
1307
+ // but they must not fail as otherwise the whole qr scanning becomes unusable until restart.
1308
+ let qr = dc_get_securejoin_qr ( & alice, None ) . await ?;
1309
+ let alice_id = dc_join_securejoin ( & bob, & qr) . await ?;
1310
+ let chat = Chat :: load_from_db ( & bob, alice_id) . await ?;
1311
+ assert ! ( !alice_id. is_special( ) ) ;
1312
+ assert_eq ! ( chat. typ, Chattype :: Single ) ;
1313
+ assert_ne ! ( claire_id, alice_id) ;
1314
+ assert ! ( bob
1315
+ . pop_sent_msg( )
1316
+ . await
1317
+ . payload( )
1318
+
1319
+
1320
+ Ok ( ( ) )
1321
+ }
1322
+
1288
1323
#[ async_std:: test]
1289
1324
async fn test_secure_join ( ) -> Result < ( ) > {
1290
1325
let alice = TestContext :: new_alice ( ) . await ;
0 commit comments