|
@ -15,66 +15,10 @@ thread_local pEp::Adapter::Session pEp::Adapter::session{}; |
|
|
|
|
|
|
|
|
namespace pEp { |
|
|
namespace pEp { |
|
|
namespace Adapter { |
|
|
namespace Adapter { |
|
|
std::thread _sync_thread; |
|
|
::SYNC_EVENT _cb_dequeue_next_sync_event(void *management, unsigned threshold); |
|
|
::utility::locked_queue<SYNC_EVENT, ::free_Sync_event> sync_evt_q; |
|
|
|
|
|
std::mutex mut; |
|
|
|
|
|
|
|
|
|
|
|
// private
|
|
|
|
|
|
std::thread::id sync_thread_id() |
|
|
|
|
|
{ |
|
|
|
|
|
return _sync_thread.get_id(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// private
|
|
|
|
|
|
int _process_sync_event(::SYNC_EVENT ev, void *management) |
|
|
|
|
|
{ |
|
|
|
|
|
if (ev != nullptr) { |
|
|
|
|
|
::do_sync_protocol_step(session(), nullptr, ev); |
|
|
|
|
|
} |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// public (json adapter needs it, but should use Session mgmt from libpEpAdapter eventually)
|
|
|
|
|
|
int _inject_sync_event(::SYNC_EVENT ev, void *management) |
|
|
|
|
|
{ |
|
|
|
|
|
try { |
|
|
|
|
|
if (ev == nullptr) { |
|
|
|
|
|
sync_evt_q.clear(); |
|
|
|
|
|
sync_evt_q.push_back(ev); |
|
|
|
|
|
} else { |
|
|
|
|
|
sync_evt_q.push_front(ev); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (exception &) { |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// private
|
|
|
|
|
|
PEP_STATUS _ensure_passphrase(::PEP_SESSION session, const char *fpr) |
|
|
|
|
|
{ |
|
|
|
|
|
return passphrase_cache.ensure_passphrase(session, fpr); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// public
|
|
|
|
|
|
::SYNC_EVENT _retrieve_next_sync_event(void *management, unsigned threshold) |
|
|
|
|
|
{ |
|
|
|
|
|
::SYNC_EVENT syncEvent = nullptr; |
|
|
|
|
|
const bool success = sync_evt_q.try_pop_front(syncEvent, std::chrono::seconds(threshold)); |
|
|
|
|
|
|
|
|
|
|
|
if (!success) { |
|
|
|
|
|
return ::new_sync_timeout_event(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return syncEvent; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// public
|
|
|
|
|
|
bool on_sync_thread() |
|
|
|
|
|
{ |
|
|
|
|
|
return _sync_thread.get_id() == this_thread::get_id(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
|
|
// SESSION
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
Session::Session() : |
|
|
Session::Session() : |
|
|
_sync_mode{ SyncModes::Async }, _messageToSend{ nullptr }, _notifyHandshake{ nullptr }, |
|
|
_sync_mode{ SyncModes::Async }, _messageToSend{ nullptr }, _notifyHandshake{ nullptr }, |
|
@ -167,6 +111,62 @@ namespace pEp { |
|
|
return _session.get(); |
|
|
return _session.get(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
|
|
// SYNC
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------
|
|
|
|
|
|
std::thread _sync_thread{}; |
|
|
|
|
|
::utility::locked_queue<SYNC_EVENT, ::free_Sync_event> sync_evt_q{}; |
|
|
|
|
|
|
|
|
|
|
|
// private
|
|
|
|
|
|
std::thread::id sync_thread_id() |
|
|
|
|
|
{ |
|
|
|
|
|
return _sync_thread.get_id(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// private
|
|
|
|
|
|
int _cb_pass_sync_event_to_engine(::SYNC_EVENT ev, void *management) |
|
|
|
|
|
{ |
|
|
|
|
|
if (ev != nullptr) { |
|
|
|
|
|
::do_sync_protocol_step(session(), nullptr, ev); |
|
|
|
|
|
} |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// public (json adapter needs it, but should use Session mgmt from libpEpAdapter eventually)
|
|
|
|
|
|
int _cb_enqueue_sync_event(::SYNC_EVENT ev, void *management) |
|
|
|
|
|
{ |
|
|
|
|
|
try { |
|
|
|
|
|
if (ev == nullptr) { |
|
|
|
|
|
sync_evt_q.clear(); |
|
|
|
|
|
sync_evt_q.push_back(ev); |
|
|
|
|
|
} else { |
|
|
|
|
|
sync_evt_q.push_front(ev); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (...) { |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// public
|
|
|
|
|
|
::SYNC_EVENT _cb_dequeue_next_sync_event(void *management, unsigned threshold) |
|
|
|
|
|
{ |
|
|
|
|
|
::SYNC_EVENT syncEvent = nullptr; |
|
|
|
|
|
const bool success = sync_evt_q.try_pop_front(syncEvent, std::chrono::seconds(threshold)); |
|
|
|
|
|
|
|
|
|
|
|
if (!success) { |
|
|
|
|
|
return ::new_sync_timeout_event(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return syncEvent; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// public
|
|
|
|
|
|
bool on_sync_thread() |
|
|
|
|
|
{ |
|
|
|
|
|
return _sync_thread.get_id() == this_thread::get_id(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// public
|
|
|
// public
|
|
|
void inject_sync_shutdown() |
|
|
void inject_sync_shutdown() |
|
|
{ |
|
|
{ |
|
@ -214,6 +214,12 @@ namespace pEp { |
|
|
} |
|
|
} |
|
|
return !ev; |
|
|
return !ev; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PEP_STATUS _ensure_passphrase(::PEP_SESSION session, const char *fpr) |
|
|
|
|
|
{ |
|
|
|
|
|
return passphrase_cache.ensure_passphrase(session, fpr); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} // namespace Adapter
|
|
|
} // namespace Adapter
|
|
|
|
|
|
|
|
|
void throw_status(::PEP_STATUS status) |
|
|
void throw_status(::PEP_STATUS status) |
|
|