mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
added non selective tracking for GXS messages
This commit is contained in:
parent
7db3bb1c9b
commit
47dd70fbe8
13 changed files with 160 additions and 83 deletions
|
@ -27,13 +27,56 @@
|
|||
#include "groutermatrix.h"
|
||||
#include "grouteritems.h"
|
||||
|
||||
//#define ROUTING_MATRIX_DEBUG
|
||||
#define ROUTING_MATRIX_DEBUG
|
||||
|
||||
GRouterMatrix::GRouterMatrix()
|
||||
{
|
||||
_proba_need_updating = true ;
|
||||
}
|
||||
|
||||
bool GRouterMatrix::addTrackingInfo(const RsGxsMessageId& mid,const RsPeerId& source_friend)
|
||||
{
|
||||
time_t now = time(NULL) ;
|
||||
uint32_t fid = getFriendId(source_friend) ;
|
||||
|
||||
RoutingTrackEntry rte ;
|
||||
|
||||
rte.friend_id = fid ;
|
||||
rte.time_stamp = now ;
|
||||
|
||||
_tracking_clues[mid] = rte ;
|
||||
#ifdef ROUTING_MATRIX_DEBUG
|
||||
std::cerr << "GRouterMatrix::addTrackingInfo(): Added clue mid=" << mid << ", from " << source_friend << " ID=" << fid << std::endl;
|
||||
#endif
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool GRouterMatrix::cleanUp()
|
||||
{
|
||||
// remove all tracking entries that have become too old.
|
||||
|
||||
#ifdef ROUTING_MATRIX_DEBUG
|
||||
std::cerr << "GRouterMatrix::cleanup()" << std::endl;
|
||||
#endif
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
for(std::map<RsGxsMessageId,RoutingTrackEntry>::iterator it(_tracking_clues.begin());it!=_tracking_clues.end();)
|
||||
if(it->second.time_stamp + RS_GROUTER_MAX_KEEP_TRACKING_CLUES < now)
|
||||
{
|
||||
#ifdef ROUTING_MATRIX_DEBUG
|
||||
std::cerr << " removing old entry msgId=" << it->first << ", from id " << it->second.friend_id << ", obtained " << (now - it->second.time_stamp) << " secs ago." << std::endl;
|
||||
#endif
|
||||
std::map<RsGxsMessageId,RoutingTrackEntry>::iterator tmp(it) ;
|
||||
++tmp ;
|
||||
_tracking_clues.erase(it) ;
|
||||
it=tmp ;
|
||||
}
|
||||
else
|
||||
++it ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool GRouterMatrix::addRoutingClue(const GRouterKeyId& key_id,const RsPeerId& source_friend,float weight)
|
||||
{
|
||||
// 1 - get the friend index.
|
||||
|
|
|
@ -42,6 +42,12 @@ struct RoutingMatrixHitEntry
|
|||
time_t time_stamp ;
|
||||
};
|
||||
|
||||
struct RoutingTrackEntry
|
||||
{
|
||||
uint32_t friend_id ; // not the full key. Gets too big otherwise!
|
||||
time_t time_stamp ;
|
||||
};
|
||||
|
||||
class GRouterMatrix
|
||||
{
|
||||
public:
|
||||
|
@ -61,10 +67,13 @@ class GRouterMatrix
|
|||
// Record one routing clue. The events can possibly be merged in time buckets.
|
||||
//
|
||||
bool addRoutingClue(const GRouterKeyId& id,const RsPeerId& source_friend,float weight) ;
|
||||
bool addTrackingInfo(const RsGxsMessageId& id,const RsPeerId& source_friend) ;
|
||||
|
||||
bool saveList(std::list<RsItem*>& items) ;
|
||||
bool loadList(std::list<RsItem*>& items) ;
|
||||
|
||||
bool cleanUp() ;
|
||||
|
||||
// Dump info in terminal.
|
||||
//
|
||||
void debugDump() const ;
|
||||
|
@ -81,8 +90,9 @@ class GRouterMatrix
|
|||
|
||||
// List of events received and computed routing probabilities
|
||||
//
|
||||
std::map<GRouterKeyId, std::list<RoutingMatrixHitEntry> > _routing_clues ; // received routing clues. Should be saved.
|
||||
std::map<GRouterKeyId, std::vector<float> > _time_combined_hits ; // hit matrix after time-convolution filter
|
||||
std::map<GRouterKeyId, std::list<RoutingMatrixHitEntry> > _routing_clues ; // received routing clues. Should be saved.
|
||||
std::map<GRouterKeyId, std::vector<float> > _time_combined_hits ; // hit matrix after time-convolution filter
|
||||
std::map<RsGxsMessageId,RoutingTrackEntry> _tracking_clues ; // who provided the most recent messages
|
||||
|
||||
// This is used to avoid re-computing probas when new events have been received.
|
||||
//
|
||||
|
@ -93,6 +103,5 @@ class GRouterMatrix
|
|||
//
|
||||
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.
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -37,9 +37,10 @@ class RsGRouterSignedReceiptItem ;
|
|||
|
||||
static const uint16_t GROUTER_CLIENT_ID_MESSAGES = 0x1001 ;
|
||||
|
||||
static const uint32_t RS_GROUTER_MATRIX_MAX_HIT_ENTRIES = 10 ; // max number of clues to store
|
||||
static const uint32_t RS_GROUTER_MATRIX_MIN_TIME_BETWEEN_HITS = 60 ; // can be set to up to half the publish time interval. Prevents flooding routes.
|
||||
static const uint32_t RS_GROUTER_MIN_CONFIG_SAVE_PERIOD = 5 ; // at most save config every 5 seconds
|
||||
static const uint32_t RS_GROUTER_MATRIX_MAX_HIT_ENTRIES = 10 ; // max number of clues to store
|
||||
static const uint32_t RS_GROUTER_MATRIX_MIN_TIME_BETWEEN_HITS = 60 ; // can be set to up to half the publish time interval. Prevents flooding routes.
|
||||
static const uint32_t RS_GROUTER_MIN_CONFIG_SAVE_PERIOD = 5 ; // at most save config every 5 seconds
|
||||
static const uint32_t RS_GROUTER_MAX_KEEP_TRACKING_CLUES = 86400*10 ; // max time for which we keep record of tracking info: 10 days.
|
||||
|
||||
static const float RS_GROUTER_BASE_WEIGHT_ROUTED_MSG = 1.0f ; // base contribution of routed message clue to routing matrix
|
||||
static const float RS_GROUTER_BASE_WEIGHT_GXS_PACKET = 0.1f ; // base contribution of GXS message to routing matrix
|
||||
|
@ -56,7 +57,7 @@ static const uint32_t MAX_INACTIVE_DATA_PIPE_DELAY = 300 ; // cl
|
|||
|
||||
static const time_t RS_GROUTER_DEBUG_OUTPUT_PERIOD = 10 ; // Output everything
|
||||
static const time_t RS_GROUTER_AUTOWASH_PERIOD = 10 ; // Autowash every minute. Not a costly operation.
|
||||
static const time_t RS_GROUTER_MATRIX_UPDATE_PERIOD = 1 *10 ; // Check for key advertising every 10 minutes
|
||||
static const time_t RS_GROUTER_MATRIX_UPDATE_PERIOD = 60*10 ; // Check for key advertising every 10 minutes
|
||||
static const uint32_t GROUTER_ITEM_MAX_CACHE_KEEP_TIME = 2*86400 ; // Cached items are kept for 48 hours at most.
|
||||
|
||||
static const uint32_t RS_GROUTER_DATA_STATUS_UNKNOWN = 0x0000 ; // unknown. Unused.
|
||||
|
|
|
@ -252,6 +252,7 @@ int p3GRouter::tick()
|
|||
|
||||
_last_matrix_update_time = now ;
|
||||
_routing_matrix.updateRoutingProbabilities() ; // This should be locked.
|
||||
_routing_matrix.cleanUp() ; // This should be locked.
|
||||
}
|
||||
|
||||
#ifdef GROUTER_DEBUG
|
||||
|
@ -1698,6 +1699,14 @@ bool p3GRouter::locked_getClientAndServiceId(const TurtleFileHash& hash, const R
|
|||
return true ;
|
||||
}
|
||||
|
||||
void p3GRouter::addTrackingInfo(const RsGxsMessageId& mid,const RsPeerId& peer_id)
|
||||
{
|
||||
RS_STACK_MUTEX(grMtx) ;
|
||||
#ifdef GROUTER_DEBUG
|
||||
grouter_debug() << "Received new routing clue for key " << id << " from peer " << peer_id << std::endl;
|
||||
#endif
|
||||
_routing_matrix.addTrackingInfo(mid,peer_id) ;
|
||||
}
|
||||
void p3GRouter::addRoutingClue(const GRouterKeyId& id,const RsPeerId& peer_id)
|
||||
{
|
||||
RS_STACK_MUTEX(grMtx) ;
|
||||
|
|
|
@ -130,6 +130,7 @@ public:
|
|||
//===================================================//
|
||||
|
||||
virtual void addRoutingClue(const GRouterKeyId& id,const RsPeerId& peer_id) ;
|
||||
virtual void addTrackingInfo(const RsGxsMessageId& mid,const RsPeerId& peer_id) ;
|
||||
|
||||
//===================================================//
|
||||
// Client/server request services //
|
||||
|
@ -300,7 +301,6 @@ private:
|
|||
//
|
||||
GRouterMatrix _routing_matrix ;
|
||||
|
||||
|
||||
// Stores the keys which identify the router's node. For each key, a structure holds:
|
||||
// - the client service
|
||||
// - flags
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue