From adfd8b2ac4f8fd0cac4e7dbf38f28af1af15ca45 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Mon, 10 Nov 2014 13:52:12 +0100 Subject: [PATCH] Eliminate BootstrapNodes#DIGITAL_OCEAN_1_DEV Instead of including testing-related bootstrap nodes in the BootstrapNodes class, this change introduces a Node#withPort method that allows for obtaining a copy of an existing bootstrap node (e.g. DIGITAL_OCEAN_1) with a modified port value. This approach to `with*` methods allows for convenient customization of value types without sacrificing immutability. See [1] for details. [1]: http://blog.joda.org/2014/03/valjos-value-java-objects.html --- src/main/java/io/bitsquare/network/BootstrapNodes.java | 1 - src/main/java/io/bitsquare/network/Node.java | 7 +++++++ src/test/java/io/bitsquare/msg/TomP2PTests.java | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/bitsquare/network/BootstrapNodes.java b/src/main/java/io/bitsquare/network/BootstrapNodes.java index c542be8d01..bb2713a175 100644 --- a/src/main/java/io/bitsquare/network/BootstrapNodes.java +++ b/src/main/java/io/bitsquare/network/BootstrapNodes.java @@ -23,7 +23,6 @@ import java.util.List; public interface BootstrapNodes { Node DIGITAL_OCEAN_1 = Node.at("digitalocean1.bitsquare.io", "188.226.179.109"); - Node DIGITAL_OCEAN_1_DEV = Node.at("digitalocean1.bitsquare.io", "188.226.179.109", 7367); /** * Alias to the default bootstrap node. diff --git a/src/main/java/io/bitsquare/network/Node.java b/src/main/java/io/bitsquare/network/Node.java index 9a83378170..349f9dcfce 100644 --- a/src/main/java/io/bitsquare/network/Node.java +++ b/src/main/java/io/bitsquare/network/Node.java @@ -68,6 +68,13 @@ public final class Node { return String.valueOf(port); } + /** + * Return a copy of this node with the port updated to the given value. + */ + public Node withPort(int newPort) { + return Node.at(this.name, this.ip, newPort); + } + @Override public boolean equals(Object object) { if (this == object) diff --git a/src/test/java/io/bitsquare/msg/TomP2PTests.java b/src/test/java/io/bitsquare/msg/TomP2PTests.java index 848f4d4bb1..5e76f51654 100644 --- a/src/test/java/io/bitsquare/msg/TomP2PTests.java +++ b/src/test/java/io/bitsquare/msg/TomP2PTests.java @@ -89,7 +89,7 @@ public class TomP2PTests { // Typically you run the bootstrap node on localhost to test direct connection. // If you have a setup where you are not behind a router you can also use a WAN bootstrap node. private static final Node BOOTSTRAP_NODE = (FORCED_CONNECTION_TYPE == ConnectionType.DIRECT) ? - BootstrapNodes.LOCALHOST : BootstrapNodes.DIGITAL_OCEAN_1_DEV; + BootstrapNodes.LOCALHOST : BootstrapNodes.DIGITAL_OCEAN_1.withPort(7367); private static final PeerAddress BOOTSTRAP_NODE_ADDRESS;