Commit bc655178 authored by johan's avatar johan

Do not ever again use soci bulk operation

- bugged(only on gcc-4.9)
- use rowset instead
parent 1243693c
...@@ -609,26 +609,14 @@ void Lime<Curve>::cache_DR_sessions(std::vector<recipientInfos<Curve>> &internal ...@@ -609,26 +609,14 @@ void Lime<Curve>::cache_DR_sessions(std::vector<recipientInfos<Curve>> &internal
sqlString_requestedDevices.pop_back(); // remove the last ',' sqlString_requestedDevices.pop_back(); // remove the last ','
/* fetch them from DB */ /* fetch them from DB */
std::vector<long int>sessionId(requestedDevicesCount); rowset<row> rs = (m_localStorage->sql.prepare << "SELECT s.sessionId, d.DeviceId FROM DR_sessions as s INNER JOIN lime_PeerDevices as d ON s.Did=d.Did WHERE d.Uid= :Uid AND s.Status=1 AND d.DeviceId IN ("<<sqlString_requestedDevices<<");", use(m_db_Uid));
std::vector<std::string>peerId(requestedDevicesCount); for (auto &r : rs) {
auto sessionId = r.get<int>(0);
statement st = (m_localStorage->sql.prepare << "SELECT s.sessionId, d.DeviceId FROM DR_sessions as s INNER JOIN lime_PeerDevices as d ON s.Did=d.Did WHERE d.Uid= :Uid AND s.Status=1 AND d.DeviceId IN ("<<sqlString_requestedDevices<<");", into(sessionId), into(peerId), use(m_db_Uid)); auto peerDeviceId = r.get<string>(1);
st.execute(); auto DRsession = std::make_shared<DR<Curve>>(m_localStorage.get(), sessionId); // load session from local storage
while (st.fetch()) { // we shall do it only once as we probably won't get more devices than requested, could happend if DB is in chaos and we have several sessions actives for one pair requestedDevices[peerDeviceId] = DRsession; // store found session in a our temp container
/* load session in cache for them */ m_DR_sessions_cache[peerDeviceId] = DRsession; // session is also stored in cache
for (size_t i=0; i<sessionId.size(); i++ ) {
requestedDevices[peerId[i]] = std::make_shared<DR<Curve>>(m_localStorage.get(), sessionId[i]); // load session from cache
}
/* loop on found sessions and store them in cache */
for (auto &recipient : requestedDevices) {
m_DR_sessions_cache[recipient.first] = recipient.second;
}
// useless but recommended by SOCI spec
sessionId.resize(requestedDevicesCount);
peerId.resize(requestedDevicesCount);
} }
/* loop on internal recipient and fill it with the found ones, store the missing ones in the missing_devices vector */ /* loop on internal recipient and fill it with the found ones, store the missing ones in the missing_devices vector */
...@@ -638,7 +626,7 @@ void Lime<Curve>::cache_DR_sessions(std::vector<recipientInfos<Curve>> &internal ...@@ -638,7 +626,7 @@ void Lime<Curve>::cache_DR_sessions(std::vector<recipientInfos<Curve>> &internal
if (retrievedElem == requestedDevices.end()) { // we didn't found this one if (retrievedElem == requestedDevices.end()) { // we didn't found this one
missing_devices.push_back(recipient.deviceId); missing_devices.push_back(recipient.deviceId);
} else { // we got this one } else { // we got this one
recipient.DRSession = std::move(retrievedElem->second); // don't need this pointer in map anymore recipient.DRSession = std::move(retrievedElem->second); // don't need this pointer in tmp comtainer anymore
} }
} }
} }
...@@ -686,16 +674,11 @@ long int Lime<Curve>::store_peerDevice(const std::string &peerDeviceId, const ED ...@@ -686,16 +674,11 @@ long int Lime<Curve>::store_peerDevice(const std::string &peerDeviceId, const ED
// load from local storage in DRSessions all DR session matching the peerDeviceId, ignore the one picked by id in 2nd arg // load from local storage in DRSessions all DR session matching the peerDeviceId, ignore the one picked by id in 2nd arg
template <typename Curve> template <typename Curve>
void Lime<Curve>::get_DRSessions(const std::string &senderDeviceId, const long int ignoreThisDRSessionId, std::vector<std::shared_ptr<DR<Curve>>> &DRSessions) { void Lime<Curve>::get_DRSessions(const std::string &senderDeviceId, const long int ignoreThisDRSessionId, std::vector<std::shared_ptr<DR<Curve>>> &DRSessions) {
std::vector<long int> sessionIds(10); // get sessions 10 by 10, one fetch shall be enough anyway rowset<int> rs = (m_localStorage->sql.prepare << "SELECT s.sessionId FROM DR_sessions as s INNER JOIN lime_PeerDevices as d ON s.Did=d.Did WHERE d.DeviceId = :senderDeviceId AND s.sessionId <> :ignoreThisDRSessionId ORDER BY s.Status DESC, timeStamp ASC;", use(senderDeviceId), use(ignoreThisDRSessionId));
statement st = (m_localStorage->sql.prepare << "SELECT s.sessionId FROM DR_sessions as s INNER JOIN lime_PeerDevices as d ON s.Did=d.Did WHERE d.DeviceId = :senderDeviceId AND s.sessionId <> :ignoreThisDRSessionId ORDER BY s.Status DESC, timeStamp ASC;", into(sessionIds), use(senderDeviceId), use(ignoreThisDRSessionId));
st.execute(); for (auto sessionId : rs) {
/* load session in cache DRSessions */
while (st.fetch()) { DRSessions.push_back(make_shared<DR<Curve>>(m_localStorage.get(), sessionId)); // load session from cache
for (auto sessionId : sessionIds) {
/* load session in cache DRSessions */
DRSessions.push_back(make_shared<DR<Curve>>(m_localStorage.get(), sessionId)); // load session from cache
}
sessionIds.resize(10);
} }
}; };
......
...@@ -206,13 +206,14 @@ static void x3dh_sending_chain_limit_test(const lime::CurveId curve, const std:: ...@@ -206,13 +206,14 @@ static void x3dh_sending_chain_limit_test(const lime::CurveId curve, const std::
if (!continuousSession) { managersClean (aliceManager, bobManager, dbFilenameAlice, dbFilenameBob);} if (!continuousSession) { managersClean (aliceManager, bobManager, dbFilenameAlice, dbFilenameBob);}
BC_ASSERT_FALSE(DR_message_holdsX3DHInit((*aliceRecipients)[0].cipherHeader)); // it's an ongoing session, no X3DH init BC_ASSERT_FALSE(DR_message_holdsX3DHInit((*aliceRecipients)[0].cipherHeader)); // it's an ongoing session, no X3DH init
/*
// bob decrypt, it's not really needed here but... // bob decrypt, it's not really needed here but cannot really hurt, comment if the test is too slow
/*
std::vector<uint8_t> receivedMessage{}; std::vector<uint8_t> receivedMessage{};
BC_ASSERT_TRUE(bobManager->decrypt(*bobDevice1, "bob", *aliceDevice1, (*aliceRecipients)[0].cipherHeader, *aliceCipherMessage, receivedMessage)); BC_ASSERT_TRUE(bobManager->decrypt(*bobDevice1, "bob", *aliceDevice1, (*aliceRecipients)[0].cipherHeader, *aliceCipherMessage, receivedMessage));
std::string receivedMessageString{receivedMessage.begin(), receivedMessage.end()}; std::string receivedMessageString{receivedMessage.begin(), receivedMessage.end()};
BC_ASSERT_TRUE(receivedMessageString == lime_messages_pattern[i%lime_messages_pattern.size()]); BC_ASSERT_TRUE(receivedMessageString == lime_messages_pattern[i%lime_messages_pattern.size()]);
*/ */
} }
} catch (BctbxException &e) { } catch (BctbxException &e) {
BCTBX_SLOGE <<e;; BCTBX_SLOGE <<e;;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment