From dc605c02f18579ae8092906251bbe914f657d210 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 29 Jun 2017 13:15:39 +0200 Subject: [PATCH] added a last modif TS in GrpNetworkStats, that is inited from network Grp statistics, and used to provide a value for unsubscribed groups --- libretroshare/src/gxs/rsgds.h | 1 + libretroshare/src/gxs/rsgenexchange.cc | 9 ++++++++- libretroshare/src/gxs/rsgxsnetservice.cc | 18 ++++++++++++------ libretroshare/src/gxs/rsgxsutil.cc | 4 ++-- libretroshare/src/gxstrans/p3gxstrans.cc | 7 +++++++ libretroshare/src/rsitems/rsgxsupdateitems.h | 6 ++++-- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/libretroshare/src/gxs/rsgds.h b/libretroshare/src/gxs/rsgds.h index 303d411b8..2cb153056 100644 --- a/libretroshare/src/gxs/rsgds.h +++ b/libretroshare/src/gxs/rsgds.h @@ -92,6 +92,7 @@ public: uint32_t mMaxVisibleCount ; bool mGrpAutoSync ; bool mAllowMsgSync; + time_t mLastGroupModificationTS ; }; typedef std::map > NxsMsgDataResult; diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 5aa526a0f..e48988e33 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -65,7 +65,7 @@ static const uint32_t INDEX_AUTHEN_ADMIN = 0x00000040; // admin key //#define GEN_EXCH_DEBUG 1 -static const uint32_t MSG_CLEANUP_PERIOD = 6 *59; // 59 minutes +static const uint32_t MSG_CLEANUP_PERIOD = 60*59; // 59 minutes static const uint32_t INTEGRITY_CHECK_PERIOD = 60*31; // 31 minutes RsGenExchange::RsGenExchange(RsGeneralDataService *gds, RsNetworkExchangeService *ns, @@ -1376,6 +1376,13 @@ 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/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index 3b84b900b..94a321e9d 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -333,7 +333,7 @@ RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds, if(mDefaultMsgStorePeriod > 0 && mDefaultMsgSyncPeriod > mDefaultMsgStorePeriod) { std::cerr << "(WW) in GXS service \"" << getServiceInfo().mServiceName << "\": too large message sync period will be set to message store period." << std::endl; - mDefaultMsgSyncPeriod == mDefaultMsgStorePeriod ; + mDefaultMsgSyncPeriod = mDefaultMsgStorePeriod ; } } @@ -696,7 +696,7 @@ void RsGxsNetService::syncGrpStatistics() GXSNETDEBUG__G(it->first) << " group " << it->first ; #endif - if(rec.update_TS + GROUP_STATS_UPDATE_DELAY < now && rec.suppliers.ids.size() > 0) + if(rec.statistics_update_TS + GROUP_STATS_UPDATE_DELAY < now && rec.suppliers.ids.size() > 0) { #ifdef NXS_NET_DEBUG_6 GXSNETDEBUG__G(it->first) << " needs update. Randomly asking to some friends" << std::endl; @@ -796,7 +796,10 @@ void RsGxsNetService::handleRecvSyncGrpStatistics(RsNxsSyncGrpStatsItem *grs) grs_resp->grpId = grs->grpId; grs_resp->PeerId(grs->PeerId()) ; - grs_resp->last_post_TS = 0 ; + grs_resp->last_post_TS = grpMeta->mPublishTs ; // This is not zero, and necessarily older than any message in the group up to clock precision. + // This allows us to use 0 as "uninitialized" proof. If the group meta has been changed, this time + // will be more recent than some messages. This shouldn't be a problem, since this value can only + // be used to discard groups that are not used. for(uint32_t i=0;iPeerId()) ; rec.max_visible_count = std::max(rec.max_visible_count,grs->number_of_posts) ; - rec.update_TS = time(NULL) ; + rec.statistics_update_TS = time(NULL) ; + rec.last_group_modification_TS = grs->last_post_TS; if (old_count != rec.max_visible_count || old_suppliers_count != rec.suppliers.ids.size()) mNewStatsToNotify.insert(grs->grpId) ; @@ -1433,7 +1437,7 @@ bool RsGxsNetService::loadList(std::list &load) // the update time stamp is randomised so as not to ask all friends at once about group statistics. - it->second.update_TS = now - GROUP_STATS_UPDATE_DELAY + (RSRandom::random_u32()%(GROUP_STATS_UPDATE_DELAY/10)) ; + it->second.statistics_update_TS = now - GROUP_STATS_UPDATE_DELAY + (RSRandom::random_u32()%(GROUP_STATS_UPDATE_DELAY/10)) ; // Similarly, we remove all suppliers. // Actual suppliers will come back automatically. @@ -2307,6 +2311,7 @@ bool RsGxsNetService::getGroupNetworkStats(const RsGxsGroupId& gid,RsGroupNetwor stats.mMaxVisibleCount = it->second.max_visible_count ; stats.mAllowMsgSync = mAllowMsgSync ; stats.mGrpAutoSync = mGrpAutoSync ; + stats.mLastGroupModificationTS = it->second.last_group_modification_TS ; return true ; } @@ -4477,7 +4482,8 @@ RsGxsGrpConfig& RsGxsNetService::locked_getGrpConfig(const RsGxsGroupId& grp_id) conf.msg_req_delay = mDefaultMsgSyncPeriod; conf.max_visible_count = 0 ; - conf.update_TS = 0 ; + conf.statistics_update_TS = 0 ; + conf.last_group_modification_TS = 0 ; return conf ; } diff --git a/libretroshare/src/gxs/rsgxsutil.cc b/libretroshare/src/gxs/rsgxsutil.cc index d9fc6dbc9..41d3bec9b 100644 --- a/libretroshare/src/gxs/rsgxsutil.cc +++ b/libretroshare/src/gxs/rsgxsutil.cc @@ -33,9 +33,9 @@ static const uint32_t MAX_GXS_IDS_REQUESTS_NET = 10 ; // max number of requests from cache/net (avoids killing the system!) -#define DEBUG_GXSUTIL 1 +//#define DEBUG_GXSUTIL 1 -#define GXSUTIL_DEBUG() std::cerr << time(NULL) << " : GXS_UTIL : " << __FUNCTION__ << " : " +#define GXSUTIL_DEBUG() std::cerr << "[" << time(NULL) << "] : GXS_UTIL : " << __FUNCTION__ << " : " RsGxsMessageCleanUp::RsGxsMessageCleanUp(RsGeneralDataService* const dataService, RsGenExchange *genex, uint32_t chunkSize) : mDs(dataService), mGenExchangeClient(genex), CHUNK_SIZE(chunkSize) diff --git a/libretroshare/src/gxstrans/p3gxstrans.cc b/libretroshare/src/gxstrans/p3gxstrans.cc index 71cc9763e..216be1f18 100644 --- a/libretroshare/src/gxstrans/p3gxstrans.cc +++ b/libretroshare/src/gxstrans/p3gxstrans.cc @@ -143,6 +143,9 @@ void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type) { case GROUPS_LIST: { +#ifdef DEBUG_GXSTRANS + std::cerr << " Reviewing available groups. " << std::endl; +#endif std::vector groups; getGroupData(token, groups); @@ -491,6 +494,10 @@ void p3GxsTrans::service_tick() mCleanupThread->start() ; mLastMsgCleanup = now ; } + + // This forces to review all groups, and decide to subscribe or not to each of them. + + requestGroupsData(); } // now grab collected messages to delete diff --git a/libretroshare/src/rsitems/rsgxsupdateitems.h b/libretroshare/src/rsitems/rsgxsupdateitems.h index 8ea020fe5..15a0976b6 100644 --- a/libretroshare/src/rsitems/rsgxsupdateitems.h +++ b/libretroshare/src/rsitems/rsgxsupdateitems.h @@ -68,7 +68,8 @@ public: msg_req_delay = RS_GXS_DEFAULT_MSG_REQ_PERIOD ; max_visible_count = 0 ; - update_TS = 0 ; + statistics_update_TS = 0 ; + last_group_modification_TS = 0 ; } uint32_t msg_keep_delay ; // delay after which we discard the posts @@ -77,7 +78,8 @@ public: RsTlvPeerIdSet suppliers; // list of friends who feed this group uint32_t max_visible_count ; // max visible count reported by contributing friends - time_t update_TS ; // last time the max visible count was updated. + time_t statistics_update_TS ; // last time the max visible count was updated. + time_t last_group_modification_TS ; // last time the group was modified, either in meta data or in the list of messages posted in it. }; class RsGxsGrpConfigItem : public RsGxsNetServiceItem, public RsGxsGrpConfig