Access Journal::Stream using member functions (RIPD-1087):

Replace Journal public data members with member function accessors
in order to make Journal lighter weight.  The change makes a
Journal cheaper to pass by value.

Also add missing stream checks (e.g., calls to JLOG) to avoid
text processing that ultimately will not be stored in the log.
This commit is contained in:
Scott Schurr
2016-03-09 10:48:21 -08:00
committed by seelabs
parent b3f5986c83
commit 7a4bd2278d
132 changed files with 1843 additions and 1799 deletions

View File

@@ -79,7 +79,7 @@ Json::Value doBookOffers (RPC::Context& context)
if (!to_currency (pay_currency, taker_pays [jss::currency].asString ()))
{
JLOG (context.j.info) << "Bad taker_pays currency.";
JLOG (context.j.info()) << "Bad taker_pays currency.";
return RPC::make_error (rpcSRC_CUR_MALFORMED,
"Invalid field 'taker_pays.currency', bad currency.");
}
@@ -88,7 +88,7 @@ Json::Value doBookOffers (RPC::Context& context)
if (!to_currency (get_currency, taker_gets [jss::currency].asString ()))
{
JLOG (context.j.info) << "Bad taker_gets currency.";
JLOG (context.j.info()) << "Bad taker_gets currency.";
return RPC::make_error (rpcDST_AMT_MALFORMED,
"Invalid field 'taker_gets.currency', bad currency.");
}
@@ -168,7 +168,7 @@ Json::Value doBookOffers (RPC::Context& context)
if (pay_currency == get_currency && pay_issuer == get_issuer)
{
JLOG (context.j.info) << "taker_gets same as taker_pays.";
JLOG (context.j.info()) << "taker_gets same as taker_pays.";
return RPC::make_error (rpcBAD_MARKET);
}

View File

@@ -45,10 +45,10 @@ Json::Value doInternal (RPC::Context& context)
{
if (name == h->name_)
{
JLOG (context.j.warning)
JLOG (context.j.warn())
<< "Internal command " << name << ": " << params;
Json::Value ret = h->handler_ (params);
JLOG (context.j.warning)
JLOG (context.j.warn())
<< "Internal command returns: " << ret;
return ret;
}

View File

@@ -126,7 +126,7 @@ Json::Value doRipplePathFind (RPC::Context& context)
&& (!saDstAmount.getIssuer () ||
noAccount() == saDstAmount.getIssuer ())))
{
JLOG (context.j.info) << "Bad destination_amount.";
JLOG (context.j.info()) << "Bad destination_amount.";
jvResult = rpcError (rpcINVALID_PARAMS);
}
else if (
@@ -137,7 +137,7 @@ Json::Value doRipplePathFind (RPC::Context& context)
context.params[jss::source_currencies].size() >
RPC::Tuning::max_src_cur))
{
JLOG (context.j.info) << "Bad source_currencies.";
JLOG (context.j.info()) << "Bad source_currencies.";
jvResult = rpcError(rpcINVALID_PARAMS);
}
else
@@ -241,7 +241,7 @@ Json::Value doRipplePathFind (RPC::Context& context)
jvResult[jss::alternatives] = pathFindResult.second;
}
JLOG (context.j.debug)
JLOG (context.j.debug())
<< "ripple_path_find< " << jvResult;
return jvResult;
@@ -289,7 +289,7 @@ ripplePathFind (std::shared_ptr<RippleLineCache> const& cache,
if (! c.isMember(jss::currency) ||
! to_currency(srcCurrencyID, c[jss::currency].asString()))
{
JLOG (j.info) << "Bad currency.";
JLOG (j.info()) << "Bad currency.";
return std::make_pair(false, rpcError(rpcSRC_CUR_MALFORMED));
}
@@ -301,7 +301,7 @@ ripplePathFind (std::shared_ptr<RippleLineCache> const& cache,
srcIssuerID.isZero() != srcCurrencyID.isZero() ||
noAccount() == srcIssuerID))
{
JLOG (j.info) << "Bad issuer.";
JLOG (j.info()) << "Bad issuer.";
return std::make_pair(false, rpcError(rpcSRC_ISR_MALFORMED));
}
@@ -342,7 +342,7 @@ ripplePathFind (std::shared_ptr<RippleLineCache> const& cache,
return std::make_pair(false, paths.error);
spsComputed = paths.object->getFieldPathSet(sfPaths);
JLOG (j.trace) << "ripple_path_find: Paths: " <<
JLOG (j.trace()) << "ripple_path_find: Paths: " <<
spsComputed.getJson(0);
}
@@ -350,7 +350,7 @@ ripplePathFind (std::shared_ptr<RippleLineCache> const& cache,
currency_map, issue.currency, saDstAmount, level, app);
if (! pathfinder)
{
JLOG (j.warning) << "ripple_path_find: No paths found.";
JLOG (j.warn()) << "ripple_path_find: No paths found.";
continue;
}
@@ -404,7 +404,7 @@ ripplePathFind (std::shared_ptr<RippleLineCache> const& cache,
app.config(),
&rcInput);
JLOG(j.info)
JLOG(j.info())
<< "ripple_path_find:"
<< " saMaxAmount=" << saMaxAmount
<< " saDstAmount=" << saDstAmount
@@ -416,7 +416,7 @@ ripplePathFind (std::shared_ptr<RippleLineCache> const& cache,
(rc.result() == terNO_LINE || rc.result() == tecPATH_PARTIAL))
{
auto jpr = app.journal("PathRequest");
JLOG(jpr.debug)
JLOG(jpr.debug())
<< "Trying with an extra path element";
ps.push_back(fullLiquidityPath);
sandbox.emplace(&*cache->getLedger(), tapNONE);
@@ -431,7 +431,7 @@ ripplePathFind (std::shared_ptr<RippleLineCache> const& cache,
ps, // --> Path set.
app.logs(),
app.config());
JLOG(jpr.debug)
JLOG(jpr.debug())
<< "Extra path element gives "
<< transHuman(rc.result());
}
@@ -460,7 +460,7 @@ ripplePathFind (std::shared_ptr<RippleLineCache> const& cache,
std::string strToken;
std::string strHuman;
transResultInfo(rc.result(), strToken, strHuman);
JLOG (j.debug)
JLOG (j.debug())
<< "ripple_path_find: "
<< strToken << " "
<< strHuman << " "

View File

@@ -42,7 +42,7 @@ Json::Value doSubscribe (RPC::Context& context)
if (! context.infoSub && ! context.params.isMember(jss::url))
{
// Must be a JSON-RPC call.
JLOG(context.j.info) << "doSubscribe: RPC subscribe requires a url";
JLOG(context.j.info()) << "doSubscribe: RPC subscribe requires a url";
return rpcError (rpcINVALID_PARAMS);
}
@@ -68,7 +68,7 @@ Json::Value doSubscribe (RPC::Context& context)
ispSub = context.netOps.findRpcSub(strUrl);
if (! ispSub)
{
JLOG (context.j.debug)
JLOG (context.j.debug())
<< "doSubscribe: building: " << strUrl;
auto rspSub = make_RPCSub (context.app.getOPs (),
@@ -79,7 +79,7 @@ Json::Value doSubscribe (RPC::Context& context)
}
else
{
JLOG (context.j.trace)
JLOG (context.j.trace())
<< "doSubscribe: reusing: " << strUrl;
if (auto rpcSub = std::dynamic_pointer_cast<RPCSub> (ispSub))
@@ -104,7 +104,7 @@ Json::Value doSubscribe (RPC::Context& context)
{
if (! context.params[jss::streams].isArray ())
{
JLOG (context.j.info)
JLOG (context.j.info())
<< "doSubscribe: streams requires an array.";
return rpcError (rpcINVALID_PARAMS);
}
@@ -176,7 +176,7 @@ Json::Value doSubscribe (RPC::Context& context)
if (ids.empty())
return rpcError(rpcACT_MALFORMED);
context.netOps.subAccount(ispSub, ids, false);
JLOG(context.j.debug) << "doSubscribe: accounts: " << ids.size();
JLOG(context.j.debug()) << "doSubscribe: accounts: " << ids.size();
}
if (context.params.isMember(jss::books))
@@ -201,7 +201,7 @@ Json::Value doSubscribe (RPC::Context& context)
if (! taker_pays.isMember (jss::currency) || ! to_currency (
book.in.currency, taker_pays[jss::currency].asString ()))
{
JLOG (context.j.info) << "Bad taker_pays currency.";
JLOG (context.j.info()) << "Bad taker_pays currency.";
return rpcError (rpcSRC_CUR_MALFORMED);
}
@@ -214,7 +214,7 @@ Json::Value doSubscribe (RPC::Context& context)
|| (!book.in.currency != !book.in.account)
|| noAccount() == book.in.account)
{
JLOG (context.j.info) << "Bad taker_pays issuer.";
JLOG (context.j.info()) << "Bad taker_pays issuer.";
return rpcError (rpcSRC_ISR_MALFORMED);
}
@@ -222,7 +222,7 @@ Json::Value doSubscribe (RPC::Context& context)
if (! taker_gets.isMember (jss::currency) || !to_currency (
book.out.currency, taker_gets[jss::currency].asString ()))
{
JLOG (context.j.info) << "Bad taker_pays currency.";
JLOG (context.j.info()) << "Bad taker_pays currency.";
return rpcError (rpcSRC_CUR_MALFORMED);
}
@@ -235,14 +235,14 @@ Json::Value doSubscribe (RPC::Context& context)
|| (!book.out.currency != !book.out.account)
|| noAccount() == book.out.account)
{
JLOG (context.j.info) << "Bad taker_gets issuer.";
JLOG (context.j.info()) << "Bad taker_gets issuer.";
return rpcError (rpcDST_ISR_MALFORMED);
}
if (book.in.currency == book.out.currency
&& book.in.account == book.out.account)
{
JLOG (context.j.info)
JLOG (context.j.info())
<< "taker_gets same as taker_pays.";
return rpcError (rpcBAD_MARKET);
}
@@ -259,7 +259,7 @@ Json::Value doSubscribe (RPC::Context& context)
if (!isConsistent (book))
{
JLOG (context.j.warning) << "Bad market: " << book;
JLOG (context.j.warn()) << "Bad market: " << book;
return rpcError (rpcBAD_MARKET);
}

View File

@@ -155,7 +155,7 @@ Json::Value doUnsubscribe (RPC::Context& context)
|| !to_currency (
book.in.currency, taker_pays[jss::currency].asString ()))
{
JLOG (context.j.info) << "Bad taker_pays currency.";
JLOG (context.j.info()) << "Bad taker_pays currency.";
return rpcError (rpcSRC_CUR_MALFORMED);
}
// Parse optional issuer.
@@ -167,7 +167,7 @@ Json::Value doUnsubscribe (RPC::Context& context)
|| !isConsistent (book.in)
|| noAccount() == book.in.account)
{
JLOG (context.j.info) << "Bad taker_pays issuer.";
JLOG (context.j.info()) << "Bad taker_pays issuer.";
return rpcError (rpcSRC_ISR_MALFORMED);
}
@@ -177,7 +177,7 @@ Json::Value doUnsubscribe (RPC::Context& context)
|| !to_currency (book.out.currency,
taker_gets[jss::currency].asString ()))
{
JLOG (context.j.info) << "Bad taker_pays currency.";
JLOG (context.j.info()) << "Bad taker_pays currency.";
return rpcError (rpcSRC_CUR_MALFORMED);
}
@@ -190,14 +190,14 @@ Json::Value doUnsubscribe (RPC::Context& context)
|| !isConsistent (book.out)
|| noAccount() == book.out.account)
{
JLOG (context.j.info) << "Bad taker_gets issuer.";
JLOG (context.j.info()) << "Bad taker_gets issuer.";
return rpcError (rpcDST_ISR_MALFORMED);
}
if (book.in == book.out)
{
JLOG (context.j.info)
JLOG (context.j.info())
<< "taker_gets same as taker_pays.";
return rpcError (rpcBAD_MARKET);
}

