mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Unify introduction response methods and handle ProtocolStateException
It is possible that a remote DECLINE message arrives short before the user responds to the introduction. This will cause a ProtocolStateException which (for now) is just caught and a generic (existing) error message will be shown.
This commit is contained in:
@@ -865,7 +865,8 @@ introductionOnboardingSeen();
|
||||
"Unknown Request Type");
|
||||
}
|
||||
loadMessages();
|
||||
} catch (DbException | FormatException e) {
|
||||
} catch (DbException e) {
|
||||
// TODO use more generic error message
|
||||
introductionResponseError();
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
@@ -898,11 +899,14 @@ introductionOnboardingSeen();
|
||||
|
||||
@DatabaseExecutor
|
||||
private void respondToIntroductionRequest(SessionId sessionId,
|
||||
boolean accept, long time) throws DbException, FormatException {
|
||||
if (accept) {
|
||||
introductionManager.acceptIntroduction(contactId, sessionId, time);
|
||||
} else {
|
||||
introductionManager.declineIntroduction(contactId, sessionId, time);
|
||||
boolean accept, long time) throws DbException {
|
||||
try {
|
||||
introductionManager
|
||||
.respondToIntroduction(contactId, sessionId, time, accept);
|
||||
} catch (ProtocolStateException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
introductionResponseError();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,16 +34,10 @@ public interface IntroductionManager extends ConversationClient {
|
||||
long timestamp) throws DbException;
|
||||
|
||||
/**
|
||||
* Accepts an introduction.
|
||||
* Responds to an introduction.
|
||||
*/
|
||||
void acceptIntroduction(ContactId contactId, SessionId sessionId,
|
||||
long timestamp) throws DbException;
|
||||
|
||||
/**
|
||||
* Declines an introduction.
|
||||
*/
|
||||
void declineIntroduction(ContactId contactId, SessionId sessionId,
|
||||
long timestamp) throws DbException;
|
||||
void respondToIntroduction(ContactId contactId, SessionId sessionId,
|
||||
long timestamp, boolean accept) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all introduction messages for the given contact.
|
||||
|
||||
@@ -339,18 +339,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptIntroduction(ContactId contactId, SessionId sessionId,
|
||||
long timestamp) throws DbException {
|
||||
respondToRequest(contactId, sessionId, timestamp, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void declineIntroduction(ContactId contactId, SessionId sessionId,
|
||||
long timestamp) throws DbException {
|
||||
respondToRequest(contactId, sessionId, timestamp, false);
|
||||
}
|
||||
|
||||
private void respondToRequest(ContactId contactId, SessionId sessionId,
|
||||
public void respondToIntroduction(ContactId contactId, SessionId sessionId,
|
||||
long timestamp, boolean accept) throws DbException {
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
|
||||
@@ -445,7 +445,8 @@ public class IntroductionIntegrationTest
|
||||
|
||||
// answer request manually
|
||||
introductionManager2
|
||||
.acceptIntroduction(contactId0From2, listener2.sessionId, time);
|
||||
.respondToIntroduction(contactId0From2, listener2.sessionId, time,
|
||||
true);
|
||||
|
||||
// sync second response and ACK and make sure there is no abort
|
||||
sync2To0(2, true);
|
||||
@@ -1003,25 +1004,13 @@ public class IntroductionIntegrationTest
|
||||
long time = clock.currentTimeMillis();
|
||||
try {
|
||||
if (introducee == 1 && answerRequests) {
|
||||
if (accept) {
|
||||
introductionManager1
|
||||
.acceptIntroduction(contactId, sessionId,
|
||||
time);
|
||||
} else {
|
||||
introductionManager1
|
||||
.declineIntroduction(contactId, sessionId,
|
||||
time);
|
||||
}
|
||||
introductionManager1
|
||||
.respondToIntroduction(contactId, sessionId,
|
||||
time, accept);
|
||||
} else if (introducee == 2 && answerRequests) {
|
||||
if (accept) {
|
||||
introductionManager2
|
||||
.acceptIntroduction(contactId, sessionId,
|
||||
time);
|
||||
} else {
|
||||
introductionManager2
|
||||
.declineIntroduction(contactId, sessionId,
|
||||
time);
|
||||
}
|
||||
introductionManager2
|
||||
.respondToIntroduction(contactId, sessionId,
|
||||
time, accept);
|
||||
}
|
||||
} catch (DbException exception) {
|
||||
eventWaiter.rethrow(exception);
|
||||
|
||||
Reference in New Issue
Block a user