diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2021-11-13 22:14:54 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2021-11-13 22:14:54 +0100 |
commit | 09015df5e93de837bdbe0ad87469762dbdda4e6d (patch) | |
tree | 2a336c2830ba1138862c3848a65b0feecdc6b426 /include/erebos | |
parent | 28220406f68f38d56648c3932c555b6d6d2b5788 (diff) |
Pairing: properly handle lingering threads after server stops
Diffstat (limited to 'include/erebos')
-rw-r--r-- | include/erebos/pairing.h | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/include/erebos/pairing.h b/include/erebos/pairing.h index 4457426..b8b680a 100644 --- a/include/erebos/pairing.h +++ b/include/erebos/pairing.h @@ -29,6 +29,8 @@ using std::vector; class PairingServiceBase : public Service { public: + virtual ~PairingServiceBase(); + typedef function<void(const Peer &)> RequestInitHook; void onRequestInit(RequestInitHook); @@ -49,7 +51,6 @@ private: static vector<uint8_t> nonceDigest(const Identity & id1, const Identity & id2, const vector<uint8_t> & nonce1, const vector<uint8_t> & nonce2); static string confirmationNumber(const vector<uint8_t> &); - void waitForConfirmation(Peer peer, string confirm); RequestInitHook requestInitHook; ConfirmHook responseHook; @@ -70,14 +71,17 @@ private: }; struct State { + mutex lock; StatePhase phase; vector<uint8_t> nonce; vector<uint8_t> peerCheck; promise<bool> success; }; - map<Peer, State> peerStates; + map<Peer, shared_ptr<State>> peerStates; mutex stateLock; + + void waitForConfirmation(Peer peer, weak_ptr<State> state, string confirm, ConfirmHook hook); }; template<class Result> |