mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +01:00
Broadcast events for client versioning updates.
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
package org.briarproject.bramble.api.versioning.event;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
|
import org.briarproject.bramble.api.event.Event;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.versioning.ClientVersion;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event that is broadcast when we receive a client versioning update from
|
||||||
|
* a contact.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
@NotNullByDefault
|
||||||
|
public class ClientVersionUpdatedEvent extends Event {
|
||||||
|
|
||||||
|
private final ContactId contactId;
|
||||||
|
private final ClientVersion clientVersion;
|
||||||
|
|
||||||
|
public ClientVersionUpdatedEvent(ContactId contactId,
|
||||||
|
ClientVersion clientVersion) {
|
||||||
|
this.contactId = contactId;
|
||||||
|
this.clientVersion = clientVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContactId getContactId() {
|
||||||
|
return contactId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientVersion getClientVersion() {
|
||||||
|
return clientVersion;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ import org.briarproject.bramble.api.system.Clock;
|
|||||||
import org.briarproject.bramble.api.versioning.ClientMajorVersion;
|
import org.briarproject.bramble.api.versioning.ClientMajorVersion;
|
||||||
import org.briarproject.bramble.api.versioning.ClientVersion;
|
import org.briarproject.bramble.api.versioning.ClientVersion;
|
||||||
import org.briarproject.bramble.api.versioning.ClientVersioningManager;
|
import org.briarproject.bramble.api.versioning.ClientVersioningManager;
|
||||||
|
import org.briarproject.bramble.api.versioning.event.ClientVersionUpdatedEvent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -228,9 +229,21 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
|||||||
Map<ClientMajorVersion, Visibility> after =
|
Map<ClientMajorVersion, Visibility> after =
|
||||||
getVisibilities(newLocalStates, newRemoteStates);
|
getVisibilities(newLocalStates, newRemoteStates);
|
||||||
// Call hooks for any visibilities that have changed
|
// Call hooks for any visibilities that have changed
|
||||||
|
ContactId c = getContactId(txn, m.getGroupId());
|
||||||
if (!before.equals(after)) {
|
if (!before.equals(after)) {
|
||||||
Contact c = getContact(txn, m.getGroupId());
|
Contact contact = db.getContact(txn, c);
|
||||||
callVisibilityHooks(txn, c, before, after);
|
callVisibilityHooks(txn, contact, before, after);
|
||||||
|
}
|
||||||
|
// Broadcast events for any new client versions
|
||||||
|
Set<ClientVersion> oldRemoteVersions = new HashSet<>();
|
||||||
|
for (ClientState cs : oldRemoteStates) {
|
||||||
|
oldRemoteVersions.add(cs.clientVersion);
|
||||||
|
}
|
||||||
|
for (ClientState cs : newRemoteStates) {
|
||||||
|
if (!oldRemoteVersions.contains(cs.clientVersion)) {
|
||||||
|
txn.attach(new ClientVersionUpdatedEvent(c,
|
||||||
|
cs.clientVersion));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new InvalidMessageException(e);
|
throw new InvalidMessageException(e);
|
||||||
@@ -508,12 +521,12 @@ class ClientVersioningManagerImpl implements ClientVersioningManager,
|
|||||||
storeUpdate(txn, g, states, 1);
|
storeUpdate(txn, g, states, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Contact getContact(Transaction txn, GroupId g) throws DbException {
|
private ContactId getContactId(Transaction txn, GroupId g)
|
||||||
|
throws DbException {
|
||||||
try {
|
try {
|
||||||
BdfDictionary meta =
|
BdfDictionary meta =
|
||||||
clientHelper.getGroupMetadataAsDictionary(txn, g);
|
clientHelper.getGroupMetadataAsDictionary(txn, g);
|
||||||
int id = meta.getLong(GROUP_KEY_CONTACT_ID).intValue();
|
return new ContactId(meta.getLong(GROUP_KEY_CONTACT_ID).intValue());
|
||||||
return db.getContact(txn, new ContactId(id));
|
|
||||||
} catch (FormatException e) {
|
} catch (FormatException e) {
|
||||||
throw new DbException(e);
|
throw new DbException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user