/*
- * Sone - IdentityLoader.java - Copyright © 2013–2019 David Roden
+ * Sone - IdentityLoader.kt - Copyright © 2013–2020 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
private val logger: Logger = Logger.getLogger(IdentityLoader::class.java.name)
@Throws(WebOfTrustException::class)
- fun loadIdentities() =
+ fun loadTrustedIdentities() =
time({ stopwatch, identities -> "Loaded ${identities.size} own identities in ${stopwatch.elapsed(MILLISECONDS) / 1000.0}s." }) {
webOfTrustConnector.loadAllOwnIdentities()
}.let(this::loadTrustedIdentitiesForOwnIdentities)
+ fun loadAllIdentities() =
+ time({ stopwatch, identities -> "Loaded ${identities.size} own identities in ${stopwatch.elapsed(MILLISECONDS) / 1000.0}s." }) {
+ webOfTrustConnector.loadAllOwnIdentities()
+ }.let(this::loadAllIdentitiesForOwnIdentities)
+
@Throws(PluginException::class)
private fun loadTrustedIdentitiesForOwnIdentities(ownIdentities: Collection<OwnIdentity>) =
ownIdentities
} else {
logger.fine { "Loading trusted identities for $ownIdentity from WoT..." }
time({ stopwatch, identities -> "Loaded ${identities.size} identities for ${ownIdentity.nickname} in ${stopwatch.elapsed(MILLISECONDS) / 1000.0}s." }) {
- try {
- webOfTrustConnector.loadTrustedIdentities(ownIdentity, context?.context)
- } catch (e: Exception) {
- logger.warning { "Caught $e on loading trusted identities for $ownIdentity."}
- throw e
- }
+ webOfTrustConnector.loadTrustedIdentities(ownIdentity, context?.context)
+ }
+ }
+ }
+
+ private fun loadAllIdentitiesForOwnIdentities(ownIdentities: Collection<OwnIdentity>) =
+ ownIdentities
+ .also { logger.fine { "Getting trusted identities for ${it.size} own identities..." } }
+ .associateWith { ownIdentity ->
+ logger.fine { "Getting trusted identities for $ownIdentity..." }
+ if (ownIdentity.doesNotHaveCorrectContext()) {
+ logger.fine { "Skipping $ownIdentity because of incorrect context." }
+ emptySet()
+ } else {
+ logger.fine { "Loading trusted identities for $ownIdentity from WoT..." }
+ time({ stopwatch, identities -> "Loaded ${identities.size} identities for ${ownIdentity.nickname} in ${stopwatch.elapsed(MILLISECONDS) / 1000.0}s." }) {
+ webOfTrustConnector.loadAllIdentities(ownIdentity, context?.context)
}
}
}