mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
transactional versions of addPendingContact, getPendingContacts, getConversationId and respondToIntroduction
This commit is contained in:
committed by
Sebastian Kürten
parent
c340071469
commit
5b27eb354c
@@ -113,6 +113,26 @@ public interface ContactManager {
|
||||
*/
|
||||
String getHandshakeLink(Transaction txn) throws DbException;
|
||||
|
||||
/**
|
||||
* Creates a {@link PendingContact} from the given handshake link and
|
||||
* alias, adds it to the database and returns it.
|
||||
*
|
||||
* @param link The handshake link received from the pending contact
|
||||
* @param alias The alias the user has given this pending contact
|
||||
* @throws UnsupportedVersionException If the link uses a format version
|
||||
* that is not supported
|
||||
* @throws FormatException If the link is invalid
|
||||
* @throws GeneralSecurityException If the pending contact's handshake
|
||||
* public key is invalid
|
||||
* @throws ContactExistsException If a contact with the same handshake
|
||||
* public key already exists
|
||||
* @throws PendingContactExistsException If a pending contact with the same
|
||||
* handshake public key already exists
|
||||
*/
|
||||
PendingContact addPendingContact(Transaction txn, String link, String alias)
|
||||
throws DbException, FormatException, GeneralSecurityException,
|
||||
ContactExistsException, PendingContactExistsException;
|
||||
|
||||
/**
|
||||
* Creates a {@link PendingContact} from the given handshake link and
|
||||
* alias, adds it to the database and returns it.
|
||||
@@ -146,6 +166,13 @@ public interface ContactManager {
|
||||
Collection<Pair<PendingContact, PendingContactState>> getPendingContacts()
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns a list of {@link PendingContact PendingContacts} and their
|
||||
* {@link PendingContactState states}.
|
||||
*/
|
||||
Collection<Pair<PendingContact, PendingContactState>> getPendingContacts(Transaction txn)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Removes a {@link PendingContact}.
|
||||
*/
|
||||
|
||||
@@ -131,22 +131,29 @@ class ContactManagerImpl implements ContactManager, EventListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PendingContact addPendingContact(String link, String alias)
|
||||
public PendingContact addPendingContact(Transaction txn, String link, String alias)
|
||||
throws DbException, FormatException, GeneralSecurityException {
|
||||
PendingContact p =
|
||||
pendingContactFactory.createPendingContact(link, alias);
|
||||
AuthorId local = identityManager.getLocalAuthor(txn).getId();
|
||||
db.addPendingContact(txn, p, local);
|
||||
KeyPair ourKeyPair = identityManager.getHandshakeKeys(txn);
|
||||
keyManager.addPendingContact(txn, p.getId(), p.getPublicKey(),
|
||||
ourKeyPair);
|
||||
return p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PendingContact addPendingContact(String link, String alias)
|
||||
throws DbException, FormatException, GeneralSecurityException {
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
AuthorId local = identityManager.getLocalAuthor(txn).getId();
|
||||
db.addPendingContact(txn, p, local);
|
||||
KeyPair ourKeyPair = identityManager.getHandshakeKeys(txn);
|
||||
keyManager.addPendingContact(txn, p.getId(), p.getPublicKey(),
|
||||
ourKeyPair);
|
||||
PendingContact p = addPendingContact(txn, link, alias);
|
||||
db.commitTransaction(txn);
|
||||
return p;
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -158,8 +165,13 @@ class ContactManagerImpl implements ContactManager, EventListener {
|
||||
@Override
|
||||
public Collection<Pair<PendingContact, PendingContactState>> getPendingContacts()
|
||||
throws DbException {
|
||||
Collection<PendingContact> pendingContacts =
|
||||
db.transactionWithResult(true, db::getPendingContacts);
|
||||
return db.transactionWithResult(true, this::getPendingContacts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Pair<PendingContact, PendingContactState>> getPendingContacts(Transaction txn)
|
||||
throws DbException {
|
||||
Collection<PendingContact> pendingContacts = db.getPendingContacts(txn);
|
||||
List<Pair<PendingContact, PendingContactState>> pairs =
|
||||
new ArrayList<>(pendingContacts.size());
|
||||
for (PendingContact p : pendingContacts) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.briar.api.introduction;
|
||||
import org.briarproject.bramble.api.contact.Contact;
|
||||
import org.briarproject.bramble.api.contact.ContactId;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.Transaction;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.ClientId;
|
||||
import org.briarproject.briar.api.client.SessionId;
|
||||
@@ -45,4 +46,10 @@ public interface IntroductionManager extends ConversationClient {
|
||||
void respondToIntroduction(ContactId contactId, SessionId sessionId,
|
||||
boolean accept) throws DbException;
|
||||
|
||||
/**
|
||||
* Responds to an introduction.
|
||||
*/
|
||||
void respondToIntroduction(Transaction txn, ContactId contactId,
|
||||
SessionId sessionId, boolean accept) throws DbException;
|
||||
|
||||
}
|
||||
|
||||
@@ -67,6 +67,11 @@ public interface MessagingManager extends ConversationClient {
|
||||
*/
|
||||
GroupId getConversationId(ContactId c) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the ID of the private conversation with the given contact.
|
||||
*/
|
||||
GroupId getConversationId(Transaction txn, ContactId c) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the text of the private message with the given ID, or null if
|
||||
* the private message has no text.
|
||||
|
||||
@@ -377,6 +377,12 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
respondToIntroduction(contactId, sessionId, accept, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void respondToIntroduction(Transaction txn, ContactId contactId,
|
||||
SessionId sessionId, boolean accept) throws DbException {
|
||||
respondToIntroduction(txn, contactId, sessionId, accept, false);
|
||||
}
|
||||
|
||||
private void respondToIntroduction(ContactId contactId, SessionId sessionId,
|
||||
boolean accept, boolean isAutoDecline) throws DbException {
|
||||
db.transaction(false,
|
||||
|
||||
@@ -389,14 +389,13 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
|
||||
|
||||
@Override
|
||||
public GroupId getConversationId(ContactId c) throws DbException {
|
||||
Contact contact;
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
contact = db.getContact(txn, c);
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return db.transactionWithResult(true,
|
||||
txn -> getConversationId(txn, c));
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupId getConversationId(Transaction txn, ContactId c) throws DbException {
|
||||
Contact contact = db.getContact(txn, c);
|
||||
return getContactGroup(contact).getId();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user