added info functions in grouter and basic widget to display routage info in settings

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-IdCleaning@7207 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-03-25 20:37:42 +00:00
parent d2ab6cc6ab
commit d739fb2c52
10 changed files with 574 additions and 77 deletions

View file

@ -27,7 +27,8 @@
#include "serialiser/rsserial.h"
#include "retroshare/rstypes.h"
#include "rsgrouter.h"
#include "retroshare/rsgrouter.h"
#include "p3grouter.h"
// To be put in serialiser/rsserviceids.h

View file

@ -102,6 +102,14 @@ uint32_t GRouterMatrix::getFriendId(const RsPeerId& source_friend)
return it->second ;
}
void GRouterMatrix::getListOfKnownKeys(std::vector<GRouterKeyId>& key_ids) const
{
key_ids.clear() ;
for(std::map<GRouterKeyId,std::vector<float> >::const_iterator it(_time_combined_hits.begin());it!=_time_combined_hits.end();++it)
key_ids.push_back(it->first) ;
}
void GRouterMatrix::debugDump() const
{
std::cerr << " Proba needs up: " << _proba_need_updating << std::endl;
@ -129,7 +137,7 @@ void GRouterMatrix::debugDump() const
}
}
bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, const std::list<RsPeerId>& friends, std::map<RsPeerId,float>& probas) const
bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, const std::vector<RsPeerId>& friends, std::vector<float>& probas) const
{
// Routing probabilities are computed according to routing clues
//
@ -143,7 +151,7 @@ bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, cons
if(_proba_need_updating)
std::cerr << "GRouterMatrix::computeRoutingProbabilities(): matrix is not up to date. Not a real problem, but still..." << std::endl;
probas.clear() ;
probas.resize(friends.size(),0.0f) ;
float total = 0.0f ;
std::map<GRouterKeyId,std::vector<float> >::const_iterator it2 = _time_combined_hits.find(key_id) ;
@ -154,30 +162,30 @@ bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, cons
//
float p = 1.0f / friends.size() ;
for(std::list<RsPeerId>::const_iterator it(friends.begin());it!=friends.end();++it)
probas[*it] = p ;
probas.clear() ;
probas.resize(friends.size(),p) ;
std::cerr << "GRouterMatrix::computeRoutingProbabilities(): key id " << key_id.toStdString() << " does not exist! Returning uniform probabilities." << std::endl;
return false ;
}
const std::vector<float>& w(it2->second) ;
for(std::list<RsPeerId>::const_iterator it(friends.begin());it!=friends.end();++it)
for(uint32_t i=0;i<friends.size();++i)
{
uint32_t findex = getFriendId_const(*it) ;
uint32_t findex = getFriendId_const(friends[i]) ;
if(findex >= w.size())
probas[*it] = 0.0f ;
probas[i] = 0.0f ;
else
{
probas[*it] = w[findex] ;
probas[i] = w[findex] ;
total += w[findex] ;
}
}
if(total > 0.0f)
for(std::map<RsPeerId,float>::iterator it(probas.begin());it!=probas.end();++it)
it->second /= total ;
for(int i=0;i<friends.size();++i)
probas[i] /= total ;
return true ;
}

View file

@ -28,8 +28,8 @@
#include <list>
#include "pgp/rscertificate.h"
#include "retroshare/rsgrouter.h"
#include "groutertypes.h"
#include "rsgrouter.h"
class RsItem ;
@ -51,7 +51,7 @@ class GRouterMatrix
// the computation accounts for the time at which the info was received and the
// weight of each routing hit record.
//
bool computeRoutingProbabilities(const GRouterKeyId& id, const std::list<RsPeerId>& friends, std::map<RsPeerId,float>& probas) const ;
bool computeRoutingProbabilities(const GRouterKeyId& id, const std::vector<RsPeerId>& friends, std::vector<float>& probas) const ;
// Update routing probabilities for each key, accounting for all received events, but without
// activity information
@ -62,12 +62,13 @@ class GRouterMatrix
//
bool addRoutingClue(const GRouterKeyId& id,const RsPeerId& source_friend,float weight) ;
bool saveList(std::list<RsItem*>& items) ;
bool loadList(std::list<RsItem*>& items) ;
// Dump info in terminal.
//
void debugDump() const ;
bool saveList(std::list<RsItem*>& items) ;
bool loadList(std::list<RsItem*>& items) ;
void getListOfKnownKeys(std::vector<GRouterKeyId>& key_ids) const ;
private:
// returns the friend id, possibly creating a new id.

