Added #defines to disable much debugging statements.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6157 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2013-02-27 21:16:03 +00:00
parent 5b4739352e
commit 65e3f02bb0
6 changed files with 280 additions and 8 deletions

View File

@ -30,7 +30,9 @@
#include "rsgxsnetservice.h"
#include "rsgxsflags.h"
#define NXS_NET_DEBUG
/**
* #define NXS_NET_DEBUG 1
**/
#define SYNC_PERIOD 12 // in microseconds every 10 seconds (1 second for testing)
#define TRANSAC_TIMEOUT 5 // 5 seconds

View File

@ -1,7 +1,10 @@
#include "rsnxsitems.h"
#include "rsbaseserial.h"
#define RSSERIAL_DEBUG
/***
* #define RSSERIAL_DEBUG 1
***/
const uint8_t RsNxsSyncGrpItem::FLAG_REQUEST = 0x001;
const uint8_t RsNxsSyncGrpItem::FLAG_RESPONSE = 0x002;
@ -110,7 +113,7 @@ RsItem* RsNxsSerialiser::deserialise(void *data, uint32_t *size) {
return deserialNxsExtended(data, size);
default:
{
#ifdef NXS_DEBUG
#ifdef RSSERIAL_DEBUG
std::cerr << "RsNxsSerialiser::deserialise() : data has no type"
<< std::endl;
#endif

View File

@ -37,7 +37,7 @@
#include <stdio.h>
/****
* #define ID_DEBUG 1
* #define DEBUG_CIRCLES 1
****/
RsGxsCircles *rsGxsCircles = NULL;
@ -226,8 +226,11 @@ bool p3GxsCircles:: getNickname(const RsGxsId &id, std::string &nickname)
bool p3GxsCircles:: getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails &details)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::getCircleDetails(" << id << ")";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
{
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
@ -253,8 +256,10 @@ bool p3GxsCircles:: getCircleDetails(const RsGxsCircleId &id, RsGxsCircleDetails
bool p3GxsCircles:: getCircleIdList(std::list<RsGxsCircleId> &circleIds)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::getCircleIdList()";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
circleIds = mCircleIdList;
@ -339,8 +344,10 @@ bool p3GxsCircles::getGroupData(const uint32_t &token, std::vector<RsGxsCircleGr
bool p3GxsCircles::createGroup(uint32_t& token, RsGxsCircleGroup &group)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::createGroup()";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
RsGxsCircleGroupItem* item = new RsGxsCircleGroupItem();
item->convertFrom(group);
@ -350,8 +357,10 @@ bool p3GxsCircles::createGroup(uint32_t& token, RsGxsCircleGroup &group)
void p3GxsCircles::service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& /*keySet*/)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::service_CreateGroup()";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
RsGxsCircleGroupItem *item = dynamic_cast<RsGxsCircleGroupItem *>(grpItem);
if (!item)
@ -401,8 +410,10 @@ bool RsGxsCircleCache::loadBaseCircle(const RsGxsCircleGroup &circle)
mUpdateTime = time(NULL);
mProcessedCircles.insert(mCircleId);
#ifdef DEBUG_CIRCLES
std::cerr << "RsGxsCircleCache::loadBaseCircle(" << mCircleId << ")";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
return true;
}
@ -412,8 +423,10 @@ bool RsGxsCircleCache::loadSubCircle(const RsGxsCircleCache &subcircle)
/* copy across all the lists */
/* should not be any unprocessed circles or peers */
#ifdef DEBUG_CIRCLES
std::cerr << "RsGxsCircleCache::loadSubCircle(" << subcircle.mCircleId << ") TODO";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
return true;
}
@ -455,8 +468,10 @@ bool p3GxsCircles::request_CircleIdList()
{
/* trigger request to load missing ids into cache */
std::list<RsGxsGroupId> groupIds;
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::request_CircleIdList()";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
uint32_t ansType = RS_TOKREQ_ANSTYPE_LIST;
RsTokReqOptions opts;
@ -472,8 +487,10 @@ bool p3GxsCircles::request_CircleIdList()
bool p3GxsCircles::load_CircleIdList(uint32_t token)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::load_CircleIdList() : " << token;
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
std::list<RsGxsGroupId> groupIds;
bool ok = RsGenExchange::getGroupList(token, groupIds);
@ -628,8 +645,10 @@ bool p3GxsCircles::cachetest_handlerequest(uint32_t token)
bool p3GxsCircles::cache_request_load(const RsGxsCircleId &id)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::cache_request_load(" << id << ")";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
{
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
@ -675,8 +694,10 @@ bool p3GxsCircles::cache_request_load(const RsGxsCircleId &id)
bool p3GxsCircles::cache_start_load()
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::cache_start_load()";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
/* trigger request to load missing ids into cache */
std::list<RsGxsGroupId> groupIds;
@ -687,8 +708,11 @@ bool p3GxsCircles::cache_start_load()
std::list<RsGxsId>::iterator it;
for(it = mCacheLoad_ToCache.begin(); it != mCacheLoad_ToCache.end(); it++)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::cache_start_load() GroupId: " << *it;
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
groupIds.push_back(*it); // might need conversion?
}
@ -697,8 +721,10 @@ bool p3GxsCircles::cache_start_load()
if (groupIds.size() > 0)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::cache_start_load() #Groups: " << groupIds.size();
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
uint32_t ansType = RS_TOKREQ_ANSTYPE_DATA;
RsTokReqOptions opts;
@ -714,8 +740,10 @@ bool p3GxsCircles::cache_start_load()
bool p3GxsCircles::cache_load_for_token(uint32_t token)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::cache_load_for_token() : " << token;
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
std::vector<RsGxsGrpItem*> grpData;
bool ok = RsGenExchange::getGroupData(token, grpData);
@ -730,9 +758,11 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token)
RsGxsCircleGroup group;
item->convertTo(group);
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::cache_load_for_token() Loaded Id with Meta: ";
std::cerr << item->meta;
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
@ -868,8 +898,10 @@ bool p3GxsCircles::cache_load_for_token(uint32_t token)
bool p3GxsCircles::cache_reloadids(const std::string &circleId)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::cache_reloadids()";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
RsStackMutex stack(mCircleMtx); /********** STACK LOCKED MTX ******/
@ -904,17 +936,21 @@ bool p3GxsCircles::cache_reloadids(const std::string &circleId)
{
cache.addAllowedPeer(details.mPgpId, *pit);
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::cache_reloadids() AllowedPeer: ";
std::cerr << *pit;
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
}
else
{
cache.mUnknownPeers.insert(*pit);
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::cache_reloadids() UnknownPeer: ";
std::cerr << *pit;
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
}
}
else
@ -940,9 +976,11 @@ bool p3GxsCircles::cache_reloadids(const std::string &circleId)
// If sub-circles are complete too.
if (cache.mUnprocessedCircles.empty())
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::cache_reloadids() Adding to cache Id: ";
std::cerr << circleId;
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
// Push to Cache.
mCircleCache.store(circleId, cache);
@ -1156,8 +1194,10 @@ std::string p3GxsCircles::genRandomId()
void p3GxsCircles::generateDummyData()
{
// request Id Data...
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::generateDummyData() getting Id List";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
uint32_t ansType = RS_TOKREQ_ANSTYPE_DATA;
RsTokReqOptions opts;
@ -1177,8 +1217,11 @@ void p3GxsCircles::generateDummyData()
void p3GxsCircles::checkDummyIdData()
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::checkDummyIdData()";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
// check the token.
uint32_t status = rsIdentity->getTokenService()->requestStatus(mDummyIdToken);
if ( (RsTokenService::GXS_REQUEST_V2_STATUS_FAILED == status) ||
@ -1198,21 +1241,27 @@ void p3GxsCircles::checkDummyIdData()
{
if (it->mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::checkDummyIdData() PgpLinkedId: " << it->mMeta.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
mDummyPgpLinkedIds.push_back(it->mMeta.mGroupId);
if (it->mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::checkDummyIdData() OwnId: " << it->mMeta.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
mDummyOwnIds.push_back(it->mMeta.mGroupId);
}
}
else
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::checkDummyIdData() Other Id: " << it->mMeta.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
}
}
@ -1233,8 +1282,10 @@ void p3GxsCircles::checkDummyIdData()
void p3GxsCircles::generateDummyCircle()
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::generateDummyCircle()";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
int npgps = mDummyPgpLinkedIds.size();
RsGxsCircleGroup group;
@ -1270,15 +1321,19 @@ void p3GxsCircles::generateDummyCircle()
}
group.mMeta.mGroupName = genRandomId();
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::generateDummyCircle() Name: " << group.mMeta.mGroupName;
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
std::set<RsGxsId>::iterator it;
for(it = idset.begin(); it != idset.end(); it++)
{
group.mInvitedMembers.push_back(*it);
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::generateDummyCircle() Adding: " << *it;
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
}
uint32_t dummyToken;
@ -1329,8 +1384,10 @@ std::ostream &operator<<(std::ostream &out, const RsGxsCircleMsg &msg)
// Overloaded from GxsTokenQueue for Request callbacks.
void p3GxsCircles::handleResponse(uint32_t token, uint32_t req_type)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::handleResponse(" << token << "," << req_type << ")";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
// stuff.
switch(req_type)
@ -1361,8 +1418,10 @@ void p3GxsCircles::handleResponse(uint32_t token, uint32_t req_type)
// Overloaded from RsTickEvent for Event callbacks.
void p3GxsCircles::handle_event(uint32_t event_type, const std::string &elabel)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::handle_event(" << event_type << ")";
std::cerr << std::endl;
#endif // DEBUG_CIRCLES
// stuff.
switch(event_type)

