1 package net.pterodactylus.fcp.quelaton;
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.hamcrest.Matchers.contains;
5 import static org.hamcrest.Matchers.containsInAnyOrder;
6 import static org.hamcrest.Matchers.hasSize;
7 import static org.hamcrest.Matchers.is;
8 import static org.hamcrest.Matchers.not;
9 import static org.hamcrest.Matchers.notNullValue;
10 import static org.hamcrest.Matchers.startsWith;
12 import java.io.ByteArrayInputStream;
14 import java.io.IOException;
16 import java.nio.charset.StandardCharsets;
17 import java.util.Collection;
18 import java.util.List;
19 import java.util.Optional;
20 import java.util.concurrent.CopyOnWriteArrayList;
21 import java.util.concurrent.ExecutionException;
22 import java.util.concurrent.ExecutorService;
23 import java.util.concurrent.Executors;
24 import java.util.concurrent.Future;
25 import java.util.stream.Collectors;
27 import net.pterodactylus.fcp.ARK;
28 import net.pterodactylus.fcp.ConfigData;
29 import net.pterodactylus.fcp.DSAGroup;
30 import net.pterodactylus.fcp.FcpKeyPair;
31 import net.pterodactylus.fcp.Key;
32 import net.pterodactylus.fcp.NodeData;
33 import net.pterodactylus.fcp.NodeRef;
34 import net.pterodactylus.fcp.Peer;
35 import net.pterodactylus.fcp.PeerNote;
36 import net.pterodactylus.fcp.Priority;
37 import net.pterodactylus.fcp.fake.FakeTcpServer;
38 import net.pterodactylus.fcp.quelaton.ClientGetCommand.Data;
40 import com.google.common.io.ByteStreams;
41 import com.google.common.io.Files;
42 import org.hamcrest.Description;
43 import org.hamcrest.Matcher;
44 import org.hamcrest.TypeSafeDiagnosingMatcher;
45 import org.junit.After;
46 import org.junit.Assert;
47 import org.junit.Test;
50 * Unit test for {@link DefaultFcpClient}.
52 * @author <a href="bombe@freenetproject.org">David ‘Bombe’ Roden</a>
54 public class DefaultFcpClientTest {
56 private static final String INSERT_URI =
57 "SSK@RVCHbJdkkyTCeNN9AYukEg76eyqmiosSaNKgE3U9zUw,7SHH53gletBVb9JD7nBsyClbLQsBubDPEIcwg908r7Y,AQECAAE/";
58 private static final String REQUEST_URI =
59 "SSK@wtbgd2loNcJCXvtQVOftl2tuWBomDQHfqS6ytpPRhfw,7SHH53gletBVb9JD7nBsyClbLQsBubDPEIcwg908r7Y,AQACAAE/";
61 private static int threadCounter = 0;
62 private final FakeTcpServer fcpServer;
63 private final DefaultFcpClient fcpClient;
65 public DefaultFcpClientTest() throws IOException {
66 ExecutorService threadPool =
67 Executors.newCachedThreadPool(r -> new Thread(r, "Test-Thread-" + threadCounter++));
68 fcpServer = new FakeTcpServer(threadPool);
69 fcpClient = new DefaultFcpClient(threadPool, "localhost", fcpServer.getPort(), () -> "Test");
73 public void tearDown() throws IOException {
77 @Test(expected = ExecutionException.class)
78 public void defaultFcpClientThrowsExceptionIfItCanNotConnect()
79 throws IOException, ExecutionException, InterruptedException {
80 Future<FcpKeyPair> keyPairFuture = fcpClient.generateKeypair().execute();
81 fcpServer.connect().get();
82 fcpServer.collectUntil(is("EndMessage"));
84 "CloseConnectionDuplicateClientName",
90 @Test(expected = ExecutionException.class)
91 public void defaultFcpClientThrowsExceptionIfConnectionIsClosed()
92 throws IOException, ExecutionException, InterruptedException {
93 Future<FcpKeyPair> keyPairFuture = fcpClient.generateKeypair().execute();
94 fcpServer.connect().get();
95 fcpServer.collectUntil(is("EndMessage"));
101 public void defaultFcpClientCanGenerateKeypair() throws ExecutionException, InterruptedException, IOException {
102 Future<FcpKeyPair> keyPairFuture = fcpClient.generateKeypair().execute();
104 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
105 String identifier = extractIdentifier(lines);
106 fcpServer.writeLine("SSKKeypair",
107 "InsertURI=" + INSERT_URI + "",
108 "RequestURI=" + REQUEST_URI + "",
109 "Identifier=" + identifier,
111 FcpKeyPair keyPair = keyPairFuture.get();
112 assertThat(keyPair.getPublicKey(), is(REQUEST_URI));
113 assertThat(keyPair.getPrivateKey(), is(INSERT_URI));
116 private void connectNode() throws InterruptedException, ExecutionException, IOException {
117 fcpServer.connect().get();
118 fcpServer.collectUntil(is("EndMessage"));
119 fcpServer.writeLine("NodeHello",
120 "CompressionCodecs=4 - GZIP(0), BZIP2(1), LZMA(2), LZMA_NEW(3)",
121 "Revision=build01466",
123 "Version=Fred,0.7,1.0,1466",
125 "ConnectionIdentifier=14318898267048452a81b36e7f13a3f0",
129 "NodeLanguage=ENGLISH",
136 public void clientGetCanDownloadData() throws InterruptedException, ExecutionException, IOException {
137 Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
139 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
140 assertThat(lines, matchesFcpMessage("ClientGet", "ReturnType=direct", "URI=KSK@foo.txt"));
141 String identifier = extractIdentifier(lines);
144 "Identifier=" + identifier,
146 "StartupTime=1435610539000",
147 "CompletionTime=1435610540000",
148 "Metadata.ContentType=text/plain;charset=utf-8",
152 Optional<Data> data = dataFuture.get();
153 assertThat(data.get().getMimeType(), is("text/plain;charset=utf-8"));
154 assertThat(data.get().size(), is(6L));
155 assertThat(ByteStreams.toByteArray(data.get().getInputStream()),
156 is("Hello\n".getBytes(StandardCharsets.UTF_8)));
159 private String extractIdentifier(List<String> lines) {
160 return lines.stream()
161 .filter(s -> s.startsWith("Identifier="))
162 .map(s -> s.substring(s.indexOf('=') + 1))
168 public void clientGetDownloadsDataForCorrectIdentifier()
169 throws InterruptedException, ExecutionException, IOException {
170 Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
172 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
173 assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt"));
174 String identifier = extractIdentifier(lines);
177 "Identifier=not-test",
179 "StartupTime=1435610539000",
180 "CompletionTime=1435610540000",
181 "Metadata.ContentType=text/plain;charset=latin-9",
187 "Identifier=" + identifier,
189 "StartupTime=1435610539000",
190 "CompletionTime=1435610540000",
191 "Metadata.ContentType=text/plain;charset=utf-8",
195 Optional<Data> data = dataFuture.get();
196 assertThat(data.get().getMimeType(), is("text/plain;charset=utf-8"));
197 assertThat(data.get().size(), is(6L));
198 assertThat(ByteStreams.toByteArray(data.get().getInputStream()),
199 is("Hello\n".getBytes(StandardCharsets.UTF_8)));
203 public void clientGetRecognizesGetFailed() throws InterruptedException, ExecutionException, IOException {
204 Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
206 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
207 assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt"));
208 String identifier = extractIdentifier(lines);
211 "Identifier=" + identifier,
215 Optional<Data> data = dataFuture.get();
216 assertThat(data.isPresent(), is(false));
220 public void clientGetRecognizesGetFailedForCorrectIdentifier()
221 throws InterruptedException, ExecutionException, IOException {
222 Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
224 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
225 assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt"));
226 String identifier = extractIdentifier(lines);
229 "Identifier=not-test",
235 "Identifier=" + identifier,
239 Optional<Data> data = dataFuture.get();
240 assertThat(data.isPresent(), is(false));
243 @Test(expected = ExecutionException.class)
244 public void clientGetRecognizesConnectionClosed() throws InterruptedException, ExecutionException, IOException {
245 Future<Optional<Data>> dataFuture = fcpClient.clientGet().uri("KSK@foo.txt").execute();
247 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
248 assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt"));
254 public void defaultFcpClientReusesConnection() throws InterruptedException, ExecutionException, IOException {
255 Future<FcpKeyPair> keyPair = fcpClient.generateKeypair().execute();
257 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
258 String identifier = extractIdentifier(lines);
261 "InsertURI=" + INSERT_URI + "",
262 "RequestURI=" + REQUEST_URI + "",
263 "Identifier=" + identifier,
267 keyPair = fcpClient.generateKeypair().execute();
268 lines = fcpServer.collectUntil(is("EndMessage"));
269 identifier = extractIdentifier(lines);
272 "InsertURI=" + INSERT_URI + "",
273 "RequestURI=" + REQUEST_URI + "",
274 "Identifier=" + identifier,
281 public void defaultFcpClientCanReconnectAfterConnectionHasBeenClosed()
282 throws InterruptedException, ExecutionException, IOException {
283 Future<FcpKeyPair> keyPair = fcpClient.generateKeypair().execute();
285 fcpServer.collectUntil(is("EndMessage"));
290 } catch (ExecutionException e) {
292 keyPair = fcpClient.generateKeypair().execute();
294 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
295 String identifier = extractIdentifier(lines);
298 "InsertURI=" + INSERT_URI + "",
299 "RequestURI=" + REQUEST_URI + "",
300 "Identifier=" + identifier,
307 public void clientGetWithIgnoreDataStoreSettingSendsCorrectCommands()
308 throws InterruptedException, ExecutionException, IOException {
309 fcpClient.clientGet().ignoreDataStore().uri("KSK@foo.txt").execute();
311 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
312 assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "IgnoreDS=true"));
316 public void clientGetWithDataStoreOnlySettingSendsCorrectCommands()
317 throws InterruptedException, ExecutionException, IOException {
318 fcpClient.clientGet().dataStoreOnly().uri("KSK@foo.txt").execute();
320 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
321 assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "DSonly=true"));
325 public void clientGetWithMaxSizeSettingSendsCorrectCommands()
326 throws InterruptedException, ExecutionException, IOException {
327 fcpClient.clientGet().maxSize(1048576).uri("KSK@foo.txt").execute();
329 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
330 assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "MaxSize=1048576"));
334 public void clientGetWithPrioritySettingSendsCorrectCommands()
335 throws InterruptedException, ExecutionException, IOException {
336 fcpClient.clientGet().priority(Priority.interactive).uri("KSK@foo.txt").execute();
338 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
339 assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "PriorityClass=1"));
343 public void clientGetWithRealTimeSettingSendsCorrectCommands()
344 throws InterruptedException, ExecutionException, IOException {
345 fcpClient.clientGet().realTime().uri("KSK@foo.txt").execute();
347 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
348 assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "RealTimeFlag=true"));
352 public void clientGetWithGlobalSettingSendsCorrectCommands()
353 throws InterruptedException, ExecutionException, IOException {
354 fcpClient.clientGet().global().uri("KSK@foo.txt").execute();
356 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
357 assertThat(lines, matchesFcpMessage("ClientGet", "URI=KSK@foo.txt", "Global=true"));
360 private Matcher<List<String>> matchesFcpMessage(String name, String... requiredLines) {
361 return new TypeSafeDiagnosingMatcher<List<String>>() {
363 protected boolean matchesSafely(List<String> item, Description mismatchDescription) {
364 if (!item.get(0).equals(name)) {
365 mismatchDescription.appendText("FCP message is named ").appendValue(item.get(0));
368 for (String requiredLine : requiredLines) {
369 if (item.indexOf(requiredLine) < 1) {
370 mismatchDescription.appendText("FCP message does not contain ").appendValue(requiredLine);
378 public void describeTo(Description description) {
379 description.appendText("FCP message named ").appendValue(name);
380 description.appendValueList(", containing the lines ", ", ", "", requiredLines);
386 public void clientPutWithDirectDataSendsCorrectCommand()
387 throws IOException, ExecutionException, InterruptedException {
388 fcpClient.clientPut()
389 .from(new ByteArrayInputStream("Hello\n".getBytes()))
394 List<String> lines = fcpServer.collectUntil(is("Hello"));
395 assertThat(lines, matchesFcpMessage("ClientPut", "UploadFrom=direct", "DataLength=6", "URI=KSK@foo.txt"));
399 public void clientPutWithDirectDataSucceedsOnCorrectIdentifier()
400 throws InterruptedException, ExecutionException, IOException {
401 Future<Optional<Key>> key = fcpClient.clientPut()
402 .from(new ByteArrayInputStream("Hello\n".getBytes()))
407 List<String> lines = fcpServer.collectUntil(is("Hello"));
408 String identifier = extractIdentifier(lines);
411 "Identifier=not-the-right-one",
417 "Identifier=" + identifier,
420 assertThat(key.get().get().getKey(), is("KSK@foo.txt"));
424 public void clientPutWithDirectDataFailsOnCorrectIdentifier()
425 throws InterruptedException, ExecutionException, IOException {
426 Future<Optional<Key>> key = fcpClient.clientPut()
427 .from(new ByteArrayInputStream("Hello\n".getBytes()))
432 List<String> lines = fcpServer.collectUntil(is("Hello"));
433 String identifier = extractIdentifier(lines);
436 "Identifier=not-the-right-one",
442 "Identifier=" + identifier,
445 assertThat(key.get().isPresent(), is(false));
449 public void clientPutWithRenamedDirectDataSendsCorrectCommand()
450 throws InterruptedException, ExecutionException, IOException {
451 fcpClient.clientPut()
452 .named("otherName.txt")
453 .from(new ByteArrayInputStream("Hello\n".getBytes()))
458 List<String> lines = fcpServer.collectUntil(is("Hello"));
459 assertThat(lines, matchesFcpMessage("ClientPut", "TargetFilename=otherName.txt", "UploadFrom=direct",
460 "DataLength=6", "URI=KSK@foo.txt"));
464 public void clientPutWithRedirectSendsCorrectCommand()
465 throws IOException, ExecutionException, InterruptedException {
466 fcpClient.clientPut().redirectTo("KSK@bar.txt").uri("KSK@foo.txt").execute();
468 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
470 matchesFcpMessage("ClientPut", "UploadFrom=redirect", "URI=KSK@foo.txt", "TargetURI=KSK@bar.txt"));
474 public void clientPutWithFileSendsCorrectCommand() throws InterruptedException, ExecutionException, IOException {
475 fcpClient.clientPut().from(new File("/tmp/data.txt")).uri("KSK@foo.txt").execute();
477 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
479 matchesFcpMessage("ClientPut", "UploadFrom=disk", "URI=KSK@foo.txt", "Filename=/tmp/data.txt"));
483 public void clientPutWithFileCanCompleteTestDdaSequence()
484 throws IOException, ExecutionException, InterruptedException {
485 File tempFile = createTempFile();
486 fcpClient.clientPut().from(new File(tempFile.getParent(), "test.dat")).uri("KSK@foo.txt").execute();
488 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
489 String identifier = extractIdentifier(lines);
492 "Identifier=" + identifier,
496 lines = fcpServer.collectUntil(is("EndMessage"));
497 assertThat(lines, matchesFcpMessage(
499 "Directory=" + tempFile.getParent(),
500 "WantReadDirectory=true",
501 "WantWriteDirectory=false",
506 "Directory=" + tempFile.getParent(),
507 "ReadFilename=" + tempFile,
510 lines = fcpServer.collectUntil(is("EndMessage"));
511 assertThat(lines, matchesFcpMessage(
513 "Directory=" + tempFile.getParent(),
514 "ReadContent=test-content",
519 "Directory=" + tempFile.getParent(),
520 "ReadDirectoryAllowed=true",
523 lines = fcpServer.collectUntil(is("EndMessage"));
525 matchesFcpMessage("ClientPut", "UploadFrom=disk", "URI=KSK@foo.txt",
526 "Filename=" + new File(tempFile.getParent(), "test.dat")));
529 private File createTempFile() throws IOException {
530 File tempFile = File.createTempFile("test-dda-", ".dat");
531 tempFile.deleteOnExit();
532 Files.write("test-content", tempFile, StandardCharsets.UTF_8);
537 public void clientPutDoesNotReactToProtocolErrorForDifferentIdentifier()
538 throws InterruptedException, ExecutionException, IOException {
539 Future<Optional<Key>> key = fcpClient.clientPut().from(new File("/tmp/data.txt")).uri("KSK@foo.txt").execute();
541 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
542 String identifier = extractIdentifier(lines);
545 "Identifier=not-the-right-one",
551 "Identifier=" + identifier,
555 assertThat(key.get().get().getKey(), is("KSK@foo.txt"));
559 public void clientPutAbortsOnProtocolErrorOtherThan25()
560 throws InterruptedException, ExecutionException, IOException {
561 Future<Optional<Key>> key = fcpClient.clientPut().from(new File("/tmp/data.txt")).uri("KSK@foo.txt").execute();
563 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
564 String identifier = extractIdentifier(lines);
567 "Identifier=" + identifier,
571 assertThat(key.get().isPresent(), is(false));
575 public void clientPutDoesNotReplyToWrongTestDdaReply() throws IOException, ExecutionException,
576 InterruptedException {
577 File tempFile = createTempFile();
578 fcpClient.clientPut().from(new File(tempFile.getParent(), "test.dat")).uri("KSK@foo.txt").execute();
580 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
581 String identifier = extractIdentifier(lines);
584 "Identifier=" + identifier,
588 lines = fcpServer.collectUntil(is("EndMessage"));
589 assertThat(lines, matchesFcpMessage(
591 "Directory=" + tempFile.getParent(),
592 "WantReadDirectory=true",
593 "WantWriteDirectory=false",
598 "Directory=/some-other-directory",
599 "ReadFilename=" + tempFile,
604 "Directory=" + tempFile.getParent(),
605 "ReadFilename=" + tempFile,
608 lines = fcpServer.collectUntil(is("EndMessage"));
609 assertThat(lines, matchesFcpMessage(
611 "Directory=" + tempFile.getParent(),
612 "ReadContent=test-content",
618 public void clientPutSendsResponseEvenIfFileCanNotBeRead()
619 throws IOException, ExecutionException, InterruptedException {
620 File tempFile = createTempFile();
621 fcpClient.clientPut().from(new File(tempFile.getParent(), "test.dat")).uri("KSK@foo.txt").execute();
623 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
624 String identifier = extractIdentifier(lines);
627 "Identifier=" + identifier,
631 lines = fcpServer.collectUntil(is("EndMessage"));
632 assertThat(lines, matchesFcpMessage(
634 "Directory=" + tempFile.getParent(),
635 "WantReadDirectory=true",
636 "WantWriteDirectory=false",
641 "Directory=" + tempFile.getParent(),
642 "ReadFilename=" + tempFile + ".foo",
645 lines = fcpServer.collectUntil(is("EndMessage"));
646 assertThat(lines, matchesFcpMessage(
648 "Directory=" + tempFile.getParent(),
649 "ReadContent=failed-to-read",
655 public void clientPutDoesNotResendOriginalClientPutOnTestDDACompleteWithWrongDirectory()
656 throws IOException, ExecutionException, InterruptedException {
657 File tempFile = createTempFile();
658 fcpClient.clientPut().from(new File(tempFile.getParent(), "test.dat")).uri("KSK@foo.txt").execute();
660 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
661 String identifier = extractIdentifier(lines);
664 "Directory=/some-other-directory",
669 "Identifier=" + identifier,
673 lines = fcpServer.collectUntil(is("EndMessage"));
674 assertThat(lines, matchesFcpMessage(
676 "Directory=" + tempFile.getParent(),
677 "WantReadDirectory=true",
678 "WantWriteDirectory=false",
684 public void clientPutSendsNotificationsForGeneratedKeys()
685 throws InterruptedException, ExecutionException, IOException {
686 List<String> generatedKeys = new CopyOnWriteArrayList<>();
687 Future<Optional<Key>> key = fcpClient.clientPut()
688 .onKeyGenerated(generatedKeys::add)
689 .from(new ByteArrayInputStream("Hello\n".getBytes()))
694 List<String> lines = fcpServer.collectUntil(is("Hello"));
695 String identifier = extractIdentifier(lines);
698 "Identifier=" + identifier,
705 "Identifier=" + identifier,
708 assertThat(key.get().get().getKey(), is("KSK@foo.txt"));
709 assertThat(generatedKeys, contains("KSK@foo.txt"));
713 public void clientCanListPeers() throws IOException, ExecutionException, InterruptedException {
714 Future<Collection<Peer>> peers = fcpClient.listPeers().execute();
716 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
717 assertThat(lines, matchesFcpMessage(
719 "WithVolatile=false",
720 "WithMetadata=false",
723 String identifier = extractIdentifier(lines);
726 "Identifier=" + identifier,
732 "Identifier=" + identifier,
738 "Identifier=" + identifier,
741 assertThat(peers.get(), hasSize(2));
742 assertThat(peers.get().stream().map(Peer::getIdentity).collect(Collectors.toList()),
743 containsInAnyOrder("id1", "id2"));
747 public void clientCanListPeersWithMetadata() throws IOException, ExecutionException, InterruptedException {
748 Future<Collection<Peer>> peers = fcpClient.listPeers().includeMetadata().execute();
750 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
751 assertThat(lines, matchesFcpMessage(
753 "WithVolatile=false",
757 String identifier = extractIdentifier(lines);
760 "Identifier=" + identifier,
767 "Identifier=" + identifier,
774 "Identifier=" + identifier,
777 assertThat(peers.get(), hasSize(2));
778 assertThat(peers.get().stream().map(peer -> peer.getMetadata("foo")).collect(Collectors.toList()),
779 containsInAnyOrder("bar1", "bar2"));
783 public void clientCanListPeersWithVolatiles() throws IOException, ExecutionException, InterruptedException {
784 Future<Collection<Peer>> peers = fcpClient.listPeers().includeVolatile().execute();
786 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
787 assertThat(lines, matchesFcpMessage(
790 "WithMetadata=false",
793 String identifier = extractIdentifier(lines);
796 "Identifier=" + identifier,
803 "Identifier=" + identifier,
810 "Identifier=" + identifier,
813 assertThat(peers.get(), hasSize(2));
814 assertThat(peers.get().stream().map(peer -> peer.getVolatile("foo")).collect(Collectors.toList()),
815 containsInAnyOrder("bar1", "bar2"));
819 public void defaultFcpClientCanGetNodeInformation() throws InterruptedException, ExecutionException, IOException {
820 Future<NodeData> nodeData = fcpClient.getNode().execute();
822 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
823 String identifier = extractIdentifier(lines);
824 assertThat(lines, matchesFcpMessage(
826 "Identifier=" + identifier,
827 "GiveOpennetRef=false",
829 "WithVolatile=false",
834 "Identifier=" + identifier,
835 "ark.pubURI=SSK@3YEf.../ark",
838 "version=Fred,0.7,1.0,1466",
839 "lastGoodVersion=Fred,0.7,1.0,1466",
842 assertThat(nodeData.get(), notNullValue());
846 public void defaultFcpClientCanGetNodeInformationWithOpennetRef()
847 throws InterruptedException, ExecutionException, IOException {
848 Future<NodeData> nodeData = fcpClient.getNode().opennetRef().execute();
850 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
851 String identifier = extractIdentifier(lines);
852 assertThat(lines, matchesFcpMessage(
854 "Identifier=" + identifier,
855 "GiveOpennetRef=true",
857 "WithVolatile=false",
862 "Identifier=" + identifier,
864 "ark.pubURI=SSK@3YEf.../ark",
867 "version=Fred,0.7,1.0,1466",
868 "lastGoodVersion=Fred,0.7,1.0,1466",
871 assertThat(nodeData.get().getVersion().toString(), is("Fred,0.7,1.0,1466"));
875 public void defaultFcpClientCanGetNodeInformationWithPrivateData()
876 throws InterruptedException, ExecutionException, IOException {
877 Future<NodeData> nodeData = fcpClient.getNode().includePrivate().execute();
879 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
880 String identifier = extractIdentifier(lines);
881 assertThat(lines, matchesFcpMessage(
883 "Identifier=" + identifier,
884 "GiveOpennetRef=false",
886 "WithVolatile=false",
891 "Identifier=" + identifier,
893 "ark.pubURI=SSK@3YEf.../ark",
896 "version=Fred,0.7,1.0,1466",
897 "lastGoodVersion=Fred,0.7,1.0,1466",
898 "ark.privURI=SSK@XdHMiRl",
901 assertThat(nodeData.get().getARK().getPrivateURI(), is("SSK@XdHMiRl"));
905 public void defaultFcpClientCanGetNodeInformationWithVolatileData()
906 throws InterruptedException, ExecutionException, IOException {
907 Future<NodeData> nodeData = fcpClient.getNode().includeVolatile().execute();
909 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
910 String identifier = extractIdentifier(lines);
911 assertThat(lines, matchesFcpMessage(
913 "Identifier=" + identifier,
914 "GiveOpennetRef=false",
921 "Identifier=" + identifier,
923 "ark.pubURI=SSK@3YEf.../ark",
926 "version=Fred,0.7,1.0,1466",
927 "lastGoodVersion=Fred,0.7,1.0,1466",
928 "volatile.freeJavaMemory=205706528",
931 assertThat(nodeData.get().getVolatile("freeJavaMemory"), is("205706528"));
935 public void defaultFcpClientCanListSinglePeerByIdentity()
936 throws InterruptedException, ExecutionException, IOException {
937 Future<Optional<Peer>> peer = fcpClient.listPeer().byIdentity("id1").execute();
939 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
940 String identifier = extractIdentifier(lines);
941 assertThat(lines, matchesFcpMessage(
943 "Identifier=" + identifier,
944 "NodeIdentifier=id1",
949 "Identifier=" + identifier,
952 "ark.pubURI=SSK@3YEf.../ark",
955 "version=Fred,0.7,1.0,1466",
956 "lastGoodVersion=Fred,0.7,1.0,1466",
959 assertThat(peer.get().get().getIdentity(), is("id1"));
963 public void defaultFcpClientCanListSinglePeerByHostAndPort()
964 throws InterruptedException, ExecutionException, IOException {
965 Future<Optional<Peer>> peer = fcpClient.listPeer().byHostAndPort("host.free.net", 12345).execute();
967 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
968 String identifier = extractIdentifier(lines);
969 assertThat(lines, matchesFcpMessage(
971 "Identifier=" + identifier,
972 "NodeIdentifier=host.free.net:12345",
977 "Identifier=" + identifier,
980 "ark.pubURI=SSK@3YEf.../ark",
983 "version=Fred,0.7,1.0,1466",
984 "lastGoodVersion=Fred,0.7,1.0,1466",
987 assertThat(peer.get().get().getIdentity(), is("id1"));
991 public void defaultFcpClientCanListSinglePeerByName()
992 throws InterruptedException, ExecutionException, IOException {
993 Future<Optional<Peer>> peer = fcpClient.listPeer().byName("FriendNode").execute();
995 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
996 String identifier = extractIdentifier(lines);
997 assertThat(lines, matchesFcpMessage(
999 "Identifier=" + identifier,
1000 "NodeIdentifier=FriendNode",
1003 fcpServer.writeLine(
1005 "Identifier=" + identifier,
1008 "ark.pubURI=SSK@3YEf.../ark",
1011 "version=Fred,0.7,1.0,1466",
1012 "lastGoodVersion=Fred,0.7,1.0,1466",
1015 assertThat(peer.get().get().getIdentity(), is("id1"));
1019 public void defaultFcpClientRecognizesUnknownNodeIdentifiers()
1020 throws InterruptedException, ExecutionException, IOException {
1021 Future<Optional<Peer>> peer = fcpClient.listPeer().byIdentity("id2").execute();
1023 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1024 String identifier = extractIdentifier(lines);
1025 assertThat(lines, matchesFcpMessage(
1027 "Identifier=" + identifier,
1028 "NodeIdentifier=id2",
1031 fcpServer.writeLine(
1032 "UnknownNodeIdentifier",
1033 "Identifier=" + identifier,
1034 "NodeIdentifier=id2",
1037 assertThat(peer.get().isPresent(), is(false));
1041 public void defaultFcpClientCanAddPeerFromFile() throws InterruptedException, ExecutionException, IOException {
1042 Future<Optional<Peer>> peer = fcpClient.addPeer().fromFile(new File("/tmp/ref.txt")).execute();
1044 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1045 String identifier = extractIdentifier(lines);
1046 assertThat(lines, matchesFcpMessage(
1048 "Identifier=" + identifier,
1049 "File=/tmp/ref.txt",
1052 fcpServer.writeLine(
1054 "Identifier=" + identifier,
1057 "ark.pubURI=SSK@3YEf.../ark",
1060 "version=Fred,0.7,1.0,1466",
1061 "lastGoodVersion=Fred,0.7,1.0,1466",
1064 assertThat(peer.get().get().getIdentity(), is("id1"));
1068 public void defaultFcpClientCanAddPeerFromURL() throws InterruptedException, ExecutionException, IOException {
1069 Future<Optional<Peer>> peer = fcpClient.addPeer().fromURL(new URL("http://node.ref/")).execute();
1071 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1072 String identifier = extractIdentifier(lines);
1073 assertThat(lines, matchesFcpMessage(
1075 "Identifier=" + identifier,
1076 "URL=http://node.ref/",
1079 fcpServer.writeLine(
1081 "Identifier=" + identifier,
1084 "ark.pubURI=SSK@3YEf.../ark",
1087 "version=Fred,0.7,1.0,1466",
1088 "lastGoodVersion=Fred,0.7,1.0,1466",
1091 assertThat(peer.get().get().getIdentity(), is("id1"));
1095 public void defaultFcpClientCanAddPeerFromNodeRef() throws InterruptedException, ExecutionException, IOException {
1096 NodeRef nodeRef = new NodeRef();
1097 nodeRef.setIdentity("id1");
1098 nodeRef.setName("name");
1099 nodeRef.setARK(new ARK("public", "1"));
1100 nodeRef.setDSAGroup(new DSAGroup("base", "prime", "subprime"));
1101 nodeRef.setNegotiationTypes(new int[] { 3, 5 });
1102 nodeRef.setPhysicalUDP("1.2.3.4:5678");
1103 nodeRef.setDSAPublicKey("dsa-public");
1104 nodeRef.setSignature("sig");
1105 Future<Optional<Peer>> peer = fcpClient.addPeer().fromNodeRef(nodeRef).execute();
1107 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1108 String identifier = extractIdentifier(lines);
1109 assertThat(lines, matchesFcpMessage(
1111 "Identifier=" + identifier,
1114 "ark.pubURI=public",
1118 "dsaGroup.q=subprime",
1119 "dsaPubKey.y=dsa-public",
1120 "physical.udp=1.2.3.4:5678",
1121 "auth.negTypes=3;5",
1125 fcpServer.writeLine(
1127 "Identifier=" + identifier,
1130 "ark.pubURI=SSK@3YEf.../ark",
1133 "version=Fred,0.7,1.0,1466",
1134 "lastGoodVersion=Fred,0.7,1.0,1466",
1137 assertThat(peer.get().get().getIdentity(), is("id1"));
1141 public void listPeerNotesCanGetPeerNotesByNodeName() throws InterruptedException, ExecutionException, IOException {
1142 Future<Optional<PeerNote>> peerNote = fcpClient.listPeerNotes().byName("Friend1").execute();
1144 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1145 String identifier = extractIdentifier(lines);
1146 assertThat(lines, matchesFcpMessage(
1148 "NodeIdentifier=Friend1",
1151 fcpServer.writeLine(
1153 "Identifier=" + identifier,
1154 "NodeIdentifier=Friend1",
1155 "NoteText=RXhhbXBsZSBUZXh0Lg==",
1159 fcpServer.writeLine(
1161 "Identifier=" + identifier,
1164 assertThat(peerNote.get().get().getNoteText(), is("RXhhbXBsZSBUZXh0Lg=="));
1165 assertThat(peerNote.get().get().getPeerNoteType(), is(1));
1169 public void listPeerNotesReturnsEmptyOptionalWhenNodeIdenfierUnknown()
1170 throws InterruptedException, ExecutionException,
1172 Future<Optional<PeerNote>> peerNote = fcpClient.listPeerNotes().byName("Friend1").execute();
1174 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1175 String identifier = extractIdentifier(lines);
1176 assertThat(lines, matchesFcpMessage(
1178 "NodeIdentifier=Friend1",
1181 fcpServer.writeLine(
1182 "UnknownNodeIdentifier",
1183 "Identifier=" + identifier,
1184 "NodeIdentifier=Friend1",
1187 assertThat(peerNote.get().isPresent(), is(false));
1191 public void listPeerNotesCanGetPeerNotesByNodeIdentifier()
1192 throws InterruptedException, ExecutionException, IOException {
1193 Future<Optional<PeerNote>> peerNote = fcpClient.listPeerNotes().byIdentity("id1").execute();
1195 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1196 String identifier = extractIdentifier(lines);
1197 assertThat(lines, matchesFcpMessage(
1199 "NodeIdentifier=id1",
1202 fcpServer.writeLine(
1204 "Identifier=" + identifier,
1205 "NodeIdentifier=id1",
1206 "NoteText=RXhhbXBsZSBUZXh0Lg==",
1210 fcpServer.writeLine(
1212 "Identifier=" + identifier,
1215 assertThat(peerNote.get().get().getNoteText(), is("RXhhbXBsZSBUZXh0Lg=="));
1216 assertThat(peerNote.get().get().getPeerNoteType(), is(1));
1220 public void listPeerNotesCanGetPeerNotesByHostNameAndPortNumber()
1221 throws InterruptedException, ExecutionException, IOException {
1222 Future<Optional<PeerNote>> peerNote = fcpClient.listPeerNotes().byHostAndPort("1.2.3.4", 5678).execute();
1224 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1225 String identifier = extractIdentifier(lines);
1226 assertThat(lines, matchesFcpMessage(
1228 "NodeIdentifier=1.2.3.4:5678",
1231 fcpServer.writeLine(
1233 "Identifier=" + identifier,
1234 "NodeIdentifier=id1",
1235 "NoteText=RXhhbXBsZSBUZXh0Lg==",
1239 fcpServer.writeLine(
1241 "Identifier=" + identifier,
1244 assertThat(peerNote.get().get().getNoteText(), is("RXhhbXBsZSBUZXh0Lg=="));
1245 assertThat(peerNote.get().get().getPeerNoteType(), is(1));
1249 public void defaultFcpClientCanEnablePeerByName() throws InterruptedException, ExecutionException, IOException {
1250 Future<Optional<Peer>> peer = fcpClient.modifyPeer().enable().byName("Friend1").execute();
1252 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1253 String identifier = extractIdentifier(lines);
1254 assertThat(lines, matchesFcpMessage(
1256 "Identifier=" + identifier,
1257 "NodeIdentifier=Friend1",
1261 fcpServer.writeLine(
1263 "Identifier=" + identifier,
1264 "NodeIdentifier=Friend1",
1268 assertThat(peer.get().get().getIdentity(), is("id1"));
1272 public void defaultFcpClientCanDisablePeerByName() throws InterruptedException, ExecutionException, IOException {
1273 Future<Optional<Peer>> peer = fcpClient.modifyPeer().disable().byName("Friend1").execute();
1275 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1276 String identifier = extractIdentifier(lines);
1277 assertThat(lines, matchesFcpMessage(
1279 "Identifier=" + identifier,
1280 "NodeIdentifier=Friend1",
1284 fcpServer.writeLine(
1286 "Identifier=" + identifier,
1287 "NodeIdentifier=Friend1",
1291 assertThat(peer.get().get().getIdentity(), is("id1"));
1295 public void defaultFcpClientCanEnablePeerByIdentity() throws InterruptedException, ExecutionException, IOException {
1296 Future<Optional<Peer>> peer = fcpClient.modifyPeer().enable().byIdentity("id1").execute();
1298 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1299 String identifier = extractIdentifier(lines);
1300 assertThat(lines, matchesFcpMessage(
1302 "Identifier=" + identifier,
1303 "NodeIdentifier=id1",
1307 fcpServer.writeLine(
1309 "Identifier=" + identifier,
1310 "NodeIdentifier=Friend1",
1314 assertThat(peer.get().get().getIdentity(), is("id1"));
1318 public void defaultFcpClientCanEnablePeerByHostAndPort()
1319 throws InterruptedException, ExecutionException, IOException {
1320 Future<Optional<Peer>> peer = fcpClient.modifyPeer().enable().byHostAndPort("1.2.3.4", 5678).execute();
1322 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1323 String identifier = extractIdentifier(lines);
1324 assertThat(lines, matchesFcpMessage(
1326 "Identifier=" + identifier,
1327 "NodeIdentifier=1.2.3.4:5678",
1331 fcpServer.writeLine(
1333 "Identifier=" + identifier,
1334 "NodeIdentifier=Friend1",
1338 assertThat(peer.get().get().getIdentity(), is("id1"));
1342 public void defaultFcpClientCanNotModifyPeerOfUnknownNode()
1343 throws InterruptedException, ExecutionException, IOException {
1344 Future<Optional<Peer>> peer = fcpClient.modifyPeer().enable().byIdentity("id1").execute();
1346 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1347 String identifier = extractIdentifier(lines);
1348 assertThat(lines, matchesFcpMessage(
1350 "Identifier=" + identifier,
1351 "NodeIdentifier=id1",
1355 fcpServer.writeLine(
1356 "UnknownNodeIdentifier",
1357 "Identifier=" + identifier,
1358 "NodeIdentifier=id1",
1361 assertThat(peer.get().isPresent(), is(false));
1365 public void defaultFcpClientCanAllowLocalAddressesOfPeer()
1366 throws InterruptedException, ExecutionException, IOException {
1367 Future<Optional<Peer>> peer = fcpClient.modifyPeer().allowLocalAddresses().byIdentity("id1").execute();
1369 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1370 String identifier = extractIdentifier(lines);
1371 assertThat(lines, matchesFcpMessage(
1373 "Identifier=" + identifier,
1374 "NodeIdentifier=id1",
1375 "AllowLocalAddresses=true",
1378 assertThat(lines, not(contains(startsWith("IsDisabled="))));
1379 fcpServer.writeLine(
1381 "Identifier=" + identifier,
1382 "NodeIdentifier=Friend1",
1386 assertThat(peer.get().get().getIdentity(), is("id1"));
1390 public void defaultFcpClientCanDisallowLocalAddressesOfPeer()
1391 throws InterruptedException, ExecutionException, IOException {
1392 Future<Optional<Peer>> peer = fcpClient.modifyPeer().disallowLocalAddresses().byIdentity("id1").execute();
1394 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1395 String identifier = extractIdentifier(lines);
1396 assertThat(lines, matchesFcpMessage(
1398 "Identifier=" + identifier,
1399 "NodeIdentifier=id1",
1400 "AllowLocalAddresses=false",
1403 assertThat(lines, not(contains(startsWith("IsDisabled="))));
1404 fcpServer.writeLine(
1406 "Identifier=" + identifier,
1407 "NodeIdentifier=Friend1",
1411 assertThat(peer.get().get().getIdentity(), is("id1"));
1415 public void defaultFcpClientCanSetBurstOnlyForPeer()
1416 throws InterruptedException, ExecutionException, IOException {
1417 Future<Optional<Peer>> peer = fcpClient.modifyPeer().setBurstOnly().byIdentity("id1").execute();
1419 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1420 String identifier = extractIdentifier(lines);
1421 assertThat(lines, matchesFcpMessage(
1423 "Identifier=" + identifier,
1424 "NodeIdentifier=id1",
1428 assertThat(lines, not(contains(startsWith("AllowLocalAddresses="))));
1429 assertThat(lines, not(contains(startsWith("IsDisabled="))));
1430 fcpServer.writeLine(
1432 "Identifier=" + identifier,
1433 "NodeIdentifier=Friend1",
1437 assertThat(peer.get().get().getIdentity(), is("id1"));
1441 public void defaultFcpClientCanClearBurstOnlyForPeer()
1442 throws InterruptedException, ExecutionException, IOException {
1443 Future<Optional<Peer>> peer = fcpClient.modifyPeer().clearBurstOnly().byIdentity("id1").execute();
1445 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1446 String identifier = extractIdentifier(lines);
1447 assertThat(lines, matchesFcpMessage(
1449 "Identifier=" + identifier,
1450 "NodeIdentifier=id1",
1451 "IsBurstOnly=false",
1454 assertThat(lines, not(contains(startsWith("AllowLocalAddresses="))));
1455 assertThat(lines, not(contains(startsWith("IsDisabled="))));
1456 fcpServer.writeLine(
1458 "Identifier=" + identifier,
1459 "NodeIdentifier=Friend1",
1463 assertThat(peer.get().get().getIdentity(), is("id1"));
1467 public void defaultFcpClientCanSetListenOnlyForPeer()
1468 throws InterruptedException, ExecutionException, IOException {
1469 Future<Optional<Peer>> peer = fcpClient.modifyPeer().setListenOnly().byIdentity("id1").execute();
1471 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1472 String identifier = extractIdentifier(lines);
1473 assertThat(lines, matchesFcpMessage(
1475 "Identifier=" + identifier,
1476 "NodeIdentifier=id1",
1477 "IsListenOnly=true",
1480 assertThat(lines, not(contains(startsWith("AllowLocalAddresses="))));
1481 assertThat(lines, not(contains(startsWith("IsDisabled="))));
1482 assertThat(lines, not(contains(startsWith("IsBurstOnly="))));
1483 fcpServer.writeLine(
1485 "Identifier=" + identifier,
1486 "NodeIdentifier=Friend1",
1490 assertThat(peer.get().get().getIdentity(), is("id1"));
1494 public void defaultFcpClientCanClearListenOnlyForPeer()
1495 throws InterruptedException, ExecutionException, IOException {
1496 Future<Optional<Peer>> peer = fcpClient.modifyPeer().clearListenOnly().byIdentity("id1").execute();
1498 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1499 String identifier = extractIdentifier(lines);
1500 assertThat(lines, matchesFcpMessage(
1502 "Identifier=" + identifier,
1503 "NodeIdentifier=id1",
1504 "IsListenOnly=false",
1507 assertThat(lines, not(contains(startsWith("AllowLocalAddresses="))));
1508 assertThat(lines, not(contains(startsWith("IsDisabled="))));
1509 assertThat(lines, not(contains(startsWith("IsBurstOnly="))));
1510 fcpServer.writeLine(
1512 "Identifier=" + identifier,
1513 "NodeIdentifier=Friend1",
1517 assertThat(peer.get().get().getIdentity(), is("id1"));
1521 public void defaultFcpClientCanIgnoreSourceForPeer()
1522 throws InterruptedException, ExecutionException, IOException {
1523 Future<Optional<Peer>> peer = fcpClient.modifyPeer().ignoreSource().byIdentity("id1").execute();
1525 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1526 String identifier = extractIdentifier(lines);
1527 assertThat(lines, matchesFcpMessage(
1529 "Identifier=" + identifier,
1530 "NodeIdentifier=id1",
1531 "IgnoreSourcePort=true",
1534 assertThat(lines, not(contains(startsWith("AllowLocalAddresses="))));
1535 assertThat(lines, not(contains(startsWith("IsDisabled="))));
1536 assertThat(lines, not(contains(startsWith("IsBurstOnly="))));
1537 assertThat(lines, not(contains(startsWith("IsListenOnly="))));
1538 fcpServer.writeLine(
1540 "Identifier=" + identifier,
1541 "NodeIdentifier=Friend1",
1545 assertThat(peer.get().get().getIdentity(), is("id1"));
1549 public void defaultFcpClientCanUseSourceForPeer()
1550 throws InterruptedException, ExecutionException, IOException {
1551 Future<Optional<Peer>> peer = fcpClient.modifyPeer().useSource().byIdentity("id1").execute();
1553 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1554 String identifier = extractIdentifier(lines);
1555 assertThat(lines, matchesFcpMessage(
1557 "Identifier=" + identifier,
1558 "NodeIdentifier=id1",
1559 "IgnoreSourcePort=false",
1562 assertThat(lines, not(contains(startsWith("AllowLocalAddresses="))));
1563 assertThat(lines, not(contains(startsWith("IsDisabled="))));
1564 assertThat(lines, not(contains(startsWith("IsBurstOnly="))));
1565 assertThat(lines, not(contains(startsWith("IsListenOnly="))));
1566 fcpServer.writeLine(
1568 "Identifier=" + identifier,
1569 "NodeIdentifier=Friend1",
1573 assertThat(peer.get().get().getIdentity(), is("id1"));
1577 public void defaultFcpClientCanRemovePeerByName() throws InterruptedException, ExecutionException, IOException {
1578 Future<Boolean> peer = fcpClient.removePeer().byName("Friend1").execute();
1580 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1581 String identifier = extractIdentifier(lines);
1582 assertThat(lines, matchesFcpMessage(
1584 "Identifier=" + identifier,
1585 "NodeIdentifier=Friend1",
1588 fcpServer.writeLine(
1590 "Identifier=" + identifier,
1591 "NodeIdentifier=Friend1",
1594 assertThat(peer.get(), is(true));
1598 public void defaultFcpClientCanNotRemovePeerByInvalidName()
1599 throws InterruptedException, ExecutionException, IOException {
1600 Future<Boolean> peer = fcpClient.removePeer().byName("NotFriend1").execute();
1602 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1603 String identifier = extractIdentifier(lines);
1604 assertThat(lines, matchesFcpMessage(
1606 "Identifier=" + identifier,
1607 "NodeIdentifier=NotFriend1",
1610 fcpServer.writeLine(
1611 "UnknownNodeIdentifier",
1612 "Identifier=" + identifier,
1615 assertThat(peer.get(), is(false));
1619 public void defaultFcpClientCanRemovePeerByIdentity() throws InterruptedException, ExecutionException, IOException {
1620 Future<Boolean> peer = fcpClient.removePeer().byIdentity("id1").execute();
1622 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1623 String identifier = extractIdentifier(lines);
1624 assertThat(lines, matchesFcpMessage(
1626 "Identifier=" + identifier,
1627 "NodeIdentifier=id1",
1630 fcpServer.writeLine(
1632 "Identifier=" + identifier,
1633 "NodeIdentifier=Friend1",
1636 assertThat(peer.get(), is(true));
1640 public void defaultFcpClientCanRemovePeerByHostAndPort()
1641 throws InterruptedException, ExecutionException, IOException {
1642 Future<Boolean> peer = fcpClient.removePeer().byHostAndPort("1.2.3.4", 5678).execute();
1644 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1645 String identifier = extractIdentifier(lines);
1646 assertThat(lines, matchesFcpMessage(
1648 "Identifier=" + identifier,
1649 "NodeIdentifier=1.2.3.4:5678",
1652 fcpServer.writeLine(
1654 "Identifier=" + identifier,
1655 "NodeIdentifier=Friend1",
1658 assertThat(peer.get(), is(true));
1662 public void defaultFcpClientCanModifyPeerNoteByName()
1663 throws InterruptedException, ExecutionException, IOException {
1664 Future<Boolean> noteUpdated = fcpClient.modifyPeerNote().darknetComment("foo").byName("Friend1").execute();
1666 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1667 String identifier = extractIdentifier(lines);
1668 assertThat(lines, matchesFcpMessage(
1670 "Identifier=" + identifier,
1671 "NodeIdentifier=Friend1",
1676 fcpServer.writeLine(
1678 "Identifier=" + identifier,
1679 "NodeIdentifier=Friend1",
1684 assertThat(noteUpdated.get(), is(true));
1688 public void defaultFcpClientKnowsPeerNoteWasNotModifiedOnUnknownNodeIdentifier()
1689 throws InterruptedException, ExecutionException, IOException {
1690 Future<Boolean> noteUpdated = fcpClient.modifyPeerNote().darknetComment("foo").byName("Friend1").execute();
1692 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1693 String identifier = extractIdentifier(lines);
1694 assertThat(lines, matchesFcpMessage(
1696 "Identifier=" + identifier,
1697 "NodeIdentifier=Friend1",
1702 fcpServer.writeLine(
1703 "UnknownNodeIdentifier",
1704 "Identifier=" + identifier,
1705 "NodeIdentifier=Friend1",
1708 assertThat(noteUpdated.get(), is(false));
1712 public void defaultFcpClientFailsToModifyPeerNoteWithoutPeerNote()
1713 throws InterruptedException, ExecutionException, IOException {
1714 Future<Boolean> noteUpdated = fcpClient.modifyPeerNote().byName("Friend1").execute();
1715 assertThat(noteUpdated.get(), is(false));
1719 public void defaultFcpClientCanModifyPeerNoteByIdentifier()
1720 throws InterruptedException, ExecutionException, IOException {
1721 Future<Boolean> noteUpdated = fcpClient.modifyPeerNote().darknetComment("foo").byIdentifier("id1").execute();
1723 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1724 String identifier = extractIdentifier(lines);
1725 assertThat(lines, matchesFcpMessage(
1727 "Identifier=" + identifier,
1728 "NodeIdentifier=id1",
1733 fcpServer.writeLine(
1735 "Identifier=" + identifier,
1736 "NodeIdentifier=id1",
1741 assertThat(noteUpdated.get(), is(true));
1745 public void defaultFcpClientCanModifyPeerNoteByHostAndPort()
1746 throws InterruptedException, ExecutionException, IOException {
1747 Future<Boolean> noteUpdated =
1748 fcpClient.modifyPeerNote().darknetComment("foo").byHostAndPort("1.2.3.4", 5678).execute();
1750 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1751 String identifier = extractIdentifier(lines);
1752 assertThat(lines, matchesFcpMessage(
1754 "Identifier=" + identifier,
1755 "NodeIdentifier=1.2.3.4:5678",
1760 fcpServer.writeLine(
1762 "Identifier=" + identifier,
1763 "NodeIdentifier=1.2.3.4:5678",
1768 assertThat(noteUpdated.get(), is(true));
1772 public void defaultFcpClientCanGetConfigWithoutDetails()
1773 throws InterruptedException, ExecutionException, IOException {
1774 Future<ConfigData> configData = fcpClient.getConfig().execute();
1776 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1777 String identifier = extractIdentifier(lines);
1778 assertThat(lines, matchesFcpMessage(
1780 "Identifier=" + identifier,
1783 fcpServer.writeLine(
1785 "Identifier=" + identifier,
1788 assertThat(configData.get(), notNullValue());
1792 public void defaultFcpClientCanGetConfigWithCurrent()
1793 throws InterruptedException, ExecutionException, IOException {
1794 Future<ConfigData> configData = fcpClient.getConfig().withCurrent().execute();
1796 List<String> lines = fcpServer.collectUntil(is("EndMessage"));
1797 String identifier = extractIdentifier(lines);
1798 assertThat(lines, matchesFcpMessage(
1800 "Identifier=" + identifier,
1804 fcpServer.writeLine(
1806 "Identifier=" + identifier,
1810 assertThat(configData.get().getCurrent("foo"), is("bar"));