mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
merge of branch v0.6-idclean 7180
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7187 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
7815efb16f
commit
0f29d28b1b
397 changed files with 6503 additions and 5702 deletions
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* libretroshare/src/services: grouterclient.h
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2013 by Cyril Soler
|
||||
*
|
||||
* 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 "csoler@users.sourceforge.net".
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Derive from this class to be a client for the global router. Typical potential clients are:
|
||||
// - the messaging system
|
||||
//
|
||||
class GRouterClient
|
||||
{
|
||||
public:
|
||||
virtual void receiveLongDistanceItem(void *data,uint32_t size) = 0 ;
|
||||
};
|
||||
|
65
libretroshare/src/grouter/grouterclientservice.h
Normal file
65
libretroshare/src/grouter/grouterclientservice.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* libretroshare/src/grouter: grouterclientservice.h
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* Copyright 2013 by Cyril Soler
|
||||
*
|
||||
* 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 "csoler@users.sourceforge.net".
|
||||
*
|
||||
*/
|
||||
|
||||
// This class is the parent class for any service that will use the global router to distribute its packets.
|
||||
// Typical representative clients include:
|
||||
//
|
||||
// p3msgservice: sends distant messages and advertise messaging keys
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include <grouter/grouteritems.h>
|
||||
|
||||
class RsItem ;
|
||||
|
||||
class GRouterClientService
|
||||
{
|
||||
public:
|
||||
// This method is called by the turtle router to send data that comes out of a turtle tunnel.
|
||||
// The turtle router stays responsible for the memory management of data. Most of the time the
|
||||
// data chunk is a serialized item to be de-serialized by the client service.
|
||||
//
|
||||
// Parameters:
|
||||
// item : global router item. Handled by the client service.
|
||||
// destination_key : key that is associated with this item. Can be useful for the client.
|
||||
//
|
||||
// GRouter stays owner of the item, so the client should not delete it!
|
||||
//
|
||||
virtual void receiveGRouterData(RsGRouterGenericDataItem * /*item*/,const GRouterKeyId& destination_key)
|
||||
{
|
||||
std::cerr << "!!!!!! Received Data from global router, but the client service is not handling it !!!!!!!!!!" << std::endl ;
|
||||
std::cerr << " destination key_id = " << destination_key.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
// This function is mandatory. It should do two things:
|
||||
// 1 - keep a pointer to the global router, so as to be able to send data (e.g. copy pt into a local variable)
|
||||
// 2 - call pt->registerTunnelService(this), so that the TR knows that service and can send back information to it.
|
||||
//
|
||||
virtual void connectToGlobalRouter(p3GRouter *pt) = 0 ;
|
||||
};
|
||||
|
||||
|
|
@ -55,12 +55,12 @@ bool RsGRouterPublishKeyItem::serialise(void *data, uint32_t& pktsize) const
|
|||
offset += 8 ;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, diffusion_id);
|
||||
ok &= setRawSha1(data, tlvsize, &offset, published_key);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, diffusion_id);
|
||||
ok &= published_key.serialise(data, tlvsize, offset) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, service_id);
|
||||
ok &= setRawUFloat32(data, tlvsize, &offset, randomized_distance);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, description_string);
|
||||
ok &= setRawPGPFingerprint(data, tlvsize, &offset, fingerprint);
|
||||
ok &= fingerprint.serialise(data, tlvsize, offset) ;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
|
@ -134,10 +134,9 @@ bool RsGRouterProofOfWorkObject::checkProofOfWork(unsigned char *mem,uint32_t si
|
|||
{
|
||||
Sha1CheckSum sum = RsDirUtil::sha1sum(mem,size) ;
|
||||
|
||||
for(uint32_t i=0;i<(7+PROOF_OF_WORK_REQUESTED_BYTES)/4;++i)
|
||||
for(int j=0;j<(PROOF_OF_WORK_REQUESTED_BYTES%4);++j)
|
||||
if(sum.fourbytes[i] & (0xff << (8*(3-j))) != 0)
|
||||
return false ;
|
||||
for(int i=0;i<PROOF_OF_WORK_REQUESTED_BYTES;++i)
|
||||
if(sum.toByteArray()[i] != 0)
|
||||
return false ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
@ -183,11 +182,11 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterPublishKeyItem(void *da
|
|||
offset += 8 ;
|
||||
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &item->diffusion_id); // file hash
|
||||
ok &= getRawSha1(data, pktsize, &offset, item->published_key);
|
||||
ok &= item->published_key.deserialise(data, pktsize, offset) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &item->service_id); // file hash
|
||||
ok &= getRawUFloat32(data, pktsize, &offset, item->randomized_distance); // file hash
|
||||
ok &= GetTlvString(data, pktsize, &offset, TLV_TYPE_STR_VALUE,item->description_string);
|
||||
ok &= getRawPGPFingerprint(data,pktsize,&offset,item->fingerprint) ;
|
||||
ok &= item->fingerprint.deserialise(data,pktsize,offset) ;
|
||||
|
||||
if (offset != rssize || !ok)
|
||||
{
|
||||
|
@ -207,7 +206,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataItem(void *d
|
|||
RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem() ;
|
||||
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &item->routing_id); // file hash
|
||||
ok &= getRawSha1(data, pktsize, &offset, item->destination_key);
|
||||
ok &= item->destination_key.deserialise(data, pktsize, offset) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &item->data_size); // file hash
|
||||
|
||||
if( NULL == (item->data_bytes = (uint8_t*)malloc(item->data_size)))
|
||||
|
@ -257,7 +256,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoItem(void *d
|
|||
RsGRouterRoutingInfoItem *item = new RsGRouterRoutingInfoItem() ;
|
||||
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &item->status_flags);
|
||||
ok &= getRawSSLId(data, pktsize, &offset, item->origin);
|
||||
ok &= item->origin.deserialise(data, pktsize, offset) ;
|
||||
ok &= getRawTimeT(data, pktsize, &offset, item->received_time);
|
||||
|
||||
uint32_t s = 0 ;
|
||||
|
@ -267,7 +266,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoItem(void *d
|
|||
{
|
||||
FriendTrialRecord ftr ;
|
||||
|
||||
ok &= getRawSSLId(data, pktsize, &offset, ftr.friend_id);
|
||||
ok &= ftr.friend_id.deserialise(data, pktsize, offset) ;
|
||||
ok &= getRawTimeT(data, pktsize, &offset, ftr.time_stamp) ;
|
||||
|
||||
item->tried_friends.push_back(ftr) ;
|
||||
|
@ -276,7 +275,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoItem(void *d
|
|||
item->data_item = new RsGRouterGenericDataItem ;
|
||||
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &item->data_item->routing_id);
|
||||
ok &= getRawSha1(data, pktsize, &offset, item->data_item->destination_key) ;
|
||||
ok &= item->data_item->destination_key.deserialise(data, pktsize, offset) ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &item->data_item->data_size) ;
|
||||
|
||||
item->data_item->data_bytes = (uint8_t*)malloc(item->data_item->data_size) ;
|
||||
|
@ -305,7 +304,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixFriendListItem(vo
|
|||
item->reverse_friend_indices.resize(nb_friends) ;
|
||||
|
||||
for(uint32_t i=0;ok && i<nb_friends;++i)
|
||||
ok &= getRawSSLId(data, pktsize, &offset, item->reverse_friend_indices[i]) ;
|
||||
ok &= item->reverse_friend_indices[i].deserialise(data, pktsize, offset) ;
|
||||
|
||||
if (offset != rssize || !ok)
|
||||
{
|
||||
|
@ -323,7 +322,7 @@ RsGRouterItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixCluesItem(void *d
|
|||
|
||||
RsGRouterMatrixCluesItem *item = new RsGRouterMatrixCluesItem() ;
|
||||
|
||||
ok &= getRawSha1(data,pktsize,&offset,item->destination_key) ;
|
||||
ok &= item->destination_key.deserialise(data,pktsize,offset) ;
|
||||
|
||||
uint32_t nb_clues = 0 ;
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &nb_clues);
|
||||
|
@ -395,7 +394,7 @@ bool RsGRouterGenericDataItem::serialise(void *data,uint32_t& size) const
|
|||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, routing_id);
|
||||
ok &= setRawSha1(data, tlvsize, &offset, destination_key);
|
||||
ok &= destination_key.serialise(data, tlvsize, offset) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, data_size);
|
||||
|
||||
memcpy(&((uint8_t*)data)[offset],data_bytes,data_size) ;
|
||||
|
@ -445,24 +444,24 @@ uint32_t RsGRouterMatrixFriendListItem::serial_size() const
|
|||
{
|
||||
uint32_t s = 8 ; // header
|
||||
s += 4 ; // reverse_friend_indices.size()
|
||||
s += 16 * reverse_friend_indices.size() ; // sha1 for published_key
|
||||
s += RsFileHash::SIZE_IN_BYTES * reverse_friend_indices.size() ; // sha1 for published_key
|
||||
|
||||
return s ;
|
||||
}
|
||||
uint32_t RsGRouterRoutingInfoItem::serial_size() const
|
||||
{
|
||||
uint32_t s = 8 ; // header
|
||||
s += 4 ; // status_flags
|
||||
s += 16 ; // origin
|
||||
s += 8 ; // received_time
|
||||
s += 4 ; // tried_friends.size() ;
|
||||
uint32_t s = 8 ; // header
|
||||
s += 4 ; // status_flags
|
||||
s += origin.SIZE_IN_BYTES ; // origin
|
||||
s += 8 ; // received_time
|
||||
s += 4 ; // tried_friends.size() ;
|
||||
|
||||
s += tried_friends.size() * ( 16 + 8 ) ; // FriendTrialRecord
|
||||
s += tried_friends.size() * ( RsPeerId::SIZE_IN_BYTES + 8 ) ; // FriendTrialRecord
|
||||
|
||||
s += 4; // data_item->routing_id
|
||||
s += 20; // data_item->destination_key
|
||||
s += 4; // data_item->data_size
|
||||
s += data_item->data_size; // data_item->data_bytes
|
||||
s += 4; // data_item->routing_id
|
||||
s += data_item->destination_key.SIZE_IN_BYTES; // data_item->destination_key
|
||||
s += 4; // data_item->data_size
|
||||
s += data_item->data_size; // data_item->data_bytes
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
@ -479,7 +478,7 @@ bool RsGRouterMatrixFriendListItem::serialise(void *data,uint32_t& size) const
|
|||
ok &= setRawUInt32(data, tlvsize, &offset, reverse_friend_indices.size());
|
||||
|
||||
for(uint32_t i=0;ok && i<reverse_friend_indices.size();++i)
|
||||
ok &= setRawSSLId(data,tlvsize,&offset,reverse_friend_indices[i]) ;
|
||||
ok &= reverse_friend_indices[i].serialise(data,tlvsize,offset) ;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
|
@ -498,7 +497,7 @@ bool RsGRouterMatrixCluesItem::serialise(void *data,uint32_t& size) const
|
|||
return false ;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= setRawSha1(data,tlvsize,&offset,destination_key) ;
|
||||
ok &= destination_key.serialise(data,tlvsize,offset) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, clues.size());
|
||||
|
||||
for(std::list<RoutingMatrixHitEntry>::const_iterator it2(clues.begin());it2!=clues.end();++it2)
|
||||
|
@ -518,37 +517,37 @@ bool RsGRouterMatrixCluesItem::serialise(void *data,uint32_t& size) const
|
|||
}
|
||||
bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const
|
||||
{
|
||||
uint32_t tlvsize,offset=0;
|
||||
bool ok = true;
|
||||
|
||||
if(!serialise_header(data,size,tlvsize,offset))
|
||||
return false ;
|
||||
uint32_t tlvsize,offset=0;
|
||||
bool ok = true;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, status_flags) ;
|
||||
ok &= setRawSSLId(data, tlvsize, &offset, origin) ;
|
||||
ok &= setRawTimeT(data, tlvsize, &offset, received_time) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, tried_friends.size()) ;
|
||||
if(!serialise_header(data,size,tlvsize,offset))
|
||||
return false ;
|
||||
|
||||
for(std::list<FriendTrialRecord>::const_iterator it(tried_friends.begin());it!=tried_friends.end();++it)
|
||||
{
|
||||
ok &= setRawSSLId(data, tlvsize, &offset, (*it).friend_id) ;
|
||||
ok &= setRawTimeT(data, tlvsize, &offset, (*it).time_stamp) ;
|
||||
}
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, status_flags) ;
|
||||
ok &= origin.serialise(data, tlvsize, offset) ;
|
||||
ok &= setRawTimeT(data, tlvsize, &offset, received_time) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, tried_friends.size()) ;
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, data_item->routing_id) ;
|
||||
ok &= setRawSha1(data, tlvsize, &offset, data_item->destination_key) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, data_item->data_size) ;
|
||||
for(std::list<FriendTrialRecord>::const_iterator it(tried_friends.begin());it!=tried_friends.end();++it)
|
||||
{
|
||||
ok &= (*it).friend_id.serialise(data, tlvsize, offset ) ;
|
||||
ok &= setRawTimeT(data, tlvsize, &offset, (*it).time_stamp) ;
|
||||
}
|
||||
|
||||
memcpy(&((uint8_t*)data)[offset],data_item->data_bytes,data_item->data_size) ;
|
||||
offset += data_item->data_size ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, data_item->routing_id) ;
|
||||
ok &= data_item->destination_key.serialise(data, tlvsize, offset) ;
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, data_item->data_size) ;
|
||||
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "rsfileitemserialiser::serialisedata() size error! " << std::endl;
|
||||
}
|
||||
memcpy(&((uint8_t*)data)[offset],data_item->data_bytes,data_item->data_size) ;
|
||||
offset += data_item->data_size ;
|
||||
|
||||
return ok;
|
||||
if (offset != tlvsize)
|
||||
{
|
||||
ok = false;
|
||||
std::cerr << "rsfileitemserialiser::serialisedata() size error! " << std::endl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
|
@ -558,7 +557,7 @@ bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const
|
|||
std::ostream& RsGRouterPublishKeyItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "GRouterPublishKeyItem:" << std::endl ;
|
||||
o << " POW bytes : \""<< PGPIdType(pow_bytes).toStdString() << "\"" << std::endl ;
|
||||
o << " POW bytes : \""<< RsPgpId(pow_bytes).toStdString() << "\"" << std::endl ;
|
||||
o << " direct origin: \""<< PeerId() << "\"" << std::endl ;
|
||||
o << " Key: " << published_key.toStdString() << std::endl ;
|
||||
o << " Req. Id: " << std::hex << diffusion_id << std::dec << std::endl ;
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "util/rsid.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "rsgrouter.h"
|
||||
#include "p3grouter.h"
|
||||
|
||||
|
@ -207,7 +207,7 @@ class RsGRouterMatrixFriendListItem: public RsGRouterItem
|
|||
|
||||
// packet data
|
||||
//
|
||||
std::vector<SSLIdType> reverse_friend_indices ;
|
||||
std::vector<RsPeerId> reverse_friend_indices ;
|
||||
};
|
||||
|
||||
class RsGRouterRoutingInfoItem: public RsGRouterItem, public GRouterRoutingInfo, public RsGRouterNonCopyableObject
|
||||
|
|
|
@ -33,7 +33,7 @@ GRouterMatrix::GRouterMatrix()
|
|||
}
|
||||
|
||||
bool GRouterMatrix::addRoutingClue( const GRouterKeyId& key_id,const GRouterServiceId& sid,float distance,
|
||||
const std::string& desc_string,const SSLIdType& source_friend)
|
||||
const std::string& desc_string,const RsPeerId& source_friend)
|
||||
{
|
||||
// 1 - get the friend index.
|
||||
//
|
||||
|
@ -76,18 +76,18 @@ bool GRouterMatrix::addRoutingClue( const GRouterKeyId& key_id,const GRouterServ
|
|||
|
||||
return true ;
|
||||
}
|
||||
uint32_t GRouterMatrix::getFriendId_const(const SSLIdType& source_friend) const
|
||||
uint32_t GRouterMatrix::getFriendId_const(const RsPeerId& source_friend) const
|
||||
{
|
||||
std::map<SSLIdType,uint32_t>::const_iterator it = _friend_indices.find(source_friend) ;
|
||||
std::map<RsPeerId,uint32_t>::const_iterator it = _friend_indices.find(source_friend) ;
|
||||
|
||||
if(it == _friend_indices.end())
|
||||
return _reverse_friend_indices.size() ;
|
||||
else
|
||||
return it->second ;
|
||||
}
|
||||
uint32_t GRouterMatrix::getFriendId(const SSLIdType& source_friend)
|
||||
uint32_t GRouterMatrix::getFriendId(const RsPeerId& source_friend)
|
||||
{
|
||||
std::map<SSLIdType,uint32_t>::const_iterator it = _friend_indices.find(source_friend) ;
|
||||
std::map<RsPeerId,uint32_t>::const_iterator it = _friend_indices.find(source_friend) ;
|
||||
|
||||
if(it == _friend_indices.end())
|
||||
{
|
||||
|
@ -130,7 +130,7 @@ void GRouterMatrix::debugDump() const
|
|||
}
|
||||
}
|
||||
|
||||
bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, const std::list<SSLIdType>& friends, std::map<SSLIdType,float>& probas) const
|
||||
bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, const std::list<RsPeerId>& friends, std::map<RsPeerId,float>& probas) const
|
||||
{
|
||||
// Routing probabilities are computed according to routing clues
|
||||
//
|
||||
|
@ -156,7 +156,7 @@ bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, cons
|
|||
}
|
||||
const std::vector<float>& w(it2->second) ;
|
||||
|
||||
for(std::list<SSLIdType>::const_iterator it(friends.begin());it!=friends.end();++it)
|
||||
for(std::list<RsPeerId>::const_iterator it(friends.begin());it!=friends.end();++it)
|
||||
{
|
||||
uint32_t findex = getFriendId_const(*it) ;
|
||||
|
||||
|
@ -170,7 +170,7 @@ bool GRouterMatrix::computeRoutingProbabilities(const GRouterKeyId& key_id, cons
|
|||
}
|
||||
|
||||
if(total > 0.0f)
|
||||
for(std::map<SSLIdType,float>::iterator it(probas.begin());it!=probas.end();++it)
|
||||
for(std::map<RsPeerId,float>::iterator it(probas.begin());it!=probas.end();++it)
|
||||
it->second /= total ;
|
||||
|
||||
return true ;
|
||||
|
|
|
@ -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<SSLIdType>& friends, std::map<SSLIdType,float>& probas) const ;
|
||||
bool computeRoutingProbabilities(const GRouterKeyId& id, const std::list<RsPeerId>& friends, std::map<RsPeerId,float>& probas) const ;
|
||||
|
||||
// Update routing probabilities for each key, accounting for all received events, but without
|
||||
// activity information
|
||||
|
@ -60,7 +60,7 @@ class GRouterMatrix
|
|||
|
||||
// Record one routing clue. The events can possibly be merged in time buckets.
|
||||
//
|
||||
bool addRoutingClue(const GRouterKeyId& id,const GRouterServiceId& sid,float distance,const std::string& desc_string,const SSLIdType& source_friend) ;
|
||||
bool addRoutingClue(const GRouterKeyId& id,const GRouterServiceId& sid,float distance,const std::string& desc_string,const RsPeerId& source_friend) ;
|
||||
|
||||
// Dump info in terminal.
|
||||
//
|
||||
|
@ -72,11 +72,11 @@ class GRouterMatrix
|
|||
private:
|
||||
// returns the friend id, possibly creating a new id.
|
||||
//
|
||||
uint32_t getFriendId(const SSLIdType& id) ;
|
||||
uint32_t getFriendId(const RsPeerId& id) ;
|
||||
|
||||
// returns the friend id. If not exist, returns _reverse_friend_indices.size()
|
||||
//
|
||||
uint32_t getFriendId_const(const SSLIdType& id) const;
|
||||
uint32_t getFriendId_const(const RsPeerId& id) const;
|
||||
|
||||
// List of events received and computed routing probabilities
|
||||
//
|
||||
|
@ -90,8 +90,8 @@ class GRouterMatrix
|
|||
// Routing weights. These are the result of a time convolution of the routing clues and weights
|
||||
// recorded in _routing_clues.
|
||||
//
|
||||
std::map<SSLIdType,uint32_t> _friend_indices ; // index for each friend to lookup in the routing matrix Not saved.
|
||||
std::vector<SSLIdType> _reverse_friend_indices ;// SSLid corresponding to each friend index. Saved.
|
||||
std::map<RsPeerId,uint32_t> _friend_indices ; // index for each friend to lookup in the routing matrix Not saved.
|
||||
std::vector<RsPeerId> _reverse_friend_indices ;// SSLid corresponding to each friend index. Saved.
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ class GRouterPublishedKeyInfo
|
|||
|
||||
struct FriendTrialRecord
|
||||
{
|
||||
SSLIdType friend_id ; // id of the friend
|
||||
RsPeerId friend_id ; // id of the friend
|
||||
time_t time_stamp ; // time of the last tried
|
||||
};
|
||||
|
||||
|
@ -79,7 +79,7 @@ class GRouterRoutingInfo
|
|||
|
||||
uint32_t status_flags ; // pending, waiting, etc.
|
||||
std::list<FriendTrialRecord> tried_friends ; // list of friends to which the item was sent ordered with time.
|
||||
SSLIdType origin ; // which friend sent us that item
|
||||
RsPeerId origin ; // which friend sent us that item
|
||||
time_t received_time ; // time at which the item was received
|
||||
};
|
||||
|
||||
|
|
|
@ -23,6 +23,153 @@
|
|||
*
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Decentralized routing
|
||||
// =====================
|
||||
//
|
||||
// Use cases:
|
||||
// - Peer A asks for B's key, for which he has the signature, or the ID.
|
||||
// - Peer A wants to send a private msg to peer C, for which he has the public key
|
||||
// - Peer A wants to contact a channel's owner, a group owner, a forum owner, etc.
|
||||
// - Peer C needs to route msg/key requests from unknown peer, to unknown peer so that the information
|
||||
// eventually reach their destination.
|
||||
//
|
||||
// Main idea: Each peer holds a local routing table, a matrix with probabilities that each friend
|
||||
// is a correct path for a given key ID.
|
||||
//
|
||||
// The routing tables are updated as messages go back and forth. Successful
|
||||
// interactions feed the routing table with information of where to route the
|
||||
// packets.
|
||||
//
|
||||
// The routing is kept probabilistic, meaning that the optimal route is not
|
||||
// always chosen, but the randomness helps updating the routing probabilities.
|
||||
//
|
||||
// Services that might use the router (All services really...)
|
||||
// - Identity manager (p3Identity)
|
||||
// - asks identities i.e. RSA public keys (i.e. sends dentity requests through router)
|
||||
// - Messenger
|
||||
// - sends/receives messages to distant peers
|
||||
// - Channels, forums, posted, etc.
|
||||
// - send messages to the origin of the channel/forum/posted
|
||||
//
|
||||
// GUI
|
||||
// - a debug panel should show the routing info: probabilities for all known IDs
|
||||
// - routing probabilities for a given ID accordign to who's connected
|
||||
//
|
||||
// Decentralized routing algorithm:
|
||||
// - tick() method
|
||||
// * calls autoWash(), send() and receive()
|
||||
//
|
||||
// - message passing
|
||||
// - upward:
|
||||
// * Forward msg to friends according to probabilities.
|
||||
// * If all equal, send to all friends (or a rando subset of them).
|
||||
// * keep the local routing info in a cache that is saved (Which peer issued the msg)
|
||||
// - which probability was used to chose this friend (will be useful
|
||||
// to compute the routing contribution if the msg is ACK-ed)
|
||||
//
|
||||
// - downward: look into routing cache. If info not present, drop the item.
|
||||
// Forward item into stored direction.
|
||||
//
|
||||
// - routing probability computation: count number of times a reliable info is obtained from
|
||||
// which direction for which identity
|
||||
// * the count is a floating point number, since weights can be assigned to each info
|
||||
// (especially for importance sampling)
|
||||
// * init: all friends have equal count of 0 (or 1, well, we'll have to make this right).
|
||||
// * We use importance sampling, meaning that when peer relays a msg from ID:
|
||||
// count[ID, peer] += 1.0 / importance
|
||||
//
|
||||
// ... where importance was the probability of chosing peer for the
|
||||
// route upward.
|
||||
//
|
||||
// * probability of forward is proportional to count.
|
||||
//
|
||||
// - routing cache
|
||||
// * this cache stores messages IDs (like turtle router) but is saved on disk
|
||||
// * it is used to remember where to send back responses to messages, and
|
||||
// with what probability the route was chosen.
|
||||
// * cache items have a TTL and the cache is cleaned regularly.
|
||||
//
|
||||
// - routing matrix
|
||||
// * the structure is fed by other services, when they receive key IDs.
|
||||
// * stores for each identity the count of how many times each peer gave reliable info for that ID.
|
||||
// That information should be enough to route packets in the correct direction.
|
||||
// * saved to disk.
|
||||
// * all contributions should have a time stamp. Regularly, the oldest contributions are removed.
|
||||
//
|
||||
// struct RoutingMatrixHitEntry
|
||||
// {
|
||||
// float weight ;
|
||||
// time_t time_stamp ;
|
||||
// }
|
||||
// typedef std::map<std::string,std::list<RoutingMatrixHitEntry> > RSAKeyRoutingMap ;
|
||||
//
|
||||
// class RoutingMatrix
|
||||
// {
|
||||
// public:
|
||||
// // Computes the routing probabilities for this id for the given list of friends.
|
||||
// // the computation accounts for the time at which the info was received and the
|
||||
// // weight of each routing hit record.
|
||||
// //
|
||||
// bool computeRoutingProbabilities(RSAKeyIDType id, const std::vector<SSLIdType>& friends,
|
||||
// std::vector<float>& probas) const ;
|
||||
//
|
||||
// // remove oldest entries.
|
||||
// bool autoWash() ;
|
||||
//
|
||||
// // Record one routing clue. The events can possibly be merged in time buckets.
|
||||
// //
|
||||
// bool addRoutingEvent(RSAKeyIDType id,const SSLIdType& which friend) ;
|
||||
//
|
||||
// private:
|
||||
// std::map<RSAKeyIDType, RSAKeyRoutingMap> _known_keys ;
|
||||
// };
|
||||
//
|
||||
// - Routed packets: we use a common packet type for all services:
|
||||
//
|
||||
// We need two abstract item types:
|
||||
//
|
||||
// * Data packet
|
||||
// - packet unique ID (sha1, or uint64_t)
|
||||
// - destination ID (for Dn packets, the destination is the source!)
|
||||
// - packet type: Id request, Message, etc.
|
||||
// - packet service ID (Can be messenging, channels, etc).
|
||||
// - packet data (void* + size_t)
|
||||
// - flags (such as ACK or response required, and packet direction)
|
||||
// * ACK packet.
|
||||
// - packet unique ID (the id of the corresponding data)
|
||||
// - flags (reason for ACK. Could be data delivered, or error, too far, etc)
|
||||
//
|
||||
// - Data storage packets
|
||||
// * We need storage packets for the matrix states.
|
||||
// * General routing options info?
|
||||
//
|
||||
// - estimated memory cost
|
||||
// For each identity, the matrix needs
|
||||
// - hits for each friend peer with time stamps. That means 8 bytes per hit.
|
||||
// That is for 1000 identities, having at most 100 hits each (We keep
|
||||
// the hits below a maximum. 100 seems ok.), that is 1000*100*8 < 1MB. Not much.
|
||||
//
|
||||
// - Main difficulties:
|
||||
// * have a good re-try strategy if a msg does not arrive.
|
||||
// * handle peer availability. In forward mode: easy. In backward mode:
|
||||
// difficult. We should wait, and send back the packet if possible.
|
||||
// * robustness
|
||||
// * security: avoid flooding, and message alteration.
|
||||
//
|
||||
// - Questions to be solved
|
||||
// * how do we talk to other services?
|
||||
// - keep a list of services?
|
||||
//
|
||||
// - in practice, services will need to send requests, and expect responses.
|
||||
// * gxs (p3identity) asks for a key, gxs (p3identity) should get the key.
|
||||
// * msg service wants to send a distant msg, or msg receives a distant msg.
|
||||
//
|
||||
// => we need abstract packets and service ids.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "util/rsrandom.h"
|
||||
#include "pqi/p3linkmgr.h"
|
||||
#include "serialiser/rsconfigitems.h"
|
||||
|
@ -175,13 +322,9 @@ void p3GRouter::routePendingObjects()
|
|||
std::cerr << "p3GRouter::routeObjects() triage phase:" << std::endl;
|
||||
std::cerr << "Cached Items : " << _pending_messages.size() << std::endl;
|
||||
|
||||
std::list<std::string> lst_tmp ;
|
||||
std::list<SSLIdType> lst ;
|
||||
mLinkMgr->getOnlineList(lst_tmp) ;
|
||||
SSLIdType own_id( mLinkMgr->getOwnId() );
|
||||
|
||||
for(std::list<std::string>::const_iterator it(lst_tmp.begin());it!=lst_tmp.end();++it)
|
||||
lst.push_back(SSLIdType(*it)) ;
|
||||
std::list<RsPeerId> lst ;
|
||||
mLinkMgr->getOnlineList(lst) ;
|
||||
RsPeerId own_id( mLinkMgr->getOwnId() );
|
||||
|
||||
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))
|
||||
|
@ -193,8 +336,8 @@ void p3GRouter::routePendingObjects()
|
|||
std::cerr << " Flags : " << it->second.status_flags << std::endl;
|
||||
std::cerr << " Probabilities: " << std::endl;
|
||||
|
||||
std::map<SSLIdType,float> probas ; // friends probabilities for online friend list.
|
||||
SSLIdType routed_friend ; // friend chosen for the next hop
|
||||
std::map<RsPeerId,float> probas ; // friends probabilities for online friend list.
|
||||
RsPeerId routed_friend ; // friend chosen for the next hop
|
||||
float best_proba = 0.0f; // temp variable used to select the best proba
|
||||
bool should_remove = false ; // should we remove this from the map?
|
||||
|
||||
|
@ -223,7 +366,7 @@ void p3GRouter::routePendingObjects()
|
|||
|
||||
bool friend_found = false ;
|
||||
|
||||
for(std::map<SSLIdType,float>::const_iterator it2(probas.begin());it2!=probas.end();++it2)
|
||||
for(std::map<RsPeerId,float>::const_iterator it2(probas.begin());it2!=probas.end();++it2)
|
||||
{
|
||||
std::cerr << " " << it2->first.toStdString() << " : " << it2->second << std::endl;
|
||||
|
||||
|
@ -255,10 +398,10 @@ void p3GRouter::routePendingObjects()
|
|||
|
||||
std::cerr << " Sending..." << std::endl;
|
||||
// send
|
||||
new_item->PeerId(routed_friend.toStdString()) ;
|
||||
new_item->PeerId(routed_friend) ;
|
||||
sendItem(new_item) ;
|
||||
}
|
||||
else if(it->second.origin.toStdString() != mLinkMgr->getOwnId() || std::find(lst.begin(),lst.end(),it->second.origin) != lst.end())
|
||||
else if(it->second.origin != mLinkMgr->getOwnId() || std::find(lst.begin(),lst.end(),it->second.origin) != lst.end())
|
||||
{
|
||||
// There's no correct friend to send this item to. We keep it for a while. If it's too old,
|
||||
// we discard it. For now, the procedure is to send back an ACK.
|
||||
|
@ -320,7 +463,7 @@ void p3GRouter::publishKeys()
|
|||
item.randomized_distance = drand48() ;
|
||||
item.fingerprint = info.fpr;
|
||||
item.description_string = info.description_string ;
|
||||
item.PeerId("") ; // no peer id => key is forwarded to all friends.
|
||||
item.PeerId(RsPeerId()) ; // no peer id => key is forwarded to all friends.
|
||||
|
||||
locked_forwardKey(item) ;
|
||||
|
||||
|
@ -332,14 +475,14 @@ void p3GRouter::publishKeys()
|
|||
|
||||
void p3GRouter::locked_forwardKey(const RsGRouterPublishKeyItem& item)
|
||||
{
|
||||
std::list<std::string> connected_peers ;
|
||||
std::list<RsPeerId> connected_peers ;
|
||||
mLinkMgr->getOnlineList(connected_peers) ;
|
||||
|
||||
std::cerr << " Forwarding key item to all available friends..." << std::endl;
|
||||
|
||||
// get list of connected friends, and broadcast to all of them
|
||||
//
|
||||
for(std::list<std::string>::const_iterator it(connected_peers.begin());it!=connected_peers.end();++it)
|
||||
for(std::list<RsPeerId>::const_iterator it(connected_peers.begin());it!=connected_peers.end();++it)
|
||||
if(item.PeerId() != *it)
|
||||
{
|
||||
std::cerr << " sending to " << (*it) << std::endl;
|
||||
|
@ -432,7 +575,7 @@ void p3GRouter::handleRecvPublishKeyItem(RsGRouterPublishKeyItem *item)
|
|||
|
||||
// update the route matrix
|
||||
|
||||
_routing_matrix.addRoutingClue(item->published_key,item->service_id,item->randomized_distance,item->description_string,SSLIdType(item->PeerId())) ;
|
||||
_routing_matrix.addRoutingClue(item->published_key,item->service_id,item->randomized_distance,item->description_string,RsPeerId(item->PeerId())) ;
|
||||
|
||||
// forward the key to other peers according to key forwarding cache
|
||||
|
||||
|
@ -496,7 +639,7 @@ void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
|||
break ;
|
||||
}
|
||||
|
||||
if(it->second.origin.toStdString() == mLinkMgr->getOwnId())
|
||||
if(it->second.origin == mLinkMgr->getOwnId())
|
||||
{
|
||||
// find the client service and notify it.
|
||||
std::cerr << " We're owner: should notify client id" << std::endl;
|
||||
|
@ -511,7 +654,7 @@ void p3GRouter::handleRecvACKItem(RsGRouterACKItem *item)
|
|||
void p3GRouter::handleRecvDataItem(RsGRouterGenericDataItem *item)
|
||||
{
|
||||
RsStackMutex mtx(grMtx) ;
|
||||
std::cerr << "Received data item for key " << item->destination_key.toStdString() << std::endl;
|
||||
std::cerr << "Received data item for key " << item->destination_key << std::endl;
|
||||
|
||||
// Do we have this item in the cache already?
|
||||
// - if not, add in the pending items
|
||||
|
@ -541,7 +684,7 @@ void p3GRouter::handleRecvDataItem(RsGRouterGenericDataItem *item)
|
|||
else
|
||||
info.status_flags = RS_GROUTER_ROUTING_STATE_PEND ;
|
||||
|
||||
info.origin = SSLIdType(item->PeerId()) ;
|
||||
info.origin = RsPeerId(item->PeerId()) ;
|
||||
info.received_time = time(NULL) ;
|
||||
|
||||
_pending_messages[item->routing_id] = info ;
|
||||
|
@ -588,7 +731,7 @@ void p3GRouter::sendData(const GRouterKeyId& destination, RsGRouterGenericDataIt
|
|||
|
||||
info.data_item = item ;
|
||||
info.status_flags = RS_GROUTER_ROUTING_STATE_PEND ;
|
||||
info.origin = SSLIdType(mLinkMgr->getOwnId()) ;
|
||||
info.origin = RsPeerId(mLinkMgr->getOwnId()) ;
|
||||
info.received_time = time(NULL) ;
|
||||
|
||||
// Make sure we have a unique id (at least locally).
|
||||
|
@ -606,13 +749,13 @@ void p3GRouter::sendData(const GRouterKeyId& destination, RsGRouterGenericDataIt
|
|||
_pending_messages[propagation_id] = info ;
|
||||
}
|
||||
|
||||
void p3GRouter::sendACK(const SSLIdType& peer, GRouterMsgPropagationId mid, uint32_t ack_flags)
|
||||
void p3GRouter::sendACK(const RsPeerId& peer, GRouterMsgPropagationId mid, uint32_t ack_flags)
|
||||
{
|
||||
RsGRouterACKItem *item = new RsGRouterACKItem ;
|
||||
|
||||
item->state = ack_flags ;
|
||||
item->mid = mid ;
|
||||
item->PeerId(peer.toStdString()) ;
|
||||
item->PeerId(peer) ;
|
||||
|
||||
sendItem(item) ;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include "rsgrouter.h"
|
||||
#include "services/p3service.h"
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
#include "util/rsid.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
|
||||
#include "groutertypes.h"
|
||||
#include "groutermatrix.h"
|
||||
|
@ -92,7 +92,7 @@ class p3GRouter: public RsGRouter, public p3Service, public p3Config
|
|||
// Sends an ACK to the origin of the msg. This is used to notify for
|
||||
// unfound route, or message correctly received, depending on the particular situation.
|
||||
//
|
||||
void sendACK(const SSLIdType& peer,GRouterMsgPropagationId mid, uint32_t flags) ;
|
||||
void sendACK(const RsPeerId& peer,GRouterMsgPropagationId mid, uint32_t flags) ;
|
||||
|
||||
//===================================================//
|
||||
// Interface with RsGRouter //
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue