2012-06-21 19:23:46 -04:00
|
|
|
/*
|
|
|
|
* libretroshare/src/services/p3bwctrl.h
|
|
|
|
*
|
|
|
|
* Bandwidth Control.
|
|
|
|
*
|
|
|
|
* Copyright 2012 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2.1 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SERVICE_RSBANDWIDTH_CONTROL_HEADER
|
|
|
|
#define SERVICE_RSBANDWIDTH_CONTROL_HEADER
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
#include "serialiser/rsbwctrlitems.h"
|
|
|
|
#include "services/p3service.h"
|
2014-03-28 23:57:44 -04:00
|
|
|
#include "pqi/pqiservicemonitor.h"
|
2012-06-21 19:23:46 -04:00
|
|
|
#include "retroshare/rsconfig.h" // for datatypes.
|
|
|
|
|
2014-03-28 23:57:44 -04:00
|
|
|
class pqipersongrp;
|
|
|
|
|
2012-06-21 19:23:46 -04:00
|
|
|
// Extern is defined here - as this is bundled with rsconfig.h
|
|
|
|
class p3BandwidthControl;
|
|
|
|
extern p3BandwidthControl *rsBandwidthControl;
|
|
|
|
|
|
|
|
|
|
|
|
class BwCtrlData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BwCtrlData()
|
|
|
|
:mRateUpdateTs(0), mAllocated(0), mLastSend(0), mAllowedOut(0), mLastRecvd(0)
|
|
|
|
{ return; }
|
|
|
|
|
|
|
|
/* Rates are floats in KB/s */
|
|
|
|
RsBwRates mRates;
|
|
|
|
time_t mRateUpdateTs;
|
|
|
|
|
|
|
|
/* these are integers (B/s) */
|
|
|
|
uint32_t mAllocated;
|
|
|
|
time_t mLastSend;
|
|
|
|
|
|
|
|
uint32_t mAllowedOut;
|
|
|
|
time_t mLastRecvd;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//!The RS bandwidth Control Service.
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Exchange packets to regulate p2p bandwidth.
|
|
|
|
*
|
|
|
|
* Sadly this has to be strongly integrated into pqi, with ref to pqipersongrp.
|
|
|
|
*/
|
|
|
|
|
2014-03-28 23:57:44 -04:00
|
|
|
class p3BandwidthControl: public p3Service, public pqiServiceMonitor
|
2012-06-21 19:23:46 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
p3BandwidthControl(pqipersongrp *pg);
|
2014-03-21 23:53:44 -04:00
|
|
|
virtual RsServiceInfo getServiceInfo();
|
2012-06-21 19:23:46 -04:00
|
|
|
|
|
|
|
/***** overloaded from RsBanList *****/
|
|
|
|
|
|
|
|
|
|
|
|
/***** overloaded from p3Service *****/
|
|
|
|
/*!
|
|
|
|
* This retrieves all BwCtrl items
|
|
|
|
*/
|
|
|
|
virtual int tick();
|
|
|
|
virtual int status();
|
|
|
|
|
|
|
|
|
|
|
|
/***** for RsConfig (not directly overloaded) ****/
|
|
|
|
|
|
|
|
virtual int getTotalBandwidthRates(RsConfigDataRates &rates);
|
2014-03-17 16:56:06 -04:00
|
|
|
virtual int getAllBandwidthRates(std::map<RsPeerId, RsConfigDataRates> &ratemap);
|
2012-06-21 19:23:46 -04:00
|
|
|
|
|
|
|
|
2014-10-31 17:24:42 -04:00
|
|
|
virtual int ExtractOutQueueStatistics(OutQueueStatistics& stats) ;
|
2012-06-21 19:23:46 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Interface stuff.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*************** pqiMonitor callback ***********************/
|
2014-03-28 23:57:44 -04:00
|
|
|
virtual void statusChange(const std::list<pqiServicePeer> &plist);
|
2012-06-21 19:23:46 -04:00
|
|
|
|
|
|
|
|
|
|
|
/************* from p3Config *******************/
|
|
|
|
//virtual RsSerialiser *setupSerialiser() ;
|
|
|
|
//virtual bool saveList(bool& cleanup, std::list<RsItem*>&) ;
|
|
|
|
//virtual void saveDone();
|
|
|
|
//virtual bool loadList(std::list<RsItem*>& load) ;
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
bool checkAvailableBandwidth();
|
|
|
|
bool processIncoming();
|
|
|
|
|
|
|
|
pqipersongrp *mPg;
|
|
|
|
|
|
|
|
RsMutex mBwMtx;
|
|
|
|
|
|
|
|
int printRateInfo_locked(std::ostream &out);
|
|
|
|
|
|
|
|
time_t mLastCheck;
|
|
|
|
|
|
|
|
RsBwRates mTotalRates;
|
2014-03-17 16:56:06 -04:00
|
|
|
std::map<RsPeerId, BwCtrlData> mBwMap;
|
2012-06-21 19:23:46 -04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SERVICE_RSBANDWIDTH_CONTROL_HEADER
|