Add method to remove a peer by host name and port number
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 19:03:37 +0000 (21:03 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 19:03:37 +0000 (21:03 +0200)
src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommand.java
src/main/java/net/pterodactylus/fcp/quelaton/RemovePeerCommandImpl.java
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index cd43adb..e9f6e1e 100644 (file)
@@ -9,5 +9,6 @@ public interface RemovePeerCommand {
 
        Executable<Boolean> byName(String name);
        Executable<Boolean> byIdentity(String nodeIdentity);
+       Executable<Boolean> byHostAndPort(String host, int port);
 
 }
index 6b791e8..b12e225 100644 (file)
@@ -42,6 +42,12 @@ public class RemovePeerCommandImpl implements RemovePeerCommand {
                return this::execute;
        }
 
+       @Override
+       public Executable<Boolean> byHostAndPort(String host, int port) {
+               nodeIdentifier.set(String.format("%s:%d", host, port));
+               return this::execute;
+       }
+
        private ListenableFuture<Boolean> execute() {
                return threadPool.submit(this::executeDialog);
        }
index eb0e193..d2918a8 100644 (file)
@@ -1614,4 +1614,26 @@ public class DefaultFcpClientTest {
                assertThat(peer.get(), is(true));
        }
 
+       @Test
+       public void defaultFcpClientCanRemovePeerByHostAndPort()
+       throws InterruptedException, ExecutionException, IOException {
+               Future<Boolean> peer = fcpClient.removePeer().byHostAndPort("1.2.3.4", 5678).execute();
+               connectNode();
+               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+               String identifier = extractIdentifier(lines);
+               assertThat(lines, matchesFcpMessage(
+                       "RemovePeer",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=1.2.3.4:5678",
+                       "EndMessage"
+               ));
+               fcpServer.writeLine(
+                       "PeerRemoved",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=Friend1",
+                       "EndMessage"
+               );
+               assertThat(peer.get(), is(true));
+       }
+
 }