*/
public Identity removeProperty(String name);
+ Map<OwnIdentity, Trust> getTrust();
+
/**
* Retrieves the trust that this identity receives from the given own
* identity. If this identity is not in the own identity’s trust tree, a
package net.pterodactylus.sone.freenet.wot
-import java.util.Collections.*
+import java.util.Collections.synchronizedMap
+import java.util.Collections.synchronizedSet
+import kotlin.collections.set
/**
* A Web of Trust identity.
}
}
+ override fun getTrust(): Map<OwnIdentity, Trust> = synchronized(trustCache) {
+ trustCache.toMap()
+ }
+
override fun getTrust(ownIdentity: OwnIdentity) = synchronized(trustCache) {
trustCache[ownIdentity]
}
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() }})).")
} catch (e: Exception) {
false
}
+
+private fun Trust.hasZeroOrPositiveTrust() =
+ if (explicit == null) {
+ implicit == null || implicit >= 0
+ } else {
+ explicit >= 0
+ }