From 71e1dd9acb633ab03eef0968d4ea1fdb50107a81 Mon Sep 17 00:00:00 2001 From: akwizgran <michael@briarproject.org> Date: Fri, 1 Mar 2013 22:13:08 +0000 Subject: [PATCH] Changed database cleaning constants to suit smaller devices. --- .../api/messaging/MessagingConstants.java | 6 ++++++ .../net/sf/briar/db/DatabaseCleanerImpl.java | 1 + .../sf/briar/db/DatabaseComponentImpl.java | 7 ++++++- .../net/sf/briar/db/DatabaseConstants.java | 20 ++++--------------- .../src/net/sf/briar/db/JdbcDatabase.java | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/briar-api/src/net/sf/briar/api/messaging/MessagingConstants.java b/briar-api/src/net/sf/briar/api/messaging/MessagingConstants.java index 5790af212c..5f3f93ac28 100644 --- a/briar-api/src/net/sf/briar/api/messaging/MessagingConstants.java +++ b/briar-api/src/net/sf/briar/api/messaging/MessagingConstants.java @@ -44,4 +44,10 @@ public interface MessagingConstants { /** The length of a message's random salt in bytes. */ int SALT_LENGTH = 8; + + /** + * The timestamp of the oldest message in the database is rounded using + * this modulus to avoid revealing the presence of any particular message. + */ + long RETENTION_MODULUS = 60 * 60 * 1000; // 1 hour } diff --git a/briar-core/src/net/sf/briar/db/DatabaseCleanerImpl.java b/briar-core/src/net/sf/briar/db/DatabaseCleanerImpl.java index f2720b1b31..8ede59d187 100644 --- a/briar-core/src/net/sf/briar/db/DatabaseCleanerImpl.java +++ b/briar-core/src/net/sf/briar/db/DatabaseCleanerImpl.java @@ -39,6 +39,7 @@ class DatabaseCleanerImpl extends TimerTask implements DatabaseCleaner { if(callback == null) throw new IllegalStateException(); try { if(callback.shouldCheckFreeSpace()) { + if(LOG.isLoggable(INFO)) LOG.info("Checking free space"); callback.checkFreeSpaceAndClean(); } } catch(DbClosedException e) { diff --git a/briar-core/src/net/sf/briar/db/DatabaseComponentImpl.java b/briar-core/src/net/sf/briar/db/DatabaseComponentImpl.java index 5456d37971..24633f9009 100644 --- a/briar-core/src/net/sf/briar/db/DatabaseComponentImpl.java +++ b/briar-core/src/net/sf/briar/db/DatabaseComponentImpl.java @@ -1,5 +1,6 @@ package net.sf.briar.db; +import static java.util.logging.Level.INFO; import static java.util.logging.Level.WARNING; import static net.sf.briar.api.Rating.GOOD; import static net.sf.briar.db.DatabaseConstants.BYTES_PER_SWEEP; @@ -84,6 +85,7 @@ DatabaseCleaner.Callback { private static final Logger LOG = Logger.getLogger(DatabaseComponentImpl.class.getName()); + private static final int MS_BETWEEN_SWEEPS = 10 * 1000; // 10 seconds /* * Locks must always be acquired in alphabetical order. See the Database @@ -135,7 +137,7 @@ DatabaseCleaner.Callback { if(open) throw new IllegalStateException(); open = true; db.open(resume); - cleaner.startCleaning(this, MAX_MS_BETWEEN_SPACE_CHECKS); + cleaner.startCleaning(this, MS_BETWEEN_SWEEPS); shutdownHandle = shutdown.addShutdownHook(new Runnable() { public void run() { try { @@ -1802,6 +1804,7 @@ DatabaseCleaner.Callback { public void checkFreeSpaceAndClean() throws DbException { long freeSpace = db.getFreeSpace(); + if(LOG.isLoggable(INFO)) LOG.info(freeSpace + " bytes free space"); while(freeSpace < MIN_FREE_SPACE) { boolean expired = expireMessages(BYTES_PER_SWEEP); if(freeSpace < CRITICAL_FREE_SPACE && !expired) { @@ -1832,6 +1835,8 @@ DatabaseCleaner.Callback { for(MessageId m : old) removeMessage(txn, m); db.incrementRetentionVersions(txn); removed = true; + if(LOG.isLoggable(INFO)) + LOG.info("Expired " + old.size() + " messages"); } db.commitTransaction(txn); } catch(DbException e) { diff --git a/briar-core/src/net/sf/briar/db/DatabaseConstants.java b/briar-core/src/net/sf/briar/db/DatabaseConstants.java index ac31535e14..4a8a5dfeb5 100644 --- a/briar-core/src/net/sf/briar/db/DatabaseConstants.java +++ b/briar-core/src/net/sf/briar/db/DatabaseConstants.java @@ -9,20 +9,20 @@ interface DatabaseConstants { * device where the database is stored. Whenever less than this much space * is free, old messages will be expired from the database. */ - long MIN_FREE_SPACE = 300 * 1024 * 1024; // 300 MiB + long MIN_FREE_SPACE = 50 * 1024 * 1024; // 50 MiB /** * The minimum amount of space in bytes that must be kept free on the device * where the database is stored. If less than this much space is free and * there are no more messages to expire, an Error will be thrown. */ - long CRITICAL_FREE_SPACE = 100 * 1024 * 1024; // 100 MiB + long CRITICAL_FREE_SPACE = 10 * 1024 * 1024; // 10 MiB /** * The amount of free space will be checked whenever this many bytes of * messages have been added to the database since the last check. */ - int MAX_BYTES_BETWEEN_SPACE_CHECKS = 5 * 1024 * 1024; // 5 MiB + int MAX_BYTES_BETWEEN_SPACE_CHECKS = 1024 * 1024; // 1 MiB /** * The amount of free space will be checked whenever this many milliseconds @@ -34,17 +34,5 @@ interface DatabaseConstants { * Up to this many bytes of messages will be expired from the database each * time it is necessary to expire messages. */ - int BYTES_PER_SWEEP = 5 * 1024 * 1024; // 5 MiB - - /** - * The timestamp of the oldest message in the database is rounded using - * this modulus to avoid revealing the presence of any particular message. - */ - long RETENTION_MODULUS = 60 * 60 * 1000; // 1 hour - - /** - * The time in milliseconds after which a subscription or transport update - * should be sent to a contact even if no changes have occurred. - */ - long MAX_UPDATE_INTERVAL = 12 * 60 * 60 * 1000; // 12 hours + int BYTES_PER_SWEEP = 10 * 1024 * 1024; // 10 MiB } diff --git a/briar-core/src/net/sf/briar/db/JdbcDatabase.java b/briar-core/src/net/sf/briar/db/JdbcDatabase.java index 6f242d906f..e7611872fe 100644 --- a/briar-core/src/net/sf/briar/db/JdbcDatabase.java +++ b/briar-core/src/net/sf/briar/db/JdbcDatabase.java @@ -6,7 +6,7 @@ import static java.util.logging.Level.INFO; import static java.util.logging.Level.WARNING; import static net.sf.briar.api.Rating.UNRATED; import static net.sf.briar.api.messaging.MessagingConstants.MAX_SUBSCRIPTIONS; -import static net.sf.briar.db.DatabaseConstants.RETENTION_MODULUS; +import static net.sf.briar.api.messaging.MessagingConstants.RETENTION_MODULUS; import static net.sf.briar.db.ExponentialBackoff.calculateExpiry; import java.io.File; -- GitLab