|
|
|
@ -6,6 +6,7 @@
|
|
|
|
|
#include <pEp/call_with_lock.hh>
|
|
|
|
|
#include <pEp/status_to_string.hh> // from libpEpAdapter.
|
|
|
|
|
#include <pEp/locked_queue.hh>
|
|
|
|
|
#include <pEp/Adapter.hh>
|
|
|
|
|
|
|
|
|
|
namespace pEp {
|
|
|
|
|
namespace mini {
|
|
|
|
@ -17,90 +18,34 @@ namespace mini {
|
|
|
|
|
PEP_SESSION keyserver_lookup_session = nullptr; // FIXME: what if another adapter started it already?
|
|
|
|
|
ThreadPtr keyserver_lookup_thread;
|
|
|
|
|
|
|
|
|
|
utility::locked_queue< Sync_event*, &free_Sync_event> sync_queue;
|
|
|
|
|
PEP_SESSION sync_session = nullptr;
|
|
|
|
|
ThreadPtr sync_thread;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int injectSyncMsg(Sync_event* msg, void* /* management */)
|
|
|
|
|
{
|
|
|
|
|
sync_queue.push_back(msg);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int injectIdentity(pEp_identity* idy)
|
|
|
|
|
{
|
|
|
|
|
keyserver_lookup_queue.push_back(idy);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Sync_event* retrieveNextSyncMsg(void* /*management*/, unsigned timeout)
|
|
|
|
|
{
|
|
|
|
|
Sync_event* msg = nullptr;
|
|
|
|
|
if(timeout)
|
|
|
|
|
{
|
|
|
|
|
const bool success = sync_queue.try_pop_front(msg, std::chrono::seconds(timeout));
|
|
|
|
|
if(!success)
|
|
|
|
|
{
|
|
|
|
|
// this is timeout occurrence
|
|
|
|
|
return new_sync_timeout_event();
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
msg = sync_queue.pop_front();
|
|
|
|
|
}
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pEp_identity* retrieveNextIdentity(void* /*userdata*/)
|
|
|
|
|
{
|
|
|
|
|
return keyserver_lookup_queue.pop_front();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void* syncThreadRoutine(void* arg)
|
|
|
|
|
{
|
|
|
|
|
PEP_STATUS status = pEp::call_with_lock(&init, &sync_session, &JsonAdapter::messageToSend, &injectSyncMsg);
|
|
|
|
|
if (status != PEP_STATUS_OK)
|
|
|
|
|
throw std::runtime_error("Cannot init sync_session! status: " + ::pEp::status_to_string(status));
|
|
|
|
|
|
|
|
|
|
status = register_sync_callbacks(sync_session,
|
|
|
|
|
(void*) -1,
|
|
|
|
|
&JsonAdapter::notifyHandshake,
|
|
|
|
|
&retrieveNextSyncMsg);
|
|
|
|
|
if (status != PEP_STATUS_OK)
|
|
|
|
|
throw std::runtime_error("Cannot register sync callbacks! status: " + ::pEp::status_to_string(status));
|
|
|
|
|
|
|
|
|
|
status = do_sync_protocol(sync_session, arg); // does the whole work
|
|
|
|
|
sync_queue.clear(); // remove remaining messages
|
|
|
|
|
return (void*) status;
|
|
|
|
|
}
|
|
|
|
|
struct dummy_t{};
|
|
|
|
|
dummy_t dummy{};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void startSync()
|
|
|
|
|
{
|
|
|
|
|
sync_queue.clear();
|
|
|
|
|
|
|
|
|
|
// status = attach_sync_session(i->session, i->sync_session);
|
|
|
|
|
// if(status != PEP_STATUS_OK)
|
|
|
|
|
// throw std::runtime_error("Cannot attach to sync session! status: " + status_to_string(status));
|
|
|
|
|
|
|
|
|
|
sync_thread.reset( new std::thread( syncThreadRoutine, nullptr ) );
|
|
|
|
|
::pEp::Adapter::startup<dummy_t>(
|
|
|
|
|
&JsonAdapter::messageToSend,
|
|
|
|
|
&JsonAdapter::notifyHandshake,
|
|
|
|
|
&dummy
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void stopSync()
|
|
|
|
|
{
|
|
|
|
|
// No sync session active
|
|
|
|
|
if(sync_session == nullptr)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
sync_queue.push_front(NULL);
|
|
|
|
|
sync_thread->join();
|
|
|
|
|
|
|
|
|
|
unregister_sync_callbacks(sync_session);
|
|
|
|
|
sync_queue.clear();
|
|
|
|
|
|
|
|
|
|
pEp::call_with_lock(&release, sync_session);
|
|
|
|
|
sync_session = nullptr;
|
|
|
|
|
::pEp::Adapter::shutdown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -109,7 +54,7 @@ void startKeyserverLookup()
|
|
|
|
|
if(keyserver_lookup_session)
|
|
|
|
|
throw std::runtime_error("KeyserverLookup already started.");
|
|
|
|
|
|
|
|
|
|
PEP_STATUS status = pEp::call_with_lock(&init, &keyserver_lookup_session, &JsonAdapter::messageToSend, &injectSyncMsg);
|
|
|
|
|
PEP_STATUS status = pEp::call_with_lock(&init, &keyserver_lookup_session, &JsonAdapter::messageToSend, &::pEp::Adapter::_inject_sync_event);
|
|
|
|
|
if(status != PEP_STATUS_OK || keyserver_lookup_session==nullptr)
|
|
|
|
|
{
|
|
|
|
|
throw std::runtime_error("Cannot create keyserver lookup session! status: " + ::pEp::status_to_string(status));
|
|
|
|
@ -150,7 +95,6 @@ int examineIdentity(pEp_identity* idy, void* obj)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void* keyserverLookupThreadRoutine(void* arg)
|
|
|
|
|
{
|
|
|
|
|
PEP_STATUS status = do_keymanagement(
|
|
|
|
@ -170,7 +114,7 @@ Adapter& Adapter::createInstance()
|
|
|
|
|
|
|
|
|
|
std::thread::id Adapter::get_sync_thread_id() const
|
|
|
|
|
{
|
|
|
|
|
return sync_thread ? sync_thread->get_id() : std::thread::id{} ;
|
|
|
|
|
return ::pEp::Adapter::sync_thread_id();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|