View file

@ -58,16 +58,6 @@ static const uint32_t RS_GROUTER_ROUTING_STATE_PEND = 0x0001 ; // item is pendi
static const uint32_t RS_GROUTER_ROUTING_STATE_SENT = 0x0002 ; // item is sent. Waiting for answer
static const uint32_t RS_GROUTER_ROUTING_STATE_ARVD = 0x0003 ; // item is at destination. The cache only holds it to avoid duplication.
class GRouterPublishedKeyInfo
{
public:
GRouterServiceId service_id ;
std::string description_string ;
PGPFingerprintType fpr ;
time_t last_published_time ;
time_t validity_time ;
};
class FriendTrialRecord
{
public:

View file

@ -306,6 +306,10 @@ void p3GRouter::routePendingObjects()
mLinkMgr->getOnlineList(lst) ;
RsPeerId own_id( mLinkMgr->getOwnId() );
std::vector<RsPeerId> pids ;
for(std::list<RsPeerId>::const_iterator it(lst.begin());it!=lst.end();++it)
pids.push_back(*it) ;
for(std::map<GRouterMsgPropagationId, GRouterRoutingInfo>::iterator it(_pending_messages.begin());it!=_pending_messages.end();)
if((it->second.status_flags == RS_GROUTER_ROUTING_STATE_PEND) || (it->second.status_flags == RS_GROUTER_ROUTING_STATE_SENT && it->second.tried_friends.front().time_stamp+RS_GROUTER_ROUTING_WAITING_TIME < now))
{
@ -317,27 +321,27 @@ void p3GRouter::routePendingObjects()
std::cerr << " Dist : " << it->second.data_item->randomized_distance<< std::endl;
std::cerr << " Probabilities: " << std::endl;
std::map<RsPeerId,float> probas ; // friends probabilities for online friend list.
RsPeerId routed_friend ; // friend chosen for the next hop
bool should_remove = false ; // should we remove this from the map?
std::vector<float> probas ; // friends probabilities for online friend list.
RsPeerId routed_friend ; // friend chosen for the next hop
bool should_remove = false ; // should we remove this from the map?
// Retrieve probabilities for this key. This call always succeeds. If no route is known, all probabilities become equal.
//
_routing_matrix.computeRoutingProbabilities(it->second.data_item->destination_key, lst, probas) ;
_routing_matrix.computeRoutingProbabilities(it->second.data_item->destination_key, pids, probas) ;
// Compute the branching factor.
int N = computeBranchingFactor(probas,it->second.data_item->randomized_distance) ;
int N = computeBranchingFactor(pids,probas,it->second.data_item->randomized_distance) ;
// Now use this to select N random peers according to the given probabilities
std::set<RsPeerId> routing_friends = computeRoutingFriends(probas,N) ;
std::set<uint32_t> routing_friend_indices = computeRoutingFriends(pids,probas,N) ;
std::cerr << " Routing statistics: " << std::endl;
// Actually send the item.
for(std::set<RsPeerId>::const_iterator its(routing_friends.begin());its!=routing_friends.end();++its)
for(std::set<uint32_t>::const_iterator its(routing_friend_indices.begin());its!=routing_friend_indices.end();++its)
{
std::cerr << " Friend : " << (*its) << std::endl;
@ -347,7 +351,7 @@ void p3GRouter::routePendingObjects()
// update cache entry
FriendTrialRecord ftr ;
ftr.time_stamp = now ;
ftr.friend_id = routed_friend ;
ftr.friend_id = pids[*its];
ftr.probability = probas[*its] ;
ftr.nb_friends = probas.size() ;
@ -358,8 +362,8 @@ void p3GRouter::routePendingObjects()
std::cerr << " Sending..." << std::endl;
// send
new_item->PeerId(*its) ;
new_item->randomized_distance += computeRandomDistanceIncrement(*its,new_item->destination_key) ;
new_item->PeerId(pids[*its]) ;
new_item->randomized_distance += computeRandomDistanceIncrement(pids[*its],new_item->destination_key) ;
sendItem(new_item) ;
}
@ -406,30 +410,31 @@ uint32_t p3GRouter::computeRandomDistanceIncrement(const RsPeerId& pid,const GRo
return RsDirUtil::sha1sum(tmpmem,total_size).toByteArray()[5] ;
}
uint32_t p3GRouter::computeBranchingFactor(const std::map<RsPeerId,float>& probas,uint32_t dist)
uint32_t p3GRouter::computeBranchingFactor(const std::vector<RsPeerId>& friends,const std::vector<float>& probas,uint32_t dist)
{
// This should be made a bit more adaptive ;-)
//
return 1 ;
}
std::set<RsPeerId> p3GRouter::computeRoutingFriends(const std::map<RsPeerId,float>& probas,uint32_t N)
std::set<uint32_t> p3GRouter::computeRoutingFriends(const std::vector<RsPeerId>& pids,const std::vector<float>& probas,uint32_t N)
{
// We draw N friends according to the routing probabilitites that are passed as parameter.
//
std::set<RsPeerId> res ;
std::set<uint32_t> res ;
if(probas.empty())
return res ;
res.insert(probas.begin()->first) ;
res.insert(0) ;
return res ;
}
void p3GRouter::publishKeys()
{
#ifdef SUSPENDED
RsStackMutex mtx(grMtx) ;
// Go through list of published keys
@ -449,14 +454,13 @@ void p3GRouter::publishKeys()
std::cerr << " Key id : " << it->first.toStdString() << std::endl;
std::cerr << " Service id : " << std::hex << info.service_id << std::dec << std::endl;
std::cerr << " Description : " << info.description_string << std::endl;
std::cerr << " Fingerprint : " << info.fpr.toStdString() << std::endl;
RsGRouterPublishKeyItem item ;
item.diffusion_id = RSRandom::random_u32() ;
item.published_key = it->first ;
item.service_id = info.service_id ;
item.randomized_distance = drand48() ;
item.fingerprint = info.fpr;
item.fingerprint.clear() ; // not set
item.description_string = info.description_string ;
item.PeerId(RsPeerId()) ; // no peer id => key is forwarded to all friends.
@ -466,6 +470,7 @@ void p3GRouter::publishKeys()
info.last_published_time = now ;
}
}
#endif
}
void p3GRouter::locked_forwardKey(const RsGRouterPublishKeyItem& item)
@ -505,7 +510,7 @@ bool p3GRouter::registerKey(const GRouterKeyId& key,const GRouterServiceId& clie
GRouterPublishedKeyInfo info ;
info.service_id = client_id ;
info.description_string = description.substr(0,20);
info.last_published_time = 0 ; // means never published, se it will be re-published soon.
//info.last_published_time = 0 ; // means never published, se it will be re-published soon.
_owned_key_ids[key] = info ;
@ -864,6 +869,54 @@ bool p3GRouter::saveList(bool& cleanup,std::list<RsItem*>& items)
return true ;
}
bool p3GRouter::getRoutingMatrixInfo(RsGRouter::GRouterRoutingMatrixInfo& info)
{
info.per_friend_probabilities.clear() ;
info.friend_ids.clear() ;
info.published_keys.clear() ;
std::list<RsPeerId> ids ;
mLinkMgr->getOnlineList(ids) ;
RsStackMutex mtx(grMtx) ;
info.published_keys = _owned_key_ids ;
for(std::list<RsPeerId>::const_iterator it(ids.begin());it!=ids.end();++it)
info.friend_ids.push_back(*it) ;
std::vector<GRouterKeyId> known_keys ;
std::vector<float> probas ;
_routing_matrix.getListOfKnownKeys(known_keys) ;
for(uint32_t i=0;i<known_keys.size();++i)
{
_routing_matrix.computeRoutingProbabilities(known_keys[i],info.friend_ids,probas) ;
info.per_friend_probabilities[known_keys[i]] = probas ;
}
return true ;
}
bool p3GRouter::getRoutingCacheInfo(std::vector<GRouterRoutingCacheInfo>& infos)
{
RsStackMutex mtx(grMtx) ;
infos.clear() ;
for(std::map<GRouterMsgPropagationId,GRouterRoutingInfo>::const_iterator it(_pending_messages.begin());it!=_pending_messages.end();++it)
{
infos.push_back(GRouterRoutingCacheInfo()) ;
GRouterRoutingCacheInfo& cinfo(infos.back()) ;
cinfo.mid = it->first ;
cinfo.local_origin = it->second.origin ;
cinfo.destination = it->second.data_item->destination_key ;
cinfo.time_stamp = it->second.received_time ;
cinfo.status = it->second.status_flags ;
cinfo.data_size = it->second.data_item->data_size ;
}
return true ;
}
// Dump everything
//
void p3GRouter::debugDump()
@ -880,7 +933,7 @@ void p3GRouter::debugDump()
std::cerr << " Key id : " << it->first.toStdString() << std::endl;
std::cerr << " Service id : " << std::hex << it->second.service_id << std::dec << std::endl;
std::cerr << " Description : " << it->second.description_string << std::endl;
std::cerr << " Last published: " << now - it->second.last_published_time << " secs ago" << std::endl;
//std::cerr << " Last published: " << now - it->second.last_published_time << " secs ago" << std::endl;
}
std::cerr << " Registered services: " << std::endl;

