X-Git-Url: https://git.pterodactylus.net/?p=WoTNS.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fwotns%2Ffreenet%2Fwot%2FIdentityManager.java;h=5a5310605244ad20efbb33c17137f53fdc6473e7;hp=3086f276579d378dd0b1094c9b117edaae11f311;hb=9251a40d3196f48d8c72b604ee8944bf391d26b0;hpb=ab09aee8c42db059abbb568f5e2a3047f6fc3002 diff --git a/src/main/java/net/pterodactylus/wotns/freenet/wot/IdentityManager.java b/src/main/java/net/pterodactylus/wotns/freenet/wot/IdentityManager.java index 3086f27..5a53106 100644 --- a/src/main/java/net/pterodactylus/wotns/freenet/wot/IdentityManager.java +++ b/src/main/java/net/pterodactylus/wotns/freenet/wot/IdentityManager.java @@ -27,9 +27,7 @@ import java.util.Map.Entry; import java.util.logging.Level; import java.util.logging.Logger; -import net.pterodactylus.util.collection.SetBuilder; import net.pterodactylus.util.logging.Logging; -import net.pterodactylus.util.object.Default; import net.pterodactylus.util.service.AbstractService; import net.pterodactylus.wotns.freenet.plugin.PluginException; @@ -173,15 +171,34 @@ public class IdentityManager extends AbstractService { } } + /** + * Returns all identities that are trusted by the given own identity. In + * addition to all non-own identities the given own identity is also + * returned. + * + * @param ownIdentity + * The own identity to get the trusted identities for + * @return The identities trusted by the given own identity + */ public Set getTrustedIdentities(OwnIdentity ownIdentity) { - SetBuilder identities = new SetBuilder(); - if ((context == null) || ownIdentity.getContexts().contains(context)) { - identities.add(ownIdentity); + Set identities = new HashSet(); + for (OwnIdentity additionalOwnIdentity : getAllOwnIdentities()) { + if ((context == null) || additionalOwnIdentity.getContexts().contains(context)) { + identities.add(additionalOwnIdentity); + } } - synchronized (syncObject) { - identities.addAll(Default.forNull(currentTrustedIdentities.get(ownIdentity), Collections. emptySet())); + try { + Set trustedIdentities = webOfTrustConnector.loadTrustedIdentities(ownIdentity, context); + Map newTrustedIdentities = new HashMap(); + for (Identity trustedIdentity : trustedIdentities) { + newTrustedIdentities.put(trustedIdentity.getId(), trustedIdentity); + } + checkTrustedIdentities(ownIdentity, newTrustedIdentities); + identities.addAll(trustedIdentities); + } catch (WebOfTrustException wote1) { + logger.log(Level.WARNING, String.format("Could not load all trusted identities for %s.", ownIdentity), wote1); } - return identities.get(); + return identities; } // @@ -195,7 +212,6 @@ public class IdentityManager extends AbstractService { protected void serviceRun() { while (!shouldStop()) { Map> currentIdentities = new HashMap>(); - @SuppressWarnings("hiding") Map currentOwnIdentities = new HashMap(); Set ownIdentities = null; @@ -218,7 +234,10 @@ public class IdentityManager extends AbstractService { identities.put(identity.getId(), identity); } - /* add own identities, too, as long as the WoT doesn’t do that. */ + /* + * add own identities, too, as long as the WoT doesn’t do + * that. + */ for (OwnIdentity additionalOwnIdentity : ownIdentities) { if (additionalOwnIdentity == ownIdentity) { continue; @@ -268,6 +287,7 @@ public class IdentityManager extends AbstractService { for (OwnIdentity oldOwnIdentity : currentOwnIdentities.values()) { if (!newOwnIdentities.containsKey(oldOwnIdentity.getId())) { identityListenerManager.fireOwnIdentityRemoved(oldOwnIdentity); + currentTrustedIdentities.remove(oldOwnIdentity); } } @@ -293,7 +313,6 @@ public class IdentityManager extends AbstractService { */ private void checkTrustedIdentities(OwnIdentity ownIdentity, Map trustedIdentities) { - @SuppressWarnings("hiding") Map currentTrustedIdentities = new HashMap(); synchronized (syncObject) { if (this.currentTrustedIdentities.containsKey(ownIdentity)) {