Merge branch 'master' into gxs_mail_experiments

This commit is contained in:
Gioacchino Mazzurco 2017-05-05 15:44:22 +02:00
commit 5159e326c7
335 changed files with 12307 additions and 24670 deletions

View file

@ -30,11 +30,12 @@
#include "util/rsnet.h"
#include "services/p3banlist.h"
#include "serialiser/rsbanlistitems.h"
#include "serialiser/rsconfigitems.h"
#include "retroshare/rsdht.h"
#include "retroshare/rsbanlist.h"
#include "rsitems/rsbanlistitems.h"
#include "rsitems/rsconfigitems.h"
#include <sys/time.h>
#include <sstream>
@ -66,8 +67,8 @@
*/
RsBanList *rsBanList = NULL ;
p3BanList::p3BanList(p3ServiceControl *sc, p3NetMgr *nm)
:p3Service(), mBanMtx("p3BanList"), mServiceCtrl(sc), mNetMgr(nm)
p3BanList::p3BanList(p3ServiceControl *sc, p3NetMgr */*nm*/)
:p3Service(), mBanMtx("p3BanList"), mServiceCtrl(sc)//, mNetMgr(nm)
{
addSerialType(new RsBanListSerialiser());

View file

@ -31,7 +31,7 @@
#include <list>
#include <map>
#include "serialiser/rsbanlistitems.h"
#include "rsitems/rsbanlistitems.h"
#include "services/p3service.h"
#include "retroshare/rsbanlist.h"
@ -148,7 +148,7 @@ private:
std::map<struct sockaddr_storage, BanListPeer> mWhiteListedRanges;
p3ServiceControl *mServiceCtrl;
p3NetMgr *mNetMgr;
//p3NetMgr *mNetMgr;
time_t mLastDhtInfoRequest ;
bool mIPFilteringEnabled ;

View file

@ -30,7 +30,7 @@
#include "util/rsnet.h"
#include "services/p3bwctrl.h"
#include "serialiser/rsbwctrlitems.h"
#include "rsitems/rsbwctrlitems.h"
#include <sys/time.h>

View file

@ -31,7 +31,7 @@
#include <list>
#include <map>
#include "serialiser/rsbwctrlitems.h"
#include "rsitems/rsbwctrlitems.h"
#include "services/p3service.h"
#include "pqi/pqiservicemonitor.h"
#include "retroshare/rsconfig.h" // for datatypes.

View file

@ -35,7 +35,7 @@
#include "pqi/p3netmgr.h"
#include "pqi/pqiservicemonitor.h"
#include "serialiser/rsdiscovery2items.h"
#include "rsitems/rsdiscovery2items.h"
#include "services/p3service.h"
#include "pqi/authgpg.h"

View file

@ -1,914 +0,0 @@
/*
* libretroshare/src/services/p3dsdv.h
*
* Network-Wide Routing Service.
*
* Copyright 2011 by Robert Fernie.
*
* 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 "retroshare@lunamutt.com".
*
*/
#include <list>
#include <string>
#include <time.h>
//#include "serialiser/rsdsdvitems.h"
#include "services/p3dsdv.h"
#include "pqi/p3linkmgr.h"
#include "util/rsrandom.h"
#include <openssl/sha.h>
/****
* #define DEBUG_DSDV 1
****/
#define DEBUG_DSDV 1
/* DEFINE INTERFACE POINTER! */
RsDsdv *rsDsdv = NULL;
/*****
* Routing Services are provided for any service or peer that wants to access / receive info
* over the internal network.
*
* This is going to be based loosely on Ben's Algorithm...
* Each Service / Peer is identified by a HASH.
* This HASH is disguised by a temporary ANON-CHUNK.
* DSDVID = Sha1(ANONCHUNK + HASH).
*
* Each peer can advertise as many Services as they want.
* The Anon-chunk should be rotated regularly to hide it well.
* period to be defined.
*
*
* Once this Routing table has been established, Routes can be created - in a similar manner to turtle paths.
* (Send Path request (Path Id + Origin + Destination))... path is established.
*
* Then we can do Onion Routing etc, on top of this.
*
****/
p3Dsdv::p3Dsdv(p3ServiceControl *sc)
:p3Service(), /* p3Config(CONFIG_TYPE_DSDV), */ mDsdvMtx("p3Dsdv"), mServiceCtrl(sc)
{
addSerialType(new RsDsdvSerialiser());
mSentTablesTime = 0;
mSentIncrementTime = 0;
}
const std::string DSDV_APP_NAME = "dsdv";
const uint16_t DSDV_APP_MAJOR_VERSION = 1;
const uint16_t DSDV_APP_MINOR_VERSION = 0;
const uint16_t DSDV_MIN_MAJOR_VERSION = 1;
const uint16_t DSDV_MIN_MINOR_VERSION = 0;
RsServiceInfo p3Dsdv::getServiceInfo()
{
return RsServiceInfo(RS_SERVICE_TYPE_DSDV,
DSDV_APP_NAME,
DSDV_APP_MAJOR_VERSION,
DSDV_APP_MINOR_VERSION,
DSDV_MIN_MAJOR_VERSION,
DSDV_MIN_MINOR_VERSION);
}
int p3Dsdv::tick()
{
processIncoming();
sendTables();
return 0;
}
int p3Dsdv::status()
{
return 1;
}
#define DSDV_BROADCAST_PERIOD (60*10) // 10 Minutes.
#define DSDV_MIN_INCREMENT_PERIOD 5
#define DSDV_DISCARD_PERIOD (DSDV_BROADCAST_PERIOD * 2)
int p3Dsdv::sendTables()
{
time_t now = time(NULL);
time_t tt, it;
bool updateRequired = false;
{
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
tt = mSentTablesTime;
it = mSentIncrementTime;
updateRequired = mSignificantChanges;
}
if (now - tt > DSDV_BROADCAST_PERIOD)
{
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::sendTables() Broadcast Time";
std::cerr << std::endl;
#endif
selectStableRoutes();
clearOldRoutes();
generateRoutingTables(false);
printDsdvTable(std::cerr);
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
mSentTablesTime = now;
mSentIncrementTime = now;
return true ;
}
/* otherwise send incremental changes */
if ((updateRequired) && (now - it > DSDV_MIN_INCREMENT_PERIOD))
{
selectStableRoutes();
generateRoutingTables(true);
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
mSentIncrementTime = now;
}
return true;
}
#define RSDSDV_SEQ_INCREMENT 2
void p3Dsdv::advanceLocalSequenceNumbers()
{
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
time_t now = time(NULL);
std::map<std::string, RsDsdvTableEntry>::iterator it;
for(it = mTable.begin(); it != mTable.end(); ++it)
{
RsDsdvTableEntry &v = (it->second);
if (v.mOwnSource)
{
v.mStableRoute.mSequence += RSDSDV_SEQ_INCREMENT;
v.mStableRoute.mReceived = now;
}
}
}
void p3Dsdv::clearSignificantChangesFlags()
{
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
std::map<std::string, RsDsdvTableEntry>::iterator it;
for(it = mTable.begin(); it != mTable.end(); ++it)
{
RsDsdvTableEntry &v = (it->second);
if (v.mFlags & RSDSDV_FLAGS_SIGNIFICANT_CHANGE)
{
v.mFlags &= ~RSDSDV_FLAGS_SIGNIFICANT_CHANGE;
}
}
mSignificantChanges = false;
}
int p3Dsdv::generateRoutingTables(bool incremental)
{
/* we ping our peers */
/* who is online? */
std::set<RsPeerId> idList;
mServiceCtrl->getPeersConnected(getServiceInfo().mServiceType, idList);
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::generateRoutingTables(" << incremental << ")";
std::cerr << std::endl;
#endif
if (!incremental)
{
/* now clear significant flag */
advanceLocalSequenceNumbers();
}
/* prepare packets */
std::set<RsPeerId>::iterator it;
for(it = idList.begin(); it != idList.end(); ++it)
{
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::generateRoutingTables() For: " << *it;
std::cerr << std::endl;
#endif
generateRoutingTable(*it, incremental);
}
/* now clear significant flag */
clearSignificantChangesFlags();
return 1;
}
int p3Dsdv::generateRoutingTable(const RsPeerId &peerId, bool incremental)
{
RsDsdvRouteItem *dsdv = new RsDsdvRouteItem();
dsdv->PeerId(peerId);
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
std::map<std::string, RsDsdvTableEntry>::iterator it;
for(it = mTable.begin(); it != mTable.end(); ++it)
{
RsDsdvTableEntry &v = (it->second);
/* discard/ignore criterion */
if (!v.mIsStable)
{
continue;
}
if (v.mStableRoute.mDistance >= RSDSDV_MAX_DISTANCE)
{
continue;
}
if (incremental)
{
if (v.mFlags & RSDSDV_FLAGS_SIGNIFICANT_CHANGE)
{
// Done elsewhere.
//v.mFlags &= ~SIGNIFICANT_CHANGE;
}
else
{
/* ignore non-significant changes */
continue;
}
}
RsTlvDsdvEntry entry;
entry.endPoint.idType = v.mDest.mIdType;
entry.endPoint.anonChunk = v.mDest.mAnonChunk;
entry.endPoint.serviceId = v.mDest.mHash;
entry.sequence = v.mStableRoute.mSequence;
entry.distance = v.mStableRoute.mDistance;
//dsdv->routes.entries.push_back(entry);
dsdv->routes.mList.push_back(entry);
//if (dsdv->routes.entries.size() > RSDSDV_MAX_ROUTE_TABLE)
if (dsdv->routes.mList.size() > RSDSDV_MAX_ROUTE_TABLE)
{
sendItem(dsdv);
dsdv = new RsDsdvRouteItem();
dsdv->PeerId(peerId);
}
}
sendItem(dsdv);
return 1;
}
/****************************************************************************
****************************************************************************/
int p3Dsdv::processIncoming()
{
/* for each packet - pass to specific handler */
RsItem *item = NULL;
while(NULL != (item = recvItem()))
{
switch(item->PacketSubType())
{
default:
break;
case RS_PKT_SUBTYPE_DSDV_ROUTE:
{
handleDSDV((RsDsdvRouteItem *) item);
}
break;
}
/* clean up */
delete item;
}
return true ;
}
int p3Dsdv::handleDSDV(RsDsdvRouteItem *dsdv)
{
/* iterate over the entries */
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
time_t now = time(NULL);
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::handleDSDV() Received Pkt from: " << dsdv->PeerId();
std::cerr << std::endl;
//dsdv->print(std::cerr);
//std::cerr << std::endl;
#endif
std::list<RsTlvDsdvEntry>::iterator it;
//for(it = dsdv->routes.entries.begin(); it != dsdv->routes.entries.end(); ++it)
for(it = dsdv->routes.mList.begin(); it != dsdv->routes.mList.end(); ++it)
{
/* check for existing */
RsTlvDsdvEntry &entry = *it;
uint32_t realDistance = entry.distance + 1; // metric.
/* find the entry */
std::map<std::string, RsDsdvTableEntry>::iterator tit;
tit = mTable.find(entry.endPoint.serviceId);
if (tit == mTable.end())
{
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::handleDSDV() Adding Entry for New ServiceId: ";
std::cerr << entry.endPoint.serviceId;
std::cerr << std::endl;
#endif
/* new entry! */
RsDsdvTableEntry v;
v.mDest.mIdType = entry.endPoint.idType;
v.mDest.mAnonChunk = entry.endPoint.anonChunk;
v.mDest.mHash = entry.endPoint.serviceId;
/* add as a possible route */
RsDsdvRoute newRoute;
newRoute.mNextHop = dsdv->PeerId();
newRoute.mReceived = now;
newRoute.mSequence = entry.sequence;
newRoute.mDistance = realDistance;
newRoute.mValidSince = now;
v.mAllRoutes[dsdv->PeerId()] = newRoute;
v.mIsStable = false;
v.mFlags = RSDSDV_FLAGS_NEW_ROUTE;
v.mOwnSource = false;
v.mMatched = false;
// store in table.
mTable[v.mDest.mHash] = v;
}
else
{
RsDsdvTableEntry &v = tit->second;
if (v.mOwnSource)
{
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::handleDSDV() Ignoring OwnSource Entry:";
std::cerr << entry.endPoint.serviceId;
std::cerr << std::endl;
#endif
continue; // Ignore if we are source.
}
/* look for this in mAllRoutes */
std::map<RsPeerId, RsDsdvRoute>::iterator rit;
rit = v.mAllRoutes.find(dsdv->PeerId());
if (rit == v.mAllRoutes.end())
{
/* add a new entry in */
RsDsdvRoute newRoute;
newRoute.mNextHop = dsdv->PeerId();
newRoute.mReceived = now;
newRoute.mSequence = entry.sequence;
newRoute.mDistance = realDistance;
newRoute.mValidSince = now;
v.mAllRoutes[dsdv->PeerId()] = newRoute;
/* if we've just added it in - can't be stable one */
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::handleDSDV() Adding NewRoute Entry:";
std::cerr << entry.endPoint.serviceId;
std::cerr << std::endl;
#endif
}
else
{
if (rit->second.mSequence >= entry.sequence)
{
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::handleDSDV() Ignoring OLDSEQ Entry:";
std::cerr << entry.endPoint.serviceId;
std::cerr << std::endl;
#endif
/* ignore same/old sequence number??? */
continue;
}
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::handleDSDV() Updating Entry:";
std::cerr << entry.endPoint.serviceId;
std::cerr << std::endl;
#endif
/* update seq,dist,etc */
if (rit->second.mSequence + 2 < entry.sequence)
{
/* skipped a sequence number - reset timer */
rit->second.mValidSince = now;
}
//rit->second.mNextHop; // unchanged.
rit->second.mReceived = now;
rit->second.mSequence = entry.sequence;
rit->second.mDistance = realDistance;
/* if consistent route... maintain */
if ((v.mIsStable) &&
(rit->second.mNextHop == v.mStableRoute.mNextHop))
{
v.mStableRoute = rit->second;
}
else
{
/* otherwise we need to wait - see if we get new update */
}
}
}
}
return 1;
}
int p3Dsdv::selectStableRoutes()
{
/* iterate over the entries */
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
time_t now = time(NULL);
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::selectStableRoutes()";
std::cerr << std::endl;
#endif
/* find the entry */
std::map<std::string, RsDsdvTableEntry>::iterator tit;
for(tit = mTable.begin(); tit != mTable.end(); ++tit)
{
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::selectStableRoutes() For Entry: ";
std::cerr << tit->second;
std::cerr << std::endl;
#endif
if (tit->second.mOwnSource)
{
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::selectStableRoutes() OwnSource... Ignoring";
std::cerr << std::endl;
#endif
continue; // Ignore if we are source.
}
std::map<RsPeerId, RsDsdvRoute>::iterator rit;
uint32_t newest = 0;
RsPeerId newestId;
uint32_t closest = RSDSDV_MAX_DISTANCE + 1;
RsPeerId closestId;
time_t closestAge = 0;
/* find newest sequence number */
for(rit = tit->second.mAllRoutes.begin();
rit != tit->second.mAllRoutes.end(); ++rit)
{
if ((now - rit->second.mReceived <= DSDV_DISCARD_PERIOD) &&
(rit->second.mSequence >= newest))
{
newest = rit->second.mSequence;
newestId = rit->first;
/* also becomes default for closest (later) */
closest = rit->second.mDistance;
closestId = rit->first;
closestAge = now - rit->second.mValidSince;
}
}
if (closest >= RSDSDV_MAX_DISTANCE + 1)
{
#ifdef DEBUG_DSDV
std::cerr << "\tNo Suitable Route";
std::cerr << std::endl;
#endif
tit->second.mIsStable = false;
continue;
}
uint32_t currseq = newest - (newest % 2); // remove 'kill'=ODD Seq.
#ifdef DEBUG_DSDV
std::cerr << "\t Newest Seq: " << newest << " from: " << newestId;
std::cerr << std::endl;
#endif
/* find closest distance - with valid seq & max valid time */
for(rit = tit->second.mAllRoutes.begin();
rit != tit->second.mAllRoutes.end(); ++rit)
{
/* Maximum difference in Sequence number is 2*DISTANCE
* Otherwise it must be old.
*/
if (rit->second.mSequence + rit->second.mDistance * 2 < currseq)
{
#ifdef DEBUG_DSDV
std::cerr << "\t\tIgnoring OLD SEQ Entry: " << rit->first;
std::cerr << std::endl;
#endif
continue; // ignore.
}
/* if we haven't received an update in ages - old */
if (now - rit->second.mReceived > DSDV_DISCARD_PERIOD)
{
#ifdef DEBUG_DSDV
std::cerr << "\t\tIgnoring OLD TIME Entry: " << rit->first;
std::cerr << std::endl;
#endif
continue; // ignore.
}
if (rit->second.mDistance < closest)
{
closest = rit->second.mDistance;
closestId = rit->first;
closestAge = now - rit->second.mValidSince;
#ifdef DEBUG_DSDV
std::cerr << "\t\tUpdating to Closer Entry: " << rit->first;
std::cerr << std::endl;
#endif
}
else if ((rit->second.mDistance == closest) &&
(closestAge < now - rit->second.mValidSince))
{
/* have a more stable (older) one */
closest = rit->second.mDistance;
closestId = rit->first;
closestAge = now - rit->second.mValidSince;
#ifdef DEBUG_DSDV
std::cerr << "\t\tUpdating to Stabler Entry: " << rit->first;
std::cerr << std::endl;
#endif
}
else
{
#ifdef DEBUG_DSDV
std::cerr << "\t\tIgnoring Distant Entry: " << rit->first;
std::cerr << std::endl;
#endif
}
}
tit->second.mIsStable = true;
rit = tit->second.mAllRoutes.find(closestId);
tit->second.mStableRoute = rit->second;
tit->second.mFlags &= ~RSDSDV_FLAGS_NEW_ROUTE;
#ifdef DEBUG_DSDV
std::cerr << "\tStable Route: " << tit->second.mStableRoute;
std::cerr << std::endl;
#endif
}
return 1;
}
int p3Dsdv::clearOldRoutes()
{
/* iterate over the entries */
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::clearOldRoutes()";
std::cerr << std::endl;
#endif
/* find the entry */
std::map<std::string, RsDsdvTableEntry>::iterator it, it2;
for(it = mTable.begin(); it != mTable.end(); ++it)
{
if (it->second.mOwnSource)
{
continue;
}
if (it->second.mIsStable)
{
continue;
}
if (it->second.mFlags & RSDSDV_FLAGS_NEW_ROUTE)
{
continue;
}
/* backstep iterator for loop, and delete original */
it2 = it;
it--;
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::clearOldRoutes() Deleting OLD ServiceId: " << it2->first;
std::cerr << std::endl;
#endif
mTable.erase(it2);
}
return 1;
}
/*************** pqiMonitor callback ***********************/
void p3Dsdv::statusChange(const std::list<pqiServicePeer> &plist)
{
std::list<pqiServicePeer>::const_iterator it;
for(it = plist.begin(); it != plist.end(); ++it)
{
/* only care about disconnected / not friends cases */
if ( 1 )
{
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
}
}
}
int p3Dsdv::addTestService()
{
RsDsdvId testId;
int rndhash1[SHA_DIGEST_LENGTH / 4];
int rndhash2[SHA_DIGEST_LENGTH / 4];
std::string realHash;
std::string seedHash;
for(int i = 0; i < SHA_DIGEST_LENGTH / 4; i++)
{
rndhash1[i] = RSRandom::random_u32();
rndhash2[i] = RSRandom::random_u32();
}
for(int i = 0; i < SHA_DIGEST_LENGTH; i++)
{
rs_sprintf_append(realHash, "%02x", (uint32_t) ((uint8_t *) rndhash1)[i]);
rs_sprintf_append(seedHash, "%02x", (uint32_t) ((uint8_t *) rndhash2)[i]);
}
uint8_t sha_hash[SHA_DIGEST_LENGTH];
memset(sha_hash,0,SHA_DIGEST_LENGTH*sizeof(uint8_t)) ;
SHA_CTX *sha_ctx = new SHA_CTX;
SHA1_Init(sha_ctx);
SHA1_Update(sha_ctx, realHash.c_str(), realHash.length());
SHA1_Update(sha_ctx, seedHash.c_str(), seedHash.length());
SHA1_Final(sha_hash, sha_ctx);
delete sha_ctx;
for(int i = 0; i < SHA_DIGEST_LENGTH; i++)
{
rs_sprintf_append(testId.mHash, "%02x", (uint32_t) (sha_hash)[i]);
}
testId.mIdType = RSDSDV_IDTYPE_TEST;
testId.mAnonChunk = seedHash;
addDsdvId(&testId, realHash);
return 1;
}
int p3Dsdv::addDsdvId(RsDsdvId *id, std::string realHash)
{
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::addDsdvId() ID: " << *id << " RealHash: " << realHash;
std::cerr << std::endl;
#endif
time_t now = time(NULL);
/* check for duplicate */
std::map<std::string, RsDsdvTableEntry>::iterator it;
it = mTable.find(id->mHash);
if (it != mTable.end())
{
/* error */
std::cerr << "p3Dsdv::addDsdvId() ERROR Duplicate ID";
std::cerr << std::endl;
return 0;
}
/* new entry! */
RsDsdvTableEntry v;
v.mDest = *id;
v.mStableRoute.mNextHop = mServiceCtrl->getOwnId();
v.mStableRoute.mReceived = now;
v.mStableRoute.mValidSince = now;
v.mStableRoute.mSequence = 0;
v.mStableRoute.mDistance = 0;
v.mIsStable = true;
v.mFlags = RSDSDV_FLAGS_OWN_SERVICE;
v.mOwnSource = true;
v.mMatched = true;
v.mMatchedHash = realHash;
// store in table.
mTable[v.mDest.mHash] = v;
return 1;
}
int p3Dsdv::dropDsdvId(RsDsdvId *id)
{
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
#ifdef DEBUG_DSDV
std::cerr << "p3Dsdv::dropDsdvId() ID: " << *id;
std::cerr << std::endl;
#endif
/* This should send out an infinity packet... and flag for deletion */
std::map<std::string, RsDsdvTableEntry>::iterator it;
it = mTable.find(id->mHash);
if (it == mTable.end())
{
/* error */
std::cerr << "p3Dsdv::addDsdvId() ERROR Unknown ID";
std::cerr << std::endl;
return 0;
}
mTable.erase(it);
return 1;
}
int p3Dsdv::printDsdvTable(std::ostream &out)
{
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
/* iterate over the entries */
std::map<std::string, RsDsdvTableEntry>::iterator it;
for(it = mTable.begin(); it != mTable.end(); ++it)
{
RsDsdvTableEntry &v = it->second;
out << v;
out << std::endl;
}
return 1;
}
/*****************************************/
uint32_t p3Dsdv::getLocalServices(std::list<std::string> &hashes)
{
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
/* iterate over the entries */
std::map<std::string, RsDsdvTableEntry>::iterator it;
for(it = mTable.begin(); it != mTable.end(); ++it)
{
if (it->second.mOwnSource)
{
hashes.push_back(it->first);
}
}
return 1;
}
uint32_t p3Dsdv::getAllServices(std::list<std::string> &hashes)
{
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
/* iterate over the entries */
std::map<std::string, RsDsdvTableEntry>::iterator it;
for(it = mTable.begin(); it != mTable.end(); ++it)
{
hashes.push_back(it->first);
}
return 1;
}
int p3Dsdv::getDsdvEntry(const std::string &hash, RsDsdvTableEntry &entry)
{
RsStackMutex stack(mDsdvMtx); /****** LOCKED MUTEX *******/
/* iterate over the entries */
std::map<std::string, RsDsdvTableEntry>::iterator it;
it = mTable.find(hash);
if (it == mTable.end())
{
return 0;
}
entry = it->second;
return 1;
}
std::ostream &operator<<(std::ostream &out, const RsDsdvId &id)
{
out << "[Type: " << id.mIdType << " AMZ: " << id.mAnonChunk << " THASH: " << id.mHash;
out << "]";
return out;
}
std::ostream &operator<<(std::ostream &out, const RsDsdvRoute &route)
{
time_t now = time(NULL);
out << "< Seq: " << route.mSequence << " Dist: " << route.mDistance;
out << " NextHop: " << route.mNextHop;
out << " recvd: " << now-route.mReceived;
out << " validSince: " << now-route.mValidSince;
out << " >";
return out;
}
std::ostream &operator<<(std::ostream &out, const RsDsdvTableEntry &entry)
{
out << "DSDV Route for: " << entry.mDest << std::endl;
if (entry.mIsStable)
{
out << "\tStable: " << entry.mStableRoute << std::endl;
}
else
{
out << "\tNo Stable Route" << std::endl;
}
out << "\tOwnSource: " << entry.mOwnSource;
out << " Flags: " << entry.mFlags;
if (entry.mMatched)
{
out << " Matched: " << entry.mMatchedHash;
}
else
{
out << " Non Matched";
}
out << std::endl;
if (entry.mAllRoutes.size() > 0)
{
out << "\tAll Routes:" << std::endl;
}
std::map<RsPeerId, RsDsdvRoute>::const_iterator it;
for(it = entry.mAllRoutes.begin(); it != entry.mAllRoutes.end(); ++it)
{
out << "\t\t" << it->second << std::endl;
}
return out;
}

View file

@ -1,123 +0,0 @@
/*
* libretroshare/src/services/p3dsdv.h
*
* Network-Wide Routing Service.
*
* Copyright 2011 by Robert Fernie.
*
* 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 "retroshare@lunamutt.com".
*
*/
#ifndef SERVICE_RSDSDV_HEADER
#define SERVICE_RSDSDV_HEADER
#include <list>
#include <string>
#include "serialiser/rsdsdvitems.h"
#include "services/p3service.h"
#include "pqi/p3cfgmgr.h"
#include "pqi/pqimonitor.h"
#include "retroshare/rsdsdv.h"
class p3ServiceControl;
#define RSDSDV_MAX_DISTANCE 3
#define RSDSDV_MAX_SEND_TABLE 100
//!The RS DSDV service.
/**
*
* Finds RS wide paths to Services and Peers.
*/
class p3Dsdv: public RsDsdv, public p3Service /* , public p3Config */, public pqiServiceMonitor
{
public:
p3Dsdv(p3ServiceControl *cm);
virtual RsServiceInfo getServiceInfo();
/*** internal librs interface ****/
int addDsdvId(RsDsdvId *id, std::string realHash);
int dropDsdvId(RsDsdvId *id);
int printDsdvTable(std::ostream &out);
int addTestService();
private:
int sendTables();
void advanceLocalSequenceNumbers();
void clearSignificantChangesFlags();
int generateRoutingTables(bool incremental);
int generateRoutingTable(const RsPeerId &peerId, bool incremental);
int processIncoming();
int handleDSDV(RsDsdvRouteItem *dsdv);
int selectStableRoutes();
int clearOldRoutes();
public:
/***** overloaded from rsDsdv *****/
virtual uint32_t getLocalServices(std::list<std::string> &hashes);
virtual uint32_t getAllServices(std::list<std::string> &hashes);
virtual int getDsdvEntry(const std::string &hash, RsDsdvTableEntry &entry);
/***** overloaded from p3Service *****/
/*!
* Process stuff.
*/
virtual int tick();
virtual int status();
/*************** pqiMonitor callback ***********************/
virtual void statusChange(const std::list<pqiServicePeer> &plist);
/************* from p3Config *******************/
//virtual RsSerialiser *setupSerialiser() ;
//virtual bool saveList(bool& cleanup, std::list<RsItem*>&) ;
//virtual void saveDone();
//virtual bool loadList(std::list<RsItem*>& load) ;
private:
RsMutex mDsdvMtx;
std::map<std::string, RsDsdvTableEntry> mTable;
time_t mSentTablesTime;
time_t mSentIncrementTime;
bool mSignificantChanges;
p3ServiceControl *mServiceCtrl;
};
#endif // SERVICE_RSDSDV_HEADER

View file

@ -24,7 +24,7 @@
*/
#include "services/p3gxschannels.h"
#include "serialiser/rsgxschannelitems.h"
#include "rsitems/rsgxschannelitems.h"
#include "util/radix64.h"
#include "util/rsmemory.h"

View file

@ -23,8 +23,9 @@
*
*/
#include "rsitems/rsgxscircleitems.h"
#include "services/p3gxscircles.h"
#include "serialiser/rsgxscircleitems.h"
#include "retroshare/rsgxsflags.h"
#include "util/rsrandom.h"
#include "util/rsdir.h"

View file

@ -25,7 +25,7 @@
#include "retroshare/rsgxscommon.h"
#include "services/p3gxscommon.h"
#include "serialiser/rsgxscommentitems.h"
#include "rsitems/rsgxscommentitems.h"
#include "util/rsstring.h"
#include <stdio.h>

View file

@ -24,7 +24,7 @@
*/
#include "services/p3gxsforums.h"
#include "serialiser/rsgxsforumitems.h"
#include "rsitems/rsgxsforumitems.h"
#include <retroshare/rsidentity.h>

View file

@ -29,8 +29,9 @@
#include "retroshare/rspeers.h"
#include "services/p3gxsreputation.h"
#include "serialiser/rsgxsreputationitems.h"
#include "serialiser/rsconfigitems.h"
#include "rsitems/rsgxsreputationitems.h"
#include "rsitems/rsconfigitems.h"
#include <sys/time.h>
@ -1035,7 +1036,7 @@ bool p3GxsReputation::setOwnOpinion(const RsGxsId& gxsid, const RsReputations::O
if (rit == mReputations.end())
{
#warning we should set the owner node id here.
#warning csoler 2017-01-05: We should set the owner node id here.
mReputations[gxsid] = Reputation(gxsid);
rit = mReputations.find(gxsid);
}
@ -1210,6 +1211,7 @@ bool p3GxsReputation::loadList(std::list<RsItem *>& loadList)
if (set)
loadReputationSet(set, peerSet);
#ifdef TO_REMOVE
RsGxsReputationSetItem_deprecated3 *set2 = dynamic_cast<RsGxsReputationSetItem_deprecated3 *>(*it);
if(set2)
@ -1217,6 +1219,7 @@ bool p3GxsReputation::loadList(std::list<RsItem *>& loadList)
std::cerr << "(II) reading and converting old format ReputationSetItem." << std::endl;
loadReputationSet_deprecated3(set2, peerSet);
}
#endif
RsGxsReputationBannedNodeSetItem *itm2 = dynamic_cast<RsGxsReputationBannedNodeSetItem*>(*it) ;
@ -1274,6 +1277,7 @@ bool p3GxsReputation::loadList(std::list<RsItem *>& loadList)
loadList.clear() ;
return true;
}
#ifdef TO_REMOVE
bool p3GxsReputation::loadReputationSet_deprecated3(RsGxsReputationSetItem_deprecated3 *item, const std::set<RsPeerId> &peerSet)
{
{
@ -1324,7 +1328,7 @@ bool p3GxsReputation::loadReputationSet_deprecated3(RsGxsReputationSetItem_depre
#endif
return true;
}
#endif
bool p3GxsReputation::loadReputationSet(RsGxsReputationSetItem *item, const std::set<RsPeerId> &peerSet)
{

View file

@ -36,7 +36,7 @@ static const uint32_t REPUTATION_IDENTITY_FLAG_UP_TO_DATE = 0x0100; // This
static const uint32_t REPUTATION_IDENTITY_FLAG_PGP_LINKED = 0x0001;
static const uint32_t REPUTATION_IDENTITY_FLAG_PGP_KNOWN = 0x0002;
#include "serialiser/rsgxsreputationitems.h"
#include "rsitems/rsgxsreputationitems.h"
#include "retroshare/rsidentity.h"
#include "retroshare/rsreputations.h"
@ -156,7 +156,9 @@ private:
// internal update of data. Takes care of cleaning empty boxes.
void locked_updateOpinion(const RsPeerId &from, const RsGxsId &about, RsReputations::Opinion op);
bool loadReputationSet(RsGxsReputationSetItem *item, const std::set<RsPeerId> &peerSet);
#ifdef TO_REMOVE
bool loadReputationSet_deprecated3(RsGxsReputationSetItem_deprecated3 *item, const std::set<RsPeerId> &peerSet);
#endif
int sendPackets();
void cleanup();
void sendReputationRequests();
@ -174,7 +176,7 @@ private:
time_t mLastIdentityFlagsUpdate ;
bool mReputationsUpdated;
float mAutoBanIdentitiesLimit ;
//float mAutoBanIdentitiesLimit ;
bool mAutoSetPositiveOptionToContacts;
p3LinkMgr *mLinkMgr;

View file

@ -26,7 +26,7 @@
#include <time.h>
#include "services/p3heartbeat.h"
#include "serialiser/rsheartbeatitems.h"
#include "rsitems/rsheartbeatitems.h"
#include "pqi/p3servicecontrol.h"
#include "pqi/pqipersongrp.h"

View file

@ -27,8 +27,8 @@
#include "services/p3idservice.h"
#include "pgp/pgpauxutils.h"
#include "serialiser/rsgxsiditems.h"
#include "serialiser/rsconfigitems.h"
#include "rsitems/rsgxsiditems.h"
#include "rsitems/rsconfigitems.h"
#include "retroshare/rsgxsflags.h"
#include "util/rsrandom.h"
#include "util/rsstring.h"
@ -70,6 +70,8 @@ static const time_t MAX_KEEP_KEYS_SIGNED_KNOWN = 30 * 86400 ; // signed ident
static const uint32_t MAX_DELAY_BEFORE_CLEANING= 1800 ; // clean old keys every 30 mins
static const uint32_t MAX_SERIALISED_IDENTITY_AGE = 600 ; // after 10 mins, a serialised identity record must be renewed.
RsIdentity *rsIdentity = NULL;
/******
@ -97,13 +99,12 @@ RsIdentity *rsIdentity = NULL;
#define BG_REPUTATION 3
#define GXSIDREQ_CACHELOAD 0x0001
#define GXSIDREQ_CACHEOWNIDS 0x0002
#define GXSIDREQ_PGPHASH 0x0010
#define GXSIDREQ_RECOGN 0x0020
#define GXSIDREQ_OPINION 0x0030
#define GXSIDREQ_CACHELOAD 0x0001
#define GXSIDREQ_CACHEOWNIDS 0x0002
#define GXSIDREQ_PGPHASH 0x0010
#define GXSIDREQ_RECOGN 0x0020
#define GXSIDREQ_OPINION 0x0030
#define GXSIDREQ_SERIALIZE_TO_MEMORY 0x0040
#define GXSIDREQ_CACHETEST 0x1000
@ -697,6 +698,84 @@ bool p3IdService::getOwnIds(std::list<RsGxsId> &ownIds)
return true ;
}
bool p3IdService::serialiseIdentityToMemory(const RsGxsId& id,std::string& radix_string)
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
// look into cache. If available, return the data. If not, request it.
std::map<RsGxsId,SerialisedIdentityStruct>::const_iterator it = mSerialisedIdentities.find(id);
if(it != mSerialisedIdentities.end())
{
Radix64::encode(it->second.mMem,it->second.mSize,radix_string) ;
if(it->second.mLastUsageTS + MAX_SERIALISED_IDENTITY_AGE > time(NULL))
return true ;
std::cerr << "Identity " << id << " will be re-serialised, because the last record is too old." << std::endl;
}
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
uint32_t token = 0;
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(RsGxsGroupId(id)) ;
RsGenExchange::getTokenService()->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds);
GxsTokenQueue::queueRequest(token, GXSIDREQ_SERIALIZE_TO_MEMORY);
return false;
}
void p3IdService::handle_get_serialized_grp(uint32_t token)
{
// store the serialized data in cache.
unsigned char *mem = NULL;
uint32_t size;
RsGxsGroupId id ;
if(!RsGenExchange::getSerializedGroupData(token,id, mem,size))
{
std::cerr << "(EE) call to RsGenExchage::getSerializedGroupData() failed." << std::endl;
return ;
}
std::cerr << "Received serialised group from RsGenExchange." << std::endl;
std::map<RsGxsId,SerialisedIdentityStruct>::const_iterator it = mSerialisedIdentities.find(RsGxsId(id));
if(it != mSerialisedIdentities.end())
free(it->second.mMem) ;
SerialisedIdentityStruct s ;
s.mMem = mem ;
s.mSize = size ;
s.mLastUsageTS = time(NULL) ;
mSerialisedIdentities[RsGxsId(id)] = s ;
}
bool p3IdService::deserialiseIdentityFromMemory(const std::string& radix_string)
{
std::vector<uint8_t> mem = Radix64::decode(radix_string) ;
if(mem.empty())
{
std::cerr << "Cannot decode radix string \"" << radix_string << "\"" << std::endl;
return false ;
}
if(!RsGenExchange::deserializeGroupData(mem.data(),mem.size()))
{
std::cerr << "Cannot load identity from radix string \"" << radix_string << "\"" << std::endl;
return false ;
}
return true ;
}
bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters &params)
{
@ -709,7 +788,7 @@ bool p3IdService::createIdentity(uint32_t& token, RsIdentityParameters &params)
if (params.isPgpLinked)
{
#warning Backward compatibility issue to fix here in v0.7.0
#warning csoler 2017-02-07: Backward compatibility issue to fix here in v0.7.0
// This is a hack, because a bad decision led to having RSGXSID_GROUPFLAG_REALID be equal to GXS_SERV::FLAG_PRIVACY_PRIVATE.
// In order to keep backward compatibility, we'll also add the new value
@ -1587,6 +1666,28 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup>
return ok;
}
bool p3IdService::getGroupSerializedData(const uint32_t &token, std::map<RsGxsId,std::string>& serialized_groups)
{
unsigned char *mem = NULL;
uint32_t size;
RsGxsGroupId id ;
serialized_groups.clear() ;
if(!RsGenExchange::getSerializedGroupData(token,id, mem,size))
{
std::cerr << "(EE) call to RsGenExchage::getSerializedGroupData() failed." << std::endl;
return false;
}
std::string radix ;
Radix64::encode(mem,size,radix) ;
serialized_groups[RsGxsId(id)] = radix ;
return true;
}
/********************************************************************************/
/********************************************************************************/
@ -4309,6 +4410,9 @@ void p3IdService::handleResponse(uint32_t token, uint32_t req_type)
case GXSIDREQ_OPINION:
opinion_handlerequest(token);
break;
case GXSIDREQ_SERIALIZE_TO_MEMORY:
handle_get_serialized_grp(token) ;
default:
/* error */
std::cerr << "p3IdService::handleResponse() Unknown Request Type: " << req_type;

View file

@ -32,7 +32,7 @@
#include "gxs/rsgixs.h" // Internal Interfaces.
#include "gxs/gxstokenqueue.h"
#include "serialiser/rsgxsiditems.h"
#include "rsitems/rsgxsiditems.h"
#include <map>
#include <string>
@ -43,7 +43,7 @@
#include "pqi/authgpg.h"
#include "serialiser/rsgxsrecognitems.h"
#include "rsitems/rsgxsrecognitems.h"
class PgpAuxUtils;
@ -212,6 +212,13 @@ private:
void init(const RsGxsIdGroupItem *item, const RsTlvPublicRSAKey& in_pub_key, const RsTlvPrivateRSAKey& in_priv_key,const std::list<RsRecognTag> &tagList);
};
struct SerialisedIdentityStruct
{
unsigned char *mMem ;
uint32_t mSize ;
time_t mLastUsageTS;
};
// Not sure exactly what should be inherited here?
// Chris - please correct as necessary.
@ -238,6 +245,8 @@ public:
// These are exposed via RsIdentity.
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup> &groups);
virtual bool getGroupSerializedData(const uint32_t &token, std::map<RsGxsId,std::string>& serialized_groups);
//virtual bool getMsgData(const uint32_t &token, std::vector<RsGxsIdOpinion> &opinions);
// These are local - and not exposed via RsIdentity.
@ -341,6 +350,8 @@ public:
const RsIdentityUsage &use_info );
virtual bool requestPrivateKey(const RsGxsId &id);
virtual bool serialiseIdentityToMemory(const RsGxsId& id,std::string& radix_string);
virtual bool deserialiseIdentityFromMemory(const std::string& radix_string);
/**************** RsGixsReputation Implementation ****************/
@ -433,6 +444,12 @@ private:
bool mBgSchedule_Active;
uint32_t mBgSchedule_Mode;
/***********************************8
* Fonction to receive and handle group serialisation to memory
*/
virtual void handle_get_serialized_grp(uint32_t token);
/************************************************************************
* pgphash processing.
*
@ -563,6 +580,8 @@ private:
std::map<RsGxsId, std::list<RsPeerId> > mIdsNotPresent;
std::map<RsGxsId,keyTSInfo> mKeysTS ;
std::map<RsGxsId,SerialisedIdentityStruct> mSerialisedIdentities ;
// keep a list of regular contacts. This is useful to sort IDs, and allow some services to priviledged ids only.
std::set<RsGxsId> mContacts;
RsNetworkExchangeService* mNes;

View file

@ -41,7 +41,8 @@
#include "pgp/pgpkeyutil.h"
#include "rsserver/p3face.h"
#include "serialiser/rsconfigitems.h"
#include "rsitems/rsconfigitems.h"
#include "grouter/p3grouter.h"
#include "grouter/groutertypes.h"
@ -93,9 +94,7 @@ p3MsgService::p3MsgService( p3ServiceControl *sc, p3IdService *id_serv,
recentlyReceivedMutex("p3MsgService recently received hash mutex"),
mGxsTransServ(gxsMS)
{
/* this serialiser is used for services. It's not the same than the one
* returned by setupSerialiser(). We need both!! */
_serialiser = new RsMsgSerialiser();
_serialiser = new RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE); // this serialiser is used for services. It's not the same than the one returned by setupSerialiser(). We need both!!
addSerialType(_serialiser);
/* MsgIds are not transmitted, but only used locally as a storage index.
@ -531,7 +530,7 @@ RsSerialiser* p3MsgService::setupSerialiser() // this serialiser is used for con
{
RsSerialiser *rss = new RsSerialiser ;
rss->addSerialType(new RsMsgSerialiser(true));
rss->addSerialType(new RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_CONFIG));
rss->addSerialType(new RsGeneralConfigSerialiser());
return rss;
@ -2243,15 +2242,14 @@ void p3MsgService::sendDistantMsgItem(RsMsgItem *msgitem)
/* The item is serialized and turned into a generic turtle item. Use use the
* explicit serialiser to make sure that the msgId is not included */
uint32_t msg_serialized_rssize = msgitem->serial_size(false);
RsTemporaryMemory msg_serialized_data(msg_serialized_rssize);
uint32_t msg_serialized_rssize = RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE).size(msgitem) ;
RsTemporaryMemory msg_serialized_data(msg_serialized_rssize) ;
if(!msgitem->serialise(msg_serialized_data,msg_serialized_rssize,false))
{
std::cerr << "(EE) p3MsgService::sendTurtleData(): Serialization error."
<< std::endl;
return;
}
if(!RsMsgSerialiser(RsServiceSerializer::SERIALIZATION_FLAG_NONE).serialise(msgitem,msg_serialized_data,&msg_serialized_rssize))
{
std::cerr << "(EE) p3MsgService::sendTurtleData(): Serialization error." << std::endl;
return ;
}
#ifdef DEBUG_DISTANT_MSG
std::cerr << " serialised size : " << msg_serialized_rssize << std::endl;
#endif

View file

@ -40,7 +40,7 @@
#include "pqi/p3cfgmgr.h"
#include "services/p3service.h"
#include "serialiser/rsmsgitems.h"
#include "rsitems/rsmsgitems.h"
#include "util/rsthreads.h"
#include "retroshare/rsgxsifacetypes.h"

View file

@ -1,5 +1,5 @@
#include "p3photoservice.h"
#include "serialiser/rsphotoitems.h"
#include "rsitems/rsphotoitems.h"
#include "retroshare/rsgxsflags.h"
RsPhoto *rsPhoto = NULL;

View file

@ -30,7 +30,7 @@
#include <math.h>
#include "services/p3postbase.h"
#include "serialiser/rsgxscommentitems.h"
#include "rsitems/rsgxscommentitems.h"
#include "rsserver/p3face.h"
#include "retroshare/rsnotify.h"

View file

@ -24,7 +24,7 @@
*/
#include "services/p3posted.h"
#include "serialiser/rsposteditems.h"
#include "rsitems/rsposteditems.h"
#include <math.h>
@ -156,6 +156,7 @@ bool p3Posted::getPostData(const uint32_t &token, std::vector<RsPostedPost> &msg
std::cerr << "Not a PostedPostItem neither a RsGxsCommentItem"
<< " PacketService=" << std::hex << (int)msg->PacketService() << std::dec
<< " PacketSubType=" << std::hex << (int)msg->PacketSubType() << std::dec
<< " type name =" << typeid(*msg).name()
<< " , deleting!" << std::endl;
delete *vit;
}

View file

@ -30,11 +30,13 @@
#include "pqi/pqibin.h"
#include "pqi/pqistore.h"
#include "pqi/p3linkmgr.h"
#include "rsserver/p3face.h"
#include "services/p3rtt.h"
#include "serialiser/rsrttitems.h"
#include "rsitems/rsrttitems.h"
#include <sys/time.h>
#include <math.h>
/****
* #define DEBUG_RTT 1
@ -358,7 +360,26 @@ int p3rtt::storePongResult(const RsPeerId& id, uint32_t counter, double recv_ts,
peerInfo->mPongResults.pop_front();
}
/* should do calculations */
//Wait at least 20 pongs before compute mean time offset
if(peerInfo->mPongResults.size() > 20)
{
double mean = 0;
for(std::list<RsRttPongResult>::const_iterator prIt = peerInfo->mPongResults.begin(), end = peerInfo->mPongResults.end(); prIt != end; ++ prIt)
{
mean += prIt->mOffset;
}
peerInfo->mCurrentMeanOffset = mean / peerInfo->mPongResults.size();
if(fabs(peerInfo->mCurrentMeanOffset) > 120)
{
p3Notify *notify = RsServer::notify();
if (notify)
{
//notify->AddPopupMessage(RS_POPUP_OFFSET, eerInfo->mId.toStdString(),"", "Time Offset: ");
notify->AddFeedItem(RS_FEED_ITEM_PEER_OFFSET, peerInfo->mId.toStdString());
}
std::cerr << "(WW) Peer:" << peerInfo->mId << " get time offset more than two minutes with you!!!" << std::endl;
}
}
return 1;
}
@ -379,7 +400,16 @@ uint32_t p3rtt::getPongResults(const RsPeerId& id, int n, std::list<RsRttPongRes
return i ;
}
double p3rtt::getMeanOffset(const RsPeerId &id)
{
RsStackMutex stack(mRttMtx); /****** LOCKED MUTEX *******/
RttPeerInfo *peer = locked_GetPeerInfo(id);
if(peer)
return peer->mCurrentMeanOffset;
else
return 0;
}
RttPeerInfo *p3rtt::locked_GetPeerInfo(const RsPeerId& id)
{

View file

@ -30,7 +30,7 @@
#include <list>
#include <string>
#include "serialiser/rsrttitems.h"
#include "rsitems/rsrttitems.h"
#include "services/p3service.h"
#include "retroshare/rsrtt.h"
@ -46,6 +46,7 @@ class RttPeerInfo
double mCurrentPingTS;
double mCurrentPingCounter;
bool mCurrentPongRecvd;
double mCurrentMeanOffset;
uint32_t mLostPongs;
uint32_t mSentPings;
@ -69,6 +70,7 @@ virtual RsServiceInfo getServiceInfo();
/***** overloaded from rsRtt *****/
virtual uint32_t getPongResults(const RsPeerId& id, int n, std::list<RsRttPongResult> &results);
virtual double getMeanOffset(const RsPeerId &id);
/***** overloaded from p3Service *****/

View file

@ -23,6 +23,8 @@
*
*/
#include "rsitems/itempriorities.h"
#include "pqi/pqi.h"
#include "util/rsstring.h"
#include "services/p3service.h"

View file

@ -29,7 +29,7 @@
#include "util/rsnet.h"
#include "services/p3serviceinfo.h"
#include "serialiser/rsbanlistitems.h"
#include "rsitems/rsbanlistitems.h"
#include <sys/time.h>

View file

@ -36,7 +36,7 @@
#include "services/p3service.h"
#include "serialiser/rsserviceinfoitems.h"
#include "rsitems/rsserviceinfoitems.h"
//!The ServiceInfo service.
/**

View file

@ -24,7 +24,7 @@
*/
#include "services/p3statusservice.h"
#include "serialiser/rsstatusitems.h"
#include "rsitems/rsstatusitems.h"
#include "rsserver/p3face.h"
#include "retroshare/rsiface.h"

View file

@ -29,7 +29,7 @@
#include <map>
#include <list>
#include "serialiser/rsstatusitems.h"
#include "rsitems/rsstatusitems.h"
#include "retroshare/rsstatus.h"
#include "services/p3service.h"
#include "pqi/p3cfgmgr.h"

View file

@ -25,7 +25,7 @@
#include "services/p3wiki.h"
#include "retroshare/rsgxsflags.h"
#include "serialiser/rswikiitems.h"
#include "rsitems/rswikiitems.h"
#include "util/rsrandom.h"

View file

@ -24,7 +24,7 @@
*/
#include "services/p3wire.h"
#include "serialiser/rswireitems.h"
#include "rsitems/rswireitems.h"
#include "util/rsrandom.h"