From d558b6c8d41b6b25adf49eadda1dae32af2c5933 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 10 Jul 2015 21:55:22 +0200 Subject: [PATCH] Add flag for returning the opennet ref to GetNode command --- .../pterodactylus/fcp/quelaton/GetNodeCommand.java | 2 ++ .../fcp/quelaton/GetNodeCommandImpl.java | 10 +++++++- .../fcp/quelaton/DefaultFcpClientTest.java | 29 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommand.java b/src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommand.java index 9d8a1a9..da7bf68 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommand.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommand.java @@ -9,4 +9,6 @@ import net.pterodactylus.fcp.NodeData; */ public interface GetNodeCommand extends Executable { + GetNodeCommand opennetRef(); + } diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommandImpl.java index 7efffc0..3c260ab 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommandImpl.java @@ -2,6 +2,7 @@ package net.pterodactylus.fcp.quelaton; import java.io.IOException; import java.util.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import net.pterodactylus.fcp.GetNode; @@ -20,6 +21,7 @@ public class GetNodeCommandImpl implements GetNodeCommand { private final ListeningExecutorService threadPool; private final ConnectionSupplier connectionSupplier; + private final AtomicBoolean giveOpennetRef = new AtomicBoolean(false); public GetNodeCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); @@ -27,8 +29,14 @@ public class GetNodeCommandImpl implements GetNodeCommand { } @Override + public GetNodeCommand opennetRef() { + giveOpennetRef.set(true); + return this; + } + + @Override public ListenableFuture execute() { - GetNode getNode = new GetNode(new RandomIdentifierGenerator().generate(), false, false, false); + GetNode getNode = new GetNode(new RandomIdentifierGenerator().generate(), giveOpennetRef.get(), false, false); return threadPool.submit(() -> new GetNodeReplySequence().send(getNode).get()); } diff --git a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java index 76e04fd..1bef22d 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -776,4 +776,33 @@ public class DefaultFcpClientTest { assertThat(nodeData.get(), notNullValue()); } + @Test + public void defaultFcpClientCanGetNodeInformationWithOpennetRef() + throws InterruptedException, ExecutionException, IOException { + Future nodeData = fcpClient.getNode().opennetRef().execute(); + connectNode(); + List lines = fcpServer.collectUntil(is("EndMessage")); + String identifier = extractIdentifier(lines); + assertThat(lines, matchesFcpMessage( + "GetNode", + "Identifier=" + identifier, + "GiveOpennetRef=true", + "WithPrivate=false", + "WithVolatile=false", + "EndMessage" + )); + fcpServer.writeLine( + "NodeData", + "Identifier=" + identifier, + "opennet=true", + "ark.pubURI=SSK@3YEf.../ark", + "ark.number=78", + "auth.negTypes=2", + "version=Fred,0.7,1.0,1466", + "lastGoodVersion=Fred,0.7,1.0,1466", + "EndMessage" + ); + assertThat(nodeData.get().getVersion().toString(), is("Fred,0.7,1.0,1466")); + } + } -- 2.7.4