X-Git-Url: https://git.pterodactylus.net/?p=WoTNS.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fwotns%2Fmain%2FResolver.java;h=66032d94bce7b8ff062cb35850b20aa6376a8050;hp=0d94ce22fa07831be5fdcdc6d58a9df0bb92b61c;hb=19cb82fef226e1d2aee9e761df4b4d3a9539718e;hpb=6328a49176de53708653299833bc4739dd9caacf diff --git a/src/main/java/net/pterodactylus/wotns/main/Resolver.java b/src/main/java/net/pterodactylus/wotns/main/Resolver.java index 0d94ce2..66032d9 100644 --- a/src/main/java/net/pterodactylus/wotns/main/Resolver.java +++ b/src/main/java/net/pterodactylus/wotns/main/Resolver.java @@ -23,7 +23,10 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.object.Default; import net.pterodactylus.wotns.freenet.wot.Identity; import net.pterodactylus.wotns.freenet.wot.IdentityManager; @@ -32,24 +35,61 @@ import net.pterodactylus.wotns.freenet.wot.Trust; import freenet.keys.FreenetURI; /** - * TODO + * Resolves short names as given by the user. + *
+ * Short names generally have the syntax: + * + *
+ * identity [ â@â start-of-key ] â/â target [ â/â file-path ] + *+ *
+ * Because resolving a short name is based on the web of trust, the ID of
+ * an own identity must be given in order to find the entry point into the web
+ * of trust. If no ID is specified, the ID of a random own identity is used. If
+ * no own identity exists, short names can not be resolved.
*
* @author David âBombeâ Roden
*/
public class Resolver {
+ /** The logger. */
+ private static final Logger logger = Logging.getLogger(Resolver.class);
+
+ /** The identity manager. */
private final IdentityManager identityManager;
+ /** The ID of the own identity to use for resolving. */
private String ownIdentityId;
+ /**
+ * Creates a new resolver.
+ *
+ * @param identityManager
+ * The identity manager to use
+ */
public Resolver(IdentityManager identityManager) {
this.identityManager = identityManager;
}
+ //
+ // ACCESSORS
+ //
+
+ /**
+ * Returns the ID of the own identity used for resolving short names.
+ *
+ * @return The ID of the own identity used for resolving
+ */
public String getOwnIdentityId() {
return ownIdentityId;
}
+ /**
+ * Sets the ID of the own identity used for resolving short names.
+ *
+ * @param ownIdentityId
+ * The ID of the own identity used for resolving
+ */
public void setOwnIdentityId(String ownIdentityId) {
this.ownIdentityId = ownIdentityId;
}
@@ -58,6 +98,16 @@ public class Resolver {
// ACTIONS
//
+ /**
+ * Resolves a short name.
+ *
+ * @param shortUri
+ * The short name to resolve
+ * @return The Freenet URI the short name resolves to, or {@code null} if
+ * the short name can not be resolved
+ * @throws MalformedURLException
+ * if the short name is malformed
+ */
public FreenetURI resolveURI(String shortUri) throws MalformedURLException {
int firstSlash = shortUri.indexOf('/');
if (firstSlash == -1) {
@@ -77,6 +127,18 @@ public class Resolver {
// PRIVATE METHODS
//
+ /**
+ * Locates the identity specified by the given short name. If more than one
+ * identity matches the given pattern, the one with the highest trust is
+ * used. When calculating the trust, local and remote trust are treated
+ * equally, i.e. the higher value of either one is used.
+ *
+ * @param shortName
+ * The short name to locate an identity for
+ * @return The located identity, or {@code null} if no identity can be
+ * found, or if no own identity is found to use for locating an
+ * identity
+ */
private Identity locateIdentity(String shortName) {
int atSign = shortName.indexOf('@');
String identityName = shortName;
@@ -85,21 +147,18 @@ public class Resolver {
identityName = shortName.substring(0, atSign);
keyStart = shortName.substring(atSign + 1);
}
- @SuppressWarnings("hiding")
final OwnIdentity ownIdentity;
- if ((this.ownIdentityId != null) && (identityManager.getOwnIdentity(this.ownIdentityId) != null)) {
- ownIdentity = identityManager.getOwnIdentity(this.ownIdentityId);
- } else if (this.ownIdentityId == null) {
- Set