update of groups up to the latest attached circle server update TS. Should re-send groups that depend on a circle when the circle change

This commit is contained in:
csoler 2016-03-21 23:21:26 -04:00
parent b153c2e119
commit 1fb1f3ebaf
6 changed files with 122 additions and 38 deletions

View File

@ -156,6 +156,11 @@ RsGenExchange::~RsGenExchange()
}
bool RsGenExchange::getGroupServerUpdateTS(const RsGxsGroupId& gid, time_t& grp_server_update_TS, time_t& msg_server_update_TS)
{
return mNetService->getGroupServerUpdateTS(gid,grp_server_update_TS,msg_server_update_TS) ;
}
void RsGenExchange::data_tick()
{

View File

@ -615,6 +615,14 @@ public:
*/
void shareGroupPublishKey(const RsGxsGroupId& grpId,const std::set<RsPeerId>& peers) ;
/*!
* Returns the local TS of the group as known by the network service.
* This is useful to allow various network services to sync their update TS
* when needed. Typical use case is forums and circles.
* @param gid GroupId the TS is which is requested
*/
bool getGroupServerUpdateTS(const RsGxsGroupId& gid,time_t& grp_server_update_TS,time_t& msg_server_update_TS) ;
protected:

View File

@ -215,6 +215,8 @@ 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 getLocalCircleServerUpdateTS(const RsGxsCircleId& gid,time_t& grp_server_update_TS,time_t& msg_server_update_TS) =0;
};
@ -225,8 +227,12 @@ public:
RsGxsCircleExchange(RsGeneralDataService* gds, RsNetworkExchangeService* ns, RsSerialType* serviceSerialiser,
uint16_t mServType, RsGixs* gixs, uint32_t authenPolicy)
:RsGenExchange(gds,ns,serviceSerialiser,mServType, gixs, authenPolicy) { return; }
virtual ~RsGxsCircleExchange() { return; }
virtual ~RsGxsCircleExchange() { return; }
virtual bool getLocalCircleServerUpdateTS(const RsGxsCircleId& gid,time_t& grp_server_update_TS,time_t& msg_server_update_TS)
{
return RsGenExchange::getGroupServerUpdateTS(RsGxsGroupId(gid),grp_server_update_TS,msg_server_update_TS) ;
}
};

View File

