removed channel delete feature

added optimisation suggestion with load/savelist

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3920 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2010-12-18 19:35:07 +00:00
parent d3a6f7316c
commit 2f559dae96
37 changed files with 133 additions and 388 deletions

View file

@ -474,10 +474,9 @@ bool p3Channels::channelExtraFileHash(std::string path, std::string chId, FileIn
fname.append(fnameBuff.rbegin(), fnameBuff.rend());
uint32_t flags = RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_EXTRA;
uint32_t flags = RS_FILE_HINTS_NETWORK_WIDE;
// then hash file, but hash file at original location if its too large
// and get file info too
// then hash file and get file info too
if(!mRsFiles->ExtraFileHash(path, CHANNEL_STOREPERIOD, flags))
return false;
@ -540,19 +539,6 @@ bool p3Channels::locked_checkDistribMsg(RsDistribMsg *msg)
}
RsDistribGrp *p3Channels::locked_createPublicDistribGrp(GroupInfo &info)
{
RsDistribGrp *grp = NULL; //new RsChannelGrp();
return grp;
}
RsDistribGrp *p3Channels::locked_createPrivateDistribGrp(GroupInfo &info)
{
RsDistribGrp *grp = NULL; //new RsChannelGrp();
return grp;
}
bool p3Channels::channelSubscribe(std::string cId, bool subscribe)
@ -630,12 +616,6 @@ bool p3Channels::locked_eventDuplicateMsg(GroupInfo *grp, RsDistribMsg *msg, std
std::string nullId;
// std::cerr << "p3Channels::locked_eventDuplicateMsg() ";
// std::cerr << " grpId: " << grpId << " msgId: " << msgId;
// std::cerr << " peerId: " << id;
// std::cerr << std::endl;
RsChannelMsg *chanMsg = dynamic_cast<RsChannelMsg *>(msg);
if (!chanMsg)
{
@ -652,10 +632,10 @@ bool p3Channels::locked_eventDuplicateMsg(GroupInfo *grp, RsDistribMsg *msg, std
if (id == mOwnId)
{
download = false;
//#ifdef CHANNEL_DEBUG
#ifdef CHANNEL_DEBUG
std::cerr << "p3Channels::locked_eventDuplicateMsg() msg from self - not downloading";
std::cerr << std::endl;
//#endif
#endif
}
/* check subscribed */
@ -672,6 +652,18 @@ bool p3Channels::locked_eventDuplicateMsg(GroupInfo *grp, RsDistribMsg *msg, std
return true;
}
// get channel info to determine if channel is private or not
ChannelInfo cInfo;
bool chanPrivate = false;
// tho if empty don't bother
if(!chanMsg->attachment.items.empty()){
getChannelInfo(grpId, cInfo);
if(cInfo.channelFlags & RS_DISTRIB_PRIVATE)
chanPrivate = true;
}
/* Iterate through files */
std::list<RsTlvFileItem>::iterator fit;
for(fit = chanMsg->attachment.items.begin();
@ -681,11 +673,22 @@ bool p3Channels::locked_eventDuplicateMsg(GroupInfo *grp, RsDistribMsg *msg, std
std::string hash = fit->hash;
uint64_t size = fit->filesize;
std::string channelname = grpId;
std::string localpath = mChannelsDir + "/" + channelname;
uint32_t flags = RS_FILE_HINTS_EXTRA |
RS_FILE_HINTS_BACKGROUND |
RS_FILE_HINTS_NETWORK_WIDE;
std::string localpath;
uint32_t flags;
// send to download directory if file is private
if(chanPrivate){
localpath = mChannelsDir + "/" + channelname;
flags = RS_FILE_HINTS_BACKGROUND | RS_FILE_HINTS_EXTRA;
}else{
localpath = ""; // forces dl to default directory
flags = RS_FILE_HINTS_BACKGROUND |
RS_FILE_HINTS_NETWORK_WIDE;
}
std::list<std::string> srcIds;
srcIds.push_back(id);
@ -695,12 +698,10 @@ bool p3Channels::locked_eventDuplicateMsg(GroupInfo *grp, RsDistribMsg *msg, std
* FileRequest will ignore request if file is already indexed.
*/
//#ifdef CHANNEL_DEBUG
#ifdef CHANNEL_DEBUG
std::cerr << "p3Channels::locked_eventDuplicateMsg() " << " Downloading: " << fname;
std::cerr << " to: " << localpath << " from: " << id << std::endl;
//#endif
#endif
if(size < MAX_AUTO_DL)
mRsFiles->FileRequest(fname, hash, size,
@ -719,12 +720,6 @@ bool p3Channels::locked_eventNewMsg(GroupInfo *grp, RsDistribMsg *msg, std::stri
std::string msgId = msg->msgId;
std::string nullId;
// std::cerr << "p3Channels::locked_eventNewMsg() ";
// std::cerr << " grpId: " << grpId;
// std::cerr << " msgId: " << msgId;
// std::cerr << " peerId: " << id;
// std::cerr << std::endl;
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_CHAN_MSG, grpId, msgId, nullId);
/* request the files
@ -742,10 +737,6 @@ void p3Channels::locked_notifyGroupChanged(GroupInfo &grp, uint32_t flags)
std::string msgId;
std::string nullId;
// std::cerr << "p3Channels::locked_notifyGroupChanged() ";
// std::cerr << grpId;
// std::cerr << " flags:" << flags;
// std::cerr << std::endl;
switch(flags)
{
@ -812,112 +803,6 @@ void p3Channels::locked_notifyGroupChanged(GroupInfo &grp, uint32_t flags)
return p3GroupDistrib::locked_notifyGroupChanged(grp, flags);
}
bool p3Channels::getCleanUpList(std::map<std::string, uint32_t>& warnings,const std::string& chId,uint32_t limit)
{
ChannelInfo chInfo;
getChannelInfo(chId, chInfo);
if(chInfo.channelFlags & RS_DISTRIB_ADMIN)
return false;
time_t now = time(NULL);
uint32_t timeLeft = 0;
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 + CHANNEL_STOREPERIOD > (time_t)now + (time_t)limit) || (chMsgInfo.count < 1))
continue;
timeLeft = CHANNEL_STOREPERIOD - (now - chMsgInfo.ts);
warnings.insert(std::pair<std::string, uint32_t>(msg_it->msgId, timeLeft));
}
return true ;
}
void p3Channels::cleanUpOldFiles()
{
time_t now = time(NULL);
std::list<ChannelInfo> chList;
std::list<ChannelInfo>::iterator ch_it;
// first get channel list
if(!getChannelList(chList))
return;
std::list<ChannelMsgSummary> msgList;
std::list<ChannelMsgSummary>::iterator msg_it;
// then msg for each channel
for(ch_it = chList.begin(); ch_it != chList.end(); ch_it++){
// don't deal with files owned by client (they are not extra files anyways so slightly redundant)
if(!getChannelMsgList(ch_it->channelId, msgList) || (ch_it->channelFlags & RS_DISTRIB_ADMIN))
continue;
std::string channelname = ch_it->channelId;
std::string localpath = mChannelsDir + "/" + channelname;
for(msg_it = msgList.begin(); msg_it != msgList.end(); msg_it++){
ChannelMsgInfo chMsgInfo;
if(!getChannelMessage(ch_it->channelId, msg_it->msgId, chMsgInfo))
continue;
// if msg not old, leave it alone
if( chMsgInfo.ts > (now - CHANNEL_STOREPERIOD))
continue;
std::list<FileInfo>::iterator file_it;
// get the files
for(file_it = chMsgInfo.files.begin(); file_it != chMsgInfo.files.end(); file_it++){
std::string msgFile = localpath + "/" + file_it->fname;
if(mRsFiles){
if(mRsFiles->ExtraFileRemove(file_it->hash, ~(RS_FILE_HINTS_DOWNLOAD | RS_FILE_HINTS_UPLOAD)))
std::cerr << "p3Channels::clearOldFIles() failed to remove files from extras" << std::endl;
if(remove(msgFile.c_str()) == 0){
std::cerr << "p3Channels::clearOldFiles() file removed: "
<< msgFile << std::endl;
}else{
std::cerr << "p3Channels::clearOldFiles() failed to remove file: "
<< msgFile << std::endl;
}
}else{
std::cerr << "p3Channels::cleanUpOldFiles() : Pointer passed to (this) Invalid" << std::endl;
}
}
}
}
// clean up local caches
//. clear_local_caches(now); //how about remote caches, remember its hardwired
return;
}
//TODO: if you want to config saving and loading for channel distrib service implement this method further
bool p3Channels::childLoadList(std::list<RsItem* >& configSaves)
@ -949,114 +834,3 @@ std::list<RsItem *> p3Channels::childSaveList()
}
/****************************************/
#if 0
void p3Channels::loadDummyData()
{
ChannelInfo fi;
std::string channelId;
std::string msgId;
time_t now = time(NULL);
fi.channelId = "FID1234";
fi.channelName = L"Channel 1";
fi.channelDesc = L"Channel 1";
fi.channelFlags = RS_DISTRIB_ADMIN;
fi.pop = 2;
fi.lastPost = now - 123;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID2345";
fi.channelName = L"Channel 2";
fi.channelDesc = L"Channel 2";
fi.channelFlags = RS_DISTRIB_SUBSCRIBED;
fi.pop = 3;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
msgId = createChannelMsg(channelId, "", L"WELCOME TO Channel1", L"Hello!");
msgId = createChannelMsg(channelId, msgId, L"Love this channel", L"Hello2!");
return;
/* ignore this */
fi.channelId = "FID3456";
fi.channelName = L"Channel 3";
fi.channelDesc = L"Channel 3";
fi.channelFlags = 0;
fi.pop = 3;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID4567";
fi.channelName = L"Channel 4";
fi.channelDesc = L"Channel 4";
fi.channelFlags = 0;
fi.pop = 5;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID5678";
fi.channelName = L"Channel 5";
fi.channelDesc = L"Channel 5";
fi.channelFlags = 0;
fi.pop = 1;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID6789";
fi.channelName = L"Channel 6";
fi.channelDesc = L"Channel 6";
fi.channelFlags = 0;
fi.pop = 2;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID7890";
fi.channelName = L"Channel 7";
fi.channelDesc = L"Channel 7";
fi.channelFlags = 0;
fi.pop = 4;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID8901";
fi.channelName = L"Channel 8";
fi.channelDesc = L"Channel 8";
fi.channelFlags = 0;
fi.pop = 3;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID9012";
fi.channelName = L"Channel 9";
fi.channelDesc = L"Channel 9";
fi.channelFlags = 0;
fi.pop = 2;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
fi.channelId = "FID9123";
fi.channelName = L"Channel 10";
fi.channelDesc = L"Channel 10";
fi.channelFlags = 0;
fi.pop = 1;
fi.lastPost = now - 1234;
channelId = createChannel(fi.channelName, fi.channelDesc, fi.channelFlags);
mChannelsChanged = true;
}
#endif

View file

@ -79,7 +79,8 @@ 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) *************************/
/***************************************************************************************/
@ -96,8 +97,7 @@ virtual bool locked_eventDuplicateMsg(GroupInfo *, RsDistribMsg *, std::string);
virtual RsSerialType *createSerialiser();
virtual bool locked_checkDistribMsg(RsDistribMsg *msg);
virtual RsDistribGrp *locked_createPublicDistribGrp(GroupInfo &info);
virtual RsDistribGrp *locked_createPrivateDistribGrp(GroupInfo &info);
virtual bool childLoadList(std::list<RsItem* >& configSaves);
virtual std::list<RsItem *> childSaveList();

View file

@ -893,7 +893,7 @@ std::cerr << "p3chatservice: sending requested status string for peer " << peer_
sendItem(cs);
}
bool p3ChatService::loadList(std::list<RsItem*> load)
bool p3ChatService::loadList(std::list<RsItem*>& load)
{
for(std::list<RsItem*>::const_iterator it(load.begin());it!=load.end();++it)
{
@ -954,14 +954,12 @@ bool p3ChatService::loadList(std::list<RsItem*> load)
return true;
}
std::list<RsItem*> p3ChatService::saveList(bool& cleanup)
bool p3ChatService::saveList(bool& cleanup, std::list<RsItem*>& list)
{
cleanup = true;
/* now we create a pqistore, and stream all the msgs into it */
std::list<RsItem*> list ;
if(_own_avatar != NULL)
{
RsChatAvatarItem *ci = makeOwnAvatarItem() ;
@ -999,7 +997,7 @@ std::list<RsItem*> p3ChatService::saveList(bool& cleanup)
list.push_back(ci);
}
return list;
return true;
}
void p3ChatService::saveDone()

View file

@ -157,9 +157,9 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor
/*!
* chat msg items and custom status are saved
*/
virtual std::list<RsItem*> saveList(bool& cleanup) ;
virtual bool saveList(bool& cleanup, std::list<RsItem*>&) ;
virtual void saveDone();
virtual bool loadList(std::list<RsItem*> load) ;
virtual bool loadList(std::list<RsItem*>& load) ;
private:
RsMutex mChatMtx;

View file

@ -1120,13 +1120,13 @@ RsSerialiser *p3disc::setupSerialiser()
return rss ;
}
std::list<RsItem*> p3disc::saveList(bool& cleanup)
bool p3disc::saveList(bool& cleanup, std::list<RsItem*>& lst)
{
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::saveList() called" << std::endl;
#endif
cleanup = true ;
std::list<RsItem*> lst ;
// Now save config for network digging strategies
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
@ -1144,10 +1144,10 @@ std::list<RsItem*> p3disc::saveList(bool& cleanup)
}
lst.push_back(vitem);
return lst ;
return true ;
}
bool p3disc::loadList(std::list<RsItem*> load)
bool p3disc::loadList(std::list<RsItem*>& load)
{
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::loadList() Item Count: " << load.size() << std::endl;

View file

@ -102,8 +102,8 @@ virtual void setGPGOperation(AuthGPGOperation *operation);
/*********************** p3config ******************************/
/* Key Functions to be overloaded for Full Configuration */
virtual RsSerialiser *setupSerialiser();
virtual std::list<RsItem *> saveList(bool &cleanup);
virtual bool loadList(std::list<RsItem *> load);
virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
virtual bool loadList(std::list<RsItem *>& load);
/*****************************************************************/
private:

View file

@ -1299,9 +1299,8 @@ RsSerialiser *p3GroupDistrib::setupSerialiser()
return rss;
}
std::list<RsItem *> p3GroupDistrib::saveList(bool &cleanup)
bool p3GroupDistrib::saveList(bool &cleanup, std::list<RsItem *>& saveData)
{
std::list<RsItem *> saveData;
#ifdef DISTRIB_DEBUG
std::cerr << "p3GroupDistrib::saveList()";
@ -1471,7 +1470,7 @@ std::list<RsItem *> p3GroupDistrib::saveList(bool &cleanup)
delete childSer;
return saveData;
return true;
}
void p3GroupDistrib::saveDone()
@ -1489,7 +1488,7 @@ void p3GroupDistrib::saveDone()
distribMtx.unlock(); /****** MUTEX UNLOCKED *******/
}
bool p3GroupDistrib::loadList(std::list<RsItem *> load)
bool p3GroupDistrib::loadList(std::list<RsItem *>& load)
{
std::list<RsItem *>::iterator lit;

View file

@ -428,9 +428,9 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu
protected:
virtual RsSerialiser *setupSerialiser();
virtual std::list<RsItem *> saveList(bool &cleanup);
virtual bool saveList(bool &cleanup, std::list<RsItem *>& saveList);
virtual void saveDone();
virtual bool loadList(std::list<RsItem *> load);
virtual bool loadList(std::list<RsItem *>& load);
/*!
* called by top class, child can use to save configs

View file

@ -282,12 +282,9 @@ int p3MsgService::checkOutgoingMessages()
std::list<RsItem*> p3MsgService::saveList(bool& cleanup)
bool p3MsgService::saveList(bool& cleanup, std::list<RsItem*>& itemList)
{
std::list<RsItem*> itemList;
std::map<uint32_t, RsMsgItem *>::iterator mit;
std::map<uint32_t, RsMsgTagType* >::iterator mit2;
std::map<uint32_t, RsMsgTags* >::iterator mit3;
@ -319,7 +316,7 @@ std::list<RsItem*> p3MsgService::saveList(bool& cleanup)
for(mit4 = mParentId.begin(); mit4 != mParentId.end(); mit4++)
itemList.push_back(mit4->second);
return itemList;
return true;
}
void p3MsgService::saveDone()
@ -376,7 +373,7 @@ void p3MsgService::initStandardTagTypes()
}
}
bool p3MsgService::loadList(std::list<RsItem*> load)
bool p3MsgService::loadList(std::list<RsItem*>& load)
{
RsMsgItem *mitem;
RsMsgTagType* mtt;

View file

@ -90,8 +90,8 @@ int status();
/*** Overloaded from p3Config ****/
virtual RsSerialiser *setupSerialiser();
virtual std::list<RsItem*> saveList(bool& cleanup);
virtual bool loadList(std::list<RsItem*> load);
virtual bool saveList(bool& cleanup, std::list<RsItem*>&);
virtual bool loadList(std::list<RsItem*>& load);
virtual void saveDone();
/*** Overloaded from p3Config ****/

View file

@ -1260,9 +1260,8 @@ bool p3Ranking::addAnonToList(RsRankLinkMsg *msg)
return true;
}
std::list<RsItem *> p3Ranking::saveList(bool &cleanup)
bool p3Ranking::saveList(bool &cleanup, std::list<RsItem *> & saveData)
{
std::list<RsItem *> saveData;
mRankMtx.lock(); /*********************** LOCK *******/
@ -1275,7 +1274,7 @@ std::list<RsItem *> p3Ranking::saveList(bool &cleanup)
}
/* list completed! */
return saveData;
return true;
}
void p3Ranking::saveDone()
@ -1284,7 +1283,7 @@ void p3Ranking::saveDone()
return;
}
bool p3Ranking::loadList(std::list<RsItem *> load)
bool p3Ranking::loadList(std::list<RsItem *>& load)
{
std::list<RsItem *>::iterator it;
RsRankLinkMsg *msg;

View file

@ -124,8 +124,8 @@ pqistore *createStore(std::string file, std::string src, bool reading);
bool addAnonToList(RsRankLinkMsg *msg);
virtual RsSerialiser *setupSerialiser();
virtual std::list<RsItem *> saveList(bool &cleanup);
virtual bool loadList(std::list<RsItem *> load);
virtual bool saveList(bool &cleanup, std::list<RsItem *>&);
virtual bool loadList(std::list<RsItem *>& load);
virtual void saveDone();
private:

View file

@ -246,13 +246,13 @@ RsSerialiser* p3StatusService::setupSerialiser(){
return rss;
}
std::list<RsItem*> p3StatusService::saveList(bool& cleanup){
bool p3StatusService::saveList(bool& cleanup, std::list<RsItem*>& ilist){
// save your status before quiting
cleanup = true;
RsStatusItem* own_status = new RsStatusItem;
StatusInfo own_info;
std::list<RsItem*> ilist;
std::map<std::string, StatusInfo>::iterator it;
{
@ -263,7 +263,7 @@ std::list<RsItem*> p3StatusService::saveList(bool& cleanup){
std::cerr << "p3StatusService::saveList() :" << "Did not find your status"
<< mConnMgr->getOwnId() << std::endl;
delete own_status;
return ilist;
return false;
}
own_info = it->second;
@ -275,10 +275,10 @@ std::list<RsItem*> p3StatusService::saveList(bool& cleanup){
ilist.push_back(own_status);
return ilist;
return true;
}
bool p3StatusService::loadList(std::list<RsItem*> load){
bool p3StatusService::loadList(std::list<RsItem*>& load){
// load your status from last rs session
StatusInfo own_info;

View file

@ -79,12 +79,12 @@ virtual RsSerialiser *setupSerialiser();
/*!
* This stores information on what your status was before you exited rs
*/
virtual std::list<RsItem*> saveList(bool& cleanup);
virtual bool saveList(bool& cleanup, std::list<RsItem*>&);
/*!
* @param load Should contain a single item which is clients status from last rs session
*/
virtual bool loadList(std::list<RsItem*> load);
virtual bool loadList(std::list<RsItem*>& load);
private: