From 123041a684b2fb83d6276f03b023e2a48da588db Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 10 Apr 2016 18:55:05 -0400 Subject: [PATCH 1/3] skip circle vetting when sending message posts with no author --- libretroshare/src/gxs/rsgxsnetservice.cc | 108 ++++++++++------------- 1 file changed, 46 insertions(+), 62 deletions(-) diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index 5947efee0..617b2d593 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -4570,92 +4570,76 @@ void RsGxsNetService::locked_pushMsgRespFromList(std::list& itemL, c bool RsGxsNetService::canSendMsgIds(std::vector& 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; + GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << "RsGxsNetService::canSendMsgIds() CIRCLE VETTING" << std::endl; #endif - // first do the simple checks - uint8_t circleType = grpMeta.mCircleType; + // first do the simple checks + uint8_t circleType = grpMeta.mCircleType; - if(circleType == GXS_CIRCLE_TYPE_LOCAL) - { + if(circleType == GXS_CIRCLE_TYPE_LOCAL) + { #ifdef NXS_NET_DEBUG_4 GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: LOCAL => returning false" << std::endl; #endif return false; - } + } - if(circleType == GXS_CIRCLE_TYPE_PUBLIC) - { + if(circleType == GXS_CIRCLE_TYPE_PUBLIC) + { #ifdef NXS_NET_DEBUG_4 GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: PUBLIC => returning true" << std::endl; #endif return true; - } + } - const RsGxsCircleId& circleId = grpMeta.mCircleId; + const RsGxsCircleId& circleId = grpMeta.mCircleId; - if(circleType == GXS_CIRCLE_TYPE_EXTERNAL) - { + if(circleType == GXS_CIRCLE_TYPE_EXTERNAL) + { #ifdef NXS_NET_DEBUG_4 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;iisRecipient(circleId, msgMetas[i]->mAuthorId)) - { + + // 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. + // Unsigned messages are still transmitted. This is because in some groups (channels) the posts are not signed. Whether an unsigned post + // is allowed at this point is anyway already vetted by the RsGxsGenExchange service. + + // Messages that stay in the list will be sent. As a consequence true is always returned. + // Messages put in vetting list will be dealt with later + + std::vector toVet; + + for(uint32_t i=0;imAuthorId.isNull() ) // keep the message in this case + ++i ; + else + { + if(mCircles->isLoaded(circleId) && mCircles->isRecipient(circleId, msgMetas[i]->mAuthorId)) + { + ++i ; + continue ; + } + + MsgIdCircleVet mic(msgMetas[i]->mMsgId, msgMetas[i]->mAuthorId); + toVet.push_back(mic); #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; + 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 - GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle type: EXTERNAL. Circle Id: " << circleId << std::endl; -#endif - if(mCircles->isLoaded(circleId)) - { - const RsPgpId& pgpId = mPgpUtils->getPGPId(sslId); - bool res = mCircles->canSend(circleId, pgpId); -#ifdef NXS_NET_DEBUG_4 - GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Answer from circle::canSend(): " << res << std::endl; -#endif - return res ; - } -#endif + delete msgMetas[i] ; + msgMetas[i] = msgMetas[msgMetas.size()-1] ; + msgMetas.pop_back() ; + } #ifdef NXS_NET_DEBUG_4 - GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle info not loaded. Putting in vetting list and returning false." << std::endl; + GXSNETDEBUG_PG(sslId,grpMeta.mGroupId) << " Circle info not loaded. Putting in vetting list and returning false." << std::endl; #endif - std::vector toVet; - std::vector::const_iterator vit = msgMetas.begin(); + if(!toVet.empty()) + mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mPgpUtils, toVet, grpMeta.mGroupId, sslId, grpMeta.mCircleId)); - for(; vit != msgMetas.end(); ++vit) - { - const RsGxsMsgMetaData* const& meta = *vit; - - MsgIdCircleVet mic(meta->mMsgId, meta->mAuthorId); - toVet.push_back(mic); - } - - if(!toVet.empty()) - mPendingCircleVets.push_back(new MsgCircleIdsRequestVetting(mCircles, mPgpUtils, toVet, grpMeta.mGroupId, sslId, grpMeta.mCircleId)); - - return false; - } + return true ; + } if(circleType == GXS_CIRCLE_TYPE_YOUREYESONLY) { @@ -4721,7 +4705,7 @@ bool RsGxsNetService::canSendMsgIds(std::vector& msgMetas, co } } - return true; + return false; } /** inherited methods **/ From ba1a1b2a61c842cdf7416fe69a218b331d86abdb Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 14 Apr 2016 23:09:59 -0400 Subject: [PATCH 2/3] fixed auto-subscribed of circles when some IDs are unknown --- libretroshare/src/services/p3gxscircles.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index 460cdbaab..17cf3efd9 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -37,6 +37,7 @@ /**** * #define DEBUG_CIRCLES 1 ****/ +#define DEBUG_CIRCLES 1 RsGxsCircles *rsGxsCircles = NULL; @@ -119,9 +120,8 @@ p3GxsCircles::p3GxsCircles(RsGeneralDataService *gds, RsNetworkExchangeService * RsTickEvent::schedule_now(CIRCLE_EVENT_LOADIDS); // Dummy Circles. -// RsTickEvent::schedule_in(CIRCLE_EVENT_DUMMYSTART, CIRCLE_DUMMY_STARTPERIOD); - mDummyIdToken = 0; - + // RsTickEvent::schedule_in(CIRCLE_EVENT_DUMMYSTART, CIRCLE_DUMMY_STARTPERIOD); + mDummyIdToken = 0; } @@ -1114,12 +1114,12 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token) isUnprocessedPeers = false; } - + // we can check for self inclusion in the circle right away, since own ids are always loaded. + // that allows to subscribe/unsubscribe uncomplete circles + checkCircleCacheForAutoSubscribe(cache); if (isComplete) { - checkCircleCacheForAutoSubscribe(cache); - /* move straight into the cache */ mCircleCache.store(id, cache); mCircleCache.resize(); @@ -1266,8 +1266,11 @@ bool p3GxsCircles::cache_reloadids(const RsGxsCircleId &circleId) /* We need to AutoSubscribe if the Circle is relevent to us */ + bool p3GxsCircles::checkCircleCacheForAutoSubscribe(RsGxsCircleCache &cache) { +#warning we should also check for items in mLoadingCache in this method. + #ifdef DEBUG_CIRCLES std::cerr << "p3GxsCircles::checkCircleCacheForAutoSubscribe() : "<< cache.mCircleId << std::endl; #endif From 048192ee9c13821eaaff07c9272c4da312e27a1c Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 14 Apr 2016 23:47:42 -0400 Subject: [PATCH 3/3] added mOriginator to CircleCache entry and auto-ask for unknown GXS ids to the friend who supplied the circle group --- libretroshare/src/gxs/rsgenexchange.cc | 4 ++-- libretroshare/src/services/p3gxscircles.cc | 4 +++- libretroshare/src/services/p3gxscircles.h | 2 ++ retroshare-gui/src/gui/Identity/IdDialog.cpp | 12 ++---------- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index c1e2dd116..468792b18 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -2840,8 +2840,8 @@ void RsGenExchange::processRecvdGroups() // now check if group already existss if(std::find(existingGrpIds.begin(), existingGrpIds.end(), grp->grpId) == existingGrpIds.end()) { - if(meta->mCircleType == GXS_CIRCLE_TYPE_YOUREYESONLY) - meta->mOriginator = grp->PeerId(); + //if(meta->mCircleType == GXS_CIRCLE_TYPE_YOUREYESONLY) + meta->mOriginator = grp->PeerId(); meta->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_NOT_SUBSCRIBED; diff --git a/libretroshare/src/services/p3gxscircles.cc b/libretroshare/src/services/p3gxscircles.cc index 17cf3efd9..d70e4cd3e 100644 --- a/libretroshare/src/services/p3gxscircles.cc +++ b/libretroshare/src/services/p3gxscircles.cc @@ -37,7 +37,6 @@ /**** * #define DEBUG_CIRCLES 1 ****/ -#define DEBUG_CIRCLES 1 RsGxsCircles *rsGxsCircles = NULL; @@ -978,6 +977,7 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token) RsGxsCircleCache &cache = it->second; cache.loadBaseCircle(group); + cache.mOriginator = item->meta.mOriginator ; delete item; @@ -1043,6 +1043,8 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token) #endif std::list peers; + peers.push_back(cache.mOriginator) ; + mIdentities->requestKey(*pit, peers); /* store in to_process queue. */ diff --git a/libretroshare/src/services/p3gxscircles.h b/libretroshare/src/services/p3gxscircles.h index 2ad9934b6..f17f7dc12 100644 --- a/libretroshare/src/services/p3gxscircles.h +++ b/libretroshare/src/services/p3gxscircles.h @@ -156,6 +156,8 @@ class RsGxsCircleCache std::set mAllowedAnonPeers; std::map > mAllowedSignedPeers; + + RsPeerId mOriginator ; // peer who sent the data, in case we need to ask for ids }; diff --git a/retroshare-gui/src/gui/Identity/IdDialog.cpp b/retroshare-gui/src/gui/Identity/IdDialog.cpp index 22c8571e5..bcf87ef8b 100644 --- a/retroshare-gui/src/gui/Identity/IdDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdDialog.cpp @@ -882,9 +882,6 @@ bool IdDialog::fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item, item->setToolTip(RSID_COL_IDTYPE, tooltip) ; } -#ifdef ID_DEBUG - std::cerr << "Setting item image : " << pixmap.width() << " x " << pixmap.height() << std::endl; -#endif QPixmap pixmap ; if(data.mImage.mSize == 0 || !pixmap.loadFromData(data.mImage.mData, data.mImage.mSize, "PNG")) @@ -1119,7 +1116,7 @@ void IdDialog::insertIdDetails(uint32_t token) pixmap = QPixmap::fromImage(GxsIdDetails::makeDefaultIcon(RsGxsId(data.mMeta.mGroupId))) ; #ifdef ID_DEBUG - std::cerr << "Setting header frame image : " << pix.width() << " x " << pix.height() << std::endl; + std::cerr << "Setting header frame image : " << pixmap.width() << " x " << pixmap.height() << std::endl; #endif ui->avlabel->setPixmap(pixmap); @@ -1263,7 +1260,7 @@ void IdDialog::modifyReputation() rsReputations->setOwnOpinion(id,op) ; #ifdef ID_DEBUG - std::cerr << "IdDialog::modifyReputation() ID: " << id << " Mod: " << mod; + std::cerr << "IdDialog::modifyReputation() ID: " << id << " Mod: " << op; std::cerr << std::endl; #endif @@ -1281,11 +1278,6 @@ void IdDialog::modifyReputation() } #endif -#ifdef ID_DEBUG - std::cerr << "IdDialog::modifyReputation() queuingRequest(), token: " << token; - std::cerr << std::endl; -#endif - // trigger refresh when finished. // basic / anstype are not needed. requestIdDetails();