mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 19:15:54 +00:00
102 lines
3.2 KiB
C++
102 lines
3.2 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
Copyright (c) 2011-2013, OpenCoin, Inc.
|
|
*/
|
|
//==============================================================================
|
|
|
|
SETUP_LOG (WSDoor)
|
|
|
|
//
|
|
// This is a light weight, untrusted interface for web clients.
|
|
// For now we don't provide proof. Later we will.
|
|
//
|
|
// Might need to support this header for browsers: Access-Control-Allow-Origin: *
|
|
// - https://developer.mozilla.org/en-US/docs/HTTP_access_control
|
|
//
|
|
|
|
//
|
|
// Strategy:
|
|
// - We only talk to NetworkOPs (so we will work even in thin mode)
|
|
// - NetworkOPs is smart enough to subscribe and or pass back messages
|
|
//
|
|
// VFALCO NOTE NetworkOPs isn't used here...
|
|
//
|
|
void WSDoor::startListening ()
|
|
{
|
|
setCallingThreadName ("websocket");
|
|
// Generate a single SSL context for use by all connections.
|
|
boost::shared_ptr<boost::asio::ssl::context> mCtx;
|
|
mCtx = boost::make_shared<boost::asio::ssl::context> (boost::asio::ssl::context::sslv23);
|
|
|
|
mCtx->set_options (
|
|
boost::asio::ssl::context::default_workarounds
|
|
| boost::asio::ssl::context::no_sslv2
|
|
| boost::asio::ssl::context::single_dh_use);
|
|
|
|
SSL_CTX_set_tmp_dh_callback (mCtx->native_handle (), handleTmpDh);
|
|
|
|
// Construct a single handler for all requests.
|
|
websocketpp::server_autotls::handler::ptr handler (new WSServerHandler<websocketpp::server_autotls> (mCtx, mPublic));
|
|
|
|
// Construct a websocket server.
|
|
mSEndpoint = new websocketpp::server_autotls (handler);
|
|
|
|
// mEndpoint->alog().unset_level(websocketpp::log::alevel::ALL);
|
|
// mEndpoint->elog().unset_level(websocketpp::log::elevel::ALL);
|
|
|
|
// Call the main-event-loop of the websocket server.
|
|
try
|
|
{
|
|
mSEndpoint->listen (
|
|
boost::asio::ip::tcp::endpoint (
|
|
boost::asio::ip::address ().from_string (mIp), mPort));
|
|
}
|
|
catch (websocketpp::exception& e)
|
|
{
|
|
WriteLog (lsWARNING, WSDoor) << "websocketpp exception: " << e.what ();
|
|
|
|
while (1) // temporary workaround for websocketpp throwing exceptions on access/close races
|
|
{
|
|
// https://github.com/zaphoyd/websocketpp/issues/98
|
|
try
|
|
{
|
|
mSEndpoint->get_io_service ().run ();
|
|
break;
|
|
}
|
|
catch (websocketpp::exception& e)
|
|
{
|
|
WriteLog (lsWARNING, WSDoor) << "websocketpp exception: " << e.what ();
|
|
}
|
|
}
|
|
}
|
|
|
|
delete mSEndpoint;
|
|
}
|
|
|
|
WSDoor* WSDoor::createWSDoor (const std::string& strIp, const int iPort, bool bPublic)
|
|
{
|
|
WSDoor* wdpResult = new WSDoor (strIp, iPort, bPublic);
|
|
|
|
WriteLog (lsINFO, WSDoor) <<
|
|
boost::str (boost::format ("Websocket: %s: Listening: %s %d ")
|
|
% (bPublic ? "Public" : "Private")
|
|
% strIp
|
|
% iPort);
|
|
|
|
wdpResult->mThread = new boost::thread (BIND_TYPE (&WSDoor::startListening, wdpResult));
|
|
|
|
return wdpResult;
|
|
}
|
|
|
|
void WSDoor::stop ()
|
|
{
|
|
if (mThread)
|
|
{
|
|
if (mSEndpoint)
|
|
mSEndpoint->stop ();
|
|
|
|
|
|
mThread->join ();
|
|
}
|
|
}
|