Browse Source

Fix session mgmt and some cleanup

pull/14/head
heck 4 years ago
parent
commit
ec5b5643ca
  1. 10
      src/pEp/__init__.py
  2. 79
      src/pEp/_pEp/pEpmodule.cc

10
src/pEp/__init__.py

@ -35,13 +35,13 @@ import pEp._pEp
# 3rd party imports # 3rd party imports
from threading import Thread, Barrier from threading import Thread, Barrier
from time import sleep from time import sleep
from enum import Enum
# Executed on module import # Executed on module import
def init(): def init():
# print(init, "called") _pEp._init_callbackdispatcher()
_pEp._init_after_main_module() _pEp._init_session(True)
_pEp._session_init(True);
def start_sync() -> None: def start_sync() -> None:
@ -125,13 +125,13 @@ class Sync(Thread):
""" """
# TODO catch exception, and rethrow in start() # TODO catch exception, and rethrow in start()
# _pEp._register_sync_callbacks() # _pEp._register_sync_callbacks()
_pEp._session_init(True) _pEp._init_session(True)
self.barr.wait() self.barr.wait()
while _pEp._do_protocol_step(): while _pEp._do_protocol_step():
sleep(1) sleep(1)
_pEp._unregister_sync_callbacks() _pEp._free_session()
def start(self): def start(self):
""" """

79
src/pEp/_pEp/pEpmodule.cc

@ -33,23 +33,13 @@ namespace pEp {
static const char *version_string = "p≡p Python adapter version 0.3"; static const char *version_string = "p≡p Python adapter version 0.3";
void init_before_main_module() { void _init_callbackdispatcher() {
pEpLog("called"); pEpLog("called");
callback_dispatcher.add(_messageToSend, _notifyHandshake, nullptr, nullptr);
} }
// hidden init function, wrapped by _pEp.init() void _init_session(bool mode_async) {
void _init_after_main_module() {
pEpLog("called"); 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) { if(mode_async) {
Adapter::session.initialize(pEp::Adapter::SyncModes::Async, true); Adapter::session.initialize(pEp::Adapter::SyncModes::Async, true);
} else { } else {
@ -74,10 +64,6 @@ namespace pEp {
_throw_status(status); _throw_status(status);
} }
void key_reset_user2(string user_id) {
key_reset_user(user_id, "");
}
void key_reset_all_own_keys() { void key_reset_all_own_keys() {
PEP_STATUS status = ::key_reset_all_own_keys(Adapter::session()); PEP_STATUS status = ::key_reset_all_own_keys(Adapter::session());
_throw_status(status); _throw_status(status);
@ -152,16 +138,9 @@ namespace pEp {
} }
} }
// void _register_sync_callbacks() { void _free_session() {
// 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() {
::unregister_sync_callbacks(Adapter::session()); ::unregister_sync_callbacks(Adapter::session());
// Adapter::session(release); Adapter::session.release();
} }
// TODO: Integrate this (currently SEGFAULTING) // TODO: Integrate this (currently SEGFAULTING)
@ -188,10 +167,6 @@ namespace pEp {
::disable_all_sync_channels(Adapter::session()); ::disable_all_sync_channels(Adapter::session());
} }
void testfunc() {
_messageToSend(NULL);
}
void deliverHandshakeResult(int result, object identities) { void deliverHandshakeResult(int result, object identities) {
identity_list *shared_identities = nullptr; identity_list *shared_identities = nullptr;
if (identities != boost::python::api::object() && boost::python::len(identities)) { if (identities != boost::python::api::object() && boost::python::len(identities)) {
@ -220,17 +195,12 @@ namespace pEp {
} }
BOOST_PYTHON_MODULE(_pEp) { BOOST_PYTHON_MODULE(_pEp) {
init_before_main_module(); def("_init_callbackdispatcher", _init_callbackdispatcher);
// Module init function called by pEp.init()
def("_init_after_main_module", _init_after_main_module);
def("testfunc", &testfunc);
docstring_options doc_options(true, false, false); docstring_options doc_options(true, false, false);
boost::locale::generator gen; boost::locale::generator gen;
std::locale::global(gen("")); std::locale::global(gen(""));
scope().attr("about") = about(); scope().attr("about") = about();
scope().attr("per_user_directory") = per_user_directory(); scope().attr("per_user_directory") = per_user_directory();
scope().attr("per_machine_directory") = per_machine_directory(); scope().attr("per_machine_directory") = per_machine_directory();
@ -241,31 +211,12 @@ namespace pEp {
"Switch debug logging on/off"); "Switch debug logging on/off");
def("_session_init", _session_init); def("_init_session", _init_session);
// def("_register_sync_callbacks", _register_sync_callbacks, def("_free_session", _free_session);
// ""); def("_do_protocol_step", _do_protocol_step);
def("_inject_sync_shutdown", Adapter::inject_sync_shutdown);
def("_unregister_sync_callbacks", _unregister_sync_callbacks, def("_notifyHandshake_sync_start", _notifyHandshake_sync_start);
""); def("_notifyHandshake_sync_stop", _notifyHandshake_sync_stop);
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_<pEp::Adapter::SyncModes>("SyncModes")
// .value("Async", pEp::Adapter::SyncModes::Async)
// .value("Sync", pEp::Adapter::SyncModes::Sync);
def("passive_mode", config_passive_mode, def("passive_mode", config_passive_mode,
"do not attach pub keys to all messages"); "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" "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."); "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, def("key_reset_all_own_keys", key_reset_all_own_keys,
"revoke and mistrust all own keys, generate new keys for all\n" "revoke and mistrust all own keys, generate new keys for all\n"
"own identities, and opportunistically communicate key reset\n" "own identities, and opportunistically communicate key reset\n"

Loading…
Cancel
Save