View file

@ -28,15 +28,16 @@
#include <map>
#include <queue>
#include "rsgrouter.h"
#include "retroshare/rsgrouter.h"
#include "retroshare/rstypes.h"
#include "services/p3service.h"
#include "pqi/p3cfgmgr.h"
#include "retroshare/rstypes.h"
#include "groutertypes.h"
#include "groutermatrix.h"
#include "groutercache.h"
#include "grouteritems.h"
//#include "groutercache.h"
// To be put in pqi/p3cfgmgr.h
//
@ -101,7 +102,7 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
// - list of clues/time_stamp for each key.
// - real time routing probabilities
//
virtual bool getRoutingMatrixInfo(RoutingMatrixInfo& info) { return false ;}
virtual bool getRoutingMatrixInfo(GRouterRoutingMatrixInfo& info) ;
// debug info from routing cache
// - Cache Items
@ -111,7 +112,7 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
// * message type
// - Cache state (memory size, etc)
//
virtual bool getRoutingCacheInfo(RoutingCacheInfo& info) { return false ;}
virtual bool getRoutingCacheInfo(std::vector<GRouterRoutingCacheInfo>& info) ;
protected:
//===================================================//
@ -135,8 +136,8 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
// utility functions
//
static uint32_t computeBranchingFactor(const std::map<RsPeerId,float>& probas,uint32_t dist) ;
static std::set<RsPeerId> computeRoutingFriends(const std::map<RsPeerId,float>& probas,uint32_t N) ;
static uint32_t computeBranchingFactor(const std::vector<RsPeerId>& friends,const std::vector<float>& probas,uint32_t dist) ;
static std::set<uint32_t> computeRoutingFriends(const std::vector<RsPeerId>& friends,const std::vector<float>& probas,uint32_t N) ;
static uint32_t computeRandomDistanceIncrement(const RsPeerId& pid,const GRouterKeyId& destination_id) ;
//===================================================//

