summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-02-03 11:17:13 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2024-02-03 11:27:59 +0100
commita28d1daed8d89fceaa014a244a506d8092d6ca7c (patch)
treefd0209d1e4be68d6b8968d8f5568bcef42edaedd /include
parent33773031d59762a28fbc4673c7df2dd378b79d0e (diff)
Message: separate thread for peer synchronization
Diffstat (limited to 'include')
-rw-r--r--include/erebos/message.h17
1 files changed, 15 insertions, 2 deletions
diff --git a/include/erebos/message.h b/include/erebos/message.h
index a74e6a3..b52b84b 100644
--- a/include/erebos/message.h
+++ b/include/erebos/message.h
@@ -3,16 +3,21 @@
#include <erebos/merge.h>
#include <erebos/service.h>
-#include <chrono>
+#include <condition_variable>
+#include <deque>
#include <functional>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
+#include <tuple>
namespace erebos {
+using std::condition_variable;
+using std::deque;
using std::mutex;
+using std::tuple;
using std::unique_ptr;
class Contact;
@@ -142,7 +147,9 @@ public:
private:
void updateHandler(const DirectMessageThreads &);
void peerWatcher(size_t, const class Peer *);
- static void syncWithPeer(const Head<LocalState> &, const DirectMessageThread &, const Peer &);
+ void syncWithPeer(const DirectMessageThread &, const Peer &);
+ void doSyncWithPeers();
+ void doSyncWithPeer(const DirectMessageThread &, const Peer &);
const Config config;
const Server & server;
@@ -150,6 +157,12 @@ private:
vector<Stored<DirectMessageState>> prevState;
mutex stateMutex;
+ mutex peerSyncMutex;
+ condition_variable peerSyncCond;
+ bool peerSyncRun;
+ deque<tuple<DirectMessageThread, Peer>> peerSyncQueue;
+ std::thread peerSyncThread;
+
Watched<DirectMessageThreads> watched;
};