From 09015df5e93de837bdbe0ad87469762dbdda4e6d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Roman=20Smr=C5=BE?= <roman.smrz@seznam.cz>
Date: Sat, 13 Nov 2021 22:14:54 +0100
Subject: Pairing: properly handle lingering threads after server stops

---
 include/erebos/pairing.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

(limited to 'include')

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>
-- 
cgit v1.2.3