mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 13:49:53 +01:00
Merge branch 'add-pending-contact-transactional' into 'master'
Transactional versions of some more API calls See merge request briar/briar!1561
This commit is contained in:
@@ -113,6 +113,26 @@ public interface ContactManager {
|
|||||||
*/
|
*/
|
||||||
String getHandshakeLink(Transaction txn) throws DbException;
|
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
|
* Creates a {@link PendingContact} from the given handshake link and
|
||||||
* alias, adds it to the database and returns it.
|
* alias, adds it to the database and returns it.
|
||||||
@@ -146,6 +166,13 @@ public interface ContactManager {
|
|||||||
Collection<Pair<PendingContact, PendingContactState>> getPendingContacts()
|
Collection<Pair<PendingContact, PendingContactState>> getPendingContacts()
|
||||||
throws DbException;
|
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}.
|
* Removes a {@link PendingContact}.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -131,22 +131,29 @@ class ContactManagerImpl implements ContactManager, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PendingContact addPendingContact(String link, String alias)
|
public PendingContact addPendingContact(Transaction txn, String link, String alias)
|
||||||
throws DbException, FormatException, GeneralSecurityException {
|
throws DbException, FormatException, GeneralSecurityException {
|
||||||
PendingContact p =
|
PendingContact p =
|
||||||
pendingContactFactory.createPendingContact(link, alias);
|
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);
|
Transaction txn = db.startTransaction(false);
|
||||||
try {
|
try {
|
||||||
AuthorId local = identityManager.getLocalAuthor(txn).getId();
|
PendingContact p = addPendingContact(txn, link, alias);
|
||||||
db.addPendingContact(txn, p, local);
|
|
||||||
KeyPair ourKeyPair = identityManager.getHandshakeKeys(txn);
|
|
||||||
keyManager.addPendingContact(txn, p.getId(), p.getPublicKey(),
|
|
||||||
ourKeyPair);
|
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
|
return p;
|
||||||
} finally {
|
} finally {
|
||||||
db.endTransaction(txn);
|
db.endTransaction(txn);
|
||||||
}
|
}
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -158,8 +165,13 @@ class ContactManagerImpl implements ContactManager, EventListener {
|
|||||||
@Override
|
@Override
|
||||||
public Collection<Pair<PendingContact, PendingContactState>> getPendingContacts()
|
public Collection<Pair<PendingContact, PendingContactState>> getPendingContacts()
|
||||||
throws DbException {
|
throws DbException {
|
||||||
Collection<PendingContact> pendingContacts =
|
return db.transactionWithResult(true, this::getPendingContacts);
|
||||||
db.transactionWithResult(true, db::getPendingContacts);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Pair<PendingContact, PendingContactState>> getPendingContacts(Transaction txn)
|
||||||
|
throws DbException {
|
||||||
|
Collection<PendingContact> pendingContacts = db.getPendingContacts(txn);
|
||||||
List<Pair<PendingContact, PendingContactState>> pairs =
|
List<Pair<PendingContact, PendingContactState>> pairs =
|
||||||
new ArrayList<>(pendingContacts.size());
|
new ArrayList<>(pendingContacts.size());
|
||||||
for (PendingContact p : pendingContacts) {
|
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.Contact;
|
||||||
import org.briarproject.bramble.api.contact.ContactId;
|
import org.briarproject.bramble.api.contact.ContactId;
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
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.nullsafety.NotNullByDefault;
|
||||||
import org.briarproject.bramble.api.sync.ClientId;
|
import org.briarproject.bramble.api.sync.ClientId;
|
||||||
import org.briarproject.briar.api.client.SessionId;
|
import org.briarproject.briar.api.client.SessionId;
|
||||||
@@ -45,4 +46,10 @@ public interface IntroductionManager extends ConversationClient {
|
|||||||
void respondToIntroduction(ContactId contactId, SessionId sessionId,
|
void respondToIntroduction(ContactId contactId, SessionId sessionId,
|
||||||
boolean accept) throws DbException;
|
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;
|
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
|
* Returns the text of the private message with the given ID, or null if
|
||||||
* the private message has no text.
|
* the private message has no text.
|
||||||
|
|||||||
@@ -377,6 +377,12 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
|||||||
respondToIntroduction(contactId, sessionId, accept, false);
|
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,
|
private void respondToIntroduction(ContactId contactId, SessionId sessionId,
|
||||||
boolean accept, boolean isAutoDecline) throws DbException {
|
boolean accept, boolean isAutoDecline) throws DbException {
|
||||||
db.transaction(false,
|
db.transaction(false,
|
||||||
|
|||||||
@@ -389,14 +389,13 @@ class MessagingManagerImpl implements MessagingManager, IncomingMessageHook,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GroupId getConversationId(ContactId c) throws DbException {
|
public GroupId getConversationId(ContactId c) throws DbException {
|
||||||
Contact contact;
|
return db.transactionWithResult(true,
|
||||||
Transaction txn = db.startTransaction(true);
|
txn -> getConversationId(txn, c));
|
||||||
try {
|
}
|
||||||
contact = db.getContact(txn, c);
|
|
||||||
db.commitTransaction(txn);
|
@Override
|
||||||
} finally {
|
public GroupId getConversationId(Transaction txn, ContactId c) throws DbException {
|
||||||
db.endTransaction(txn);
|
Contact contact = db.getContact(txn, c);
|
||||||
}
|
|
||||||
return getContactGroup(contact).getId();
|
return getContactGroup(contact).getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user