Add method to disallow local addresses for a peer
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / quelaton / ModifyPeerCommandImpl.java
index 50d780f..4b30572 100644 (file)
@@ -26,6 +26,7 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand {
        private final ConnectionSupplier connectionSupplier;
        private final AtomicReference<String> nodeIdentifier = new AtomicReference<>();
        private final AtomicReference<Boolean> enabled = new AtomicReference<>();
+       private final AtomicReference<Boolean> allowLocalAddresses = new AtomicReference<>();
 
        public ModifyPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
                this.threadPool = MoreExecutors.listeningDecorator(threadPool);
@@ -45,6 +46,18 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand {
        }
 
        @Override
+       public ModifyPeerCommand allowLocalAddresses() {
+               allowLocalAddresses.set(true);
+               return this;
+       }
+
+       @Override
+       public ModifyPeerCommand disallowLocalAddresses() {
+               allowLocalAddresses.set(false);
+               return this;
+       }
+
+       @Override
        public Executable<Optional<Peer>> byName(String name) {
                nodeIdentifier.set(name);
                return this::execute;
@@ -56,6 +69,12 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand {
                return this::execute;
        }
 
+       @Override
+       public Executable<Optional<Peer>> byHostAndPort(String host, int port) {
+               nodeIdentifier.set(String.format("%s:%d", host, port));
+               return this::execute;
+       }
+
        private ListenableFuture<Optional<Peer>> execute() {
                return threadPool.submit(this::executeSequence);
        }
@@ -63,6 +82,7 @@ public class ModifyPeerCommandImpl implements ModifyPeerCommand {
        private Optional<Peer> executeSequence() throws IOException, ExecutionException, InterruptedException {
                ModifyPeer modifyPeer = new ModifyPeer(new RandomIdentifierGenerator().generate(), nodeIdentifier.get());
                Optional.ofNullable(enabled.get()).ifPresent(enabled -> modifyPeer.setEnabled(enabled));
+               Optional.ofNullable(allowLocalAddresses.get()).ifPresent(allowed -> modifyPeer.setAllowLocalAddresses(allowed));
                try (ModifyPeerDialog modifyPeerDialog = new ModifyPeerDialog()) {
                        return modifyPeerDialog.send(modifyPeer).get();
                }