Renamed some methods, fixed SQL typo bugs in JdbcDatabase.

This commit is contained in:
akwizgran
2013-01-29 16:43:13 +00:00
parent 61a6931643
commit 7ecda94340
14 changed files with 113 additions and 121 deletions

View File

@@ -9,7 +9,8 @@ public class RetentionAck {
this.version = version; this.version = version;
} }
public long getVersionNumber() { /** Returns the version number of the acknowledged update. */
public long getVersion() {
return version; return version;
} }
} }

View File

@@ -17,7 +17,7 @@ public class RetentionUpdate {
return retention; return retention;
} }
public long getVersionNumber() { public long getVersion() {
return version; return version;
} }
} }

View File

@@ -10,7 +10,7 @@ public class SubscriptionAck {
} }
/** Returns the version number of the acknowledged update. */ /** Returns the version number of the acknowledged update. */
public long getVersionNumber() { public long getVersion() {
return version; return version;
} }
} }

View File

@@ -22,7 +22,7 @@ public class SubscriptionUpdate {
} }
/** Returns the update's version number. */ /** Returns the update's version number. */
public long getVersionNumber() { public long getVersion() {
return version; return version;
} }
} }

View File

@@ -17,7 +17,7 @@ public class TransportAck {
} }
/** Returns the version number of the acknowledged update. */ /** Returns the version number of the acknowledged update. */
public long getVersionNumber() { public long getVersion() {
return version; return version;
} }
} }

View File

@@ -29,7 +29,7 @@ public class TransportUpdate {
} }
/** Returns the update's version number. */ /** Returns the update's version number. */
public long getVersionNumber() { public long getVersion() {
return version; return version;
} }
} }

View File

