/** * Time to live in seconds for public keys the client sends. Defaults to the maximum of 28 days, * but on weak devices smaller values might be desirable. * <p> * Please be aware that this might cause some problems where you can't receive a message (the * sender can't receive your public key) in some special situations. Also note that it's probably * not a good idea to set it too low. * </p> * * @deprecated use {@link TTL#pubkey(long)} instead. */ public Builder pubkeyTTL(long days) { if (days < 0 || days > 28 * DAY) throw new IllegalArgumentException("TTL must be between 1 and 28 days"); TTL.pubkey(days); return this; }
public Plaintext build() { if (from == null) { from = new BitmessageAddress(Factory.createPubkey( addressVersion, stream, publicSigningKey, publicEncryptionKey, nonceTrialsPerByte, extraBytes, behaviorBitfield )); } if (to == null && type != Type.BROADCAST && destinationRipe != null) { to = new BitmessageAddress(0, 0, destinationRipe); } if (type == Type.MSG && ackMessage == null && ackData == null) { ackData = cryptography().randomBytes(Msg.ACK_LENGTH); } if (ttl <= 0) { ttl = TTL.msg(); } return new Plaintext(this); } }
/** * Be aware that if the pubkey already exists in the inventory, the metods will not request it and the callback * for freshly received pubkeys will not be called. Instead the pubkey is added to the contact and stored on DB. */ public void requestPubkey(final BitmessageAddress contact) { BitmessageAddress stored = addressRepository.getAddress(contact.getAddress()); tryToFindMatchingPubkey(contact); if (contact.getPubkey() != null) { if (stored != null) { stored.setPubkey(contact.getPubkey()); addressRepository.save(stored); } else { addressRepository.save(contact); } return; } if (stored == null) { addressRepository.save(contact); } long expires = UnixTime.now(TTL.getpubkey()); LOG.info("Expires at " + expires); final ObjectMessage request = new ObjectMessage.Builder() .stream(contact.getStream()) .expiresTime(expires) .payload(new GetPubkey(contact)) .build(); proofOfWorkService.doProofOfWork(request); }
public void sendPubkey(final BitmessageAddress identity, final long targetStream) { try { long expires = UnixTime.now(TTL.pubkey()); LOG.info("Expires at " + expires); final ObjectMessage response = new ObjectMessage.Builder() .stream(targetStream) .expiresTime(expires) .payload(identity.getPubkey()) .build(); response.sign(identity.getPrivateKey()); response.encrypt(cryptography.createPublicKey(identity.getPublicDecryptionKey())); // TODO: remember that the pubkey is just about to be sent, and on which stream! proofOfWorkService.doProofOfWork(response); } catch (IOException e) { throw new ApplicationException(e); } }