mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Don't share groups unless the contact supports the client.
This commit is contained in:
@@ -48,6 +48,7 @@ import javax.annotation.Nullable;
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.briarproject.bramble.api.sync.Group.Visibility.SHARED;
|
||||
import static org.briarproject.briar.privategroup.invitation.CreatorState.START;
|
||||
import static org.briarproject.briar.privategroup.invitation.GroupInvitationConstants.GROUP_KEY_CONTACT_ID;
|
||||
import static org.briarproject.briar.privategroup.invitation.MessageType.ABORT;
|
||||
@@ -468,8 +469,13 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
SessionId sessionId = getSessionId(privateGroupId);
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
c.getId(), PrivateGroupManager.CLIENT_ID,
|
||||
PrivateGroupManager.MAJOR_VERSION);
|
||||
StoredSession ss = getSession(txn, contactGroupId, sessionId);
|
||||
db.commitTransaction(txn);
|
||||
// The group can't be shared unless the contact supports the client
|
||||
if (client != SHARED) return false;
|
||||
// If there's no session, the contact can be invited
|
||||
if (ss == null) return true;
|
||||
// If the session's in the start state, the contact can be invited
|
||||
|
||||
@@ -54,7 +54,7 @@ class BlogSharingManagerImpl extends SharingManagerImpl<Blog>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getClientVersion() {
|
||||
protected int getMajorVersion() {
|
||||
return MAJOR_VERSION;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class BlogSharingManagerImpl extends SharingManagerImpl<Blog>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getShareableClientVersion() {
|
||||
protected int getShareableMajorVersion() {
|
||||
return BlogManager.MAJOR_VERSION;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class ForumSharingManagerImpl extends SharingManagerImpl<Forum>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getClientVersion() {
|
||||
protected int getMajorVersion() {
|
||||
return MAJOR_VERSION;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class ForumSharingManagerImpl extends SharingManagerImpl<Forum>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getShareableClientVersion() {
|
||||
protected int getShareableMajorVersion() {
|
||||
return ForumManager.MAJOR_VERSION;
|
||||
}
|
||||
|
||||
|
||||
@@ -85,17 +85,17 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
|
||||
protected abstract ClientId getClientId();
|
||||
|
||||
protected abstract int getClientVersion();
|
||||
protected abstract int getMajorVersion();
|
||||
|
||||
protected abstract ClientId getShareableClientId();
|
||||
|
||||
protected abstract int getShareableClientVersion();
|
||||
protected abstract int getShareableMajorVersion();
|
||||
|
||||
@Override
|
||||
public void createLocalState(Transaction txn) throws DbException {
|
||||
// Create a local group to indicate that we've set this client up
|
||||
Group localGroup = contactGroupFactory.createLocalGroup(getClientId(),
|
||||
getClientVersion());
|
||||
getMajorVersion());
|
||||
if (db.containsGroup(txn, localGroup.getId())) return;
|
||||
db.addGroup(txn, localGroup);
|
||||
// Set things up for any pre-existing contacts
|
||||
@@ -109,7 +109,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
// Store the group and share it with the contact
|
||||
db.addGroup(txn, g);
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
c.getId(), getClientId(), getClientVersion());
|
||||
c.getId(), getClientId(), getMajorVersion());
|
||||
db.setGroupVisibility(txn, c.getId(), g.getId(), client);
|
||||
// Attach the contact ID to the group
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
@@ -123,14 +123,14 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
|
||||
@Override
|
||||
public void removingContact(Transaction txn, Contact c) throws DbException {
|
||||
// remove the contact group (all messages will be removed with it)
|
||||
// Remove the contact group (all messages will be removed with it)
|
||||
db.removeGroup(txn, getContactGroup(c));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getContactGroup(Contact c) {
|
||||
return contactGroupFactory.createContactGroup(getClientId(),
|
||||
getClientVersion(), c);
|
||||
getMajorVersion(), c);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -174,7 +174,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
|
||||
// Apply the client's visibility
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
c.getId(), getShareableClientId(), getShareableClientVersion());
|
||||
c.getId(), getShareableClientId(), getShareableMajorVersion());
|
||||
db.setGroupVisibility(txn, c.getId(), shareable.getId(), client);
|
||||
|
||||
// Initialize session in sharing state
|
||||
@@ -437,7 +437,6 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
// FIXME: Check the session for the preferred visibility?
|
||||
if (db.getGroupVisibility(txn, c.getId(), g) == SHARED)
|
||||
contacts.add(c);
|
||||
}
|
||||
@@ -462,6 +461,10 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
|
||||
private boolean canBeShared(Transaction txn, GroupId g, Contact c)
|
||||
throws DbException {
|
||||
// The group can't be shared unless the contact supports the client
|
||||
Visibility client = clientVersioningManager.getClientVisibility(txn,
|
||||
c.getId(), getShareableClientId(), getShareableMajorVersion());
|
||||
if (client != SHARED) return false;
|
||||
GroupId contactGroupId = getContactGroup(c).getId();
|
||||
SessionId sessionId = getSessionId(g);
|
||||
try {
|
||||
@@ -515,7 +518,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
Visibility client) throws DbException {
|
||||
try {
|
||||
Collection<Group> shareables = db.getGroups(txn,
|
||||
getShareableClientId(), getShareableClientVersion());
|
||||
getShareableClientId(), getShareableMajorVersion());
|
||||
Map<GroupId, Visibility> m = getPreferredVisibilities(txn, c);
|
||||
for (Group g : shareables) {
|
||||
Visibility preferred = m.get(g.getId());
|
||||
|
||||
@@ -826,6 +826,10 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
will(returnValue(contactGroup));
|
||||
oneOf(db).startTransaction(true);
|
||||
will(returnValue(txn));
|
||||
oneOf(clientVersioningManager).getClientVisibility(txn, contactId,
|
||||
PrivateGroupManager.CLIENT_ID,
|
||||
PrivateGroupManager.MAJOR_VERSION);
|
||||
will(returnValue(SHARED));
|
||||
oneOf(sessionParser)
|
||||
.parseCreatorSession(contactGroup.getId(), bdfSession);
|
||||
will(returnValue(creatorSession));
|
||||
|
||||
Reference in New Issue
Block a user