X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FFreenetInterface.java;h=b3895877b564678fcd548869e6516beea36b75e1;hb=f67d0cbb1bc328c0072fe5f795ffb31cf1b987bb;hp=abac50804f74e5e82e0fbd6e44f2a3625b43ac28;hpb=3112dbc82b31381b0fa65fda1ee46b22e2172aa5;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index abac508..b389587 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -35,8 +35,11 @@ import net.pterodactylus.sone.data.TemporaryImage; import net.pterodactylus.util.logging.Logging; import com.db4o.ObjectContainer; + +import com.google.common.base.Function; import com.google.common.eventbus.EventBus; import com.google.inject.Inject; +import com.google.inject.Singleton; import freenet.client.ClientMetadata; import freenet.client.FetchException; @@ -64,6 +67,7 @@ import freenet.support.io.ArrayBucket; * * @author David ‘Bombe’ Roden */ +@Singleton public class FreenetInterface { /** The logger. */ @@ -178,16 +182,7 @@ public class FreenetInterface { } } - /** - * Registers the USK for the given Sone and notifies the given - * {@link SoneDownloader} if an update was found. - * - * @param sone - * The Sone to watch - * @param soneDownloader - * The Sone download to notify on updates - */ - public void registerUsk(final Sone sone, final SoneDownloader soneDownloader) { + public void registerUsk(final Sone sone, final SoneUpdater soneUpdater) { try { logger.log(Level.FINE, String.format("Registering Sone “%s” for USK updates at %s…", sone, sone.getRequestUri().setMetaString(new String[] { "sone.xml" }))); USKCallback uskCallback = new USKCallback() { @@ -196,16 +191,7 @@ public class FreenetInterface { @SuppressWarnings("synthetic-access") public void onFoundEdition(long edition, USK key, ObjectContainer objectContainer, ClientContext clientContext, boolean metadata, short codec, byte[] data, boolean newKnownGood, boolean newSlotToo) { logger.log(Level.FINE, String.format("Found USK update for Sone “%s” at %s, new known good: %s, new slot too: %s.", sone, key, newKnownGood, newSlotToo)); - if (edition > sone.getLatestEdition()) { - sone.setLatestEdition(edition); - new Thread(new Runnable() { - - @Override - public void run() { - soneDownloader.fetchSone(sone); - } - }, "Sone Downloader").start(); - } + soneUpdater.updateSone(edition); } @Override @@ -494,4 +480,13 @@ public class FreenetInterface { } + public class InsertTokenSupplier implements Function { + + @Override + public InsertToken apply(Image image) { + return new InsertToken(image); + } + + } + }