X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FFreenetInterface.java;h=5dd8fbfacd087b006649263c6c841557257cfa55;hb=3568c3e220993291936f182ee1845bd795b8f513;hp=e92cf8e078aad5e9d0b2b4d2cee85c414529f23a;hpb=6e9a43ccd93ae125720547c0fe421dc81a54ba90;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 e92cf8e..5dd8fbf 100644
--- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java
+++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java
@@ -35,14 +35,16 @@ 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;
import freenet.client.FetchResult;
import freenet.client.HighLevelSimpleClient;
-import freenet.client.HighLevelSimpleClientImpl;
import freenet.client.InsertBlock;
import freenet.client.InsertContext;
import freenet.client.InsertException;
@@ -55,6 +57,7 @@ import freenet.keys.FreenetURI;
import freenet.keys.InsertableClientSSK;
import freenet.keys.USK;
import freenet.node.Node;
+import freenet.node.RequestClient;
import freenet.node.RequestStarter;
import freenet.support.api.Bucket;
import freenet.support.io.ArrayBucket;
@@ -64,6 +67,7 @@ import freenet.support.io.ArrayBucket;
*
* @author David âBombeâ Roden
*/
+@Singleton
public class FreenetInterface {
/** The logger. */
@@ -111,11 +115,10 @@ public class FreenetInterface {
* @return The result of the fetch, or {@code null} if an error occured
*/
public Fetched fetchUri(FreenetURI uri) {
- FetchResult fetchResult = null;
FreenetURI currentUri = new FreenetURI(uri);
while (true) {
try {
- fetchResult = client.fetch(currentUri);
+ FetchResult fetchResult = client.fetch(currentUri);
return new Fetched(currentUri, fetchResult);
} catch (FetchException fe1) {
if (fe1.getMode() == FetchException.PERMANENT_REDIRECT) {
@@ -129,16 +132,6 @@ public class FreenetInterface {
}
/**
- * Creates a key pair.
- *
- * @return The request key at index 0, the insert key at index 1
- */
- public String[] generateKeyPair() {
- FreenetURI[] keyPair = client.generateKeyPair("");
- return new String[] { keyPair[1].toString(), keyPair[0].toString() };
- }
-
- /**
* Inserts the image data of the given {@link TemporaryImage} and returns
* the given insert token that can be used to add listeners or cancel the
* insert.
@@ -209,13 +202,7 @@ public class FreenetInterface {
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();
+ new Thread(soneDownloader.fetchSoneAction(sone), "Sone Downloader").start();
}
}
@@ -231,7 +218,7 @@ public class FreenetInterface {
};
soneUskCallbacks.put(sone.getId(), uskCallback);
boolean runBackgroundFetch = (System.currentTimeMillis() - sone.getTime()) < TimeUnit.DAYS.toMillis(7);
- node.clientCore.uskManager.subscribe(USK.create(sone.getRequestUri()), uskCallback, runBackgroundFetch, (HighLevelSimpleClientImpl) client);
+ node.clientCore.uskManager.subscribe(USK.create(sone.getRequestUri()), uskCallback, runBackgroundFetch, (RequestClient) client);
} catch (MalformedURLException mue1) {
logger.log(Level.WARNING, String.format("Could not subscribe USK â%sâ!", sone.getRequestUri()), mue1);
}
@@ -285,7 +272,7 @@ public class FreenetInterface {
};
try {
- node.clientCore.uskManager.subscribe(USK.create(uri), uskCallback, true, (HighLevelSimpleClientImpl) client);
+ node.clientCore.uskManager.subscribe(USK.create(uri), uskCallback, true, (RequestClient) client);
uriUskCallbacks.put(uri, uskCallback);
} catch (MalformedURLException mue1) {
logger.log(Level.WARNING, String.format("Could not subscribe to USK: %s", uri), mue1);
@@ -505,4 +492,13 @@ public class FreenetInterface {
}
+ public class InsertTokenSupplier implements Function {
+
+ @Override
+ public InsertToken apply(Image image) {
+ return new InsertToken(image);
+ }
+
+ }
+
}