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<OwnIdentity>) =
ownIdentities
}
}
+ private fun loadAllIdentitiesForOwnIdentities(ownIdentities: Collection<OwnIdentity>) =
+ 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
while (!shouldStop()) {
try {
- val currentIdentities = identityLoader.loadTrustedIdentities()
+ val currentIdentities = identityLoader.loadAllIdentities()
val identitiesWithTrust = currentIdentities.values.flatten()
.groupBy { it.id }
package net.pterodactylus.sone.freenet.wot
-import com.google.inject.*
-import freenet.support.*
-import kotlinx.coroutines.*
-import net.pterodactylus.sone.freenet.*
-import net.pterodactylus.sone.freenet.plugin.*
-import java.lang.String.*
-import java.util.logging.*
+import com.google.inject.Inject
+import freenet.support.SimpleFieldSet
+import kotlinx.coroutines.runBlocking
+import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder
+import net.pterodactylus.sone.freenet.plugin.PluginConnector
+import net.pterodactylus.sone.freenet.plugin.PluginException
+import net.pterodactylus.sone.freenet.plugin.PluginReply
+import java.lang.String.format
+import java.util.logging.Level
import java.util.logging.Logger
-import java.util.logging.Logger.*
+import java.util.logging.Logger.getLogger
/**
* Connector for the Web of Trust plugin.
.fields
.parseIdentities { parseTrustedIdentity(it, ownIdentity) }
+ override fun loadAllIdentities(ownIdentity: OwnIdentity, context: String?): Set<Identity> =
+ performRequest(SimpleFieldSetBuilder().put("Message", "GetIdentitiesByScore").put("Truster", ownIdentity.id).put("Selection", "+").put("Context", context ?: "").put("WantTrustValues", "true").get())
+ .fields
+ .parseIdentities { parseTrustedIdentity(it, ownIdentity) } +
+ performRequest(SimpleFieldSetBuilder().put("Message", "GetIdentitiesByScore").put("Truster", ownIdentity.id).put("Selection", "-").put("Context", context ?: "").put("WantTrustValues", "true").get())
+ .fields
+ .parseIdentities { parseTrustedIdentity(it, ownIdentity) }
+
@Throws(PluginException::class)
override fun addContext(ownIdentity: OwnIdentity, context: String) {
performRequest(SimpleFieldSetBuilder().put("Message", "AddContext").put("Identity", ownIdentity.id).put("Context", context).get())
fun loadTrustedIdentities(ownIdentity: OwnIdentity, context: String? = null): Set<Identity>
/**
+ * Loads all identities known to the given own identity that have the (optional) given context.
+ *
+ * @param ownIdentity The own identity
+ * @param context The context to filter, or `null`
+ * @return All trusted identities
+ * @throws PluginException if an error occured talking to the Web of Trust plugin
+ */
+ fun loadAllIdentities(ownIdentity: OwnIdentity, context: String? = null): Set<Identity>
+
+ /**
* Adds the given context to the given identity.
*
* @param ownIdentity The identity to add the context to
override fun loadAllOwnIdentities() = emptySet<OwnIdentity>()
override fun loadTrustedIdentities(ownIdentity: OwnIdentity, context: String?) = emptySet<Identity>()
+ override fun loadAllIdentities(ownIdentity: OwnIdentity, context: String?) = emptySet<Identity>()
override fun addContext(ownIdentity: OwnIdentity, context: String) = Unit
override fun removeContext(ownIdentity: OwnIdentity, context: String) = Unit
override fun setProperty(ownIdentity: OwnIdentity, name: String, value: String) = Unit