mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-25 06:40:58 -04:00
fixed id auto-cleaning
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8134 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
b0b986efff
commit
68d25b324a
2 changed files with 44 additions and 19 deletions
|
@ -56,7 +56,7 @@
|
||||||
#define ID_REQUEST_OPINION 0x0004
|
#define ID_REQUEST_OPINION 0x0004
|
||||||
|
|
||||||
static const uint32_t MAX_KEEP_UNUSED_KEYS = 30*86400 ; // remove unused keys after 30 days
|
static const uint32_t MAX_KEEP_UNUSED_KEYS = 30*86400 ; // remove unused keys after 30 days
|
||||||
static const uint32_t MAX_DELAY_BEFORE_CLEANING = 3601 ; // clean old keys every hour
|
static const uint32_t MAX_DELAY_BEFORE_CLEANING = 601 ; // clean old keys every 10 mins
|
||||||
|
|
||||||
RsIdentity *rsIdentity = NULL;
|
RsIdentity *rsIdentity = NULL;
|
||||||
|
|
||||||
|
@ -152,6 +152,7 @@ p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *ne
|
||||||
mBgSchedule_Active = false;
|
mBgSchedule_Active = false;
|
||||||
mLastKeyCleaningTime = 0 ;
|
mLastKeyCleaningTime = 0 ;
|
||||||
mLastConfigUpdate = 0 ;
|
mLastConfigUpdate = 0 ;
|
||||||
|
mOwnIdsLoaded = false ;
|
||||||
|
|
||||||
// Kick off Cache Testing, + Others.
|
// Kick off Cache Testing, + Others.
|
||||||
RsTickEvent::schedule_in(GXSID_EVENT_PGPHASH, PGPHASH_PERIOD);
|
RsTickEvent::schedule_in(GXSID_EVENT_PGPHASH, PGPHASH_PERIOD);
|
||||||
|
@ -265,27 +266,43 @@ bool p3IdService::saveList(bool& cleanup,std::list<RsItem*>& items)
|
||||||
}
|
}
|
||||||
void p3IdService::cleanUnusedKeys()
|
void p3IdService::cleanUnusedKeys()
|
||||||
{
|
{
|
||||||
|
std::list<RsGxsId> ids_to_delete ;
|
||||||
|
|
||||||
|
// we need to stash all ids to delete into an off-mutex structure since deleteIdentity() will trigger the lock
|
||||||
|
{
|
||||||
RS_STACK_MUTEX(mIdMtx) ;
|
RS_STACK_MUTEX(mIdMtx) ;
|
||||||
|
|
||||||
time_t now = time(NULL) ;
|
if(!mOwnIdsLoaded)
|
||||||
|
|
||||||
for(std::map<RsGxsId,time_t>::iterator it(mKeysTS.begin());it!=mKeysTS.end();)
|
|
||||||
if(it->second + MAX_KEEP_UNUSED_KEYS < now
|
|
||||||
&& std::find(mOwnIds.begin(),mOwnIds.end(),it->first) == mOwnIds.end())
|
|
||||||
{
|
{
|
||||||
std::cerr << "Deleting identity " << it->first << " which is too old." << std::endl;
|
std::cerr << "(EE) Own ids not loaded. Cannot clean unused keys." << std::endl;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// grab at most 10 identities to delete. No need to send too many requests to the token queue at once.
|
||||||
|
time_t now = time(NULL) ;
|
||||||
|
int n=0 ;
|
||||||
|
|
||||||
|
for(std::map<RsGxsId,time_t>::iterator it(mKeysTS.begin());it!=mKeysTS.end() && n < 10;++it)
|
||||||
|
if(it->second + MAX_KEEP_UNUSED_KEYS < now && std::find(mOwnIds.begin(),mOwnIds.end(),it->first) == mOwnIds.end())
|
||||||
|
ids_to_delete.push_back(it->first),++n ;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(std::list<RsGxsId>::const_iterator it(ids_to_delete.begin());it!=ids_to_delete.end();++it)
|
||||||
|
{
|
||||||
|
std::cerr << "Deleting identity " << *it << " which is too old." << std::endl;
|
||||||
uint32_t token ;
|
uint32_t token ;
|
||||||
RsGxsIdGroup group;
|
RsGxsIdGroup group;
|
||||||
group.mMeta.mGroupId=RsGxsGroupId(it->first);
|
group.mMeta.mGroupId=RsGxsGroupId(*it);
|
||||||
//rsIdentity->deleteIdentity(token, group);
|
rsIdentity->deleteIdentity(token, group);
|
||||||
|
|
||||||
std::map<RsGxsId,time_t>::iterator tmp = it ;
|
{
|
||||||
++tmp ;
|
RS_STACK_MUTEX(mIdMtx) ;
|
||||||
//mKeysTS.erase(it) ;
|
std::map<RsGxsId,time_t>::iterator tmp = mKeysTS.find(*it) ;
|
||||||
it = tmp ;
|
|
||||||
|
if(mKeysTS.end() != tmp)
|
||||||
|
mKeysTS.erase(tmp) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
++it ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void p3IdService::service_tick()
|
void p3IdService::service_tick()
|
||||||
|
@ -2157,9 +2174,14 @@ bool p3IdService::cache_load_ownids(uint32_t token)
|
||||||
if (item->meta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN)
|
if (item->meta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN)
|
||||||
{
|
{
|
||||||
mOwnIds.push_back(RsGxsId(item->meta.mGroupId));
|
mOwnIds.push_back(RsGxsId(item->meta.mGroupId));
|
||||||
|
|
||||||
|
// This prevents automatic deletion to get rid of them.
|
||||||
|
// In other words, own ids are always used.
|
||||||
|
mKeysTS[RsGxsId(item->meta.mGroupId)] = time(NULL) ;
|
||||||
}
|
}
|
||||||
delete item ;
|
delete item ;
|
||||||
}
|
}
|
||||||
|
mOwnIdsLoaded = true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// No need to cache these items...
|
// No need to cache these items...
|
||||||
|
@ -2603,6 +2625,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
|
||||||
if (std::find(mOwnIds.begin(), mOwnIds.end(), gxsId) == mOwnIds.end())
|
if (std::find(mOwnIds.begin(), mOwnIds.end(), gxsId) == mOwnIds.end())
|
||||||
{
|
{
|
||||||
mOwnIds.push_back(gxsId);
|
mOwnIds.push_back(gxsId);
|
||||||
|
mKeysTS[gxsId] = time(NULL) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -512,6 +512,8 @@ std::string genRandomId(int len = 20);
|
||||||
|
|
||||||
time_t mLastKeyCleaningTime ;
|
time_t mLastKeyCleaningTime ;
|
||||||
time_t mLastConfigUpdate ;
|
time_t mLastConfigUpdate ;
|
||||||
|
|
||||||
|
bool mOwnIdsLoaded ;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // P3_IDENTITY_SERVICE_HEADER
|
#endif // P3_IDENTITY_SERVICE_HEADER
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue