Inject journals:

Calls to WriteLog are replaced with injected journals
This commit is contained in:
seelabs
2015-09-19 11:06:12 -07:00
committed by Vinnie Falco
parent df6ac8f7f5
commit 92b2ca70b7
131 changed files with 1336 additions and 1076 deletions

View File

@@ -46,22 +46,32 @@ public:
using callback = std::function <void (error_code)>;
public:
AutoSocket (boost::asio::io_service& s, boost::asio::ssl::context& c)
AutoSocket (boost::asio::io_service& s, boost::asio::ssl::context& c, beast::Journal j)
: mSecure (false)
, mBuffer (4)
, j_ (j)
{
mSocket = std::make_shared<ssl_socket> (s, c);
}
AutoSocket (
boost::asio::io_service& s, boost::asio::ssl::context& c,
bool secureOnly, bool plainOnly)
bool secureOnly, bool plainOnly, beast::Journal j)
: mSecure (secureOnly)
, mBuffer ((plainOnly || secureOnly) ? 0 : 4)
, j_ (j)
{
mSocket = std::make_shared<ssl_socket> (s, c);
}
// swd TBD try remove this constructor
// This needs to use `deprecatedLogs` or a change is needed
// in websocket_02 (which breaks leveling)
AutoSocket (
boost::asio::io_service& s, boost::asio::ssl::context& c,
bool secureOnly, bool plainOnly)
: AutoSocket (s, c, secureOnly, plainOnly, ripple::deprecatedLogs().journal ("AutoSocket")){}
boost::asio::io_service& get_io_service () noexcept
{
return mSocket->get_io_service ();
@@ -121,14 +131,14 @@ public:
static bool rfc2818_verify (std::string const& domain, bool preverified,
boost::asio::ssl::verify_context& ctx)
boost::asio::ssl::verify_context& ctx, beast::Journal j)
{
using namespace ripple;
if (boost::asio::ssl::rfc2818_verification (domain) (preverified, ctx))
return true;
WriteLog (lsWARNING, AutoSocket) <<
JLOG (j.warning) <<
"Outbound SSL connection to " << domain <<
" fails certificate verification";
return false;
@@ -143,7 +153,7 @@ public:
// XXX Verify semantics of RFC 2818 are what we want.
mSocket->set_verify_callback (
std::bind (&rfc2818_verify, strDomain,
std::placeholders::_1, std::placeholders::_2), ec);
std::placeholders::_1, std::placeholders::_2, j_), ec);
return ec;
}
@@ -316,7 +326,7 @@ protected:
if (ec)
{
WriteLog (lsWARNING, AutoSocket) <<
JLOG (j_.warning) <<
"Handle autodetect error: " << ec;
cbFunc (ec);
}
@@ -329,14 +339,14 @@ protected:
|| ((mBuffer[3] < 127) && (mBuffer[3] > 31))))
{
// not ssl
WriteLog (lsTRACE, AutoSocket) << "non-SSL";
JLOG (j_.trace) << "non-SSL";
mSecure = false;
cbFunc (ec);
}
else
{
// ssl
WriteLog (lsTRACE, AutoSocket) << "SSL";
JLOG (j_.trace) << "SSL";
mSecure = true;
mSocket->async_handshake (ssl_socket::server, cbFunc);
}
@@ -346,6 +356,7 @@ private:
socket_ptr mSocket;
bool mSecure;
std::vector<char> mBuffer;
beast::Journal j_;
};
#endif

View File

