@Override public void run() { LOG.info("Doing POW for " + items.size() + " tasks."); for (byte[] initialHash : items) { Item item = powRepo.getItem(initialHash); cryptography.doProofOfWork(item.object, item.nonceTrialsPerByte, item.extraBytes, ProofOfWorkService.this); } } }, delayInMilliseconds);
public void doMissingProofOfWork(long delayInMilliseconds) { final List<byte[]> items = powRepo.getItems(); if (items.isEmpty()) return; // Wait for 30 seconds, to let the application start up before putting heavy load on the CPU new Timer().schedule(new TimerTask() { @Override public void run() { LOG.info("Doing POW for " + items.size() + " tasks."); for (byte[] initialHash : items) { Item item = powRepo.getItem(initialHash); cryptography.doProofOfWork(item.object, item.nonceTrialsPerByte, item.extraBytes, ProofOfWorkService.this); } } }, delayInMilliseconds); }
@Override public void onNonceCalculated(byte[] initialHash, byte[] nonce) { Item item = powRepo.getItem(initialHash); if (item.message == null) { ObjectMessage object = powRepo.getItem(initialHash).object; object.setNonce(nonce); Plaintext plaintext = messageRepo.getMessage(initialHash); powRepo.removeObject(initialHash);
public void doProofOfWorkWithAck(Plaintext plaintext, long expirationTime) { final ObjectMessage ack = plaintext.getAckMessage(); messageRepo.save(plaintext); Item item = new Item(ack, NETWORK_NONCE_TRIALS_PER_BYTE, NETWORK_EXTRA_BYTES, expirationTime, plaintext); powRepo.putObject(item); cryptography.doProofOfWork(ack, NETWORK_NONCE_TRIALS_PER_BYTE, NETWORK_EXTRA_BYTES, this); }
public void doProofOfWork(BitmessageAddress recipient, ObjectMessage object) { Pubkey pubkey = recipient == null ? null : recipient.getPubkey(); long nonceTrialsPerByte = pubkey == null ? NETWORK_NONCE_TRIALS_PER_BYTE : pubkey.getNonceTrialsPerByte(); long extraBytes = pubkey == null ? NETWORK_EXTRA_BYTES : pubkey.getExtraBytes(); powRepo.putObject(object, nonceTrialsPerByte, extraBytes); if (object.getPayload() instanceof PlaintextHolder) { Plaintext plaintext = ((PlaintextHolder) object.getPayload()).getPlaintext(); plaintext.setInitialHash(cryptography.getInitialHash(object)); messageRepo.save(plaintext); } cryptography.doProofOfWork(object, nonceTrialsPerByte, extraBytes, this); }