From: David ‘Bombe’ Roden Date: Mon, 13 Dec 2010 21:00:14 +0000 (+0100) Subject: Keep track of which own identities trusts which identities. X-Git-Tag: 0.4^2~8^2~58 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=91724f5f8bd2a4e5425835b7d926ae947adb5fbd;p=Sone.git Keep track of which own identities trusts which identities. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index f1a8d3e..9263063 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -145,6 +145,9 @@ public class Core implements IdentityListener { /** All known replies. */ private Set knownReplies = new HashSet(); + /** Trusted identities, sorted by own identities. */ + private Map> trustedIdentities = Collections.synchronizedMap(new HashMap>()); + /** * Creates a new core. * @@ -501,6 +504,19 @@ public class Core implements IdentityListener { } /** + * Returns whether the target Sone is trusted by the origin Sone. + * + * @param origin + * The origin Sone + * @param target + * The target Sone + * @return {@code true} if the target Sone is trusted by the origin Sone + */ + public boolean isSoneTrusted(Sone origin, Sone target) { + return trustedIdentities.containsKey(origin) && trustedIdentities.get(origin.getIdentity()).contains(target); + } + + /** * Returns the post with the given ID. * * @param postId @@ -1566,6 +1582,7 @@ public class Core implements IdentityListener { public void ownIdentityAdded(OwnIdentity ownIdentity) { logger.log(Level.FINEST, "Adding OwnIdentity: " + ownIdentity); if (ownIdentity.hasContext("Sone")) { + trustedIdentities.put(ownIdentity, Collections.synchronizedSet(new HashSet())); addLocalSone(ownIdentity); } } @@ -1576,6 +1593,7 @@ public class Core implements IdentityListener { @Override public void ownIdentityRemoved(OwnIdentity ownIdentity) { logger.log(Level.FINEST, "Removing OwnIdentity: " + ownIdentity); + trustedIdentities.remove(ownIdentity); } /** @@ -1584,6 +1602,7 @@ public class Core implements IdentityListener { @Override public void identityAdded(OwnIdentity ownIdentity, Identity identity) { logger.log(Level.FINEST, "Adding Identity: " + identity); + trustedIdentities.get(ownIdentity).add(identity); addRemoteSone(identity); } @@ -1608,7 +1627,7 @@ public class Core implements IdentityListener { */ @Override public void identityRemoved(OwnIdentity ownIdentity, Identity identity) { - /* TODO */ + trustedIdentities.get(ownIdentity).remove(identity); } }