Replaced last connection time with time of last private message.

This commit is contained in:
akwizgran
2014-04-05 18:14:07 +01:00
parent 3d9f5c496f
commit 839f67dd44
11 changed files with 27 additions and 154 deletions

View File

@@ -326,14 +326,6 @@ interface Database<T> {
Collection<MessageHeader> getInboxMessageHeaders(T txn, ContactId c)
throws DbException;
/**
* Returns the time at which a connection to each contact was last opened
* or closed.
* <p>
* Locking: window read.
*/
Map<ContactId, Long> getLastConnected(T txn) throws DbException;
/**
* Returns the local pseudonym with the given ID.
* <p>
@@ -732,13 +724,6 @@ interface Database<T> {
*/
public void setInboxGroup(T txn, ContactId c, Group g) throws DbException;
/**
* Sets the time at which a connection to the given contact was last made.
* <p>
* Locking: window write.
*/
void setLastConnected(T txn, ContactId c, long now) throws DbException;
/**
* Marks a message as read or unread.
* <p>

View File

@@ -77,7 +77,6 @@ import org.briarproject.api.messaging.SubscriptionAck;
import org.briarproject.api.messaging.SubscriptionUpdate;
import org.briarproject.api.messaging.TransportAck;
import org.briarproject.api.messaging.TransportUpdate;
import org.briarproject.api.system.Clock;
import org.briarproject.api.transport.Endpoint;
import org.briarproject.api.transport.TemporarySecret;
@@ -119,7 +118,6 @@ DatabaseCleaner.Callback {
private final Database<T> db;
private final DatabaseCleaner cleaner;
private final ShutdownManager shutdown;
private final Clock clock;
private final Collection<EventListener> listeners =
new CopyOnWriteArrayList<EventListener>();
@@ -130,11 +128,10 @@ DatabaseCleaner.Callback {
@Inject
DatabaseComponentImpl(Database<T> db, DatabaseCleaner cleaner,
ShutdownManager shutdown, Clock clock) {
ShutdownManager shutdown) {
this.db = db;
this.cleaner = cleaner;
this.shutdown = shutdown;
this.clock = clock;
}
public boolean open() throws DbException, IOException {
@@ -965,23 +962,6 @@ DatabaseCleaner.Callback {
}
}
public Map<ContactId, Long> getLastConnected() throws DbException {
windowLock.readLock().lock();
try {
T txn = db.startTransaction();
try {
Map<ContactId, Long> times = db.getLastConnected(txn);
db.commitTransaction(txn);
return times;
} catch(DbException e) {
db.abortTransaction(txn);
throw e;
}
} finally {
windowLock.readLock().unlock();
}
}
public LocalAuthor getLocalAuthor(AuthorId a) throws DbException {
identityLock.readLock().lock();
try {
@@ -1244,10 +1224,6 @@ DatabaseCleaner.Callback {
throw new NoSuchTransportException();
long counter = db.incrementConnectionCounter(txn, c, t,
period);
if(counter != -1) {
long now = clock.currentTimeMillis();
db.setLastConnected(txn, c, now);
}
db.commitTransaction(txn);
return counter;
} catch(DbException e) {
@@ -1802,7 +1778,6 @@ DatabaseCleaner.Callback {
throw new NoSuchTransportException();
db.setConnectionWindow(txn, c, t, period, centre,
bitmap);
db.setLastConnected(txn, c, clock.currentTimeMillis());
db.commitTransaction(txn);
} catch(DbException e) {
db.abortTransaction(txn);

View File

@@ -17,7 +17,6 @@ import org.briarproject.api.db.DatabaseConfig;
import org.briarproject.api.db.DatabaseExecutor;
import org.briarproject.api.lifecycle.LifecycleManager;
import org.briarproject.api.lifecycle.ShutdownManager;
import org.briarproject.api.system.Clock;
import org.briarproject.api.system.FileUtils;
import org.briarproject.system.SystemClock;
@@ -54,9 +53,8 @@ public class DatabaseModule extends AbstractModule {
@Provides @Singleton
DatabaseComponent getDatabaseComponent(Database<Connection> db,
DatabaseCleaner cleaner, ShutdownManager shutdown, Clock clock) {
return new DatabaseComponentImpl<Connection>(db, cleaner, shutdown,
clock);
DatabaseCleaner cleaner, ShutdownManager shutdown) {
return new DatabaseComponentImpl<Connection>(db, cleaner, shutdown);
}
@Provides @Singleton @DatabaseExecutor

View File

@@ -62,7 +62,7 @@ import org.briarproject.api.transport.TemporarySecret;
*/
abstract class JdbcDatabase implements Database<Connection> {
private static final int SCHEMA_VERSION = 5;
private static final int SCHEMA_VERSION = 6;
private static final int MIN_SCHEMA_VERSION = 5;
private static final String CREATE_SETTINGS =
@@ -326,16 +326,6 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " REFERENCES transports (transportId)"
+ " ON DELETE CASCADE)";
// Locking: window
private static final String CREATE_CONNECTION_TIMES =
"CREATE TABLE connectionTimes"
+ " (contactId INT NOT NULL,"
+ " lastConnected BIGINT NOT NULL,"
+ " PRIMARY KEY (contactId),"
+ " FOREIGN KEY (contactId)"
+ " REFERENCES contacts (contactId)"
+ " ON DELETE CASCADE)";
private static final Logger LOG =
Logger.getLogger(JdbcDatabase.class.getName());
@@ -445,7 +435,6 @@ abstract class JdbcDatabase implements Database<Connection> {
s.executeUpdate(insertTypeNames(CREATE_CONTACT_TRANSPORT_VERSIONS));
s.executeUpdate(insertTypeNames(CREATE_ENDPOINTS));
s.executeUpdate(insertTypeNames(CREATE_SECRETS));
s.executeUpdate(insertTypeNames(CREATE_CONNECTION_TIMES));
s.close();
} catch(SQLException e) {
tryToClose(s);
@@ -633,15 +622,6 @@ abstract class JdbcDatabase implements Database<Connection> {
}
ps.close();
}
// Create a connection time row
sql = "INSERT INTO connectionTimes (contactId, lastConnected)"
+ " VALUES (?, ?)";
ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt());
ps.setLong(2, clock.currentTimeMillis());
affected = ps.executeUpdate();
if(affected != 1) throw new DbStateException();
ps.close();
// Create a retention version row
sql = "INSERT INTO retentionVersions (contactId, retention,"
+ " localVersion, localAcked, remoteVersion, remoteAcked,"
@@ -1525,27 +1505,6 @@ abstract class JdbcDatabase implements Database<Connection> {
}
}
public Map<ContactId, Long> getLastConnected(Connection txn)
throws DbException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
String sql = "SELECT contactId, lastConnected FROM connectionTimes";
ps = txn.prepareStatement(sql);
rs = ps.executeQuery();
Map<ContactId, Long> times = new HashMap<ContactId, Long>();
while(rs.next())
times.put(new ContactId(rs.getInt(1)), rs.getLong(2));
rs.close();
ps.close();
return Collections.unmodifiableMap(times);
} catch(SQLException e) {
tryToClose(rs);
tryToClose(ps);
throw new DbException(e);
}
}
public LocalAuthor getLocalAuthor(Connection txn, AuthorId a)
throws DbException {
PreparedStatement ps = null;
@@ -3087,24 +3046,6 @@ abstract class JdbcDatabase implements Database<Connection> {
}
}
public void setLastConnected(Connection txn, ContactId c, long now)
throws DbException {
PreparedStatement ps = null;
try {
String sql = "UPDATE connectionTimes SET lastConnected = ?"
+ " WHERE contactId = ?";
ps = txn.prepareStatement(sql);
ps.setLong(1, now);
ps.setInt(2, c.getInt());
int affected = ps.executeUpdate();
if(affected < 0 || affected > 1) throw new DbStateException();
ps.close();
} catch(SQLException e) {
tryToClose(ps);
throw new DbException(e);
}
}
public void setReadFlag(Connection txn, MessageId m, boolean read)
throws DbException {
PreparedStatement ps = null;