From d739fb2c52a0b3ca100edec251a9ef2b1aadc040 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 25 Mar 2014 20:37:42 +0000 Subject: [PATCH] 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 --- libretroshare/src/grouter/grouteritems.h | 3 +- libretroshare/src/grouter/groutermatrix.cc | 28 +- libretroshare/src/grouter/groutermatrix.h | 11 +- libretroshare/src/grouter/groutertypes.h | 10 - libretroshare/src/grouter/p3grouter.cc | 89 ++++- libretroshare/src/grouter/p3grouter.h | 15 +- .../src/{grouter => retroshare}/rsgrouter.h | 62 +-- .../gui/settings/GlobalRouterStatistics.cpp | 361 ++++++++++++++++++ .../src/gui/settings/GlobalRouterStatistics.h | 70 ++++ retroshare-gui/src/retroshare-gui.pro | 2 + 10 files changed, 574 insertions(+), 77 deletions(-) rename libretroshare/src/{grouter => retroshare}/rsgrouter.h (62%) create mode 100644 retroshare-gui/src/gui/settings/GlobalRouterStatistics.cpp create mode 100644 retroshare-gui/src/gui/settings/GlobalRouterStatistics.h diff --git a/libretroshare/src/grouter/grouteritems.h b/libretroshare/src/grouter/grouteritems.h index a15592eed..67b4b4198 100644 --- a/libretroshare/src/grouter/grouteritems.h +++ b/libretroshare/src/grouter/grouteritems.h @@ -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 diff --git a/libretroshare/src/grouter/groutermatrix.cc b/libretroshare/src/grouter/groutermatrix.cc index acda1074f..6647428fb 100644 --- a/libretroshare/src/grouter/groutermatrix.cc +++ b/libretroshare/src/grouter/groutermatrix.cc @@ -102,6 +102,14 @@ uint32_t GRouterMatrix::getFriendId(const RsPeerId& source_friend) return it->second ; } +void GRouterMatrix::getListOfKnownKeys(std::vector& key_ids) const +{ + key_ids.clear() ; + + for(std::map >::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& friends, std::map& probas) const +bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, const std::vector& friends, std::vector& 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 >::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::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& w(it2->second) ; - for(std::list::const_iterator it(friends.begin());it!=friends.end();++it) + for(uint32_t i=0;i= 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::iterator it(probas.begin());it!=probas.end();++it) - it->second /= total ; + for(int i=0;i #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& friends, std::map& probas) const ; + bool computeRoutingProbabilities(const GRouterKeyId& id, const std::vector& friends, std::vector& 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& items) ; + bool loadList(std::list& items) ; + // Dump info in terminal. // void debugDump() const ; - - bool saveList(std::list& items) ; - bool loadList(std::list& items) ; + void getListOfKnownKeys(std::vector& key_ids) const ; private: // returns the friend id, possibly creating a new id. diff --git a/libretroshare/src/grouter/groutertypes.h b/libretroshare/src/grouter/groutertypes.h index 8aaf52779..7d872ffea 100644 --- a/libretroshare/src/grouter/groutertypes.h +++ b/libretroshare/src/grouter/groutertypes.h @@ -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: diff --git a/libretroshare/src/grouter/p3grouter.cc b/libretroshare/src/grouter/p3grouter.cc index 67b1b7767..d5fae3e4d 100644 --- a/libretroshare/src/grouter/p3grouter.cc +++ b/libretroshare/src/grouter/p3grouter.cc @@ -306,6 +306,10 @@ void p3GRouter::routePendingObjects() mLinkMgr->getOnlineList(lst) ; RsPeerId own_id( mLinkMgr->getOwnId() ); + std::vector pids ; + for(std::list::const_iterator it(lst.begin());it!=lst.end();++it) + pids.push_back(*it) ; + for(std::map::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 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 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 routing_friends = computeRoutingFriends(probas,N) ; + std::set routing_friend_indices = computeRoutingFriends(pids,probas,N) ; std::cerr << " Routing statistics: " << std::endl; // Actually send the item. - for(std::set::const_iterator its(routing_friends.begin());its!=routing_friends.end();++its) + for(std::set::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& probas,uint32_t dist) +uint32_t p3GRouter::computeBranchingFactor(const std::vector& friends,const std::vector& probas,uint32_t dist) { // This should be made a bit more adaptive ;-) // return 1 ; } -std::set p3GRouter::computeRoutingFriends(const std::map& probas,uint32_t N) +std::set p3GRouter::computeRoutingFriends(const std::vector& pids,const std::vector& probas,uint32_t N) { // We draw N friends according to the routing probabilitites that are passed as parameter. // - std::set res ; + std::set 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& items) return true ; } +bool p3GRouter::getRoutingMatrixInfo(RsGRouter::GRouterRoutingMatrixInfo& info) +{ + info.per_friend_probabilities.clear() ; + info.friend_ids.clear() ; + info.published_keys.clear() ; + + std::list ids ; + mLinkMgr->getOnlineList(ids) ; + + RsStackMutex mtx(grMtx) ; + + info.published_keys = _owned_key_ids ; + + for(std::list::const_iterator it(ids.begin());it!=ids.end();++it) + info.friend_ids.push_back(*it) ; + + std::vector known_keys ; + std::vector probas ; + _routing_matrix.getListOfKnownKeys(known_keys) ; + + for(uint32_t i=0;i& infos) +{ + RsStackMutex mtx(grMtx) ; + infos.clear() ; + + for(std::map::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; diff --git a/libretroshare/src/grouter/p3grouter.h b/libretroshare/src/grouter/p3grouter.h index 462c2c196..b7800f0f0 100644 --- a/libretroshare/src/grouter/p3grouter.h +++ b/libretroshare/src/grouter/p3grouter.h @@ -28,15 +28,16 @@ #include #include -#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& info) ; protected: //===================================================// @@ -135,8 +136,8 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config // utility functions // - static uint32_t computeBranchingFactor(const std::map& probas,uint32_t dist) ; - static std::set computeRoutingFriends(const std::map& probas,uint32_t N) ; + static uint32_t computeBranchingFactor(const std::vector& friends,const std::vector& probas,uint32_t dist) ; + static std::set computeRoutingFriends(const std::vector& friends,const std::vector& probas,uint32_t N) ; static uint32_t computeRandomDistanceIncrement(const RsPeerId& pid,const GRouterKeyId& destination_id) ; //===================================================// diff --git a/libretroshare/src/grouter/rsgrouter.h b/libretroshare/src/retroshare/rsgrouter.h similarity index 62% rename from libretroshare/src/grouter/rsgrouter.h rename to libretroshare/src/retroshare/rsgrouter.h index e0f4c3c01..facc15681 100644 --- a/libretroshare/src/grouter/rsgrouter.h +++ b/libretroshare/src/retroshare/rsgrouter.h @@ -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 > per_friend_probabilities ; - - // List of own published keys, with associated service ID - // - std::map 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 > per_friend_probabilities ; + + // List of friend ids in the same order. Should roughly correspond to the friends that are currently online. + // + std::vector friend_ids ; + + // List of own published keys, with associated service ID + // + std::map published_keys ; + }; + //===================================================// // Debugging info // //===================================================// - virtual bool getRoutingCacheInfo(RoutingCacheInfo& info) =0; - virtual bool getRoutingMatrixInfo(RoutingMatrixInfo& info) =0; + virtual bool getRoutingCacheInfo(std::vector& 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 diff --git a/retroshare-gui/src/gui/settings/GlobalRouterStatistics.cpp b/retroshare-gui/src/gui/settings/GlobalRouterStatistics.cpp new file mode 100644 index 000000000..a277067f0 --- /dev/null +++ b/retroshare-gui/src/gui/settings/GlobalRouterStatistics.cpp @@ -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 +#include +#include + +#include +#include +#include + +#include +#include +#include "GlobalRouterStatistics.h" + +#include "gui/settings/rsharesettings.h" + +static const int MAX_TUNNEL_REQUESTS_DISPLAY = 10 ; + +// class TRHistogram +// { +// public: +// TRHistogram(const std::vector& 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 > hits ; +// std::map > depths ; +// std::map >::iterator it ; +// +// int max_hits = 1; +// int max_depth = 1; +// +// for(uint32_t i=0;i<_infos.size();++i) +// { +// std::vector& h(hits[_infos[i].source_peer_id]) ; +// std::vector& 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;ifillRect(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;idrawText(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;ifillRect(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;idrawText(ox+i*cellx,oy+(p+1)*celly+4,QString::number(i)) ; +// for(int i=0;idrawText(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& _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 names ; + + std::map::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 +#include +#include + +#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 ; +}; + diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index 1e08f7ec5..a148f20fd 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -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 \