View File

@ -37,7 +37,7 @@
#include <stdio.h>
/****
* #define ID_DEBUG 1
* #define DEBUG_IDS 1
* #define GXSID_GEN_DUMMY_DATA 1
****/
@ -328,13 +328,14 @@ bool p3IdService::getGroupData(const uint32_t &token, std::vector<RsGxsIdGroup>
{
group.mPgpKnown = ssdata.pgp.idKnown;
group.mPgpId = ssdata.pgp.pgpId;
#ifdef DEBUG_IDS
std::cerr << "p3IdService::getGroupData() Success decoding ServiceString";
std::cerr << std::endl;
std::cerr << "\t mGpgKnown: " << group.mPgpKnown;
std::cerr << std::endl;
std::cerr << "\t mGpgId: " << group.mPgpId;
std::cerr << std::endl;
#endif // DEBUG_IDS
}
else
{
@ -495,65 +496,85 @@ bool SSGxsIdGroup::load(const std::string &input)
// split into two parts.
if (4 != sscanf(input.c_str(), "v1 {P:%[^}]} {Y:%[^}]} {O:%[^}]} {R:%[^}]}", pgpstr, scorestr, opinionstr, repstr))
{
#ifdef DEBUG_IDS
std::cerr << "SSGxsIdGroup::load() Failed to extract 4 Parts";
std::cerr << std::endl;
#endif // DEBUG_IDS
return false;
}
bool ok = true;
if (pgp.load(pgpstr))
{
#ifdef DEBUG_IDS
std::cerr << "SSGxsIdGroup::load() pgpstr: " << pgpstr;
std::cerr << std::endl;
#endif // DEBUG_IDS
}
else
{
#ifdef DEBUG_IDS
std::cerr << "SSGxsIdGroup::load() Invalid pgpstr: " << pgpstr;
std::cerr << std::endl;
#endif // DEBUG_IDS
ok = false;
}
if (score.load(scorestr))
{
#ifdef DEBUG_IDS
std::cerr << "SSGxsIdGroup::load() scorestr: " << scorestr;
std::cerr << std::endl;
#endif // DEBUG_IDS
}
else
{
#ifdef DEBUG_IDS
std::cerr << "SSGxsIdGroup::load() Invalid scorestr: " << scorestr;
std::cerr << std::endl;
#endif // DEBUG_IDS
ok = false;
}
if (opinion.load(opinionstr))
{
#ifdef DEBUG_IDS
std::cerr << "SSGxsIdGroup::load() opinionstr: " << opinionstr;
std::cerr << std::endl;
#endif // DEBUG_IDS
}
else
{
#ifdef DEBUG_IDS
std::cerr << "SSGxsIdGroup::load() Invalid opinionstr: " << opinionstr;
std::cerr << std::endl;
#endif // DEBUG_IDS
ok = false;
}
if (reputation.load(repstr))
{
#ifdef DEBUG_IDS
std::cerr << "SSGxsIdGroup::load() repstr: " << repstr;
std::cerr << std::endl;
#endif // DEBUG_IDS
}
else
{
#ifdef DEBUG_IDS
std::cerr << "SSGxsIdGroup::load() Invalid repstr: " << repstr;
std::cerr << std::endl;
#endif // DEBUG_IDS
ok = false;
}
#ifdef DEBUG_IDS
std::cerr << "SSGxsIdGroup::load() regurgitated: " << save();
std::cerr << std::endl;
std::cerr << "SSGxsIdGroup::load() isOkay?: " << ok;
std::cerr << std::endl;
#endif // DEBUG_IDS
return ok;
}
@ -617,8 +638,10 @@ RsGxsIdCache::RsGxsIdCache(const RsGxsIdGroupItem *item, const RsTlvSecurityKey
details.mNickname = item->meta.mGroupName;
details.mId = item->meta.mGroupId;
#ifdef DEBUG_IDS
std::cerr << "RsGxsIdCache::RsGxsIdCache() for: " << details.mId;
std::cerr << std::endl;
#endif // DEBUG_IDS
details.mIsOwnId = (item->meta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN);
@ -667,8 +690,10 @@ void RsGxsIdCache::updateServiceString(std::string serviceString)
bool p3IdService::cache_store(const RsGxsIdGroupItem *item)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_store() Item: " << item->meta.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_IDS
//item->print(std::cerr, 0); NEEDS CONST!!!! TODO
//std::cerr << std::endl;
@ -697,8 +722,10 @@ bool p3IdService::cache_store(const RsGxsIdGroupItem *item)
{
if (kit->second.keyFlags & RSTLV_KEY_DISTRIB_ADMIN)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_store() Found Admin Key";
std::cerr << std::endl;
#endif // DEBUG_IDS
/* save full key - if we have it */
if (kit->second.keyFlags & RSTLV_KEY_TYPE_FULL)
@ -749,8 +776,10 @@ bool p3IdService::cache_store(const RsGxsIdGroupItem *item)
bool p3IdService::cache_request_load(const RsGxsId &id)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_request_load(" << id << ")";
std::cerr << std::endl;
#endif // DEBUG_IDS
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
@ -789,8 +818,10 @@ bool p3IdService::cache_start_load()
std::list<RsGxsId>::iterator it;
for(it = mCacheLoad_ToCache.begin(); it != mCacheLoad_ToCache.end(); it++)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_start_load() GroupId: " << *it;
std::cerr << std::endl;
#endif // DEBUG_IDS
groupIds.push_back(*it); // might need conversion?
}
@ -799,8 +830,10 @@ bool p3IdService::cache_start_load()
if (groupIds.size() > 0)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_start_load() #Groups: " << groupIds.size();
std::cerr << std::endl;
#endif // DEBUG_IDS
uint32_t ansType = RS_TOKREQ_ANSTYPE_DATA;
RsTokReqOptions opts;
@ -816,8 +849,10 @@ bool p3IdService::cache_start_load()
bool p3IdService::cache_load_for_token(uint32_t token)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_load_for_token() : " << token;
std::cerr << std::endl;
#endif // DEBUG_IDS
std::vector<RsGxsGrpItem*> grpData;
bool ok = RsGenExchange::getGroupData(token, grpData);
@ -830,9 +865,11 @@ bool p3IdService::cache_load_for_token(uint32_t token)
{
RsGxsIdGroupItem* item = dynamic_cast<RsGxsIdGroupItem*>(*vit);
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_load_for_token() Loaded Id with Meta: ";
std::cerr << item->meta;
std::cerr << std::endl;
#endif // DEBUG_IDS
/* cache the data */
cache_store(item);
@ -854,8 +891,10 @@ bool p3IdService::cache_load_for_token(uint32_t token)
bool p3IdService::cache_update_if_cached(const RsGxsId &id, std::string serviceString)
{
/* if these entries are cached - update with new info */
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_update_if_cached(" << id << ")";
std::cerr << std::endl;
#endif // DEBUG_IDS
/* retrieve - update, save */
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
@ -863,8 +902,10 @@ bool p3IdService::cache_update_if_cached(const RsGxsId &id, std::string serviceS
RsGxsIdCache pub_data;
if (mPublicKeyCache.fetch(id, pub_data))
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_update_if_cached() Updating Public Cache";
std::cerr << std::endl;
#endif // DEBUG_IDS
pub_data.updateServiceString(serviceString);
mPublicKeyCache.store(id, pub_data);
@ -874,8 +915,10 @@ bool p3IdService::cache_update_if_cached(const RsGxsId &id, std::string serviceS
RsGxsIdCache priv_data;
if (mPrivateKeyCache.fetch(id, priv_data))
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_update_if_cached() Updating Private Cache";
std::cerr << std::endl;
#endif // DEBUG_IDS
priv_data.updateServiceString(serviceString);
mPrivateKeyCache.store(id, priv_data);
@ -891,8 +934,10 @@ bool p3IdService::cache_request_ownids()
{
/* trigger request to load missing ids into cache */
std::list<RsGxsGroupId> groupIds;
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_request_ownids()";
std::cerr << std::endl;
#endif // DEBUG_IDS
uint32_t ansType = RS_TOKREQ_ANSTYPE_DATA;
RsTokReqOptions opts;
@ -909,8 +954,10 @@ bool p3IdService::cache_request_ownids()
bool p3IdService::cache_load_ownids(uint32_t token)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_load_ownids() : " << token;
std::cerr << std::endl;
#endif // DEBUG_IDS
std::vector<RsGxsGrpItem*> grpData;
bool ok = RsGenExchange::getGroupData(token, grpData);
@ -974,8 +1021,10 @@ bool p3IdService::cache_load_ownids(uint32_t token)
bool p3IdService::cachetest_getlist()
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cachetest_getlist() making request";
std::cerr << std::endl;
#endif // DEBUG_IDS
uint32_t ansType = RS_TOKREQ_ANSTYPE_LIST;
RsTokReqOptions opts;
@ -992,11 +1041,13 @@ bool p3IdService::cachetest_getlist()
bool p3IdService::cachetest_handlerequest(uint32_t token)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cachetest_handlerequest() token: " << token;
std::cerr << std::endl;
#endif // DEBUG_IDS
std::list<RsGxsId> grpIds;
bool ok = RsGenExchange::getGroupList(token, grpIds);
std::list<RsGxsId> grpIds;
bool ok = RsGenExchange::getGroupList(token, grpIds);
if(ok)
{
@ -1006,8 +1057,10 @@ bool p3IdService::cachetest_handlerequest(uint32_t token)
/* 5% chance of checking it! */
if (RSRandom::random_f32() < 0.25)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cachetest_request() Testing Id: " << *vit;
std::cerr << std::endl;
#endif // DEBUG_IDS
/* try the cache! */
if (!haveKey(*vit))
@ -1015,16 +1068,20 @@ bool p3IdService::cachetest_handlerequest(uint32_t token)
std::list<PeerId> nullpeers;
requestKey(*vit, nullpeers);
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cachetest_request() Requested Key Id: " << *vit;
std::cerr << std::endl;
#endif // DEBUG_IDS
}
else
{
RsTlvSecurityKey seckey;
if (getKey(*vit, seckey))
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cachetest_request() Got Key OK Id: " << *vit;
std::cerr << std::endl;
#endif // DEBUG_IDS
// success!
seckey.print(std::cerr, 10);
@ -1043,8 +1100,10 @@ bool p3IdService::cachetest_handlerequest(uint32_t token)
if (!havePrivateKey(*vit))
{
requestPrivateKey(*vit);
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cachetest_request() Requested PrivateKey Id: " << *vit;
std::cerr << std::endl;
#endif // DEBUG_IDS
}
else
{
@ -1052,8 +1111,10 @@ bool p3IdService::cachetest_handlerequest(uint32_t token)
if (getPrivateKey(*vit, seckey))
{
// success!
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cachetest_request() Got PrivateKey OK Id: " << *vit;
std::cerr << std::endl;
#endif // DEBUG_IDS
}
else
{
@ -1096,16 +1157,20 @@ bool p3IdService::CacheArbitration(uint32_t mode)
if (!mBgSchedule_Active)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::CacheArbitration() Okay";
std::cerr << std::endl;
#endif // DEBUG_IDS
mBgSchedule_Active = true;
mBgSchedule_Mode = mode;
return true;
}
#ifdef DEBUG_IDS
std::cerr << "p3IdService::CacheArbitration() Is busy...";
std::cerr << std::endl;
#endif // DEBUG_IDS
return false;
}
@ -1122,8 +1187,10 @@ void p3IdService::CacheArbitrationDone(uint32_t mode)
return;
}
#ifdef DEBUG_IDS
std::cerr << "p3IdService::CacheArbitrationDone()";
std::cerr << std::endl;
#endif // DEBUG_IDS
mBgSchedule_Active = false;
}
@ -1161,8 +1228,10 @@ static void calcPGPHash(const RsGxsId &id, const PGPFingerprintType &pgp, GxsIdP
// Must Use meta.
void p3IdService::service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::service_CreateGroup()";
std::cerr << std::endl;
#endif // DEBUG_IDS
RsGxsIdGroupItem *item = dynamic_cast<RsGxsIdGroupItem *>(grpItem);
if (!item)
@ -1227,10 +1296,12 @@ void p3IdService::service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet
#ifdef DEBUG_IDS
std::cerr << "p3IdService::service_CreateGroup() for : " << item->group.mMeta.mGroupId;
std::cerr << std::endl;
std::cerr << "p3IdService::service_CreateGroup() Alt GroupId : " << item->meta.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_IDS
if (item->group.mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID)
{
@ -1258,8 +1329,10 @@ void p3IdService::service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet
calcPGPHash(item->group.mMeta.mGroupId, ownFinger, hash);
item->group.mPgpIdHash = hash.toStdString();
#ifdef DEBUG_IDS
std::cerr << "p3IdService::service_CreateGroup() Calculated PgpIdHash : " << item->group.mPgpIdHash;
std::cerr << std::endl;
#endif // DEBUG_IDS
/* do signature */
@ -1308,8 +1381,10 @@ bool p3IdService::pgphash_start()
{
if (!CacheArbitration(BG_PGPHASH))
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::pgphash_start() Other Events running... Rescheduling";
std::cerr << std::endl;
#endif // DEBUG_IDS
/* reschedule in a bit */
RsTickEvent::schedule_in(GXSID_EVENT_PGPHASH, PGPHASH_RETRY_PERIOD);
@ -1319,8 +1394,10 @@ bool p3IdService::pgphash_start()
// SCHEDULE NEXT ONE.
RsTickEvent::schedule_in(GXSID_EVENT_PGPHASH, PGPHASH_PERIOD);
#ifdef DEBUG_IDS
std::cerr << "p3IdService::pgphash_start() making request";
std::cerr << std::endl;
#endif // DEBUG_IDS
getPgpIdList();
@ -1343,8 +1420,10 @@ bool p3IdService::pgphash_start()
bool p3IdService::pgphash_handlerequest(uint32_t token)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::pgphash_handlerequest(" << token << ")";
std::cerr << std::endl;
#endif // DEBUG_IDS
// We need full data - for access to Hash & Signature.
// Perhaps we will change this to an initial pass through Meta,
@ -1362,20 +1441,26 @@ bool p3IdService::pgphash_handlerequest(uint32_t token)
if(ok)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::pgphash_request() Have " << groups.size() << " Groups";
std::cerr << std::endl;
#endif // DEBUG_IDS
std::vector<RsGxsIdGroup>::iterator vit;
for(vit = groups.begin(); vit != groups.end(); vit++)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::pgphash_request() Group Id: " << vit->mMeta.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_IDS
/* Filter based on IdType */
if (!(vit->mMeta.mGroupFlags & RSGXSID_GROUPFLAG_REALID))
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::pgphash_request() discarding AnonID";
std::cerr << std::endl;
#endif // DEBUG_IDS
continue;
}
@ -1385,8 +1470,10 @@ bool p3IdService::pgphash_handlerequest(uint32_t token)
{
if (ssdata.pgp.idKnown)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::pgphash_request() discarding Already Known";
std::cerr << std::endl;
#endif // DEBUG_IDS
continue;
}
@ -1406,15 +1493,19 @@ bool p3IdService::pgphash_handlerequest(uint32_t token)
if (age < wait_period)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::pgphash_request() discarding Recent Check";
std::cerr << std::endl;
#endif // DEBUG_IDS
continue;
}
}
/* if we get here -> then its to be processed */
#ifdef DEBUG_IDS
std::cerr << "p3IdService::pgphash_request() ToProcess Group: " << vit->mMeta.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_IDS
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
mGroupsToProcess.push_back(*vit);
@ -1443,8 +1534,10 @@ bool p3IdService::pgphash_process()
pg = mGroupsToProcess.front();
mGroupsToProcess.pop_front();
#ifdef DEBUG_IDS
std::cerr << "p3IdService::pgphash_process() Popped Group: " << pg.mMeta.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_IDS
}
else
{
@ -1454,8 +1547,10 @@ bool p3IdService::pgphash_process()
if (isDone)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::pgphash_process() List Empty... Done";
std::cerr << std::endl;
#endif // DEBUG_IDS
// FINISHED.
CacheArbitrationDone(BG_PGPHASH);
return true;
@ -1472,9 +1567,11 @@ bool p3IdService::pgphash_process()
/* found a match - update everything */
/* Consistency issues here - what if Reputation was recently updated? */
#ifdef DEBUG_IDS
std::cerr << "p3IdService::pgphash_process() CheckId Success for Group: " << pg.mMeta.mGroupId;
std::cerr << " PgpId: " << pgpId.toStdString();
std::cerr << std::endl;
#endif // DEBUG_IDS
/* update */
ssdata.pgp.idKnown = true;
@ -1506,8 +1603,10 @@ bool p3IdService::pgphash_process()
}
else
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::pgphash_process() No Match for Group: " << pg.mMeta.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_IDS
ssdata.pgp.lastCheckTs = time(NULL);
ssdata.pgp.checkAttempts++;
@ -1529,14 +1628,19 @@ bool p3IdService::pgphash_process()
bool p3IdService::checkId(const RsGxsIdGroup &grp, PGPIdType &pgpId)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::checkId() Starting Match Check for RsGxsId: ";
std::cerr << grp.mMeta.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_IDS
/* some sanity checking... make sure hash is the right size */
#ifdef DEBUG_IDS
std::cerr << "p3IdService::checkId() PgpIdHash is: " << grp.mPgpIdHash;
std::cerr << std::endl;
#endif // DEBUG_IDS
if (grp.mPgpIdHash.length() != SHA_DIGEST_LENGTH * 2)
{
@ -1547,8 +1651,10 @@ bool p3IdService::checkId(const RsGxsIdGroup &grp, PGPIdType &pgpId)
/* iterate through and check hash */
GxsIdPgpHash ans(grp.mPgpIdHash);
#ifdef DEBUG_IDS
std::cerr << "\tExpected Answer: " << ans.toStdString();
std::cerr << std::endl;
#endif // DEBUG_IDS
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
@ -1581,16 +1687,22 @@ bool p3IdService::checkId(const RsGxsIdGroup &grp, PGPIdType &pgpId)
std::cerr << std::endl;
#else
pgpId = mit->first;
#ifdef DEBUG_IDS
std::cerr << "p3IdService::checkId() Skipping Signature check for now... Hash Okay";
std::cerr << std::endl;
#endif // DEBUG_IDS
return true;
#endif
}
}
#ifdef DEBUG_IDS
std::cerr << "p3IdService::checkId() Checked " << mPgpFingerprintMap.size() << " Hashes without Match";
std::cerr << std::endl;
#endif // DEBUG_IDS
return false;
}
@ -1599,8 +1711,10 @@ bool p3IdService::checkId(const RsGxsIdGroup &grp, PGPIdType &pgpId)
/* worker functions */
void p3IdService::getPgpIdList()
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::getPgpIdList() Starting....";
std::cerr << std::endl;
#endif // DEBUG_IDS
std::list<std::string> list;
AuthGPG::getAuthGPG()->getGPGFilteredList(list);
@ -1616,14 +1730,18 @@ void p3IdService::getPgpIdList()
PGPFingerprintType fp;
AuthGPG::getAuthGPG()->getKeyFingerprint(pgpId, fp);
#ifdef DEBUG_IDS
std::cerr << "p3IdService::getPgpIdList() Id: " << pgpId.toStdString() << " => " << fp.toStdString();
std::cerr << std::endl;
#endif // DEBUG_IDS
mPgpFingerprintMap[pgpId] = fp;
}
#ifdef DEBUG_IDS
std::cerr << "p3IdService::getPgpIdList() Items: " << mPgpFingerprintMap.size();
std::cerr << std::endl;
#endif // DEBUG_IDS
}
@ -1639,6 +1757,7 @@ void calcPGPHash(const RsGxsId &id, const PGPFingerprintType &pgp, GxsIdPgpHash
SHA1_Final(signature, sha_ctx);
hash = GxsIdPgpHash(signature);
#ifdef DEBUG_IDS
std::cerr << "calcPGPHash():";
std::cerr << std::endl;
std::cerr << "\tRsGxsId: " << id;
@ -1647,6 +1766,7 @@ void calcPGPHash(const RsGxsId &id, const PGPFingerprintType &pgp, GxsIdPgpHash
std::cerr << std::endl;
std::cerr << "\tFinal Hash: " << hash.toStdString();
std::cerr << std::endl;
#endif // DEBUG_IDS
delete sha_ctx;
}
@ -1928,8 +2048,10 @@ bool p3IdService::reputation_start()
{
if (!CacheArbitration(BG_REPUTATION))
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::reputation_start() Other Events running... Rescheduling";
std::cerr << std::endl;
#endif // DEBUG_IDS
/* reschedule in a bit */
RsTickEvent::schedule_in(GXSID_EVENT_REPUTATION, REPUTATION_RETRY_PERIOD);
@ -1948,8 +2070,10 @@ bool p3IdService::reputation_start()
int p3IdService::background_tick()
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_tick()";
std::cerr << std::endl;
#endif // DEBUG_IDS
// Run Background Stuff.
background_checkTokenRequest();
@ -2041,8 +2165,10 @@ bool p3IdService::background_checkTokenRequest()
bool p3IdService::background_requestGroups()
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_requestGroups()";
std::cerr << std::endl;
#endif // DEBUG_IDS
// grab all the subscribed groups.
uint32_t token = 0;
@ -2085,8 +2211,10 @@ bool p3IdService::background_requestGroups()
bool p3IdService::background_requestNewMessages()
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_requestNewMessages()";
std::cerr << std::endl;
#endif // DEBUG_IDS
std::list<RsGroupMetaData> modGroupList;
std::list<RsGroupMetaData>::iterator it;
@ -2146,8 +2274,10 @@ bool p3IdService::background_requestNewMessages()
bool p3IdService::background_processNewMessages()
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages()";
std::cerr << std::endl;
#endif // DEBUG_IDS
GxsMsgMetaMap newMsgMap;
GxsMsgMetaMap::iterator it;
@ -2179,8 +2309,10 @@ bool p3IdService::background_processNewMessages()
std::vector<RsMsgMetaData>::iterator vit;
for(vit = it->second.begin(); vit != it->second.end(); vit++)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages() new MsgId: " << vit->mMsgId;
std::cerr << std::endl;
#endif // DEBUG_IDS
/* flag each new vote as processed */
/**
@ -2204,8 +2336,10 @@ bool p3IdService::background_processNewMessages()
if (mit->second.mGroupStatus & ID_LOCAL_STATUS_FULL_CALC_FLAG)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages() Group Already marked FULL_CALC";
std::cerr << std::endl;
#endif // DEBUG_IDS
/* already marked */
continue;
@ -2217,8 +2351,10 @@ bool p3IdService::background_processNewMessages()
* not original -> hard, redo calc (alt: could substract previous score)
*/
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages() Update, mark for FULL_CALC";
std::cerr << std::endl;
#endif // DEBUG_IDS
mit->second.mGroupStatus |= ID_LOCAL_STATUS_FULL_CALC_FLAG;
}
@ -2231,8 +2367,10 @@ bool p3IdService::background_processNewMessages()
* - flag group as modified.
*/
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages() NewOpt, Try Inc Calc";
std::cerr << std::endl;
#endif // DEBUG_IDS
mit->second.mGroupStatus |= ID_LOCAL_STATUS_INC_CALC_FLAG;
@ -2244,6 +2382,7 @@ bool p3IdService::background_processNewMessages()
std::cerr << std::endl;
}
#ifdef DEBUG_IDS
/* do calcs */
std::cerr << "p3IdService::background_processNewMessages() Extracted: ";
std::cerr << std::endl;
@ -2251,6 +2390,7 @@ bool p3IdService::background_processNewMessages()
/* store it back in */
std::cerr << "p3IdService::background_processNewMessages() Stored: ";
std::cerr << std::endl;
#endif // DEBUG_IDS
std::string serviceString = ssdata.save();
if (0)
@ -2272,24 +2412,30 @@ bool p3IdService::background_processNewMessages()
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages() Checking Groups for Calc Type";
std::cerr << std::endl;
#endif // DEBUG_IDS
for(mit = mBgGroupMap.begin(); mit != mBgGroupMap.end(); mit++)
{
if (mit->second.mGroupStatus & ID_LOCAL_STATUS_FULL_CALC_FLAG)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages() FullCalc for: ";
std::cerr << mit->second.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_IDS
mBgFullCalcGroups.push_back(mit->second.mGroupId);
}
else if (mit->second.mGroupStatus & ID_LOCAL_STATUS_INC_CALC_FLAG)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processNewMessages() IncCalc done for: ";
std::cerr << mit->second.mGroupId;
std::cerr << std::endl;
#endif // DEBUG_IDS
/* set Cache */
uint32_t dummyToken = 0;
@ -2358,8 +2504,10 @@ bool p3IdService::background_FullCalcRequest()
bool p3IdService::background_processFullCalc()
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processFullCalc()";
std::cerr << std::endl;
#endif // DEBUG_IDS
std::list<RsMsgMetaData> msgList;
std::list<RsMsgMetaData>::iterator it;
@ -2400,9 +2548,11 @@ bool p3IdService::background_processFullCalc()
groupId = opinion.mMeta.mGroupId;
}
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_processFullCalc() Msg:";
std::cerr << opinion;
std::cerr << std::endl;
#endif // DEBUG_IDS
validmsgs = true;
@ -2461,8 +2611,10 @@ bool p3IdService::background_processFullCalc()
SSGxsIdGroup ssdata;
std::string serviceString = ssdata.save();
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_updateVoteCounts() Encoded String: " << serviceString;
std::cerr << std::endl;
#endif // DEBUG_IDS
/* store new result */
uint32_t dummyToken = 0;
setGroupServiceString(dummyToken, groupId, serviceString);
@ -2480,8 +2632,10 @@ bool p3IdService::background_processFullCalc()
bool p3IdService::background_cleanup()
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::background_cleanup()";
std::cerr << std::endl;
#endif // DEBUG_IDS
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
@ -2526,8 +2680,10 @@ std::ostream &operator<<(std::ostream &out, const RsGxsIdOpinion &opinion)
// Overloaded from GxsTokenQueue for Request callbacks.
void p3IdService::handleResponse(uint32_t token, uint32_t req_type)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::handleResponse(" << token << "," << req_type << ")";
std::cerr << std::endl;
#endif // DEBUG_IDS
// stuff.
switch(req_type)
@ -2560,8 +2716,10 @@ void p3IdService::handleResponse(uint32_t token, uint32_t req_type)
// Overloaded from RsTickEvent for Event callbacks.
void p3IdService::handle_event(uint32_t event_type, const std::string &elabel)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::handle_event(" << event_type << ")";
std::cerr << std::endl;
#endif // DEBUG_IDS
// stuff.
switch(event_type)

