@Override public void write(OutputStream out) throws IOException { if (nonce == null) { out.write(new byte[8]); } else { out.write(nonce); } out.write(getPayloadBytesWithoutNonce()); }
@Override public void write(OutputStream out) throws IOException { out.write(nonce); out.write(getPayloadBytesWithoutNonce()); }
@Override public void write(ByteBuffer buffer) { if (nonce == null) { buffer.put(new byte[8]); } else { buffer.put(nonce); } buffer.put(getPayloadBytesWithoutNonce()); }
@Override public byte[] getInitialHash(ObjectMessage object) { return sha512(object.getPayloadBytesWithoutNonce()); }
private static byte[] getInitialHash(ObjectMessage object) throws IOException { return Security.sha512(object.getPayloadBytesWithoutNonce()); }
private static byte[] getProofOfWorkTarget(ObjectMessage object, long nonceTrialsPerByte, long extraBytes) throws IOException { BigInteger TTL = BigInteger.valueOf(object.getExpiresTime() - UnixTime.now()); LOG.debug("TTL: " + TTL + "s"); BigInteger numerator = TWO.pow(64); BigInteger powLength = BigInteger.valueOf(object.getPayloadBytesWithoutNonce().length + extraBytes); BigInteger denominator = BigInteger.valueOf(nonceTrialsPerByte).multiply(powLength.add(powLength.multiply(TTL).divide(BigInteger.valueOf(2).pow(16)))); return Bytes.expand(numerator.divide(denominator).toByteArray(), 8); }
@Override public byte[] getProofOfWorkTarget(ObjectMessage object, long nonceTrialsPerByte, long extraBytes) { if (nonceTrialsPerByte == 0) nonceTrialsPerByte = NETWORK_NONCE_TRIALS_PER_BYTE; if (extraBytes == 0) extraBytes = NETWORK_EXTRA_BYTES; BigInteger TTL = BigInteger.valueOf(object.getExpiresTime() - UnixTime.now()); BigInteger powLength = BigInteger.valueOf(object.getPayloadBytesWithoutNonce().length + extraBytes); BigInteger denominator = BigInteger.valueOf(nonceTrialsPerByte) .multiply( powLength.add( powLength.multiply(TTL).divide(TWO_POW_16) ) ); return Bytes.expand(TWO_POW_64.divide(denominator).toByteArray(), 8); }
public InventoryVector getInventoryVector() { return new InventoryVector(Bytes.truncate(Security.doubleSha512(nonce, getPayloadBytesWithoutNonce()), 32)); }
public InventoryVector getInventoryVector() { return new InventoryVector( Bytes.truncate(cryptography().doubleSha512(nonce, getPayloadBytesWithoutNonce()), 32) ); }