Send several NO_OLM in one request

This commit is contained in:
Valere 2021-03-18 15:08:56 +01:00
parent c1254ed5b1
commit 35635c859d
2 changed files with 24 additions and 17 deletions

View File

@ -5,7 +5,7 @@ Features ✨:
- -
Improvements 🙌: Improvements 🙌:
- - Crypto improvement | Bulck send NO_OLM withheld code
Bugfix 🐛: Bugfix 🐛:
- -

View File

@ -67,8 +67,9 @@ internal class MXMegolmEncryption(
init { init {
// restore existing outbound session if any // restore existing outbound session if any
outboundSession = olmDevice.restoreOutboundGroupSessionForRoom(roomId) outboundSession = olmDevice.restoreOutboundGroupSessionForRoom(roomId)
} }
// Default rotation periods // Default rotation periods
// TODO: Make it configurable via parameters // TODO: Make it configurable via parameters
// Session rotation periods // Session rotation periods
@ -125,6 +126,7 @@ internal class MXMegolmEncryption(
Timber.v("## CRYPTO | preshareKey ${System.currentTimeMillis() - ts} millis") Timber.v("## CRYPTO | preshareKey ${System.currentTimeMillis() - ts} millis")
} }
/** /**
* Prepare a new session. * Prepare a new session.
* *
@ -240,6 +242,7 @@ internal class MXMegolmEncryption(
val contentMap = MXUsersDevicesMap<Any>() val contentMap = MXUsersDevicesMap<Any>()
var haveTargets = false var haveTargets = false
val userIds = results.userIds val userIds = results.userIds
val noOlmToNotify = mutableListOf<UserDevice>()
for (userId in userIds) { for (userId in userIds) {
val devicesToShareWith = devicesByUser[userId] val devicesToShareWith = devicesByUser[userId]
for ((deviceID) in devicesToShareWith!!) { for ((deviceID) in devicesToShareWith!!) {
@ -251,13 +254,7 @@ internal class MXMegolmEncryption(
// MSC 2399 // MSC 2399
// send withheld m.no_olm: an olm session could not be established. // send withheld m.no_olm: an olm session could not be established.
// This may happen, for example, if the sender was unable to obtain a one-time key from the recipient. // This may happen, for example, if the sender was unable to obtain a one-time key from the recipient.
notifyKeyWithHeld( noOlmToNotify.add(UserDevice(userId, deviceID))
listOf(UserDevice(userId, deviceID)),
session.sessionId,
olmDevice.deviceCurve25519Key,
WithHeldCode.NO_OLM
)
continue continue
} }
Timber.i("## CRYPTO | shareUserDevicesKey() : Add to share keys contentMap for $userId:$deviceID") Timber.i("## CRYPTO | shareUserDevicesKey() : Add to share keys contentMap for $userId:$deviceID")
@ -277,14 +274,14 @@ internal class MXMegolmEncryption(
session.sharedWithHelper.markedSessionAsShared(userId, deviceId, chainIndex) session.sharedWithHelper.markedSessionAsShared(userId, deviceId, chainIndex)
gossipingEventBuffer.add( gossipingEventBuffer.add(
Event( Event(
type = EventType.ROOM_KEY, type = EventType.ROOM_KEY,
senderId = this.userId, senderId = this.userId,
content = submap.apply { content = submap.apply {
this["session_key"] = "" this["session_key"] = ""
// we add a fake key for trail // we add a fake key for trail
this["_dest"] = "$userId|$deviceId" this["_dest"] = "$userId|$deviceId"
} }
)) ))
} }
} }
@ -304,6 +301,16 @@ internal class MXMegolmEncryption(
} else { } else {
Timber.i("## CRYPTO | shareUserDevicesKey() : no need to sharekey") Timber.i("## CRYPTO | shareUserDevicesKey() : no need to sharekey")
} }
if (noOlmToNotify.isNotEmpty()) {
//XXX offload?, as they won't read the message anyhow?
notifyKeyWithHeld(
noOlmToNotify,
session.sessionId,
olmDevice.deviceCurve25519Key,
WithHeldCode.NO_OLM
)
}
} }
private suspend fun notifyKeyWithHeld(targets: List<UserDevice>, private suspend fun notifyKeyWithHeld(targets: List<UserDevice>,