From: David ‘Bombe’ Roden Date: Tue, 14 Jul 2015 19:25:56 +0000 (+0200) Subject: Add method to modify peer note by host and port X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=7a9badc9ffa665b777529976e23456cd2e46e5d9;hp=74a13907af14380c5a02c3b44eb517174d134beb;p=jFCPlib.git Add method to modify peer note by host and port --- diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerNoteCommand.java b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerNoteCommand.java index 690671f..ee76487 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerNoteCommand.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerNoteCommand.java @@ -11,5 +11,6 @@ public interface ModifyPeerNoteCommand { Executable byName(String name); Executable byIdentifier(String identifier); + Executable byHostAndPort(String host, int port); } diff --git a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerNoteCommandImpl.java b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerNoteCommandImpl.java index ecb4ed9..6e6dcc2 100644 --- a/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerNoteCommandImpl.java +++ b/src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerNoteCommandImpl.java @@ -55,6 +55,12 @@ public class ModifyPeerNoteCommandImpl implements ModifyPeerNoteCommand { 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() { if (darknetComment.get() == null) { return Futures.immediateFuture(false); diff --git a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java index 4781101..fbfff9e 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -1740,4 +1740,31 @@ public class DefaultFcpClientTest { assertThat(noteUpdated.get(), is(true)); } + @Test + public void defaultFcpClientCanModifyPeerNoteByHostAndPort() + throws InterruptedException, ExecutionException, IOException { + Future noteUpdated = + fcpClient.modifyPeerNote().darknetComment("foo").byHostAndPort("1.2.3.4", 5678).execute(); + connectNode(); + List lines = fcpServer.collectUntil(is("EndMessage")); + String identifier = extractIdentifier(lines); + assertThat(lines, matchesFcpMessage( + "ModifyPeerNote", + "Identifier=" + identifier, + "NodeIdentifier=1.2.3.4:5678", + "PeerNoteType=1", + "NoteText=Zm9v", + "EndMessage" + )); + fcpServer.writeLine( + "PeerNote", + "Identifier=" + identifier, + "NodeIdentifier=1.2.3.4:5678", + "NoteText=Zm9v", + "PeerNoteType=1", + "EndMessage" + ); + assertThat(noteUpdated.get(), is(true)); + } + }