Merge pull request #789 from PhenomRetroShare/Add_FriendTimeOffsetNewsFeed

Add Friend Time Offset news feed.
This commit is contained in:
csoler 2017-04-30 22:43:10 +02:00 committed by GitHub
commit 3d17d31e49
9 changed files with 172 additions and 42 deletions

View file

@ -78,15 +78,16 @@ const uint32_t RS_FEED_TYPE_SECURITY = 0x0800;
const uint32_t RS_FEED_TYPE_POSTED = 0x1000;
const uint32_t RS_FEED_TYPE_SECURITY_IP = 0x2000;
const uint32_t RS_FEED_ITEM_PEER_CONNECT = RS_FEED_TYPE_PEER | 0x0001;
const uint32_t RS_FEED_ITEM_PEER_DISCONNECT = RS_FEED_TYPE_PEER | 0x0002;
const uint32_t RS_FEED_ITEM_PEER_HELLO = RS_FEED_TYPE_PEER | 0x0003;
const uint32_t RS_FEED_ITEM_PEER_NEW = RS_FEED_TYPE_PEER | 0x0004;
const uint32_t RS_FEED_ITEM_PEER_CONNECT = RS_FEED_TYPE_PEER | 0x0001;
const uint32_t RS_FEED_ITEM_PEER_DISCONNECT = RS_FEED_TYPE_PEER | 0x0002;
const uint32_t RS_FEED_ITEM_PEER_HELLO = RS_FEED_TYPE_PEER | 0x0003;
const uint32_t RS_FEED_ITEM_PEER_NEW = RS_FEED_TYPE_PEER | 0x0004;
const uint32_t RS_FEED_ITEM_PEER_OFFSET = RS_FEED_TYPE_PEER | 0x0005;
const uint32_t RS_FEED_ITEM_SEC_CONNECT_ATTEMPT = RS_FEED_TYPE_SECURITY | 0x0001;
const uint32_t RS_FEED_ITEM_SEC_AUTH_DENIED = RS_FEED_TYPE_SECURITY | 0x0002;
const uint32_t RS_FEED_ITEM_SEC_UNKNOWN_IN = RS_FEED_TYPE_SECURITY | 0x0003;
const uint32_t RS_FEED_ITEM_SEC_UNKNOWN_OUT = RS_FEED_TYPE_SECURITY | 0x0004;
const uint32_t RS_FEED_ITEM_SEC_CONNECT_ATTEMPT = RS_FEED_TYPE_SECURITY | 0x0001;
const uint32_t RS_FEED_ITEM_SEC_AUTH_DENIED = RS_FEED_TYPE_SECURITY | 0x0002;
const uint32_t RS_FEED_ITEM_SEC_UNKNOWN_IN = RS_FEED_TYPE_SECURITY | 0x0003;
const uint32_t RS_FEED_ITEM_SEC_UNKNOWN_OUT = RS_FEED_TYPE_SECURITY | 0x0004;
const uint32_t RS_FEED_ITEM_SEC_WRONG_SIGNATURE = RS_FEED_TYPE_SECURITY | 0x0005;
const uint32_t RS_FEED_ITEM_SEC_BAD_CERTIFICATE = RS_FEED_TYPE_SECURITY | 0x0006;
const uint32_t RS_FEED_ITEM_SEC_INTERNAL_ERROR = RS_FEED_TYPE_SECURITY | 0x0007;

View file

@ -2,7 +2,7 @@
#define RETROSHARE_RTT_INTERFACE_H
/*
* libretroshare/src/retroshare: rsrtt.h
* libretroshare/src/retroshare: rsrtt.h
*
* RetroShare C++ Interface.
*
@ -58,6 +58,7 @@ class RsRtt
virtual ~RsRtt() { return; }
virtual uint32_t getPongResults(const RsPeerId& id, int n, std::list<RsRttPongResult> &results) = 0;
virtual double getMeanOffset(const RsPeerId& id) = 0;
};

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 <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

@ -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 *****/