X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Fwot%2FIdentityManagerImpl.kt;h=676278d6110cfc677043b8f62d0ab066be467873;hp=f0e08d4665eb8d994ba58a2d2dbeaa4b3597c996;hb=69a95e89c8a306713bbe719ce23f49e7536774be;hpb=e2eb4417311b9c18e297c2dff2a51d508fffa1d8 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 f0e08d4..676278d 100644 --- a/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.kt +++ b/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.kt @@ -58,9 +58,20 @@ class IdentityManagerImpl @Inject constructor( try { val currentIdentities = identityLoader.loadIdentities() - val onlyTrustedByAll = currentIdentities.mapValues { (ownIdentity, trustedIdentities) -> + 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.filterValues { it.isNotEmpty() }.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 + }