Add method to ignore source for a peer
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 18:34:04 +0000 (20:34 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 18:34:04 +0000 (20:34 +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 d421ae1..104401f 100644 (file)
@@ -19,6 +19,7 @@ public interface ModifyPeerCommand {
        ModifyPeerCommand clearBurstOnly();
        ModifyPeerCommand setListenOnly();
        ModifyPeerCommand clearListenOnly();
+       ModifyPeerCommand ignoreSource();
 
        Executable<Optional<Peer>> byName(String name);
        Executable<Optional<Peer>> byIdentity(String nodeIdentity);
index 6877245..257bcfa 100644 (file)
@@ -29,6 +29,7 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand {
        private final AtomicReference<Boolean> allowLocalAddresses = new AtomicReference<>();
        private final AtomicReference<Boolean> burstOnly = new AtomicReference<>();
        private final AtomicReference<Boolean> listenOnly = new AtomicReference<>();
+       private final AtomicReference<Boolean> ignoreSource = new AtomicReference<>();
 
        public ModifyPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
                this.threadPool = MoreExecutors.listeningDecorator(threadPool);
@@ -84,6 +85,12 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand {
        }
 
        @Override
+       public ModifyPeerCommand ignoreSource() {
+               ignoreSource.set(true);
+               return this;
+       }
+
+       @Override
        public Executable<Optional<Peer>> byName(String name) {
                nodeIdentifier.set(name);
                return this::execute;
@@ -111,6 +118,7 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand {
                Optional.ofNullable(allowLocalAddresses.get()).ifPresent(allowed -> modifyPeer.setAllowLocalAddresses(allowed));
                Optional.ofNullable(burstOnly.get()).ifPresent(burstOnly -> modifyPeer.setBurstOnly(burstOnly));
                Optional.ofNullable(listenOnly.get()).ifPresent(listenOnly -> modifyPeer.setListenOnly(listenOnly));
+               Optional.ofNullable(ignoreSource.get()).ifPresent(ignoreSource -> modifyPeer.setIgnoreSource(ignoreSource));
                try (ModifyPeerDialog modifyPeerDialog = new ModifyPeerDialog()) {
                        return modifyPeerDialog.send(modifyPeer).get();
                }
index c87e47a..80fb19c 100644 (file)
@@ -1493,4 +1493,32 @@ public class DefaultFcpClientTest {
                assertThat(peer.get().get().getIdentity(), is("id1"));
        }
 
+       @Test
+       public void defaultFcpClientCanIgnoreSourceForPeer()
+       throws InterruptedException, ExecutionException, IOException {
+               Future<Optional<Peer>> peer = fcpClient.modifyPeer().ignoreSource().byIdentity("id1").execute();
+               connectNode();
+               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+               String identifier = extractIdentifier(lines);
+               assertThat(lines, matchesFcpMessage(
+                       "ModifyPeer",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=id1",
+                       "IgnoreSourcePort=true",
+                       "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"));
+       }
+
 }