Browse Source

wrong add...

synchronous Release_2.1.0-RC12
Volker Birk 2 years ago
parent
commit
89459b946c
3 changed files with 17 additions and 10 deletions
  1. +0
    -1
      callback_dispatcher.cc
  2. +3
    -0
      callback_dispatcher.hh
  3. +14
    -9
      passphrase_cache.cc

+ 0
- 1
callback_dispatcher.cc View File

@ -29,7 +29,6 @@ namespace pEp {
throw std::invalid_argument("messageToSend must be set");
targets.push_back({messageToSend, notifyHandshake, on_startup, shutdown});
semaphore.go();
}
void CallbackDispatcher::remove(::messageToSend_t messageToSend)


+ 3
- 0
callback_dispatcher.hh View File

@ -5,6 +5,7 @@
#include <mutex>
#include "Adapter.hh"
#include "Semaphore.hh"
#include "passphrase_cache.hh"
namespace pEp {
// use this class when implementing a desktop adapter
@ -46,6 +47,8 @@ namespace pEp {
PEP_STATUS _messageToSend(::message *msg);
PEP_STATUS _notifyHandshake(::pEp_identity *me,
::pEp_identity *partner, ::sync_handshake_signal signal);
friend const char *PassphraseCache::add(const std::string& passphrase);
};
extern CallbackDispatcher callback_dispatcher;


+ 14
- 9
passphrase_cache.cc View File

@ -1,6 +1,7 @@
#include <cassert>
#include "Adapter.hh"
#include "passphrase_cache.hh"
#include "callback_dispatcher.hh"
pEp::PassphraseCache pEp::passphrase_cache;
@ -35,15 +36,19 @@ namespace pEp {
const char *PassphraseCache::add(const std::string& passphrase)
{
if (!passphrase.empty()) {
std::lock_guard<std::mutex> lock(_mtx);
while (_cache.size() >= _max_size)
_cache.pop_front();
_cache.push_back({passphrase, clock::now()});
auto back = _cache.end();
assert(!_cache.empty());
auto result = (--back)->passphrase.c_str();
const char *result = nullptr;
{
std::lock_guard<std::mutex> lock(_mtx);
while (_cache.size() >= _max_size)
_cache.pop_front();
_cache.push_back({passphrase, clock::now()});
auto back = _cache.end();
assert(!_cache.empty());
result = (--back)->passphrase.c_str();
}
callback_dispatcher.semaphore.go();
return result;
}


Loading…
Cancel
Save