From d0ef0149762409d60312db82e23d7845ac90fb2c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 13 Jul 2015 20:34:04 +0200 Subject: [PATCH] Add method to ignore source for a peer --- .../fcp/quelaton/ModifyPeerCommand.java | 1 + .../fcp/quelaton/ModifyPeerCommandImpl.java | 8 +++++++ .../fcp/quelaton/DefaultFcpClientTest.java | 28 ++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java index d421ae1..104401f 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java @@ -19,6 +19,7 @@ public interface ModifyPeerCommand { ModifyPeerCommand clearBurstOnly(); ModifyPeerCommand setListenOnly(); ModifyPeerCommand clearListenOnly(); + ModifyPeerCommand ignoreSource(); Executable> byName(String name); Executable> byIdentity(String nodeIdentity); diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java index 6877245..257bcfa 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java @@ -29,6 +29,7 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand { private final AtomicReference allowLocalAddresses = new AtomicReference<>(); private final AtomicReference burstOnly = new AtomicReference<>(); private final AtomicReference listenOnly = new AtomicReference<>(); + private final AtomicReference 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> 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(); } diff --git a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java index c87e47a..80fb19c 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -1493,4 +1493,32 @@ public class DefaultFcpClientTest { assertThat(peer.get().get().getIdentity(), is("id1")); } + @Test + public void defaultFcpClientCanIgnoreSourceForPeer() + throws InterruptedException, ExecutionException, IOException { + Future> peer = fcpClient.modifyPeer().ignoreSource().byIdentity("id1").execute(); + connectNode(); + List 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")); + } + } -- 2.7.4