/*
- * Sone - IdentityManager.java - Copyright © 2010 David Roden
+ * WoTNS - IdentityManager.java - Copyright © 2010–2017 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
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;
* The Web of Trust connector
*/
public IdentityManager(WebOfTrustConnector webOfTrustConnector) {
- super("Sone Identity Manager", false);
+ super("WoTNS Identity Manager", false);
this.webOfTrustConnector = webOfTrustConnector;
}
}
}
+ /**
+ * 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<Identity> getTrustedIdentities(OwnIdentity ownIdentity) {
- SetBuilder<Identity> identities = new SetBuilder<Identity>();
- if ((context == null) || ownIdentity.getContexts().contains(context)) {
- identities.add(ownIdentity);
+ Set<Identity> identities = new HashSet<Identity>();
+ for (OwnIdentity additionalOwnIdentity : getAllOwnIdentities()) {
+ if ((context == null) || additionalOwnIdentity.getContexts().contains(context)) {
+ identities.add(additionalOwnIdentity);
+ }
}
- synchronized (syncObject) {
- identities.addAll(Default.forNull(currentTrustedIdentities.get(ownIdentity), Collections.<Identity> emptySet()));
+ try {
+ Set<Identity> trustedIdentities = webOfTrustConnector.loadTrustedIdentities(ownIdentity, context);
+ Map<String, Identity> newTrustedIdentities = new HashMap<String, Identity>();
+ 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;
}
//
protected void serviceRun() {
while (!shouldStop()) {
Map<OwnIdentity, Map<String, Identity>> currentIdentities = new HashMap<OwnIdentity, Map<String, Identity>>();
- @SuppressWarnings("hiding")
Map<String, OwnIdentity> currentOwnIdentities = new HashMap<String, OwnIdentity>();
Set<OwnIdentity> ownIdentities = null;
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;
for (OwnIdentity oldOwnIdentity : currentOwnIdentities.values()) {
if (!newOwnIdentities.containsKey(oldOwnIdentity.getId())) {
identityListenerManager.fireOwnIdentityRemoved(oldOwnIdentity);
+ currentTrustedIdentities.remove(oldOwnIdentity);
}
}
*/
private void checkTrustedIdentities(OwnIdentity ownIdentity, Map<String, Identity> trustedIdentities) {
- @SuppressWarnings("hiding")
Map<String, Identity> currentTrustedIdentities = new HashMap<String, Identity>();
synchronized (syncObject) {
if (this.currentTrustedIdentities.containsKey(ownIdentity)) {