diff --git a/build.gradle b/build.gradle index dc918be..b944a14 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ subprojects { sourceCompatibility = 1.7 group = 'ch.dissem.jabit' - version = '1.0.0' + version = '1.0.1-SNAPSHOT' ext.isReleaseVersion = !version.endsWith("SNAPSHOT") @@ -34,7 +34,7 @@ subprojects { } signing { - required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") } + required { isReleaseVersion } sign configurations.archives } diff --git a/core/src/main/java/ch/dissem/bitmessage/BitmessageContext.java b/core/src/main/java/ch/dissem/bitmessage/BitmessageContext.java index 28e8483..dbc08d3 100644 --- a/core/src/main/java/ch/dissem/bitmessage/BitmessageContext.java +++ b/core/src/main/java/ch/dissem/bitmessage/BitmessageContext.java @@ -200,6 +200,7 @@ public class BitmessageContext { LOG.info("Public key is missing from recipient. Requesting."); requestPubkey(msg.getFrom(), to); msg.setStatus(PUBKEY_REQUESTED); + msg.addLabels(ctx.getMessageRepository().getLabels(Label.Type.OUTBOX)); ctx.getMessageRepository().save(msg); } else { LOG.info("Sending message."); @@ -224,7 +225,7 @@ public class BitmessageContext { requestingIdentity, address, new GetPubkey(address), - +28 * DAY + +2 * DAY ); } diff --git a/core/src/main/java/ch/dissem/bitmessage/ProofOfWorkService.java b/core/src/main/java/ch/dissem/bitmessage/ProofOfWorkService.java index 19e231f..ecd1099 100644 --- a/core/src/main/java/ch/dissem/bitmessage/ProofOfWorkService.java +++ b/core/src/main/java/ch/dissem/bitmessage/ProofOfWorkService.java @@ -4,6 +4,7 @@ import ch.dissem.bitmessage.entity.BitmessageAddress; import ch.dissem.bitmessage.entity.ObjectMessage; import ch.dissem.bitmessage.entity.Plaintext; import ch.dissem.bitmessage.entity.PlaintextHolder; +import ch.dissem.bitmessage.entity.payload.Pubkey; import ch.dissem.bitmessage.ports.MessageRepository; import ch.dissem.bitmessage.ports.ProofOfWorkEngine; import ch.dissem.bitmessage.ports.ProofOfWorkRepository; @@ -42,10 +43,10 @@ public class ProofOfWorkService implements ProofOfWorkEngine.Callback, InternalC } public void doProofOfWork(BitmessageAddress recipient, ObjectMessage object) { - long nonceTrialsPerByte = recipient == null ? - ctx.getNetworkNonceTrialsPerByte() : recipient.getPubkey().getNonceTrialsPerByte(); - long extraBytes = recipient == null ? - ctx.getNetworkExtraBytes() : recipient.getPubkey().getExtraBytes(); + Pubkey pubkey = recipient == null ? null : recipient.getPubkey(); + + long nonceTrialsPerByte = pubkey == null ? ctx.getNetworkNonceTrialsPerByte() : pubkey.getNonceTrialsPerByte(); + long extraBytes = pubkey == null ? ctx.getNetworkExtraBytes() : pubkey.getExtraBytes(); powRepo.putObject(object, nonceTrialsPerByte, extraBytes); if (object.getPayload() instanceof PlaintextHolder) { diff --git a/core/src/main/java/ch/dissem/bitmessage/entity/valueobject/Label.java b/core/src/main/java/ch/dissem/bitmessage/entity/valueobject/Label.java index 7c37973..02f0384 100644 --- a/core/src/main/java/ch/dissem/bitmessage/entity/valueobject/Label.java +++ b/core/src/main/java/ch/dissem/bitmessage/entity/valueobject/Label.java @@ -79,6 +79,7 @@ public class Label implements Serializable { INBOX, BROADCAST, DRAFT, + OUTBOX, SENT, UNREAD, TRASH diff --git a/repositories/src/main/java/ch/dissem/bitmessage/repository/JdbcAddressRepository.java b/repositories/src/main/java/ch/dissem/bitmessage/repository/JdbcAddressRepository.java index 337d50a..bf15a6a 100644 --- a/repositories/src/main/java/ch/dissem/bitmessage/repository/JdbcAddressRepository.java +++ b/repositories/src/main/java/ch/dissem/bitmessage/repository/JdbcAddressRepository.java @@ -152,13 +152,25 @@ public class JdbcAddressRepository extends JdbcHelper implements AddressReposito private void update(BitmessageAddress address) throws IOException, SQLException { try (Connection connection = config.getConnection()) { - PreparedStatement ps = connection.prepareStatement( - "UPDATE Address SET alias=?, public_key=?, private_key=?, subscribed=? WHERE address=?"); - ps.setString(1, address.getAlias()); - writePubkey(ps, 2, address.getPubkey()); - writeBlob(ps, 3, address.getPrivateKey()); - ps.setBoolean(4, address.isSubscribed()); - ps.setString(5, address.getAddress()); + StringBuilder statement = new StringBuilder("UPDATE Address SET alias=?"); + if (address.getPubkey() != null) { + statement.append(", public_key=?"); + } + if (address.getPrivateKey() != null) { + statement.append(", private_key=?"); + } + statement.append(", subscribed=? WHERE address=?"); + PreparedStatement ps = connection.prepareStatement(statement.toString()); + int i = 0; + ps.setString(++i, address.getAlias()); + if (address.getPubkey() != null) { + writePubkey(ps, ++i, address.getPubkey()); + } + if (address.getPrivateKey() != null) { + writeBlob(ps, ++i, address.getPrivateKey()); + } + ps.setBoolean(++i, address.isSubscribed()); + ps.setString(++i, address.getAddress()); ps.executeUpdate(); } } diff --git a/repositories/src/test/java/ch/dissem/bitmessage/repository/JdbcAddressRepositoryTest.java b/repositories/src/test/java/ch/dissem/bitmessage/repository/JdbcAddressRepositoryTest.java index 18fc83c..18e70b2 100644 --- a/repositories/src/test/java/ch/dissem/bitmessage/repository/JdbcAddressRepositoryTest.java +++ b/repositories/src/test/java/ch/dissem/bitmessage/repository/JdbcAddressRepositoryTest.java @@ -128,6 +128,17 @@ public class JdbcAddressRepositoryTest extends TestBase { assertEquals("Test-Alias", address.getAlias()); } + @Test + public void ensureExistingKeysAreNotDeleted() { + BitmessageAddress address = new BitmessageAddress(IDENTITY_A); + address.setAlias("Test"); + repo.save(address); + BitmessageAddress identityA = repo.getAddress(IDENTITY_A); + assertNotNull(identityA.getPubkey()); + assertNotNull(identityA.getPrivateKey()); + assertEquals("Test", identityA.getAlias()); + } + @Test public void testRemove() throws Exception { BitmessageAddress address = repo.getAddress(IDENTITY_A);