View file

@ -34,38 +34,49 @@ typedef GRouterKeyIdType GRouterKeyId ; // we use SSLIds, so that it's easier in
class GRouterClientService ;
class RsGRouterGenericDataItem ;
// This is the interface file for the global router service.
//
struct RoutingCacheInfo
{
// what do we want to show here?
// - recently routed items
// - ongoing routing info
// - pending items, waiting for an answer
// -
};
struct RoutingMatrixInfo
{
// Probabilities of reaching a given key for each friend.
// This concerns all known keys.
//
std::map<GRouterKeyId, std::vector<float> > per_friend_probabilities ;
// List of own published keys, with associated service ID
//
std::map<GRouterKeyId, GRouterClientService *> published_keys ;
};
class RsGRouter
{
public:
// This is the interface file for the global router service.
//
struct GRouterRoutingCacheInfo
{
GRouterMsgPropagationId mid ;
RsPeerId local_origin;
GRouterKeyId destination ;
time_t time_stamp ;
uint32_t status ;
uint32_t data_size ;
};
struct GRouterPublishedKeyInfo
{
std::string description_string ;
uint32_t service_id ;
};
struct GRouterRoutingMatrixInfo
{
// Probabilities of reaching a given key for each friend.
// This concerns all known keys.
//
std::map<GRouterKeyId, std::vector<float> > per_friend_probabilities ;
// List of friend ids in the same order. Should roughly correspond to the friends that are currently online.
//
std::vector<RsPeerId> friend_ids ;
// List of own published keys, with associated service ID
//
std::map<GRouterKeyId,GRouterPublishedKeyInfo> published_keys ;
};
//===================================================//
// Debugging info //
//===================================================//
virtual bool getRoutingCacheInfo(RoutingCacheInfo& info) =0;
virtual bool getRoutingMatrixInfo(RoutingMatrixInfo& info) =0;
virtual bool getRoutingCacheInfo(std::vector<GRouterRoutingCacheInfo>& infos) =0;
virtual bool getRoutingMatrixInfo(GRouterRoutingMatrixInfo& info) =0;
// retrieve the routing probabilities
@ -75,7 +86,6 @@ class RsGRouter
virtual void sendData(const GRouterKeyId& destination, RsGRouterGenericDataItem *item) =0;
virtual bool registerKey(const GRouterKeyId& key,const GRouterServiceId& client_id,const std::string& description_string) =0;
};
// To access the GRouter from anywhere

