summaryrefslogtreecommitdiff
path: root/src/sync.cpp
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-05-06 17:09:32 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2023-05-06 18:54:24 +0200
commit25a1ba71e3cf4250489291f688423963aa603498 (patch)
treefb1e23060b810237316f4cde6524c0b1a66d5d0e /src/sync.cpp
parent07f61b1ad6363cd471b7dab3f94c3160636fd6a0 (diff)
Server and services configuration using separate objects
Diffstat (limited to 'src/sync.cpp')
-rw-r--r--src/sync.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/sync.cpp b/src/sync.cpp
index 8263974..5680da6 100644
--- a/src/sync.cpp
+++ b/src/sync.cpp
@@ -9,7 +9,15 @@ using std::scoped_lock;
static const UUID myUUID("a4f538d0-4e50-4082-8e10-7e3ec2af175d");
-SyncService::SyncService() = default;
+SyncService::SyncService(Config &&, const Server & s):
+ server(s)
+{
+ server.peerList().onUpdate(std::bind(&SyncService::peerWatcher, this,
+ std::placeholders::_1, std::placeholders::_2));
+ watchedLocal = server.localState().lens<vector<Ref>>().watch(std::bind(&SyncService::localStateWatcher, this,
+ std::placeholders::_1));
+}
+
SyncService::~SyncService() = default;
UUID SyncService::uuid() const
@@ -34,21 +42,12 @@ void SyncService::handle(Context & ctx)
);
}
-void SyncService::serverStarted(const Server & s)
-{
- server = &s;
- server->peerList().onUpdate(std::bind(&SyncService::peerWatcher, this,
- std::placeholders::_1, std::placeholders::_2));
- watchedLocal = server->localState().lens<vector<Ref>>().watch(std::bind(&SyncService::localStateWatcher, this,
- std::placeholders::_1));
-}
-
void SyncService::peerWatcher(size_t, const Peer * peer)
{
if (peer) {
if (auto id = peer->identity()) {
- if (id->finalOwner().sameAs(server->identity().finalOwner()))
- for (const auto & r : server->localState().get().sharedRefs())
+ if (id->finalOwner().sameAs(server.identity().finalOwner()))
+ for (const auto & r : server.localState().get().sharedRefs())
peer->send(myUUID, r);
}
}
@@ -56,8 +55,8 @@ void SyncService::peerWatcher(size_t, const Peer * peer)
void SyncService::localStateWatcher(const vector<Ref> & refs)
{
- const auto & plist = server->peerList();
- const Identity owner = server->identity().finalOwner();
+ const auto & plist = server.peerList();
+ const Identity owner = server.identity().finalOwner();
for (size_t i = 0; i < plist.size(); i++)
if (auto id = plist.at(i).identity())