Rename Node#{id => name}

Refer to the "name" of a node rather than its "id". This is reflected in
the command line options as well. Instead of `--id`, now pass `--name`.
Instead of `--bootstrap.node.id`, now pass `--bootstrap.node.id`.
This commit is contained in:
Chris Beams 2014-11-10 12:49:24 +01:00
parent 2ae5949448
commit 3398a97311
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
8 changed files with 34 additions and 30 deletions

View File

@ -36,13 +36,13 @@ public class ArgumentParser {
.description("Bitsquare - The decentralized bitcoin exchange");
// Args for local node config
parser.addArgument("--" + Node.ID_KEY)
parser.addArgument("--" + Node.NAME_KEY)
.help("Local node ID");
parser.addArgument("--" + Node.PORT_KEY)
.help("Local port to listen on");
// Args for seed node config
parser.addArgument("--" + BOOTSTRAP_NODE_ID_KEY)
parser.addArgument("--" + BOOTSTRAP_NODE_NAME_KEY)
.help("Seed node ID");
parser.addArgument("--" + BOOTSTRAP_NODE_IP_KEY)
.help("Seed node IP");

View File

@ -45,15 +45,15 @@ public class SeedNode {
ArgumentParser parser = new ArgumentParser();
Namespace namespace = parser.parseArgs(args);
String id = namespace.getString(Node.ID_KEY);
if (id == null)
throw new IllegalArgumentException(String.format("--%s option is required", Node.ID_KEY));
String name = namespace.getString(Node.NAME_KEY);
if (name == null)
throw new IllegalArgumentException(String.format("--%s option is required", Node.NAME_KEY));
String portValue = namespace.getString(Node.PORT_KEY);
int port = portValue != null ? Integer.valueOf(portValue) : Node.DEFAULT_PORT;
try {
Number160 peerId = Number160.createHash(id);
Number160 peerId = Number160.createHash(name);
PeerMapConfiguration pmc = new PeerMapConfiguration(peerId).peerNoVerification();
PeerMap pm = new PeerMap(pmc);
peer = new PeerBuilder(peerId).ports(port).peerMap(pm).start();

View File

@ -51,6 +51,7 @@ import net.sourceforge.argparse4j.inf.Namespace;
import static io.bitsquare.app.AppModule.APP_NAME_KEY;
import static io.bitsquare.msg.tomp2p.TomP2PMessageModule.*;
import static io.bitsquare.network.Node.*;
public class Main extends Application {
private static final Logger log = LoggerFactory.getLogger(Main.class);
@ -70,8 +71,11 @@ public class Main extends Application {
properties.setProperty(APP_NAME_KEY, appName);
if (argumentsNamespace.getString(BOOTSTRAP_NODE_ID_KEY) != null)
properties.setProperty(BOOTSTRAP_NODE_ID_KEY, argumentsNamespace.getString(BOOTSTRAP_NODE_ID_KEY));
if (argumentsNamespace.getString(NAME_KEY) != null)
properties.setProperty(NAME_KEY, argumentsNamespace.getString(NAME_KEY));
if (argumentsNamespace.getString(BOOTSTRAP_NODE_NAME_KEY) != null)
properties.setProperty(BOOTSTRAP_NODE_NAME_KEY, argumentsNamespace.getString(BOOTSTRAP_NODE_NAME_KEY));
if (argumentsNamespace.getString(BOOTSTRAP_NODE_IP_KEY) != null)
properties.setProperty(BOOTSTRAP_NODE_IP_KEY, argumentsNamespace.getString(BOOTSTRAP_NODE_IP_KEY));

View File

@ -349,7 +349,7 @@ class BootstrappedPeerFactory {
private PeerAddress getBootstrapAddress() {
try {
return new PeerAddress(Number160.createHash(bootstrapNode.getId()),
return new PeerAddress(Number160.createHash(bootstrapNode.getName()),
InetAddress.getByName(bootstrapNode.getIp()),
bootstrapNode.getPort(),
bootstrapNode.getPort());

View File

@ -30,7 +30,7 @@ import static io.bitsquare.network.BootstrapNodes.DEFAULT_BOOTSTRAP_NODE;
public class TomP2PMessageModule extends MessageModule {
public static final String BOOTSTRAP_NODE_ID_KEY = "bootstrap.node.id";
public static final String BOOTSTRAP_NODE_NAME_KEY = "bootstrap.node.name";
public static final String BOOTSTRAP_NODE_IP_KEY = "bootstrap.node.ip";
public static final String BOOTSTRAP_NODE_PORT_KEY = "bootstrap.node.port";
public static final String NETWORK_INTERFACE_KEY = BootstrappedPeerFactory.NETWORK_INTERFACE_KEY;
@ -48,7 +48,7 @@ public class TomP2PMessageModule extends MessageModule {
bind(Node.class).annotatedWith(Names.named(BOOTSTRAP_NODE_KEY)).toInstance(
Node.at(
properties.getProperty(BOOTSTRAP_NODE_ID_KEY, DEFAULT_BOOTSTRAP_NODE.getId()),
properties.getProperty(BOOTSTRAP_NODE_NAME_KEY, DEFAULT_BOOTSTRAP_NODE.getName()),
properties.getProperty(BOOTSTRAP_NODE_IP_KEY, DEFAULT_BOOTSTRAP_NODE.getIp()),
properties.getProperty(BOOTSTRAP_NODE_PORT_KEY, DEFAULT_BOOTSTRAP_NODE.getPortAsString())
)

View File

@ -20,34 +20,34 @@ package io.bitsquare.network;
import com.google.common.base.Objects;
public final class Node {
public static final String ID_KEY = "id";
public static final String NAME_KEY = "name";
public static final String PORT_KEY = "port";
public static final int DEFAULT_PORT = 7366;
private final String id;
private final String name;
private final String ip;
private final int port;
private Node(String id, String ip, int port) {
this.id = id;
private Node(String name, String ip, int port) {
this.name = name;
this.ip = ip;
this.port = port;
}
public static Node at(String id, String ip) {
return Node.at(id, ip, DEFAULT_PORT);
public static Node at(String name, String ip) {
return Node.at(name, ip, DEFAULT_PORT);
}
public static Node at(String id, String ip, int port) {
return new Node(id, ip, port);
public static Node at(String name, String ip, int port) {
return new Node(name, ip, port);
}
public static Node at(String id, String ip, String port) {
return new Node(id, ip, Integer.valueOf(port));
public static Node at(String name, String ip, String port) {
return new Node(name, ip, Integer.valueOf(port));
}
public String getId() {
return id;
public String getName() {
return name;
}
public String getIp() {
@ -71,20 +71,20 @@ public final class Node {
return false;
Node that = (Node) object;
return Objects.equal(this.id, that.id) &&
return Objects.equal(this.name, that.name) &&
Objects.equal(this.ip, that.ip) &&
Objects.equal(this.port, that.port);
}
@Override
public int hashCode() {
return Objects.hashCode(id, ip, port);
return Objects.hashCode(name, ip, port);
}
@Override
public String toString() {
return Objects.toStringHelper(Node.class.getSimpleName())
.add("id", id)
.add("name", name)
.add("ip", ip)
.add("port", port)
.toString();

View File

@ -97,7 +97,7 @@ public class TomP2PTests {
static {
try {
BOOTSTRAP_NODE_ADDRESS = new PeerAddress(
Number160.createHash(BOOTSTRAP_NODE.getId()),
Number160.createHash(BOOTSTRAP_NODE.getName()),
BOOTSTRAP_NODE.getIp(), BOOTSTRAP_NODE.getPort(), BOOTSTRAP_NODE.getPort());
} catch (UnknownHostException ex) {
throw new RuntimeException(BOOTSTRAP_NODE.toString(), ex);

View File

@ -38,8 +38,8 @@ public class NodeTests {
assertThat(node1a, not((Object) equalTo("not a node")));
assertThat(node1a, not(equalTo(Node.at("bitsquare2.example.com", node1a.getIp()))));
assertThat(node1a, not(equalTo(Node.at(node1a.getId(), "203.0.113.2"))));
assertThat(node1a, not(equalTo(Node.at(node1a.getId(), node1a.getIp(), Node.DEFAULT_PORT + 1))));
assertThat(node1a, not(equalTo(Node.at(node1a.getName(), "203.0.113.2"))));
assertThat(node1a, not(equalTo(Node.at(node1a.getName(), node1a.getIp(), Node.DEFAULT_PORT + 1))));
Node node2 = Node.at("bitsquare2.example.com", "203.0.113.2");
assertThat(node1a.hashCode(), equalTo(node1b.hashCode()));
@ -57,6 +57,6 @@ public class NodeTests {
@Test
public void testToString() {
Node node = Node.at("bitsquare1.example.com", "203.0.113.1", 5001);
assertThat(node.toString(), equalTo("Node{id=bitsquare1.example.com, ip=203.0.113.1, port=5001}"));
assertThat(node.toString(), equalTo("Node{name=bitsquare1.example.com, ip=203.0.113.1, port=5001}"));
}
}