Add method to disallow local addresses for a peer
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 18:13:19 +0000 (20:13 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 13 Jul 2015 18:13:19 +0000 (20:13 +0200)
src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommand.java
src/main/java/net/pterodactylus/fcp/quelaton/ModifyPeerCommandImpl.java
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index 6987d9a..d7dff80 100644 (file)
@@ -14,6 +14,7 @@ public interface ModifyPeerCommand {
        ModifyPeerCommand enable();
        ModifyPeerCommand disable();
        ModifyPeerCommand allowLocalAddresses();
+       ModifyPeerCommand disallowLocalAddresses();
 
        Executable<Optional<Peer>> byName(String name);
        Executable<Optional<Peer>> byIdentity(String nodeIdentity);
index 35d6d57..4b30572 100644 (file)
@@ -52,6 +52,12 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand {
        }
 
        @Override
+       public ModifyPeerCommand disallowLocalAddresses() {
+               allowLocalAddresses.set(false);
+               return this;
+       }
+
+       @Override
        public Executable<Optional<Peer>> byName(String name) {
                nodeIdentifier.set(name);
                return this::execute;
index b826881..7b829dc 100644 (file)
@@ -1362,4 +1362,29 @@ public class DefaultFcpClientTest {
                assertThat(peer.get().get().getIdentity(), is("id1"));
        }
 
+       @Test
+       public void defaultFcpClientCanDisallowLocalAddressesOfPeer()
+       throws InterruptedException, ExecutionException, IOException {
+               Future<Optional<Peer>> peer = fcpClient.modifyPeer().disallowLocalAddresses().byIdentity("id1").execute();
+               connectNode();
+               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+               String identifier = extractIdentifier(lines);
+               assertThat(lines, matchesFcpMessage(
+                       "ModifyPeer",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=id1",
+                       "AllowLocalAddresses=false",
+                       "EndMessage"
+               ));
+               assertThat(lines, not(contains(startsWith("IsDisabled="))));
+               fcpServer.writeLine(
+                       "Peer",
+                       "Identifier=" + identifier,
+                       "NodeIdentifier=Friend1",
+                       "identity=id1",
+                       "EndMessage"
+               );
+               assertThat(peer.get().get().getIdentity(), is("id1"));
+       }
+
 }