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() void RsGenExchange::data_tick()
{ {

View file

@ -616,6 +616,14 @@ public:
void shareGroupPublishKey(const RsGxsGroupId& grpId,const std::set<RsPeerId>& peers) ; 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: protected:
/** Notifications **/ /** Notifications **/

View file

@ -215,6 +215,8 @@ class RsGcxs
virtual int canReceive(const RsGxsCircleId &circleId, const RsPgpId &id) = 0; 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<RsPgpId>& friendlist) = 0;
virtual bool recipients(const RsGxsCircleId &circleId, std::list<RsGxsId>& idlist) = 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, RsGxsCircleExchange(RsGeneralDataService* gds, RsNetworkExchangeService* ns, RsSerialType* serviceSerialiser,
uint16_t mServType, RsGixs* gixs, uint32_t authenPolicy) uint16_t mServType, RsGixs* gixs, uint32_t authenPolicy)
:RsGenExchange(gds,ns,serviceSerialiser,mServType, gixs, authenPolicy) { return; } :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,14 +1929,14 @@ void RsGxsNetService::updateClientSyncTS()
void RsGxsNetService::updateServerSyncTS() void RsGxsNetService::updateServerSyncTS()
{ {
RS_STACK_MUTEX(mNxsMutex) ;
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> gxsMap; 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; GXSNETDEBUG___<< "updateServerSyncTS(): updating last modification time stamp of local data." << std::endl;
#endif //#endif
{
RS_STACK_MUTEX(mNxsMutex) ;
// retrieve all grps and update TS // retrieve all grps and update TS
mDataStore->retrieveGxsGrpMetaData(gxsMap); mDataStore->retrieveGxsGrpMetaData(gxsMap);
@ -1949,8 +1949,6 @@ void RsGxsNetService::updateServerSyncTS()
if(mGrpServerUpdateItem == NULL) if(mGrpServerUpdateItem == NULL)
mGrpServerUpdateItem = new RsGxsServerGrpUpdateItem(mServType); mGrpServerUpdateItem = new RsGxsServerGrpUpdateItem(mServType);
bool change = false;
// then remove from mServerMsgUpdateMap, all items that are not in the group list! // then remove from mServerMsgUpdateMap, all items that are not in the group list!
#ifdef NXS_NET_DEBUG_0 #ifdef NXS_NET_DEBUG_0
@ -1972,20 +1970,54 @@ void RsGxsNetService::updateServerSyncTS()
} }
else else
++it; ++it;
}
#ifdef NXS_NET_DEBUG_0 #ifdef NXS_NET_DEBUG_0
if(gxsMap.empty()) if(gxsMap.empty())
GXSNETDEBUG___<< " database seems to be empty. The modification timestamp will be reset." << std::endl; GXSNETDEBUG___<< " database seems to be empty. The modification timestamp will be reset." << std::endl;
#endif #endif
// finally, update timestamps. // finally, update timestamps.
bool change = false;
for(std::map<RsGxsGroupId, RsGxsGrpMetaData*>::const_iterator mit = gxsMap.begin();mit != gxsMap.end(); ++mit) for(std::map<RsGxsGroupId, RsGxsGrpMetaData*>::const_iterator mit = gxsMap.begin();mit != gxsMap.end(); ++mit)
{ {
const RsGxsGroupId& grpId = mit->first; 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 #ifdef TO_REMOVE
// That accounts for modification of the meta data. // That accounts for modification of the meta data.
@ -1998,6 +2030,8 @@ void RsGxsNetService::updateServerSyncTS()
} }
#endif #endif
ServerMsgMap::iterator mapIT = mServerMsgUpdateMap.find(grpId);
if(mapIT == mServerMsgUpdateMap.end()) if(mapIT == mServerMsgUpdateMap.end())
{ {
msui = new RsGxsServerMsgUpdateItem(mServType); 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; 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 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 */ /* p3Config methods */
public: public:

View file

@ -134,6 +134,16 @@ public:
* \param msgId * \param msgId
*/ */
virtual void rejectMessage(const RsGxsMessageId& msgId) =0; 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 #endif // RSGNP_H