From e821d617802ebbfff756844e4d9720342fc78a4e Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 13 Nov 2026 14:12:49 +0100 Subject: Swarm POC --- poc/web_swarm/orchestrator/c++/session.hpp | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 poc/web_swarm/orchestrator/c++/session.hpp (limited to 'poc/web_swarm/orchestrator/c++/session.hpp') diff --git a/poc/web_swarm/orchestrator/c++/session.hpp b/poc/web_swarm/orchestrator/c++/session.hpp new file mode 100644 index 0000000..cdc6be3 --- /dev/null +++ b/poc/web_swarm/orchestrator/c++/session.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include + +#include +#include +#include + +namespace kel { +namespace lbm { +namespace swarm { + +/** + * One worker's connection, from the signalling socket through to the control + * channel. + * + * Lifetime is the reason this is a type rather than three locals. libdatachannel + * hands callbacks a reference to nothing in particular, and a PeerConnection + * dropped at the end of the accept handler takes the whole negotiation with it. + * The orchestrator therefore holds a shared_ptr per session and the callbacks + * capture a weak_ptr, so a worker that disconnects mid-negotiation tears down + * cleanly instead of leaving a callback pointing at freed state. + * + * Threading: every member here is touched from libdatachannel's threads, not + * from main. The handles themselves are set once during setup and then only + * read, and the mutable state behind them is libdatachannel's own problem. The + * orchestrator's own mutable state lives in the registry, behind its mutex. + */ +struct session { + /// Assigned by the orchestrator, not the worker. Stable for the connection. + std::string id; + + /// Signalling. Stays open after negotiation so renegotiation is possible. + std::shared_ptr ws; + + std::shared_ptr pc; + + /** + * The control channel. Created by the orchestrator rather than the worker + * so that channel-open ordering is deterministic: the offer already + * contains it, so by the time the worker answers it knows the channel is + * coming and does not have to race onDataChannel against its own send. + */ + std::shared_ptr dc; +}; + +} // namespace swarm +} // namespace lbm +} // namespace kel -- cgit v1.3.1