projects
/
Sone.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e2eb441
)
🚧 Try to only allow identities that have no or positive trust
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Sat, 18 Apr 2020 14:14:41 +0000
(16:14 +0200)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Sat, 18 Apr 2020 14:14:41 +0000
(16:14 +0200)
src/main/java/net/pterodactylus/sone/freenet/wot/Identity.java
patch
|
blob
|
history
src/main/kotlin/net/pterodactylus/sone/freenet/wot/DefaultIdentity.kt
patch
|
blob
|
history
src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityManagerImpl.kt
patch
|
blob
|
history
diff --git
a/src/main/java/net/pterodactylus/sone/freenet/wot/Identity.java
b/src/main/java/net/pterodactylus/sone/freenet/wot/Identity.java
index
63bceb1
..
e6f4f62
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/freenet/wot/Identity.java
+++ b/
src/main/java/net/pterodactylus/sone/freenet/wot/Identity.java
@@
-131,6
+131,8
@@
public interface Identity {
*/
public Identity removeProperty(String name);
*/
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
/**
* 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
diff --git
a/src/main/kotlin/net/pterodactylus/sone/freenet/wot/DefaultIdentity.kt
b/src/main/kotlin/net/pterodactylus/sone/freenet/wot/DefaultIdentity.kt
index
6097916
..
88527b3
100644
(file)
--- a/
src/main/kotlin/net/pterodactylus/sone/freenet/wot/DefaultIdentity.kt
+++ b/
src/main/kotlin/net/pterodactylus/sone/freenet/wot/DefaultIdentity.kt
@@
-17,7
+17,9
@@
package net.pterodactylus.sone.freenet.wot
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.
/**
* A Web of Trust identity.
@@
-77,6
+79,10
@@
open class DefaultIdentity(private val id: String, private val nickname: String?
}
}
}
}
+ override fun getTrust(): Map<OwnIdentity, Trust> = synchronized(trustCache) {
+ trustCache.toMap()
+ }
+
override fun getTrust(ownIdentity: OwnIdentity) = synchronized(trustCache) {
trustCache[ownIdentity]
}
override fun getTrust(ownIdentity: OwnIdentity) = synchronized(trustCache) {
trustCache[ownIdentity]
}
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
(file)
--- 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()
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 ->
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() }})).")
}
}
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
}
} catch (e: Exception) {
false
}
+
+private fun Trust.hasZeroOrPositiveTrust() =
+ if (explicit == null) {
+ implicit == null || implicit >= 0
+ } else {
+ explicit >= 0
+ }