mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-11 11:57:01 +01:00
Hardened EOSEAccountFast against concurrent access so callers no longer iterate over live mutable maps
This commit is contained in:
@@ -125,12 +125,14 @@ class EOSEAccountFast<T : Any>(
|
||||
cacheSize: Int = 20,
|
||||
) {
|
||||
private val users: LruCache<T, EOSERelayList> = LruCache<T, EOSERelayList>(cacheSize)
|
||||
private val lock = Any()
|
||||
|
||||
fun addOrUpdate(
|
||||
user: T,
|
||||
relayUrl: NormalizedRelayUrl,
|
||||
time: Long,
|
||||
) {
|
||||
synchronized(lock) {
|
||||
val relayList = users[user]
|
||||
if (relayList == null) {
|
||||
val newList = EOSERelayList()
|
||||
@@ -141,20 +143,28 @@ class EOSEAccountFast<T : Any>(
|
||||
relayList.addOrUpdate(relayUrl, time)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun removeEveryoneBut(list: Set<T>) {
|
||||
synchronized(lock) {
|
||||
users.snapshot().forEach {
|
||||
if (it.key !in list) {
|
||||
users.remove(it.key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun removeDataFor(user: T) {
|
||||
users.remove(user)
|
||||
}
|
||||
|
||||
fun since(key: T) = users[key]?.relayList
|
||||
fun removeDataFor(user: T) {
|
||||
synchronized(lock) {
|
||||
users.remove(user)
|
||||
}
|
||||
}
|
||||
|
||||
fun since(key: T): SincePerRelayMap? =
|
||||
synchronized(lock) {
|
||||
users[key]?.relayList?.toMutableMap()
|
||||
}
|
||||
|
||||
fun newEose(
|
||||
user: T,
|
||||
|
||||
Reference in New Issue
Block a user