Annotate some core classes

This commit is contained in:
Vinnie Falco
2013-06-23 19:31:16 -07:00
parent fca16f5c71
commit 5c21ce5b3c
12 changed files with 125 additions and 99 deletions

View File

@@ -139,6 +139,9 @@ public:
static Json::Value runHandler (const std::string& name, const Json::Value& params);
private:
// VFALCO TODO Replace with a singleton with a well defined interface and
// a lock free stack (if necessary).
//
static RPCInternalHandler* sHeadHandler;
RPCInternalHandler* mNextHandler;

View File

@@ -202,40 +202,63 @@ void LoadManager::threadEntry ()
{
setCallingThreadName ("loadmgr");
// VFALCO TODO replace this with a beast Time object
// VFALCO TODO replace this with a beast Time object?
//
// Initialize the clock to the current time.
boost::posix_time::ptime t = boost::posix_time::microsec_clock::universal_time ();
while (1)
for (;;)
{
{
// VFALCO NOTE What is this lock protecting?
boost::mutex::scoped_lock sl (mLock);
// Check for the shutdown flag.
if (mShutdown)
{
// VFALCO NOTE Why clear the flag now?
mShutdown = false;
return;
}
// VFALCO NOTE I think this is to reduce calls to the operating system
// for retrieving the current time.
//
// TODO Instead of incrementing can't we just retrieve the current
// time again?
//
// Manually update the timer.
UptimeTimer::getInstance ().incrementElapsedTime ();
int dlTime = UptimeTimer::getInstance ().getElapsedSeconds () - mDeadLock;
// Measure the amount of time we have been deadlocked, in seconds.
//
// VFALCO NOTE mDeadLock is a canary for detecting the condition.
int const timeSpentDeadlocked = UptimeTimer::getInstance ().getElapsedSeconds () - mDeadLock;
if (mArmed && (dlTime >= 10))
if (mArmed && (timeSpentDeadlocked >= 10))
{
if ((dlTime % 10) == 0)
// Report the deadlocked condition every 10 seconds
if ((timeSpentDeadlocked % 10) == 0)
{
boost::thread (BIND_TYPE (&LogDeadLock, dlTime)).detach ();
// VFALCO TODO Replace this with a dedicated thread with call queue.
//
boost::thread (BIND_TYPE (&LogDeadLock, timeSpentDeadlocked)).detach ();
}
assert (dlTime < 500);
// If we go over 500 seconds spent deadlocked, it means that the
// deadlock resolution code has failed, which qualifies as undefined
// behavior.
//
assert (timeSpentDeadlocked < 500);
}
}
// VFALCO TODO Eliminate the dependence on the Application object by
// constructing with the job queue and the fee tracker.
bool change;
// VFALCO TODO Eliminate the dependence on the Application object.
// Choices include constructing with the job queue / feetracker.
// Another option is using an observer pattern to invert the dependency.
if (theApp->getJobQueue ().isOverloaded ())
{
WriteLog (lsINFO, LoadManager) << theApp->getJobQueue ().getJson (0);

View File

@@ -40,7 +40,23 @@ enum
LC_Network = 4
};
// a single endpoint that can impose load
/** Tracks the consumption of resources at an endpoint.
To prevent monopolization of server resources or attacks on servers,
resource consumption is monitored at each endpoint. When consumption
exceeds certain thresholds, costs are imposed. Costs include charging
additional XRP for transactions, requiring a proof of work to be
performed, or simply disconnecting the endpoint.
Currently, consumption endpoints include:
- WebSocket connections
- Peer connections
@note Although RPC connections consume resources, they are transient and
cannot be rate limited. It is advised not to expose RPC interfaces
to the general public.
*/
class LoadSource
{
private:
@@ -53,6 +69,13 @@ public:
static const int lsfOutbound = 2; // outbound connection
public:
/** Construct a load source.
Sources with admin privileges have relaxed or no restrictions
on resource consumption.
@param admin `true` if the source has admin privileges.
*/
explicit LoadSource (bool admin)
: mBalance (0)
, mFlags (admin ? lsfPrivileged : 0)
@@ -142,22 +165,6 @@ public:
void init ();
int getCreditRate () const;
int getCreditLimit () const;
int getDebitWarn () const;
int getDebitLimit () const;
void setCreditRate (int);
void setCreditLimit (int);
void setDebitWarn (int);
void setDebitLimit (int);
bool shouldWarn (LoadSource&) const;
bool shouldCutoff (LoadSource&) const;
@@ -182,6 +189,17 @@ public:
mArmed = true;
}
private:
// VFALCO TODO These used to be public but are apparently not used. Find out why.
int getCreditRate () const;
int getCreditLimit () const;
int getDebitWarn () const;
int getDebitLimit () const;
void setCreditRate (int);
void setCreditLimit (int);
void setDebitWarn (int);
void setDebitLimit (int);
private:
class Cost
{
@@ -201,7 +219,7 @@ private:
}
public:
// VFALCO TODO Make these private
// VFALCO TODO Make these private and const
LoadType mType;
int mCost;
int mCategories;