X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FFreenetInterface.java;h=aa46f936608dbf0fe64ff8cfd933478a7fda9bce;hb=80b69bbf2b53e5587088a1e8b8764aeb92e1c1ae;hp=5d0a1a27eee0ab7c0ba085a7cea9f9300d0c458f;hpb=aaba08b539df7fb8db17f16d6802e31fb5f3bfaa;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 5d0a1a2..aa46f93 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.core; +import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; @@ -25,6 +26,7 @@ import net.pterodactylus.util.service.AbstractService; import freenet.client.FetchException; import freenet.client.FetchResult; import freenet.client.HighLevelSimpleClient; +import freenet.client.InsertException; import freenet.keys.FreenetURI; import freenet.node.Node; @@ -39,6 +41,7 @@ public class FreenetInterface extends AbstractService { private static final Logger logger = Logging.getLogger(FreenetInterface.class); /** The node to interact with. */ + @SuppressWarnings("unused") private final Node node; /** The high-level client to use for requests. */ @@ -81,4 +84,35 @@ public class FreenetInterface extends AbstractService { return fetchResult; } + /** + * 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 a directory into Freenet. + * + * @param insertUri + * The insert URI + * @param manifestEntries + * The directory entries + * @param defaultFile + * The name of the default file + * @return The generated URI + * @throws SoneException + * if an insert error occurs + */ + public FreenetURI insertDirectory(FreenetURI insertUri, HashMap manifestEntries, String defaultFile) throws SoneException { + try { + return client.insertManifest(insertUri, manifestEntries, defaultFile); + } catch (InsertException ie1) { + throw new SoneException(null, ie1); + } + } + }