SchedBase Class Reference

#include <schedbase.h>

Inheritance diagram for SchedBase:

Inheritance graph
[legend]
Collaboration diagram for SchedBase:

Collaboration graph
[legend]
List of all members.

Detailed Description

SchedBase implements the third level of hydranode networking scheduler.

This class performs the actual bandwidth and connections dividing between requests in it's main scheduler loop. It is derived from EventTableBase, and as such will be run during each event loop, performing bandwidth requests handling.

Definition at line 42 of file schedbase.h.


Public Member Functions

size_t getConnReqCount () const
 Get number of pending connection requests.
size_t getUploadReqCount () const
 Get number of pending upload requests.
size_t getDownloadReqCount () const
 Get number of pending download requests.
bool isLimited (uint32_t ip)
 Check if speed limiting should be applied to specified IP address.
Accessors for various limits and other internal variables
void setUpLimit (uint32_t amount)
void setDownLimit (uint32_t amount)
uint32_t getUpLimit () const
uint32_t getDownLimit () const
uint32_t getConnLimit () const
uint64_t getTotalUpstream () const
uint64_t getTotalDownstream () const
uint32_t getUpSpeed ()
 Current upload speed.
uint32_t getDownSpeed ()
 Current download speed.
uint32_t getConnCount () const
 Number of current TCP connections.
Internal stuff - add new requests
void addUploadReq (UploadReqBase *r)
void addDloadReq (DownloadReqBase *r)
void addConnReq (ConnReqBase *r)
Modify open connection count
void addConn ()
void delConn ()

Static Public Member Functions

static SchedBaseinstance ()
 Singleton class - accessor to the only instance (created on demand).
template<typename Module, typename ImplPtr>
static float getScore (ImplPtr s)

Static Public Attributes

static const uint32_t INPUT_BUFSIZE = 100*1024

Private Member Functions

void exit ()
 Called by HydraNode on application shutdown.
void addUpStream (uint32_t amount)
 Refer to addDownStream for docs.
void addDownStream (uint32_t amount)
 Add upstream data.
void error (const boost::format &where, const std::string &what)
 Trace-logs an error.
Singleton
 SchedBase ()
 ~SchedBase ()
 SchedBase (const SchedBase &)
SchedBaseoperator= (const SchedBase &)
Main networking loop and helper functions
void handleEvents ()
 Must be overridden by derived classes.
void handleDownloads ()
void handleUploads ()
void handleConnections ()
Get the amount of free bandwidth/connections at this moment
uint32_t getFreeDown ()
uint32_t getFreeUp ()
bool getConnection ()

Private Attributes

uint64_t m_curTick
 Keeps current tick value - to reduce getTick() calls somewhat.
RangeList32 m_noSpeedLimit
 Ip addresses in this list are not affected by speed limits; traffic to these addresses is not counted towards total traffic.
Request sets
boost::scoped_ptr< Detail::UploadReqMapm_uploadReqs
boost::scoped_ptr< Detail::DownloadReqMapm_downloadReqs
boost::scoped_ptr< Detail::ConnReqMapm_connReqs
Various limits and counts
uint32_t m_upLimit
 upstream limit
uint32_t m_downLimit
 downstream limit
uint32_t m_connLimit
 open connections limit
uint32_t m_connCnt
 open connections count
uint64_t m_totalUp
 overall total uploaded
uint64_t m_totalDown
 overall total downloaded
uint64_t m_lastDownReset
 Last time download speed counter was reset.
uint64_t m_lastUpReset
 Last time upload speed counter was reset.
uint32_t m_recentDown
 Downloaded data since last counter reset.
uint32_t m_recentUp
 Uploaded data since last counter reset.
std::deque< uint32_t > m_upList
 Last 10 upload speed counters.
std::deque< uint32_t > m_downList
 Last 10 download speed counters.
uint32_t m_curUpSpeed
 Current, e.g. last seconds, upspeed.
uint32_t m_curDownSpeed
 Current, e.g. last seconds, downspeed.

Friends

class HydraNode

Classes

class  ConnReqBase
 Request of type connection. More...
class  DownloadReqBase
 Request of type download. More...
class  ReqBase
 Request base, only contains score of the request. More...
class  UploadReqBase
 Request of type upload. More...

Constructor & Destructor Documentation

SchedBase::SchedBase  )  [private]
 

Todo:
Move NoLimit IP address list to some config file

Definition at line 103 of file schedbase.cpp.

