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 "rsgxsnetservice.h"
#include "rsgxsflags.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 SYNC_PERIOD 12 // in microseconds every 10 seconds (1 second for testing)
#define TRANSAC_TIMEOUT 5 // 5 seconds #define TRANSAC_TIMEOUT 5 // 5 seconds

View File

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

View File

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

View File

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

View File

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