Made TTLs easily changeable (albeit not for specific messages)
This should make the system test run on Travis CI again
This commit is contained in:
@ -28,6 +28,7 @@ import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
|
||||
import ch.dissem.bitmessage.exception.DecryptionFailedException;
|
||||
import ch.dissem.bitmessage.ports.*;
|
||||
import ch.dissem.bitmessage.utils.Property;
|
||||
import ch.dissem.bitmessage.utils.TTL;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -168,7 +169,7 @@ public class BitmessageContext {
|
||||
msg.getFrom(),
|
||||
to,
|
||||
new Msg(msg),
|
||||
+2 * DAY
|
||||
TTL.msg()
|
||||
);
|
||||
msg.setStatus(SENT);
|
||||
msg.addLabels(ctx.getMessageRepository().getLabels(Label.Type.SENT));
|
||||
@ -288,7 +289,6 @@ public class BitmessageContext {
|
||||
int connectionLimit = 150;
|
||||
long connectionTTL = 30 * MINUTE;
|
||||
boolean sendPubkeyOnIdentityCreation = true;
|
||||
long pubkeyTTL = 28;
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
@ -383,7 +383,7 @@ public class BitmessageContext {
|
||||
*/
|
||||
public Builder pubkeyTTL(long days) {
|
||||
if (days < 0 || days > 28 * DAY) throw new IllegalArgumentException("TTL must be between 1 and 28 days");
|
||||
this.pubkeyTTL = days;
|
||||
TTL.pubkey(days);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ import ch.dissem.bitmessage.entity.ObjectMessage;
|
||||
import ch.dissem.bitmessage.entity.payload.*;
|
||||
import ch.dissem.bitmessage.ports.*;
|
||||
import ch.dissem.bitmessage.utils.Singleton;
|
||||
import ch.dissem.bitmessage.utils.TTL;
|
||||
import ch.dissem.bitmessage.utils.UnixTime;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -58,7 +59,6 @@ public class InternalContext {
|
||||
private final long clientNonce;
|
||||
private final long networkNonceTrialsPerByte = 1000;
|
||||
private final long networkExtraBytes = 1000;
|
||||
private final long pubkeyTTL;
|
||||
private long connectionTTL;
|
||||
private int connectionLimit;
|
||||
|
||||
@ -78,7 +78,6 @@ public class InternalContext {
|
||||
this.port = builder.port;
|
||||
this.connectionLimit = builder.connectionLimit;
|
||||
this.connectionTTL = builder.connectionTTL;
|
||||
this.pubkeyTTL = builder.pubkeyTTL;
|
||||
|
||||
Singleton.initialize(cryptography);
|
||||
|
||||
@ -194,7 +193,7 @@ public class InternalContext {
|
||||
|
||||
public void sendPubkey(final BitmessageAddress identity, final long targetStream) {
|
||||
try {
|
||||
long expires = UnixTime.now(pubkeyTTL);
|
||||
long expires = UnixTime.now(TTL.pubkey());
|
||||
LOG.info("Expires at " + expires);
|
||||
final ObjectMessage response = new ObjectMessage.Builder()
|
||||
.stream(targetStream)
|
||||
@ -233,7 +232,7 @@ public class InternalContext {
|
||||
addressRepository.save(contact);
|
||||
}
|
||||
|
||||
long expires = UnixTime.now(+pubkeyTTL);
|
||||
long expires = UnixTime.now(TTL.getpubkey());
|
||||
LOG.info("Expires at " + expires);
|
||||
final ObjectMessage request = new ObjectMessage.Builder()
|
||||
.stream(contact.getStream())
|
||||
|
40
core/src/main/java/ch/dissem/bitmessage/utils/TTL.java
Normal file
40
core/src/main/java/ch/dissem/bitmessage/utils/TTL.java
Normal file
@ -0,0 +1,40 @@
|
||||
package ch.dissem.bitmessage.utils;
|
||||
|
||||
import static ch.dissem.bitmessage.utils.UnixTime.DAY;
|
||||
|
||||
/**
|
||||
* Stores times to live for different object types. Usually this shouldn't be messed with,
|
||||
* but for tests it might be a good idea to reduce it to a minimum, and on mobile clients
|
||||
* you might want to optimize it as well.
|
||||
*
|
||||
* @author Christian Basler
|
||||
*/
|
||||
public class TTL {
|
||||
private static long msg = 2 * DAY;
|
||||
private static long getpubkey = 2 * DAY;
|
||||
private static long pubkey = 28 * DAY;
|
||||
|
||||
public static long msg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static void msg(long msg) {
|
||||
TTL.msg = msg;
|
||||
}
|
||||
|
||||
public static long getpubkey() {
|
||||
return getpubkey;
|
||||
}
|
||||
|
||||
public static void getpubkey(long getpubkey) {
|
||||
TTL.getpubkey = getpubkey;
|
||||
}
|
||||
|
||||
public static long pubkey() {
|
||||
return pubkey;
|
||||
}
|
||||
|
||||
public static void pubkey(long pubkey) {
|
||||
TTL.pubkey = pubkey;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user