From: David ‘Bombe’ Roden Date: Mon, 13 Jul 2015 17:52:13 +0000 (+0200) Subject: Add method to modify peers by host name and port number X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=a04b60f09eb2e6c4a7264db26789740ddb6e0637;p=jFCPlib.git Add method to modify peers by host name and port number --- diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java index 7037e3b..09f01ec 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java @@ -16,5 +16,6 @@ public interface ModifyPeerCommand { Executable> byName(String name); Executable> byIdentity(String nodeIdentity); + Executable> byHostAndPort(String host, int port); } diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java index 50d780f..189e2e2 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java @@ -56,6 +56,12 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand { return this::execute; } + @Override + public Executable> byHostAndPort(String host, int port) { + nodeIdentifier.set(String.format("%s:%d", host, port)); + return this::execute; + } + private ListenableFuture> execute() { return threadPool.submit(this::executeSequence); } diff --git a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java index b0b50ae..39d2c6a 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -1311,4 +1311,28 @@ public class DefaultFcpClientTest { assertThat(peer.get().get().getIdentity(), is("id1")); } + @Test + public void defaultFcpClientCanEnablePeerByHostAndPort() + throws InterruptedException, ExecutionException, IOException { + Future> peer = fcpClient.modifyPeer().enable().byHostAndPort("1.2.3.4", 5678).execute(); + connectNode(); + List lines = fcpServer.collectUntil(is("EndMessage")); + String identifier = extractIdentifier(lines); + assertThat(lines, matchesFcpMessage( + "ModifyPeer", + "Identifier=" + identifier, + "NodeIdentifier=1.2.3.4:5678", + "IsDisabled=false", + "EndMessage" + )); + fcpServer.writeLine( + "Peer", + "Identifier=" + identifier, + "NodeIdentifier=Friend1", + "identity=id1", + "EndMessage" + ); + assertThat(peer.get().get().getIdentity(), is("id1")); + } + }