added anon ids to offline vetting

This commit is contained in:
csoler 2016-03-23 20:54:45 -04:00
parent 57f4463864
commit 981f81deae
13 changed files with 138 additions and 46 deletions

View File

@ -66,6 +66,7 @@ public:
std::cerr << "!!!!!! Received Data status from global router, but the client service is not handling it !!!!!!!!!!" << std::endl ;
std::cerr << " message ID = " << received_id << std::endl;
std::cerr << " data status = " << data_status << std::endl;
std::cerr << " signer ID = " << signer_id << std::endl;
}
// This function is mandatory. It should do two things:

View File

@ -215,6 +215,7 @@ class RsGcxs
virtual int canReceive(const RsGxsCircleId &circleId, const RsPgpId &id) = 0;
virtual bool recipients(const RsGxsCircleId &circleId, std::list<RsPgpId>& friendlist) = 0;
virtual bool recipients(const RsGxsCircleId &circleId, std::list<RsGxsId>& idlist) = 0;
virtual bool isRecipient(const RsGxsCircleId &circleId, const RsGxsId& id) = 0;
virtual bool getLocalCircleServerUpdateTS(const RsGxsCircleId& gid,time_t& grp_server_update_TS,time_t& msg_server_update_TS) =0;
};

View File

@ -1998,17 +1998,23 @@ void RsGxsNetService::updateServerSyncTS()
if(mCircles->getLocalCircleServerUpdateTS(mit->second->mCircleId,circle_group_server_ts,circle_msg_server_ts))
{
std::cerr << "Group " << mit->first << " is conditionned to circle " << mit->second->mCircleId << ". local Grp TS=" << time(NULL) - mGrpServerUpdateItem->grpUpdateTS << " secs ago, circle grp server update TS=" << time(NULL) - circle_group_server_ts << " secs ago";
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG__G(mit->first) << " Group " << mit->first << " is conditionned to circle " << mit->second->mCircleId << ". local Grp TS=" << time(NULL) - mGrpServerUpdateItem->grpUpdateTS << " secs ago, circle grp server update TS=" << time(NULL) - circle_group_server_ts << " secs ago";
#endif
if(circle_group_server_ts > mGrpServerUpdateItem->grpUpdateTS)
{
std::cerr << " - Updating local Grp Server update TS to follow changes in circles." << std::endl;
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG__G(mit->first) << " - Updating local Grp Server update TS to follow changes in circles." << std::endl;
#endif
RS_STACK_MUTEX(mNxsMutex) ;
mGrpServerUpdateItem->grpUpdateTS = circle_group_server_ts ;
}
#ifdef NXS_NET_DEBUG_0
else
std::cerr << " - Nothing to do." << std::endl;
GXSNETDEBUG__G(mit->first) << " - Nothing to do." << std::endl;
#endif
}
else
std::cerr << "(EE) Cannot retrieve attached circle TS" << std::endl;
@ -3334,15 +3340,24 @@ void RsGxsNetService::runVetting()
std::vector<GrpCircleVetting*>::iterator vit2 = mPendingCircleVets.begin();
for(; vit2 != mPendingCircleVets.end(); )
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG___ << " Examining/clearing pending vetting of type " << (*vit2)->getType() << std::endl;
#endif
GrpCircleVetting*& gcv = *vit2;
if(gcv->cleared() || gcv->expired())
{
if(gcv->getType() == GrpCircleVetting::GRP_ID_PEND)
{
GrpCircleIdRequestVetting* gcirv = static_cast<GrpCircleIdRequestVetting*>(gcv);
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_P_(gcirv->mPeerId) << " vetting is a GRP ID PENDING Response" << std::endl;
#endif
if(!locked_createTransactionFromPending(gcirv))
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_P_(gcirv->mPeerId) << " Response sent!" << std::endl;
#endif
++vit2 ;
continue ;
}
@ -3351,10 +3366,18 @@ void RsGxsNetService::runVetting()
{
MsgCircleIdsRequestVetting* mcirv = static_cast<MsgCircleIdsRequestVetting*>(gcv);
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_P_(mcirv->mPeerId) << " vetting is a MSG ID PENDING Response" << std::endl;
#endif
if(mcirv->cleared())
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_P_(mcirv->mPeerId) << " vetting cleared! Sending..." << std::endl;
#endif
if(!locked_createTransactionFromPending(mcirv))
continue ; // keep it in the list for retry
}
}
else
{
#ifdef NXS_NET_DEBUG_4
@ -3367,6 +3390,9 @@ void RsGxsNetService::runVetting()
}
else
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG___ << " ... not cleared yet." << std::endl;
#endif
++vit2;
}
}
@ -4462,7 +4488,7 @@ void RsGxsNetService::locked_pushMsgRespFromList(std::list<RsNxsItem*>& itemL, c
}
bool RsGxsNetService::canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMetas, const RsGxsGrpMetaData& grpMeta, const RsPeerId& sslId,RsGxsCircleId& should_encrypt_id)
bool RsGxsNetService::canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, const RsGxsGrpMetaData& grpMeta, const RsPeerId& sslId,RsGxsCircleId& should_encrypt_id)
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << "RsGxsNetService::canSendMsgIds() CIRCLE VETTING" << std::endl;
@ -4495,7 +4521,27 @@ bool RsGxsNetService::canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMet
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: EXTERNAL => returning true. Msgs ids list will be encrypted." << std::endl;
#endif
should_encrypt_id = circleId ;
// For each message ID, check that the author is in the circle. If not, do not send the message, which means, remove it from the list.
if(mCircles->isLoaded(circleId))
{
for(uint32_t i=0;i<msgMetas.size();)
if(!mCircles->isRecipient(circleId, msgMetas[i]->mAuthorId))
{
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " deleting MsgMeta entry for msg ID " << msgMetas[i]->mMsgId << " signed by " << msgMetas[i]->mAuthorId << " who is not in group circle " << circleId << std::endl;
#endif
delete msgMetas[i] ;
msgMetas[i] = msgMetas[msgMetas.size()-1] ;
msgMetas.pop_back() ;
}
else
++i ;
return true ;
}
#ifdef TO_BE_REMOVED_OLD_VETTING_FOR_EXTERNAL_CIRCLES
#ifdef NXS_NET_DEBUG_4
@ -4510,6 +4556,7 @@ bool RsGxsNetService::canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMet
#endif
return res ;
}
#endif
#ifdef NXS_NET_DEBUG_4
GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle info not loaded. Putting in vetting list and returning false." << std::endl;
@ -4526,11 +4573,9 @@ bool RsGxsNetService::canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMet
}
if(!toVet.empty())
mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mPgpUtils, toVet, grpMeta.mGroupId,
sslId, grpMeta.mCircleId));
mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mPgpUtils, toVet, grpMeta.mGroupId, sslId, grpMeta.mCircleId));
return false;
#endif
}
if(circleType == GXS_CIRCLE_TYPE_YOUREYESONLY)

View File

@ -352,7 +352,7 @@ private:
* @return false, if you cannot send to this peer, true otherwise
*/
bool canSendGrpId(const RsPeerId& sslId, RsGxsGrpMetaData& grpMeta, std::vector<GrpIdCircleVet>& toVet, bool &should_encrypt);
bool canSendMsgIds(const std::vector<RsGxsMsgMetaData*>& msgMetas, const RsGxsGrpMetaData&, const RsPeerId& sslId, RsGxsCircleId &should_encrypt_id);
bool canSendMsgIds(std::vector<RsGxsMsgMetaData*>& msgMetas, const RsGxsGrpMetaData&, const RsPeerId& sslId, RsGxsCircleId &should_encrypt_id);
bool checkCanRecvMsgFromPeer(const RsPeerId& sslId, const RsGxsGrpMetaData& meta);

View File

@ -284,9 +284,30 @@ MsgCircleIdsRequestVetting::MsgCircleIdsRequestVetting(RsGcxs* const circles,
bool MsgCircleIdsRequestVetting::cleared()
{
if(!mCircles->isLoaded(mCircleId))
{
mCircles->loadCircle(mCircleId);
return false ;
}
return canSend(mPeerId, mCircleId, mShouldEncrypt);
for(uint32_t i=0;i<mMsgs.size();)
if(!mCircles->isRecipient(mCircleId,mMsgs[i].mAuthorId))
{
std::cerr << "(WW) MsgCircleIdsRequestVetting::cleared() filtering out message " << mMsgs[i].mMsgId << " because it's signed by author " << mMsgs[i].mAuthorId << " which is not in circle " << mCircleId << std::endl;
mMsgs[i] = mMsgs[mMsgs.size()-1] ;
mMsgs.pop_back();
}
else
++i ;
RsPgpId pgpId = mPgpUtils->getPGPId(mPeerId);
bool can_send_res = mCircles->canSend(mCircleId, pgpId,mShouldEncrypt);
if(mShouldEncrypt) // that means the circle is external
return true ;
else
return can_send_res ;
}
int MsgCircleIdsRequestVetting::getType() const

View File

@ -256,8 +256,6 @@ public:
protected:
bool canSend(const RsPeerId& peerId, const RsGxsCircleId& circleId, bool& should_encrypt);
private:
RsGcxs* const mCircles;
PgpAuxUtils *mPgpUtils;
time_t mTimeStamp;

View File

@ -127,7 +127,7 @@ class RsGxsCircleDetails
}
std::set<RsGxsId> mAllowedAnonPeers;
std::map<RsPgpId, std::list<RsGxsId> > mAllowedSignedPeers;
std::map<RsPgpId, std::set<RsGxsId> > mAllowedSignedPeers;
};
class RsGxsCircles: public RsGxsIfaceHelper

