X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Fwot%2FIdentityManagerImpl.kt;h=36d31fbff516a4a9e3fbec76c5b053c4f0e5bbba;hb=5b7e77d92a7dc57652332c87031c6d638d7588eb;hp=5f087c7eb899555fee35ffafd0d53f31d83140cc;hpb=a6aaf80dbee1c4b6e70159bf6b3c26609d8c3974;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.kt b/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.kt index 5f087c7..36d31fb 100644 --- a/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.kt +++ b/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.kt @@ -56,11 +56,22 @@ class IdentityManagerImpl @Inject constructor( while (!shouldStop()) { try { - val currentIdentities = identityLoader.loadIdentities() - - val onlyTrustedByAll = currentIdentities.mapValues { (ownIdentity, trustedIdentities) -> + val currentIdentities = identityLoader.loadTrustedIdentities() + + val identitiesWithTrust = currentIdentities.values.flatten() + .groupBy { it.id } + .mapValues { (_, identities) -> + identities.reduce { accIdentity, identity -> + identity.trust.forEach { (ownIdentity: OwnIdentity?, trust: Trust?) -> + accIdentity.setTrust(ownIdentity, trust) + } + accIdentity + } + } + + val onlyTrustedByAll = currentIdentities.mapValues { (_, trustedIdentities) -> trustedIdentities.filter { trustedIdentity -> - currentIdentities.all { trustedIdentity in it.value } + identitiesWithTrust[trustedIdentity.id]!!.trust.all { it.value.hasZeroOrPositiveTrust() } } } logger.log(Level.FINE, "Reduced (${currentIdentities.size},(${currentIdentities.values.joinToString { it.size.toString() }})) identities to (${onlyTrustedByAll.size},(${onlyTrustedByAll.values.joinToString { it.size.toString() }})).") @@ -96,3 +107,10 @@ private fun notThrowing(action: () -> Unit): Boolean = } catch (e: Exception) { false } + +private fun Trust.hasZeroOrPositiveTrust() = + if (explicit == null) { + implicit == null || implicit >= 0 + } else { + explicit >= 0 + }