mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Identity manager hooks. #209
This commit is contained in:
@@ -61,7 +61,6 @@ public class Contact {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof Contact) return id.equals(((Contact) o).id);
|
||||
return false;
|
||||
return o instanceof Contact && id.equals(((Contact) o).id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ public class ContactId {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof ContactId) return id == ((ContactId) o).id;
|
||||
return false;
|
||||
return o instanceof ContactId && id == ((ContactId) o).id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,6 +152,9 @@ public interface DatabaseComponent {
|
||||
/** Returns all contacts. */
|
||||
Collection<Contact> getContacts() throws DbException;
|
||||
|
||||
/** Returns all contacts associated with the given local pseudonym. */
|
||||
Collection<ContactId> getContacts(AuthorId a) throws DbException;
|
||||
|
||||
/** Returns the group with the given ID, if the user subscribes to it. */
|
||||
Group getGroup(GroupId g) throws DbException;
|
||||
|
||||
@@ -300,6 +303,10 @@ public interface DatabaseComponent {
|
||||
/** Sets the status of the given contact. */
|
||||
void setContactStatus(ContactId c, Contact.Status s) throws DbException;
|
||||
|
||||
/** Sets the status of the given local pseudonym. */
|
||||
void setLocalAuthorStatus(AuthorId a, LocalAuthor.Status s)
|
||||
throws DbException;
|
||||
|
||||
/** Marks the given message as valid or invalid. */
|
||||
void setMessageValidity(Message m, ClientId c, boolean valid)
|
||||
throws DbException;
|
||||
|
||||
@@ -6,6 +6,12 @@ import java.util.Collection;
|
||||
|
||||
public interface IdentityManager {
|
||||
|
||||
/** Registers a hook to be called whenever a local pseudonym is added. */
|
||||
void registerIdentityAddedHook(IdentityAddedHook hook);
|
||||
|
||||
/** Registers a hook to be called whenever a local pseudonym is removed. */
|
||||
void registerIdentityRemovedHook(IdentityRemovedHook hook);
|
||||
|
||||
/** Stores a local pseudonym. */
|
||||
void addLocalAuthor(LocalAuthor a) throws DbException;
|
||||
|
||||
@@ -17,4 +23,12 @@ public interface IdentityManager {
|
||||
|
||||
/** Removes a local pseudonym and all associated state. */
|
||||
void removeLocalAuthor(AuthorId a) throws DbException;
|
||||
|
||||
interface IdentityAddedHook {
|
||||
void identityAdded(AuthorId a);
|
||||
}
|
||||
|
||||
interface IdentityRemovedHook {
|
||||
void identityRemoved(AuthorId a);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,36 @@ package org.briarproject.api.identity;
|
||||
/** A pseudonym for the local user. */
|
||||
public class LocalAuthor extends Author {
|
||||
|
||||
public enum Status {
|
||||
|
||||
ADDING(0), ACTIVE(1), REMOVING(2);
|
||||
|
||||
private final int value;
|
||||
|
||||
Status(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static Status fromValue(int value) {
|
||||
for (Status s : values()) if (s.value == value) return s;
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
private final byte[] privateKey;
|
||||
private final long created;
|
||||
private final Status status;
|
||||
|
||||
public LocalAuthor(AuthorId id, String name, byte[] publicKey,
|
||||
byte[] privateKey, long created) {
|
||||
byte[] privateKey, long created, Status status) {
|
||||
super(id, name, publicKey);
|
||||
this.privateKey = privateKey;
|
||||
this.created = created;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/** Returns the private key used to generate the pseudonym's signatures. */
|
||||
@@ -18,7 +40,16 @@ public class LocalAuthor extends Author {
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time the pseudonym was created, in milliseconds since the
|
||||
* Unix epoch.
|
||||
*/
|
||||
public long getTimeCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
/** Returns the status of the pseudonym. */
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user