Add flag to GetNode command to include private data
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 10 Jul 2015 20:04:34 +0000 (22:04 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Fri, 10 Jul 2015 20:09:24 +0000 (22:09 +0200)
src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommand.java
src/main/java/net/pterodactylus/fcp/quelaton/GetNodeCommandImpl.java
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index da7bf68..ff94622 100644 (file)
@@ -10,5 +10,6 @@ import net.pterodactylus.fcp.NodeData;
 public interface GetNodeCommand extends Executable<NodeData> {
 
        GetNodeCommand opennetRef();
+       GetNodeCommand includePrivate();
 
 }
index 3c260ab..23c5ad0 100644 (file)
@@ -22,6 +22,7 @@ public class GetNodeCommandImpl implements GetNodeCommand {
        private final ListeningExecutorService threadPool;
        private final ConnectionSupplier connectionSupplier;
        private final AtomicBoolean giveOpennetRef = new AtomicBoolean(false);
+       private final AtomicBoolean includePrivate = new AtomicBoolean(false);
 
        public GetNodeCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
                this.threadPool = MoreExecutors.listeningDecorator(threadPool);
@@ -35,8 +36,15 @@ public class GetNodeCommandImpl implements GetNodeCommand {
        }
 
        @Override
+       public GetNodeCommand includePrivate() {
+               includePrivate.set(true);
+               return this;
+       }
+
+       @Override
        public ListenableFuture<NodeData> execute() {
-               GetNode getNode = new GetNode(new RandomIdentifierGenerator().generate(), giveOpennetRef.get(), false, false);
+               GetNode getNode = new GetNode(new RandomIdentifierGenerator().generate(), giveOpennetRef.get(),
+                       includePrivate.get(), false);
                return threadPool.submit(() -> new GetNodeReplySequence().send(getNode).get());
        }
 
index 1bef22d..1e484dc 100644 (file)
@@ -805,4 +805,34 @@ public class DefaultFcpClientTest {
                assertThat(nodeData.get().getVersion().toString(), is("Fred,0.7,1.0,1466"));
        }
 
+       @Test
+       public void defaultFcpClientCanGetNodeInformationWithPrivateData()
+       throws InterruptedException, ExecutionException, IOException {
+               Future<NodeData> nodeData = fcpClient.getNode().includePrivate().execute();
+               connectNode();
+               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+               String identifier = extractIdentifier(lines);
+               assertThat(lines, matchesFcpMessage(
+                       "GetNode",
+                       "Identifier=" + identifier,
+                       "GiveOpennetRef=false",
+                       "WithPrivate=true",
+                       "WithVolatile=false",
+                       "EndMessage"
+               ));
+               fcpServer.writeLine(
+                       "NodeData",
+                       "Identifier=" + identifier,
+                       "opennet=false",
+                       "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",
+                       "ark.privURI=SSK@XdHMiRl",
+                       "EndMessage"
+               );
+               assertThat(nodeData.get().getARK().getPrivateURI(), is("SSK@XdHMiRl"));
+       }
+
 }