From: David ‘Bombe’ Roden Date: Mon, 11 Nov 2013 21:47:38 +0000 (+0100) Subject: Use the identity loader for loading identities. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=2ff7fd6b411a079c8c8a52eee90cafeb14630ae8;p=Sone.git Use the identity loader for loading identities. --- diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java index 2459c06..9817038 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityManager.java @@ -17,9 +17,9 @@ package net.pterodactylus.sone.freenet.wot; +import static com.google.common.base.Optional.fromNullable; import static com.google.common.collect.HashMultimap.create; -import java.util.Collection; import java.util.HashSet; import java.util.Set; import java.util.logging.Level; @@ -60,12 +60,11 @@ public class IdentityManager extends AbstractService { /** The event bus. */ private final EventBus eventBus; + private final IdentityLoader identityLoader; + /** The Web of Trust connector. */ private final WebOfTrustConnector webOfTrustConnector; - /** The context to filter for. */ - private final String context; - /** The currently known own identities. */ /* synchronize access on syncObject. */ private final Set currentOwnIdentities = Sets.newHashSet(); @@ -85,7 +84,7 @@ public class IdentityManager extends AbstractService { super("Sone Identity Manager", false); this.eventBus = eventBus; this.webOfTrustConnector = webOfTrustConnector; - this.context = context; + this.identityLoader = new IdentityLoader(webOfTrustConnector, fromNullable(context)); } // @@ -130,15 +129,14 @@ public class IdentityManager extends AbstractService { while (!shouldStop()) { try { - Collection currentOwnIdentities = webOfTrustConnector.loadAllOwnIdentities(); - Multimap currentIdentities = loadTrustedIdentitiesForOwnIdentities(currentOwnIdentities); + Multimap currentIdentities = identityLoader.loadIdentities(); - detectChangesInIdentities(currentOwnIdentities, currentIdentities, oldIdentities); + detectChangesInIdentities(currentIdentities, oldIdentities); oldIdentities = currentIdentities; synchronized (currentOwnIdentities) { - this.currentOwnIdentities.clear(); - this.currentOwnIdentities.addAll(currentOwnIdentities); + currentOwnIdentities.clear(); + currentOwnIdentities.addAll(currentIdentities.keySet()); } } catch (WebOfTrustException wote1) { logger.log(Level.WARNING, "WoT has disappeared!", wote1); @@ -149,12 +147,12 @@ public class IdentityManager extends AbstractService { } } - private void detectChangesInIdentities(Collection currentOwnIdentities, Multimap newIdentities, Multimap oldIdentities) { + private void detectChangesInIdentities(Multimap newIdentities, Multimap oldIdentities) { IdentityChangeDetector identityChangeDetector = new IdentityChangeDetector(getAllOwnIdentities()); identityChangeDetector.onNewIdentity(addNewOwnIdentityAndItsTrustedIdentities(newIdentities)); identityChangeDetector.onRemovedIdentity(removeOwnIdentityAndItsTrustedIdentities(oldIdentities)); identityChangeDetector.onUnchangedIdentity(detectChangesInTrustedIdentities(newIdentities, oldIdentities)); - identityChangeDetector.detectChanges(currentOwnIdentities); + identityChangeDetector.detectChanges(newIdentities.keySet()); } private IdentityProcessor detectChangesInTrustedIdentities(Multimap newIdentities, Multimap oldIdentities) { @@ -185,23 +183,6 @@ public class IdentityManager extends AbstractService { }; } - private Multimap loadTrustedIdentitiesForOwnIdentities(Collection ownIdentities) throws PluginException { - Multimap currentIdentities = create(); - - for (OwnIdentity ownIdentity : ownIdentities) { - if ((context != null) && !ownIdentity.hasContext(context)) { - continue; - } - - logger.finer(String.format("Getting trusted identities for %s...", ownIdentity.getId())); - Set trustedIdentities = webOfTrustConnector.loadTrustedIdentities(ownIdentity, context); - logger.finest(String.format("Got %d trusted identities.", trustedIdentities.size())); - currentIdentities.putAll(ownIdentity, trustedIdentities); - } - - return currentIdentities; - } - private class DefaultIdentityProcessor implements IdentityProcessor { private final Multimap oldIdentities;