View File

@ -308,6 +308,9 @@ bool p3Wiki::submitSnapshot(uint32_t &token, RsWikiSnapshot &snapshot)
bool p3Wiki::submitComment(uint32_t &token, RsWikiComment &comment)
{
std::cerr << "p3Wiki::submitComment(): " << comment;
std::cerr << std::endl;
RsGxsWikiCommentItem* commentItem = new RsGxsWikiCommentItem();
commentItem->comment = comment;
commentItem->meta = comment.mMeta;

View File

@ -44,6 +44,10 @@
* - mLruMap[AccessTS] => key (multimap)
*/
/***
* #define DEBUG_RSMEMCACHE 1
***/
#define DEFAULT_MEM_CACHE_SIZE 100
template<class Key, class Value> class RsMemCache
@ -107,14 +111,18 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::is_cached(const Ke
it = mDataMap.find(key);
if (it == mDataMap.end())
{
#ifdef DEBUG_RSMEMCACHE
std::cerr << "RsMemCache::is_cached(" << key << ") false";
std::cerr << std::endl;
#endif // DEBUG_RSMEMCACHE
mStats_cachemiss++;
return false;
}
#ifdef DEBUG_RSMEMCACHE
std::cerr << "RsMemCache::is_cached(" << key << ") false";
std::cerr << std::endl;
#endif // DEBUG_RSMEMCACHE
mStats_iscached++;
return true;
@ -123,20 +131,29 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::is_cached(const Ke
template<class Key, class Value> bool RsMemCache<Key, Value>::fetch(const Key &key, Value &data)
{
#ifdef DEBUG_RSMEMCACHE
std::cerr << "RsMemCache::fetch()";
std::cerr << std::endl;
printStats(std::cerr);
#endif // DEBUG_RSMEMCACHE
typename std::map<Key, cache_data>::iterator it;
it = mDataMap.find(key);
if (it == mDataMap.end())
{
#ifdef DEBUG_RSMEMCACHE
std::cerr << "RsMemCache::fetch(" << key << ") false";
std::cerr << std::endl;
#endif // DEBUG_RSMEMCACHE
mStats_accessmiss++;
return false;
}
#ifdef DEBUG_RSMEMCACHE
std::cerr << "RsMemCache::fetch(" << key << ") OK";
std::cerr << std::endl;
#endif // DEBUG_RSMEMCACHE
data = it->second.data;
@ -154,13 +171,20 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::fetch(const Key &k
template<class Key, class Value> Value &RsMemCache<Key, Value>::ref(const Key &key)
{
#ifdef DEBUG_RSMEMCACHE
std::cerr << "RsMemCache::ref()";
std::cerr << std::endl;
printStats(std::cerr);
#endif // DEBUG_RSMEMCACHE
typename std::map<Key, cache_data>::iterator it;
it = mDataMap.find(key);
if (it == mDataMap.end())
{
#ifdef DEBUG_RSMEMCACHE
std::cerr << "RsMemCache::ref(" << key << ") ERROR missing Key inserting Empty Data in LRU slot";
std::cerr << std::endl;
#endif // DEBUG_RSMEMCACHE
// insert operation.
time_t new_ts = 0;
@ -175,8 +199,10 @@ template<class Key, class Value> Value &RsMemCache<Key, Value>::ref(const Key &k
}
else
{
#ifdef DEBUG_RSMEMCACHE
std::cerr << "RsMemCache::ref(" << key << ") OK";
std::cerr << std::endl;
#endif // DEBUG_RSMEMCACHE
/* update ts on data */
time_t old_ts = it->second.ts;
@ -192,9 +218,11 @@ template<class Key, class Value> Value &RsMemCache<Key, Value>::ref(const Key &k
template<class Key, class Value> bool RsMemCache<Key, Value>::store(const Key &key, const Value &data)
{
#ifdef DEBUG_RSMEMCACHE
std::cerr << "RsMemCache::store()";
std::cerr << std::endl;
printStats(std::cerr);
#endif // DEBUG_RSMEMCACHE
/* update lrumap entry */
time_t old_ts = 0;
@ -206,8 +234,10 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::store(const Key &k
if (it != mDataMap.end())
{
// ERROR.
#ifdef DEBUG_RSMEMCACHE
std::cerr << "RsMemCache::store() WARNING overriding existing entry";
std::cerr << std::endl;
#endif // DEBUG_RSMEMCACHE
old_ts = it->second.ts;
}
@ -229,8 +259,10 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::update_lrumap(cons
{
if (old_ts == 0)
{
#ifdef DEBUG_RSMEMCACHE
std::cerr << "p3IdService::locked_cache_update_lrumap(" << key << ") just insert!";
std::cerr << std::endl;
#endif // DEBUG_RSMEMCACHE
/* new insertion */
mLruMap.insert(std::make_pair(new_ts, key));
@ -247,29 +279,37 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::update_lrumap(cons
if (mit->second == key)
{
mLruMap.erase(mit);
#ifdef DEBUG_RSMEMCACHE
std::cerr << "p3IdService::locked_cache_update_lrumap(" << key << ") rm old";
std::cerr << std::endl;
#endif // DEBUG_RSMEMCACHE
if (new_ts != 0) // == 0, means remove.
{
#ifdef DEBUG_RSMEMCACHE
std::cerr << "p3IdService::locked_cache_update_lrumap(" << key << ") added new_ts";
std::cerr << std::endl;
#endif // DEBUG_RSMEMCACHE
mLruMap.insert(std::make_pair(new_ts, key));
}
return true;
}
}
#ifdef DEBUG_RSMEMCACHE
std::cerr << "p3IdService::locked_cache_update_lrumap(" << key << ") ERROR";
std::cerr << std::endl;
#endif // DEBUG_RSMEMCACHE
return false;
}
template<class Key, class Value> bool RsMemCache<Key, Value>::resize()
{
#ifdef DEBUG_RSMEMCACHE
std::cerr << "RsMemCache::resize()";
std::cerr << std::endl;
printStats(std::cerr);
#endif // DEBUG_RSMEMCACHE
int count_to_clear = 0;
{
@ -285,8 +325,10 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::resize()
if (mDataCount > mMaxSize)
{
count_to_clear = mDataCount - mMaxSize;
#ifdef DEBUG_RSMEMCACHE
std::cerr << "RsMemCache::resize() to_clear: " << count_to_clear;
std::cerr << std::endl;
#endif // DEBUG_RSMEMCACHE
}
}
@ -322,8 +364,10 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::discard_LRU(int co
}
else
{
#ifdef DEBUG_RSMEMCACHE
std::cerr << "RsMemCache::discard_LRU() removing: " << key;
std::cerr << std::endl;
#endif // DEBUG_RSMEMCACHE
mDataMap.erase(it);
mDataCount--;
mStats_dropped++;
@ -332,8 +376,11 @@ template<class Key, class Value> bool RsMemCache<Key, Value>::discard_LRU(int co
else
{
// No More Data, ERROR.
#ifdef DEBUG_RSMEMCACHE
std::cerr << "RsMemCache::discard_LRU(): INFO more more cache data";
std::cerr << std::endl;
#endif // DEBUG_RSMEMCACHE
return true;
}
count_to_clear--;