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);
}
@Override
+ public ModifyPeerCommand allowLocalAddresses() {
+ allowLocalAddresses.set(true);
+ return this;
+ }
+
+ @Override
public Executable<Optional<Peer>> byName(String name) {
nodeIdentifier.set(name);
return this::execute;
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();
}
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.startsWith;
import java.io.ByteArrayInputStream;
import java.io.File;
assertThat(peer.get().get().getIdentity(), is("id1"));
}
+ @Test
+ public void defaultFcpClientCanAllowLocalAddressesOfPeer()
+ throws InterruptedException, ExecutionException, IOException {
+ Future<Optional<Peer>> peer = fcpClient.modifyPeer().allowLocalAddresses().byIdentity("id1").execute();
+ connectNode();
+ List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+ String identifier = extractIdentifier(lines);
+ assertThat(lines, matchesFcpMessage(
+ "ModifyPeer",
+ "Identifier=" + identifier,
+ "NodeIdentifier=id1",
+ "AllowLocalAddresses=true",
+ "EndMessage"
+ ));
+ assertThat(lines, not(contains(startsWith("IsDisabled="))));
+ fcpServer.writeLine(
+ "Peer",
+ "Identifier=" + identifier,
+ "NodeIdentifier=Friend1",
+ "identity=id1",
+ "EndMessage"
+ );
+ assertThat(peer.get().get().getIdentity(), is("id1"));
+ }
+
}