conversation_module: retry to sync if first connection fails

If first connection fails and presence is not tracked, the
conversation will not sync until the receiver restarts its jami,
causing the conversation to be stuck a very long time even if
peer is online and can sync.
In this patch, if we receives a trust request, we retry to sync
(this will be the case because the sender will re-send a trust
request to the contact who is still detected as an invited member)

GitLab: #922
Change-Id: I8866ceda98d50b0ddd2ea5402ef34f067f560e97
This commit is contained in:
Sébastien Blin
2023-11-22 10:04:50 -05:00
parent 63172ddf16
commit 191396aa1b
9 changed files with 116 additions and 58 deletions

View File

@ -60,6 +60,7 @@ public:
void testAddMember();
void testMemberAddedNoBadFile();
void testAddOfflineMemberThenConnects();
void testAddAcceptOfflineThenConnects();
void testGetMembers();
void testRemoveMember();
void testRemovedMemberDoesNotReceiveMessage();
@ -105,6 +106,7 @@ private:
CPPUNIT_TEST(testAddMember);
CPPUNIT_TEST(testMemberAddedNoBadFile);
CPPUNIT_TEST(testAddOfflineMemberThenConnects);
CPPUNIT_TEST(testAddAcceptOfflineThenConnects);
CPPUNIT_TEST(testGetMembers);
CPPUNIT_TEST(testRemoveMember);
CPPUNIT_TEST(testRemovedMemberDoesNotReceiveMessage);
@ -468,13 +470,54 @@ ConversationMembersEventTest::testAddOfflineMemberThenConnects()
CPPUNIT_ASSERT(cv.wait_for(lk, 60s, [&] { return requestReceived; }));
libjami::acceptConversationRequest(carlaId, convId);
cv.wait_for(lk, 30s, [&]() { return conversationReady; });
CPPUNIT_ASSERT(cv.wait_for(lk, 30s, [&]() { return conversationReady; }));
auto clonedPath = fileutils::get_data_dir() / carlaAccount->getAccountID()
/ "conversations" / convId;
CPPUNIT_ASSERT(std::filesystem::is_directory(clonedPath));
libjami::unregisterSignalHandlers();
}
void
ConversationMembersEventTest::testAddAcceptOfflineThenConnects()
{
auto aliceAccount = Manager::instance().getAccount<JamiAccount>(aliceId);
auto bobAccount = Manager::instance().getAccount<JamiAccount>(bobId);
auto bobUri = bobAccount->getUsername();
auto convId = libjami::startConversation(aliceId);
std::map<std::string, std::shared_ptr<libjami::CallbackWrapperBase>> confHandlers;
bool conversationReady = false, requestReceived = false;
confHandlers.insert(libjami::exportable_callback<libjami::ConversationSignal::ConversationReady>(
[&](const std::string& accountId, const std::string& /* conversationId */) {
if (accountId == bobId) {
conversationReady = true;
cv.notify_one();
}
}));
confHandlers.insert(
libjami::exportable_callback<libjami::ConversationSignal::ConversationRequestReceived>(
[&](const std::string& /*accountId*/,
const std::string& /* conversationId */,
std::map<std::string, std::string> /*metadatas*/) {
requestReceived = true;
cv.notify_one();
}));
libjami::registerSignalHandlers(confHandlers);
libjami::addConversationMember(aliceId, convId, bobUri);
CPPUNIT_ASSERT(cv.wait_for(lk, 60s, [&] { return requestReceived; }));
Manager::instance().sendRegister(aliceId, false); // This avoid to sync immediately
libjami::acceptConversationRequest(bobId, convId);
std::this_thread::sleep_for(40s); // Wait for negotiation to timeout
Manager::instance().sendRegister(aliceId, true); // This avoid to sync immediately
CPPUNIT_ASSERT(cv.wait_for(lk, 30s, [&]() { return conversationReady; }));
libjami::unregisterSignalHandlers();
}
void
ConversationMembersEventTest::testGetMembers()
{