View File

@@ -180,8 +180,9 @@ bool isValidated (LedgerMaster& ledgerMaster, ReadView const& ledger,
}
catch (SHAMapMissingNode const&)
{
JLOG (app.journal ("RPCHandler").warning)
<< "Missing SHANode " << std::to_string (seq);
auto stream = app.journal ("RPCHandler").warn();
JLOG (stream)
<< "Missing SHANode " << std::to_string (seq);
return false;
}

View File

@@ -119,7 +119,7 @@ error_code_i fillHandler (Context& context,
int jc = context.app.getJobQueue ().getJobCountGE (jtCLIENT);
if (jc > Tuning::maxJobQueueClients)
{
JLOG (context.j.debug) << "Too busy for command: " << jc;
JLOG (context.j.debug()) << "Too busy for command: " << jc;
return rpcTOO_BUSY;
}
}
@@ -129,8 +129,8 @@ error_code_i fillHandler (Context& context,
std::string strCommand = context.params[jss::command].asString ();
JLOG (context.j.trace) << "COMMAND:" << strCommand;
JLOG (context.j.trace) << "REQUEST:" << context.params;
JLOG (context.j.trace()) << "COMMAND:" << strCommand;
JLOG (context.j.trace()) << "REQUEST:" << context.params;
auto handler = getHandler(strCommand);
@@ -143,7 +143,7 @@ error_code_i fillHandler (Context& context,
if ((handler->condition_ & NEEDS_NETWORK_CONNECTION) &&
(context.netOps.getOperatingMode () < NetworkOPs::omSYNCING))
{
JLOG (context.j.info)
JLOG (context.j.info())
<< "Insufficient network mode for RPC: "
<< context.netOps.strOperatingMode ();
@@ -164,7 +164,7 @@ error_code_i fillHandler (Context& context,
if (cID + 10 < vID)
{
JLOG (context.j.debug) << "Current ledger ID(" << cID <<
JLOG (context.j.debug()) << "Current ledger ID(" << cID <<
") is less than validated ledger ID(" << vID << ")";
return rpcNO_CURRENT;
}
@@ -192,7 +192,7 @@ Status callMethod (
}
catch (std::exception& e)
{
JLOG (context.j.info) << "Caught throw: " << e.what ();
JLOG (context.j.info()) << "Caught throw: " << e.what ();
if (context.loadType == Resource::feeReferenceRPC)
context.loadType = Resource::feeExceptionRPC;
@@ -209,7 +209,7 @@ void getResult (
auto&& result = Json::addObject (object, jss::result);
if (auto status = callMethod (context, method, name, result))
{
JLOG (context.j.debug) << "rpcError: " << status.toString();
JLOG (context.j.debug()) << "rpcError: " << status.toString();
result[jss::status] = jss::error;
result[jss::request] = context.params;
}
@@ -236,13 +236,13 @@ Status doCommand (
if (! context.headers.user.empty() ||
! context.headers.forwardedFor.empty())
{
context.j.debug << "start command: " << handler->name_ <<
JLOG(context.j.debug()) << "start command: " << handler->name_ <<
", X-User: " << context.headers.user << ", X-Forwarded-For: " <<
context.headers.forwardedFor;
auto ret = callMethod (context, method, handler->name_, result);
context.j.debug << "finish command: " << handler->name_ <<
JLOG(context.j.debug()) << "finish command: " << handler->name_ <<
", X-User: " << context.headers.user << ", X-Forwarded-For: " <<
context.headers.forwardedFor;

View File

@@ -218,7 +218,7 @@ static Json::Value checkPayment(
}
auto j = app.journal ("RPCHandler");
JLOG (j.debug)
JLOG (j.debug())
<< "transactionSign: build_path: "
<< result.getJson (0);
@@ -378,7 +378,7 @@ transactionPreProcessImpl (
if (verify && !sle)
{
// If not offline and did not find account, error.
JLOG (j.debug)
JLOG (j.debug())
<< "transactionSign: Failed to find source account "
<< "in current ledger: "
<< toBase58(srcAddressID);
@@ -417,7 +417,7 @@ transactionPreProcessImpl (
{
if (! sle)
{
JLOG (j.debug)
JLOG (j.debug())
<< "transactionSign: Failed to find source account "
<< "in current ledger: "
<< toBase58(srcAddressID);
@@ -441,7 +441,7 @@ transactionPreProcessImpl (
// XXX Ignore transactions for accounts not created.
return rpcError (rpcSRC_ACT_NOT_FOUND);
JLOG (j.trace)
JLOG (j.trace())
<< "verify: " << toBase58(calcAccountID(keypair.first))
<< " : " << toBase58(srcAddressID);
@@ -704,7 +704,7 @@ Json::Value transactionSign (
using namespace detail;
auto j = app.journal ("RPCHandler");
JLOG (j.debug) << "transactionSign: " << jvRequest;
JLOG (j.debug()) << "transactionSign: " << jvRequest;
// Add and amend fields based on the transaction type.
SigningForParams signForParams;
@@ -739,7 +739,7 @@ Json::Value transactionSubmit (
using namespace detail;
auto j = app.journal ("RPCHandler");
JLOG (j.debug) << "transactionSubmit: " << jvRequest;
JLOG (j.debug()) << "transactionSubmit: " << jvRequest;
// Add and amend fields based on the transaction type.
@@ -861,7 +861,7 @@ Json::Value transactionSignFor (
std::shared_ptr<ReadView const> const& ledger)
{
auto j = app.journal ("RPCHandler");
JLOG (j.debug) << "transactionSignFor: " << jvRequest;
JLOG (j.debug()) << "transactionSignFor: " << jvRequest;
// Verify presence of the signer's account field.
const char accountField[] = "account";
@@ -972,7 +972,7 @@ Json::Value transactionSubmitMultiSigned (
ProcessTransactionFn const& processTransaction)
{
auto j = app.journal ("RPCHandler");
JLOG (j.debug)
JLOG (j.debug())
<< "transactionSubmitMultiSigned: " << jvRequest;
// When multi-signing, the "Sequence" and "SigningPubKey" fields must
@@ -1001,7 +1001,7 @@ Json::Value transactionSubmitMultiSigned (
if (!sle)
{
// If did not find account, error.
JLOG (j.debug)
JLOG (j.debug())
<< "transactionSubmitMultiSigned: Failed to find source account "
<< "in current ledger: "
<< toBase58(srcAddressID);