From 7a9badc9ffa665b777529976e23456cd2e46e5d9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 14 Jul 2015 21:25:56 +0200 Subject: [PATCH 1/1] Add method to modify peer note by host and port --- .../fcp/quelaton/ModifyPeerNoteCommand.java | 1 + .../fcp/quelaton/ModifyPeerNoteCommandImpl.java | 6 +++++ .../fcp/quelaton/DefaultFcpClientTest.java | 27 ++++++++++++++++++++++ 3 files changed, 34 insertions(+) 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)); + } + } -- 2.7.4