2007-11-14 22:18:48 -05:00
|
|
|
/*
|
|
|
|
* "$Id: pqihandler.h,v 1.10 2007-03-31 09:41:32 rmf24 Exp $"
|
|
|
|
*
|
|
|
|
* 3P/PQI network interface for RetroShare.
|
|
|
|
*
|
|
|
|
* Copyright 2004-2006 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 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 MRK_PQI_HANDLER_HEADER
|
|
|
|
#define MRK_PQI_HANDLER_HEADER
|
|
|
|
|
|
|
|
#include "pqi/pqi.h"
|
2011-09-04 16:01:30 -04:00
|
|
|
#include "pqi/pqiqos.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-11-22 08:15:07 -05:00
|
|
|
#include "util/rsthreads.h"
|
2014-03-17 16:56:06 -04:00
|
|
|
#include "retroshare/rstypes.h"
|
2014-10-31 17:24:42 -04:00
|
|
|
#include "retroshare/rsconfig.h"
|
2008-11-22 08:15:07 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
#include <map>
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
class SearchModule
|
|
|
|
{
|
|
|
|
public:
|
2016-06-11 17:54:11 -04:00
|
|
|
SearchModule() : pqi(NULL) {}
|
2016-06-08 22:44:28 -04:00
|
|
|
|
|
|
|
RsPeerId peerid ;
|
|
|
|
PQInterface *pqi;
|
2007-11-14 22:18:48 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// Presents a P3 Face to the world!
|
|
|
|
// and funnels data through to a PQInterface.
|
|
|
|
//
|
2013-10-01 06:11:34 -04:00
|
|
|
class pqihandler: public P3Interface, public pqiPublisher
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
public:
|
2015-06-17 04:49:43 -04:00
|
|
|
pqihandler();
|
2013-10-01 06:11:34 -04:00
|
|
|
|
|
|
|
/**** Overloaded from pqiPublisher ****/
|
|
|
|
virtual bool sendItem(RsRawItem *item)
|
|
|
|
{
|
|
|
|
return SendRsRawItem(item);
|
|
|
|
}
|
|
|
|
|
2011-09-04 16:01:30 -04:00
|
|
|
bool AddSearchModule(SearchModule *mod);
|
|
|
|
bool RemoveSearchModule(SearchModule *mod);
|
|
|
|
|
|
|
|
// Rest of P3Interface
|
|
|
|
virtual int tick();
|
|
|
|
virtual int status();
|
|
|
|
|
|
|
|
// Service Data Interface
|
|
|
|
virtual int SendRsRawItem(RsRawItem *);
|
2015-04-24 05:29:40 -04:00
|
|
|
#ifdef TO_BE_REMOVED
|
2011-09-04 16:01:30 -04:00
|
|
|
virtual RsRawItem *GetRsRawItem();
|
2015-04-24 05:29:40 -04:00
|
|
|
#endif
|
2011-09-04 16:01:30 -04:00
|
|
|
|
|
|
|
// rate control.
|
2016-06-11 17:54:11 -04:00
|
|
|
//void setMaxRate(const RsPeerId& pid,bool in, uint32_t val_kBs);
|
2011-09-04 16:01:30 -04:00
|
|
|
void setMaxRate(bool in, float val);
|
|
|
|
float getMaxRate(bool in);
|
2016-06-08 22:44:28 -04:00
|
|
|
|
|
|
|
void setMaxRates(const RsPeerId& pid,bool in,float val) ;
|
|
|
|
float getMaxRates(const RsPeerId& pid,bool in) ;
|
2011-09-04 16:01:30 -04:00
|
|
|
|
|
|
|
void getCurrentRates(float &in, float &out);
|
|
|
|
|
2012-06-21 19:23:46 -04:00
|
|
|
// TESTING INTERFACE.
|
2014-03-17 16:56:06 -04:00
|
|
|
int ExtractRates(std::map<RsPeerId, RsBwRates> &ratemap, RsBwRates &totals);
|
2016-06-08 22:44:28 -04:00
|
|
|
int ExtractTrafficInfo(std::list<RSTrafficClue> &out_lst, std::list<RSTrafficClue> &in_lst);
|
2012-06-21 19:23:46 -04:00
|
|
|
|
2015-07-12 00:04:18 -04:00
|
|
|
protected:
|
2011-09-04 16:01:30 -04:00
|
|
|
/* check to be overloaded by those that can
|
|
|
|
* generates warnings otherwise
|
|
|
|
*/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2015-06-17 05:07:45 -04:00
|
|
|
int locked_HandleRsItem(RsItem *ns, uint32_t& size);
|
2011-09-04 16:01:30 -04:00
|
|
|
bool queueOutRsItem(RsItem *) ;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2015-04-24 05:29:40 -04:00
|
|
|
#ifdef TO_BE_REMOVED
|
|
|
|
int locked_GetItems();
|
2011-09-04 16:01:30 -04:00
|
|
|
void locked_SortnStoreItem(RsItem *item);
|
2015-04-24 05:29:40 -04:00
|
|
|
#endif
|
2008-11-22 08:15:07 -05:00
|
|
|
|
2011-09-04 16:01:30 -04:00
|
|
|
RsMutex coreMtx; /* MUTEX */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
std::map<RsPeerId, SearchModule *> mods;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2013-10-01 04:11:15 -04:00
|
|
|
std::list<RsItem *> in_service;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2011-09-04 16:01:30 -04:00
|
|
|
// rate control.
|
|
|
|
int UpdateRates();
|
|
|
|
void locked_StoreCurrentRates(float in, float out);
|
|
|
|
|
|
|
|
float rateIndiv_in;
|
|
|
|
float rateIndiv_out;
|
|
|
|
float rateMax_in;
|
|
|
|
float rateMax_out;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-09-04 16:01:30 -04:00
|
|
|
float rateTotal_in;
|
|
|
|
float rateTotal_out;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-09-04 16:01:30 -04:00
|
|
|
uint32_t nb_ticks ;
|
|
|
|
time_t last_m ;
|
2016-06-11 18:07:57 -04:00
|
|
|
time_t mLastRateCapUpdate ;
|
2011-09-04 16:01:30 -04:00
|
|
|
float ticks_per_sec ;
|
2007-11-14 22:18:48 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
inline void pqihandler::setMaxRate(bool in, float val)
|
|
|
|
{
|
2008-11-22 08:15:07 -05:00
|
|
|
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
2007-11-14 22:18:48 -05:00
|
|
|
if (in)
|
|
|
|
rateMax_in = val;
|
|
|
|
else
|
|
|
|
rateMax_out = val;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline float pqihandler::getMaxRate(bool in)
|
|
|
|
{
|
2008-11-22 08:15:07 -05:00
|
|
|
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
2007-11-14 22:18:48 -05:00
|
|
|
if (in)
|
|
|
|
return rateMax_in;
|
|
|
|
else
|
|
|
|
return rateMax_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MRK_PQI_HANDLER_HEADER
|