Code cleanup & improvements
- most notably removed some unnecessary synchronize blocks in the DefaultNetworkHandler
This commit is contained in:
@ -302,9 +302,6 @@ public class BitmessageContext {
|
||||
long connectionTTL = 30 * MINUTE;
|
||||
boolean sendPubkeyOnIdentityCreation = true;
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
public Builder port(int port) {
|
||||
this.port = port;
|
||||
return this;
|
||||
|
@ -55,9 +55,6 @@ public class Addr implements MessagePayload {
|
||||
public static final class Builder {
|
||||
private List<NetworkAddress> addresses = new ArrayList<NetworkAddress>();
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
public Builder addresses(Collection<NetworkAddress> addresses){
|
||||
this.addresses.addAll(addresses);
|
||||
return this;
|
||||
|
@ -188,7 +188,7 @@ public class BitmessageAddress implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return alias != null ? alias : address;
|
||||
return alias == null ? address : alias;
|
||||
}
|
||||
|
||||
public byte[] getRipe() {
|
||||
|
@ -28,6 +28,8 @@ import java.util.List;
|
||||
* The 'getdata' command is used to request objects from a node.
|
||||
*/
|
||||
public class GetData implements MessagePayload {
|
||||
public static final int MAX_INVENTORY_SIZE = 50_000;
|
||||
|
||||
List<InventoryVector> inventory;
|
||||
|
||||
private GetData(Builder builder) {
|
||||
@ -54,9 +56,6 @@ public class GetData implements MessagePayload {
|
||||
public static final class Builder {
|
||||
private List<InventoryVector> inventory = new LinkedList<>();
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
public Builder addInventoryVector(InventoryVector inventoryVector) {
|
||||
this.inventory.add(inventoryVector);
|
||||
return this;
|
||||
|
@ -54,9 +54,6 @@ public class Inv implements MessagePayload {
|
||||
public static final class Builder {
|
||||
private List<InventoryVector> inventory = new LinkedList<>();
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
public Builder addInventoryVector(InventoryVector inventoryVector) {
|
||||
this.inventory.add(inventoryVector);
|
||||
return this;
|
||||
|
@ -156,10 +156,10 @@ public class ObjectMessage implements MessagePayload {
|
||||
|
||||
@Override
|
||||
public void write(OutputStream out) throws IOException {
|
||||
if (nonce != null) {
|
||||
out.write(nonce);
|
||||
} else {
|
||||
if (nonce == null) {
|
||||
out.write(new byte[8]);
|
||||
} else {
|
||||
out.write(nonce);
|
||||
}
|
||||
out.write(getPayloadBytesWithoutNonce());
|
||||
}
|
||||
|
@ -143,9 +143,6 @@ public class Version implements MessagePayload {
|
||||
private String userAgent;
|
||||
private long[] streamNumbers;
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
public Builder defaults() {
|
||||
version = BitmessageContext.CURRENT_VERSION;
|
||||
services = 1;
|
||||
|
@ -96,9 +96,6 @@ public class V2Pubkey extends Pubkey {
|
||||
private byte[] publicSigningKey;
|
||||
private byte[] publicEncryptionKey;
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
public Builder stream(long streamNumber) {
|
||||
this.streamNumber = streamNumber;
|
||||
return this;
|
||||
|
@ -123,9 +123,6 @@ public class V3Pubkey extends V2Pubkey {
|
||||
private long extraBytes;
|
||||
private byte[] signature = new byte[0];
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
public Builder stream(long streamNumber) {
|
||||
this.streamNumber = streamNumber;
|
||||
return this;
|
||||
|
@ -134,9 +134,6 @@ public class NetworkAddress implements Streamable {
|
||||
private byte[] ipv6;
|
||||
private int port;
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
public Builder time(final long time) {
|
||||
this.time = time;
|
||||
return this;
|
||||
|
@ -20,6 +20,7 @@ import ch.dissem.bitmessage.exception.ApplicationException;
|
||||
import ch.dissem.bitmessage.utils.Bytes;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import static ch.dissem.bitmessage.utils.Bytes.inc;
|
||||
|
||||
@ -33,18 +34,17 @@ import static ch.dissem.bitmessage.utils.Bytes.inc;
|
||||
public class SimplePOWEngine implements ProofOfWorkEngine {
|
||||
@Override
|
||||
public void calculateNonce(byte[] initialHash, byte[] target, Callback callback) {
|
||||
byte[] nonce = new byte[8];
|
||||
MessageDigest mda;
|
||||
try {
|
||||
mda = MessageDigest.getInstance("SHA-512");
|
||||
} catch (Exception e) {
|
||||
MessageDigest mda = MessageDigest.getInstance("SHA-512");
|
||||
byte[] nonce = new byte[8];
|
||||
do {
|
||||
inc(nonce);
|
||||
mda.update(nonce);
|
||||
mda.update(initialHash);
|
||||
} while (Bytes.lt(target, mda.digest(mda.digest()), 8));
|
||||
callback.onNonceCalculated(initialHash, nonce);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new ApplicationException(e);
|
||||
}
|
||||
do {
|
||||
inc(nonce);
|
||||
mda.update(nonce);
|
||||
mda.update(initialHash);
|
||||
} while (Bytes.lt(target, mda.digest(mda.digest()), 8));
|
||||
callback.onNonceCalculated(initialHash, nonce);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user