mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-07 16:45:11 -04:00
merged remaining of v0.6-IdCleaning branch (7180->7213) to incorporate global router stuff in trunk
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7214 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
0e6302ac6a
commit
1042744685
53 changed files with 2387 additions and 1904 deletions
|
@ -32,8 +32,7 @@ GRouterMatrix::GRouterMatrix()
|
|||
_proba_need_updating = true ;
|
||||
}
|
||||
|
||||
bool GRouterMatrix::addRoutingClue( const GRouterKeyId& key_id,const GRouterServiceId& sid,float distance,
|
||||
const std::string& desc_string,const RsPeerId& source_friend)
|
||||
bool GRouterMatrix::addRoutingClue(const GRouterKeyId& key_id,const RsPeerId& source_friend,float weight)
|
||||
{
|
||||
// 1 - get the friend index.
|
||||
//
|
||||
|
@ -44,7 +43,7 @@ bool GRouterMatrix::addRoutingClue( const GRouterKeyId& key_id,const GRouterServ
|
|||
time_t now = time(NULL) ;
|
||||
|
||||
RoutingMatrixHitEntry rc ;
|
||||
rc.weight = 1.0f / (1.0f + distance) ;
|
||||
rc.weight = weight ;
|
||||
rc.time_stamp = now ;
|
||||
rc.friend_id = fid ;
|
||||
|
||||
|
@ -103,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;
|
||||
|
@ -130,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
|
||||
//
|
||||
|
@ -144,34 +151,41 @@ 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) ;
|
||||
|
||||
if(it2 == _time_combined_hits.end())
|
||||
{
|
||||
std::cerr << "GRouterMatrix::computeRoutingProbabilities(): key id " << key_id.toStdString() << " does not exist!" << std::endl;
|
||||
// The key is not known. In this case, we return equal probabilities for all peers.
|
||||
//
|
||||
float p = 1.0f / friends.size() ;
|
||||
|
||||
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 ;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue