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