Implement nbd-proxy as a part of bmcweb
Nbd-proxy is responsible for exposing websocket endpoint in bmcweb.
It matches WS endpoints with unix socket paths using configuration
exposed on D-Bus by Virtual-Media.
Virtual-Media is then notified about unix socket availability through
mount/unmount D-Bus methods.
Currently, this feature is disabled by default.
Tested: Integrated with initial version of Virtual-Media.
Change-Id: I9c572e9841b16785727e5676fea1bb63b0311c63
Signed-off-by: Iwona Klimaszewska <iwona.klimaszewska@intel.com>
Signed-off-by: Przemyslaw Czarnowski <przemyslaw.hawrylewicz.czarnowski@intel.com>
diff --git a/http/routing.h b/http/routing.h
index 200cfa0..7846924 100644
--- a/http/routing.h
+++ b/http/routing.h
@@ -3,6 +3,7 @@
#include "privileges.hpp"
#include "sessions.hpp"
+#include <async_resp.hpp>
#include <boost/container/flat_map.hpp>
#include <boost/container/small_vector.hpp>
#include <boost/lexical_cast.hpp>
@@ -323,19 +324,19 @@
res.end();
}
- void handleUpgrade(const Request& req, Response&,
+ void handleUpgrade(const Request& req, Response& res,
boost::asio::ip::tcp::socket&& adaptor) override
{
std::shared_ptr<
crow::websocket::ConnectionImpl<boost::asio::ip::tcp::socket>>
myConnection = std::make_shared<
crow::websocket::ConnectionImpl<boost::asio::ip::tcp::socket>>(
- req, std::move(adaptor), openHandler, messageHandler,
+ req, res, std::move(adaptor), openHandler, messageHandler,
closeHandler, errorHandler);
myConnection->start();
}
#ifdef BMCWEB_ENABLE_SSL
- void handleUpgrade(const Request& req, Response&,
+ void handleUpgrade(const Request& req, Response& res,
boost::beast::ssl_stream<boost::asio::ip::tcp::socket>&&
adaptor) override
{
@@ -343,7 +344,7 @@
boost::beast::ssl_stream<boost::asio::ip::tcp::socket>>>
myConnection = std::make_shared<crow::websocket::ConnectionImpl<
boost::beast::ssl_stream<boost::asio::ip::tcp::socket>>>(
- req, std::move(adaptor), openHandler, messageHandler,
+ req, res, std::move(adaptor), openHandler, messageHandler,
closeHandler, errorHandler);
myConnection->start();
}
@@ -374,7 +375,9 @@
}
protected:
- std::function<void(crow::websocket::Connection&)> openHandler;
+ std::function<void(crow::websocket::Connection&,
+ std::shared_ptr<bmcweb::AsyncResp>)>
+ openHandler;
std::function<void(crow::websocket::Connection&, const std::string&, bool)>
messageHandler;
std::function<void(crow::websocket::Connection&, const std::string&)>
diff --git a/http/websocket.h b/http/websocket.h
index 61b3e5a..80d536a 100644
--- a/http/websocket.h
+++ b/http/websocket.h
@@ -1,5 +1,6 @@
#pragma once
#include <array>
+#include <async_resp.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/beast/websocket.hpp>
@@ -15,10 +16,11 @@
{
namespace websocket
{
+
struct Connection : std::enable_shared_from_this<Connection>
{
public:
- explicit Connection(const crow::Request& reqIn) :
+ explicit Connection(const crow::Request& reqIn, crow::Response& res) :
req(reqIn), userdataPtr(nullptr){};
virtual void sendBinary(const std::string_view msg) = 0;
@@ -39,6 +41,7 @@
}
crow::Request req;
+ crow::Response res;
private:
void* userdataPtr;
@@ -48,13 +51,14 @@
{
public:
ConnectionImpl(
- const crow::Request& reqIn, Adaptor adaptorIn,
- std::function<void(Connection&)> open_handler,
+ const crow::Request& reqIn, crow::Response& res, Adaptor adaptorIn,
+ std::function<void(Connection&, std::shared_ptr<bmcweb::AsyncResp>)>
+ open_handler,
std::function<void(Connection&, const std::string&, bool)>
message_handler,
std::function<void(Connection&, const std::string&)> close_handler,
std::function<void(Connection&)> error_handler) :
- Connection(reqIn),
+ Connection(reqIn, res),
ws(std::move(adaptorIn)), inString(), inBuffer(inString, 131088),
openHandler(std::move(open_handler)),
messageHandler(std::move(message_handler)),
@@ -158,11 +162,15 @@
{
BMCWEB_LOG_DEBUG << "Websocket accepted connection";
+ auto asyncResp = std::make_shared<bmcweb::AsyncResp>(
+ res, [this, self(shared_from_this())]() { doRead(); });
+
+ asyncResp->res.result(boost::beast::http::status::ok);
+
if (openHandler)
{
- openHandler(*this);
+ openHandler(*this, asyncResp);
}
- doRead();
}
void doRead()
@@ -241,7 +249,8 @@
std::vector<std::string> outBuffer;
bool doingWrite = false;
- std::function<void(Connection&)> openHandler;
+ std::function<void(Connection&, std::shared_ptr<bmcweb::AsyncResp>)>
+ openHandler;
std::function<void(Connection&, const std::string&, bool)> messageHandler;
std::function<void(Connection&, const std::string&)> closeHandler;
std::function<void(Connection&)> errorHandler;