mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-13 02:35:52 +00:00
PeerAddress: Remove mostly unused setters to make the class more immutable.
This commit is contained in:
parent
88fec4e937
commit
380abd0d52
@ -71,12 +71,12 @@ public class PeerAddress extends ChildMessage {
|
||||
/**
|
||||
* Construct a peer address from a memorized or hardcoded address.
|
||||
*/
|
||||
public PeerAddress(NetworkParameters params, InetAddress addr, int port, int protocolVersion) {
|
||||
public PeerAddress(NetworkParameters params, InetAddress addr, int port, int protocolVersion, BigInteger services) {
|
||||
super(params);
|
||||
this.addr = checkNotNull(addr);
|
||||
this.port = port;
|
||||
this.protocolVersion = protocolVersion;
|
||||
this.services = BigInteger.ZERO;
|
||||
this.services = services;
|
||||
length = protocolVersion > 31402 ? MESSAGE_SIZE : MESSAGE_SIZE - 4;
|
||||
}
|
||||
|
||||
@ -84,7 +84,8 @@ public class PeerAddress extends ChildMessage {
|
||||
* Constructs a peer address from the given IP address and port. Version number is default for the given parameters.
|
||||
*/
|
||||
public PeerAddress(NetworkParameters params, InetAddress addr, int port) {
|
||||
this(params, addr, port, params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.CURRENT));
|
||||
this(params, addr, port, params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.CURRENT),
|
||||
BigInteger.ZERO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -178,38 +179,18 @@ public class PeerAddress extends ChildMessage {
|
||||
return new InetSocketAddress(getAddr(), getPort());
|
||||
}
|
||||
|
||||
public void setAddr(InetAddress addr) {
|
||||
unCache();
|
||||
this.addr = addr;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
unCache();
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public BigInteger getServices() {
|
||||
return services;
|
||||
}
|
||||
|
||||
public void setServices(BigInteger services) {
|
||||
unCache();
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
unCache();
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (hostname != null) {
|
||||
@ -224,7 +205,6 @@ public class PeerAddress extends ChildMessage {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
PeerAddress other = (PeerAddress) o;
|
||||
return other.addr.equals(addr) && other.port == port && other.time == time && other.services.equals(services);
|
||||
//TODO: including services and time could cause same peer to be added multiple times in collections
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,6 +22,7 @@ import com.google.common.net.InetAddresses;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Locale;
|
||||
@ -100,8 +101,8 @@ public class VersionMessage extends Message {
|
||||
// Note that the Bitcoin Core doesn't do anything with these, and finding out your own external IP address
|
||||
// is kind of tricky anyway, so we just put nonsense here for now.
|
||||
InetAddress localhost = InetAddresses.forString("127.0.0.1");
|
||||
myAddr = new PeerAddress(params, localhost, params.getPort(), 0);
|
||||
theirAddr = new PeerAddress(params, localhost, params.getPort(), 0);
|
||||
myAddr = new PeerAddress(params, localhost, params.getPort(), 0, BigInteger.ZERO);
|
||||
theirAddr = new PeerAddress(params, localhost, params.getPort(), 0, BigInteger.ZERO);
|
||||
subVer = LIBRARY_SUBVER;
|
||||
bestHeight = newBestHeight;
|
||||
relayTxesBeforeFilter = true;
|
||||
|
@ -800,8 +800,9 @@ public class WalletProtobufSerializer {
|
||||
throw new UnreadableWalletException("Peer IP address does not have the right length", e);
|
||||
}
|
||||
int port = proto.getPort();
|
||||
PeerAddress address = new PeerAddress(params, ip, port);
|
||||
address.setServices(BigInteger.valueOf(proto.getServices()));
|
||||
int protocolVersion = params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.CURRENT);
|
||||
BigInteger services = BigInteger.valueOf(proto.getServices());
|
||||
PeerAddress address = new PeerAddress(params, ip, port, protocolVersion, services);
|
||||
confidence.markBroadcastBy(address);
|
||||
}
|
||||
if (confidenceProto.hasLastBroadcastedAt())
|
||||
|
@ -20,6 +20,7 @@ package org.bitcoinj.core;
|
||||
import org.bitcoinj.params.MainNetParams;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetAddress;
|
||||
|
||||
import static org.bitcoinj.core.Utils.HEX;
|
||||
@ -39,7 +40,7 @@ public class PeerAddressTest
|
||||
|
||||
@Test
|
||||
public void testBitcoinSerialize() throws Exception {
|
||||
PeerAddress pa = new PeerAddress(MainNetParams.get(), InetAddress.getByName(null), 8333, 0);
|
||||
PeerAddress pa = new PeerAddress(MainNetParams.get(), InetAddress.getByName(null), 8333, 0, BigInteger.ZERO);
|
||||
assertEquals("000000000000000000000000000000000000ffff7f000001208d",
|
||||
Utils.HEX.encode(pa.bitcoinSerialize()));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user