X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Fwot%2FDefaultIdentity.java;h=f200022b78b4f11895cb7e36e509230a1a90fa24;hb=b95f0d80fa0ac4f9f6f8b51b2fecf796a1f72801;hp=288a99ef066b7c9d19e691cc17289f888558d353;hpb=6ab999d8120ca28c4a1cb7370ae9e8ac61504556;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java b/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java index 288a99e..f200022 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/DefaultIdentity.java @@ -1,5 +1,5 @@ /* - * Sone - DefaultIdentity.java - Copyright © 2010 David Roden + * Sone - DefaultIdentity.java - Copyright © 2010–2012 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 @@ -22,6 +22,9 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.logging.Logger; + +import net.pterodactylus.util.logging.Logging; /** * A Web of Trust identity. @@ -30,6 +33,12 @@ import java.util.Set; */ public class DefaultIdentity implements Identity { + /** The logger. */ + private static final Logger logger = Logging.getLogger(DefaultIdentity.class); + + /** The web of trust connector. */ + private final WebOfTrustConnector webOfTrustConnector; + /** The ID of the identity. */ private final String id; @@ -45,9 +54,15 @@ public class DefaultIdentity implements Identity { /** The properties of the identity. */ private final Map properties = Collections.synchronizedMap(new HashMap()); + /** Cached trust. */ + /* synchronize on itself. */ + private final Map trustCache = new HashMap(); + /** * Creates a new identity. * + * @param webOfTrustConnector + * The web of trust connector * @param id * The ID of the identity * @param nickname @@ -55,7 +70,8 @@ public class DefaultIdentity implements Identity { * @param requestUri * The request URI of the identity */ - public DefaultIdentity(String id, String nickname, String requestUri) { + public DefaultIdentity(WebOfTrustConnector webOfTrustConnector, String id, String nickname, String requestUri) { + this.webOfTrustConnector = webOfTrustConnector; this.id = id; this.nickname = nickname; this.requestUri = requestUri; @@ -207,6 +223,30 @@ public class DefaultIdentity implements Identity { } } + /** + * {@inheritDoc} + */ + @Override + public Trust getTrust(OwnIdentity ownIdentity) { + synchronized (trustCache) { + return trustCache.get(ownIdentity); + } + } + + /** + * Sets the trust received for this identity by the given own identity. + * + * @param ownIdentity + * The own identity that gives the trust + * @param trust + * The trust received for this identity + */ + public void setTrust(OwnIdentity ownIdentity, Trust trust) { + synchronized (trustCache) { + trustCache.put(ownIdentity, trust); + } + } + // // OBJECT METHODS //