X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Fwot%2FIdentityLoader.kt;h=f6e1d5905af71b8fe44656ea94921a1a608fab1d;hp=fe5be5c5f91caab017260101be3af562b14cccc2;hb=HEAD;hpb=d0de7459fa121c7e3048109df4b9c06f3eaef21a diff --git a/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityLoader.kt b/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityLoader.kt index fe5be5c..f6e1d59 100644 --- a/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityLoader.kt +++ b/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityLoader.kt @@ -1,5 +1,5 @@ /* - * 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 @@ -31,24 +31,48 @@ class IdentityLoader @Inject constructor(private val webOfTrustConnector: WebOfT 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) = - ownIdentities.associateWith { ownIdentity -> - logger.fine { "Getting trusted identities for ${ownIdentities.size} own identities..."} - if (ownIdentity.doesNotHaveCorrectContext()) { - logger.fine { "Skipping $ownIdentity because of incorrect context."} - emptySet() - } else { - time({ stopwatch, identities -> "Loaded ${identities.size} identities for ${ownIdentity.nickname} in ${stopwatch.elapsed(MILLISECONDS) / 1000.0}s." }) { - webOfTrustConnector.loadTrustedIdentities(ownIdentity, context?.context) + 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.loadTrustedIdentities(ownIdentity, context?.context) + } + } + } + + private fun loadAllIdentitiesForOwnIdentities(ownIdentities: Collection) = + 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) + } + } } - } - } private fun OwnIdentity.doesNotHaveCorrectContext() = context?.let { it.context !in contexts } ?: false