@@ -571,8 +571,8 @@ interface Database<T> {
* <p> * <p>
* Locking: contact read, transport write. * Locking: contact read, transport write.
*/ */
void setRemoteProperties(T txn, ContactId c, TransportUpdate u) void setRemoteProperties(T txn, ContactId c, TransportId t,
throws DbException; TransportProperties p, long version) throws DbException;
/** /**
* Sets the retention time of the given contact's database, unless an * Sets the retention time of the given contact's database, unless an
@@ -625,8 +625,8 @@ interface Database<T> {
* <p> * <p>
* Locking: contact read, subscription write. * Locking: contact read, subscription write.
*/ */
void setSubscriptions(T txn, ContactId c, SubscriptionUpdate u) void setSubscriptions(T txn, ContactId c, Collection<Group> subs,
throws DbException; long version) throws DbException;
/** /**
* Records a retention ack from the given contact for the given version * Records a retention ack from the given contact for the given version

View File

@@ -1207,7 +1207,7 @@ DatabaseCleaner.Callback {
try { try {
if(!db.containsContact(txn, c)) if(!db.containsContact(txn, c))
throw new NoSuchContactException(); throw new NoSuchContactException();
db.setRetentionUpdateAcked(txn, c, a.getVersionNumber()); db.setRetentionUpdateAcked(txn, c, a.getVersion());
db.commitTransaction(txn); db.commitTransaction(txn);
} catch(DbException e) { } catch(DbException e) {
db.abortTransaction(txn); db.abortTransaction(txn);
@@ -1232,7 +1232,7 @@ DatabaseCleaner.Callback {
if(!db.containsContact(txn, c)) if(!db.containsContact(txn, c))
throw new NoSuchContactException(); throw new NoSuchContactException();
db.setRetentionTime(txn, c, u.getRetentionTime(), db.setRetentionTime(txn, c, u.getRetentionTime(),
u.getVersionNumber()); u.getVersion());
db.commitTransaction(txn); db.commitTransaction(txn);
} catch(DbException e) { } catch(DbException e) {
db.abortTransaction(txn); db.abortTransaction(txn);
@@ -1257,7 +1257,7 @@ DatabaseCleaner.Callback {
try { try {
if(!db.containsContact(txn, c)) if(!db.containsContact(txn, c))
throw new NoSuchContactException(); throw new NoSuchContactException();
db.setSubscriptionUpdateAcked(txn, c, a.getVersionNumber()); db.setSubscriptionUpdateAcked(txn, c, a.getVersion());
db.commitTransaction(txn); db.commitTransaction(txn);
} catch(DbException e) { } catch(DbException e) {
db.abortTransaction(txn); db.abortTransaction(txn);
@@ -1281,7 +1281,7 @@ DatabaseCleaner.Callback {
try { try {
if(!db.containsContact(txn, c)) if(!db.containsContact(txn, c))
throw new NoSuchContactException(); throw new NoSuchContactException();
db.setSubscriptions(txn, c, u); db.setSubscriptions(txn, c, u.getGroups(), u.getVersion());
db.commitTransaction(txn); db.commitTransaction(txn);
} catch(DbException e) { } catch(DbException e) {
db.abortTransaction(txn); db.abortTransaction(txn);
@@ -1309,7 +1309,7 @@ DatabaseCleaner.Callback {
TransportId t = a.getId(); TransportId t = a.getId();
if(!db.containsTransport(txn, t)) if(!db.containsTransport(txn, t))
throw new NoSuchTransportException(); throw new NoSuchTransportException();
db.setTransportUpdateAcked(txn, c, t, a.getVersionNumber()); db.setTransportUpdateAcked(txn, c, t, a.getVersion());
db.commitTransaction(txn); db.commitTransaction(txn);
} catch(DbException e) { } catch(DbException e) {
db.abortTransaction(txn); db.abortTransaction(txn);
@@ -1333,7 +1333,8 @@ DatabaseCleaner.Callback {
try { try {
if(!db.containsContact(txn, c)) if(!db.containsContact(txn, c))
throw new NoSuchContactException(); throw new NoSuchContactException();
db.setRemoteProperties(txn, c, u); db.setRemoteProperties(txn, c, u.getId(), u.getProperties(),
u.getVersion());
db.commitTransaction(txn); db.commitTransaction(txn);
} catch(DbException e) { } catch(DbException e) {
db.abortTransaction(txn); db.abortTransaction(txn);

View File

@@ -54,9 +54,52 @@ abstract class JdbcDatabase implements Database<Connection> {
// Locking: contact // Locking: contact
private static final String CREATE_CONTACTS = private static final String CREATE_CONTACTS =
"CREATE TABLE contacts" "CREATE TABLE contacts (contactId COUNTER)";
+ " (contactId COUNTER,"
+ " PRIMARY KEY (contactId))"; // Locking: subscription
private static final String CREATE_GROUPS =
"CREATE TABLE groups"
+ " (groupId HASH NOT NULL,"
+ " name VARCHAR NOT NULL,"
+ " key BINARY," // Null for unrestricted groups
+ " PRIMARY KEY (groupId))";
// Locking: contact read, subscription
private static final String CREATE_GROUP_VISIBILITIES =
"CREATE TABLE groupVisibilities"
+ " (contactId INT NOT NULL,"
+ " groupId HASH NOT NULL,"
+ " FOREIGN KEY (contactId)"
+ " REFERENCES contacts (contactId)"
+ " ON DELETE CASCADE,"
+ " FOREIGN KEY (groupId)"
+ " REFERENCES groups (groupId)"
+ " ON DELETE CASCADE)";
// Locking: contact read, subscription
private static final String CREATE_CONTACT_GROUPS =
"CREATE TABLE contactGroups"
+ " (contactId INT NOT NULL,"
+ " groupId HASH NOT NULL," // Not a foreign key
+ " name VARCHAR NOT NULL,"
+ " key BINARY," // Null for unrestricted groups
+ " PRIMARY KEY (contactId, groupId),"
+ " FOREIGN KEY (contactId)"
+ " REFERENCES contacts (contactId)"
+ " ON DELETE CASCADE)";
// Locking: contact read, subscription
private static final String CREATE_GROUP_VERSIONS =
"CREATE TABLE groupVersions"
+ " (contactId INT NOT NULL,"
+ " localVersion BIGINT NOT NULL,"
+ " localAcked BIGINT NOT NULL,"
+ " remoteVersion BIGINT NOT NULL,"
+ " remoteAcked BOOLEAN NOT NULL,"
+ " PRIMARY KEY (contactId),"
+ " FOREIGN KEY (contactid)"
+ " REFERENCES contacts (contactId)"
+ " ON DELETE CASCADE)";
// Locking: message // Locking: message
private static final String CREATE_MESSAGES = private static final String CREATE_MESSAGES =
@@ -155,56 +198,9 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " REFERENCES contacts (contactId)" + " REFERENCES contacts (contactId)"
+ " ON DELETE CASCADE)"; + " ON DELETE CASCADE)";
// Locking: subscription
private static final String CREATE_GROUPS =
"CREATE TABLE groups"
+ " (groupId HASH NOT NULL,"
+ " name VARCHAR NOT NULL,"
+ " key BINARY," // Null for unrestricted groups
+ " PRIMARY KEY (groupId))";
// Locking: contact read, subscription
private static final String CREATE_GROUP_VISIBILITIES =
"CREATE TABLE groupVisibilities"
+ " (contactId INT NOT NULL,"
+ " groupId HASH NOT NULL,"
+ " FOREIGN KEY (contactId)"
+ " REFERENCES contacts (contactId)"
+ " ON DELETE CASCADE,"
+ " FOREIGN KEY (groupId)"
+ " REFERENCES groups (groupId)"
+ " ON DELETE CASCADE)";
// Locking: contact read, subscription
private static final String CREATE_CONTACT_GROUPS =
"CREATE TABLE contactGroups"
+ " (contactId INT NOT NULL,"
+ " groupId HASH NOT NULL," // Not a foreign key
+ " name VARCHAR NOT NULL,"
+ " key BINARY," // Null for unrestricted groups
+ " PRIMARY KEY (contactId, groupId),"
+ " FOREIGN KEY (contactId)"
+ " REFERENCES contacts (contactId)"
+ " ON DELETE CASCADE)";
// Locking: contact read, subscription
private static final String CREATE_GROUP_VERSIONS =
"CREATE TABLE groupVersions"
+ " (contactId INT NOT NULL,"
+ " localVersion BIGINT NOT NULL,"
+ " localAcked BIGINT NOT NULL,"
+ " remoteVersion BIGINT NOT NULL,"
+ " remoteAcked BOOLEAN NOT NULL,"
+ " PRIMARY KEY (contactId),"
+ " FOREIGN KEY (contactid)"
+ " REFERENCES contacts (contactId)"
+ " ON DELETE CASCADE)";
// Locking: transport // Locking: transport
private static final String CREATE_TRANSPORTS = private static final String CREATE_TRANSPORTS =
"CREATE TABLE transports" "CREATE TABLE transports (transportId HASH NOT NULL)";
+ " (transportId HASH NOT NULL,"
+ " PRIMARY KEY (transportId))";
// Locking: transport // Locking: transport
private static final String CREATE_TRANSPORT_CONFIGS = private static final String CREATE_TRANSPORT_CONFIGS =
@@ -355,6 +351,10 @@ abstract class JdbcDatabase implements Database<Connection> {
try { try {
s = txn.createStatement(); s = txn.createStatement();
s.executeUpdate(insertTypeNames(CREATE_CONTACTS)); s.executeUpdate(insertTypeNames(CREATE_CONTACTS));
s.executeUpdate(insertTypeNames(CREATE_GROUPS));
s.executeUpdate(insertTypeNames(CREATE_GROUP_VISIBILITIES));
s.executeUpdate(insertTypeNames(CREATE_CONTACT_GROUPS));
s.executeUpdate(insertTypeNames(CREATE_GROUP_VERSIONS));
s.executeUpdate(insertTypeNames(CREATE_MESSAGES)); s.executeUpdate(insertTypeNames(CREATE_MESSAGES));
s.executeUpdate(INDEX_MESSAGES_BY_PARENT); s.executeUpdate(INDEX_MESSAGES_BY_PARENT);
s.executeUpdate(INDEX_MESSAGES_BY_AUTHOR); s.executeUpdate(INDEX_MESSAGES_BY_AUTHOR);
@@ -367,10 +367,6 @@ abstract class JdbcDatabase implements Database<Connection> {
s.executeUpdate(insertTypeNames(CREATE_FLAGS)); s.executeUpdate(insertTypeNames(CREATE_FLAGS));
s.executeUpdate(insertTypeNames(CREATE_RATINGS)); s.executeUpdate(insertTypeNames(CREATE_RATINGS));
s.executeUpdate(insertTypeNames(CREATE_RETENTION_VERSIONS)); s.executeUpdate(insertTypeNames(CREATE_RETENTION_VERSIONS));
s.executeUpdate(insertTypeNames(CREATE_GROUPS));
s.executeUpdate(insertTypeNames(CREATE_GROUP_VISIBILITIES));
s.executeUpdate(insertTypeNames(CREATE_CONTACT_GROUPS));
s.executeUpdate(insertTypeNames(CREATE_GROUP_VERSIONS));
s.executeUpdate(insertTypeNames(CREATE_TRANSPORTS)); s.executeUpdate(insertTypeNames(CREATE_TRANSPORTS));
s.executeUpdate(insertTypeNames(CREATE_TRANSPORT_CONFIGS)); s.executeUpdate(insertTypeNames(CREATE_TRANSPORT_CONFIGS));
s.executeUpdate(insertTypeNames(CREATE_TRANSPORT_PROPS)); s.executeUpdate(insertTypeNames(CREATE_TRANSPORT_PROPS));
@@ -832,7 +828,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " VALUES (?, ?)"; + " VALUES (?, ?)";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
ps.setBytes(3, g.getBytes()); ps.setBytes(2, g.getBytes());
int affected = ps.executeUpdate(); int affected = ps.executeUpdate();
if(affected != 1) throw new DbStateException(); if(affected != 1) throw new DbStateException();
ps.close(); ps.close();
@@ -940,13 +936,11 @@ abstract class JdbcDatabase implements Database<Connection> {
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
String sql = "SELECT NULL FROM groups AS g" String sql = "SELECT NULL FROM groupVisibilities"
+ " JOIN groupVisibilities AS gv" + " WHERE contactId = ? AND groupId = ?";
+ " ON g.groupId = gv.groupId"
+ " WHERE g.groupId = ? AND contactId = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, g.getBytes()); ps.setInt(1, c.getInt());
ps.setInt(2, c.getInt()); ps.setBytes(2, g.getBytes());
rs = ps.executeQuery(); rs = ps.executeQuery();
boolean found = rs.next(); boolean found = rs.next();
if(rs.next()) throw new DbStateException(); if(rs.next()) throw new DbStateException();
@@ -1550,7 +1544,7 @@ abstract class JdbcDatabase implements Database<Connection> {
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
String sql = "SELECT ct.contactId, ct.transportId, epoch," String sql = "SELECT e.contactId, e.transportId, epoch,"
+ " clockDiff, latency, alice, period, secret, outgoing," + " clockDiff, latency, alice, period, secret, outgoing,"
+ " centre, bitmap" + " centre, bitmap"
+ " FROM endpoints AS e" + " FROM endpoints AS e"
@@ -1783,11 +1777,11 @@ abstract class JdbcDatabase implements Database<Connection> {
try { try {
String sql = "SELECT g.groupId, name, key, localVersion" String sql = "SELECT g.groupId, name, key, localVersion"
+ " FROM groups AS g" + " FROM groups AS g"
+ " JOIN groupVisibilities AS gv" + " JOIN groupVisibilities AS vis"
+ " ON g.groupId = gv.groupId" + " ON g.groupId = vis.groupId"
+ " JOIN groupVersions AS v" + " JOIN groupVersions AS ver"
+ " ON gv.contactId = v.contactId" + " ON vis.contactId = ver.contactId"
+ " WHERE gv.contactId = ?" + " WHERE vis.contactId = ?"
+ " AND localVersion > localAcked"; + " AND localVersion > localAcked";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
@@ -1971,7 +1965,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " JOIN groupVisibilities AS gv" + " JOIN groupVisibilities AS gv"
+ " ON m.groupId = gv.groupId" + " ON m.groupId = gv.groupId"
+ " AND cg.contactId = gv.contactId" + " AND cg.contactId = gv.contactId"
+ " JOIN retentionVersios AS rv" + " JOIN retentionVersions AS rv"
+ " ON cg.contactId = rv.contactId" + " ON cg.contactId = rv.contactId"
+ " JOIN statuses AS s" + " JOIN statuses AS s"
+ " ON m.messageId = s.messageId" + " ON m.messageId = s.messageId"
@@ -2461,12 +2455,11 @@ abstract class JdbcDatabase implements Database<Connection> {
} }
} }
public void setRemoteProperties(Connection txn, ContactId c, public void setRemoteProperties(Connection txn, ContactId c, TransportId t,
TransportUpdate u) throws DbException { TransportProperties p, long version) throws DbException {
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
TransportId t = u.getId();
// Find the existing version, if any // Find the existing version, if any
String sql = "SELECT remoteVersion FROM contactTransportVersions" String sql = "SELECT remoteVersion FROM contactTransportVersions"
+ " WHERE contactId = ? AND transportId = ?"; + " WHERE contactId = ? AND transportId = ?";
@@ -2474,12 +2467,12 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
ps.setBytes(2, t.getBytes()); ps.setBytes(2, t.getBytes());
rs = ps.executeQuery(); rs = ps.executeQuery();
long version = rs.next() ? rs.getLong(1) : -1L; long currentVersion = rs.next() ? rs.getLong(1) : -1L;
if(rs.next()) throw new DbStateException(); if(rs.next()) throw new DbStateException();
rs.close(); rs.close();
ps.close(); ps.close();
// Mark the update as needing to be acked // Mark the update as needing to be acked
if(version == -1L) { if(currentVersion == -1L) {
// The row doesn't exist - create it // The row doesn't exist - create it
sql = "INSERT INTO contactTransportVersions (contactId," sql = "INSERT INTO contactTransportVersions (contactId,"
+ " transportId, remoteVersion, remoteAcked)" + " transportId, remoteVersion, remoteAcked)"
@@ -2487,7 +2480,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
ps.setBytes(2, t.getBytes()); ps.setBytes(2, t.getBytes());
ps.setLong(3, u.getVersionNumber()); ps.setLong(3, version);
int affected = ps.executeUpdate(); int affected = ps.executeUpdate();
if(affected != 1) throw new DbStateException(); if(affected != 1) throw new DbStateException();
ps.close(); ps.close();
@@ -2495,16 +2488,18 @@ abstract class JdbcDatabase implements Database<Connection> {
// The row exists - update it // The row exists - update it
sql = "UPDATE contactTransportVersions" sql = "UPDATE contactTransportVersions"
+ " SET remoteVersion = ?, remoteAcked = FALSE" + " SET remoteVersion = ?, remoteAcked = FALSE"
+ " WHERE contactId = ? AND transportId = ?"; + " WHERE contactId = ? AND transportId = ?"
+ " AND remoteVersion < ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setLong(1, Math.max(version, u.getVersionNumber())); ps.setLong(1, version);
ps.setInt(1, c.getInt()); ps.setInt(2, c.getInt());
ps.setBytes(2, t.getBytes()); ps.setBytes(3, t.getBytes());
ps.setLong(4, version);
int affected = ps.executeUpdate(); int affected = ps.executeUpdate();
if(affected > 1) throw new DbStateException(); if(affected > 1) throw new DbStateException();
ps.close(); ps.close();
// Return if the update is obsolete // Return if the update is obsolete
if(u.getVersionNumber() <= version) return; if(version <= currentVersion) return;
} }
// Delete the existing properties, if any // Delete the existing properties, if any
sql = "DELETE FROM contactTransportProperties" sql = "DELETE FROM contactTransportProperties"
@@ -2515,7 +2510,6 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.executeUpdate(); ps.executeUpdate();
ps.close(); ps.close();
// Store the new properties, if any // Store the new properties, if any
TransportProperties p = u.getProperties();
if(p.isEmpty()) return; if(p.isEmpty()) return;
sql = "INSERT INTO contactTransportProperties" sql = "INSERT INTO contactTransportProperties"
+ " (contactId, transportId, key, value)" + " (contactId, transportId, key, value)"
@@ -2524,8 +2518,8 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
ps.setBytes(2, t.getBytes()); ps.setBytes(2, t.getBytes());
for(Entry<String, String> e : p.entrySet()) { for(Entry<String, String> e : p.entrySet()) {
ps.setString(1, e.getKey()); ps.setString(3, e.getKey());
ps.setString(2, e.getValue()); ps.setString(4, e.getValue());
ps.addBatch(); ps.addBatch();
} }
int[] batchAffected = ps.executeBatch(); int[] batchAffected = ps.executeBatch();
@@ -2701,7 +2695,7 @@ abstract class JdbcDatabase implements Database<Connection> {
} }
public void setSubscriptions(Connection txn, ContactId c, public void setSubscriptions(Connection txn, ContactId c,
SubscriptionUpdate u) throws DbException { Collection<Group> subs, long version) throws DbException {
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
@@ -2712,27 +2706,29 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
rs = ps.executeQuery(); rs = ps.executeQuery();
if(!rs.next()) throw new DbStateException(); if(!rs.next()) throw new DbStateException();
long version = rs.getLong(1); long currentVersion = rs.getLong(1);
if(rs.next()) throw new DbStateException(); if(rs.next()) throw new DbStateException();
rs.close(); rs.close();
ps.close(); ps.close();
// Mark the update as needing to be acked // Mark the update as needing to be acked
sql = "UPDATE groupVersions" sql = "UPDATE groupVersions"
+ " SET remoteVersion = ?, remoteAcked = FALSE" + " SET remoteVersion = ?, remoteAcked = FALSE"
+ " WHERE contactId = ?"; + " WHERE contactId = ? AND remoteVersion < ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setLong(1, Math.max(version, u.getVersionNumber())); ps.setLong(1, version);
ps.setInt(2, c.getInt()); ps.setInt(2, c.getInt());
ps.setLong(3, version);
int affected = ps.executeUpdate(); int affected = ps.executeUpdate();
if(affected > 1) throw new DbStateException(); if(affected > 1) throw new DbStateException();
ps.close(); ps.close();
// Return if the update is obsolete
if(version <= currentVersion) return;
// Delete the existing subscriptions, if any // Delete the existing subscriptions, if any
sql = "DELETE FROM contactGroups WHERE contactId = ?"; sql = "DELETE FROM contactGroups WHERE contactId = ?";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
ps.executeUpdate(); ps.executeUpdate();
// Store the new subscriptions, if any // Store the new subscriptions, if any
Collection<Group> subs = u.getGroups();
if(subs.isEmpty()) return; if(subs.isEmpty()) return;
sql = "INSERT INTO contactGroups (contactId, groupId, name, key)" sql = "INSERT INTO contactGroups (contactId, groupId, name, key)"
+ " VALUES (?, ?, ?, ?)"; + " VALUES (?, ?, ?, ?)";

View File

@@ -109,20 +109,20 @@ class ProtocolWriterImpl implements ProtocolWriter {
public void writeRetentionAck(RetentionAck a) throws IOException { public void writeRetentionAck(RetentionAck a) throws IOException {
w.writeStructId(RETENTION_ACK); w.writeStructId(RETENTION_ACK);
w.writeInt64(a.getVersionNumber()); w.writeInt64(a.getVersion());
if(flush) out.flush(); if(flush) out.flush();
} }
public void writeRetentionUpdate(RetentionUpdate u) throws IOException { public void writeRetentionUpdate(RetentionUpdate u) throws IOException {
w.writeStructId(RETENTION_UPDATE); w.writeStructId(RETENTION_UPDATE);
w.writeInt64(u.getRetentionTime()); w.writeInt64(u.getRetentionTime());
w.writeInt64(u.getVersionNumber()); w.writeInt64(u.getVersion());
if(flush) out.flush(); if(flush) out.flush();
} }
public void writeSubscriptionAck(SubscriptionAck a) throws IOException { public void writeSubscriptionAck(SubscriptionAck a) throws IOException {
w.writeStructId(SUBSCRIPTION_ACK); w.writeStructId(SUBSCRIPTION_ACK);
w.writeInt64(a.getVersionNumber()); w.writeInt64(a.getVersion());
if(flush) out.flush(); if(flush) out.flush();
} }
@@ -138,14 +138,14 @@ class ProtocolWriterImpl implements ProtocolWriter {
else w.writeBytes(publicKey); else w.writeBytes(publicKey);
} }
w.writeListEnd(); w.writeListEnd();
w.writeInt64(u.getVersionNumber()); w.writeInt64(u.getVersion());
if(flush) out.flush(); if(flush) out.flush();
} }
public void writeTransportAck(TransportAck a) throws IOException { public void writeTransportAck(TransportAck a) throws IOException {
w.writeStructId(TRANSPORT_ACK); w.writeStructId(TRANSPORT_ACK);
w.writeBytes(a.getId().getBytes()); w.writeBytes(a.getId().getBytes());
w.writeInt64(a.getVersionNumber()); w.writeInt64(a.getVersion());
if(flush) out.flush(); if(flush) out.flush();
} }
@@ -153,7 +153,7 @@ class ProtocolWriterImpl implements ProtocolWriter {
w.writeStructId(TRANSPORT_UPDATE); w.writeStructId(TRANSPORT_UPDATE);
w.writeBytes(u.getId().getBytes()); w.writeBytes(u.getId().getBytes());
w.writeMap(u.getProperties()); w.writeMap(u.getProperties());
w.writeInt64(u.getVersionNumber()); w.writeInt64(u.getVersion());
if(flush) out.flush(); if(flush) out.flush();
} }

View File

@@ -12,7 +12,6 @@ import java.util.Arrays;
import java.util.BitSet; import java.util.BitSet;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map;
import java.util.Random; import java.util.Random;
import net.sf.briar.api.ContactId; import net.sf.briar.api.ContactId;
@@ -32,10 +31,7 @@ import net.sf.briar.api.protocol.ProtocolReaderFactory;
import net.sf.briar.api.protocol.ProtocolWriter; import net.sf.briar.api.protocol.ProtocolWriter;
import net.sf.briar.api.protocol.ProtocolWriterFactory; import net.sf.briar.api.protocol.ProtocolWriterFactory;
import net.sf.briar.api.protocol.Request; import net.sf.briar.api.protocol.Request;
import net.sf.briar.api.protocol.Subscription;
import net.sf.briar.api.protocol.SubscriptionHole;
import net.sf.briar.api.protocol.SubscriptionUpdate; import net.sf.briar.api.protocol.SubscriptionUpdate;
import net.sf.briar.api.protocol.Transport;
import net.sf.briar.api.protocol.TransportId; import net.sf.briar.api.protocol.TransportId;
import net.sf.briar.api.protocol.TransportUpdate; import net.sf.briar.api.protocol.TransportUpdate;
import net.sf.briar.api.protocol.UnverifiedMessage; import net.sf.briar.api.protocol.UnverifiedMessage;

View File

@@ -17,9 +17,9 @@ import net.sf.briar.api.db.NoSuchTransportException;
import net.sf.briar.api.db.event.ContactAddedEvent; import net.sf.briar.api.db.event.ContactAddedEvent;
import net.sf.briar.api.db.event.ContactRemovedEvent; import net.sf.briar.api.db.event.ContactRemovedEvent;
import net.sf.briar.api.db.event.DatabaseListener; import net.sf.briar.api.db.event.DatabaseListener;
import net.sf.briar.api.db.event.LocalSubscriptionsUpdatedEvent;
import net.sf.briar.api.db.event.MessageAddedEvent; import net.sf.briar.api.db.event.MessageAddedEvent;
import net.sf.briar.api.db.event.RatingChangedEvent; import net.sf.briar.api.db.event.RatingChangedEvent;
import net.sf.briar.api.db.event.LocalSubscriptionsUpdatedEvent;
import net.sf.briar.api.lifecycle.ShutdownManager; import net.sf.briar.api.lifecycle.ShutdownManager;
import net.sf.briar.api.protocol.Ack; import net.sf.briar.api.protocol.Ack;
import net.sf.briar.api.protocol.AuthorId; import net.sf.briar.api.protocol.AuthorId;
@@ -30,7 +30,6 @@ import net.sf.briar.api.protocol.MessageId;
import net.sf.briar.api.protocol.Offer; import net.sf.briar.api.protocol.Offer;
import net.sf.briar.api.protocol.Request; import net.sf.briar.api.protocol.Request;
import net.sf.briar.api.protocol.SubscriptionUpdate; import net.sf.briar.api.protocol.SubscriptionUpdate;
import net.sf.briar.api.protocol.Transport;
import net.sf.briar.api.protocol.TransportId; import net.sf.briar.api.protocol.TransportId;
import net.sf.briar.api.protocol.TransportUpdate; import net.sf.briar.api.protocol.TransportUpdate;
import net.sf.briar.api.transport.Endpoint; import net.sf.briar.api.transport.Endpoint;

View File

@@ -52,9 +52,9 @@ public class ProtocolWriterImplTest extends BriarTestCase {
b.set(12); b.set(12);
b.set(15); b.set(15);
w.writeRequest(new Request(b, 16)); w.writeRequest(new Request(b, 16));
// Short user tag 6, 0 as uint7, short bytes with length 2, 0xD959 // Short user tag 5, 0 as uint7, short bytes with length 2, 0xD959
byte[] output = out.toByteArray(); byte[] output = out.toByteArray();
assertEquals("C6" + "00" + "92" + "D959", assertEquals("C5" + "00" + "92" + "D959",
StringUtils.toHexString(output)); StringUtils.toHexString(output));
} }
@@ -75,9 +75,9 @@ public class ProtocolWriterImplTest extends BriarTestCase {
b.set(11); b.set(11);
b.set(12); b.set(12);
w.writeRequest(new Request(b, 13)); w.writeRequest(new Request(b, 13));
// Short user tag 6, 3 as uint7, short bytes with length 2, 0x59D8 // Short user tag 5, 3 as uint7, short bytes with length 2, 0x59D8
byte[] output = out.toByteArray(); byte[] output = out.toByteArray();
assertEquals("C6" + "03" + "92" + "59D8", assertEquals("C5" + "03" + "92" + "59D8",
StringUtils.toHexString(output)); StringUtils.toHexString(output));
} }
} }

View File

@@ -21,7 +21,6 @@ import net.sf.briar.api.protocol.MessageFactory;
import net.sf.briar.api.protocol.MessageVerifier; import net.sf.briar.api.protocol.MessageVerifier;
import net.sf.briar.api.protocol.ProtocolReaderFactory; import net.sf.briar.api.protocol.ProtocolReaderFactory;
import net.sf.briar.api.protocol.ProtocolWriterFactory; import net.sf.briar.api.protocol.ProtocolWriterFactory;
import net.sf.briar.api.protocol.Transport;
import net.sf.briar.api.protocol.TransportId; import net.sf.briar.api.protocol.TransportId;
import net.sf.briar.api.protocol.TransportUpdate; import net.sf.briar.api.protocol.TransportUpdate;
import net.sf.briar.api.transport.ConnectionContext; import net.sf.briar.api.transport.ConnectionContext;