added additional debug info in rsgenexchange

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7549 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-09-20 19:58:07 +00:00
parent e18c934e21
commit b1dc8912c7
4 changed files with 148 additions and 50 deletions

View File

@ -1418,7 +1418,11 @@ int RsDataService::retrieveMsgIds(const RsGxsGroupId& grpId,
while(valid) while(valid)
{ {
std::string msgId; std::string msgId;
c->getString(0, msgId); c->getString(0, msgId);
if(c->columnCount() != 1)
std::cerr << "(EE) ********* not retrieving all columns!!" << std::endl;
msgIds.push_back(RsGxsMessageId(msgId)); msgIds.push_back(RsGxsMessageId(msgId));
valid = c->moveToNext(); valid = c->moveToNext();
} }

View File

@ -36,19 +36,19 @@
#include "rsgxsutil.h" #include "rsgxsutil.h"
#define PUB_GRP_MASK 0x000f #define PUB_GRP_MASK 0x000f
#define RESTR_GRP_MASK 0x00f0 #define RESTR_GRP_MASK 0x00f0
#define PRIV_GRP_MASK 0x0f00 #define PRIV_GRP_MASK 0x0f00
#define GRP_OPTIONS_MASK 0xf000 #define GRP_OPTIONS_MASK 0xf000
#define PUB_GRP_OFFSET 0 #define PUB_GRP_OFFSET 0
#define RESTR_GRP_OFFSET 8 #define RESTR_GRP_OFFSET 8
#define PRIV_GRP_OFFSET 16 #define PRIV_GRP_OFFSET 16
#define GRP_OPTIONS_OFFSET 24 #define GRP_OPTIONS_OFFSET 24
#define GXS_MASK "GXS_MASK_HACK" #define GXS_MASK "GXS_MASK_HACK"
//#define GEN_EXCH_DEBUG 1 #define GEN_EXCH_DEBUG 1
#define MSG_CLEANUP_PERIOD 60*5 // 5 minutes #define MSG_CLEANUP_PERIOD 60*5 // 5 minutes
#define INTEGRITY_CHECK_PERIOD 60*30 // 30 minutes #define INTEGRITY_CHECK_PERIOD 60*30 // 30 minutes
@ -195,41 +195,61 @@ bool RsGenExchange::acknowledgeTokenMsg(const uint32_t& token,
{ {
RsStackMutex stack(mGenMtx); RsStackMutex stack(mGenMtx);
std::map<uint32_t, RsGxsGrpMsgIdPair >::iterator mit = #ifdef GEN_EXCH_DEBUG
mMsgNotify.find(token); std::cerr << "RsGenExchange::acknowledgeTokenMsg(). token=" << token << std::endl;
#endif
std::map<uint32_t, RsGxsGrpMsgIdPair >::iterator mit = mMsgNotify.find(token);
if(mit == mMsgNotify.end()) if(mit == mMsgNotify.end())
{ {
return false; #ifdef GEN_EXCH_DEBUG
} std::cerr << " no notification found for this token." << std::endl;
#endif
return false;
}
msgId = mit->second; msgId = mit->second;
// no dump token as client has ackowledged its completion // no dump token as client has ackowledged its completion
mDataAccess->disposeOfPublicToken(token); mDataAccess->disposeOfPublicToken(token);
#ifdef GEN_EXCH_DEBUG
std::cerr << " found grpId=" << msgId.first <<", msgId=" << msgId.second << std::endl;
std::cerr << " disposing token from mDataAccess" << std::endl;
#endif
return true; return true;
} }
bool RsGenExchange::acknowledgeTokenGrp(const uint32_t& token, bool RsGenExchange::acknowledgeTokenGrp(const uint32_t& token, RsGxsGroupId& grpId)
RsGxsGroupId& grpId)
{ {
RsStackMutex stack(mGenMtx); RsStackMutex stack(mGenMtx);
#ifdef GEN_EXCH_DEBUG
std::cerr << "RsGenExchange::acknowledgeTokenGrp(). token=" << token << std::endl;
#endif
std::map<uint32_t, RsGxsGroupId >::iterator mit = std::map<uint32_t, RsGxsGroupId >::iterator mit =
mGrpNotify.find(token); mGrpNotify.find(token);
if(mit == mGrpNotify.end()) if(mit == mGrpNotify.end())
{
#ifdef GEN_EXCH_DEBUG
std::cerr << " no notification found for this token." << std::endl;
#endif
return false; return false;
}
grpId = mit->second; grpId = mit->second;
// no dump token as client has ackowledged its completion // no dump token as client has ackowledged its completion
mDataAccess->disposeOfPublicToken(token); mDataAccess->disposeOfPublicToken(token);
#ifdef GEN_EXCH_DEBUG
std::cerr << " found grpId=" << grpId << std::endl;
std::cerr << " disposing token from mDataAccess" << std::endl;
#endif
return true; return true;
} }
@ -275,8 +295,10 @@ void RsGenExchange::generatePublicFromPrivateKeys(const RsTlvSecurityKeySet &pri
uint8_t RsGenExchange::createGroup(RsNxsGrp *grp, RsTlvSecurityKeySet& privateKeySet, RsTlvSecurityKeySet& publicKeySet) uint8_t RsGenExchange::createGroup(RsNxsGrp *grp, RsTlvSecurityKeySet& privateKeySet, RsTlvSecurityKeySet& publicKeySet)
{ {
#ifdef GEN_EXCH_DEBUG
std::cerr << "RsGenExchange::createGroup()"; std::cerr << "RsGenExchange::createGroup()";
std::cerr << std::endl; std::cerr << std::endl;
#endif
RsGxsGrpMetaData* meta = grp->metaData; RsGxsGrpMetaData* meta = grp->metaData;
@ -598,6 +620,9 @@ int RsGenExchange::createMessage(RsNxsMsg* msg)
{ {
const RsGxsGroupId& id = msg->grpId; const RsGxsGroupId& id = msg->grpId;
#ifdef GEN_EXCH_DEBUG
std::cerr << "RsGenExchange::createMessage() " << std::endl;
#endif
std::map<RsGxsGroupId, RsGxsGrpMetaData*> metaMap; std::map<RsGxsGroupId, RsGxsGrpMetaData*> metaMap;
metaMap.insert(std::make_pair(id, (RsGxsGrpMetaData*)(NULL))); metaMap.insert(std::make_pair(id, (RsGxsGrpMetaData*)(NULL)));
@ -772,7 +797,7 @@ int RsGenExchange::validateMsg(RsNxsMsg *msg, const uint32_t& grpFlag, RsTlvSecu
} }
else else
{ {
#ifdef GEN_EXHANGE_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << "Gixs not enabled while request identity signature validation!" << std::endl; std::cerr << "Gixs not enabled while request identity signature validation!" << std::endl;
#endif #endif
idValidate = false; idValidate = false;
@ -844,7 +869,7 @@ int RsGenExchange::validateGrp(RsNxsGrp* grp)
} }
else else
{ {
#ifdef GEN_EXHANGE_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << "Gixs not enabled while request identity signature validation!" << std::endl; std::cerr << "Gixs not enabled while request identity signature validation!" << std::endl;
#endif #endif
idValidate = false; idValidate = false;
@ -892,6 +917,9 @@ void RsGenExchange::receiveChanges(std::vector<RsGxsNotify*>& changes)
{ {
RsStackMutex stack(mGenMtx); RsStackMutex stack(mGenMtx);
#ifdef GEN_EXCH_DEBUG
std::cerr << "RsGenExchange::receiveChanges()" << std::endl;
#endif
std::vector<RsGxsNotify*>::iterator vit = changes.begin(); std::vector<RsGxsNotify*>::iterator vit = changes.begin();
for(; vit != changes.end(); vit++) for(; vit != changes.end(); vit++)
@ -909,7 +937,8 @@ void RsGenExchange::receiveChanges(std::vector<RsGxsNotify*>& changes)
} }
else else
{ {
delete n; #warning cyril: very weird code. Why delete an element without removing it from the array??
delete n;
} }
} }
@ -1059,6 +1088,9 @@ bool RsGenExchange::getGroupMeta(const uint32_t &token, std::list<RsGroupMetaDat
bool RsGenExchange::getMsgMeta(const uint32_t &token, bool RsGenExchange::getMsgMeta(const uint32_t &token,
GxsMsgMetaMap &msgInfo) GxsMsgMetaMap &msgInfo)
{ {
#ifdef GEN_EXCH_DEBUG
std::cerr << "RsGenExchange::getMsgMeta(): retrieving meta data for token " << token << std::endl;
#endif
std::list<RsGxsMsgMetaData*> metaL; std::list<RsGxsMsgMetaData*> metaL;
GxsMsgMetaResult result; GxsMsgMetaResult result;
bool ok = mDataAccess->getMsgSummary(token, result); bool ok = mDataAccess->getMsgSummary(token, result);
@ -2277,19 +2309,36 @@ void RsGenExchange::processRecvdMessages()
{ {
RsStackMutex stack(mGenMtx); RsStackMutex stack(mGenMtx);
#ifdef GEN_EXCH_DEBUG
if(!mMsgPendingValidate.empty())
std::cerr << "processing received messages" << std::endl;
#endif
NxsMsgPendingVect::iterator pend_it = mMsgPendingValidate.begin(); NxsMsgPendingVect::iterator pend_it = mMsgPendingValidate.begin();
#ifdef GEN_EXCH_DEBUG
if(!mMsgPendingValidate.empty())
std::cerr << " pending validation" << std::endl;
#endif
for(; pend_it != mMsgPendingValidate.end();) for(; pend_it != mMsgPendingValidate.end();)
{ {
GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair>& gpsi = *pend_it; GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair>& gpsi = *pend_it;
#ifdef GEN_EXCH_DEBUG
std::cerr << " grp=" << gpsi.mId.first << ", msg=" << gpsi.mId.second << ", attempts=" << gpsi.mAttempts ;
#endif
if(gpsi.mAttempts == VALIDATE_MAX_ATTEMPTS) if(gpsi.mAttempts == VALIDATE_MAX_ATTEMPTS)
{ {
#ifdef GEN_EXCH_DEBUG
std::cerr << " = max! deleting." << std::endl;
#endif
delete gpsi.mItem; delete gpsi.mItem;
pend_it = mMsgPendingValidate.erase(pend_it); pend_it = mMsgPendingValidate.erase(pend_it);
} }
else else
{ {
#ifdef GEN_EXCH_DEBUG
std::cerr << " movign to recvd." << std::endl;
#endif
mReceivedMsgs.push_back(gpsi.mItem); mReceivedMsgs.push_back(gpsi.mItem);
pend_it++; pend_it++;
} }
@ -2313,6 +2362,9 @@ void RsGenExchange::processRecvdMessages()
mDataStore->retrieveGxsGrpMetaData(grpMetas); mDataStore->retrieveGxsGrpMetaData(grpMetas);
#ifdef GEN_EXCH_DEBUG
std::cerr << " updating received messages:" << std::endl;
#endif
for(vit = mReceivedMsgs.begin(); vit != mReceivedMsgs.end(); vit++) for(vit = mReceivedMsgs.begin(); vit != mReceivedMsgs.end(); vit++)
{ {
RsNxsMsg* msg = *vit; RsNxsMsg* msg = *vit;
@ -2325,17 +2377,27 @@ void RsGenExchange::processRecvdMessages()
msg->metaData = meta; msg->metaData = meta;
#ifdef GEN_EXCH_DEBUG
std::cerr << " deserialised info: grp id=" << meta->mGroupId << ", msg id=" << meta->mMsgId ;
#endif
uint8_t validateReturn = VALIDATE_FAIL; uint8_t validateReturn = VALIDATE_FAIL;
if(ok) if(ok)
{ {
std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMetas.find(msg->grpId); std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator mit = grpMetas.find(msg->grpId);
#ifdef GEN_EXCH_DEBUG
std::cerr << " msg info : grp id=" << msg->grpId << ", msg id=" << msg->msgId << std::endl;
#endif
// validate msg // validate msg
if(mit != grpMetas.end()) if(mit != grpMetas.end())
{ {
RsGxsGrpMetaData* grpMeta = mit->second; RsGxsGrpMetaData* grpMeta = mit->second;
validateReturn = validateMsg(msg, grpMeta->mGroupFlags, grpMeta->keys); validateReturn = validateMsg(msg, grpMeta->mGroupFlags, grpMeta->keys);
#ifdef GEN_EXCH_DEBUG
std::cerr << " message validation result: " << validateReturn << std::endl;
#endif
} }
if(validateReturn == VALIDATE_SUCCESS) if(validateReturn == VALIDATE_SUCCESS)
@ -2351,17 +2413,24 @@ void RsGenExchange::processRecvdMessages()
computeHash(msg->msg, meta->mHash); computeHash(msg->msg, meta->mHash);
meta->recvTS = time(NULL); meta->recvTS = time(NULL);
#ifdef GEN_EXCH_DEBUG
std::cerr << " new status flags: " << meta->mMsgStatus << std::endl;
std::cerr << " computed hash: " << meta->mHash << std::endl;
#endif
} }
} }
else else
{ {
#ifdef GEN_EXCH_DEBUG
std::cerr << " deserialisation failed!" <<std::endl;
#endif
validateReturn = VALIDATE_FAIL; validateReturn = VALIDATE_FAIL;
} }
if(validateReturn == VALIDATE_FAIL) if(validateReturn == VALIDATE_FAIL)
{ {
#ifdef GXS_GENX_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << "failed to deserialise incoming meta, msgId: " std::cerr << "failed to deserialise incoming meta, msgId: "
<< "msg->grpId: " << msg->grpId << ", msgId: " << msg->msgId << std::endl; << "msg->grpId: " << msg->grpId << ", msgId: " << msg->msgId << std::endl;
#endif #endif
@ -2377,7 +2446,7 @@ void RsGenExchange::processRecvdMessages()
else if(validateReturn == VALIDATE_FAIL_TRY_LATER) else if(validateReturn == VALIDATE_FAIL_TRY_LATER)
{ {
#ifdef GXS_GENX_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << "failed to validate msg, trying again: " std::cerr << "failed to validate msg, trying again: "
<< "msg->grpId: " << msg->grpId << ", msgId: " << msg->msgId << std::endl; << "msg->grpId: " << msg->grpId << ", msgId: " << msg->msgId << std::endl;
#endif #endif
@ -2408,7 +2477,14 @@ void RsGenExchange::processRecvdMessages()
if(!msgIds.empty()) if(!msgIds.empty())
{ {
removeDeleteExistingMessages(msgs, msgIds); #ifdef GEN_EXCH_DEBUG
std::cerr << " removing existing messages." << std::endl;
#endif
removeDeleteExistingMessages(msgs, msgIds);
#ifdef GEN_EXCH_DEBUG
std::cerr << " storing remaining messages" << std::endl;
#endif
mDataStore->storeMessage(msgs); mDataStore->storeMessage(msgs);
RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_RECEIVE, false); RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_RECEIVE, false);
c->msgChangeMap = msgIds; c->msgChangeMap = msgIds;
@ -2478,7 +2554,7 @@ void RsGenExchange::processRecvdGroups()
} }
else if(ret == VALIDATE_FAIL) else if(ret == VALIDATE_FAIL)
{ {
#ifdef GXS_GENX_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << "failed to deserialise incoming meta, grpId: " std::cerr << "failed to deserialise incoming meta, grpId: "
<< grp->grpId << std::endl; << grp->grpId << std::endl;
#endif #endif
@ -2488,7 +2564,7 @@ void RsGenExchange::processRecvdGroups()
else if(ret == VALIDATE_FAIL_TRY_LATER) else if(ret == VALIDATE_FAIL_TRY_LATER)
{ {
#ifdef GXS_GENX_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << "failed to validate incoming grp, trying again. grpId: " std::cerr << "failed to validate incoming grp, trying again. grpId: "
<< grp->grpId << std::endl; << grp->grpId << std::endl;
#endif #endif
@ -2531,13 +2607,13 @@ void RsGenExchange::performUpdateValidation()
RsStackMutex stack(mGenMtx); RsStackMutex stack(mGenMtx);
#ifdef GXS_GENX_DEBUG
std::cerr << "RsGenExchange::performUpdateValidation() " << std::endl;
#endif
if(mGroupUpdates.empty()) if(mGroupUpdates.empty())
return; return;
#ifdef GEN_EXCH_DEBUG
std::cerr << "RsGenExchange::performUpdateValidation() " << std::endl;
#endif
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMetas; std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMetas;
std::vector<GroupUpdate>::iterator vit = mGroupUpdates.begin(); std::vector<GroupUpdate>::iterator vit = mGroupUpdates.begin();
@ -2559,7 +2635,7 @@ void RsGenExchange::performUpdateValidation()
gu.validUpdate = updateValid(*(gu.oldGrpMeta), *(gu.newGrp)); gu.validUpdate = updateValid(*(gu.oldGrpMeta), *(gu.newGrp));
} }
#ifdef GXS_GENX_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << "RsGenExchange::performUpdateValidation() " << std::endl; std::cerr << "RsGenExchange::performUpdateValidation() " << std::endl;
#endif #endif
@ -2595,9 +2671,9 @@ bool RsGenExchange::updateValid(RsGxsGrpMetaData& oldGrpMeta, RsNxsGrp& newGrp)
if(mit == signSet.end()) if(mit == signSet.end())
{ {
#ifdef GXS_GENX_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << "RsGenExchange::updateValid() new admin sign not found! " << std::endl; std::cerr << "RsGenExchange::updateValid() new admin sign not found! " << std::endl;
std::cerr << "RsGenExchange::updateValid() grpId: " << oldGrp.grpId << std::endl; std::cerr << "RsGenExchange::updateValid() grpId: " << oldGrpMeta.mGroupId << std::endl;
#endif #endif
return false; return false;
@ -2610,7 +2686,7 @@ bool RsGenExchange::updateValid(RsGxsGrpMetaData& oldGrpMeta, RsNxsGrp& newGrp)
if(keyMit == keys.end()) if(keyMit == keys.end())
{ {
#ifdef GXS_GENX_DEBUG #ifdef GEN_EXCH_DEBUG
std::cerr << "RsGenExchange::updateValid() admin key not found! " << std::endl; std::cerr << "RsGenExchange::updateValid() admin key not found! " << std::endl;
#endif #endif
return false; return false;
@ -2637,37 +2713,42 @@ void RsGenExchange::removeDeleteExistingMessages(
RsGeneralDataService::MsgStoreMap& msgs, GxsMsgReq& msgIdsNotify) { RsGeneralDataService::MsgStoreMap& msgs, GxsMsgReq& msgIdsNotify) {
// first get grp ids of messages to be stored // first get grp ids of messages to be stored
RsGeneralDataService::MsgStoreMap::const_iterator cit =
msgs.begin();
RsGxsGroupId::std_set mGrpIdsUnique; RsGxsGroupId::std_set mGrpIdsUnique;
for(; cit != msgs.end(); cit++) for(RsGeneralDataService::MsgStoreMap::const_iterator cit = msgs.begin(); cit != msgs.end(); cit++)
{
mGrpIdsUnique.insert(cit->second->mGroupId); mGrpIdsUnique.insert(cit->second->mGroupId);
}
RsGxsGroupId::std_list grpIds(mGrpIdsUnique.begin(), mGrpIdsUnique.end()); //RsGxsGroupId::std_list grpIds(mGrpIdsUnique.begin(), mGrpIdsUnique.end());
RsGxsGroupId::std_list::const_iterator it = grpIds.begin(); //RsGxsGroupId::std_list::const_iterator it = grpIds.begin();
typedef std::map<RsGxsGroupId, RsGxsMessageId::std_vector> MsgIdReq; typedef std::map<RsGxsGroupId, RsGxsMessageId::std_vector> MsgIdReq;
MsgIdReq msgIdReq; MsgIdReq msgIdReq;
// now get a list of all msgs ids for each group // now get a list of all msgs ids for each group
for(; it != grpIds.end(); it++) for(RsGxsGroupId::std_set::const_iterator it(mGrpIdsUnique.begin()); it != mGrpIdsUnique.end(); it++)
{ {
mDataStore->retrieveMsgIds(*it, msgIdReq[*it]); mDataStore->retrieveMsgIds(*it, msgIdReq[*it]);
#ifdef GEN_EXCH_DEBUG
const std::vector<RsGxsMessageId>& vec(msgIdReq[*it]) ;
std::cerr << " retrieved " << vec.size() << " message ids for group " << *it << std::endl;
for(uint32_t i=0;i<vec.size();++i)
std::cerr << " " << vec[i] << std::endl;
#endif
} }
RsGeneralDataService::MsgStoreMap::iterator cit2 = msgs.begin(); //RsGeneralDataService::MsgStoreMap::iterator cit2 = msgs.begin();
RsGeneralDataService::MsgStoreMap filtered; RsGeneralDataService::MsgStoreMap filtered;
// now for each msg to be stored that exist in the retrieved msg/grp "index" delete and erase from map // now for each msg to be stored that exist in the retrieved msg/grp "index" delete and erase from map
for(; cit2 != msgs.end(); cit2++) for(RsGeneralDataService::MsgStoreMap::iterator cit2 = msgs.begin(); cit2 != msgs.end(); cit2++)
{ {
const RsGxsMessageId::std_vector& msgIds = msgIdReq[cit2->second->mGroupId]; const RsGxsMessageId::std_vector& msgIds = msgIdReq[cit2->second->mGroupId];
if(std::find(msgIds.begin(), msgIds.end(), cit2->second->mMsgId) != std::cerr << " grpid=" << cit2->second->mGroupId << ", msgid=" << cit2->second->mMsgId ;
msgIds.end())
if(std::find(msgIds.begin(), msgIds.end(), cit2->second->mMsgId) != msgIds.end())
{ {
// msg exist in retrieved index // msg exist in retrieved index
delete cit2->first; delete cit2->first;
@ -2676,11 +2757,17 @@ void RsGenExchange::removeDeleteExistingMessages(
notifyIds.end(), cit2->second->mMsgId); notifyIds.end(), cit2->second->mMsgId);
if(it2 != notifyIds.end()) if(it2 != notifyIds.end())
notifyIds.erase(it2); notifyIds.erase(it2);
#ifdef GEN_EXCH_DEBUG
std::cerr << " discarding " << cit2->second->mMsgId << std::endl;
#endif
} }
else else
{ {
// does not exist so add to filtered list // does not exist so add to filtered list
filtered.insert(*cit2); filtered.insert(*cit2);
#ifdef GEN_EXCH_DEBUG
std::cerr << " keeping " << cit2->second->mMsgId << std::endl;
#endif
} }
} }

View File

@ -600,7 +600,6 @@ bool RetroCursor::moveToLast(){
return true; return true;
} }
} }
int RetroCursor::getResultCount() const { int RetroCursor::getResultCount() const {
if(isOpen()) if(isOpen())
@ -608,6 +607,13 @@ int RetroCursor::getResultCount() const {
else else
return -1; return -1;
} }
int RetroCursor::columnCount() const {
if(isOpen())
return sqlite3_data_count(mStmt);
else
return -1;
}
bool RetroCursor::isOpen() const { bool RetroCursor::isOpen() const {
return !(mStmt == NULL); return !(mStmt == NULL);

View File

@ -239,6 +239,7 @@ public:
*/ */
int32_t getResultCount() const; int32_t getResultCount() const;
int32_t columnCount() const ;
/*! /*!
* Current statement is closed and discarded (finalised) * Current statement is closed and discarded (finalised)
* before actual opening occurs * before actual opening occurs