diff --git a/core/src/main/java/ch/dissem/bitmessage/utils/TTL.java b/core/src/main/java/ch/dissem/bitmessage/utils/TTL.java index 17e31e5..d1feb8a 100644 --- a/core/src/main/java/ch/dissem/bitmessage/utils/TTL.java +++ b/core/src/main/java/ch/dissem/bitmessage/utils/TTL.java @@ -3,9 +3,8 @@ 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. + * Stores times to live in seconds 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 */ @@ -19,7 +18,7 @@ public class TTL { } public static void msg(long msg) { - TTL.msg = msg; + TTL.msg = validate(msg); } public static long getpubkey() { @@ -27,7 +26,7 @@ public class TTL { } public static void getpubkey(long getpubkey) { - TTL.getpubkey = getpubkey; + TTL.getpubkey = validate(getpubkey); } public static long pubkey() { @@ -35,6 +34,11 @@ public class TTL { } public static void pubkey(long pubkey) { - TTL.pubkey = pubkey; + TTL.pubkey = validate(pubkey); + } + + private static long validate(long ttl) { + if (ttl < 0 || ttl > 28 * DAY) throw new IllegalArgumentException("TTL must be between 1 and 28 days"); + return ttl; } }