added group data request when search items are selected

This commit is contained in:
csoler 2018-07-04 21:42:09 +02:00
parent 80a43fe3d5
commit 8ad454723a
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
6 changed files with 49 additions and 1 deletions

View File

@ -304,6 +304,7 @@ static const uint32_t REJECTED_MESSAGE_RETRY_DELAY = 24*3600; //
static const uint32_t GROUP_STATS_UPDATE_DELAY = 240; // update unsubscribed group statistics every 3 mins
static const uint32_t GROUP_STATS_UPDATE_NB_PEERS = 2; // number of peers to which the group stats are asked
static const uint32_t MAX_ALLOWED_GXS_MESSAGE_SIZE = 199000; // 200,000 bytes including signature and headers
static const uint32_t MIN_DELAY_BETWEEN_GROUP_SEARCH = 40; // dont search same group more than every 40 secs.
static const uint32_t RS_NXS_ITEM_ENCRYPTION_STATUS_UNKNOWN = 0x00 ;
static const uint32_t RS_NXS_ITEM_ENCRYPTION_STATUS_NO_ERROR = 0x01 ;
@ -380,6 +381,8 @@ RsGxsNetService::RsGxsNetService(uint16_t servType, RsGeneralDataService *gds,
mOwnId = mNetMgr->getOwnId();
mUpdateCounter = 0;
mLastCacheReloadTS = 0;
// check the consistency
if(mDefaultMsgStorePeriod > 0 && mDefaultMsgSyncPeriod > mDefaultMsgStorePeriod)
@ -5106,7 +5109,25 @@ bool RsGxsNetService::locked_stampMsgServerUpdateTS(const RsGxsGroupId& gid)
TurtleRequestId RsGxsNetService::turtleGroupRequest(const RsGxsGroupId& group_id)
{
time_t now = time(NULL);
auto it = mSearchedGroups.find(group_id) ;
if(mSearchedGroups.end() != it && (it->second.ts + MIN_DELAY_BETWEEN_GROUP_SEARCH > now))
{
std::cerr << "(WW) Last turtle request was " << now - it->second.ts << " secs ago. Not searching again." << std::endl;
return it->second.request_id;
}
#ifdef NXS_NET_DEBUG_8
GXSNETDEBUG__G(group_id) << " requesting group id " << group_id << " using turtle" << std::endl;
#endif
TurtleRequestId req = mGxsNetTunnel->turtleGroupRequest(group_id,this) ;
GroupRequestRecord& rec(mSearchedGroups[group_id]) ;
rec.request_id = req;
rec.ts = now;
mSearchRequests[req] = group_id;
return req;
@ -5302,7 +5323,7 @@ bool RsGxsNetService::search(const Sha1CheckSum& hashed_group_id,unsigned char *
{
// Now check if the last request was too close in time, in which case, we dont retrieve data.
if(mLastCacheReloadTS + 60 < time(NULL))
if(mLastCacheReloadTS + 60 > time(NULL))
{
std::cerr << "(WW) Not found in cache, and last cache reload less than 60 secs ago. Returning false. " << std::endl;
return false ;
@ -5315,6 +5336,7 @@ bool RsGxsNetService::search(const Sha1CheckSum& hashed_group_id,unsigned char *
{
RS_STACK_MUTEX(mNxsMutex) ;
mDataStore->retrieveNxsGrps(grpDataMap, true, true);
mLastCacheReloadTS = time(NULL);
}
for(auto it(grpDataMap.begin());it!=grpDataMap.end();++it)

View File

@ -59,6 +59,14 @@ class RsGroupNetworkStatsRecord
time_t update_TS ;
};
struct GroupRequestRecord
{
GroupRequestRecord(): ts(0), request_id(0) {}
time_t ts ;
TurtleRequestId request_id;
};
/*!
* This class implements the RsNetWorkExchangeService
* using transactions to handle synchrnisation of Nxs items between
@ -615,6 +623,7 @@ private:
std::map<Sha1CheckSum, RsNxsGrp*> mGroupHashCache;
std::map<TurtleRequestId,RsGxsGroupId> mSearchRequests;
std::map<RsGxsGroupId,GroupRequestRecord> mSearchedGroups ;
time_t mLastCacheReloadTS ;
};

View File

@ -767,6 +767,9 @@ void GxsGroupFrameDialog::changedCurrentGroup(const QString &groupId)
return;
}
// send a request for the group, if it has been distant-searched.
checkRequestGroup(mGroupId) ;
/* search exisiting tab */
GxsMessageFrameWidget *msgWidget = messageWidget(mGroupId, true);

View File

@ -95,6 +95,7 @@ protected:
virtual RetroShareLink::enumType getLinkType() = 0;
virtual GroupFrameSettings::Type groupFrameSettingsType() { return GroupFrameSettings::Nothing; }
virtual void groupInfoToGroupItemInfo(const RsGroupMetaData &groupInfo, GroupItemInfo &groupItemInfo, const RsUserdata *userdata);
virtual void checkRequestGroup(const RsGxsGroupId& grpId) {}
private slots:
void todo();

View File

@ -346,3 +346,14 @@ bool GxsChannelDialog::getDistantSearchResults(TurtleRequestId id, std::map<RsGx
{
return rsGxsChannels->retrieveDistantSearchResults(id,group_infos);
}
void GxsChannelDialog::checkRequestGroup(const RsGxsGroupId& grpId)
{
RsGxsChannelGroup distant_group;
if( rsGxsChannels->retrieveDistantGroup(grpId,distant_group)) // normally we should also check that the group meta is not already here.
{
std::cerr << "GxsChannelDialog::checkRequestGroup() sending turtle request for group data for group " << grpId << std::endl;
rsGxsChannels->turtleGroupRequest(grpId);
}
}

View File

@ -53,6 +53,8 @@ protected:
virtual bool getDistantSearchResults(TurtleRequestId id, std::map<RsGxsGroupId,RsGxsGroupSummary>& group_infos);
virtual TurtleRequestId distantSearch(const QString& search_string) ;
virtual void checkRequestGroup(const RsGxsGroupId& grpId) ;
private slots:
void toggleAutoDownload();
void setDefaultDirectory();