2018-05-29 15:54:27 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
* libretroshare/src/services: p3bwctrl.h *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
|
|
|
* Copyright 2012 by Robert Fernie <retroshare@lunamutt.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2012-06-21 19:23:46 -04:00
|
|
|
#ifndef SERVICE_RSBANDWIDTH_CONTROL_HEADER
|
|
|
|
#define SERVICE_RSBANDWIDTH_CONTROL_HEADER
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
|
2017-04-18 15:11:37 -04:00
|
|
|
#include "rsitems/rsbwctrlitems.h"
|
2012-06-21 19:23:46 -04:00
|
|
|
#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;
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t mRateUpdateTs;
|
2012-06-21 19:23:46 -04:00
|
|
|
|
|
|
|
/* these are integers (B/s) */
|
|
|
|
uint32_t mAllocated;
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t mLastSend;
|
2012-06-21 19:23:46 -04:00
|
|
|
|
|
|
|
uint32_t mAllowedOut;
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t mLastRecvd;
|
2012-06-21 19:23:46 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//!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:
|
2017-07-28 13:16:32 -04:00
|
|
|
explicit 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
|
|
|
|
|
|
|
|
2016-03-19 11:39:53 -04:00
|
|
|
virtual int ExtractTrafficInfo(std::list<RSTrafficClue> &out_stats, std::list<RSTrafficClue> &in_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) ;
|
|
|
|
|
2015-07-12 00:04:18 -04:00
|
|
|
private:
|
2012-06-21 19:23:46 -04:00
|
|
|
|
|
|
|
bool checkAvailableBandwidth();
|
|
|
|
bool processIncoming();
|
|
|
|
|
|
|
|
pqipersongrp *mPg;
|
|
|
|
|
|
|
|
RsMutex mBwMtx;
|
|
|
|
|
|
|
|
int printRateInfo_locked(std::ostream &out);
|
|
|
|
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t mLastCheck;
|
2012-06-21 19:23:46 -04:00
|
|
|
|
|
|
|
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
|