X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=053e04280b21a4a63039203a519a3b1a743a0603;hb=1f70b96444f309fbbf338d474af395ff615d244b;hp=fc3d99cf564dbdb57196562d7d4f3049032cff7f;hpb=921c8049c4bbfcc59c7bab75d925e18b2311ebdc;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index fc3d99c..053e042 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -47,6 +47,7 @@ import net.pterodactylus.util.config.Configuration; import net.pterodactylus.util.config.ConfigurationException; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.number.Numbers; +import net.pterodactylus.util.validation.Validation; import freenet.keys.FreenetURI; /** @@ -898,8 +899,10 @@ public class Core implements IdentityListener { } /** - * Retrieves the trust relationship from the origin to the target. + * Retrieves the trust relationship from the origin to the target. If the + * trust relationship can not be retrieved, {@code null} is returned. * + * @see Identity#getTrust(OwnIdentity) * @param origin * The origin of the trust tree * @param target @@ -911,15 +914,82 @@ public class Core implements IdentityListener { logger.log(Level.WARNING, "Tried to get trust from remote Sone: %s", origin); return null; } + return target.getIdentity().getTrust((OwnIdentity) origin.getIdentity()); + } + + /** + * Sets the trust value of the given origin Sone for the target Sone. + * + * @param origin + * The origin Sone + * @param target + * The target Sone + * @param trustValue + * The trust value (from {@code -100} to {@code 100}) + */ + public void setTrust(Sone origin, Sone target, int trustValue) { + Validation.begin().isNotNull("Trust Origin", origin).check().isInstanceOf("Trust Origin", origin.getIdentity(), OwnIdentity.class).isNotNull("Trust Target", target).isLessOrEqual("Trust Value", trustValue, 100).isGreaterOrEqual("Trust Value", trustValue, -100).check(); try { - return target.getIdentity().getTrust((OwnIdentity) origin.getIdentity()); + ((OwnIdentity) origin.getIdentity()).setTrust(target.getIdentity(), trustValue, "Set from Sone Web Interface"); } catch (WebOfTrustException wote1) { - logger.log(Level.WARNING, "Could not get trust for Sone: " + target, wote1); - return null; + logger.log(Level.WARNING, "Could not set trust for Sone: " + target, wote1); } } /** + * Removes any trust assignment for the given target Sone. + * + * @param origin + * The trust origin + * @param target + * The trust target + */ + public void removeTrust(Sone origin, Sone target) { + Validation.begin().isNotNull("Trust Origin", origin).isNotNull("Trust Target", target).check().isInstanceOf("Trust Origin Identity", origin.getIdentity(), OwnIdentity.class).check(); + try { + ((OwnIdentity) origin.getIdentity()).removeTrust(target.getIdentity()); + } catch (WebOfTrustException wote1) { + logger.log(Level.WARNING, "Could not remove trust for Sone: " + target, wote1); + } + } + + /** + * Assigns the configured positive trust value for the given target. + * + * @param origin + * The trust origin + * @param target + * The trust target + */ + public void trustSone(Sone origin, Sone target) { + setTrust(origin, target, options.getIntegerOption("PositiveTrust").get()); + } + + /** + * Assigns the configured negative trust value for the given target. + * + * @param origin + * The trust origin + * @param target + * The trust target + */ + public void distrustSone(Sone origin, Sone target) { + setTrust(origin, target, options.getIntegerOption("NegativeTrust").get()); + } + + /** + * Removes the trust assignment for the given target. + * + * @param origin + * The trust origin + * @param target + * The trust target + */ + public void untrustSone(Sone origin, Sone target) { + removeTrust(origin, target); + } + + /** * Updates the stores Sone with the given Sone. * * @param sone @@ -1669,6 +1739,7 @@ public class Core implements IdentityListener { @SuppressWarnings("synthetic-access") public void run() { Sone sone = getRemoteSone(identity.getId()); + sone.setIdentity(identity); soneDownloader.fetchSone(sone); } }).start();