From: David ‘Bombe’ Roden Date: Fri, 16 Sep 2011 09:13:47 +0000 (+0200) Subject: Merge branch 'release-0.0.3' X-Git-Tag: 0.0.3^0 X-Git-Url: https://git.pterodactylus.net/?p=WoTNS.git;a=commitdiff_plain;h=1b05589c7ecc8c86c45908ec6129d4ae3dd0ef16;hp=2083a1061f5ecb9d8573cfcd98c5f416e8dffb6c Merge branch 'release-0.0.3' --- diff --git a/pom.xml b/pom.xml index 24d87ae..37e947e 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 net.pterodactylus WoTNS - 0.0.2 + 0.0.3 net.pterodactylus 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 1411ab3..ea90dac 100644 --- a/src/main/java/net/pterodactylus/wotns/freenet/wot/IdentityManager.java +++ b/src/main/java/net/pterodactylus/wotns/freenet/wot/IdentityManager.java @@ -17,6 +17,7 @@ package net.pterodactylus.wotns.freenet.wot; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -26,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; @@ -67,7 +66,7 @@ public class IdentityManager extends AbstractService { private Map currentOwnIdentities = new HashMap(); /** The currently trusted identities. */ - private Map> currentTrustedIdentities = new HashMap>(); + private Map> currentTrustedIdentities = new HashMap>(); /** * Creates a new identity manager. @@ -172,15 +171,31 @@ 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(); + Set identities = new HashSet(); if ((context == null) || ownIdentity.getContexts().contains(context)) { identities.add(ownIdentity); } - 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); + } catch (WebOfTrustException wote1) { + logger.log(Level.WARNING, String.format("Could not load all trusted identities for %s.", ownIdentity), wote1); } - return identities.get(); + return identities; } // @@ -192,7 +207,6 @@ public class IdentityManager extends AbstractService { */ @Override protected void serviceRun() { - Map> oldIdentities = Collections.emptyMap(); while (!shouldStop()) { Map> currentIdentities = new HashMap>(); @SuppressWarnings("hiding") @@ -218,7 +232,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; @@ -241,75 +258,7 @@ public class IdentityManager extends AbstractService { /* now check for changes in remote identities. */ for (OwnIdentity ownIdentity : currentOwnIdentities.values()) { - - /* find new identities. */ - for (Identity currentIdentity : currentIdentities.get(ownIdentity).values()) { - if (!oldIdentities.containsKey(ownIdentity) || !oldIdentities.get(ownIdentity).containsKey(currentIdentity.getId())) { - identityListenerManager.fireIdentityAdded(ownIdentity, currentIdentity); - } - } - - /* find removed identities. */ - if (oldIdentities.containsKey(ownIdentity)) { - for (Identity oldIdentity : oldIdentities.get(ownIdentity).values()) { - if (!currentIdentities.get(ownIdentity).containsKey(oldIdentity.getId())) { - identityListenerManager.fireIdentityRemoved(ownIdentity, oldIdentity); - } - } - - /* check for changes in the contexts. */ - for (Identity oldIdentity : oldIdentities.get(ownIdentity).values()) { - if (!currentIdentities.get(ownIdentity).containsKey(oldIdentity.getId())) { - continue; - } - Identity newIdentity = currentIdentities.get(ownIdentity).get(oldIdentity.getId()); - Set oldContexts = oldIdentity.getContexts(); - Set newContexts = newIdentity.getContexts(); - if (oldContexts.size() != newContexts.size()) { - identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity); - continue; - } - for (String oldContext : oldContexts) { - if (!newContexts.contains(oldContext)) { - identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity); - break; - } - } - } - - /* check for changes in the properties. */ - for (Identity oldIdentity : oldIdentities.get(ownIdentity).values()) { - if (!currentIdentities.get(ownIdentity).containsKey(oldIdentity.getId())) { - continue; - } - Identity newIdentity = currentIdentities.get(ownIdentity).get(oldIdentity.getId()); - Map oldProperties = oldIdentity.getProperties(); - Map newProperties = newIdentity.getProperties(); - if (oldProperties.size() != newProperties.size()) { - identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity); - continue; - } - for (Entry oldProperty : oldProperties.entrySet()) { - if (!newProperties.containsKey(oldProperty.getKey()) || !newProperties.get(oldProperty.getKey()).equals(oldProperty.getValue())) { - identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity); - break; - } - } - } - } - } - - /* remember the current set of identities. */ - oldIdentities = currentIdentities; - synchronized (syncObject) { - currentTrustedIdentities.clear(); - for (Entry> entry : currentIdentities.entrySet()) { - Set identities = new HashSet(); - currentTrustedIdentities.put(entry.getKey(), identities); - for (Identity identity : entry.getValue().values()) { - identities.add(identity); - } - } + checkTrustedIdentities(ownIdentity, currentIdentities.get(ownIdentity)); } } @@ -336,6 +285,7 @@ public class IdentityManager extends AbstractService { for (OwnIdentity oldOwnIdentity : currentOwnIdentities.values()) { if (!newOwnIdentities.containsKey(oldOwnIdentity.getId())) { identityListenerManager.fireOwnIdentityRemoved(oldOwnIdentity); + currentTrustedIdentities.remove(oldOwnIdentity); } } @@ -351,4 +301,81 @@ public class IdentityManager extends AbstractService { } } + /** + * Checks the given identities for changes since the last check. + * + * @param ownIdentity + * The own identity trusting the given identities + * @param trustedIdentities + * The trusted identities + */ + private void checkTrustedIdentities(OwnIdentity ownIdentity, Map trustedIdentities) { + + @SuppressWarnings("hiding") + Map currentTrustedIdentities = new HashMap(); + synchronized (syncObject) { + if (this.currentTrustedIdentities.containsKey(ownIdentity)) { + for (Identity identity : this.currentTrustedIdentities.get(ownIdentity)) { + currentTrustedIdentities.put(identity.getId(), identity); + } + } + } + + /* find new identities. */ + for (Identity currentIdentity : trustedIdentities.values()) { + if (!currentTrustedIdentities.containsKey(currentIdentity.getId())) { + identityListenerManager.fireIdentityAdded(ownIdentity, currentIdentity); + } + } + + /* find removed identities. */ + for (Identity oldIdentity : currentTrustedIdentities.values()) { + if (!trustedIdentities.containsKey(oldIdentity.getId())) { + identityListenerManager.fireIdentityRemoved(ownIdentity, oldIdentity); + } + } + + /* check for changes in the contexts. */ + for (Identity oldIdentity : currentTrustedIdentities.values()) { + if (!trustedIdentities.containsKey(oldIdentity.getId())) { + continue; + } + Identity newIdentity = trustedIdentities.get(oldIdentity.getId()); + Set oldContexts = oldIdentity.getContexts(); + Set newContexts = newIdentity.getContexts(); + if (oldContexts.size() != newContexts.size()) { + identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity); + continue; + } + boolean changed = false; + for (String oldContext : oldContexts) { + if (!newContexts.contains(oldContext)) { + identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity); + changed = true; + break; + } + } + if (changed) { + continue; + } + Map oldProperties = oldIdentity.getProperties(); + Map newProperties = newIdentity.getProperties(); + if (oldProperties.size() != newProperties.size()) { + identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity); + continue; + } + for (Entry oldProperty : oldProperties.entrySet()) { + if (!newProperties.containsKey(oldProperty.getKey()) || !newProperties.get(oldProperty.getKey()).equals(oldProperty.getValue())) { + identityListenerManager.fireIdentityUpdated(ownIdentity, newIdentity); + break; + } + } + } + + synchronized (syncObject) { + this.currentTrustedIdentities.put(ownIdentity, trustedIdentities.values()); + } + + } + } diff --git a/src/main/java/net/pterodactylus/wotns/freenet/wot/WebOfTrustConnector.java b/src/main/java/net/pterodactylus/wotns/freenet/wot/WebOfTrustConnector.java index 8a16efc..f56f739 100644 --- a/src/main/java/net/pterodactylus/wotns/freenet/wot/WebOfTrustConnector.java +++ b/src/main/java/net/pterodactylus/wotns/freenet/wot/WebOfTrustConnector.java @@ -70,6 +70,10 @@ public class WebOfTrustConnector implements ConnectorListener { // ACTIONS // + /** + * Stops the web of trust connector and disconnects from the plugin + * connector. + */ public void stop() { pluginConnector.removeConnectorListener(WOT_PLUGIN_NAME, PLUGIN_CONNECTION_IDENTIFIER, this); } @@ -110,10 +114,10 @@ public class WebOfTrustConnector implements ConnectorListener { * @param ownIdentity * The own identity * @return All trusted identities - * @throws PluginException + * @throws WebOfTrustException * if an error occured talking to the Web of Trust plugin */ - public Set loadTrustedIdentities(OwnIdentity ownIdentity) throws PluginException { + public Set loadTrustedIdentities(OwnIdentity ownIdentity) throws WebOfTrustException { return loadTrustedIdentities(ownIdentity, null); } @@ -126,10 +130,10 @@ public class WebOfTrustConnector implements ConnectorListener { * @param context * The context to filter, or {@code null} * @return All trusted identities - * @throws PluginException + * @throws WebOfTrustException * if an error occured talking to the Web of Trust plugin */ - public Set loadTrustedIdentities(OwnIdentity ownIdentity, String context) throws PluginException { + public Set loadTrustedIdentities(OwnIdentity ownIdentity, String context) throws WebOfTrustException { @SuppressWarnings("hiding") Reply reply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetIdentitiesByScore").put("TreeOwner", ownIdentity.getId()).put("Selection", "+").put("Context", (context == null) ? "" : context).get()); SimpleFieldSet fields = reply.getFields(); diff --git a/src/main/java/net/pterodactylus/wotns/main/IdentityComparator.java b/src/main/java/net/pterodactylus/wotns/main/IdentityComparator.java index ca540a7..c903a23 100644 --- a/src/main/java/net/pterodactylus/wotns/main/IdentityComparator.java +++ b/src/main/java/net/pterodactylus/wotns/main/IdentityComparator.java @@ -37,7 +37,7 @@ public class IdentityComparator { */ @Override public int compare(Identity leftIdentity, Identity rightIdentity) { - return leftIdentity.getNickname().compareTo(rightIdentity.getNickname()); + return leftIdentity.getNickname().compareToIgnoreCase(rightIdentity.getNickname()); } } diff --git a/src/main/java/net/pterodactylus/wotns/main/WoTNSPlugin.java b/src/main/java/net/pterodactylus/wotns/main/WoTNSPlugin.java index f08239e..f24afc7 100644 --- a/src/main/java/net/pterodactylus/wotns/main/WoTNSPlugin.java +++ b/src/main/java/net/pterodactylus/wotns/main/WoTNSPlugin.java @@ -46,7 +46,7 @@ public class WoTNSPlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL1 Logging.setupConsoleLogging(); } - private static final Version VERSION = new Version(0, 0, 2); + private static final Version VERSION = new Version(0, 0, 3); private PluginRespirator pluginRespirator; diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 6ed3fee..94b0623 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -1,6 +1,6 @@ <%include include/head.html>

WoTNS

-

The Web of Trust Service uses properties of Web of Trust identities to implement a DNS-like scheme on top of Freenet.

+

The Web of Trust Name Service uses properties of Web of Trust identities to implement a DNS-like scheme on top of Freenet.

The general syntax is: http://<%request.host>/tns/identity/target.

identity is the nickname of a Web of Trust identity, such as “WoTNS”. It is also possible to include the beginning of the identity’s key into identity, in the form of nickname@start-of-key, such as “WoTNS@DAx”.

@@ -9,7 +9,7 @@ has to fulfill the Web of Trust’s requirement for a valid property name.

To be able to add targets for one of your identities, you first have to create an identity using the Web of Trust, and you have to enable the identity here.

-<%foreach enabledIdentities identity> +<%foreach enabledIdentities identity|sort> <%first>

Enabled Identities

<%/first> @@ -21,7 +21,7 @@ and you have to enable the identity here.

<%/foreach> -<%foreach disabledIdentities identity> +<%foreach disabledIdentities identity|sort> <%first>

Disabled Identities

<%/first>