import static java.lang.String.format;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
-import static net.pterodactylus.sone.freenet.Key.routingKey;
import java.io.IOException;
import java.net.MalformedURLException;
import freenet.support.api.RandomAccessBucket;
import freenet.support.io.ArrayBucket;
import freenet.support.io.ResumeFailedException;
+import net.pterodactylus.sone.freenet.*;
/**
* Contains all necessary functionality for interacting with the Freenet node.
public void registerActiveUsk(FreenetURI requestUri,
USKCallback uskCallback) {
try {
- soneUskCallbacks.put(routingKey(requestUri), uskCallback);
+ soneUskCallbacks.put(FreenetURIsKt.getRoutingKeyString(requestUri), uskCallback);
node.clientCore.uskManager.subscribe(create(requestUri),
uskCallback, true, requestClient);
} catch (MalformedURLException mue1) {
public void registerPassiveUsk(FreenetURI requestUri,
USKCallback uskCallback) {
try {
- soneUskCallbacks.put(routingKey(requestUri), uskCallback);
+ soneUskCallbacks.put(FreenetURIsKt.getRoutingKeyString(requestUri), uskCallback);
node.clientCore
.uskManager
.subscribe(create(requestUri), uskCallback, false, requestClient);
+++ /dev/null
-package net.pterodactylus.sone.freenet;
-
-import static freenet.support.Base64.encode;
-import static java.lang.String.format;
-
-import freenet.keys.FreenetURI;
-
-import com.google.common.annotations.VisibleForTesting;
-
-/**
- * Encapsulates the parts of a {@link FreenetURI} that do not change while
- * being converted from SSK to USK and/or back.
- */
-public class Key {
-
- private final byte[] routingKey;
- private final byte[] cryptoKey;
- private final byte[] extra;
-
- private Key(byte[] routingKey, byte[] cryptoKey, byte[] extra) {
- this.routingKey = routingKey;
- this.cryptoKey = cryptoKey;
- this.extra = extra;
- }
-
- @VisibleForTesting
- public String getRoutingKey() {
- return encode(routingKey);
- }
-
- @VisibleForTesting
- public String getCryptoKey() {
- return encode(cryptoKey);
- }
-
- @VisibleForTesting
- public String getExtra() {
- return encode(extra);
- }
-
- public FreenetURI toUsk(String docName, long edition, String... paths) {
- return new FreenetURI("USK", docName, paths, routingKey, cryptoKey,
- extra, edition);
- }
-
- public FreenetURI toSsk(String docName, String... paths) {
- return new FreenetURI("SSK", docName, paths, routingKey, cryptoKey,
- extra);
- }
-
- public FreenetURI toSsk(String docName, long edition, String... paths) {
- return new FreenetURI("SSK", format("%s-%d", docName, edition), paths,
- routingKey, cryptoKey, extra, edition);
- }
-
- public static Key from(FreenetURI freenetURI) {
- return new Key(freenetURI.getRoutingKey(), freenetURI.getCryptoKey(),
- freenetURI.getExtra());
- }
-
- public static String routingKey(FreenetURI freenetURI) {
- return from(freenetURI).getRoutingKey();
- }
-
-}
--- /dev/null
+package net.pterodactylus.sone.freenet
+
+import freenet.keys.*
+import freenet.support.Base64.*
+
+val FreenetURI.routingKeyString: String get() = encode(routingKey)
--- /dev/null
+package net.pterodactylus.sone.freenet
+
+import freenet.keys.*
+import org.hamcrest.MatcherAssert.*
+import org.hamcrest.Matchers.*
+import org.junit.*
+
+/**
+ * Unit test for [Key].
+ */
+class FreenetURIsTest {
+
+ private val uri = FreenetURI("SSK@$routingKey,$cryptoKey,$extra/some-site-12/foo/bar.html")
+
+ @Test
+ fun routingKeyIsExtractCorrectly() {
+ assertThat(uri.routingKeyString, equalTo(routingKey))
+ }
+
+}
+
+private const val routingKey = "NfUYvxDwU9vqb2mh-qdT~DYJ6U0XNbxMGGoLe0aCHJs"
+private const val cryptoKey = "Miglsgix0VR56ZiPl4NgjnUd~UdrnHqIvXJ3KKHmxmI"
+private const val extra = "AQACAAE"
+++ /dev/null
-package net.pterodactylus.sone.freenet
-
-import freenet.keys.*
-import net.pterodactylus.sone.freenet.Key.*
-import org.hamcrest.MatcherAssert.*
-import org.hamcrest.Matchers.*
-import org.junit.*
-
-/**
- * Unit test for [Key].
- */
-class KeyTest {
-
- private val uri = FreenetURI("SSK@$routingKey,$cryptoKey,$extra/some-site-12/foo/bar.html")
- private val key: Key = from(uri)
-
- @Test
- fun keyCanBeCreatedFromFreenetUri() {
- assertThat(key.routingKey, equalTo(routingKey))
- assertThat(key.cryptoKey, equalTo(cryptoKey))
- assertThat(key.extra, equalTo(extra))
- }
-
- @Test
- fun keyCanBeConvertedToUsk() {
- val uskUri = key.toUsk("other-site", 15, "some", "path.html")
- assertThat(uskUri.toString(), equalTo("USK@$routingKey,$cryptoKey,$extra/other-site/15/some/path.html"))
- }
-
- @Test
- fun keyCanBeConvertedToSskWithoutEdition() {
- val uskUri = key.toSsk("other-site", "some", "path.html")
- assertThat(uskUri.toString(), equalTo("SSK@$routingKey,$cryptoKey,$extra/other-site/some/path.html"))
- }
-
- @Test
- fun keyCanBeConvertedToSskWithEdition() {
- val uskUri = key.toSsk("other-site", 15, "some", "path.html")
- assertThat(uskUri.toString(), equalTo("SSK@$routingKey,$cryptoKey,$extra/other-site-15/some/path.html"))
- }
-
- @Test
- fun routingKeyIsExtractCorrectly() {
- assertThat(routingKey(uri), equalTo(routingKey))
- }
-
-}
-
-private const val routingKey = "NfUYvxDwU9vqb2mh-qdT~DYJ6U0XNbxMGGoLe0aCHJs"
-private const val cryptoKey = "Miglsgix0VR56ZiPl4NgjnUd~UdrnHqIvXJ3KKHmxmI"
-private const val extra = "AQACAAE"