mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Rename client version to major version.
This commit is contained in:
@@ -32,25 +32,25 @@ class ContactGroupFactoryImpl implements ContactGroupFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group createLocalGroup(ClientId clientId, int clientVersion) {
|
||||
return groupFactory.createGroup(clientId, clientVersion,
|
||||
public Group createLocalGroup(ClientId clientId, int majorVersion) {
|
||||
return groupFactory.createGroup(clientId, majorVersion,
|
||||
LOCAL_GROUP_DESCRIPTOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group createContactGroup(ClientId clientId, int clientVersion,
|
||||
public Group createContactGroup(ClientId clientId, int majorVersion,
|
||||
Contact contact) {
|
||||
AuthorId local = contact.getLocalAuthorId();
|
||||
AuthorId remote = contact.getAuthor().getId();
|
||||
byte[] descriptor = createGroupDescriptor(local, remote);
|
||||
return groupFactory.createGroup(clientId, clientVersion, descriptor);
|
||||
return groupFactory.createGroup(clientId, majorVersion, descriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group createContactGroup(ClientId clientId, int clientVersion,
|
||||
public Group createContactGroup(ClientId clientId, int majorVersion,
|
||||
AuthorId authorId1, AuthorId authorId2) {
|
||||
byte[] descriptor = createGroupDescriptor(authorId1, authorId2);
|
||||
return groupFactory.createGroup(clientId, clientVersion, descriptor);
|
||||
return groupFactory.createGroup(clientId, majorVersion, descriptor);
|
||||
}
|
||||
|
||||
private byte[] createGroupDescriptor(AuthorId local, AuthorId remote) {
|
||||
|
||||
@@ -266,7 +266,7 @@ interface Database<T> {
|
||||
* <p/>
|
||||
* Read-only.
|
||||
*/
|
||||
Collection<Group> getGroups(T txn, ClientId c, int clientVersion)
|
||||
Collection<Group> getGroups(T txn, ClientId c, int majorVersion)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -436,9 +436,9 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
|
||||
@Override
|
||||
public Collection<Group> getGroups(Transaction transaction, ClientId c,
|
||||
int clientVersion) throws DbException {
|
||||
int majorVersion) throws DbException {
|
||||
T txn = unbox(transaction);
|
||||
return db.getGroups(txn, c, clientVersion);
|
||||
return db.getGroups(txn, c, majorVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -74,7 +74,7 @@ import static org.briarproject.bramble.db.ExponentialBackoff.calculateExpiry;
|
||||
abstract class JdbcDatabase implements Database<Connection> {
|
||||
|
||||
// Package access for testing
|
||||
static final int CODE_SCHEMA_VERSION = 37;
|
||||
static final int CODE_SCHEMA_VERSION = 38;
|
||||
|
||||
// Rotation period offsets for incoming transport keys
|
||||
private static final int OFFSET_PREV = -1;
|
||||
@@ -117,7 +117,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
"CREATE TABLE groups"
|
||||
+ " (groupId _HASH NOT NULL,"
|
||||
+ " clientId _STRING NOT NULL,"
|
||||
+ " clientVersion INT NOT NULL,"
|
||||
+ " majorVersion INT NOT NULL,"
|
||||
+ " descriptor _BINARY NOT NULL,"
|
||||
+ " PRIMARY KEY (groupId))";
|
||||
|
||||
@@ -276,9 +276,9 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
"CREATE INDEX IF NOT EXISTS contactsByAuthorId"
|
||||
+ " ON contacts (authorId)";
|
||||
|
||||
private static final String INDEX_GROUPS_BY_CLIENT_ID_CLIENT_VERSION =
|
||||
"CREATE INDEX IF NOT EXISTS groupsByClientIdClientVersion"
|
||||
+ " ON groups (clientId, clientVersion)";
|
||||
private static final String INDEX_GROUPS_BY_CLIENT_ID_MAJOR_VERSION =
|
||||
"CREATE INDEX IF NOT EXISTS groupsByClientIdMajorVersion"
|
||||
+ " ON groups (clientId, majorVersion)";
|
||||
|
||||
private static final String INDEX_MESSAGE_METADATA_BY_GROUP_ID_STATE =
|
||||
"CREATE INDEX IF NOT EXISTS messageMetadataByGroupIdState"
|
||||
@@ -445,7 +445,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
try {
|
||||
s = txn.createStatement();
|
||||
s.executeUpdate(INDEX_CONTACTS_BY_AUTHOR_ID);
|
||||
s.executeUpdate(INDEX_GROUPS_BY_CLIENT_ID_CLIENT_VERSION);
|
||||
s.executeUpdate(INDEX_GROUPS_BY_CLIENT_ID_MAJOR_VERSION);
|
||||
s.executeUpdate(INDEX_MESSAGE_METADATA_BY_GROUP_ID_STATE);
|
||||
s.executeUpdate(INDEX_MESSAGE_DEPENDENCIES_BY_DEPENDENCY_ID);
|
||||
s.executeUpdate(INDEX_STATUSES_BY_CONTACT_ID_GROUP_ID);
|
||||
@@ -614,12 +614,12 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
PreparedStatement ps = null;
|
||||
try {
|
||||
String sql = "INSERT INTO groups"
|
||||
+ " (groupId, clientId, clientVersion, descriptor)"
|
||||
+ " (groupId, clientId, majorVersion, descriptor)"
|
||||
+ " VALUES (?, ?, ?, ?)";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, g.getId().getBytes());
|
||||
ps.setString(2, g.getClientId().getString());
|
||||
ps.setInt(3, g.getClientVersion());
|
||||
ps.setInt(3, g.getMajorVersion());
|
||||
ps.setBytes(4, g.getDescriptor());
|
||||
int affected = ps.executeUpdate();
|
||||
if (affected != 1) throw new DbStateException();
|
||||
@@ -1349,18 +1349,18 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT clientId, clientVersion, descriptor"
|
||||
String sql = "SELECT clientId, majorVersion, descriptor"
|
||||
+ " FROM groups WHERE groupId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, g.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
if (!rs.next()) throw new DbStateException();
|
||||
ClientId clientId = new ClientId(rs.getString(1));
|
||||
int clientVersion = rs.getInt(2);
|
||||
int majorVersion = rs.getInt(2);
|
||||
byte[] descriptor = rs.getBytes(3);
|
||||
rs.close();
|
||||
ps.close();
|
||||
return new Group(g, clientId, clientVersion, descriptor);
|
||||
return new Group(g, clientId, majorVersion, descriptor);
|
||||
} catch (SQLException e) {
|
||||
tryToClose(rs);
|
||||
tryToClose(ps);
|
||||
@@ -1370,21 +1370,21 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
|
||||
@Override
|
||||
public Collection<Group> getGroups(Connection txn, ClientId c,
|
||||
int clientVersion) throws DbException {
|
||||
int majorVersion) throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT groupId, descriptor FROM groups"
|
||||
+ " WHERE clientId = ? AND clientVersion = ?";
|
||||
+ " WHERE clientId = ? AND majorVersion = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setString(1, c.getString());
|
||||
ps.setInt(2, clientVersion);
|
||||
ps.setInt(2, majorVersion);
|
||||
rs = ps.executeQuery();
|
||||
List<Group> groups = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
GroupId id = new GroupId(rs.getBytes(1));
|
||||
byte[] descriptor = rs.getBytes(2);
|
||||
groups.add(new Group(id, c, clientVersion, descriptor));
|
||||
groups.add(new Group(id, c, majorVersion, descriptor));
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
|
||||
@@ -16,7 +16,7 @@ import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID;
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_VERSION;
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.MAJOR_VERSION;
|
||||
|
||||
@Module
|
||||
public class PropertiesModule {
|
||||
@@ -35,7 +35,7 @@ public class PropertiesModule {
|
||||
Clock clock) {
|
||||
TransportPropertyValidator validator = new TransportPropertyValidator(
|
||||
clientHelper, metadataEncoder, clock);
|
||||
validationManager.registerMessageValidator(CLIENT_ID, CLIENT_VERSION,
|
||||
validationManager.registerMessageValidator(CLIENT_ID, MAJOR_VERSION,
|
||||
validator);
|
||||
return validator;
|
||||
}
|
||||
@@ -48,12 +48,12 @@ public class PropertiesModule {
|
||||
ClientVersioningManager clientVersioningManager,
|
||||
TransportPropertyManagerImpl transportPropertyManager) {
|
||||
lifecycleManager.registerClient(transportPropertyManager);
|
||||
validationManager.registerIncomingMessageHook(CLIENT_ID, CLIENT_VERSION,
|
||||
validationManager.registerIncomingMessageHook(CLIENT_ID, MAJOR_VERSION,
|
||||
transportPropertyManager);
|
||||
contactManager.registerContactHook(transportPropertyManager);
|
||||
clientVersioningManager.registerClient(CLIENT_ID, CLIENT_VERSION);
|
||||
clientVersioningManager.registerClient(CLIENT_ID, MAJOR_VERSION);
|
||||
clientVersioningManager.registerClientVersioningHook(CLIENT_ID,
|
||||
CLIENT_VERSION, transportPropertyManager);
|
||||
MAJOR_VERSION, transportPropertyManager);
|
||||
return transportPropertyManager;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
this.contactGroupFactory = contactGroupFactory;
|
||||
this.clock = clock;
|
||||
localGroup = contactGroupFactory.createLocalGroup(CLIENT_ID,
|
||||
CLIENT_VERSION);
|
||||
MAJOR_VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,7 +88,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
db.addGroup(txn, g);
|
||||
// Apply the client's visibility to the contact group
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
c.getId(), CLIENT_ID, CLIENT_VERSION);
|
||||
c.getId(), CLIENT_ID, MAJOR_VERSION);
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Applying visibility " + client + " to new contact group");
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), client);
|
||||
@@ -313,7 +313,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
|
||||
private Group getContactGroup(Contact c) {
|
||||
return contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
CLIENT_VERSION, c);
|
||||
MAJOR_VERSION, c);
|
||||
}
|
||||
|
||||
private void storeMessage(Transaction txn, GroupId g, TransportId t,
|
||||
|
||||
@@ -10,11 +10,11 @@ import javax.annotation.concurrent.Immutable;
|
||||
class ClientVersion implements Comparable<ClientVersion> {
|
||||
|
||||
final ClientId clientId;
|
||||
final int clientVersion;
|
||||
final int majorVersion;
|
||||
|
||||
ClientVersion(ClientId clientId, int clientVersion) {
|
||||
ClientVersion(ClientId clientId, int majorVersion) {
|
||||
this.clientId = clientId;
|
||||
this.clientVersion = clientVersion;
|
||||
this.majorVersion = majorVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -22,26 +22,26 @@ class ClientVersion implements Comparable<ClientVersion> {
|
||||
if (o instanceof ClientVersion) {
|
||||
ClientVersion cv = (ClientVersion) o;
|
||||
return clientId.equals(cv.clientId)
|
||||
&& clientVersion == cv.clientVersion;
|
||||
&& majorVersion == cv.majorVersion;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (clientId.hashCode() << 16) + clientVersion;
|
||||
return (clientId.hashCode() << 16) + majorVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ClientVersion c) {
|
||||
int compare = clientId.compareTo(c.clientId);
|
||||
if (compare != 0) return compare;
|
||||
return clientVersion - c.clientVersion;
|
||||
return majorVersion - c.majorVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return clientId.getString() + ":" + clientVersion;
|
||||
return clientId.getString() + ":" + majorVersion;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,23 +75,23 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
||||
this.contactGroupFactory = contactGroupFactory;
|
||||
this.clock = clock;
|
||||
localGroup = contactGroupFactory.createLocalGroup(CLIENT_ID,
|
||||
CLIENT_VERSION);
|
||||
MAJOR_VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerClient(ClientId clientId, int clientVersion) {
|
||||
clients.add(new ClientVersion(clientId, clientVersion));
|
||||
public void registerClient(ClientId clientId, int majorVersion) {
|
||||
clients.add(new ClientVersion(clientId, majorVersion));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerClientVersioningHook(ClientId clientId,
|
||||
int clientVersion, ClientVersioningHook hook) {
|
||||
hooks.put(new ClientVersion(clientId, clientVersion), hook);
|
||||
int majorVersion, ClientVersioningHook hook) {
|
||||
hooks.put(new ClientVersion(clientId, majorVersion), hook);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Visibility getClientVisibility(Transaction txn,
|
||||
ContactId contactId, ClientId clientId, int clientVersion)
|
||||
ContactId contactId, ClientId clientId, int majorVersion)
|
||||
throws DbException {
|
||||
try {
|
||||
Contact contact = db.getContact(txn, contactId);
|
||||
@@ -106,7 +106,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
||||
Update remoteUpdate = loadUpdate(txn, latest.remote.messageId);
|
||||
Map<ClientVersion, Visibility> visibilities =
|
||||
getVisibilities(localUpdate.states, remoteUpdate.states);
|
||||
ClientVersion cv = new ClientVersion(clientId, clientVersion);
|
||||
ClientVersion cv = new ClientVersion(clientId, majorVersion);
|
||||
Visibility v = visibilities.get(cv);
|
||||
return v == null ? INVISIBLE : v;
|
||||
} catch (FormatException e) {
|
||||
@@ -245,7 +245,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
||||
private BdfList encodeClientVersions(List<ClientVersion> versions) {
|
||||
BdfList encoded = new BdfList();
|
||||
for (ClientVersion cv : versions)
|
||||
encoded.add(BdfList.of(cv.clientId.getString(), cv.clientVersion));
|
||||
encoded.add(BdfList.of(cv.clientId.getString(), cv.majorVersion));
|
||||
return encoded;
|
||||
}
|
||||
|
||||
@@ -282,8 +282,8 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
||||
for (int i = 0; i < size; i++) {
|
||||
BdfList cv = body.getList(i);
|
||||
ClientId clientId = new ClientId(cv.getString(0));
|
||||
int clientVersion = cv.getLong(1).intValue();
|
||||
parsed.add(new ClientVersion(clientId, clientVersion));
|
||||
int majorVersion = cv.getLong(1).intValue();
|
||||
parsed.add(new ClientVersion(clientId, majorVersion));
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
@@ -325,7 +325,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
||||
|
||||
private Group getContactGroup(Contact c) {
|
||||
return contactGroupFactory.createContactGroup(CLIENT_ID,
|
||||
CLIENT_VERSION, c);
|
||||
MAJOR_VERSION, c);
|
||||
}
|
||||
|
||||
private LatestUpdates findLatestUpdates(Transaction txn, GroupId g)
|
||||
@@ -372,11 +372,11 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
||||
|
||||
private ClientState parseClientState(BdfList clientState)
|
||||
throws FormatException {
|
||||
// Client ID, client version, active
|
||||
// Client ID, major version, active
|
||||
ClientId clientId = new ClientId(clientState.getString(0));
|
||||
int clientVersion = clientState.getLong(1).intValue();
|
||||
int majorVersion = clientState.getLong(1).intValue();
|
||||
boolean active = clientState.getBoolean(2);
|
||||
return new ClientState(clientId, clientVersion, active);
|
||||
return new ClientState(clientId, majorVersion, active);
|
||||
}
|
||||
|
||||
private long parseUpdateVersion(BdfList body) throws FormatException {
|
||||
@@ -420,7 +420,7 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
||||
|
||||
private BdfList encodeClientState(ClientState cs) {
|
||||
return BdfList.of(cs.version.clientId.getString(),
|
||||
cs.version.clientVersion, cs.active);
|
||||
cs.version.majorVersion, cs.active);
|
||||
}
|
||||
|
||||
private Map<ClientVersion, Visibility> getVisibilities(
|
||||
@@ -536,9 +536,9 @@ class ClientVersioningManagerImpl implements ClientVersioningManager, Client,
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
private ClientState(ClientId clientId, int clientVersion,
|
||||
private ClientState(ClientId clientId, int majorVersion,
|
||||
boolean active) {
|
||||
this(new ClientVersion(clientId, clientVersion), active);
|
||||
this(new ClientVersion(clientId, majorVersion), active);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,13 +39,13 @@ class ClientVersioningValidator extends BdfMessageValidator {
|
||||
int size = states.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
BdfList clientState = states.getList(i);
|
||||
// Client ID, client version, active
|
||||
// Client ID, major version, active
|
||||
checkSize(clientState, 3);
|
||||
String clientId = clientState.getString(0);
|
||||
checkLength(clientId, 1, MAX_CLIENT_ID_LENGTH);
|
||||
int clientVersion = clientState.getLong(1).intValue();
|
||||
if (clientVersion < 0) throw new FormatException();
|
||||
boolean active = clientState.getBoolean(2);
|
||||
int majorVersion = clientState.getLong(1).intValue();
|
||||
if (majorVersion < 0) throw new FormatException();
|
||||
clientState.getBoolean(2);
|
||||
}
|
||||
// Update version
|
||||
long updateVersion = body.getLong(1);
|
||||
|
||||
@@ -28,12 +28,12 @@ class GroupFactoryImpl implements GroupFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group createGroup(ClientId c, int clientVersion, byte[] descriptor) {
|
||||
byte[] clientVersionBytes = new byte[INT_32_BYTES];
|
||||
ByteUtils.writeUint32(clientVersion, clientVersionBytes, 0);
|
||||
public Group createGroup(ClientId c, int majorVersion, byte[] descriptor) {
|
||||
byte[] majorVersionBytes = new byte[INT_32_BYTES];
|
||||
ByteUtils.writeUint32(majorVersion, majorVersionBytes, 0);
|
||||
byte[] hash = crypto.hash(LABEL, new byte[] {FORMAT_VERSION},
|
||||
StringUtils.toUtf8(c.getString()), clientVersionBytes,
|
||||
StringUtils.toUtf8(c.getString()), majorVersionBytes,
|
||||
descriptor);
|
||||
return new Group(new GroupId(hash), c, clientVersion, descriptor);
|
||||
return new Group(new GroupId(hash), c, majorVersion, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.ClientVersioningManager.CLIENT_ID;
|
||||
import static org.briarproject.bramble.api.sync.ClientVersioningManager.CLIENT_VERSION;
|
||||
import static org.briarproject.bramble.api.sync.ClientVersioningManager.MAJOR_VERSION;
|
||||
|
||||
@Module
|
||||
public class SyncModule {
|
||||
@@ -111,7 +111,7 @@ public class SyncModule {
|
||||
lifecycleManager.registerClient(clientVersioningManager);
|
||||
lifecycleManager.registerService(clientVersioningManager);
|
||||
contactManager.registerContactHook(clientVersioningManager);
|
||||
validationManager.registerIncomingMessageHook(CLIENT_ID, CLIENT_VERSION,
|
||||
validationManager.registerIncomingMessageHook(CLIENT_ID, MAJOR_VERSION,
|
||||
clientVersioningManager);
|
||||
return clientVersioningManager;
|
||||
}
|
||||
@@ -123,7 +123,7 @@ public class SyncModule {
|
||||
Clock clock, ValidationManager validationManager) {
|
||||
ClientVersioningValidator validator = new ClientVersioningValidator(
|
||||
clientHelper, metadataEncoder, clock);
|
||||
validationManager.registerMessageValidator(CLIENT_ID, CLIENT_VERSION,
|
||||
validationManager.registerMessageValidator(CLIENT_ID, MAJOR_VERSION,
|
||||
validator);
|
||||
return validator;
|
||||
}
|
||||
|
||||
@@ -81,15 +81,15 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerMessageValidator(ClientId c, int clientVersion,
|
||||
public void registerMessageValidator(ClientId c, int majorVersion,
|
||||
MessageValidator v) {
|
||||
validators.put(new ClientVersion(c, clientVersion), v);
|
||||
validators.put(new ClientVersion(c, majorVersion), v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIncomingMessageHook(ClientId c, int clientVersion,
|
||||
public void registerIncomingMessageHook(ClientId c, int majorVersion,
|
||||
IncomingMessageHook hook) {
|
||||
hooks.put(new ClientVersion(c, clientVersion), hook);
|
||||
hooks.put(new ClientVersion(c, majorVersion), hook);
|
||||
}
|
||||
|
||||
private void validateOutstandingMessagesAsync() {
|
||||
@@ -200,11 +200,11 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
Message m = messageFactory.createMessage(id, raw);
|
||||
Group g = db.getGroup(txn, m.getGroupId());
|
||||
ClientId c = g.getClientId();
|
||||
int clientVersion = g.getClientVersion();
|
||||
int majorVersion = g.getMajorVersion();
|
||||
Metadata meta =
|
||||
db.getMessageMetadataForValidator(txn, id);
|
||||
DeliveryResult result =
|
||||
deliverMessage(txn, m, c, clientVersion, meta);
|
||||
deliverMessage(txn, m, c, majorVersion, meta);
|
||||
if (result.valid) {
|
||||
pending.addAll(getPendingDependents(txn, id));
|
||||
if (result.share) {
|
||||
@@ -241,7 +241,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
@ValidationExecutor
|
||||
private void validateMessage(Message m, Group g) {
|
||||
ClientVersion cv =
|
||||
new ClientVersion(g.getClientId(), g.getClientVersion());
|
||||
new ClientVersion(g.getClientId(), g.getMajorVersion());
|
||||
MessageValidator v = validators.get(cv);
|
||||
if (v == null) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.warning("No validator for " + cv);
|
||||
@@ -249,7 +249,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
try {
|
||||
MessageContext context = v.validateMessage(m, g);
|
||||
storeMessageContextAsync(m, g.getClientId(),
|
||||
g.getClientVersion(), context);
|
||||
g.getMajorVersion(), context);
|
||||
} catch (InvalidMessageException e) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.log(INFO, e.toString(), e);
|
||||
@@ -261,13 +261,13 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
}
|
||||
|
||||
private void storeMessageContextAsync(Message m, ClientId c,
|
||||
int clientVersion, MessageContext result) {
|
||||
int majorVersion, MessageContext result) {
|
||||
dbExecutor.execute(() ->
|
||||
storeMessageContext(m, c, clientVersion, result));
|
||||
storeMessageContext(m, c, majorVersion, result));
|
||||
}
|
||||
|
||||
@DatabaseExecutor
|
||||
private void storeMessageContext(Message m, ClientId c, int clientVersion,
|
||||
private void storeMessageContext(Message m, ClientId c, int majorVersion,
|
||||
MessageContext context) {
|
||||
try {
|
||||
MessageId id = m.getId();
|
||||
@@ -299,7 +299,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
db.mergeMessageMetadata(txn, id, meta);
|
||||
if (allDelivered) {
|
||||
DeliveryResult result =
|
||||
deliverMessage(txn, m, c, clientVersion, meta);
|
||||
deliverMessage(txn, m, c, majorVersion, meta);
|
||||
if (result.valid) {
|
||||
pending = getPendingDependents(txn, id);
|
||||
if (result.share) {
|
||||
@@ -331,10 +331,10 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
|
||||
@DatabaseExecutor
|
||||
private DeliveryResult deliverMessage(Transaction txn, Message m,
|
||||
ClientId c, int clientVersion, Metadata meta) throws DbException {
|
||||
ClientId c, int majorVersion, Metadata meta) throws DbException {
|
||||
// Deliver the message to the client if it's registered a hook
|
||||
boolean shareMsg = false;
|
||||
ClientVersion cv = new ClientVersion(c, clientVersion);
|
||||
ClientVersion cv = new ClientVersion(c, majorVersion);
|
||||
IncomingMessageHook hook = hooks.get(cv);
|
||||
if (hook != null) {
|
||||
try {
|
||||
|
||||
@@ -89,7 +89,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
|
||||
private final Object txn = new Object();
|
||||
private final ClientId clientId;
|
||||
private final int clientVersion;
|
||||
private final int majorVersion;
|
||||
private final GroupId groupId;
|
||||
private final Group group;
|
||||
private final Author author;
|
||||
@@ -107,8 +107,8 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
|
||||
public DatabaseComponentImplTest() {
|
||||
clientId = getClientId();
|
||||
clientVersion = 123;
|
||||
group = getGroup(clientId, clientVersion);
|
||||
majorVersion = 123;
|
||||
group = getGroup(clientId, majorVersion);
|
||||
groupId = group.getId();
|
||||
author = getAuthor();
|
||||
localAuthor = getLocalAuthor();
|
||||
@@ -177,7 +177,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
oneOf(database).containsGroup(txn, groupId);
|
||||
will(returnValue(true));
|
||||
// getGroups()
|
||||
oneOf(database).getGroups(txn, clientId, clientVersion);
|
||||
oneOf(database).getGroups(txn, clientId, majorVersion);
|
||||
will(returnValue(singletonList(group)));
|
||||
// removeGroup()
|
||||
oneOf(database).containsGroup(txn, groupId);
|
||||
@@ -217,7 +217,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
db.addGroup(transaction, group); // First time - listeners called
|
||||
db.addGroup(transaction, group); // Second time - not called
|
||||
assertEquals(singletonList(group),
|
||||
db.getGroups(transaction, clientId, clientVersion));
|
||||
db.getGroups(transaction, clientId, majorVersion));
|
||||
db.removeGroup(transaction, group);
|
||||
db.removeContact(transaction, contactId);
|
||||
db.removeLocalAuthor(transaction, localAuthor.getId());
|
||||
|
||||
@@ -82,7 +82,7 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
private final File testDir = TestUtils.getTestDirectory();
|
||||
private final GroupId groupId;
|
||||
private final ClientId clientId;
|
||||
private final int clientVersion;
|
||||
private final int majorVersion;
|
||||
private final Group group;
|
||||
private final Author author;
|
||||
private final LocalAuthor localAuthor;
|
||||
@@ -97,8 +97,8 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
|
||||
JdbcDatabaseTest() throws Exception {
|
||||
clientId = getClientId();
|
||||
clientVersion = 123;
|
||||
group = getGroup(clientId, clientVersion);
|
||||
majorVersion = 123;
|
||||
group = getGroup(clientId, majorVersion);
|
||||
groupId = group.getId();
|
||||
author = getAuthor();
|
||||
localAuthor = getLocalAuthor();
|
||||
@@ -1835,12 +1835,12 @@ public abstract class JdbcDatabaseTest extends BrambleTestCase {
|
||||
Database<Connection> db = open(false);
|
||||
Connection txn = db.startTransaction();
|
||||
|
||||
assertEquals(emptyList(), db.getGroups(txn, clientId, clientVersion));
|
||||
assertEquals(emptyList(), db.getGroups(txn, clientId, majorVersion));
|
||||
db.addGroup(txn, group);
|
||||
assertEquals(singletonList(group),
|
||||
db.getGroups(txn, clientId, clientVersion));
|
||||
db.getGroups(txn, clientId, majorVersion));
|
||||
db.removeGroup(txn, groupId);
|
||||
assertEquals(emptyList(), db.getGroups(txn, clientId, clientVersion));
|
||||
assertEquals(emptyList(), db.getGroups(txn, clientId, majorVersion));
|
||||
|
||||
db.commitTransaction(txn);
|
||||
db.close();
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.util.Map;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID;
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_VERSION;
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.MAJOR_VERSION;
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.bramble.api.sync.SyncConstants.MAX_MESSAGE_BODY_LENGTH;
|
||||
import static org.briarproject.bramble.test.TestUtils.getAuthor;
|
||||
@@ -55,7 +55,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
context.mock(ContactGroupFactory.class);
|
||||
private final Clock clock = context.mock(Clock.class);
|
||||
|
||||
private final Group localGroup = getGroup(CLIENT_ID, CLIENT_VERSION);
|
||||
private final Group localGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
private final LocalAuthor localAuthor = getLocalAuthor();
|
||||
private final BdfDictionary fooPropertiesDict = BdfDictionary.of(
|
||||
new BdfEntry("fooKey1", "fooValue1"),
|
||||
@@ -81,7 +81,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
private TransportPropertyManagerImpl createInstance() {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(contactGroupFactory).createLocalGroup(CLIENT_ID,
|
||||
CLIENT_VERSION);
|
||||
MAJOR_VERSION);
|
||||
will(returnValue(localGroup));
|
||||
}});
|
||||
return new TransportPropertyManagerImpl(db, clientHelper,
|
||||
@@ -93,7 +93,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
public void testCreatesGroupsAtStartup() throws Exception {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup(CLIENT_ID, CLIENT_VERSION);
|
||||
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).containsGroup(txn, localGroup.getId());
|
||||
@@ -102,11 +102,11 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(singletonList(contact)));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
CLIENT_VERSION, contact);
|
||||
MAJOR_VERSION, contact);
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).addGroup(txn, contactGroup);
|
||||
oneOf(clientVersioningManager).getClientVisibility(txn,
|
||||
contact.getId(), CLIENT_ID, CLIENT_VERSION);
|
||||
contact.getId(), CLIENT_ID, MAJOR_VERSION);
|
||||
will(returnValue(SHARED));
|
||||
oneOf(db).setGroupVisibility(txn, contact.getId(),
|
||||
contactGroup.getId(), SHARED);
|
||||
@@ -140,16 +140,16 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
public void testCreatesContactGroupWhenAddingContact() throws Exception {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup(CLIENT_ID, CLIENT_VERSION);
|
||||
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
// Create the group and share it with the contact
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
CLIENT_VERSION, contact);
|
||||
MAJOR_VERSION, contact);
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).addGroup(txn, contactGroup);
|
||||
oneOf(clientVersioningManager).getClientVisibility(txn,
|
||||
contact.getId(), CLIENT_ID, CLIENT_VERSION);
|
||||
contact.getId(), CLIENT_ID, MAJOR_VERSION);
|
||||
will(returnValue(SHARED));
|
||||
oneOf(db).setGroupVisibility(txn, contact.getId(),
|
||||
contactGroup.getId(), SHARED);
|
||||
@@ -169,11 +169,11 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
public void testRemovesGroupWhenRemovingContact() throws Exception {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup(CLIENT_ID, CLIENT_VERSION);
|
||||
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
CLIENT_VERSION, contact);
|
||||
MAJOR_VERSION, contact);
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).removeGroup(txn, contactGroup);
|
||||
}});
|
||||
@@ -304,7 +304,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testStoresRemotePropertiesWithVersion0() throws Exception {
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup(CLIENT_ID, CLIENT_VERSION);
|
||||
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Map<TransportId, TransportProperties> properties =
|
||||
new LinkedHashMap<>();
|
||||
@@ -315,7 +315,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).getContact(txn, contact.getId());
|
||||
will(returnValue(contact));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
CLIENT_VERSION, contact);
|
||||
MAJOR_VERSION, contact);
|
||||
will(returnValue(contactGroup));
|
||||
}});
|
||||
expectStoreMessage(txn, contactGroup.getId(), "foo", fooPropertiesDict,
|
||||
@@ -418,8 +418,8 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
Contact contact3 = getContact(true);
|
||||
List<Contact> contacts =
|
||||
Arrays.asList(contact1, contact2, contact3);
|
||||
Group contactGroup2 = getGroup(CLIENT_ID, CLIENT_VERSION);
|
||||
Group contactGroup3 = getGroup(CLIENT_ID, CLIENT_VERSION);
|
||||
Group contactGroup2 = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
Group contactGroup3 = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
Map<MessageId, BdfDictionary> messageMetadata3 =
|
||||
new LinkedHashMap<>();
|
||||
// A remote update for another transport should be ignored
|
||||
@@ -453,14 +453,14 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
// First contact: skipped because not active
|
||||
// Second contact: no updates
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
CLIENT_VERSION, contact2);
|
||||
MAJOR_VERSION, contact2);
|
||||
will(returnValue(contactGroup2));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
contactGroup2.getId());
|
||||
will(returnValue(Collections.emptyMap()));
|
||||
// Third contact: returns an update
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
CLIENT_VERSION, contact3);
|
||||
MAJOR_VERSION, contact3);
|
||||
will(returnValue(contactGroup3));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
contactGroup3.getId());
|
||||
@@ -521,7 +521,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
public void testMergingNewPropertiesCreatesUpdate() throws Exception {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup(CLIENT_ID, CLIENT_VERSION);
|
||||
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(false);
|
||||
@@ -537,7 +537,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(singletonList(contact)));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
CLIENT_VERSION, contact);
|
||||
MAJOR_VERSION, contact);
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
contactGroup.getId());
|
||||
@@ -556,7 +556,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
public void testMergingUpdatedPropertiesCreatesUpdate() throws Exception {
|
||||
Transaction txn = new Transaction(null, false);
|
||||
Contact contact = getContact(true);
|
||||
Group contactGroup = getGroup(CLIENT_ID, CLIENT_VERSION);
|
||||
Group contactGroup = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
BdfDictionary oldMetadata = BdfDictionary.of(
|
||||
new BdfEntry("transportId", "foo"),
|
||||
new BdfEntry("version", 1),
|
||||
@@ -596,7 +596,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
oneOf(db).getContacts(txn);
|
||||
will(returnValue(singletonList(contact)));
|
||||
oneOf(contactGroupFactory).createContactGroup(CLIENT_ID,
|
||||
CLIENT_VERSION, contact);
|
||||
MAJOR_VERSION, contact);
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(clientHelper).getMessageMetadataAsDictionary(txn,
|
||||
contactGroup.getId());
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.io.IOException;
|
||||
|
||||
import static org.briarproject.bramble.api.plugin.TransportId.MAX_TRANSPORT_ID_LENGTH;
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_ID;
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.CLIENT_VERSION;
|
||||
import static org.briarproject.bramble.api.properties.TransportPropertyManager.MAJOR_VERSION;
|
||||
import static org.briarproject.bramble.test.TestUtils.getGroup;
|
||||
import static org.briarproject.bramble.test.TestUtils.getMessage;
|
||||
import static org.briarproject.bramble.test.TestUtils.getTransportId;
|
||||
@@ -43,7 +43,7 @@ public class TransportPropertyValidatorTest extends BrambleMockTestCase {
|
||||
transportProperties = new TransportProperties();
|
||||
transportProperties.put("foo", "bar");
|
||||
|
||||
group = getGroup(CLIENT_ID, CLIENT_VERSION);
|
||||
group = getGroup(CLIENT_ID, MAJOR_VERSION);
|
||||
message = getMessage(group.getId());
|
||||
|
||||
MetadataEncoder metadataEncoder = context.mock(MetadataEncoder.class);
|
||||
|
||||
@@ -81,9 +81,9 @@ public class SyncIntegrationTest extends BrambleTestCase {
|
||||
streamNumber = 123;
|
||||
// Create a group
|
||||
ClientId clientId = getClientId();
|
||||
int clientVersion = 1234567890;
|
||||
int majorVersion = 1234567890;
|
||||
byte[] descriptor = new byte[MAX_GROUP_DESCRIPTOR_LENGTH];
|
||||
Group group = groupFactory.createGroup(clientId, clientVersion,
|
||||
Group group = groupFactory.createGroup(clientId, majorVersion,
|
||||
descriptor);
|
||||
// Add two messages to the group
|
||||
long timestamp = System.currentTimeMillis();
|
||||
|
||||
@@ -53,11 +53,11 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
private final Executor dbExecutor = new ImmediateExecutor();
|
||||
private final Executor validationExecutor = new ImmediateExecutor();
|
||||
private final ClientId clientId = getClientId();
|
||||
private final int clientVersion = 123;
|
||||
private final int majorVersion = 123;
|
||||
private final MessageId messageId = new MessageId(getRandomId());
|
||||
private final MessageId messageId1 = new MessageId(getRandomId());
|
||||
private final MessageId messageId2 = new MessageId(getRandomId());
|
||||
private final Group group = getGroup(clientId, clientVersion);
|
||||
private final Group group = getGroup(clientId, majorVersion);
|
||||
private final GroupId groupId = group.getId();
|
||||
private final long timestamp = System.currentTimeMillis();
|
||||
private final byte[] raw = new byte[123];
|
||||
@@ -86,8 +86,8 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
public void setUp() {
|
||||
vm = new ValidationManagerImpl(db, dbExecutor, validationExecutor,
|
||||
messageFactory);
|
||||
vm.registerMessageValidator(clientId, clientVersion, validator);
|
||||
vm.registerIncomingMessageHook(clientId, clientVersion, hook);
|
||||
vm.registerMessageValidator(clientId, majorVersion, validator);
|
||||
vm.registerIncomingMessageHook(clientId, majorVersion, hook);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user