added machinery to allow to set/get sync and store periods for GXS groups

This commit is contained in:
csoler 2016-12-05 22:14:48 +01:00
parent d2ef2248c6
commit 7afb91d1db
13 changed files with 188 additions and 34 deletions

View File

@ -1608,6 +1608,54 @@ void RsGenExchange::publishMsg(uint32_t& token, RsGxsMsgItem *msgItem)
}
uint32_t RsGenExchange::getDefaultSyncPeriod()
{
RS_STACK_MUTEX(mGenMtx) ;
if(mNetService != NULL)
return mNetService->getDefaultSyncAge();
else
{
std::cerr << "(EE) No network service available. Cannot get default sync period. " << std::endl;
return 0;
}
}
uint32_t RsGenExchange::getSyncPeriod(const RsGxsGroupId& grpId)
{
RS_STACK_MUTEX(mGenMtx) ;
if(mNetService != NULL)
return mNetService->getSyncAge(grpId);
else
return mNetService->getDefaultSyncAge();
}
void RsGenExchange::setSyncPeriod(const RsGxsGroupId& grpId,uint32_t age_in_secs)
{
if(mNetService != NULL)
return mNetService->setKeepAge(grpId,age_in_secs) ;
else
std::cerr << "(EE) No network service available. Cannot set storage period. " << std::endl;
}
uint32_t RsGenExchange::getStoragePeriod(const RsGxsGroupId& grpId)
{
RS_STACK_MUTEX(mGenMtx) ;
if(mNetService != NULL)
return mNetService->getKeepAge(grpId,MESSAGE_STORE_PERIOD) ;
else
return MESSAGE_STORE_PERIOD;
}
void RsGenExchange::setStoragePeriod(const RsGxsGroupId& grpId,uint32_t age_in_secs)
{
if(mNetService != NULL)
return mNetService->setKeepAge(grpId,age_in_secs) ;
else
std::cerr << "(EE) No network service available. Cannot set storage period. " << std::endl;
}
void RsGenExchange::setGroupSubscribeFlags(uint32_t& token, const RsGxsGroupId& grpId, const uint32_t& flag, const uint32_t& mask)
{
/* TODO APPLY MASK TO FLAGS */

View File

@ -611,11 +611,6 @@ public:
*/
void updateGroupLastMsgTimeStamp(uint32_t& token, const RsGxsGroupId& grpId);
/*!
* @return storage time of messages in months
*/
int getStoragePeriod(){ return MESSAGE_STORE_PERIOD/(60*60*24*31);}
/*!
* sets the msg status flag
* @param token this is set to token value associated to this request
@ -647,6 +642,19 @@ public:
*/
bool getGroupServerUpdateTS(const RsGxsGroupId& gid,time_t& grp_server_update_TS,time_t& msg_server_update_TS) ;
/*!
* \brief getDefaultStoragePeriod. All times in seconds.
* \return
*/
virtual uint32_t getDefaultStoragePeriod() { return MESSAGE_STORE_PERIOD; }
virtual uint32_t getStoragePeriod(const RsGxsGroupId& grpId) ;
virtual void setStoragePeriod(const RsGxsGroupId& grpId,uint32_t age_in_secs) ;
virtual uint32_t getDefaultSyncPeriod();
virtual uint32_t getSyncPeriod(const RsGxsGroupId& grpId) ;
virtual void setSyncPeriod(const RsGxsGroupId& grpId,uint32_t age_in_secs) ;
protected:
/** Notifications **/
@ -860,7 +868,6 @@ private:
std::vector<GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair> > mMsgPendingValidate;
typedef std::vector<GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair> > NxsMsgPendingVect;
const uint32_t MESSAGE_STORE_PERIOD;
bool mCleaning;

View File

@ -4431,6 +4431,29 @@ void RsGxsNetService::setKeepAge(const RsGxsGroupId &grpId, uint32_t age_in_secs
}
}
uint32_t RsGxsNetService::getSyncAge(const RsGxsGroupId& grpId)
{
RS_STACK_MUTEX(mNxsMutex) ;
GrpConfigMap::const_iterator it = mServerGrpConfigMap.find(grpId) ;
if(it == mServerGrpConfigMap.end())
return mSYNC_PERIOD ;
else
return it->second.msg_keep_delay ;
}
uint32_t RsGxsNetService::getKeepAge(const RsGxsGroupId& grpId,uint32_t default_value)
{
RS_STACK_MUTEX(mNxsMutex) ;
GrpConfigMap::const_iterator it = mServerGrpConfigMap.find(grpId) ;
if(it == mServerGrpConfigMap.end())
return default_value ;
else
return it->second.msg_req_delay ;
}
int RsGxsNetService::requestGrp(const std::list<RsGxsGroupId>& grpId, const RsPeerId& peerId)
{
RS_STACK_MUTEX(mNxsMutex) ;

View File

@ -109,6 +109,11 @@ public:
virtual void setSyncAge(const RsGxsGroupId& grpId,uint32_t age_in_secs);
virtual void setKeepAge(const RsGxsGroupId& grpId,uint32_t age_in_secs);
virtual uint32_t getSyncAge(const RsGxsGroupId& id);
virtual uint32_t getKeepAge(const RsGxsGroupId& id,uint32_t default_value);
virtual uint32_t getDefaultSyncAge() { return mSYNC_PERIOD ; }
/*!
* pauses synchronisation of subscribed groups and request for group id
* from peers

View File

@ -67,8 +67,13 @@ public:
* Use this to set how far back synchronisation of messages should take place
* @param age in seconds the max age a sync/store item can to be allowed in a synchronisation
*/
virtual void setSyncAge(const RsGxsGroupId& id,uint32_t age_in_secs) = 0;
virtual void setKeepAge(const RsGxsGroupId& id,uint32_t age_in_secs) = 0;
virtual void setSyncAge(const RsGxsGroupId& id,uint32_t age_in_secs) =0;
virtual void setKeepAge(const RsGxsGroupId& id,uint32_t age_in_secs) =0;
virtual uint32_t getSyncAge(const RsGxsGroupId& id) =0;
virtual uint32_t getKeepAge(const RsGxsGroupId& id,uint32_t default_value) =0;
virtual uint32_t getDefaultSyncAge() =0;
/*!
* Initiates a search through the network

View File

@ -172,9 +172,15 @@ public:
virtual void setGroupReputationCutOff(uint32_t& token, const RsGxsGroupId& grpId, int CutOff) = 0;
/*!
* @return storage time of messages in months
* @return storage/sync time of messages in secs
*/
virtual int getStoragePeriod() = 0;
virtual uint32_t getDefaultStoragePeriod() = 0;
virtual uint32_t getStoragePeriod(const RsGxsGroupId& grpId) = 0;
virtual void setStoragePeriod(const RsGxsGroupId& grpId,uint32_t age_in_secs) = 0;
virtual uint32_t getDefaultSyncPeriod() = 0;
virtual uint32_t getSyncPeriod(const RsGxsGroupId& grpId) = 0;
virtual void setSyncPeriod(const RsGxsGroupId& grpId,uint32_t age_in_secs) = 0;
};

View File

@ -209,11 +209,31 @@ public:
}
/*!
* @return storage time of messages in months
* @return storage/sync time of messages in secs
*/
int getStoragePeriod()
uint32_t getDefaultStoragePeriod()
{
return mGxs->getStoragePeriod();
return mGxs->getDefaultStoragePeriod();
}
uint32_t getStoragePeriod(const RsGxsGroupId& grpId)
{
return mGxs->getStoragePeriod(grpId);
}
void setStoragePeriod(const RsGxsGroupId& grpId,uint32_t age_in_secs)
{
mGxs->setStoragePeriod(grpId,age_in_secs);
}
uint32_t getDefaultSyncPeriod()
{
return mGxs->getDefaultSyncPeriod();
}
uint32_t getSyncPeriod(const RsGxsGroupId& grpId)
{
return mGxs->getSyncPeriod(grpId);
}
void setSyncPeriod(const RsGxsGroupId& grpId,uint32_t age_in_secs)
{
mGxs->setSyncPeriod(grpId,age_in_secs);
}
private:

View File

@ -64,8 +64,8 @@ QString PostedDialog::getHelpString() const
<p>Links can be commented by subscribed users. A promotion system also gives the opportunity to \
enlight important links.</p> \
<p>There is no restriction on which links are shared. Be careful when clicking on them.</p>\
<p>Posted links get deleted after %1 months.</p>\
").arg(QString::number(rsPosted->getStoragePeriod()));
<p>Posted links are kept for %1 days, and sync-ed over the last %2 days, unless you change this.</p>\
").arg(QString::number(rsPosted->getDefaultStoragePeriod()/86400)).arg(QString::number(rsPosted->getDefaultSyncPeriod()/86400));
return hlp_str ;
}

View File

@ -576,9 +576,6 @@ bool GxsGroupDialog::prepareGroupMetaData(RsGroupMetaData &meta)
meta.mGroupFlags = flags;
meta.mSignFlags = getGroupSignFlags();
meta.mGrpDistribution_MaxStorageAge = ui.keepLimit_SB->value() * 86400 ;
meta.mGrpDistribution_MaxRequestAge = ui.syncLimit_SB->value() * 86400 ;
if (!setCircleParameters(meta)){
std::cerr << "GxsGroupDialog::prepareGroupMetaData()";
std::cerr << " Invalid Circles";

View File

@ -285,15 +285,29 @@ void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point)
action = contextMnu.addAction(QIcon(IMAGE_EDIT), tr("Edit Details"), this, SLOT(editGroupDetails()));
action->setEnabled (!mGroupId.isNull() && isAdmin);
QMenu *ctxMenu2 = contextMnu.addMenu(tr("Store posts for at most...")) ;
ctxMenu2->addAction(tr("5 days" ),this,SLOT(setStorePostDelay()))->setData(QVariant( 5 * 86400)) ;
ctxMenu2->addAction(tr("2 weeks" ),this,SLOT(setStorePostDelay()))->setData(QVariant( 15 * 86400)) ;
ctxMenu2->addAction(tr("1 month" ),this,SLOT(setStorePostDelay()))->setData(QVariant( 30 * 86400)) ;
ctxMenu2->addAction(tr("3 months"),this,SLOT(setStorePostDelay()))->setData(QVariant( 90 * 86400)) ;
ctxMenu2->addAction(tr("6 months"),this,SLOT(setStorePostDelay()))->setData(QVariant(180 * 86400)) ;
ctxMenu2->addAction(tr("1 year" ),this,SLOT(setStorePostDelay()))->setData(QVariant( 0 * 86400)) ;
ctxMenu2->addAction(tr("Indefinitely")) ;
ctxMenu2 = contextMnu.addMenu(tr("Synchronise posts of last...")) ;
ctxMenu2->addAction(tr("5 days" ),this,SLOT(setSyncPostDelay()))->setData(QVariant( 5 * 86400)) ;
ctxMenu2->addAction(tr("2 weeks" ),this,SLOT(setSyncPostDelay()))->setData(QVariant( 15 * 86400)) ;
ctxMenu2->addAction(tr("1 month" ),this,SLOT(setSyncPostDelay()))->setData(QVariant( 30 * 86400)) ;
ctxMenu2->addAction(tr("3 months"),this,SLOT(setSyncPostDelay()))->setData(QVariant( 90 * 86400)) ;
ctxMenu2->addAction(tr("6 months"),this,SLOT(setSyncPostDelay()))->setData(QVariant(180 * 86400)) ;
ctxMenu2->addAction(tr("1 year" ),this,SLOT(setSyncPostDelay()))->setData(QVariant( 0 * 86400)) ;
ctxMenu2->addAction(tr("Indefinitely")) ;
if (shareKeyType()) {
action = contextMnu.addAction(QIcon(IMAGE_SHARE), tr("Share publish permissions"), this, SLOT(sharePublishKey()));
action->setEnabled(!mGroupId.isNull() && isPublisher);
}
//if (!mGroupId.isNull() && isPublisher && !isAdmin) {
// contextMnu.addAction(QIcon(":/images/settings16.png"), tr("Restore Publish Rights" ), this, SLOT(restoreGroupKeys()));
//}
if (getLinkType() != RetroShareLink::TYPE_UNKNOWN) {
action = contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyGroupLink()));
action->setEnabled(!mGroupId.isNull());
@ -318,6 +332,41 @@ void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point)
contextMnu.exec(QCursor::pos());
}
void GxsGroupFrameDialog::setStorePostsDelay()
{
QAction *action = dynamic_cast<QAction*>(sender()) ;
if(!action || mGroupId.isNull())
{
std::cerr << "(EE) Cannot find action/group that called me! Group is " << mGroupId << ", action is " << (void*)action << " " << __PRETTY_FUNCTION__ << std::endl;
return;
}
uint32_t duration = action->data().toUInt() ;
std::cerr << "Data is " << duration << std::endl;
mInterface->setStoragePeriod(mGroupId,duration) ;
}
void GxsGroupFrameDialog::setSyncPostsDelay()
{
QAction *action = dynamic_cast<QAction*>(sender()) ;
if(!action || mGroupId.isNull())
{
std::cerr << "(EE) Cannot find action/group that called me! Group is " << mGroupId << ", action is " << (void*)action << " " << __PRETTY_FUNCTION__ << std::endl;
return;
}
uint32_t duration = action->data().toUInt() ;
std::cerr << "Data is " << duration << std::endl;
mInterface->setSyncPeriod(mGroupId,duration) ;
}
void GxsGroupFrameDialog::restoreGroupKeys(void)
{
QMessageBox::warning(this, "RetroShare", "ToDo");

View File

@ -99,6 +99,8 @@ private slots:
/** Create the context popup menu and it's submenus */
void groupTreeCustomPopupMenu(QPoint point);
void settingsChanged();
void setSyncPostsDelay();
void setStorePostsDelay();
void restoreGroupKeys();
void newGroup();

View File

@ -65,8 +65,8 @@ QString GxsChannelDialog::getHelpString() const
the posting rights or the reading rights with friend Retroshare nodes.</p>\
<p>Channels can be made anonymous, or attached to a Retroshare identity so that readers can contact you if needed.\
Enable \"Allow Comments\" if you want to let users comment on your posts.</p>\
<p>Channel posts get deleted after %1 months.</p>\
").arg(QString::number(rsGxsChannels->getStoragePeriod()));
<p>Channel posts are kept for %1 days, and sync-ed over the last %2 days, unless you change this.</p>\
").arg(QString::number(rsGxsChannels->getDefaultStoragePeriod()/86400)).arg(QString::number(rsGxsChannels->getDefaultSyncPeriod()/86400));
return hlp_str ;
}

View File

@ -54,16 +54,8 @@ QString GxsForumsDialog::getHelpString() const
<p>Retroshare Forums look like internet forums, but they work in a decentralized way</p> \
<p>You see forums your friends are subscribed to, and you forward subscribed forums to \
your friends. This automatically promotes interesting forums in the network.</p> \
<p>Forum messages get deleted after %1 months.</p>\
").arg(QString::number(rsGxsForums->getStoragePeriod()));
// not true anymore in v0.6
/*
<p>Forums are either Authenticated (<img src=\":/images/konv_message2.png\" width=\"12\"/>) \
or anonymous (<img src=\":/images/konversation.png\" width=\"12\"/>). The former \
class is more resistant to spamming because posts are \
cryptographically signed using a Retroshare pseudo-identity.</p>") ;
*/
<p>Forum messages are kept for %1 days and sync-ed over the last %2 days, unless you configure it otherwise.</p>\
").arg(QString::number(rsGxsForums->getDefaultStoragePeriod()/86400)).arg(QString::number(rsGxsForums->getDefaultSyncPeriod()/86400));
return hlp_str ;
}