mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
add transactional versions to introductionManager and privateGroupManager
This commit is contained in:
@@ -300,36 +300,37 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
|
||||
@Override
|
||||
public boolean canIntroduce(Contact c1, Contact c2) throws DbException {
|
||||
Transaction txn = db.startTransaction(true);
|
||||
return db.transactionWithResult(true,
|
||||
txn -> canIntroduce(txn, c1, c2));
|
||||
}
|
||||
|
||||
public boolean canIntroduce(Transaction txn, Contact c1, Contact c2)
|
||||
throws DbException {
|
||||
try {
|
||||
boolean can = canIntroduce(txn, c1, c2);
|
||||
db.commitTransaction(txn);
|
||||
return can;
|
||||
// Look up the session, if there is one
|
||||
Author introducer = identityManager.getLocalAuthor(txn);
|
||||
SessionId sessionId =
|
||||
crypto.getSessionId(introducer, c1.getAuthor(),
|
||||
c2.getAuthor());
|
||||
StoredSession ss = getSession(txn, sessionId);
|
||||
if (ss == null) return true;
|
||||
IntroducerSession session =
|
||||
sessionParser.parseIntroducerSession(ss.bdfSession);
|
||||
return session.getState().isComplete();
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canIntroduce(Transaction txn, Contact c1, Contact c2)
|
||||
throws DbException, FormatException {
|
||||
// Look up the session, if there is one
|
||||
Author introducer = identityManager.getLocalAuthor(txn);
|
||||
SessionId sessionId =
|
||||
crypto.getSessionId(introducer, c1.getAuthor(),
|
||||
c2.getAuthor());
|
||||
StoredSession ss = getSession(txn, sessionId);
|
||||
if (ss == null) return true;
|
||||
IntroducerSession session =
|
||||
sessionParser.parseIntroducerSession(ss.bdfSession);
|
||||
return session.getState().isComplete();
|
||||
public void makeIntroduction(Contact c1, Contact c2, @Nullable String text)
|
||||
throws DbException {
|
||||
db.transaction(false,
|
||||
txn -> makeIntroduction(txn, c1, c2, text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void makeIntroduction(Contact c1, Contact c2, @Nullable String text)
|
||||
throws DbException {
|
||||
Transaction txn = db.startTransaction(false);
|
||||
public void makeIntroduction(Transaction txn, Contact c1, Contact c2,
|
||||
@Nullable String text) throws DbException {
|
||||
try {
|
||||
// Look up the session, if there is one
|
||||
Author introducer = identityManager.getLocalAuthor(txn);
|
||||
@@ -363,11 +364,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
session = introducerEngine.onRequestAction(txn, session, text);
|
||||
// Store the updated session
|
||||
storeSession(txn, storageId, session);
|
||||
db.commitTransaction(txn);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,40 +150,35 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePrivateGroup(GroupId g) throws DbException {
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
for (PrivateGroupHook hook : hooks) {
|
||||
hook.removingGroup(txn, g);
|
||||
}
|
||||
Group group = db.getGroup(txn, g);
|
||||
db.removeGroup(txn, group);
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
public void removePrivateGroup(Transaction txn, GroupId g)
|
||||
throws DbException {
|
||||
for (PrivateGroupHook hook : hooks) {
|
||||
hook.removingGroup(txn, g);
|
||||
}
|
||||
Group group = db.getGroup(txn, g);
|
||||
db.removeGroup(txn, group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePrivateGroup(GroupId g) throws DbException {
|
||||
db.transaction(false, txn -> removePrivateGroup(txn, g));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageId getPreviousMsgId(GroupId g) throws DbException {
|
||||
MessageId previousMsgId;
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
previousMsgId = getPreviousMsgId(txn, g);
|
||||
db.commitTransaction(txn);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
return previousMsgId;
|
||||
return db.transactionWithResult(true,
|
||||
txn -> getPreviousMsgId(txn, g));
|
||||
}
|
||||
|
||||
private MessageId getPreviousMsgId(Transaction txn, GroupId g)
|
||||
throws DbException, FormatException {
|
||||
BdfDictionary d = clientHelper.getGroupMetadataAsDictionary(txn, g);
|
||||
byte[] previousMsgIdBytes = d.getRaw(KEY_PREVIOUS_MSG_ID);
|
||||
return new MessageId(previousMsgIdBytes);
|
||||
public MessageId getPreviousMsgId(Transaction txn, GroupId g)
|
||||
throws DbException {
|
||||
try {
|
||||
BdfDictionary d = clientHelper.getGroupMetadataAsDictionary(txn, g);
|
||||
byte[] previousMsgIdBytes = d.getRaw(KEY_PREVIOUS_MSG_ID);
|
||||
return new MessageId(previousMsgIdBytes);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void setPreviousMsgId(Transaction txn, GroupId g,
|
||||
@@ -483,11 +478,16 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
return messageTracker.getGroupCount(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadFlag(Transaction txn, GroupId g, MessageId m,
|
||||
boolean read) throws DbException {
|
||||
messageTracker.setReadFlag(txn, g, m, read);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadFlag(GroupId g, MessageId m, boolean read)
|
||||
throws DbException {
|
||||
db.transaction(false, txn ->
|
||||
messageTracker.setReadFlag(txn, g, m, read));
|
||||
db.transaction(false, txn -> setReadFlag(txn, g, m, read));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user