X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=e3fdd1975a06022cfaba1a4556d0740f736bb046;hp=9a40e5c4242ab5e57a69caa58570b0c5fa9bbf18;hb=864f0802a2ae1cfaf4f94b3c29292aec31be1081;hpb=efb1006429e52a74f41fb6e1d7736736156bb13a diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 9a40e5c..e3fdd19 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -54,7 +54,6 @@ import net.pterodactylus.sone.freenet.wot.IdentityListener; import net.pterodactylus.sone.freenet.wot.IdentityManager; import net.pterodactylus.sone.freenet.wot.OwnIdentity; import net.pterodactylus.sone.freenet.wot.Trust; -import net.pterodactylus.sone.freenet.wot.WebOfTrustException; import net.pterodactylus.sone.main.SonePlugin; import net.pterodactylus.util.config.Configuration; import net.pterodactylus.util.config.ConfigurationException; @@ -113,7 +112,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis private final UpdateChecker updateChecker; /** The trust updater. */ - private final TrustUpdater trustUpdater; + private final WebOfTrustUpdater webOfTrustUpdater; /** The FCP interface. */ private volatile FcpInterface fcpInterface; @@ -187,8 +186,10 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * The freenet interface * @param identityManager * The identity manager + * @param webOfTrustUpdater + * The WebOfTrust updater */ - public Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, TrustUpdater trustUpdater) { + public Core(Configuration configuration, FreenetInterface freenetInterface, IdentityManager identityManager, WebOfTrustUpdater webOfTrustUpdater) { super("Sone Core"); this.configuration = configuration; this.freenetInterface = freenetInterface; @@ -196,7 +197,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis this.soneDownloader = new SoneDownloader(this, freenetInterface); this.imageInserter = new ImageInserter(this, freenetInterface); this.updateChecker = new UpdateChecker(freenetInterface); - this.trustUpdater = trustUpdater; + this.webOfTrustUpdater = webOfTrustUpdater; } // @@ -889,10 +890,8 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis * @return The created Sone */ public Sone createSone(OwnIdentity ownIdentity) { - try { - ownIdentity.addContext("Sone"); - } catch (WebOfTrustException wote1) { - logger.log(Level.SEVERE, String.format("Could not add “Sone” context to own identity: %s", ownIdentity), wote1); + if (!webOfTrustUpdater.addContextWait(ownIdentity, "Sone")) { + logger.log(Level.SEVERE, String.format("Could not add “Sone” context to own identity: %s", ownIdentity)); return null; } Sone sone = addLocalSone(ownIdentity); @@ -1058,7 +1057,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis logger.log(Level.WARNING, String.format("Tried to get trust from remote Sone: %s", origin)); return null; } - trustUpdater.getTrust((OwnIdentity) origin.getIdentity(), target.getIdentity()); + webOfTrustUpdater.getTrust((OwnIdentity) origin.getIdentity(), target.getIdentity()); return target.getIdentity().getTrust((OwnIdentity) origin.getIdentity()); } @@ -1074,7 +1073,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis */ 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(); - trustUpdater.setTrust((OwnIdentity) origin.getIdentity(), target.getIdentity(), trustValue, preferences.getTrustComment()); + webOfTrustUpdater.setTrust((OwnIdentity) origin.getIdentity(), target.getIdentity(), trustValue, preferences.getTrustComment()); } /** @@ -1087,7 +1086,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis */ 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(); - trustUpdater.setTrust((OwnIdentity) origin.getIdentity(), target.getIdentity(), null, null); + webOfTrustUpdater.setTrust((OwnIdentity) origin.getIdentity(), target.getIdentity(), null, null); } /** @@ -1277,12 +1276,8 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis soneInserter.removeSoneInsertListener(this); soneInserter.stop(); } - try { - ((OwnIdentity) sone.getIdentity()).removeContext("Sone"); - ((OwnIdentity) sone.getIdentity()).removeProperty("Sone.LatestEdition"); - } catch (WebOfTrustException wote1) { - logger.log(Level.WARNING, String.format("Could not remove context and properties from Sone: %s", sone), wote1); - } + webOfTrustUpdater.removeContext((OwnIdentity) sone.getIdentity(), "Sone"); + webOfTrustUpdater.removeProperty((OwnIdentity) sone.getIdentity(), "Sone.LatestEdition"); try { configuration.getLongValue("Sone/" + sone.getId() + "/Time").setValue(null); } catch (ConfigurationException ce1) { @@ -1854,7 +1849,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis synchronized (albums) { albums.remove(album.getId()); } - saveSone(album.getSone()); + touchConfiguration(); } /** @@ -1894,7 +1889,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis synchronized (images) { images.remove(image.getId()); } - saveSone(image.getSone()); + touchConfiguration(); } /** @@ -1964,7 +1959,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis loadConfiguration(); updateChecker.addUpdateListener(this); updateChecker.start(); - trustUpdater.start(); + webOfTrustUpdater.start(); } /** @@ -1997,7 +1992,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis soneInserter.stop(); } } - trustUpdater.stop(); + webOfTrustUpdater.stop(); updateChecker.stop(); updateChecker.removeUpdateListener(this); soneDownloader.stop(); @@ -2137,13 +2132,11 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis configuration.save(); - ((OwnIdentity) sone.getIdentity()).setProperty("Sone.LatestEdition", String.valueOf(sone.getLatestEdition())); + webOfTrustUpdater.setProperty((OwnIdentity) sone.getIdentity(), "Sone.LatestEdition", String.valueOf(sone.getLatestEdition())); logger.log(Level.INFO, String.format("Sone %s saved.", sone)); } catch (ConfigurationException ce1) { logger.log(Level.WARNING, String.format("Could not save Sone: %s", sone), ce1); - } catch (WebOfTrustException wote1) { - logger.log(Level.WARNING, String.format("Could not set WoT property for Sone: %s", sone), wote1); } } @@ -2381,7 +2374,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis FreenetURI uri = new FreenetURI(uriString).setDocName("Sone").setMetaString(new String[0]); return uri; } catch (MalformedURLException mue1) { - logger.log(Level.WARNING, String.format("Could not create Sone URI from URI: %s", uriString, mue1)); + logger.log(Level.WARNING, String.format("Could not create Sone URI from URI: %s", uriString), mue1); return null; } } @@ -2556,7 +2549,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis logger.log(Level.WARNING, String.format("Image insert finished for %s: %s", image, key)); image.setKey(key.toString()); deleteTemporaryImage(image.getId()); - saveSone(image.getSone()); + touchConfiguration(); coreListenerManager.fireImageInsertFinished(image); }