Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions controller/EmbeddedNetworkController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
httplib::Server &s,
const std::function<void(const httplib::Request&, httplib::Response&, std::string)> setContent)
{
s.Get("/controller/network", [&](const httplib::Request &req, httplib::Response &res) {
s.Get("/controller/network", [&, setContent](const httplib::Request &req, httplib::Response &res) {
std::set<uint64_t> networkIds;
_db.networks(networkIds);
char tmp[64];
Expand All @@ -833,7 +833,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
setContent(req, res, out.dump());
});

s.Get("/controller/network/([0-9a-fA-F]{16})", [&](const httplib::Request &req, httplib::Response &res) {
s.Get("/controller/network/([0-9a-fA-F]{16})", [&, setContent](const httplib::Request &req, httplib::Response &res) {
auto networkID = req.matches[1];
uint64_t nwid = Utils::hexStrToU64(networkID.str().c_str());
json network;
Expand All @@ -845,7 +845,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
setContent(req, res, network.dump());
});

auto createNewNetwork = [&](const httplib::Request &req, httplib::Response &res) {
auto createNewNetwork = [&, setContent](const httplib::Request &req, httplib::Response &res) {
fprintf(stderr, "creating new network (new style)\n");
uint64_t nwid = 0;
uint64_t nwidPrefix = (Utils::hexStrToU64(_signingIdAddressString.c_str()) << 24) & 0xffffffffff000000ULL;
Expand All @@ -869,7 +869,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
s.Put("/controller/network", createNewNetwork);
s.Post("/controller/network", createNewNetwork);

auto createNewNetworkOldAndBusted = [&](const httplib::Request &req, httplib::Response &res) {
auto createNewNetworkOldAndBusted = [&, setContent](const httplib::Request &req, httplib::Response &res) {
auto inID = req.matches[1].str();

if (inID != _signingIdAddressString) {
Expand Down Expand Up @@ -898,7 +898,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
s.Put("/controller/network/([0-9a-fA-F]{10})______", createNewNetworkOldAndBusted);
s.Post("/controller/network/([0-9a-fA-F]{10})______", createNewNetworkOldAndBusted);

s.Delete("/controller/network/([0-9a-fA-F]{16})", [&](const httplib::Request &req, httplib::Response &res) {
s.Delete("/controller/network/([0-9a-fA-F]{16})", [&, setContent](const httplib::Request &req, httplib::Response &res) {
auto networkID = req.matches[1].str();
uint64_t nwid = Utils::hexStrToU64(networkID.c_str());

Expand All @@ -912,7 +912,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
setContent(req, res, network.dump());
});

s.Get("/controller/network/([0-9a-fA-F]{16})/member", [&](const httplib::Request &req, httplib::Response &res) {
s.Get("/controller/network/([0-9a-fA-F]{16})/member", [&, setContent](const httplib::Request &req, httplib::Response &res) {
auto networkID = req.matches[1];
uint64_t nwid = Utils::hexStrToU64(networkID.str().c_str());
json network;
Expand All @@ -938,7 +938,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
setContent(req, res, out.dump());
});

s.Get("/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})", [&](const httplib::Request &req, httplib::Response &res) {
s.Get("/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})", [&, setContent](const httplib::Request &req, httplib::Response &res) {
auto networkID = req.matches[1];
auto memberID = req.matches[2];
uint64_t nwid = Utils::hexStrToU64(networkID.str().c_str());
Expand All @@ -953,7 +953,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
setContent(req, res, member.dump());
});

auto memberPost = [&](const httplib::Request &req, httplib::Response &res) {
auto memberPost = [&, setContent](const httplib::Request &req, httplib::Response &res) {
auto networkID = req.matches[1].str();
auto memberID = req.matches[2].str();
uint64_t nwid = Utils::hexStrToU64(networkID.c_str());
Expand Down Expand Up @@ -1059,7 +1059,7 @@ void EmbeddedNetworkController::configureHTTPControlPlane(
s.Put("/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})", memberPost);
s.Post("/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})", memberPost);

s.Delete("/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})", [&](const httplib::Request &req, httplib::Response &res) {
s.Delete("/controller/network/([0-9a-fA-F]{16})/member/([0-9a-fA-F]{10})", [&, setContent](const httplib::Request &req, httplib::Response &res) {
auto networkID = req.matches[1].str();
auto memberID = req.matches[2].str();

Expand Down
34 changes: 17 additions & 17 deletions service/OneService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ class OneServiceImpl : public OneService



_controlPlane.Get("/bond/show/([0-9a-fA-F]{10})", [&](const httplib::Request &req, httplib::Response &res) {
_controlPlane.Get("/bond/show/([0-9a-fA-F]{10})", [&, setContent](const httplib::Request &req, httplib::Response &res) {
if (!_node->bondController()->inUse()) {
setContent(req, res, "");
res.status = 400;
Expand Down Expand Up @@ -1547,7 +1547,7 @@ class OneServiceImpl : public OneService
_node->freeQueryResult((void *)pl);
});

auto bondRotate = [&](const httplib::Request &req, httplib::Response &res) {
auto bondRotate = [&, setContent](const httplib::Request &req, httplib::Response &res) {
if (!_node->bondController()->inUse()) {
setContent(req, res, "");
res.status = 400;
Expand All @@ -1574,7 +1574,7 @@ class OneServiceImpl : public OneService
_controlPlane.Post("/bond/rotate/([0-9a-fA-F]{10})", bondRotate);
_controlPlane.Put("/bond/rotate/([0-9a-fA-F]{10})", bondRotate);

_controlPlane.Get("/config", [&](const httplib::Request &req, httplib::Response &res) {
_controlPlane.Get("/config", [&, setContent](const httplib::Request &req, httplib::Response &res) {
std::string config;
{
Mutex::Lock lc(_localConfig_m);
Expand All @@ -1586,7 +1586,7 @@ class OneServiceImpl : public OneService
setContent(req, res, config);
});

auto configPost = [&](const httplib::Request &req, httplib::Response &res) {
auto configPost = [&, setContent](const httplib::Request &req, httplib::Response &res) {
json j(OSUtils::jsonParse(req.body));
if (j.is_object()) {
Mutex::Lock lcl(_localConfig_m);
Expand All @@ -1604,7 +1604,7 @@ class OneServiceImpl : public OneService
_controlPlane.Post("/config/settings", configPost);
_controlPlane.Put("/config/settings", configPost);

_controlPlane.Get("/health", [&](const httplib::Request &req, httplib::Response &res) {
_controlPlane.Get("/health", [&, setContent](const httplib::Request &req, httplib::Response &res) {
json out = json::object();

char tmp[256];
Expand All @@ -1624,7 +1624,7 @@ class OneServiceImpl : public OneService
setContent(req, res, out.dump());
});

_controlPlane.Get("/moon", [&](const httplib::Request &req, httplib::Response &res) {
_controlPlane.Get("/moon", [&, setContent](const httplib::Request &req, httplib::Response &res) {
std::vector<World> moons(_node->moons());

auto out = json::array();
Expand All @@ -1636,7 +1636,7 @@ class OneServiceImpl : public OneService
setContent(req, res, out.dump());
});

_controlPlane.Get("/moon/([0-9a-fA-F]{10})", [&](const httplib::Request &req, httplib::Response &res){
_controlPlane.Get("/moon/([0-9a-fA-F]{10})", [&, setContent](const httplib::Request &req, httplib::Response &res){
std::vector<World> moons(_node->moons());
auto input = req.matches[1];
auto out = json::object();
Expand All @@ -1650,7 +1650,7 @@ class OneServiceImpl : public OneService
setContent(req, res, out.dump());
});

auto moonPost = [&](const httplib::Request &req, httplib::Response &res) {
auto moonPost = [&, setContent](const httplib::Request &req, httplib::Response &res) {
auto input = req.matches[1];
uint64_t seed = 0;
try {
Expand Down Expand Up @@ -1690,7 +1690,7 @@ class OneServiceImpl : public OneService
_controlPlane.Post("/moon/([0-9a-fA-F]{10})", moonPost);
_controlPlane.Put("/moon/([0-9a-fA-F]{10})", moonPost);

_controlPlane.Delete("/moon/([0-9a-fA-F]{10})", [&](const httplib::Request &req, httplib::Response &res) {
_controlPlane.Delete("/moon/([0-9a-fA-F]{10})", [&, setContent](const httplib::Request &req, httplib::Response &res) {
auto input = req.matches[1];
uint64_t id = Utils::hexStrToU64(input.str().c_str());
auto out = json::object();
Expand All @@ -1699,7 +1699,7 @@ class OneServiceImpl : public OneService
setContent(req, res, out.dump());
});

_controlPlane.Get("/network", [&](const httplib::Request &req, httplib::Response &res) {
_controlPlane.Get("/network", [&, setContent](const httplib::Request &req, httplib::Response &res) {
Mutex::Lock _l(_nets_m);
auto out = json::array();

Expand All @@ -1712,7 +1712,7 @@ class OneServiceImpl : public OneService
setContent(req, res, out.dump());
});

_controlPlane.Get("/network/([0-9a-fA-F]{16})", [&](const httplib::Request &req, httplib::Response &res) {
_controlPlane.Get("/network/([0-9a-fA-F]{16})", [&, setContent](const httplib::Request &req, httplib::Response &res) {
Mutex::Lock _l(_nets_m);

auto input = req.matches[1];
Expand All @@ -1728,7 +1728,7 @@ class OneServiceImpl : public OneService
res.status = 404;
});

auto networkPost = [&](const httplib::Request &req, httplib::Response &res) {
auto networkPost = [&, setContent](const httplib::Request &req, httplib::Response &res) {
auto input = req.matches[1];
uint64_t wantnw = Utils::hexStrToU64(input.str().c_str());
_node->join(wantnw, (void*)0, (void*)0);
Expand Down Expand Up @@ -1770,7 +1770,7 @@ class OneServiceImpl : public OneService
_controlPlane.Post("/network/([0-9a-fA-F]{16})", networkPost);
_controlPlane.Put("/network/([0-9a-fA-F]){16}", networkPost);

_controlPlane.Delete("/network/([0-9a-fA-F]{16})", [&](const httplib::Request &req, httplib::Response &res) {
_controlPlane.Delete("/network/([0-9a-fA-F]{16})", [&, setContent](const httplib::Request &req, httplib::Response &res) {
auto input = req.matches[1];
auto out = json::object();
ZT_VirtualNetworkList *nws = _node->networks();
Expand All @@ -1785,7 +1785,7 @@ class OneServiceImpl : public OneService
setContent(req, res, out.dump());
});

_controlPlane.Get("/peer", [&](const httplib::Request &req, httplib::Response &res) {
_controlPlane.Get("/peer", [&, setContent](const httplib::Request &req, httplib::Response &res) {
ZT_PeerList *pl = _node->peers();
auto out = nlohmann::json::array();

Expand All @@ -1803,7 +1803,7 @@ class OneServiceImpl : public OneService
setContent(req, res, out.dump());
});

_controlPlane.Get("/peer/([0-9a-fA-F]{10})", [&](const httplib::Request &req, httplib::Response &res) {
_controlPlane.Get("/peer/([0-9a-fA-F]{10})", [&, setContent](const httplib::Request &req, httplib::Response &res) {
ZT_PeerList *pl = _node->peers();

auto input = req.matches[1];
Expand All @@ -1823,7 +1823,7 @@ class OneServiceImpl : public OneService
setContent(req, res, out.dump());
});

_controlPlane.Get("/status", [&](const httplib::Request &req, httplib::Response &res) {
_controlPlane.Get("/status", [&, setContent](const httplib::Request &req, httplib::Response &res) {
ZT_NodeStatus status;
_node->status(&status);

Expand Down Expand Up @@ -1969,7 +1969,7 @@ class OneServiceImpl : public OneService
}
});

_controlPlane.set_exception_handler([&](const httplib::Request &req, httplib::Response &res, std::exception_ptr ep) {
_controlPlane.set_exception_handler([&, setContent](const httplib::Request &req, httplib::Response &res, std::exception_ptr ep) {
char buf[1024];
auto fmt = "{\"error\": %d, \"description\": \"%s\"}";
try {
Expand Down