mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-25 15:10:18 +01:00
NetworkParameters: hide packet magic behind a getter.
Conflicts: tools/src/main/java/com/google/bitcoin/tools/BlockImporter.java core/src/main/java/com/google/bitcoin/utils/BlockFileLoader.java core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java
This commit is contained in:
parent
8043bc335b
commit
1f005d7b3d
4 changed files with 16 additions and 12 deletions
|
@ -103,7 +103,7 @@ public class BitcoinSerializer {
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */];
|
byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */];
|
||||||
uint32ToByteArrayBE(params.packetMagic, header, 0);
|
uint32ToByteArrayBE(params.getPacketMagic(), header, 0);
|
||||||
|
|
||||||
// The header array is initialized to zero by Java so we don't have to worry about
|
// The header array is initialized to zero by Java so we don't have to worry about
|
||||||
// NULL terminating the string here.
|
// NULL terminating the string here.
|
||||||
|
@ -272,7 +272,7 @@ public class BitcoinSerializer {
|
||||||
}
|
}
|
||||||
// We're looking for a run of bytes that is the same as the packet magic but we want to ignore partial
|
// We're looking for a run of bytes that is the same as the packet magic but we want to ignore partial
|
||||||
// magics that aren't complete. So we keep track of where we're up to with magicCursor.
|
// magics that aren't complete. So we keep track of where we're up to with magicCursor.
|
||||||
int expectedByte = 0xFF & (int) (params.packetMagic >>> (magicCursor * 8));
|
int expectedByte = 0xFF & (int) (params.getPacketMagic() >>> (magicCursor * 8));
|
||||||
if (b == expectedByte) {
|
if (b == expectedByte) {
|
||||||
magicCursor--;
|
magicCursor--;
|
||||||
if (magicCursor < 0) {
|
if (magicCursor < 0) {
|
||||||
|
|
|
@ -62,8 +62,7 @@ public class NetworkParameters implements Serializable {
|
||||||
/** What the easiest allowable proof of work should be. */
|
/** What the easiest allowable proof of work should be. */
|
||||||
public /*final*/ BigInteger proofOfWorkLimit;
|
public /*final*/ BigInteger proofOfWorkLimit;
|
||||||
private final int port;
|
private final int port;
|
||||||
/** The header bytes that identify the start of a packet on this network. */
|
private final long packetMagic;
|
||||||
public final long packetMagic;
|
|
||||||
/**
|
/**
|
||||||
* First byte of a base58 encoded address. See {@link Address}. This is the same as acceptableAddressCodes[0] and
|
* First byte of a base58 encoded address. See {@link Address}. This is the same as acceptableAddressCodes[0] and
|
||||||
* is the one used for "normal" addresses. Other types of address may be encountered with version codes found in
|
* is the one used for "normal" addresses. Other types of address may be encountered with version codes found in
|
||||||
|
@ -397,4 +396,9 @@ public class NetworkParameters implements Serializable {
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The header bytes that identify the start of a packet on this network. */
|
||||||
|
public long getPacketMagic() {
|
||||||
|
return packetMagic;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,18 +124,18 @@ public class BlockFileLoader implements Iterable<Block>, Iterator<Block> {
|
||||||
try {
|
try {
|
||||||
int nextChar = currentFileStream.read();
|
int nextChar = currentFileStream.read();
|
||||||
while (nextChar != -1) {
|
while (nextChar != -1) {
|
||||||
if (nextChar != ((params.packetMagic >>> 24) & 0xff)) {
|
if (nextChar != ((params.getPacketMagic() >>> 24) & 0xff)) {
|
||||||
nextChar = currentFileStream.read();
|
nextChar = currentFileStream.read();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
nextChar = currentFileStream.read();
|
nextChar = currentFileStream.read();
|
||||||
if (nextChar != ((params.packetMagic >>> 16) & 0xff))
|
if (nextChar != ((params.getPacketMagic() >>> 16) & 0xff))
|
||||||
continue;
|
continue;
|
||||||
nextChar = currentFileStream.read();
|
nextChar = currentFileStream.read();
|
||||||
if (nextChar != ((params.packetMagic >>> 8) & 0xff))
|
if (nextChar != ((params.getPacketMagic() >>> 8) & 0xff))
|
||||||
continue;
|
continue;
|
||||||
nextChar = currentFileStream.read();
|
nextChar = currentFileStream.read();
|
||||||
if (nextChar == (params.packetMagic & 0xff))
|
if (nextChar == (params.getPacketMagic() & 0xff))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
byte[] bytes = new byte[4];
|
byte[] bytes = new byte[4];
|
||||||
|
|
|
@ -85,10 +85,10 @@ public class FullBlockTestGenerator {
|
||||||
public boolean add(BlockAndValidity element) {
|
public boolean add(BlockAndValidity element) {
|
||||||
if (outStream != null) {
|
if (outStream != null) {
|
||||||
try {
|
try {
|
||||||
outStream.write((int) (params.packetMagic >>> 24));
|
outStream.write((int) (params.getPacketMagic() >>> 24));
|
||||||
outStream.write((int) (params.packetMagic >>> 16));
|
outStream.write((int) (params.getPacketMagic() >>> 16));
|
||||||
outStream.write((int) (params.packetMagic >>> 8));
|
outStream.write((int) (params.getPacketMagic() >>> 8));
|
||||||
outStream.write((int) (params.packetMagic >>> 0));
|
outStream.write((int) (params.getPacketMagic() >>> 0));
|
||||||
byte[] block = element.block.bitcoinSerialize();
|
byte[] block = element.block.bitcoinSerialize();
|
||||||
byte[] length = new byte[4];
|
byte[] length = new byte[4];
|
||||||
Utils.uint32ToByteArrayBE(block.length, length, 0);
|
Utils.uint32ToByteArrayBE(block.length, length, 0);
|
||||||
|
|
Loading…
Add table
Reference in a new issue