X-Git-Url: https://git.pterodactylus.net/?p=WoTNS.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fwotns%2Fmain%2FResolver.java;h=4e535284b7b00f20c0b4e84cddb1b620eddc519f;hp=4dacad9458cf1dfd39db5ef01e03480fdc8129a2;hb=4e1244ef54d89818d48af3b1070d799c89734f15;hpb=622c4a4d3ebed447d5708a41cf3e1e82e18fa29b diff --git a/src/main/java/net/pterodactylus/wotns/main/Resolver.java b/src/main/java/net/pterodactylus/wotns/main/Resolver.java index 4dacad9..4e53528 100644 --- a/src/main/java/net/pterodactylus/wotns/main/Resolver.java +++ b/src/main/java/net/pterodactylus/wotns/main/Resolver.java @@ -23,8 +23,11 @@ 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.collection.Default; +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; import net.pterodactylus.wotns.freenet.wot.OwnIdentity; @@ -38,16 +41,22 @@ import freenet.keys.FreenetURI; */ public class Resolver { + private static final Logger logger = Logging.getLogger(Resolver.class); + private final IdentityManager identityManager; - private OwnIdentity ownIdentity; + private String ownIdentityId; public Resolver(IdentityManager identityManager) { this.identityManager = identityManager; } - public void setOwnIdentity(OwnIdentity ownIdentity) { - this.ownIdentity = ownIdentity; + public String getOwnIdentityId() { + return ownIdentityId; + } + + public void setOwnIdentityId(String ownIdentityId) { + this.ownIdentityId = ownIdentityId; } // @@ -81,9 +90,10 @@ public class Resolver { identityName = shortName.substring(0, atSign); keyStart = shortName.substring(atSign + 1); } - @SuppressWarnings("hiding") final OwnIdentity ownIdentity; - if (this.ownIdentity == null) { + if ((this.ownIdentityId != null) && (identityManager.getOwnIdentity(this.ownIdentityId) != null)) { + ownIdentity = identityManager.getOwnIdentity(this.ownIdentityId); + } else if (this.ownIdentityId == null) { Set ownIdentities = identityManager.getAllOwnIdentities(); if (!ownIdentities.isEmpty()) { ownIdentity = ownIdentities.iterator().next(); @@ -91,13 +101,14 @@ public class Resolver { ownIdentity = null; } } else { - ownIdentity = this.ownIdentity; + logger.log(Level.SEVERE, "Can not resolve “" + shortName + "” without a Web of Trust Identity!"); + ownIdentity = null; } if (ownIdentity == null) { return null; } System.out.println("using own identity " + ownIdentity + " to resolve " + shortName); - Set trustedIdentities = Default.forNull(identityManager.getTrustedIdentities(ownIdentity), Collections.emptySet()); + Set trustedIdentities = Default.forNull(identityManager.getTrustedIdentities(ownIdentity), Collections. emptySet()); List matchingIdentities = new ArrayList(); System.out.println("checking " + trustedIdentities); for (Identity identity : trustedIdentities) { @@ -122,4 +133,12 @@ public class Resolver { return matchingIdentities.get(0); } + private OwnIdentity getFirstOwnIdentity() { + Set ownIdentities = identityManager.getAllOwnIdentities(); + if (!ownIdentities.isEmpty()) { + return ownIdentities.iterator().next(); + } + return null; + } + }