Add method to not ignore source of a peer
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 18:37:32 +0000 (20:37 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 18:37:32 +0000 (20:37 +0200)
src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java
src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index 104401f..0c8a0a4 100644 (file)
@@ -20,6 +20,7 @@ public interface ModifyPeerCommand {
        ModifyPeerCommand setListenOnly();
        ModifyPeerCommand clearListenOnly();
        ModifyPeerCommand ignoreSource();
+       ModifyPeerCommand useSource();
 
        Executable<Optional<Peer>> byName(String name);
        Executable<Optional<Peer>> byIdentity(String nodeIdentity);
index 257bcfa..5dd2bf9 100644 (file)
@@ -91,6 +91,12 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand {
        }
 
        @Override
+       public ModifyPeerCommand useSource() {
+               ignoreSource.set(false);
+               return this;
+       }
+
+       @Override
        public Executable<Optional<Peer>> byName(String name) {
                nodeIdentifier.set(name);
                return this::execute;
index 80fb19c..cf7a4ae 100644 (file)
@@ -1521,4 +1521,32 @@ public class DefaultFcpClientTest {
                assertThat(peer.get().get().getIdentity(), is("id1"));
        }
 
+       @Test
+       public void defaultFcpClientCanUseSourceForPeer()
+       throws InterruptedException, ExecutionException, IOException {
+               Future<Optional<Peer>> peer = fcpClient.modifyPeer().useSource().byIdentity("id1").execute();
+               connectNode();
+               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+               String identifier = extractIdentifier(lines);
+               assertThat(lines, matchesFcpMessage(
+                       "ModifyPeer",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=id1",
+                       "IgnoreSourcePort=false",
+                       "EndMessage"
+               ));
+               assertThat(lines, not(contains(startsWith("AllowLocalAddresses="))));
+               assertThat(lines, not(contains(startsWith("IsDisabled="))));
+               assertThat(lines, not(contains(startsWith("IsBurstOnly="))));
+               assertThat(lines, not(contains(startsWith("IsListenOnly="))));
+               fcpServer.writeLine(
+                       "Peer",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=Friend1",
+                       "identity=id1",
+                       "EndMessage"
+               );
+               assertThat(peer.get().get().getIdentity(), is("id1"));
+       }
+
 }