mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 13:49:53 +01:00
Removed unneeded visibility methods.
This commit is contained in:
@@ -193,9 +193,6 @@ public interface DatabaseComponent {
|
|||||||
/** Returns the maximum latencies in milliseconds of all transports. */
|
/** Returns the maximum latencies in milliseconds of all transports. */
|
||||||
Map<TransportId, Integer> getTransportLatencies() throws DbException;
|
Map<TransportId, Integer> getTransportLatencies() throws DbException;
|
||||||
|
|
||||||
/** Returns the IDs of all contacts to which the given group is visible. */
|
|
||||||
Collection<ContactId> getVisibility(GroupId g) throws DbException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the outgoing stream counter for the given contact and
|
* Increments the outgoing stream counter for the given contact and
|
||||||
* transport in the given rotation period .
|
* transport in the given rotation period .
|
||||||
@@ -271,13 +268,6 @@ public interface DatabaseComponent {
|
|||||||
void setReorderingWindow(ContactId c, TransportId t, long rotationPeriod,
|
void setReorderingWindow(ContactId c, TransportId t, long rotationPeriod,
|
||||||
long base, byte[] bitmap) throws DbException;
|
long base, byte[] bitmap) throws DbException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes a group visible to the given set of contacts and invisible to any
|
|
||||||
* other contacts.
|
|
||||||
*/
|
|
||||||
void setVisibility(GroupId g, Collection<ContactId> visible)
|
|
||||||
throws DbException;
|
|
||||||
|
|
||||||
/** Makes a group visible or invisible to a contact. */
|
/** Makes a group visible or invisible to a contact. */
|
||||||
void setVisibleToContact(ContactId c, GroupId g, boolean visible)
|
void setVisibleToContact(ContactId c, GroupId g, boolean visible)
|
||||||
throws DbException;
|
throws DbException;
|
||||||
|
|||||||
@@ -638,20 +638,6 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<ContactId> getVisibility(GroupId g) throws DbException {
|
|
||||||
T txn = db.startTransaction();
|
|
||||||
try {
|
|
||||||
if (!db.containsGroup(txn, g))
|
|
||||||
throw new NoSuchGroupException();
|
|
||||||
Collection<ContactId> visible = db.getVisibility(txn, g);
|
|
||||||
db.commitTransaction(txn);
|
|
||||||
return visible;
|
|
||||||
} catch (DbException e) {
|
|
||||||
db.abortTransaction(txn);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void incrementStreamCounter(ContactId c, TransportId t,
|
public void incrementStreamCounter(ContactId c, TransportId t,
|
||||||
long rotationPeriod) throws DbException {
|
long rotationPeriod) throws DbException {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
@@ -956,38 +942,6 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisibility(GroupId g, Collection<ContactId> visible)
|
|
||||||
throws DbException {
|
|
||||||
Collection<ContactId> affected = new ArrayList<ContactId>();
|
|
||||||
T txn = db.startTransaction();
|
|
||||||
try {
|
|
||||||
if (!db.containsGroup(txn, g))
|
|
||||||
throw new NoSuchGroupException();
|
|
||||||
// Use HashSets for O(1) lookups, O(n) overall running time
|
|
||||||
Collection<ContactId> now = new HashSet<ContactId>(visible);
|
|
||||||
Collection<ContactId> before = db.getVisibility(txn, g);
|
|
||||||
before = new HashSet<ContactId>(before);
|
|
||||||
// Set the group's visibility for each current contact
|
|
||||||
for (ContactId c : db.getContactIds(txn)) {
|
|
||||||
boolean wasBefore = before.contains(c);
|
|
||||||
boolean isNow = now.contains(c);
|
|
||||||
if (!wasBefore && isNow) {
|
|
||||||
db.addVisibility(txn, c, g);
|
|
||||||
affected.add(c);
|
|
||||||
} else if (wasBefore && !isNow) {
|
|
||||||
db.removeVisibility(txn, c, g);
|
|
||||||
affected.add(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.commitTransaction(txn);
|
|
||||||
} catch (DbException e) {
|
|
||||||
db.abortTransaction(txn);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
if (!affected.isEmpty())
|
|
||||||
eventBus.broadcast(new GroupVisibilityUpdatedEvent(affected));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVisibleToContact(ContactId c, GroupId g, boolean visible)
|
public void setVisibleToContact(ContactId c, GroupId g, boolean visible)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
boolean wasVisible;
|
boolean wasVisible;
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class ForumSharingManagerImpl implements ForumSharingManager, AddContactHook,
|
|||||||
Group g = getContactGroup(c);
|
Group g = getContactGroup(c);
|
||||||
// Store the group and share it with the contact
|
// Store the group and share it with the contact
|
||||||
db.addGroup(g);
|
db.addGroup(g);
|
||||||
db.setVisibility(g.getId(), Collections.singletonList(c.getId()));
|
db.setVisibleToContact(c.getId(), g.getId(), true);
|
||||||
// Attach the contact ID to the group
|
// Attach the contact ID to the group
|
||||||
BdfDictionary d = new BdfDictionary();
|
BdfDictionary d = new BdfDictionary();
|
||||||
d.put("contactId", c.getId().getInt());
|
d.put("contactId", c.getId().getInt());
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -77,7 +76,7 @@ class MessagingManagerImpl implements MessagingManager, AddContactHook,
|
|||||||
Group g = getContactGroup(c);
|
Group g = getContactGroup(c);
|
||||||
// Store the group and share it with the contact
|
// Store the group and share it with the contact
|
||||||
db.addGroup(g);
|
db.addGroup(g);
|
||||||
db.setVisibility(g.getId(), Collections.singletonList(c.getId()));
|
db.setVisibleToContact(c.getId(), g.getId(), true);
|
||||||
// Attach the contact ID to the group
|
// Attach the contact ID to the group
|
||||||
BdfDictionary d = new BdfDictionary();
|
BdfDictionary d = new BdfDictionary();
|
||||||
d.put("contactId", c.getId().getInt());
|
d.put("contactId", c.getId().getInt());
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
|||||||
Group g = getContactGroup(c);
|
Group g = getContactGroup(c);
|
||||||
// Store the group and share it with the contact
|
// Store the group and share it with the contact
|
||||||
db.addGroup(g);
|
db.addGroup(g);
|
||||||
db.setVisibility(g.getId(), Collections.singletonList(c.getId()));
|
db.setVisibleToContact(c.getId(), g.getId(), true);
|
||||||
// Copy the latest local properties into the group
|
// Copy the latest local properties into the group
|
||||||
DeviceId dev = db.getDeviceId();
|
DeviceId dev = db.getDeviceId();
|
||||||
Map<TransportId, TransportProperties> local = getLocalProperties();
|
Map<TransportId, TransportProperties> local = getLocalProperties();
|
||||||
|
|||||||
@@ -455,11 +455,11 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
|||||||
final EventBus eventBus = context.mock(EventBus.class);
|
final EventBus eventBus = context.mock(EventBus.class);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
// Check whether the group is in the DB (which it's not)
|
// Check whether the group is in the DB (which it's not)
|
||||||
exactly(9).of(database).startTransaction();
|
exactly(7).of(database).startTransaction();
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
exactly(9).of(database).containsGroup(txn, groupId);
|
exactly(7).of(database).containsGroup(txn, groupId);
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
exactly(9).of(database).abortTransaction(txn);
|
exactly(7).of(database).abortTransaction(txn);
|
||||||
// This is needed for getMessageStatus(), isVisibleToContact(), and
|
// This is needed for getMessageStatus(), isVisibleToContact(), and
|
||||||
// setVisibleToContact() to proceed
|
// setVisibleToContact() to proceed
|
||||||
exactly(3).of(database).containsContact(txn, contactId);
|
exactly(3).of(database).containsContact(txn, contactId);
|
||||||
@@ -489,13 +489,6 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
|||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
db.getVisibility(groupId);
|
|
||||||
fail();
|
|
||||||
} catch (NoSuchGroupException expected) {
|
|
||||||
// Expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.isVisibleToContact(contactId, groupId);
|
db.isVisibleToContact(contactId, groupId);
|
||||||
fail();
|
fail();
|
||||||
@@ -517,13 +510,6 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
|||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
db.setVisibility(groupId, Collections.<ContactId>emptyList());
|
|
||||||
fail();
|
|
||||||
} catch (NoSuchGroupException expected) {
|
|
||||||
// Expected
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.setVisibleToContact(contactId, groupId, true);
|
db.setVisibleToContact(contactId, groupId, true);
|
||||||
fail();
|
fail();
|
||||||
@@ -1048,8 +1034,6 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testChangingVisibilityCallsListeners() throws Exception {
|
public void testChangingVisibilityCallsListeners() throws Exception {
|
||||||
final ContactId contactId1 = new ContactId(123);
|
|
||||||
final Collection<ContactId> both = Arrays.asList(contactId, contactId1);
|
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final Database<Object> database = context.mock(Database.class);
|
final Database<Object> database = context.mock(Database.class);
|
||||||
@@ -1058,13 +1042,13 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
|||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(database).startTransaction();
|
oneOf(database).startTransaction();
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
|
oneOf(database).containsContact(txn, contactId);
|
||||||
|
will(returnValue(true));
|
||||||
oneOf(database).containsGroup(txn, groupId);
|
oneOf(database).containsGroup(txn, groupId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).getVisibility(txn, groupId);
|
oneOf(database).containsVisibleGroup(txn, contactId, groupId);
|
||||||
will(returnValue(both));
|
will(returnValue(false)); // Not yet visible
|
||||||
oneOf(database).getContactIds(txn);
|
oneOf(database).addVisibility(txn, contactId, groupId);
|
||||||
will(returnValue(both));
|
|
||||||
oneOf(database).removeVisibility(txn, contactId1, groupId);
|
|
||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
oneOf(eventBus).broadcast(with(any(
|
oneOf(eventBus).broadcast(with(any(
|
||||||
GroupVisibilityUpdatedEvent.class)));
|
GroupVisibilityUpdatedEvent.class)));
|
||||||
@@ -1072,7 +1056,7 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
|||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
shutdown);
|
||||||
|
|
||||||
db.setVisibility(groupId, Collections.singletonList(contactId));
|
db.setVisibleToContact(contactId, groupId, true);
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
@@ -1080,8 +1064,6 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testNotChangingVisibilityDoesNotCallListeners()
|
public void testNotChangingVisibilityDoesNotCallListeners()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
final ContactId contactId1 = new ContactId(123);
|
|
||||||
final Collection<ContactId> both = Arrays.asList(contactId, contactId1);
|
|
||||||
Mockery context = new Mockery();
|
Mockery context = new Mockery();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final Database<Object> database = context.mock(Database.class);
|
final Database<Object> database = context.mock(Database.class);
|
||||||
@@ -1090,18 +1072,18 @@ public class DatabaseComponentImplTest extends BriarTestCase {
|
|||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(database).startTransaction();
|
oneOf(database).startTransaction();
|
||||||
will(returnValue(txn));
|
will(returnValue(txn));
|
||||||
|
oneOf(database).containsContact(txn, contactId);
|
||||||
|
will(returnValue(true));
|
||||||
oneOf(database).containsGroup(txn, groupId);
|
oneOf(database).containsGroup(txn, groupId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
oneOf(database).getVisibility(txn, groupId);
|
oneOf(database).containsVisibleGroup(txn, contactId, groupId);
|
||||||
will(returnValue(both));
|
will(returnValue(true)); // Already visible
|
||||||
oneOf(database).getContactIds(txn);
|
|
||||||
will(returnValue(both));
|
|
||||||
oneOf(database).commitTransaction(txn);
|
oneOf(database).commitTransaction(txn);
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
DatabaseComponent db = createDatabaseComponent(database, eventBus,
|
||||||
shutdown);
|
shutdown);
|
||||||
|
|
||||||
db.setVisibility(groupId, both);
|
db.setVisibleToContact(contactId, groupId, true);
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
context.assertIsSatisfied();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user