Browse Source

Fix: call register_sync_callbacks() ONLY in sync thread.

No other session/thread will have sync callbacks registered.
This is essentially reverting a change that has been done for 3.0, but i think it was wrong
pull/15/head
heck 3 years ago
parent
commit
3bcb00ab58
  1. 15
      src/Adapter.cc
  2. 22
      src/Adapter.hxx
  3. 31
      test/test_leave_device_group.cc

15
src/Adapter.cc

@ -150,7 +150,6 @@ namespace pEp {
void Session::refresh() void Session::refresh()
{ {
std::lock_guard<mutex> lock(mut); std::lock_guard<mutex> lock(mut);
release();
// Switch to mode "Sync" ensures the sync thread to be shutdown // Switch to mode "Sync" ensures the sync thread to be shutdown
if (_sync_mode == SyncModes::Sync) { if (_sync_mode == SyncModes::Sync) {
@ -172,17 +171,9 @@ namespace pEp {
::PEP_SESSION session_{ nullptr }; ::PEP_SESSION session_{ nullptr };
::PEP_STATUS status = ::init(&session_, _messageToSend, _inject_action, _ensure_passphrase); ::PEP_STATUS status = ::init(&session_, _messageToSend, _inject_action, _ensure_passphrase);
throw_status(status); throw_status(status);
status = ::register_sync_callbacks(
session_, // replace "atomically"
nullptr, release();
_notifyHandshake,
_retrieve_next_sync_event);
if (status != PEP_STATUS_OK) {
pEpLog("libpEpAdapter: WARNING - session is initialized but without sync/callbacks. "
"This is normal if there are no own identities yet. Call session.init() again to "
"re-initialize the session after creating an own identity.");
}
// store
_session = SessionPtr{ session_, ::release }; _session = SessionPtr{ session_, ::release };
} }

22
src/Adapter.hxx

@ -46,15 +46,23 @@ namespace pEp {
_startup(obj); _startup(obj);
} }
pEpLog("creating session for the sync thread");
// 2. Create session for the sync thread // 2. Create session for the sync thread
// 3. register_sync_callbacks() (in session.initialize()) pEpLog("creating session for the sync thread");
session.initialize(
rhs->_sync_mode,
rhs->_adapter_manages_sync_thread,
rhs->_messageToSend,
rhs->_notifyHandshake);
try { try {
session.initialize( // 3. register_sync_callbacks()
rhs->_sync_mode, ::PEP_STATUS status = ::register_sync_callbacks(
rhs->_adapter_manages_sync_thread, session(),
rhs->_messageToSend, nullptr,
rhs->_notifyHandshake); session._notifyHandshake,
_retrieve_next_sync_event);
throw_status(status);
register_done.store(true); register_done.store(true);
} catch (...) { } catch (...) {
_ex = std::current_exception(); _ex = std::current_exception();

31
test/test_leave_device_group.cc

@ -29,8 +29,8 @@ vector<::sync_handshake_signal> expected_notification = { SYNC_NOTIFY_IN_GROUP,
::PEP_STATUS test_messageToSend(::message* _msg) ::PEP_STATUS test_messageToSend(::message* _msg)
{ {
static auto actual = expected_msg.begin();
static auto actual = expected_msg.begin();
Test::Message msg = Test::make_message(_msg); Test::Message msg = Test::make_message(_msg);
string text = Test::make_pEp_msg(msg); string text = Test::make_pEp_msg(msg);
cerr << "expecting: " << *actual << endl; cerr << "expecting: " << *actual << endl;
@ -54,35 +54,38 @@ vector<::sync_handshake_signal> expected_notification = { SYNC_NOTIFY_IN_GROUP,
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
pEp::Adapter::pEpLog::set_enabled(true);
Test::setup(argc, argv); Test::setup(argc, argv);
Adapter::session.initialize(pEp::Adapter::SyncModes::Async, false); pEpLog(getenv("HOME"));
int n;
std::cin >> n;
Adapter::session.initialize(Adapter::SyncModes::Async, false);
// set up two own identites for sync // set up two own identites for sync
passphrase_cache.add("erwin"); passphrase_cache.add("erwin");
passphrase_cache.add("bob"); passphrase_cache.add("bob");
const char* bob_filename = ENGINE_TEST std::string bob_filename = Test::get_resource_abs(
"/test_keys/bob-primary-with-password-bob-subkey-without.pgp"; "bob-primary-with-password-bob-subkey-without.pgp");
const char* bob_fpr = "5C76378A62B04CF3F41BEC8D4940FC9FA1878736"; std::string bob_fpr = "5C76378A62B04CF3F41BEC8D4940FC9FA1878736";
const char* erwin_filename = ENGINE_TEST "/test_keys/erwin_normal_encrypted.pgp"; std::string erwin_filename = Test::get_resource_abs("erwin_normal_encrypted.pgp");
const char* erwin_fpr = "CBA968BC01FCEB89F04CCF155C5E9E3F0420A570"; std::string erwin_fpr = "CBA968BC01FCEB89F04CCF155C5E9E3F0420A570";
Test::import_key_from_file(bob_filename); Test::import_key_from_file(bob_filename);
Test::import_key_from_file(erwin_filename); Test::import_key_from_file(erwin_filename);
Test::Identity bob = Test::make_identity( Test::Identity bob = Test::make_identity(
::new_identity("bob@example.org", bob_fpr, "BOB", "Bob Dog")); ::new_identity("bob@example.org", bob_fpr.c_str(), "BOB", "Bob Dog"));
PEP_STATUS status = ::set_own_key(Adapter::session(), bob.get(), bob_fpr); PEP_STATUS status = ::set_own_key(Adapter::session(), bob.get(), bob_fpr.c_str());
assert(status == PEP_STATUS_OK); assert(status == PEP_STATUS_OK);
status = ::enable_identity_for_sync(Adapter::session(), bob.get()); status = ::enable_identity_for_sync(Adapter::session(), bob.get());
assert(status == PEP_STATUS_OK); assert(status == PEP_STATUS_OK);
Test::Identity erwin = Test::make_identity( Test::Identity erwin = Test::make_identity(
::new_identity("erwin@example.org", erwin_fpr, "BOB", "Bob is Erwin")); ::new_identity("erwin@example.org", erwin_fpr.c_str(), "BOB", "Bob is Erwin"));
status = ::set_own_key(Adapter::session(), erwin.get(), erwin_fpr); status = ::set_own_key(Adapter::session(), erwin.get(), erwin_fpr.c_str());
assert(status == PEP_STATUS_OK); assert(status == PEP_STATUS_OK);
status = ::enable_identity_for_sync(Adapter::session(), erwin.get()); status = ::enable_identity_for_sync(Adapter::session(), erwin.get());
@ -99,10 +102,8 @@ int main(int argc, char** argv)
Adapter::start_sync(); Adapter::start_sync();
// leave device group // leave device group
status = ::leave_device_group(Adapter::session()); status = ::leave_device_group(Adapter::session());
throw_status(status);
// wait for sync shutdown and release first session // wait for sync shutdown and release first session
Test::join_sync_thread(); Test::join_sync_thread();

Loading…
Cancel
Save