3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-31 07:12:17 +00:00

NetworkParameters: hide port behind a getter.

This commit is contained in:
Mike Hearn 2013-05-08 14:44:33 +02:00
parent ec62bbdeab
commit 8043bc335b
11 changed files with 19 additions and 15 deletions

View File

@ -61,8 +61,7 @@ public class NetworkParameters implements Serializable {
private final Block genesisBlock;
/** What the easiest allowable proof of work should be. */
public /*final*/ BigInteger proofOfWorkLimit;
/** Default TCP port on which to connect to nodes. */
public final int port;
private final int port;
/** The header bytes that identify the start of a packet on this network. */
public final long packetMagic;
/**
@ -393,4 +392,9 @@ public class NetworkParameters implements Serializable {
public Block getGenesisBlock() {
return genesisBlock;
}
/** Default TCP port on which to connect to nodes. */
public int getPort() {
return port;
}
}

View File

@ -90,7 +90,7 @@ public class PeerAddress extends ChildMessage {
* Constructs a peer address from the given IP address. Port and protocol version are default for the prodnet.
*/
public PeerAddress(InetAddress addr) {
this(addr, NetworkParameters.prodNet().port);
this(addr, NetworkParameters.prodNet().getPort());
}
public PeerAddress(InetSocketAddress addr) {

View File

@ -485,7 +485,7 @@ public class PeerGroup extends AbstractIdleService {
/** Convenience method for addAddress(new PeerAddress(address, params.port)); */
public void addAddress(InetAddress address) {
addAddress(new PeerAddress(address, params.port));
addAddress(new PeerAddress(address, params.getPort()));
}
/**

View File

@ -178,7 +178,7 @@ public class TCPNetworkConnection implements NetworkConnection {
@Override
public String toString() {
return "[" + remoteIp.getHostAddress() + "]:" + params.port;
return "[" + remoteIp.getHostAddress() + "]:" + params.getPort();
}
public class NetworkHandler extends ReplayingDecoder<VoidEnum> implements ChannelDownstreamHandler {
@ -244,7 +244,7 @@ public class TCPNetworkConnection implements NetworkConnection {
}
public PeerAddress getPeerAddress() {
return new PeerAddress(remoteIp, params.port);
return new PeerAddress(remoteIp, params.getPort());
}
public void close() {

View File

@ -101,8 +101,8 @@ public class VersionMessage extends Message {
// We hard-code the IPv4 localhost address here rather than use InetAddress.getLocalHost() because some
// mobile phones have broken localhost DNS entries, also, this is faster.
final byte[] localhost = new byte[] { 127, 0, 0, 1 };
myAddr = new PeerAddress(InetAddress.getByAddress(localhost), params.port, 0);
theirAddr = new PeerAddress(InetAddress.getByAddress(localhost), params.port, 0);
myAddr = new PeerAddress(InetAddress.getByAddress(localhost), params.getPort(), 0);
theirAddr = new PeerAddress(InetAddress.getByAddress(localhost), params.getPort(), 0);
} catch (UnknownHostException e) {
throw new RuntimeException(e); // Cannot happen (illegal IP length).
}

View File

@ -94,7 +94,7 @@ public class DnsDiscovery implements PeerDiscovery {
continue;
}
for (InetAddress addr : inetAddresses) {
addrs.add(new InetSocketAddress(addr, netParams.port));
addrs.add(new InetSocketAddress(addr, netParams.getPort()));
}
}
if (addrs.size() == 0)

View File

@ -53,7 +53,7 @@ public class SeedPeers implements PeerDiscovery {
private InetSocketAddress nextPeer() throws UnknownHostException {
if (pnseedIndex >= seedAddrs.length) return null;
return new InetSocketAddress(convertAddress(seedAddrs[pnseedIndex++]),
params.port);
params.getPort());
}
/**
@ -70,7 +70,7 @@ public class SeedPeers implements PeerDiscovery {
private InetSocketAddress[] allPeers() throws UnknownHostException {
InetSocketAddress[] addresses = new InetSocketAddress[seedAddrs.length];
for (int i = 0; i < seedAddrs.length; ++i) {
addresses[i] = new InetSocketAddress(convertAddress(seedAddrs[i]), params.port);
addresses[i] = new InetSocketAddress(convertAddress(seedAddrs[i]), params.getPort());
}
return addresses;
}

View File

@ -37,7 +37,7 @@ public class FetchBlock {
BlockChain chain = new BlockChain(params, blockStore);
PeerGroup peerGroup = new PeerGroup(params, chain);
peerGroup.startAndWait();
PeerAddress addr = new PeerAddress(InetAddress.getLocalHost(), params.port);
PeerAddress addr = new PeerAddress(InetAddress.getLocalHost(), params.getPort());
peerGroup.addAddress(addr);
peerGroup.waitForPeers(1).get();
Peer peer = peerGroup.getConnectedPeers().get(0);

View File

@ -38,7 +38,7 @@ public class FetchTransactions {
BlockChain chain = new BlockChain(params, blockStore);
PeerGroup peerGroup = new PeerGroup(params, chain);
peerGroup.startAndWait();
peerGroup.addAddress(new PeerAddress(InetAddress.getLocalHost(), params.port));
peerGroup.addAddress(new PeerAddress(InetAddress.getLocalHost(), params.getPort()));
peerGroup.waitForPeers(1).get();
Peer peer = peerGroup.getConnectedPeers().get(0);

View File

@ -76,7 +76,7 @@ public class PrintPeers {
List<ListenableFuture<TCPNetworkConnection>> futures = Lists.newArrayList();
for (final InetAddress addr : addrs) {
final ListenableFuture<TCPNetworkConnection> future =
TCPNetworkConnection.connectTo(params, new InetSocketAddress(addr, params.port), 1000 /* timeout */);
TCPNetworkConnection.connectTo(params, new InetSocketAddress(addr, params.getPort()), 1000 /* timeout */);
futures.add(future);
// Once the connection has completed version handshaking ...
Futures.addCallback(future, new FutureCallback<TCPNetworkConnection>() {

View File

@ -585,7 +585,7 @@ public class WalletTool {
String[] peerAddrs = peersFlag.split(",");
for (String peer : peerAddrs) {
try {
peers.addAddress(new PeerAddress(InetAddress.getByName(peer), params.port));
peers.addAddress(new PeerAddress(InetAddress.getByName(peer), params.getPort()));
} catch (UnknownHostException e) {
System.err.println("Could not understand peer domain name/IP address: " + peer + ": " + e.getMessage());
System.exit(1);