From 814c5d16198e2178d958db64510b597d934fc26b Mon Sep 17 00:00:00 2001 From: chrisparker126 Date: Thu, 7 Apr 2011 22:09:16 +0000 Subject: [PATCH] auto download option: ability to enable and disable channels auto dl added added gui update to channel feed msg download not enabled yet cache opt: added more enable cache opt #defines to disable cache opt code git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4132 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rschannels.h | 26 +++- libretroshare/src/services/p3channels.cc | 140 +++++++++++++++++++--- libretroshare/src/services/p3channels.h | 13 +- libretroshare/src/services/p3distrib.cc | 9 +- libretroshare/src/services/p3distrib.h | 2 +- 5 files changed, 162 insertions(+), 28 deletions(-) diff --git a/libretroshare/src/retroshare/rschannels.h b/libretroshare/src/retroshare/rschannels.h index 8156ebaa9..8c98283cc 100644 --- a/libretroshare/src/retroshare/rschannels.h +++ b/libretroshare/src/retroshare/rschannels.h @@ -37,6 +37,8 @@ #define CHANNEL_MSG_STATUS_MASK 0x000f #define CHANNEL_MSG_STATUS_READ 0x0001 #define CHANNEL_MSG_STATUS_UNREAD_BY_USER 0x0002 +#define CHANNEL_MSG_STATUS_DOWLOADED 0x0004 + //! Stores information for a give channel id /*! @@ -45,13 +47,15 @@ class ChannelInfo { public: - ChannelInfo() : pngChanImage(NULL), pngImageLen(0) {} + ChannelInfo() : autoDownload(false), pngChanImage(NULL), pngImageLen(0) + {} std::string channelId; std::wstring channelName; std::wstring channelDesc; uint32_t channelFlags; uint32_t pop; /// popularity + bool autoDownload; unsigned char* pngChanImage; uint32_t pngImageLen; @@ -205,8 +209,9 @@ virtual bool ChannelMessageSend(ChannelMsgInfo &info) = 0; /*! * @param cId the channel id * @param subscribe set to true if you want to subscribe and to false to unsubscribe + * @param set true to allow autodownload of new content and false otherwise, ignored when second param is false */ -virtual bool channelSubscribe(std::string cId, bool subscribe) = 0; +virtual bool channelSubscribe(std::string cId, bool subscribe, bool autoDl) = 0; /*! * This hashes a file which is not already shared by client or his peers, @@ -252,11 +257,20 @@ virtual bool channelEditInfo(std::string chId, ChannelInfo &ci) = 0; virtual void getPubKeysAvailableGrpIds(std::list& chanIds) = 0; /*! - * - * - * + * set the channel so that it does not auto download any more + * @param chId the channel id to set for + * @param set to true to enable auto dl and false to disable */ -//virtual void setPrivateChannelDir(const std::string&) = 0; +virtual bool channelSetAutoDl(const std::string& chId, bool autoDl) = 0; + + +/*! + * get what autoDl is set to for the given channel id + * @param chId id of channel to get autoDl status for + * @param autoDl + * @return false if channel cannot be found + */ +virtual bool channelGetAutoDl(const std::string& chId, bool& autoDl) = 0; }; diff --git a/libretroshare/src/services/p3channels.cc b/libretroshare/src/services/p3channels.cc index e886563e0..40f94105c 100644 --- a/libretroshare/src/services/p3channels.cc +++ b/libretroshare/src/services/p3channels.cc @@ -541,20 +541,84 @@ bool p3Channels::locked_checkDistribMsg(RsDistribMsg *msg) -bool p3Channels::channelSubscribe(std::string cId, bool subscribe) +bool p3Channels::channelSubscribe(std::string cId, bool subscribe, bool autoDl) { #ifdef CHANNEL_DEBUG std::cerr << "p3Channels::channelSubscribe() " << cId << std::endl; #endif + { + RsStackMutex stack(distribMtx); + + if(subscribe) + mChannelStatus[cId] |= autoDl ? + (RS_CHAN_STATUS_AUTO_DL & RS_CHAN_STATUS_MASK) : ~RS_CHAN_STATUS_MASK; + } + bool ok = subscribeToGroup(cId, subscribe); - if(ok) - mChannelStatus[cId] = RS_CHAN_STATUS_AUTO_DL; + // if subscribing set channel status bit field on whether + // or not to auto download + { + RsStackMutex stack(distribMtx); + + if(!ok || !subscribe){ + mChannelStatus.erase(cId); + removeChannelReadStatusEntry(cId); + } + else{ + addChannelReadStatusEntry(cId); + } + + IndicateConfigChanged(); + } return ok; } +void p3Channels::addChannelReadStatusEntry(const std::string& cId) +{ + std::list::iterator lit = mReadStatus.begin(); + RsChannelReadStatus* rds = NULL; + + // check to ensure an entry does not exist + for(; lit != mReadStatus.end(); lit++){ + + if((*lit)->channelId == cId) + { + break; + } + } + + if(lit == mReadStatus.end()){ + rds = new RsChannelReadStatus(); + rds->channelId = cId; + mReadStatus.push_back(rds); + saveList.push_back(rds); + } + + return; +} + +//TODO: delete unsubscribed channels from entry +void p3Channels::removeChannelReadStatusEntry(const std::string& cId) +{ + std::list::iterator lit = mReadStatus.begin(); + statMap::iterator mit; + // check to ensure an entry does not exist + for(; lit != mReadStatus.end(); lit++){ + + if((*lit)->channelId == cId) + { + if((mit = (*lit)->msgReadStatus.find(cId)) != + (*lit)->msgReadStatus.end()){ + (*lit)->msgReadStatus.erase(mit); + break; + } + } + } + +} bool p3Channels::channelShareKeys(std::string chId, std::list& peers){ #ifdef CHANNEL_DEBUG @@ -601,17 +665,37 @@ void p3Channels::getPubKeysAvailableGrpIds(std::list& grpIds) } -void p3Channels::channelSetAutoDl(const std::string& chId, bool autoDl) +bool p3Channels::channelSetAutoDl(const std::string& chId, bool autoDl) { RsStackMutex stack(distribMtx); - if(autoDl) - mChannelStatus[chId] |= RS_CHAN_STATUS_AUTO_DL; - else - mChannelStatus[chId] = ~RS_CHAN_STATUS_AUTO_DL; + statMap::iterator it = mChannelStatus.find(chId); + bool changed = false; - return; + if(it != mChannelStatus.end()){ + + if(autoDl) + it->second |= RS_CHAN_STATUS_AUTO_DL; + else + it->second &= ~(RS_CHAN_STATUS_AUTO_DL & RS_CHAN_STATUS_MASK); + + changed = true; + } + else + { +#ifdef CHANNEL_DEBUG + std::cerr << "p3Channels::channelSetAutoDl(): " << "Channel does not exist" + << std::endl; +#endif + return false; + } + + // save configuration + if(changed) + IndicateConfigChanged(); + + return true; } @@ -623,7 +707,7 @@ bool p3Channels::channelGetAutoDl(const std::string& chId, bool& autoDl) if(it != mChannelStatus.end()) { - autoDl = mChannelStatus[chId] & RS_CHAN_STATUS_AUTO_DL; + autoDl = it->second & RS_CHAN_STATUS_AUTO_DL; return true; } @@ -766,9 +850,12 @@ bool p3Channels::locked_eventDuplicateMsg(GroupInfo *grp, RsDistribMsg *msg, std localpath, flags, srcIds); } + if(cit != mMsgReadStatus.end()){ - mit1->second |= (CHANNEL_MSG_STATUS_MASK & - CHANNEL_MSG_STATUS_DOWLOADED); + if(mit1 != cit->second.end()) + mit1->second |= (CHANNEL_MSG_STATUS_MASK & + CHANNEL_MSG_STATUS_DOWLOADED); + } return true; } @@ -890,7 +977,9 @@ bool p3Channels::childLoadList(std::list& configSaves) { std::cerr << "p3Channels::childLoadList(): Configs items loaded were incorrect!" << std::endl; - return false; + + if(*it != NULL) + delete *it; } } @@ -908,7 +997,8 @@ void p3Channels::processChanReadStatus(RsChannelReadStatus* drs) if(sit != drs->msgReadStatus.end()){ mChannelStatus[chId] = sit->second; - drs->msgReadStatus.erase(sit); + mChanReadStatus.insert(std::make_pair + (chId, drs)); } // first pull out the channel id status @@ -920,8 +1010,30 @@ void p3Channels::processChanReadStatus(RsChannelReadStatus* drs) } + std::list p3Channels::childSaveList() { + + std::list::iterator lit = mReadStatus.begin(); + statMap::iterator sit, mit; + + // update or add current channel id status + for(; lit != mReadStatus.end(); lit++) + { + if((sit = mChannelStatus.find((*lit)->channelId)) != mChannelStatus.end()) + { + mit = (*lit)->msgReadStatus.find((*lit)->channelId); + if(mit != (*lit)->msgReadStatus.end()) + { + mit->second = sit->second; + } + else + { + (*lit)->msgReadStatus[(*lit)->channelId] = sit->second; + } + } + } + return saveList; } diff --git a/libretroshare/src/services/p3channels.h b/libretroshare/src/services/p3channels.h index dcbd7528e..7b130ef14 100644 --- a/libretroshare/src/services/p3channels.h +++ b/libretroshare/src/services/p3channels.h @@ -33,7 +33,8 @@ #include "serialiser/rstlvtypes.h" #include "serialiser/rschannelitems.h" -#define RS_CHAN_STATUS_AUTO_DL 0x0004 +#define RS_CHAN_STATUS_MASK 0x000f +#define RS_CHAN_STATUS_AUTO_DL 0x0002 typedef std::map statMap; typedef std::map chanStatMap; @@ -75,15 +76,14 @@ virtual bool setMessageStatus(const std::string& cId, const std::string& mId, co virtual bool getMessageStatus(const std::string& cId, const std::string& mId, uint32_t& status); virtual bool getMessageCount(const std::string cId, unsigned int &newCount, unsigned int &unreadCount); - -virtual bool channelSubscribe(std::string cId, bool subscribe); +virtual bool channelSubscribe(std::string cId, bool subscribe, bool autoDl); virtual bool channelExtraFileHash(std::string path, std::string chId, FileInfo& fInfo); virtual bool channelExtraFileRemove(std::string hash, std::string chId); virtual bool channelRestoreKeys(std::string chId); virtual bool channelShareKeys(std::string chId, std::list& peers); virtual bool channelEditInfo(std::string chId, ChannelInfo &ci); virtual void getPubKeysAvailableGrpIds(std::list& grpIds); -virtual void channelSetAutoDl(const std::string& chId, bool autoDl); +virtual bool channelSetAutoDl(const std::string& chId, bool autoDl); virtual bool channelGetAutoDl(const std::string& chId, bool& autoDl); /***************************************************************************************/ @@ -112,12 +112,15 @@ virtual std::list childSaveList(); private: void processChanReadStatus(RsChannelReadStatus* drs); - +void addChannelReadStatusEntry(const std::string& cId); +void removeChannelReadStatusEntry(const std::string& cId); RsFiles *mRsFiles; std::string mChannelsDir; std::list saveList; std::list mReadStatus; + std::map mChanReadStatus; + chanStatMap mMsgReadStatus; statMap mChannelStatus; }; diff --git a/libretroshare/src/services/p3distrib.cc b/libretroshare/src/services/p3distrib.cc index 82aeac397..a5a110047 100644 --- a/libretroshare/src/services/p3distrib.cc +++ b/libretroshare/src/services/p3distrib.cc @@ -61,7 +61,7 @@ //#define DISTRIB_DEBUG 1 //#define DISTRIB_THREAD_DEBUG 1 //#define DISTRIB_DUMMYMSG_DEBUG 1 -//#define DISTRIB_HISTORY_DEBUG + RSA *extractPublicKey(RsTlvSecurityKey &key); RSA *extractPrivateKey(RsTlvSecurityKey &key); @@ -209,11 +209,13 @@ int p3GroupDistrib::tick() #endif } +#ifdef ENABLE_CACHE_OPT if(updateCacheDoc){ std::cerr << "count: " << mCount << std::endl; updateCacheDocument(); } +#endif return 0; } @@ -1068,6 +1070,7 @@ void p3GroupDistrib::loadFileMsgs(const std::string &filename, uint16_t cacheSub time_t now = time(NULL); bool cache = false; +#ifdef ENABLE_CACHE_OPT // if cache id exists in cache table exit { RsStackMutex stack(distribMtx); @@ -1080,6 +1083,7 @@ void p3GroupDistrib::loadFileMsgs(const std::string &filename, uint16_t cacheSub cache = true; } } +#endif // link grp to cache id (only one cache id, so doesn't matter if one grp comes out twice // with same cache id) @@ -2617,8 +2621,9 @@ bool p3GroupDistrib::saveList(bool &cleanup, std::list& saveData) delete childSer; // now save hostory doc - +#ifdef ENABLE_CACHE_OPT locked_saveHistoryCacheFile(); +#endif return true; } diff --git a/libretroshare/src/services/p3distrib.h b/libretroshare/src/services/p3distrib.h index a23fbc39b..67f91ef1a 100644 --- a/libretroshare/src/services/p3distrib.h +++ b/libretroshare/src/services/p3distrib.h @@ -508,7 +508,7 @@ class p3GroupDistrib: public CacheSource, public CacheStore, public p3Config, pu std::string publishMsg(RsDistribMsg *msg, bool personalSign); /*! - * + * note: call back to locked_eventDuplicateMSg is made on execution * @param grpId id of group to subscribe to * @param subscribe true to subscribe and vice versa * @return