@@ -121,6 +121,7 @@ private:
weak_connection_ptr m_connection;
int pingFreq_;
beast::Journal j_;
};
template <class WebSocket>
@@ -144,6 +145,7 @@ ConnectionImpl <WebSocket>::ConnectionImpl (
, m_handler (handler)
, m_connection (cpConnection)
, pingFreq_ (app.config ().WEBSOCKET_PING_FREQ)
, j_ (app.journal ("ConnectionImpl"))
{
// VFALCO Disabled since it might cause hangs
pingFreq_ = 0;
@@ -159,7 +161,7 @@ template <class WebSocket>
void ConnectionImpl <WebSocket>::rcvMessage (
message_ptr const& msg, bool& msgRejected, bool& runQueue)
{
WriteLog (lsWARNING, ConnectionImpl)
JLOG (j_.warning)
<< "WebSocket: rcvMessage";
ScopedLockType sl (m_receiveQueueMutex);
@@ -279,7 +281,7 @@ Json::Value ConnectionImpl <WebSocket>::invokeCommand (
else
{
RPC::Context context {
jvRequest, app_, loadType, m_netOPs, app_.getLedgerMaster(),
app_.journal ("RPCHandler"), jvRequest, app_, loadType, m_netOPs, app_.getLedgerMaster(),
role, {app_, suspend, "WSClient::command"},
this->shared_from_this ()};
RPC::doCommand (context, jvResult[jss::result]);
@@ -335,7 +337,7 @@ void ConnectionImpl <WebSocket>::preDestroy ()
template <class WebSocket>
void ConnectionImpl <WebSocket>::send (Json::Value const& jvObj, bool broadcast)
{
WriteLog (lsWARNING, ConnectionImpl)
JLOG (j_.warning)
<< "WebSocket: sending '" << to_string (jvObj);
connection_ptr ptr = m_connection.lock ();
@@ -346,7 +348,7 @@ void ConnectionImpl <WebSocket>::send (Json::Value const& jvObj, bool broadcast)
template <class WebSocket>
void ConnectionImpl <WebSocket>::disconnect ()
{
WriteLog (lsWARNING, ConnectionImpl)
JLOG (j_.warning)
<< "WebSocket: disconnecting";
connection_ptr ptr = m_connection.lock ();

View File

@@ -77,6 +77,7 @@ private:
beast::insight::Event rpc_size_;
beast::insight::Event rpc_time_;
ServerDescription desc_;
beast::Journal j_;
protected:
// VFALCO TODO Make this private.
@@ -90,6 +91,7 @@ public:
HandlerImpl (ServerDescription const& desc)
: app_ (desc.app)
, desc_ (desc)
, j_ (app_.journal ("HandlerLog"))
{
auto const& group (desc_.collectorManager.group ("rpc"));
rpc_requests_ = group->make_counter ("requests");
@@ -125,7 +127,8 @@ public:
{
try
{
WriteLog (broadcast ? lsTRACE : lsDEBUG, HandlerLog)
auto& jm = broadcast ? j_.trace : j_.debug;
JLOG (jm)
<< "Ws:: Sending '" << strMessage << "'";
cpClient->send (strMessage);
@@ -161,7 +164,7 @@ public:
cpClient->terminate ({});
try
{
WriteLog (lsDEBUG, HandlerLog) <<
JLOG (j_.debug) <<
"Ws:: ping_out(" <<
// TODO(tom): re-enable this logging.
// cpClient->get_socket ().remote_endpoint ().to_string ()
@@ -211,7 +214,7 @@ public:
assert (result.second);
(void) result.second;
WriteLog (lsDEBUG, HandlerLog) <<
JLOG (j_.debug) <<
"Ws:: on_open(" << remoteEndpoint << ")";
}
catch (...)
@@ -233,7 +236,7 @@ public:
}
try
{
WriteLog (lsDEBUG, HandlerLog) <<
JLOG (j_.debug) <<
"Ws:: on_pong(" << cpClient->get_socket ().remote_endpoint() << ")";
}
catch (...)
@@ -265,7 +268,7 @@ public:
{
try
{
WriteLog (lsDEBUG, HandlerLog) <<
JLOG (j_.debug) <<
"Ws:: " << reason << "(" <<
cpClient->get_socket ().remote_endpoint() <<
") not found";
@@ -284,7 +287,7 @@ public:
ptr->preDestroy (); // Must be done before we return
try
{
WriteLog (lsDEBUG, HandlerLog) <<
JLOG (j_.debug) <<
"Ws:: " << reason << "(" <<
cpClient->get_socket ().remote_endpoint () << ") found";
}
@@ -326,7 +329,7 @@ public:
{
try
{
WriteLog (lsDEBUG, HandlerLog) <<
JLOG (j_.debug) <<
"Ws:: Rejected(" <<
cpClient->get_socket().remote_endpoint() <<
") '" << mpMessage->get_payload () << "'";
@@ -383,7 +386,7 @@ public:
try
{
WriteLog (lsDEBUG, HandlerLog)
JLOG (j_.debug)
<< "Ws:: Receiving("
<< cpClient->get_socket ().remote_endpoint ()
<< ") '" << mpMessage->get_payload () << "'";
@@ -435,9 +438,11 @@ public:
data->jvRequest = std::move(jvRequest);
data->conn = conn;
auto coroutine = [data] (RPC::Suspend const& suspend) {
auto j = app_.journal ("RPCHandler");
auto coroutine = [data, j] (RPC::Suspend const& suspend) {
data->buffer = to_string(
data->conn->invokeCommand(data->jvRequest, suspend));
data->conn->invokeCommand(
data->jvRequest, suspend));
};
static auto const disableWebsocketsCoroutines = true;
auto useCoroutines = disableWebsocketsCoroutines ?

View File

@@ -32,7 +32,7 @@ std::unique_ptr<beast::Stoppable> makeServer (ServerDescription const& desc)
if (version.empty())
version = WebSocket02::versionName();
WriteLog (lsWARNING, WebSocket) << "Websocket version " << version;
JLOG (desc.app.journal("WebSocket").warning) << "Websocket version " << version;
if (version == WebSocket02::versionName())
return makeServer02 (desc);
assert (version == "04");

View File

@@ -40,6 +40,7 @@ private:
ServerDescription desc_;
LockType m_endpointLock;
beast::Journal j_;
typename WebSocket::EndpointPtr m_endpoint;
public:
@@ -47,6 +48,7 @@ public:
: beast::Stoppable (WebSocket::versionName(), desc.source)
, Thread ("websocket")
, desc_(desc)
, j_ (desc.app.journal ("WebSocket"))
{
startThread ();
}
@@ -59,7 +61,7 @@ public:
private:
void run () override
{
WriteLog (lsWARNING, WebSocket)
JLOG (j_.warning)
<< "Websocket: creating endpoint " << desc_.port;
auto handler = WebSocket::makeHandler (desc_);
@@ -68,7 +70,7 @@ private:
m_endpoint = WebSocket::makeEndpoint (std::move (handler));
}
WriteLog (lsWARNING, WebSocket)
JLOG (j_.warning)
<< "Websocket: listening on " << desc_.port;
listen();
@@ -77,17 +79,17 @@ private:
m_endpoint.reset();
}
WriteLog (lsWARNING, WebSocket)
JLOG (j_.warning)
<< "Websocket: finished listening on " << desc_.port;
stopped ();
WriteLog (lsWARNING, WebSocket)
JLOG (j_.warning)
<< "Websocket: stopped on " << desc_.port;
}
void onStop () override
{
WriteLog (lsWARNING, WebSocket)
JLOG (j_.warning)
<< "Websocket: onStop " << desc_.port;
typename WebSocket::EndpointPtr endpoint;

View File

@@ -111,12 +111,12 @@ void Server <WebSocket02>::listen()
}
catch (std::exception const& e)
{
WriteLog (lsWARNING, Server) << "websocketpp exception: "
JLOG (j_.warning) << "websocketpp exception: "
<< e.what ();
static const int maxRetries = 10;
if (maxRetries && i >= maxRetries)
{
WriteLog (lsWARNING, Server)
JLOG (j_.warning)
<< "websocketpp exceeded max retries: " << i;
break;
}

View File

@@ -141,7 +141,7 @@ void Server <WebSocket04>::listen()
m_endpoint->listen (desc_.port.ip, desc_.port.port);
m_endpoint->start_accept();
auto c = m_endpoint->get_io_service ().run ();
WriteLog (lsWARNING, WebSocket)
JLOG (j_.warning)
<< "Server run with: '" << c;
}