Fix / concurrent start broke QR verification

This commit is contained in:
Valere 2020-03-23 18:43:52 +01:00
parent 49e5fafb2d
commit 6cc8d1b205
1 changed files with 34 additions and 34 deletions

View File

@ -456,7 +456,7 @@ internal class DefaultVerificationService @Inject constructor(
private suspend fun handleStart(otherUserId: String?,
startReq: ValidVerificationInfoStart,
txConfigure: (DefaultVerificationTransaction) -> Unit): CancelCode? {
Timber.d("## SAS onStartRequestReceived ${startReq.transactionId}")
Timber.d("## SAS onStartRequestReceived ${startReq}")
if (otherUserId?.let { checkKeysAreDownloaded(it, startReq.fromDevice) } != null) {
val tid = startReq.transactionId
var existing = getExistingTransaction(otherUserId, tid)
@ -468,15 +468,17 @@ internal class DefaultVerificationService @Inject constructor(
// smallest is used, and the other m.key.verification.start event is ignored.
// In the case of a single user verifying two of their devices, the device ID is
// compared instead .
if (existing != null && !existing.isIncoming) {
if (existing is DefaultOutgoingSASDefaultVerificationTransaction) {
val readyRequest = getExistingVerificationRequest(otherUserId, tid)
if (readyRequest?.isReady == true) {
if (isOtherPrioritary(otherUserId, existing.otherDeviceId ?: "")) {
Timber.d("## SAS concurrent start isOtherPrioritary, clear")
// The other is prioritary!
// I should replace my outgoing with an incoming
removeTransaction(otherUserId, tid)
existing = null
} else {
Timber.d("## SAS concurrent start i am prioritary, ignore")
// i am prioritary, ignore this start event!
return null
}
@ -547,7 +549,7 @@ internal class DefaultVerificationService @Inject constructor(
existing.onStartReceived(startReq)
return null
} else {
Timber.w("## SAS onStartRequestReceived - unexpected message ${startReq.transactionId}")
Timber.w("## SAS onStartRequestReceived - unexpected message ${startReq.transactionId} / ${existing}")
return CancelCode.UnexpectedMessage
}
}
@ -838,18 +840,18 @@ internal class DefaultVerificationService @Inject constructor(
if (readyReq.methods.contains(VERIFICATION_METHOD_RECIPROCATE)) {
// Create the pending transaction
val tx = DefaultQrCodeVerificationTransaction(
setDeviceVerificationAction,
readyReq.transactionId,
senderId,
readyReq.fromDevice,
crossSigningService,
outgoingGossipingRequestManager,
incomingGossipingRequestManager,
cryptoStore,
qrCodeData,
userId,
deviceId ?: "",
false)
setDeviceVerificationAction = setDeviceVerificationAction,
transactionId = readyReq.transactionId,
otherUserId = senderId,
otherDeviceId = readyReq.fromDevice,
crossSigningService = crossSigningService,
outgoingGossipingRequestManager = outgoingGossipingRequestManager,
incomingGossipingRequestManager = incomingGossipingRequestManager,
cryptoStore = cryptoStore,
qrCodeData = qrCodeData,
userId = userId,
deviceId = deviceId ?: "",
isIncoming = false)
tx.transport = transportCreator.invoke(tx)
@ -1006,13 +1008,11 @@ internal class DefaultVerificationService @Inject constructor(
}
private fun addTransaction(tx: DefaultVerificationTransaction) {
tx.otherUserId.let { otherUserId ->
synchronized(txMap) {
val txInnerMap = txMap.getOrPut(otherUserId) { HashMap() }
txInnerMap[tx.transactionId] = tx
dispatchTxAdded(tx)
tx.addListener(this)
}
synchronized(txMap) {
val txInnerMap = txMap.getOrPut(tx.otherUserId) { HashMap() }
txInnerMap[tx.transactionId] = tx
dispatchTxAdded(tx)
tx.addListener(this)
}
}
@ -1336,18 +1336,18 @@ internal class DefaultVerificationService @Inject constructor(
if (VERIFICATION_METHOD_RECIPROCATE in result) {
// Create the pending transaction
val tx = DefaultQrCodeVerificationTransaction(
setDeviceVerificationAction,
transactionId,
otherUserId,
otherDeviceId,
crossSigningService,
outgoingGossipingRequestManager,
incomingGossipingRequestManager,
cryptoStore,
qrCodeData,
userId,
deviceId ?: "",
false)
setDeviceVerificationAction = setDeviceVerificationAction,
transactionId = transactionId,
otherUserId = otherUserId,
otherDeviceId = otherDeviceId,
crossSigningService = crossSigningService,
outgoingGossipingRequestManager = outgoingGossipingRequestManager,
incomingGossipingRequestManager = incomingGossipingRequestManager,
cryptoStore = cryptoStore,
qrCodeData = qrCodeData,
userId = userId,
deviceId = deviceId ?: "",
isIncoming = false)
tx.transport = transportCreator.invoke(tx)