References Prefs::instance(), logMsg(), m_connCnt, m_connLimit, m_connReqs, m_downLimit, m_downloadReqs, m_lastDownReset, m_lastUpReset, m_noSpeedLimit, m_recentDown, m_recentUp, m_totalDown, m_totalUp, m_upLimit, m_uploadReqs, Socket::makeAddr(), RangeList< RangeType >::push(), Config::read(), Config::setPath(), and SWAP32_ON_LE.

Here is the call graph for this function:

SchedBase::~SchedBase  )  [private]
 

Definition at line 138 of file schedbase.cpp.

SchedBase::SchedBase const SchedBase  )  [private]
 


Member Function Documentation

void SchedBase::addConn  )  [inline]
 

Definition at line 218 of file schedbase.h.

void SchedBase::addConnReq ConnReqBase r  ) 
 

Definition at line 425 of file schedbase.cpp.

References m_connReqs.

Referenced by Scheduler< Impl, ImplPtr >::connect(), and SchedEventHandler::ServerEventHandler< Source, Scheduler >::onEvent().

void SchedBase::addDloadReq DownloadReqBase r  ) 
 

Definition at line 424 of file schedbase.cpp.

References m_downloadReqs.

Referenced by SchedEventHandler::ClientEventHandler< Source, Scheduler >::handleRead().

void SchedBase::addDownStream uint32_t  amount  )  [private]
 

Add upstream data.

Gaps longer than 900ms will result in a range of zeroes, so to avoid needless list manipulation, we can simply clear the list if the gap becomes larger than 900ms, which gives the same result, i.e 0.

If the gap is more than a single 100ms interval, then the first 100ms interval will contain the last "recent" value, whereas the next intervals will be zero, as no adds occoured for them.

900ms of entries are kept, which together with the amount stored in m_recentDown gives a timespan of 100ms to 1s. Is this to be desired? It will give a a fluxuation in the rate calculation, which could perhaps cause problems.

Definition at line 356 of file schedbase.cpp.

References m_curDownSpeed, m_curTick, m_downList, m_lastDownReset, m_recentDown, and m_totalDown.

Referenced by getDownSpeed(), and handleDownloads().

void SchedBase::addUploadReq UploadReqBase r  ) 
 

Definition at line 423 of file schedbase.cpp.

References m_uploadReqs.

Referenced by SchedEventHandler::ClientEventHandler< Source, Scheduler >::handleConnected(), SchedEventHandler::ClientEventHandler< Source, Scheduler >::handleWrite(), and Scheduler< Impl, ImplPtr >::write().

void SchedBase::addUpStream uint32_t  amount  )  [private]
 

Refer to addDownStream for docs.

Definition at line 382 of file schedbase.cpp.

References m_curTick, m_curUpSpeed, m_lastUpReset, m_recentUp, m_totalUp, and m_upList.

Referenced by getUpSpeed(), and handleUploads().

void SchedBase::delConn  )  [inline]
 

Definition at line 219 of file schedbase.h.

Referenced by Scheduler< Impl, ImplPtr >::delSocket(), Scheduler< Impl, ImplPtr >::disconnect(), and SchedEventHandler::ClientEventHandler< Source, Scheduler >::handleErr().

void SchedBase::error const boost::format &  where,
const std::string &  what
[private]
 

Trace-logs an error.

Parameters:
where Where the error happened
what What error happened

Definition at line 416 of file schedbase.cpp.

References logDebug().

Referenced by handleConnections(), handleDownloads(), and handleUploads().

Here is the call graph for this function:

void SchedBase::exit  )  [private]
 

Called by HydraNode on application shutdown.

Definition at line 144 of file schedbase.cpp.

References getTotalDownstream(), getTotalUpstream(), Prefs::instance(), logDebug(), logMsg(), m_connLimit, m_downLimit, m_upLimit, Config::setPath(), and Config::write().

Referenced by HydraNode::cleanup().

Here is the call graph for this function:

uint32_t SchedBase::getConnCount  )  const [inline]
 

Number of current TCP connections.

Definition at line 59 of file schedbase.h.

bool SchedBase::getConnection  )  [private]
 

Definition at line 336 of file schedbase.cpp.

References m_connCnt, and m_connLimit.

Referenced by handleConnections().

uint32_t SchedBase::getConnLimit  )  const [inline]
 

Definition at line 53 of file schedbase.h.

size_t SchedBase::getConnReqCount  )  const
 

Get number of pending connection requests.

Definition at line 420 of file schedbase.cpp.

References m_connReqs, and Config::size().

Here is the call graph for this function:

uint32_t SchedBase::getDownLimit  )  const [inline]
 

Definition at line 52 of file schedbase.h.

Referenced by getFreeDown().

size_t SchedBase::getDownloadReqCount  )  const
 

Get number of pending download requests.

Definition at line 422 of file schedbase.cpp.

