Skip to content

Commit

Permalink
Move websocket implementation to boost beast
Browse files Browse the repository at this point in the history
Boost beast is already in much better use, and gives more confidence in
the security model.  This change keeps the existing crow interfaces,
and simply replaces the backend with beast.  Calling code remains
largely unchanged, with the exception of having to explicitly cast to
string (to obtain a string view) when sending messages.

Change-Id: I90edad505faf2d4465b4888f1f2c4b12cc9e77d0
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
  • Loading branch information
edtanous committed Aug 7, 2018
1 parent 530bc74 commit 1b0044b
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 395 deletions.
1 change: 0 additions & 1 deletion crow/include/crow/http_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ struct Request {

bool keepAlive() { return req.keep_alive(); }

private:
boost::beast::http::request<boost::beast::http::string_body>& req;
};

Expand Down
8 changes: 5 additions & 3 deletions crow/include/crow/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,11 @@ class WebSocketRule : public BaseRule {
#ifdef BMCWEB_ENABLE_SSL
void handleUpgrade(const Request& req, Response&,
SSLAdaptor&& adaptor) override {
new crow::websocket::ConnectionImpl<SSLAdaptor>(req, std::move(adaptor),
openHandler, messageHandler,
closeHandler, errorHandler);
std::shared_ptr<crow::websocket::ConnectionImpl<SSLAdaptor>> myConnection =
std::make_shared<crow::websocket::ConnectionImpl<SSLAdaptor>>(
req, std::move(adaptor), openHandler, messageHandler, closeHandler,
errorHandler);
myConnection->start();
}
#endif

Expand Down
11 changes: 7 additions & 4 deletions crow/include/crow/socket_adaptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using namespace boost;
using tcp = asio::ip::tcp;

struct SocketAdaptor {
using streamType = tcp::socket;
using secure = std::false_type;
using context = void;
SocketAdaptor(boost::asio::io_service& ioService, context* /*unused*/)
Expand All @@ -38,7 +39,8 @@ struct SocketAdaptor {

template <typename F>
void start(F f) {
f(boost::system::error_code());
boost::system::error_code ec;
f(ec);
}

tcp::socket socketCls;
Expand Down Expand Up @@ -72,6 +74,7 @@ struct TestSocketAdaptor {

#ifdef BMCWEB_ENABLE_SSL
struct SSLAdaptor {
using streamType = boost::asio::ssl::stream<tcp::socket>;
using secure = std::true_type;
using context = boost::asio::ssl::context;
using ssl_socket_t = boost::asio::ssl::stream<tcp::socket>;
Expand Down Expand Up @@ -104,9 +107,9 @@ struct SSLAdaptor {
fail, because the adapter is gone. As is, doRead believes the parse
failed, because isOpen now returns False (which could also mean the client
disconnected during parse)
UPdate: The parser does in fact have an "isUpgrade" method that is intended
for exactly this purpose. Todo is now to make doRead obey the flag
appropriately so this code can be changed back.
UPdate: The parser does in fact have an "isUpgrade" method that is
intended for exactly this purpose. Todo is now to make doRead obey the
flag appropriately so this code can be changed back.
*/
if (sslSocket != nullptr) {
return sslSocket->lowest_layer().is_open();
Expand Down
Loading

0 comments on commit 1b0044b

Please sign in to comment.