diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index a654ae720..f28ddedc1 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -655,8 +655,8 @@ void RsGxsNetService::syncGrpStatistics() mDataStore->retrieveGxsGrpMetaData(grpMeta); - std::set peers; - mNetMgr->getOnlineList(mServiceInfo.mServiceType, peers); + std::set online_peers; + mNetMgr->getOnlineList(mServiceInfo.mServiceType, online_peers); // Go through group statistics and groups without information are re-requested to random peers selected // among the ones who provided the group info. @@ -684,25 +684,28 @@ void RsGxsNetService::syncGrpStatistics() ++rit ; for(uint32_t i=0;ifirst) << " asking friend " << peer_id << " for an update of stats for group " << it->first << std::endl; + GXSNETDEBUG_PG(peer_id,it->first) << " asking friend " << peer_id << " for an update of stats for group " << it->first << std::endl; #endif - RsNxsSyncGrpStats *grs = new RsNxsSyncGrpStats(mServType) ; - - grs->request_type = RsNxsSyncGrpStats::GROUP_INFO_TYPE_REQUEST ; - grs->grpId = it->first ; - grs->PeerId(peer_id) ; + RsNxsSyncGrpStats *grs = new RsNxsSyncGrpStats(mServType) ; - sendItem(grs) ; - } + grs->request_type = RsNxsSyncGrpStats::GROUP_INFO_TYPE_REQUEST ; + grs->grpId = it->first ; + grs->PeerId(peer_id) ; + + sendItem(grs) ; + } + } } #ifdef NXS_NET_DEBUG_0 else @@ -725,6 +728,14 @@ void RsGxsNetService::handleRecvSyncGrpStatistics(RsNxsSyncGrpStats *grs) RsGxsGrpMetaData* grpMeta = grpMetas[grs->grpId]; + if(grpMeta == NULL) + { +#ifdef NXS_NET_DEBUG_0 + GXSNETDEBUG_PG(grs->PeerId(),grs->grpId) << " Group is unknown. Not reponding." << std::endl; +#endif + return ; + } + // check if we're subscribed or not if(! (grpMeta->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED )) @@ -782,9 +793,15 @@ void RsGxsNetService::handleRecvSyncGrpStatistics(RsNxsSyncGrpStats *grs) RS_STACK_MUTEX(mNxsMutex) ; RsGroupNetworkStatsRecord& rec(mGroupNetworkStats[grs->grpId]) ; + int32_t old_count = rec.max_visible_count ; + int32_t old_suppliers_count = rec.suppliers.size() ; + rec.suppliers.insert(grs->PeerId()) ; rec.max_visible_count = std::max(rec.max_visible_count,grs->number_of_posts) ; rec.update_TS = time(NULL) ; + + if (old_count != rec.max_visible_count || old_suppliers_count != rec.suppliers.size()) + mObserver->notifyChangedGroupStats(grs->grpId); } else std::cerr << "(EE) RsGxsNetService::handleRecvSyncGrpStatistics(): unknown item type " << grs->request_type << " found. This is a bug." << std::endl; diff --git a/libretroshare/src/serialiser/rsnxsitems.cc b/libretroshare/src/serialiser/rsnxsitems.cc index 30bc09864..858760b76 100644 --- a/libretroshare/src/serialiser/rsnxsitems.cc +++ b/libretroshare/src/serialiser/rsnxsitems.cc @@ -38,6 +38,7 @@ uint32_t RsNxsSerialiser::size(RsItem *item) { RsNxsGrp* ngp; RsNxsMsg* nmg; RsNxsSyncGrp* sg; + RsNxsSyncGrpStats* sgs; RsNxsSyncGrpItem* sgl; RsNxsSyncMsg* sgm; RsNxsSyncMsgItem* sgml; @@ -52,6 +53,9 @@ uint32_t RsNxsSerialiser::size(RsItem *item) { { return sizeNxsSyncGrp(sg); + } else if((sgs = dynamic_cast(item)) != NULL) + { + return sizeNxsSyncGrpStats(sgs); }else if(( ntx = dynamic_cast(item)) != NULL){ return sizeNxsTrans(ntx); } @@ -109,6 +113,8 @@ RsItem* RsNxsSerialiser::deserialise(void *data, uint32_t *size) { return deserialNxsSyncMsgItem(data, size); case RS_PKT_SUBTYPE_NXS_GRP: return deserialNxsGrp(data, size); + case RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS: + return deserialNxsSyncGrpStats(data, size); case RS_PKT_SUBTYPE_NXS_MSG: return deserialNxsMsg(data, size); case RS_PKT_SUBTYPE_NXS_TRANS: @@ -134,6 +140,7 @@ bool RsNxsSerialiser::serialise(RsItem *item, void *data, uint32_t *size){ RsNxsGrp* ngp; RsNxsMsg* nmg; RsNxsSyncGrp* sg; + RsNxsSyncGrpStats* sgs; RsNxsSyncGrpItem* sgl; RsNxsSyncMsg* sgm; RsNxsSyncMsgItem* sgml; @@ -144,6 +151,10 @@ bool RsNxsSerialiser::serialise(RsItem *item, void *data, uint32_t *size){ { return serialiseNxsSyncGrp(sg, data, size); + }else if((sgs = dynamic_cast(item)) != NULL) + { + return serialiseNxsSyncGrpStats(sgs, data, size); + }else if ((ntx = dynamic_cast(item)) != NULL) { return serialiseNxsTrans(ntx, data, size);