View file

@ -0,0 +1,361 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 20011, RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <iostream>
#include <QTimer>
#include <QObject>
#include <QPainter>
#include <QStylePainter>
#include <QLayout>
#include <retroshare/rsgrouter.h>
#include <retroshare/rspeers.h>
#include "GlobalRouterStatistics.h"
#include "gui/settings/rsharesettings.h"
static const int MAX_TUNNEL_REQUESTS_DISPLAY = 10 ;
// class TRHistogram
// {
// public:
// TRHistogram(const std::vector<TurtleRequestDisplayInfo >& info) :_infos(info) {}
//
// QColor colorScale(float f)
// {
// if(f == 0)
// return QColor::fromHsv(0,0,192) ;
// else
// return QColor::fromHsv((int)((1.0-f)*280),200,255) ;
// }
//
// virtual void draw(QPainter *painter,int& ox,int& oy,const QString& title)
// {
// static const int MaxTime = 61 ;
// static const int MaxDepth = 8 ;
// static const int cellx = 7 ;
// static const int celly = 12 ;
//
// int save_ox = ox ;
// painter->setPen(QColor::fromRgb(0,0,0)) ;
// painter->drawText(2+ox,celly+oy,title) ;
// oy+=2+2*celly ;
//
// if(_infos.empty())
// return ;
//
// ox += 10 ;
// std::map<RsPeerId,std::vector<int> > hits ;
// std::map<RsPeerId,std::vector<int> > depths ;
// std::map<RsPeerId,std::vector<int> >::iterator it ;
//
// int max_hits = 1;
// int max_depth = 1;
//
// for(uint32_t i=0;i<_infos.size();++i)
// {
// std::vector<int>& h(hits[_infos[i].source_peer_id]) ;
// std::vector<int>& g(depths[_infos[i].source_peer_id]) ;
//
// if(h.size() <= _infos[i].age)
// h.resize(MaxTime,0) ;
//
// if(g.empty())
// g.resize(MaxDepth,0) ;
//
// if(_infos[i].age < h.size())
// {
// h[_infos[i].age]++ ;
// if(h[_infos[i].age] > max_hits)
// max_hits = h[_infos[i].age] ;
// }
// if(_infos[i].depth < g.size())
// {
// g[_infos[i].depth]++ ;
//
// if(g[_infos[i].depth] > max_depth)
// max_depth = g[_infos[i].depth] ;
// }
// }
//
// int max_bi = std::max(max_hits,max_depth) ;
// int p=0 ;
//
// for(it=depths.begin();it!=depths.end();++it,++p)
// for(int i=0;i<MaxDepth;++i)
// painter->fillRect(ox+MaxTime*cellx+20+i*cellx,oy+p*celly,cellx,celly,colorScale(it->second[i]/(float)max_bi)) ;
//
// painter->setPen(QColor::fromRgb(0,0,0)) ;
// painter->drawRect(ox+MaxTime*cellx+20,oy,MaxDepth*cellx,p*celly) ;
//
// for(int i=0;i<MaxTime;i+=5)
// painter->drawText(ox+i*cellx,oy+(p+1)*celly+4,QString::number(i)) ;
//
// p=0 ;
// int great_total = 0 ;
//
// for(it=hits.begin();it!=hits.end();++it,++p)
// {
// int total = 0 ;
//
// for(int i=0;i<MaxTime;++i)
// {
// painter->fillRect(ox+i*cellx,oy+p*celly,cellx,celly,colorScale(it->second[i]/(float)max_bi)) ;
// total += it->second[i] ;
// }
//
// painter->setPen(QColor::fromRgb(0,0,0)) ;
// painter->drawText(ox+MaxDepth*cellx+30+(MaxTime+1)*cellx,oy+(p+1)*celly,TurtleRouterStatistics::getPeerName(it->first)) ;
// painter->drawText(ox+MaxDepth*cellx+30+(MaxTime+1)*cellx+120,oy+(p+1)*celly,"("+QString::number(total)+")") ;
// great_total += total ;
// }
//
// painter->drawRect(ox,oy,MaxTime*cellx,p*celly) ;
//
// for(int i=0;i<MaxTime;i+=5)
// painter->drawText(ox+i*cellx,oy+(p+1)*celly+4,QString::number(i)) ;
// for(int i=0;i<MaxDepth;i++)
// painter->drawText(ox+MaxTime*cellx+20+i*cellx,oy+(p+1)*celly+4,QString::number(i)) ;
// painter->setPen(QColor::fromRgb(255,130,80)) ;
// painter->drawText(ox+MaxDepth*cellx+30+(MaxTime+1)*cellx+120,oy+(p+1)*celly+4,"("+QString::number(great_total)+")");
//
// oy += (p+1)*celly+6 ;
//
// painter->setPen(QColor::fromRgb(0,0,0)) ;
// painter->drawText(ox,oy+celly,"("+QApplication::translate("TurtleRouterStatistics", "Age in seconds")+")");
// painter->drawText(ox+MaxTime*cellx+20,oy+celly,"("+QApplication::translate("TurtleRouterStatistics", "Depth")+")");
//
// painter->drawText(ox+MaxDepth*cellx+30+(MaxTime+1)*cellx+120,oy+celly,"("+QApplication::translate("TurtleRouterStatistics", "total")+")");
//
// oy += 3*celly ;
//
// // now, draw a scale
//
// int last_hts = -1 ;
// int cellid = 0 ;
//
// for(int i=0;i<=10;++i)
// {
// int hts = (int)(max_bi*i/10.0) ;
//
// if(hts > last_hts)
// {
// painter->fillRect(ox+cellid*(cellx+22),oy,cellx,celly,colorScale(i/10.0f)) ;
// painter->setPen(QColor::fromRgb(0,0,0)) ;
// painter->drawRect(ox+cellid*(cellx+22),oy,cellx,celly) ;
// painter->drawText(ox+cellid*(cellx+22)+cellx+4,oy+celly,QString::number(hts)) ;
// last_hts = hts ;
// ++cellid ;
// }
// }
//
// oy += celly*2 ;
//
// ox = save_ox ;
// }
//
// private:
// const std::vector<TurtleRequestDisplayInfo>& _infos ;
// };
GlobalRouterStatistics::GlobalRouterStatistics(QWidget *parent)
: RsAutoUpdatePage(2000,parent)
{
//setupUi(this) ;
m_bProcessSettings = false;
layout()->addWidget( _tst_CW = new GlobalRouterStatisticsWidget() ) ;
//_tunnel_statistics_F->setWidgetResizable(true);
//_tunnel_statistics_F->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
//_tunnel_statistics_F->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
//_tunnel_statistics_F->viewport()->setBackgroundRole(QPalette::NoRole);
//_tunnel_statistics_F->setFrameStyle(QFrame::NoFrame);
//_tunnel_statistics_F->setFocusPolicy(Qt::NoFocus);
// load settings
processSettings(true);
}
GlobalRouterStatistics::~GlobalRouterStatistics()
{
// save settings
processSettings(false);
}
void GlobalRouterStatistics::processSettings(bool bLoad)
{
m_bProcessSettings = true;
Settings->beginGroup(QString("GlobalRouterStatistics"));
if (bLoad) {
// load settings
// state of splitter
//splitter->restoreState(Settings->value("Splitter").toByteArray());
} else {
// save settings
// state of splitter
//Settings->setValue("Splitter", splitter->saveState());
}
Settings->endGroup();
m_bProcessSettings = false;
}
void GlobalRouterStatistics::updateDisplay()
{
//rsTurtle->getInfo(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ;
//_tst_CW->updateTunnelStatistics(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ;
_tst_CW->update();
}
QString GlobalRouterStatistics::getPeerName(const RsPeerId &peer_id)
{
static std::map<RsPeerId, QString> names ;
std::map<RsPeerId,QString>::const_iterator it = names.find(peer_id) ;
if( it != names.end())
return it->second ;
else
{
RsPeerDetails detail ;
if(!rsPeers->getPeerDetails(peer_id,detail))
return tr("Unknown Peer");
return (names[peer_id] = QString::fromUtf8(detail.name.c_str())) ;
}
}
GlobalRouterStatisticsWidget::GlobalRouterStatisticsWidget(QWidget *parent)
: QWidget(parent)
{
maxWidth = 200 ;
maxHeight = 0 ;
}
void GlobalRouterStatisticsWidget::updateGRouterStatistics()
{
// What do we need to draw?
//
// Routing matrix
// Key [][][][][][][][][][]
//
// -> each [] shows a square (one per friend location) that is the routing probabilities for all connected friends
// computed using the "computeRoutingProbabilitites()" method.
//
// Own key ids
// key service id description
//
// Data items
// Msg id Local origin Destination Time Status
//
#ifdef SUSPENDED
static const int cellx = 6 ;
static const int celly = 10+4 ;
QPixmap tmppixmap(maxWidth, maxHeight);
tmppixmap.fill(this, 0, 0);
setFixedHeight(maxHeight);
QPainter painter(&tmppixmap);
painter.initFrom(this);
maxHeight = 500 ;
// std::cerr << "Drawing into pixmap of size " << maxWidth << "x" << maxHeight << std::endl;
// draw...
int ox=5,oy=5 ;
TRHistogram(search_reqs_info).draw(&painter,ox,oy,tr("Search requests repartition") + ":") ;
painter.setPen(QColor::fromRgb(70,70,70)) ;
painter.drawLine(0,oy,maxWidth,oy) ;
oy += celly ;
TRHistogram(tunnel_reqs_info).draw(&painter,ox,oy,tr("Tunnel requests repartition") + ":") ;
// now give information about turtle traffic.
//
TurtleTrafficStatisticsInfo info ;
rsTurtle->getTrafficStatistics(info) ;
painter.setPen(QColor::fromRgb(70,70,70)) ;
painter.drawLine(0,oy,maxWidth,oy) ;
oy += celly ;
painter.drawText(ox,oy+celly,tr("Turtle router traffic")+":") ; oy += celly*2 ;
painter.drawText(ox+2*cellx,oy+celly,tr("Tunnel requests Up")+"\t: " + speedString(info.tr_up_Bps) ) ; oy += celly ;
painter.drawText(ox+2*cellx,oy+celly,tr("Tunnel requests Dn")+"\t: " + speedString(info.tr_dn_Bps) ) ; oy += celly ;
painter.drawText(ox+2*cellx,oy+celly,tr("Incoming file data")+"\t: " + speedString(info.data_dn_Bps) ) ; oy += celly ;
painter.drawText(ox+2*cellx,oy+celly,tr("Outgoing file data")+"\t: " + speedString(info.data_up_Bps) ) ; oy += celly ;
painter.drawText(ox+2*cellx,oy+celly,tr("Forwarded data ")+"\t: " + speedString(info.unknown_updn_Bps) ) ; oy += celly ;
QString prob_string ;
for(uint i=0;i<info.forward_probabilities.size();++i)
prob_string += QString::number(info.forward_probabilities[i],'g',2) + " (" + QString::number(i) + ") " ;
painter.drawText(ox+2*cellx,oy+celly,tr("TR Forward probabilities")+"\t: " + prob_string ) ;
oy += celly ;
oy += celly ;
// update the pixmap
//
pixmap = tmppixmap;
maxHeight = oy ;
#endif
}
QString GlobalRouterStatisticsWidget::speedString(float f)
{
if(f < 1.0f)
return QString("0 B/s") ;
if(f < 1024.0f)
return QString::number((int)f)+" B/s" ;
return QString::number(f/1024.0,'f',2) + " KB/s";
}
void GlobalRouterStatisticsWidget::paintEvent(QPaintEvent */*event*/)
{
QStylePainter(this).drawPixmap(0, 0, pixmap);
}
void GlobalRouterStatisticsWidget::resizeEvent(QResizeEvent *event)
{
QRect TaskGraphRect = geometry();
maxWidth = TaskGraphRect.width();
maxHeight = TaskGraphRect.height() ;
QWidget::resizeEvent(event);
update();
}

View file

@ -0,0 +1,70 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 20011, RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#pragma once
#include <QPoint>
#include <retroshare/rsgrouter.h>
#include <retroshare/rstypes.h>
#include "RsAutoUpdatePage.h"
class GlobalRouterStatisticsWidget ;
class GlobalRouterStatistics: public RsAutoUpdatePage
{
Q_OBJECT
public:
GlobalRouterStatistics(QWidget *parent = NULL) ;
~GlobalRouterStatistics();
// Cache for peer names.
static QString getPeerName(const RsPeerId& peer_id) ;
private:
void processSettings(bool bLoad);
bool m_bProcessSettings;
virtual void updateDisplay() ;
GlobalRouterStatisticsWidget *_tst_CW ;
} ;
class GlobalRouterStatisticsWidget: public QWidget
{
Q_OBJECT
public:
GlobalRouterStatisticsWidget(QWidget *parent = NULL) ;
virtual void paintEvent(QPaintEvent *event) ;
virtual void resizeEvent(QResizeEvent *event);
void updateGRouterStatistics();
private:
static QString speedString(float f) ;
QPixmap pixmap ;
int maxWidth,maxHeight ;
};

View file

@ -388,6 +388,7 @@ HEADERS += rshare.h \
gui/msgs/MessageUserNotify.h \
gui/images/retroshare_win.rc.h \
gui/settings/rsharesettings.h \
gui/settings/GlobalRouterStatistics.h \
gui/settings/RsharePeerSettings.h \
gui/settings/rsettings.h \
gui/settings/rsettingswin.h \
@ -744,6 +745,7 @@ SOURCES += main.cpp \
gui/style/StyleDialog.cpp \
gui/settings/rsharesettings.cpp \
gui/settings/RsharePeerSettings.cpp \
gui/settings/GlobalRouterStatistics.cpp \
gui/settings/rsettings.cpp \
gui/settings/rsettingswin.cpp \
gui/settings/GeneralPage.cpp \