@ -1929,63 +1929,95 @@ void RsGxsNetService::updateClientSyncTS()
void RsGxsNetService::updateServerSyncTS()
{
RS_STACK_MUTEX(mNxsMutex) ;
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> gxsMap;
#ifdef NXS_NET_DEBUG_0
//#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG___<< "updateServerSyncTS(): updating last modification time stamp of local data." << std::endl;
#endif
//#endif
// retrieve all grps and update TS
mDataStore->retrieveGxsGrpMetaData(gxsMap);
{
RS_STACK_MUTEX(mNxsMutex) ;
// retrieve all grps and update TS
mDataStore->retrieveGxsGrpMetaData(gxsMap);
// (cyril) This code was previously removed because it sounded inconsistent: the list of grps normally does not need to be updated when
// new posts arrive. The two (grp list and msg list) are handled independently. Still, when group meta data updates are received,
// the server TS needs to be updated, because it is the only way to propagate the changes. So we update it to the publish time stamp,
// if needed.
// as a grp list server also note this is the latest item you have
if(mGrpServerUpdateItem == NULL)
mGrpServerUpdateItem = new RsGxsServerGrpUpdateItem(mServType);
// (cyril) This code was previously removed because it sounded inconsistent: the list of grps normally does not need to be updated when
// new posts arrive. The two (grp list and msg list) are handled independently. Still, when group meta data updates are received,
// the server TS needs to be updated, because it is the only way to propagate the changes. So we update it to the publish time stamp,
// if needed.
bool change = false;
// as a grp list server also note this is the latest item you have
if(mGrpServerUpdateItem == NULL)
mGrpServerUpdateItem = new RsGxsServerGrpUpdateItem(mServType);
// then remove from mServerMsgUpdateMap, all items that are not in the group list!
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG___ << " cleaning server map of groups with no data:" << std::endl;
#endif
for(std::map<RsGxsGroupId, RsGxsServerMsgUpdateItem*>::iterator it(mServerMsgUpdateMap.begin());it!=mServerMsgUpdateMap.end();)
if(gxsMap.find(it->first) == gxsMap.end())
{
// not found! Removing server update info for this group
// then remove from mServerMsgUpdateMap, all items that are not in the group list!
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG__G(it->first) << " removing server update info for group " << it->first << std::endl;
GXSNETDEBUG___ << " cleaning server map of groups with no data:" << std::endl;
#endif
std::map<RsGxsGroupId, RsGxsServerMsgUpdateItem*>::iterator tmp(it) ;
++tmp ;
mServerMsgUpdateMap.erase(it) ;
it = tmp ;
}
else
++it;
for(std::map<RsGxsGroupId, RsGxsServerMsgUpdateItem*>::iterator it(mServerMsgUpdateMap.begin());it!=mServerMsgUpdateMap.end();)
if(gxsMap.find(it->first) == gxsMap.end())
{
// not found! Removing server update info for this group
#ifdef NXS_NET_DEBUG_0
GXSNETDEBUG__G(it->first) << " removing server update info for group " << it->first << std::endl;
#endif
std::map<RsGxsGroupId, RsGxsServerMsgUpdateItem*>::iterator tmp(it) ;
++tmp ;
mServerMsgUpdateMap.erase(it) ;
it = tmp ;
}
else
++it;
}
#ifdef NXS_NET_DEBUG_0
if(gxsMap.empty())
GXSNETDEBUG___<< " database seems to be empty. The modification timestamp will be reset." << std::endl;
#endif
// finally, update timestamps.
bool change = false;
for(std::map<RsGxsGroupId, RsGxsGrpMetaData*>::const_iterator mit = gxsMap.begin();mit != gxsMap.end(); ++mit)
{
const RsGxsGroupId& grpId = mit->first;
const RsGxsGrpMetaData* grpMeta = mit->second;
ServerMsgMap::iterator mapIT = mServerMsgUpdateMap.find(grpId);
RsGxsServerMsgUpdateItem* msui = NULL;
// Check if the group is subscribed and restricted to a circle. If the circle has changed, update the
// global TS to reflect that change to clients who may be able to see/subscribe to that particular group.
if( (mit->second->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED) && !mit->second->mCircleId.isNull())
{
// ask to the GxsNetService of circles what the server TS is for that circle. If more recent, we update the serverTS of the
// local group
time_t circle_group_server_ts ;
time_t circle_msg_server_ts ;
// This call needs to be off-mutex, because of self-restricted circles.
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";
if(circle_group_server_ts > mGrpServerUpdateItem->grpUpdateTS)
{
std::cerr << " - Updating local Grp Server update TS to follow changes in circles." << std::endl;
RS_STACK_MUTEX(mNxsMutex) ;
mGrpServerUpdateItem->grpUpdateTS = circle_group_server_ts ;
}
else
std::cerr << " - Nothing to do." << std::endl;
}
else
std::cerr << "(EE) Cannot retrieve attached circle TS" << std::endl;
}
RS_STACK_MUTEX(mNxsMutex) ;
const RsGxsGrpMetaData* grpMeta = mit->second;
RsGxsServerMsgUpdateItem* msui = NULL;
#ifdef TO_REMOVE
// That accounts for modification of the meta data.
@ -1998,6 +2030,8 @@ void RsGxsNetService::updateServerSyncTS()
}
#endif
ServerMsgMap::iterator mapIT = mServerMsgUpdateMap.find(grpId);
if(mapIT == mServerMsgUpdateMap.end())
{
msui = new RsGxsServerMsgUpdateItem(mServType);
@ -4832,3 +4866,22 @@ void RsGxsNetService::handleRecvPublishKeys(RsNxsGroupPublishKeyItem *item)
std::cerr << "(EE) could not update database. Something went wrong." << std::endl;
}
}
bool RsGxsNetService::getGroupServerUpdateTS(const RsGxsGroupId& gid,time_t& group_server_update_TS, time_t& msg_server_update_TS)
{
RS_STACK_MUTEX(mNxsMutex) ;
if(mGrpServerUpdateItem == NULL)
return false ;
group_server_update_TS = mGrpServerUpdateItem->grpUpdateTS ;
std::map<RsGxsGroupId,RsGxsServerMsgUpdateItem*>::iterator it = mServerMsgUpdateMap.find(gid) ;
if(mServerMsgUpdateMap.end() == it)
msg_server_update_TS = 0 ;
else
msg_server_update_TS = it->second->msgUpdateTS ;
return true ;
}

View File

@ -154,6 +154,8 @@ public:
virtual void rejectMessage(const RsGxsMessageId& msg_id) ;
virtual bool getGroupServerUpdateTS(const RsGxsGroupId& gid,time_t& grp_server_update_TS,time_t& msg_server_update_TS) ;
/* p3Config methods */
public:

View File

@ -134,6 +134,16 @@ public:
* \param msgId
*/
virtual void rejectMessage(const RsGxsMessageId& msgId) =0;
/*!
* \brief getGroupServerUpdateTS
* Returns the server update time stamp for that group. This is used for synchronisation of TS between
* various network exchange services, suhc as channels/circles or forums/circles
* \param gid group for that request
* \param tm time stamp computed
* \return false if the group is not found, true otherwise
*/
virtual bool getGroupServerUpdateTS(const RsGxsGroupId& gid,time_t& grp_server_update_TS,time_t& msg_server_update_TS) =0;
};
#endif // RSGNP_H