From ec5b5643ca2b0a9c7e65ce14f808112e93ef45a5 Mon Sep 17 00:00:00 2001 From: heck Date: Wed, 5 Jan 2022 15:15:25 +0100 Subject: [PATCH] Fix session mgmt and some cleanup --- src/pEp/__init__.py | 10 ++--- src/pEp/_pEp/pEpmodule.cc | 79 ++++++--------------------------------- 2 files changed, 17 insertions(+), 72 deletions(-) diff --git a/src/pEp/__init__.py b/src/pEp/__init__.py index f574474..9b9fa65 100755 --- a/src/pEp/__init__.py +++ b/src/pEp/__init__.py @@ -35,13 +35,13 @@ import pEp._pEp # 3rd party imports from threading import Thread, Barrier from time import sleep +from enum import Enum # Executed on module import def init(): - # print(init, "called") - _pEp._init_after_main_module() - _pEp._session_init(True); + _pEp._init_callbackdispatcher() + _pEp._init_session(True) def start_sync() -> None: @@ -125,13 +125,13 @@ class Sync(Thread): """ # TODO catch exception, and rethrow in start() # _pEp._register_sync_callbacks() - _pEp._session_init(True) + _pEp._init_session(True) self.barr.wait() while _pEp._do_protocol_step(): sleep(1) - _pEp._unregister_sync_callbacks() + _pEp._free_session() def start(self): """ diff --git a/src/pEp/_pEp/pEpmodule.cc b/src/pEp/_pEp/pEpmodule.cc index fbef876..a13cc92 100644 --- a/src/pEp/_pEp/pEpmodule.cc +++ b/src/pEp/_pEp/pEpmodule.cc @@ -33,23 +33,13 @@ namespace pEp { static const char *version_string = "p≡p Python adapter version 0.3"; - void init_before_main_module() { + void _init_callbackdispatcher() { pEpLog("called"); + callback_dispatcher.add(_messageToSend, _notifyHandshake, nullptr, nullptr); } - // hidden init function, wrapped by _pEp.init() - void _init_after_main_module() { + void _init_session(bool mode_async) { pEpLog("called"); -// callback_dispatcher.add(_messageToSend, _notifyHandshake, nullptr, nullptr); -// Adapter::sync_initialize( -// Adapter::SyncModes::Off, -// CallbackDispatcher::messageToSend, -// CallbackDispatcher::notifyHandshake, -// true); -// Adapter::session.initialize(Adapter::SyncModes::Sync, true); - } - - void _session_init(bool mode_async) { if(mode_async) { Adapter::session.initialize(pEp::Adapter::SyncModes::Async, true); } else { @@ -74,10 +64,6 @@ namespace pEp { _throw_status(status); } - void key_reset_user2(string user_id) { - key_reset_user(user_id, ""); - } - void key_reset_all_own_keys() { PEP_STATUS status = ::key_reset_all_own_keys(Adapter::session()); _throw_status(status); @@ -152,16 +138,9 @@ namespace pEp { } } -// void _register_sync_callbacks() { -// pEpLog("called"); -// Adapter::session(); -// PEP_STATUS status = ::register_sync_callbacks(Adapter::session(), nullptr, Adapter::_notifyHandshake, Adapter::_retrieve_next_sync_event); -// _throw_status(status); -// } - - void _unregister_sync_callbacks() { + void _free_session() { ::unregister_sync_callbacks(Adapter::session()); -// Adapter::session(release); + Adapter::session.release(); } // TODO: Integrate this (currently SEGFAULTING) @@ -188,10 +167,6 @@ namespace pEp { ::disable_all_sync_channels(Adapter::session()); } - void testfunc() { - _messageToSend(NULL); - } - void deliverHandshakeResult(int result, object identities) { identity_list *shared_identities = nullptr; if (identities != boost::python::api::object() && boost::python::len(identities)) { @@ -220,17 +195,12 @@ namespace pEp { } BOOST_PYTHON_MODULE(_pEp) { - init_before_main_module(); - - // Module init function called by pEp.init() - def("_init_after_main_module", _init_after_main_module); - def("testfunc", &testfunc); + def("_init_callbackdispatcher", _init_callbackdispatcher); docstring_options doc_options(true, false, false); boost::locale::generator gen; std::locale::global(gen("")); - scope().attr("about") = about(); scope().attr("per_user_directory") = per_user_directory(); scope().attr("per_machine_directory") = per_machine_directory(); @@ -241,31 +211,12 @@ namespace pEp { "Switch debug logging on/off"); - def("_session_init", _session_init); -// def("_register_sync_callbacks", _register_sync_callbacks, -// ""); - - def("_unregister_sync_callbacks", _unregister_sync_callbacks, - ""); - - def("_do_protocol_step", _do_protocol_step, - ""); - - def("_inject_sync_shutdown", Adapter::inject_sync_shutdown, - ""); - - def("_notifyHandshake_sync_start", _notifyHandshake_sync_start, - ""); - - def("_notifyHandshake_sync_stop", _notifyHandshake_sync_stop, - ""); - -// def("_set_sync_mode", pEp::Adapter::set_sync_mode, -// ""); - -// enum_("SyncModes") -// .value("Async", pEp::Adapter::SyncModes::Async) -// .value("Sync", pEp::Adapter::SyncModes::Sync); + def("_init_session", _init_session); + def("_free_session", _free_session); + def("_do_protocol_step", _do_protocol_step); + def("_inject_sync_shutdown", Adapter::inject_sync_shutdown); + def("_notifyHandshake_sync_start", _notifyHandshake_sync_start); + def("_notifyHandshake_sync_stop", _notifyHandshake_sync_stop); def("passive_mode", config_passive_mode, "do not attach pub keys to all messages"); @@ -279,12 +230,6 @@ namespace pEp { "associated with the key and user_id, if a key is provided, and for\n" "each key (and all of their identities) if an fpr is not."); - def("key_reset", key_reset_user2, - "reset the default database status for the user / keypair provided\n" - "This will effectively perform key_reset on each identity\n" - "associated with the key and user_id, if a key is provided, and for\n" - "each key (and all of their identities) if an fpr is not."); - def("key_reset_all_own_keys", key_reset_all_own_keys, "revoke and mistrust all own keys, generate new keys for all\n" "own identities, and opportunistically communicate key reset\n"