added channels file clean up warning

added channels private key notification, and new private channel key behaviour (must subscribe to accept a private key)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3756 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2010-11-07 00:02:51 +00:00
parent 0f05f8d85e
commit 885d71370c
10 changed files with 696 additions and 517 deletions

View File

@ -42,7 +42,7 @@ const uint8_t RS_PKT_SUBTYPE_DISTRIB_CONFIG_DATA = 0x04;
/**************************************************************************/
/*!
* This should be derived from to store RsDistrib child objects
* This should be subclassed by p3distrib subclass's to store their data
* save data
*/
class RsDistribChildConfig: public RsItem

View File

@ -65,7 +65,6 @@ RsChannels *rsChannels = NULL;
/* remember 2^16 = 64K max units in store period.
* PUBPERIOD * 2^16 = max STORE PERIOD */
#define CHANNEL_STOREPERIOD (30*24*3600) /* 30 * 24 * 3600 - secs in a 30 day month */
#define TEST_CHANNEL_STOREPERIOD (24*3600) /* one day */
#define CHANNEL_PUBPERIOD 600 /* 10 minutes ... (max = 455 days) */
#define MAX_AUTO_DL 1E9 /* auto download of attachment limit; 1 GIG */
@ -603,6 +602,14 @@ bool p3Channels::channelEditInfo(std::string chId, ChannelInfo& info){
}
void p3Channels::getPubKeysAvailableGrpIds(std::list<std::string>& grpIds)
{
getGrpListPubKeyAvailable(grpIds);
return;
}
/***************************************************************************************/
/****************** Event Feedback (Overloaded form p3distrib) *************************/
/***************************************************************************************/
@ -795,7 +802,41 @@ void p3Channels::locked_notifyGroupChanged(GroupInfo &grp, uint32_t flags)
return p3GroupDistrib::locked_notifyGroupChanged(grp, flags);
}
void p3Channels::cleanUpOldFiles(){
bool p3Channels::getCleanUpList(std::map<std::string, uint32_t>& warnings,const std::string& chId,uint32_t limit)
{
time_t now = time(NULL);
uint32_t timeLeft = 0;
bool first = true;
std::list<ChannelMsgSummary> msgList;
std::list<ChannelMsgSummary>::iterator msg_it;
ChannelMsgInfo chMsgInfo;
if(!getChannelMsgList(chId, msgList))
return false;
for(msg_it = msgList.begin(); msg_it != msgList.end(); msg_it++){
if(!getChannelMessage(chId, msg_it->msgId, chMsgInfo))
continue;
// if msg not close to warning limit leave it alone
if( chMsgInfo.ts > (now - CHANNEL_STOREPERIOD + limit))
continue;
timeLeft = CHANNEL_STOREPERIOD - (now - chMsgInfo.ts);
warnings.insert(std::pair<std::string, uint32_t>(msg_it->msgId, timeLeft));
}
}
void p3Channels::cleanUpOldFiles()
{
time_t now = time(NULL);
std::list<ChannelInfo> chList;

View File

@ -78,6 +78,8 @@ virtual bool channelExtraFileRemove(std::string hash, std::string chId);
virtual bool channelRestoreKeys(std::string chId);
virtual bool channelShareKeys(std::string chId, std::list<std::string>& peers);
virtual bool channelEditInfo(std::string chId, ChannelInfo &ci);
virtual void getPubKeysAvailableGrpIds(std::list<std::string>& grpIds);
virtual bool getCleanUpList(std::map<std::string, uint32_t>& warnings,const std::string& chId, uint32_t limit);
/***************************************************************************************/
/****************** Event Feedback (Overloaded form p3distrib) *************************/
/***************************************************************************************/

View File

@ -1230,6 +1230,9 @@ bool p3GroupDistrib::subscribeToGroup(std::string grpId, bool subscribe)
{
git->second.flags |= RS_DISTRIB_SUBSCRIBED;
if(attemptPublishKeysRecvd(git->second))
git->second.flags |= RS_DISTRIB_PUBLISH;
locked_notifyGroupChanged(git->second, GRP_SUBSCRIBED);
mGroupsRepublish = true;
@ -1268,6 +1271,24 @@ bool p3GroupDistrib::subscribeToGroup(std::string grpId, bool subscribe)
return true;
}
bool p3GroupDistrib::attemptPublishKeysRecvd(GroupInfo& info)
{
std::map<std::string, RsDistribGrpKey*>::iterator mit;
mit = mRecvdPubKeys.find(info.grpId);
if(mit == mRecvdPubKeys.end())
return false;
if(locked_updateGroupPublishKey(info, mit->second))
mRecvdPubKeys.erase(mit);
else
return false;
return true;
}
/************************************* p3Config *************************************/
RsSerialiser *p3GroupDistrib::setupSerialiser()
@ -2083,30 +2104,39 @@ void p3GroupDistrib::locked_receivePubKeys(){
void p3GroupDistrib::locked_loadRecvdPubKeys(){
std::map<std::string, RsDistribGrpKey* >::iterator mit;
std::list<std::string>::iterator lit;
GroupInfo *gi;
std::list<std::string> toDelete;
bool cont = false;
#ifdef DISTRIB_DEBUG
std::cerr << "p3GroupDistrib::locked_loadRecvdPubKeys() " << std::endl;
#endif
bool ok = false;
// load received keys
// look for keys to add to private publish key received notify list
for(mit = mRecvdPubKeys.begin(); mit != mRecvdPubKeys.end(); mit++ ){
gi = locked_getGroupInfo(mit->second->grpId);
if(gi != NULL){
/* ensure grpId not added already */
for(lit=mPubKeyAvailableGrpId.begin(); lit != mPubKeyAvailableGrpId.end(); lit++){
if(locked_updateGroupPublishKey(*gi, mit->second)){
toDelete.push_back(mit->first);
ok |= true;
if(mit->second->grpId == *lit){
cont = true;
break;
}
}
else
std::cerr << "p3GroupDistrib::locked_loadRecvdPubKeys(): Failed to load" << std::endl;
if(cont)
{
cont = false;
continue;
}
mPubKeyAvailableGrpId.push_back(mit->second->grpId);
locked_notifyGroupChanged(*gi, GRP_UPDATE);
}else{
@ -2116,17 +2146,7 @@ void p3GroupDistrib::locked_loadRecvdPubKeys(){
}
mLastRecvdKeyTime = time(NULL);
if(ok)
IndicateConfigChanged();
std::list<std::string >::iterator lit;
// delete keys that have been loaded to groups
for(lit = toDelete.begin(); lit != toDelete.end(); lit++)
mRecvdPubKeys.erase(*lit);
mLastRecvdKeyTime = time(NULL);
return;
}
@ -3146,6 +3166,13 @@ RsDistribMsg *p3GroupDistrib::unpackDistribSignedMsg(RsDistribSignedMsg *newMsg)
return distribMsg;
}
void p3GroupDistrib::getGrpListPubKeyAvailable(std::list<std::string>& grpList)
{
RsStackMutex stack(distribMtx);
grpList = mPubKeyAvailableGrpId;
return;
}
bool p3GroupDistrib::locked_checkDistribMsg(
GroupInfo &gi, RsDistribMsg *msg)

View File

@ -277,6 +277,12 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
bool backUpKeys(const std::list<RsDistribGrpKey* > &keysToBackUp, std::string grpId);
void locked_sharePubKey();
/*!
* Attempt to load public key from recvd list if it exists for grpId
* @param grpId the id for the group for which private publish key is wanted
*/
bool attemptPublishKeysRecvd(GroupInfo& info);
protected:
/* load cache msgs */
@ -341,6 +347,7 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
bool subscribeToGroup(std::string grpId, bool subscribe);
/***************************************************************************************/
/***************************************************************************************/
@ -377,6 +384,11 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
GroupInfo *locked_getGroupInfo(std::string grpId);
RsDistribMsg *locked_getGroupMsg(std::string grpId, std::string msgId);
/*!
* for retrieving the grpList for which public keys are available
*/
void getGrpListPubKeyAvailable(std::list<std::string>& grpList);
/* Filter Messages */
/***************************************************************************************/
@ -497,9 +509,9 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
*/
virtual void locked_receivePubKeys();
/**
* This loads received pub keys
*
/*!
* utility function to check whether grps exist
* for private publish keys received
*/
virtual void locked_loadRecvdPubKeys();
@ -510,7 +522,7 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
*/
virtual bool locked_editGroup(std::string grpId, GroupInfo& gi);
/**
/*!
* Encrypts data using envelope encryption (taken from open ssl's evp_sealinit )
* only full publish key holders can encrypt data for given group
*@param out
@ -671,6 +683,7 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
std::map<std::string, RsDistribGrpKey* > mRecvdPubKeys; /// full publishing keys received from users
std::map<std::string, std::list<std::string> > mPendingPubKeyRecipients; /// peers to receive publics key for a given grp
std::list<std::string> mPubKeyAvailableGrpId; // groups id for which public keys are available
time_t mLastKeyPublishTime, mLastRecvdKeyTime;
};

View File

@ -26,6 +26,8 @@
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include "ChannelFeed.h"
@ -56,6 +58,8 @@
#define COMBO_TITLE_INDEX 0
#define COMBO_DESC_INDEX 1
#define WARNING_LIMIT 3600*24*2
/****
* #define CHAN_DEBUG
***/
@ -181,7 +185,7 @@ void ChannelFeed::channelListCustomPopupMenu( QPoint point )
contextMnu.addAction( shareKeyAct );
contextMnu.addAction( channeldetailsAct );
}
else if (ci.channelFlags & RS_DISTRIB_PUBLISH) {
else if ((ci.channelFlags & RS_DISTRIB_PUBLISH) && (ci.channelFlags & RS_DISTRIB_SUBSCRIBED)) {
contextMnu.addAction( postchannelAct );
contextMnu.addSeparator();
contextMnu.addAction( channeldetailsAct );
@ -350,10 +354,9 @@ void ChannelFeed::updateChannelList()
/* sort it into Publish (Own), Subscribed, Popular and Other */
uint32_t flags = it->channelFlags;
if ((flags & (RS_DISTRIB_ADMIN | RS_DISTRIB_PUBLISH)) && (flags & RS_DISTRIB_SUBSCRIBED)
) {
if ((flags & RS_DISTRIB_ADMIN) && (flags & RS_DISTRIB_PUBLISH) && (flags & RS_DISTRIB_SUBSCRIBED)) {
adminList.push_back(*it);
} else if (flags & RS_DISTRIB_SUBSCRIBED) {
} else if ((flags & RS_DISTRIB_SUBSCRIBED) || ((flags & RS_DISTRIB_SUBSCRIBED) && (flags &RS_DISTRIB_PUBLISH)) ) {
subList.push_back(*it);
} else {
/* rate the others by popularity */
@ -394,6 +397,11 @@ void ChannelFeed::updateChannelList()
fillChannelList(POPULAR, popList);
fillChannelList(OTHER, otherList);
// place notices for channel with private keys available
highlightPrivateKeys(SUBSCRIBED);
highlightPrivateKeys(POPULAR);
highlightPrivateKeys(OTHER);
updateMessageSummaryList("");
}
@ -428,8 +436,44 @@ void ChannelFeed::filterChannelList(std::list<ChannelInfo> &ci){
}
void ChannelFeed::fillChannelList(int channelItem, std::list<ChannelInfo> &channelInfos)
{
void ChannelFeed::highlightPrivateKeys(int group){
QStandardItem *groupItem = model->item(group);
QStandardItem *item = NULL;
std::list<std::string> keysAvailable;
std::list<std::string>::iterator it;
int rowCount = 0;
QBrush brush;
brush.setColor(Qt::blue);
if((groupItem == NULL) || (rsChannels == NULL))
return;
rowCount = groupItem->rowCount();
rsChannels->getPubKeysAvailableGrpIds(keysAvailable);
for(it= keysAvailable.begin(); it != keysAvailable.end(); it++)
for (int row = 0; row < rowCount; row++) {
if (groupItem->child(row, COLUMN_DATA)->data(ROLE_ID).toString() == QString::fromStdString(*it)) {
/* found channel */
item = groupItem->child(row, COLUMN_NAME);
/* set title text to bold and colored blue */
QFont chanFont = item->font();
chanFont.setBold(true);
item->setFont(chanFont);
item->setForeground(brush);
item->setToolTip(item->toolTip() + QString("\nPrivate Key Available"));
}
}
}
void ChannelFeed::fillChannelList(int channelItem, std::list<ChannelInfo> &channelInfos){
std::list<ChannelInfo>::iterator iit;
/* remove rows with groups before adding new ones */
@ -485,7 +529,7 @@ void ChannelFeed::fillChannelList(int channelItem, std::list<ChannelInfo> &chann
groupItem->child(chNameItem->index().row(), COLUMN_DATA)->setData(QDateTime::fromTime_t(ci.lastPost), ROLE_CHANNEL_TS);
chNameItem->setToolTip(tr("Popularity: %1\nFetches: %2\nAvailable: %3").arg(QString::number(ci.pop)).arg(9999).arg(9999));
chNameItem->setToolTip(tr("Popularity: %1").arg(QString::number(ci.pop)));
QPixmap chanImage;
if (ci.pngImageLen != 0) {
@ -545,6 +589,8 @@ void ChannelFeed::updateMessageSummaryList(const std::string &channelId)
{
int channelItems[2] = { OWN, SUBSCRIBED };
for (int channelItem = 0; channelItem < 2; channelItem++) {
QStandardItem *groupItem = model->item(channelItems[channelItem]);
if (groupItem == NULL) {
@ -658,14 +704,23 @@ void ChannelFeed::updateChannelMsgs()
std::list<ChannelMsgSummary> msgs;
std::list<ChannelMsgSummary>::iterator it;
rsChannels->getChannelMsgList(mChannelId, msgs);
msgs.sort(sortChannelMsgSummary);
/* set get warning list for channel */
std::map<std::string, uint32_t> warningList;
std::map<std::string, uint32_t>::iterator msgId_it;
rsChannels->getCleanUpList(warningList, mChannelId, WARNING_LIMIT);
for(it = msgs.begin(); it != msgs.end(); it++) {
ChanMsgItem *cmi = new ChanMsgItem(this, 0, mChannelId, it->msgId, true);
msgId_it = warningList.find(it->msgId);
if(msgId_it != warningList.end())
cmi->setFileCleanUpWarning(msgId_it->second);
mChanMsgItems.push_back(cmi);
verticalLayout_2->addWidget(cmi);
}

View File

@ -86,7 +86,7 @@ private slots:
void finishSearching();
private:
void highlightPrivateKeys(int group);
void updateChannelList();
void fillChannelList(int channelItem, std::list<ChannelInfo> &channelInfos);
void filterChannelList(std::list<ChannelInfo>&);

View File

@ -64,10 +64,13 @@ ChanMsgItem::ChanMsgItem(FeedHolder *parent, uint32_t feedId, std::string chanId
downloadButton->hide();
playButton->hide();
warn_image_label->hide();
warning_label->hide();
titleLabel->setMinimumWidth(100);
subjectLabel->setMinimumWidth(100);
small();
updateItemStatic();
updateItem();
@ -90,6 +93,8 @@ void ChanMsgItem::updateItemStatic()
if (!rsChannels->getChannelMessage(mChanId, mMsgId, cmi))
return;
m_inUpdateItemStatic = true;
QString title;
@ -201,6 +206,25 @@ void ChanMsgItem::updateItemStatic()
}
void ChanMsgItem::setFileCleanUpWarning(uint32_t time_left)
{
int hours = (int)time_left/3600;
int minutes = (time_left - hours*3600)%60;
warning_label->setText(tr("Warning! You have less than %1 hours and %2 minute before this file is delted Consider saving it.").arg(
QString::number(hours)).arg(QString::number(minutes)));
QFont warnFont = warning_label->font();
warnFont.setBold(true);
warning_label->setFont(warnFont);
warn_image_label->setVisible(true);
warning_label->setVisible(true);
return;
}
void ChanMsgItem::updateItem()
{
/* fill in */

View File

@ -40,6 +40,7 @@ public:
void updateItemStatic();
void small();
void setFileCleanUpWarning(uint32_t time_left);
private slots:
/* default stuff */

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>518</width>
<width>528</width>
<height>208</height>
</rect>
</property>
@ -211,7 +211,7 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QPushButton" name="readButton">
<property name="maximumSize">
<size>
@ -241,7 +241,7 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QLabel" name="newLabel">
<property name="maximumSize">
<size>
@ -265,7 +265,7 @@ border-radius: 3px}</string>
</property>
</widget>
</item>
<item row="3" column="2">
<item row="4" column="2">
<widget class="QPushButton" name="downloadButton">
<property name="font">
<font>
@ -281,7 +281,7 @@ border-radius: 3px}</string>
</property>
</widget>
</item>
<item row="3" column="3">
<item row="4" column="3">
<widget class="QPushButton" name="playButton">
<property name="font">
<font>
@ -297,7 +297,7 @@ border-radius: 3px}</string>
</property>
</widget>
</item>
<item row="3" column="4">
<item row="4" column="4">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -313,7 +313,7 @@ border-radius: 3px}</string>
</property>
</spacer>
</item>
<item row="3" column="5" colspan="2">
<item row="4" column="5" colspan="2">
<widget class="QPushButton" name="unsubscribeButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -339,7 +339,7 @@ border-radius: 3px}</string>
</property>
</widget>
</item>
<item row="3" column="7">
<item row="4" column="7">
<widget class="QPushButton" name="clearButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -365,7 +365,7 @@ border-radius: 3px}</string>
</property>
</widget>
</item>
<item row="3" column="8">
<item row="4" column="8">
<widget class="QPushButton" name="expandButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -394,6 +394,23 @@ border-radius: 3px}</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="warn_image_label">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../images.qrc">:/images/status_unknown.png</pixmap>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="warning_label">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@ -432,8 +449,7 @@ border-radius: 10px;}</string>
border-radius: 10px;}</string>
</property>
<property name="text">
<string notr="true">Long
message here</string>
<string notr="true"/>
</property>
<property name="wordWrap">
<bool>true</bool>