From: David ‘Bombe’ Roden Date: Mon, 13 Jul 2015 17:58:49 +0000 (+0200) Subject: Add method to allow local addresses for a peer X-Git-Url: https://git.pterodactylus.net/?p=jFCPlib.git;a=commitdiff_plain;h=a79a4fd515bc8eaa50c7d551fc2f47c941b99c02 Add method to allow local addresses for a peer --- diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java index 09f01ec..6987d9a 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java @@ -13,6 +13,7 @@ public interface ModifyPeerCommand { ModifyPeerCommand enable(); ModifyPeerCommand disable(); + ModifyPeerCommand allowLocalAddresses(); 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 189e2e2..35d6d57 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java @@ -26,6 +26,7 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand { private final ConnectionSupplier connectionSupplier; private final AtomicReference nodeIdentifier = new AtomicReference<>(); private final AtomicReference enabled = new AtomicReference<>(); + private final AtomicReference allowLocalAddresses = new AtomicReference<>(); public ModifyPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) { this.threadPool = MoreExecutors.listeningDecorator(threadPool); @@ -45,6 +46,12 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand { } @Override + public ModifyPeerCommand allowLocalAddresses() { + allowLocalAddresses.set(true); + return this; + } + + @Override public Executable> byName(String name) { nodeIdentifier.set(name); return this::execute; @@ -69,6 +76,7 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand { private Optional executeSequence() throws IOException, ExecutionException, InterruptedException { ModifyPeer modifyPeer = new ModifyPeer(new RandomIdentifierGenerator().generate(), nodeIdentifier.get()); Optional.ofNullable(enabled.get()).ifPresent(enabled -> modifyPeer.setEnabled(enabled)); + Optional.ofNullable(allowLocalAddresses.get()).ifPresent(allowed -> modifyPeer.setAllowLocalAddresses(allowed)); 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 39d2c6a..b826881 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -5,7 +5,9 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.startsWith; import java.io.ByteArrayInputStream; import java.io.File; @@ -1335,4 +1337,29 @@ public class DefaultFcpClientTest { assertThat(peer.get().get().getIdentity(), is("id1")); } + @Test + public void defaultFcpClientCanAllowLocalAddressesOfPeer() + throws InterruptedException, ExecutionException, IOException { + Future> peer = fcpClient.modifyPeer().allowLocalAddresses().byIdentity("id1").execute(); + connectNode(); + List lines = fcpServer.collectUntil(is("EndMessage")); + String identifier = extractIdentifier(lines); + assertThat(lines, matchesFcpMessage( + "ModifyPeer", + "Identifier=" + identifier, + "NodeIdentifier=id1", + "AllowLocalAddresses=true", + "EndMessage" + )); + assertThat(lines, not(contains(startsWith("IsDisabled=")))); + fcpServer.writeLine( + "Peer", + "Identifier=" + identifier, + "NodeIdentifier=Friend1", + "identity=id1", + "EndMessage" + ); + assertThat(peer.get().get().getIdentity(), is("id1")); + } + }