/** * Calculates the proof of work. This might take a long time, depending on the hardware, message size and time to * live. * * @param object to do the proof of work for * @param worker doing the actual proof of work * @param nonceTrialsPerByte difficulty * @param extraBytes bytes to add to the object size (makes it more difficult to send small messages) */ public static void doProofOfWork(ObjectMessage object, ProofOfWorkEngine worker, long nonceTrialsPerByte, long extraBytes) { try { if (nonceTrialsPerByte < 1000) nonceTrialsPerByte = 1000; if (extraBytes < 1000) extraBytes = 1000; byte[] initialHash = getInitialHash(object); byte[] target = getProofOfWorkTarget(object, nonceTrialsPerByte, extraBytes); byte[] nonce = worker.calculateNonce(initialHash, target); object.setNonce(nonce); } catch (IOException e) { throw new RuntimeException(e); } }
public void doProofOfWork(ObjectMessage object, long nonceTrialsPerByte, long extraBytes, ProofOfWorkEngine.Callback callback) { nonceTrialsPerByte = max(nonceTrialsPerByte, NETWORK_NONCE_TRIALS_PER_BYTE); extraBytes = max(extraBytes, NETWORK_EXTRA_BYTES); byte[] initialHash = getInitialHash(object); byte[] target = getProofOfWorkTarget(object, nonceTrialsPerByte, extraBytes); context.getProofOfWorkEngine().calculateNonce(initialHash, target, callback); }