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:
Torsten Grote
2018-04-26 18:18:31 -03:00
parent f8f98ed95d
commit 337f7e7b8f
4 changed files with 22 additions and 46 deletions

View File

@@ -865,7 +865,8 @@ introductionOnboardingSeen();
"Unknown Request Type"); "Unknown Request Type");
} }
loadMessages(); loadMessages();
} catch (DbException | FormatException e) { } catch (DbException e) {
// TODO use more generic error message
introductionResponseError(); introductionResponseError();
if (LOG.isLoggable(WARNING)) if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e); LOG.log(WARNING, e.toString(), e);
@@ -898,11 +899,14 @@ introductionOnboardingSeen();
@DatabaseExecutor @DatabaseExecutor
private void respondToIntroductionRequest(SessionId sessionId, private void respondToIntroductionRequest(SessionId sessionId,
boolean accept, long time) throws DbException, FormatException { boolean accept, long time) throws DbException {
if (accept) { try {
introductionManager.acceptIntroduction(contactId, sessionId, time); introductionManager
} else { .respondToIntroduction(contactId, sessionId, time, accept);
introductionManager.declineIntroduction(contactId, sessionId, time); } catch (ProtocolStateException e) {
if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);
introductionResponseError();
} }
} }

View File

@@ -34,16 +34,10 @@ public interface IntroductionManager extends ConversationClient {
long timestamp) throws DbException; long timestamp) throws DbException;
/** /**
* Accepts an introduction. * Responds to an introduction.
*/ */
void acceptIntroduction(ContactId contactId, SessionId sessionId, void respondToIntroduction(ContactId contactId, SessionId sessionId,
long timestamp) throws DbException; long timestamp, boolean accept) throws DbException;
/**
* Declines an introduction.
*/
void declineIntroduction(ContactId contactId, SessionId sessionId,
long timestamp) throws DbException;
/** /**
* Returns all introduction messages for the given contact. * Returns all introduction messages for the given contact.

View File

@@ -339,18 +339,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
} }
@Override @Override
public void acceptIntroduction(ContactId contactId, SessionId sessionId, public void respondToIntroduction(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,
long timestamp, boolean accept) throws DbException { long timestamp, boolean accept) throws DbException {
Transaction txn = db.startTransaction(false); Transaction txn = db.startTransaction(false);
try { try {

View File

@@ -445,7 +445,8 @@ public class IntroductionIntegrationTest
// answer request manually // answer request manually
introductionManager2 introductionManager2
.acceptIntroduction(contactId0From2, listener2.sessionId, time); .respondToIntroduction(contactId0From2, listener2.sessionId, time,
true);
// sync second response and ACK and make sure there is no abort // sync second response and ACK and make sure there is no abort
sync2To0(2, true); sync2To0(2, true);
@@ -1003,25 +1004,13 @@ public class IntroductionIntegrationTest
long time = clock.currentTimeMillis(); long time = clock.currentTimeMillis();
try { try {
if (introducee == 1 && answerRequests) { if (introducee == 1 && answerRequests) {
if (accept) { introductionManager1
introductionManager1 .respondToIntroduction(contactId, sessionId,
.acceptIntroduction(contactId, sessionId, time, accept);
time);
} else {
introductionManager1
.declineIntroduction(contactId, sessionId,
time);
}
} else if (introducee == 2 && answerRequests) { } else if (introducee == 2 && answerRequests) {
if (accept) { introductionManager2
introductionManager2 .respondToIntroduction(contactId, sessionId,
.acceptIntroduction(contactId, sessionId, time, accept);
time);
} else {
introductionManager2
.declineIntroduction(contactId, sessionId,
time);
}
} }
} catch (DbException exception) { } catch (DbException exception) {
eventWaiter.rethrow(exception); eventWaiter.rethrow(exception);