X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FFreenetInterface.java;h=6737d634a922b43decf0e9d300453eb2b99a894a;hb=920370701919c6cc8b9194af5d1c2c7d6dd8601b;hp=2c98a7e940904878ed8781f16626bc1faaaf06be;hpb=b2f452ea2e5fdc2771e8f16139eb599b91ab9a38;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 2c98a7e..6737d63 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -24,8 +24,8 @@ import java.util.logging.Level; import java.util.logging.Logger; import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.util.collection.Pair; import net.pterodactylus.util.logging.Logging; -import net.pterodactylus.util.service.AbstractService; import com.db4o.ObjectContainer; @@ -46,7 +46,7 @@ import freenet.node.RequestStarter; * * @author David ‘Bombe’ Roden */ -public class FreenetInterface extends AbstractService { +public class FreenetInterface { /** The logger. */ private static final Logger logger = Logging.getLogger(FreenetInterface.class); @@ -65,13 +65,10 @@ public class FreenetInterface extends AbstractService { * * @param node * The node to interact with - * @param client - * The high-level client */ - public FreenetInterface(Node node, HighLevelSimpleClient client) { - super("Sone Freenet Interface"); + public FreenetInterface(Node node) { this.node = node; - this.client = client; + this.client = node.clientCore.makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS, false, true); } // @@ -85,13 +82,13 @@ public class FreenetInterface extends AbstractService { * The URI to fetch * @return The result of the fetch, or {@code null} if an error occured */ - public FetchResult fetchUri(FreenetURI uri) { + public Pair fetchUri(FreenetURI uri) { FetchResult fetchResult = null; FreenetURI currentUri = new FreenetURI(uri); while (true) { try { fetchResult = client.fetch(currentUri); - return fetchResult; + return new Pair(currentUri, fetchResult); } catch (FetchException fe1) { if (fe1.getMode() == FetchException.PERMANENT_REDIRECT) { currentUri = fe1.newURI; @@ -153,8 +150,14 @@ public class FreenetInterface extends AbstractService { 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, "Found USK update for Sone “%s” at %s, new known good: %s, new slot too: %s.", new Object[] { sone, key, newKnownGood, newSlotToo }); if (newKnownGood) { - sone.updateUris(key.getURI()); - soneDownloader.fetchSone(sone); + sone.setLatestEdition(key.suggestedEdition); + new Thread(new Runnable() { + + @Override + public void run() { + soneDownloader.fetchSone(sone); + } + }, "Sone Downloader").start(); } }