From c1e18c7fe64b2076934f807cb57206d3559e2cb3 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 5 Jul 2017 22:12:56 +0200 Subject: [PATCH] fixed bug causing an infinite subscribe/unsubscribe loop in GxsTrans --- libretroshare/src/gxs/rsgenexchange.cc | 44 ++++++++++++++---------- libretroshare/src/gxstrans/p3gxstrans.cc | 2 +- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index e48988e33..eae9dab4d 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -1188,26 +1188,30 @@ bool RsGenExchange::getGroupMeta(const uint32_t &token, std::list metaL; bool ok = mDataAccess->getGroupSummary(token, metaL); - std::list::iterator lit = metaL.begin(); RsGroupMetaData m; - for(; lit != metaL.end(); ++lit) + + for( std::list::iterator lit = metaL.begin(); lit != metaL.end(); ++lit) { RsGxsGrpMetaData& gMeta = *(*lit); + m = gMeta; RsGroupNetworkStats sts ; - if(mNetService != NULL && mNetService->getGroupNetworkStats((*lit)->mGroupId,sts)) - { - m.mPop = sts.mSuppliers ; - m.mVisibleMsgCount = sts.mMaxVisibleCount ; - } - else - { - m.mPop= 0 ; - m.mVisibleMsgCount = 0 ; - } + if(mNetService != NULL && mNetService->getGroupNetworkStats(gMeta.mGroupId,sts)) + { + m.mPop = sts.mSuppliers ; + m.mVisibleMsgCount = sts.mMaxVisibleCount ; - groupInfo.push_back(m); + if((!(IS_GROUP_SUBSCRIBED(gMeta.mSubscribeFlags))) || gMeta.mLastPost == 0) + m.mLastPost = sts.mLastGroupModificationTS ; + } + else + { + m.mPop= 0 ; + m.mVisibleMsgCount = 0 ; + } + + groupInfo.push_back(m); delete (*lit); } @@ -1369,6 +1373,14 @@ bool RsGenExchange::getGroupData(const uint32_t &token, std::vectormeta.mPop = sts.mSuppliers; gItem->meta.mVisibleMsgCount = sts.mMaxVisibleCount; + + // When the group is not subscribed, the last post value is not updated, because there's no message stored. As a consequence, + // we rely on network statistics to give this value, but it is not as accurate as if it was locally computed, because of blocked + // posts, friends not available, sync delays, etc. Similarly if the group has just been subscribed, the last post info is probably + // uninitialised, so we will it too. + + if((!(IS_GROUP_SUBSCRIBED(gItem->meta.mSubscribeFlags))) || gItem->meta.mLastPost == 0) + gItem->meta.mLastPost = sts.mLastGroupModificationTS ; } else { @@ -1376,12 +1388,6 @@ bool RsGenExchange::getGroupData(const uint32_t &token, std::vectormeta.mVisibleMsgCount = 0; } - // When the group is not subscribed, the last post value is not updated, because there's no message stored. As a consequence, - // we rely on network statistics to give this value, but it is not as accurate as if it was locally computed, because of blocked - // posts, friends not available, sync delays, etc. - - if(!(IS_GROUP_SUBSCRIBED(gItem->meta.mSubscribeFlags))) - gItem->meta.mLastPost = sts.mLastGroupModificationTS ; // Also check the group privacy flags. A while ago, it as possible to publish a group without privacy flags. Now it is not possible anymore. // As a consequence, it's important to supply a correct value in this flag before the data can be edited/updated. diff --git a/libretroshare/src/gxstrans/p3gxstrans.cc b/libretroshare/src/gxstrans/p3gxstrans.cc index 382397c2e..a5a5379ce 100644 --- a/libretroshare/src/gxstrans/p3gxstrans.cc +++ b/libretroshare/src/gxstrans/p3gxstrans.cc @@ -20,7 +20,7 @@ #include "gxstrans/p3gxstrans.h" #include "util/stacktrace.h" -//#define DEBUG_GXSTRANS 1 +#define DEBUG_GXSTRANS 1 typedef unsigned int uint;