View File

@ -391,8 +391,21 @@ bool p3GxsCircles::recipients(const RsGxsCircleId &circleId, std::list<RsPgpId>&
return false;
}
bool p3GxsCircles::isRecipient(const RsGxsCircleId &circleId, const RsGxsId& id)
{
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
if (mCircleCache.is_cached(circleId))
{
const RsGxsCircleCache &data = mCircleCache.ref(circleId);
return data.isAllowedPeer(id);
}
return false;
}
bool p3GxsCircles::recipients(const RsGxsCircleId& circleId, std::list<RsGxsId>& gxs_ids)
{
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
RsGxsCircleDetails details ;
if(!getCircleDetails(circleId, details))
@ -401,8 +414,8 @@ bool p3GxsCircles::recipients(const RsGxsCircleId& circleId, std::list<RsGxsId>&
for(std::set<RsGxsId>::const_iterator it(details.mAllowedAnonPeers.begin());it!=details.mAllowedAnonPeers.end();++it)
gxs_ids.push_back(*it) ;
for(std::map<RsPgpId,std::list<RsGxsId> >::const_iterator it(details.mAllowedSignedPeers.begin());it!=details.mAllowedSignedPeers.end();++it)
for(std::list<RsGxsId>::const_iterator it2(it->second.begin());it2!=it->second.end();++it2)
for(std::map<RsPgpId,std::set<RsGxsId> >::const_iterator it(details.mAllowedSignedPeers.begin());it!=details.mAllowedSignedPeers.end();++it)
for(std::set<RsGxsId>::const_iterator it2(it->second.begin());it2!=it->second.end();++it2)
gxs_ids.push_back(*it2) ;
return true;
@ -561,9 +574,9 @@ bool RsGxsCircleCache::loadSubCircle(const RsGxsCircleCache &subcircle)
return true;
}
bool RsGxsCircleCache::getAllowedPeersList(std::list<RsPgpId> &friendlist)
bool RsGxsCircleCache::getAllowedPeersList(std::list<RsPgpId> &friendlist) const
{
std::map<RsPgpId, std::list<RsGxsId> >::iterator it;
std::map<RsPgpId, std::set<RsGxsId> >::const_iterator it;
for(it = mAllowedSignedPeers.begin(); it != mAllowedSignedPeers.end(); ++it)
{
friendlist.push_back(it->first);
@ -571,9 +584,24 @@ bool RsGxsCircleCache::getAllowedPeersList(std::list<RsPgpId> &friendlist)
return true;
}
bool RsGxsCircleCache::isAllowedPeer(const RsPgpId &id)
bool RsGxsCircleCache::isAllowedPeer(const RsGxsId &id) const
{
std::map<RsPgpId, std::list<RsGxsId> >::iterator it = mAllowedSignedPeers.find(id);
if(mUnprocessedPeers.find(id) != mUnprocessedPeers.end())
return true ;
if(mAllowedAnonPeers.find(id) != mAllowedAnonPeers.end())
return true ;
for(std::map<RsPgpId,std::set<RsGxsId> >::const_iterator it = mAllowedSignedPeers.begin();it!=mAllowedSignedPeers.end();++it)
if(it->second.find(id) != it->second.end())
return true ;
return false ;
}
bool RsGxsCircleCache::isAllowedPeer(const RsPgpId &id) const
{
std::map<RsPgpId, std::set<RsGxsId> >::const_iterator it = mAllowedSignedPeers.find(id);
if (it != mAllowedSignedPeers.end())
{
return true;
@ -584,8 +612,7 @@ bool RsGxsCircleCache::isAllowedPeer(const RsPgpId &id)
bool RsGxsCircleCache::addAllowedPeer(const RsPgpId &pgpId, const RsGxsId &gxsId)
{
/* created if doesn't exist */
std::list<RsGxsId> &gxsList = mAllowedSignedPeers[pgpId];
gxsList.push_back(gxsId);
mAllowedSignedPeers[pgpId].insert(gxsId);
return true;
}
@ -593,7 +620,7 @@ bool RsGxsCircleCache::addAllowedPeer(const RsPgpId &pgpId, const RsGxsId &gxsId
bool RsGxsCircleCache::addLocalFriend(const RsPgpId &pgpId)
{
/* empty list as no GxsID associated */
std::list<RsGxsId> &gxsList = mAllowedSignedPeers[pgpId];
mAllowedSignedPeers.insert(std::make_pair(pgpId,std::set<RsGxsId>()));
return true;
}
@ -1272,7 +1299,7 @@ bool p3GxsCircles::checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache)
const RsPgpId& ownId = mPgpUtils->getPGPOwnId();
std::map<RsPgpId, std::list<RsGxsId> >::iterator it = cache.mAllowedSignedPeers.find(ownId);
std::map<RsPgpId, std::set<RsGxsId> >::iterator it = cache.mAllowedSignedPeers.find(ownId);
bool am_I_allowed = it != cache.mAllowedSignedPeers.end() ;
if(!am_I_allowed)

View File

@ -132,8 +132,9 @@ class RsGxsCircleCache
bool loadBaseCircle(const RsGxsCircleGroup &circle);
bool loadSubCircle(const RsGxsCircleCache &subcircle);
bool getAllowedPeersList(std::list<RsPgpId> &friendlist);
bool isAllowedPeer(const RsPgpId &id);
bool getAllowedPeersList(std::list<RsPgpId> &friendlist) const;
bool isAllowedPeer(const RsPgpId &id) const;
bool isAllowedPeer(const RsGxsId &id) const;
bool addAllowedPeer(const RsPgpId &pgpid, const RsGxsId &gxsId);
bool addLocalFriend(const RsPgpId &pgpid);
@ -154,7 +155,7 @@ class RsGxsCircleCache
std::set<RsGxsId> mUnprocessedPeers;
std::set<RsGxsId> mAllowedAnonPeers;
std::map<RsPgpId, std::list<RsGxsId> > mAllowedSignedPeers;
std::map<RsPgpId, std::set<RsGxsId> > mAllowedSignedPeers;
};
@ -182,6 +183,7 @@ virtual RsServiceInfo getServiceInfo();
virtual int canReceive(const RsGxsCircleId &circleId, const RsPgpId &id);
virtual bool recipients(const RsGxsCircleId &circleId, std::list<RsPgpId> &friendlist) ;
virtual bool recipients(const RsGxsCircleId &circleId, std::list<RsGxsId> &gxs_ids) ;
virtual bool isRecipient(const RsGxsCircleId &circleId, const RsGxsId& id) ;
virtual bool getGroupData(const uint32_t &token, std::vector<RsGxsCircleGroup> &groups);

View File

@ -388,8 +388,7 @@ void CirclesDialog::circle_selected()
{
/* now mark all the members */
std::set<RsPgpId> members;
std::map<RsPgpId, std::list<RsGxsId> >::iterator it;
for(it = details.mAllowedSignedPeers.begin(); it != details.mAllowedSignedPeers.end(); ++it)
for( std::map<RsPgpId, std::set<RsGxsId> >::iterator it = details.mAllowedSignedPeers.begin(); it != details.mAllowedSignedPeers.end(); ++it)
{
members.insert(it->first);
std::cerr << "Circle member: " << it->first;

View File

@ -297,10 +297,9 @@ void CreateCircleDialog::addCircle(const RsGxsCircleDetails &cirDetails)
}//if(!gxs_id.isNull() && rsIdentity->getIdDetails(gxs_id,gxs_details))
}//for (itUnknownPeers it = cirDetails.mUnknownPeers.begin()
typedef std::map<RsPgpId, std::list<RsGxsId> >::const_iterator itAllowedPeers;
for (itAllowedPeers it = cirDetails.mAllowedSignedPeers.begin()
; it != cirDetails.mAllowedSignedPeers.end()
; ++it ) {
typedef std::map<RsPgpId, std::set<RsGxsId> >::const_iterator itAllowedPeers;
for (itAllowedPeers it = cirDetails.mAllowedSignedPeers.begin() ; it != cirDetails.mAllowedSignedPeers.end() ; ++it )
{
RsPgpId gpg_id = it->first;
RsPeerDetails details ;
if(!gpg_id.isNull() && rsPeers->getGPGDetails(gpg_id,details)) {

View File

@ -612,8 +612,8 @@ void IdDialog::circle_selected()
std::set<RsGxsId> members = details.mAllowedAnonPeers;
for(std::map<RsPgpId, std::list<RsGxsId> >::iterator it = details.mAllowedSignedPeers.begin(); it != details.mAllowedSignedPeers.end(); ++it)
for(std::list<RsGxsId>::const_iterator it2=it->second.begin();it2!=it->second.end();++it2)
for(std::map<RsPgpId, std::set<RsGxsId> >::iterator it = details.mAllowedSignedPeers.begin(); it != details.mAllowedSignedPeers.end(); ++it)
for(std::set<RsGxsId>::const_iterator it2=it->second.begin();it2!=it->second.end();++it2)
{
members.insert( (*it2) ) ;
std::cerr << "Circle member: " << it->first;

View File

@ -63,15 +63,14 @@ void CircleWidget::updateData(const RsGroupMetaData& gxs_group_info
}//if(!gxs_id.isNull())
}//for (itUnknownPeers it = _circle_details.mUnknownPeers.begin()
typedef std::map<RsPgpId, std::list<RsGxsId> >::const_iterator itAllowedPeers;
for (itAllowedPeers it = _circle_details.mAllowedSignedPeers.begin()
; it != _circle_details.mAllowedSignedPeers.end()
; ++it ) {
typedef std::map<RsPgpId, std::set<RsGxsId> >::const_iterator itAllowedPeers;
for (itAllowedPeers it = _circle_details.mAllowedSignedPeers.begin() ; it != _circle_details.mAllowedSignedPeers.end() ; ++it )
{
RsPgpId pgp_id = it->first;
emit askForPGPIdentityWidget(pgp_id);
std::list<RsGxsId> gxs_id_list = it->second;
typedef std::list<RsGxsId>::const_iterator itGxsId;
std::set<RsGxsId> gxs_id_list = it->second;
typedef std::set<RsGxsId>::const_iterator itGxsId;
for (itGxsId curs=gxs_id_list.begin()
; curs != gxs_id_list.end()
; ++curs) {