mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
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:
parent
0f05f8d85e
commit
885d71370c
10 changed files with 696 additions and 517 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) *************************/
|
||||
/***************************************************************************************/
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue