diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2021-01-20 20:51:10 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2021-01-20 20:51:10 +0100 |
commit | 05ecd0105d4e723517bc269c9b42bc650743ee89 (patch) | |
tree | 4ef3a1455ab471fca8b261ed7a522c33ca5f0e20 /src/network.cpp | |
parent | b60e7b5e07033b926c29042ba6b267d5af32f7e3 (diff) |
Changing local state via service context
Diffstat (limited to 'src/network.cpp')
-rw-r--r-- | src/network.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/network.cpp b/src/network.cpp index eab0f67..c0bcc2a 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -550,16 +550,22 @@ void Server::Peer::updateService(ReplyBuilder & reply) for (auto & x : serviceQueue) { if (auto ref = std::get<1>(x)->check(reply)) { if (lpeer) { - Service::Context ctx(new Service::Context::Priv { - .ref = *ref, - .peer = erebos::Peer(lpeer), - }); - - for (auto & svc : server.services) - if (svc->uuid() == std::get<UUID>(x)) { - svc->handle(ctx); - break; + server.localHead.update([&] (const Stored<LocalState> & local) { + Service::Context ctx(new Service::Context::Priv { + .ref = *ref, + .peer = erebos::Peer(lpeer), + .local = local, + }); + + for (auto & svc : server.services) { + if (svc->uuid() == std::get<UUID>(x)) { + svc->handle(ctx); + break; + } } + + return ctx.local(); + }); } } else { next.push_back(std::move(x)); |