From 58ab179fee620c71e60a8908e7e10793dc837648 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:13:19 +0200 Subject: [PATCH] Add method to disallow local addresses for a peer --- .../fcp/quelaton/ModifyPeerCommand.java | 1 + .../fcp/quelaton/ModifyPeerCommandImpl.java | 6 ++++++ .../fcp/quelaton/DefaultFcpClientTest.java | 25 ++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java index 6987d9a..d7dff80 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java @@ -14,6 +14,7 @@ public interface ModifyPeerCommand { ModifyPeerCommand enable(); ModifyPeerCommand disable(); ModifyPeerCommand allowLocalAddresses(); + ModifyPeerCommand disallowLocalAddresses(); 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 35d6d57..4b30572 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java @@ -52,6 +52,12 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand { } @Override + public ModifyPeerCommand disallowLocalAddresses() { + allowLocalAddresses.set(false); + return this; + } + + @Override public Executable> byName(String name) { nodeIdentifier.set(name); return this::execute; diff --git a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java index b826881..7b829dc 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -1362,4 +1362,29 @@ public class DefaultFcpClientTest { assertThat(peer.get().get().getIdentity(), is("id1")); } + @Test + public void defaultFcpClientCanDisallowLocalAddressesOfPeer() + throws InterruptedException, ExecutionException, IOException { + Future> peer = fcpClient.modifyPeer().disallowLocalAddresses().byIdentity("id1").execute(); + connectNode(); + List lines = fcpServer.collectUntil(is("EndMessage")); + String identifier = extractIdentifier(lines); + assertThat(lines, matchesFcpMessage( + "ModifyPeer", + "Identifier=" + identifier, + "NodeIdentifier=id1", + "AllowLocalAddresses=false", + "EndMessage" + )); + assertThat(lines, not(contains(startsWith("IsDisabled=")))); + fcpServer.writeLine( + "Peer", + "Identifier=" + identifier, + "NodeIdentifier=Friend1", + "identity=id1", + "EndMessage" + ); + assertThat(peer.get().get().getIdentity(), is("id1")); + } + } -- 2.7.4