References m_downloadReqs, and Config::size().

Here is the call graph for this function:

uint32_t SchedBase::getDownSpeed  ) 
 

Current download speed.

Definition at line 407 of file schedbase.cpp.

References addDownStream(), and m_curDownSpeed.

Referenced by getFreeDown(), and handleEvents().

Here is the call graph for this function:

uint32_t SchedBase::getFreeDown  )  [private]
 

Definition at line 326 of file schedbase.cpp.

References getDownLimit(), and getDownSpeed().

Referenced by handleDownloads().

Here is the call graph for this function:

uint32_t SchedBase::getFreeUp  )  [private]
 

Definition at line 332 of file schedbase.cpp.

References getUpLimit(), and getUpSpeed().

Referenced by handleUploads().

Here is the call graph for this function:

template<typename Module, typename ImplPtr>
static float SchedBase::getScore ImplPtr  s  )  [inline, static]
 

Definition at line 70 of file schedbase.h.

uint64_t SchedBase::getTotalDownstream  )  const [inline]
 

Definition at line 55 of file schedbase.h.

Referenced by exit().

uint64_t SchedBase::getTotalUpstream  )  const [inline]
 

Definition at line 54 of file schedbase.h.

Referenced by exit().

uint32_t SchedBase::getUpLimit  )  const [inline]
 

Definition at line 51 of file schedbase.h.

Referenced by getFreeUp().

size_t SchedBase::getUploadReqCount  )  const
 

Get number of pending upload requests.

Definition at line 421 of file schedbase.cpp.

References m_uploadReqs, and Config::size().

Here is the call graph for this function:

uint32_t SchedBase::getUpSpeed  ) 
 

Current upload speed.

Definition at line 411 of file schedbase.cpp.

References addUpStream(), and m_curUpSpeed.

Referenced by getFreeUp(), and handleEvents().

Here is the call graph for this function:

void SchedBase::handleConnections  )  [private]
 

Definition at line 271 of file schedbase.cpp.

References clearAndNotify(), error(), getConnection(), logTrace(), m_connCnt, m_connReqs, and TRACE_SCHED.

Referenced by handleEvents().

Here is the call graph for this function:

void SchedBase::handleDownloads  )  [private]
 

Definition at line 169 of file schedbase.cpp.

References addDownStream(), clearAndNotify(), error(), getFreeDown(), logDebug(), m_downloadReqs, and Config::size().

Referenced by handleEvents().

Here is the call graph for this function:

void SchedBase::handleEvents  )  [private, virtual]
 

Must be overridden by derived classes.

This is called from central event loop for each of the registred objects. Should handle all pending events (if existing).

Implements EventTableBase.

Definition at line 309 of file schedbase.cpp.

References Utils::bytesToString(), COL_CYAN, COL_GREEN, COL_NONE, COL_YELLOW, getDownSpeed(), Utils::getTick(), getUpSpeed(), handleConnections(), handleDownloads(), handleUploads(), m_connCnt, and m_curTick.

Here is the call graph for this function:

void SchedBase::handleUploads  )  [private]
 

Definition at line 218 of file schedbase.cpp.

References addUpStream(), clearAndNotify(), error(), getFreeUp(), logDebug(), m_uploadReqs, and Config::size().

Referenced by handleEvents().

Here is the call graph for this function:

SchedBase & SchedBase::instance  )  [static]
 

Singleton class - accessor to the only instance (created on demand).

Definition at line 139 of file schedbase.cpp.

Referenced by HydraNode::cleanup(), Scheduler< Impl, ImplPtr >::connect(), Scheduler< Impl, ImplPtr >::delSocket(), Scheduler< Impl, ImplPtr >::disconnect(), Scheduler< Impl, ImplPtr >::DownloadReq::doRecv(), Scheduler< Impl, ImplPtr >::UploadReq::doSend(), SchedEventHandler::ClientEventHandler< Source, Scheduler >::handleConnected(), SchedEventHandler::ClientEventHandler< Source, Scheduler >::handleErr(), SchedEventHandler::ClientEventHandler< Source, Scheduler >::handleRead(), SchedEventHandler::ClientEventHandler< Source, Scheduler >::handleWrite(), HydraNode::initSockets(), SchedEventHandler::ServerEventHandler< Source, Scheduler >::onEvent(), and Scheduler< Impl, ImplPtr >::write().

bool SchedBase::isLimited uint32_t  ip  )  [inline]
 

Check if speed limiting should be applied to specified IP address.

Parameters:
ip Ip address being interested in
Returns:
True if limiting should be applied, false otherwise

Definition at line 228 of file schedbase.h.

Referenced by Scheduler< Impl, ImplPtr >::DownloadReq::doRecv(), and Scheduler< Impl, ImplPtr >::UploadReq::doSend().

SchedBase& SchedBase::operator= const SchedBase  )  [private]
 

void SchedBase::setDownLimit uint32_t  amount  )  [inline]
 

Definition at line 50 of file schedbase.h.

void SchedBase::setUpLimit uint32_t  amount  )  [inline]
 

Definition at line 49 of file schedbase.h.


Friends And Related Function Documentation

friend class HydraNode [friend]
 

Definition at line 74 of file schedbase.h.


Member Data Documentation

const uint32_t SchedBase::INPUT_BUFSIZE = 100*1024 [static]
 

Definition at line 232 of file schedbase.h.

uint32_t SchedBase::m_connCnt [private]
 

open connections count

Definition at line 189 of file schedbase.h.

Referenced by getConnection(), handleConnections(), handleEvents(), and SchedBase().

uint32_t SchedBase::m_connLimit [private]
 

open connections limit

Definition at line 188 of file schedbase.h.

Referenced by exit(), getConnection(), and SchedBase().

boost::scoped_ptr<Detail::ConnReqMap> SchedBase::m_connReqs [private]
 

Definition at line 152 of file schedbase.h.

Referenced by addConnReq(), getConnReqCount(), handleConnections(), and SchedBase().

uint32_t SchedBase::m_curDownSpeed [private]
 

Current, e.g. last seconds, downspeed.

Definition at line 199 of file schedbase.h.

Referenced by addDownStream(), and getDownSpeed().

uint64_t SchedBase::m_curTick [private]
 

Keeps current tick value - to reduce getTick() calls somewhat.

Definition at line 182 of file schedbase.h.

Referenced by addDownStream(), addUpStream(), and handleEvents().

uint32_t SchedBase::m_curUpSpeed [private]
 

Current, e.g. last seconds, upspeed.

Definition at line 198 of file schedbase.h.

Referenced by addUpStream(), and getUpSpeed().

uint32_t SchedBase::m_downLimit [private]
 

downstream limit

Definition at line 187 of file schedbase.h.

Referenced by exit(), and SchedBase().

std::deque<uint32_t> SchedBase::m_downList [private]
 

Last 10 download speed counters.

Definition at line 197 of file schedbase.h.

Referenced by addDownStream().

boost::scoped_ptr<Detail::DownloadReqMap> SchedBase::m_downloadReqs [private]
 

Definition at line 151 of file schedbase.h.

Referenced by addDloadReq(), getDownloadReqCount(), handleDownloads(), and SchedBase().

uint64_t SchedBase::m_lastDownReset [private]
 

Last time download speed counter was reset.

Definition at line 192 of file schedbase.h.

Referenced by addDownStream(), and SchedBase().

uint64_t SchedBase::m_lastUpReset [private]
 

Last time upload speed counter was reset.

Definition at line 193 of file schedbase.h.

Referenced by addUpStream(), and SchedBase().

RangeList32 SchedBase::m_noSpeedLimit [private]
 

Ip addresses in this list are not affected by speed limits; traffic to these addresses is not counted towards total traffic.

Normally, this list contains localhost and LAN ip addresses.

Definition at line 207 of file schedbase.h.

Referenced by SchedBase().

uint32_t SchedBase::m_recentDown [private]
 

Downloaded data since last counter reset.

Definition at line 194 of file schedbase.h.

Referenced by addDownStream(), and SchedBase().

uint32_t SchedBase::m_recentUp [private]
 

Uploaded data since last counter reset.

Definition at line 195 of file schedbase.h.

Referenced by addUpStream(), and SchedBase().

uint64_t SchedBase::m_totalDown [private]
 

overall total downloaded

Definition at line 191 of file schedbase.h.

Referenced by addDownStream(), and SchedBase().

uint64_t SchedBase::m_totalUp [private]
 

overall total uploaded

Definition at line 190 of file schedbase.h.

Referenced by addUpStream(), and SchedBase().

uint32_t SchedBase::m_upLimit [private]
 

upstream limit

Definition at line 186 of file schedbase.h.

Referenced by exit(), and SchedBase().

std::deque<uint32_t> SchedBase::m_upList [private]
 

Last 10 upload speed counters.

Definition at line 196 of file schedbase.h.

Referenced by addUpStream().

boost::scoped_ptr<Detail::UploadReqMap> SchedBase::m_uploadReqs [private]
 

Definition at line 150 of file schedbase.h.

Referenced by addUploadReq(), getUploadReqCount(), handleUploads(), and SchedBase().


The documentation for this class was generated from the following files: