added regular timestamp-ing of GXS ids of group authors and group post authors for all subscribed groups

This commit is contained in:
csoler 2015-12-15 12:31:03 -05:00
parent 3f132f2c33
commit 8d886b8ecc
4 changed files with 132 additions and 97 deletions

View File

@ -77,10 +77,10 @@ RsGenExchange::RsGenExchange(RsGeneralDataService *gds, RsNetworkExchangeService
mAuthenPolicy(authenPolicy),
MESSAGE_STORE_PERIOD(messageStorePeriod),
mCleaning(false),
mLastClean(time(NULL)),
mLastClean(RSRandom::random_u32() % INTEGRITY_CHECK_PERIOD), // this helps unsynchronising the checks for the different services
mMsgCleanUp(NULL),
mChecking(false),
mLastCheck(time(NULL)),
mLastCheck(RSRandom::random_u32() % INTEGRITY_CHECK_PERIOD), // this helps unsynchronising the checks for the different services
mIntegrityCheck(NULL),
CREATE_FAIL(0),
CREATE_SUCCESS(1),
@ -252,7 +252,7 @@ void RsGenExchange::tick()
}
else
{
mIntegrityCheck = new RsGxsIntegrityCheck(mDataStore);
mIntegrityCheck = new RsGxsIntegrityCheck(mDataStore,mGixs);
mIntegrityCheck->start();
mChecking = true;
}
@ -499,14 +499,12 @@ int RsGenExchange::createGroupSignatures(RsTlvKeySignatureSet& signSet, RsTlvBin
authorKey, sign))
{
id_ret = SIGN_SUCCESS;
mGixs->timeStampKey(grpMeta.mAuthorId) ;
signSet.keySignSet[INDEX_AUTHEN_IDENTITY] = sign;
}
else
{
id_ret = SIGN_FAIL;
}
signSet.keySignSet[INDEX_AUTHEN_IDENTITY] = sign;
}
else
{
mGixs->requestPrivateKey(grpMeta.mAuthorId);

View File

@ -206,7 +206,7 @@
NXS_NET_DEBUG_3 publish key exchange
NXS_NET_DEBUG_4 vetting
***/
#define NXS_NET_DEBUG_0 1
//#define NXS_NET_DEBUG_0 1
//#define NXS_NET_DEBUG_1 1
//#define NXS_NET_DEBUG_2 1
//#define NXS_NET_DEBUG_3 1
@ -232,8 +232,9 @@
#if defined(NXS_NET_DEBUG_0) || defined(NXS_NET_DEBUG_1) || defined(NXS_NET_DEBUG_2) || defined(NXS_NET_DEBUG_3) || defined(NXS_NET_DEBUG_4)
//static const RsPeerId peer_to_print = RsPeerId(std::string("6718ae182d97c23af203959e678b98ac")) ; // use this to limit print to this peer id only, or "" for all IDs
static const RsPeerId peer_to_print = RsPeerId(std::string("")) ; // use this to limit print to this peer id only, or "" for all IDs
static const RsGxsGroupId group_id_to_print = RsGxsGroupId(std::string("8ad26b347697d7b443ef872ba3a8ea4b")) ; // use this to allow to this group id only, or "" for all IDs
//static const RsPeerId peer_to_print = RsPeerId(std::string("a97fef0e2dc82ddb19200fb30f9ac575")) ; // use this to limit print to this peer id only, or "" for all IDs
static const RsPeerId peer_to_print ;
static const RsGxsGroupId group_id_to_print = RsGxsGroupId(std::string("78a7480e7af4ae12303ec7fef2736745" )) ; // use this to allow to this group id only, or "" for all IDs
static const uint32_t service_to_print = 0x0217 ; // use this to allow to this service id only, or 0 for all services
// warning. Numbers should be SERVICE IDS (see serialiser/rsserviceids.h)
@ -1394,6 +1395,7 @@ void RsGxsNetService::data_tick()
processExplicitGroupRequests();
}
#if defined(NXS_NET_DEBUG_0) || defined(NXS_NET_DEBUG_1) || defined(NXS_NET_DEBUG_2) || defined(NXS_NET_DEBUG_3) || defined(NXS_NET_DEBUG_4)
static std::string nice_time_stamp(time_t now,time_t TS)
{
if(TS == 0)
@ -1405,9 +1407,11 @@ static std::string nice_time_stamp(time_t now,time_t TS)
return s.str() ;
}
}
#endif
void RsGxsNetService::debugDump()
{
#ifdef NXS_NET_DEBUG_1
RS_STACK_MUTEX(mNxsMutex) ;
time_t now = time(NULL) ;
@ -1437,6 +1441,7 @@ void RsGxsNetService::debugDump()
for(std::map<RsGxsGroupId, RsGxsMsgUpdateItem::MsgUpdateInfo>::const_iterator it2(it->second->msgUpdateInfos.begin());it2!=it->second->msgUpdateInfos.end();++it2)
GXSNETDEBUG_PG(it->first,it2->first) << " group " << it2->first << " - last updated at peer (secs ago): " << nice_time_stamp(now,it2->second.time_stamp) << ". Message count=" << it2->second.message_count << std::endl;
}
#endif
}
// This method is normally not needed, but we use it to correct possible inconsistencies in the updte time stamps
@ -1878,14 +1883,14 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
#endif
if(tr->mFlag & NxsTransaction::FLAG_STATE_COMPLETED)
{
#ifdef NXS_NET_DEBUG_1
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_P_(tr->mTransaction->PeerId()) << " transaction has completed." << std::endl;
#endif
// for a completed list response transaction
// one needs generate requests from this
if(flag & RsNxsTransac::FLAG_TYPE_MSG_LIST_RESP)
{
#ifdef NXS_NET_DEBUG_1
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_P_(tr->mTransaction->PeerId()) << " type = msg list response." << std::endl;
GXSNETDEBUG_P_(tr->mTransaction->PeerId()) << " => generate msg request based on it." << std::endl;
#endif
@ -1894,7 +1899,7 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
}else if(flag & RsNxsTransac::FLAG_TYPE_GRP_LIST_RESP)
{
#ifdef NXS_NET_DEBUG_1
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_P_(tr->mTransaction->PeerId()) << " type = grp list response." << std::endl;
GXSNETDEBUG_P_(tr->mTransaction->PeerId()) << " => generate group transaction request based on it." << std::endl;
#endif
@ -1903,7 +1908,7 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
// you've finished receiving request information now gen
else if(flag & RsNxsTransac::FLAG_TYPE_MSG_LIST_REQ)
{
#ifdef NXS_NET_DEBUG_1
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_P_(tr->mTransaction->PeerId()) << " type = msg list request." << std::endl;
GXSNETDEBUG_P_(tr->mTransaction->PeerId()) << " => generate msg list based on it." << std::endl;
#endif
@ -1911,7 +1916,7 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
}
else if(flag & RsNxsTransac::FLAG_TYPE_GRP_LIST_REQ)
{
#ifdef NXS_NET_DEBUG_1
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_P_(tr->mTransaction->PeerId()) << " type = grp list request." << std::endl;
GXSNETDEBUG_P_(tr->mTransaction->PeerId()) << " => generate grp list based on it." << std::endl;
#endif
@ -1919,7 +1924,7 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
}
else if(flag & RsNxsTransac::FLAG_TYPE_GRPS)
{
#ifdef NXS_NET_DEBUG_1
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_P_(tr->mTransaction->PeerId()) << " type = groups." << std::endl;
#endif
std::vector<RsNxsGrp*> grps;
@ -1932,16 +1937,16 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
{
tr->mItems.pop_front();
grps.push_back(grp);
#ifdef NXS_NET_DEBUG_1
GXSNETDEBUG_PG(tr->mTransaction->PeerId(),grp->grpId) << " pushing new group " << grp->grpId << " to list." << std::endl;
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_PG(tr->mTransaction->PeerId(),grp->grpId) << " adding new group " << grp->grpId << " to incoming list!" << std::endl;
#endif
}
else
std::cerr << " /!\\ item did not caste to grp" << std::endl;
}
#ifdef NXS_NET_DEBUG_1
GXSNETDEBUG_P_(tr->mTransaction->PeerId()) << " notifying observer " << std::endl;
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_P_(tr->mTransaction->PeerId()) << " ...and notifying observer " << std::endl;
#endif
// notify listener of grps
mObserver->notifyNewGroups(grps);
@ -1962,6 +1967,9 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
item = new RsGxsGrpUpdateItem(mServType);
mClientGrpUpdateMap.insert(std::make_pair(peerFrom, item));
}
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_P_(tr->mTransaction->PeerId()) << " and updating mClientGrpUpdateMap for peer " << peerFrom << " of new time stamp " << nice_time_stamp(time(NULL),updateTS) << std::endl;
#endif
#warning should not we conservatively use the most recent one, in case the peer has reset its mServerGrpUpdate time?? What happens if the peer unsubscribed a recent group?
item->grpUpdateTS = updateTS;
@ -1974,7 +1982,7 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
{
std::vector<RsNxsMsg*> msgs;
#ifdef NXS_NET_DEBUG_1
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_P_(tr->mTransaction->PeerId()) << " type = msgs." << std::endl;
#endif
RsGxsGroupId grpId;
@ -1988,8 +1996,8 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
tr->mItems.pop_front();
msgs.push_back(msg);
#ifdef NXS_NET_DEBUG_1
GXSNETDEBUG_PG(tr->mTransaction->PeerId(),msg->grpId) << " pushing grpId="<< msg->grpId << ", msgsId=" << msg->msgId << std::endl;
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_PG(tr->mTransaction->PeerId(),msg->grpId) << " pushing grpId="<< msg->grpId << ", msgsId=" << msg->msgId << " to list of incoming messages" << std::endl;
#endif
}
else
@ -2013,7 +2021,7 @@ void RsGxsNetService::locked_processCompletedIncomingTrans(NxsTransaction* tr)
}
#endif
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_P_(tr->mTransaction->PeerId()) << " notifying observer of " << msgs.size() << " new messages." << std::endl;
GXSNETDEBUG_PG(tr->mTransaction->PeerId(),grpId) << " ...and notifying observer of " << msgs.size() << " new messages." << std::endl;
#endif
// notify listener of msgs
mObserver->notifyNewMessages(msgs);
@ -2329,7 +2337,9 @@ void RsGxsNetService::locked_genReqMsgTransaction(NxsTransaction* tr)
// grp meta must be present if author present
if(!noAuthor && grpMeta == NULL)
{
#ifdef NXS_NET_DEBUG_1
GXSNETDEBUG_PG(item->PeerId(),grpId) << ", no group meta found. Givign up." << std::endl;
#endif
continue;
}
@ -3208,9 +3218,11 @@ bool RsGxsNetService::checkCanRecvMsgFromPeer(const RsPeerId& sslId, const RsGxs
const RsGxsCircleId& circleId = grpMeta.mCircleId;
if(circleId.isNull())
{
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " ERROR; EXTERNAL_CIRCLE missing NULL CircleId";
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << grpMeta.mGroupId;
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << std::endl;
#endif
// should just be shared. ? no - this happens for
// Circle Groups which lose their CircleIds.
@ -3650,7 +3662,9 @@ void RsGxsNetService::sharePublishKeysPending()
if(recipients.empty())
{
#ifdef NXS_NET_DEBUG_3
GXSNETDEBUG___ << " No recipients online. Skipping." << std::endl;
#endif
continue ;
}

View File

@ -28,6 +28,7 @@
#include "rsgxsutil.h"
#include "retroshare/rsgxsflags.h"
#include "pqi/pqihash.h"
#include "gxs/rsgixs.h"
RsGxsMessageCleanUp::RsGxsMessageCleanUp(RsGeneralDataService* const dataService, uint32_t messageStorePeriod, uint32_t chunkSize)
@ -106,9 +107,8 @@ bool RsGxsMessageCleanUp::clean()
return mGrpMeta.empty();
}
RsGxsIntegrityCheck::RsGxsIntegrityCheck(
RsGeneralDataService* const dataService) :
mDs(dataService), mDone(false), mIntegrityMutex("integrity")
RsGxsIntegrityCheck::RsGxsIntegrityCheck(RsGeneralDataService* const dataService, RsGixs *gixs) :
mDs(dataService), mDone(false), mIntegrityMutex("integrity"),mGixs(gixs)
{ }
void RsGxsIntegrityCheck::run()
@ -126,6 +126,8 @@ bool RsGxsIntegrityCheck::check()
GxsMsgReq msgIds;
GxsMsgReq grps;
std::set<RsGxsGroupId> subscribed_groups ;
// compute hash and compare to stored value, if it fails then simply add it
// to list
std::map<RsGxsGroupId, RsNxsGrp*>::iterator git = grp.begin();
@ -144,12 +146,24 @@ bool RsGxsIntegrityCheck::check()
{
// store the group for retrieveNxsMsgs
grps[grp->grpId];
if(grp->metaData->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED)
{
subscribed_groups.insert(git->first) ;
if(!grp->metaData->mAuthorId.isNull())
{
std::cerr << "TimeStamping group authors' key ID " << grp->metaData->mAuthorId << " in group ID " << grp->metaData->mAuthorId << std::endl;
mGixs->timeStampKey(grp->metaData->mAuthorId) ;
}
}
}
else
{
msgIds.erase(msgIds.find(grp->grpId));
// grpsToDel.push_back(grp->grpId);
// grpsToDel.push_back(grp->grpId);
}
}
else
{
@ -216,6 +230,11 @@ bool RsGxsIntegrityCheck::check()
std::cerr << "(EE) deleting message data with wrong hash or null meta data. meta=" << (void*)msg->metaData << std::endl;
msgsToDel[msg->grpId].push_back(msg->msgId);
}
else if(!msg->metaData->mAuthorId.isNull() && subscribed_groups.find(msg->metaData->mGroupId)!=subscribed_groups.end())
{
std::cerr << "TimeStamping message authors' key ID " << msg->metaData->mAuthorId << " in message " << msg->msgId << ", group ID " << msg->grpId<< std::endl;
mGixs->timeStampKey(msg->metaData->mAuthorId) ;
}
delete msg;
}

View File

@ -30,6 +30,8 @@
#include "serialiser/rsnxsitems.h"
#include "rsgds.h"
class RsGixs ;
/*!
* Handy function for cleaning out meta result containers
* @param container
@ -112,7 +114,7 @@ public:
* @param chunkSize
* @param sleepPeriod
*/
RsGxsIntegrityCheck(RsGeneralDataService* const dataService);
RsGxsIntegrityCheck(RsGeneralDataService* const dataService, RsGixs *gixs);
bool check();
@ -129,6 +131,8 @@ private:
RsMutex mIntegrityMutex;
std::list<RsGxsGroupId> mDeletedGrps;
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > mDeletedMsgs;
RsGixs *mGixs ;
};
class GroupUpdate