mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-17 02:17:19 -05:00
replace mNbAttempts in signature and validation of posts by a timeout, which allows to wait for missing keys more robustly
This commit is contained in:
parent
3a45bac8e7
commit
9d82a3ff16
@ -86,14 +86,14 @@ RsGenExchange::RsGenExchange(RsGeneralDataService *gds, RsNetworkExchangeService
|
|||||||
CREATE_FAIL(0),
|
CREATE_FAIL(0),
|
||||||
CREATE_SUCCESS(1),
|
CREATE_SUCCESS(1),
|
||||||
CREATE_FAIL_TRY_LATER(2),
|
CREATE_FAIL_TRY_LATER(2),
|
||||||
SIGN_MAX_ATTEMPTS(5),
|
SIGN_MAX_WAITING_TIME(60),
|
||||||
SIGN_FAIL(0),
|
SIGN_FAIL(0),
|
||||||
SIGN_SUCCESS(1),
|
SIGN_SUCCESS(1),
|
||||||
SIGN_FAIL_TRY_LATER(2),
|
SIGN_FAIL_TRY_LATER(2),
|
||||||
VALIDATE_FAIL(0),
|
VALIDATE_FAIL(0),
|
||||||
VALIDATE_SUCCESS(1),
|
VALIDATE_SUCCESS(1),
|
||||||
VALIDATE_FAIL_TRY_LATER(2),
|
VALIDATE_FAIL_TRY_LATER(2),
|
||||||
VALIDATE_MAX_ATTEMPTS(5)
|
VALIDATE_MAX_WAITING_TIME(60)
|
||||||
{
|
{
|
||||||
|
|
||||||
mDataAccess = new RsGxsDataAccess(gds);
|
mDataAccess = new RsGxsDataAccess(gds);
|
||||||
@ -1478,7 +1478,7 @@ void RsGenExchange::notifyNewGroups(std::vector<RsNxsGrp *> &groups)
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GxsPendingItem<RsNxsGrp*, RsGxsGroupId> gpsi(grp, grp->grpId);
|
GxsPendingItem<RsNxsGrp*, RsGxsGroupId> gpsi(grp, grp->grpId,time(NULL));
|
||||||
mReceivedGrps.push_back(gpsi);
|
mReceivedGrps.push_back(gpsi);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1923,7 +1923,9 @@ bool RsGenExchange::processGrpMask(const RsGxsGroupId& grpId, ContentValue &grpC
|
|||||||
void RsGenExchange::publishMsgs()
|
void RsGenExchange::publishMsgs()
|
||||||
{
|
{
|
||||||
|
|
||||||
RS_STACK_MUTEX(mGenMtx) ;
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
|
time_t now = time(NULL);
|
||||||
|
|
||||||
// stick back msgs pending signature
|
// stick back msgs pending signature
|
||||||
typedef std::map<uint32_t, GxsPendingItem<RsGxsMsgItem*, uint32_t> > PendSignMap;
|
typedef std::map<uint32_t, GxsPendingItem<RsGxsMsgItem*, uint32_t> > PendSignMap;
|
||||||
@ -1992,22 +1994,20 @@ void RsGenExchange::publishMsgs()
|
|||||||
// sign attempt
|
// sign attempt
|
||||||
if(pit == mMsgPendingSign.end())
|
if(pit == mMsgPendingSign.end())
|
||||||
{
|
{
|
||||||
GxsPendingItem<RsGxsMsgItem*, uint32_t> gsi(msgItem, token);
|
GxsPendingItem<RsGxsMsgItem*, uint32_t> gsi(msgItem, token,time(NULL));
|
||||||
mMsgPendingSign.insert(std::make_pair(token, gsi));
|
mMsgPendingSign.insert(std::make_pair(token, gsi));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// remove from attempts queue if over sign
|
// remove from attempts queue if over sign
|
||||||
// attempts limit
|
// attempts limit
|
||||||
if(pit->second.mAttempts == SIGN_MAX_ATTEMPTS)
|
if(pit->second.mFirstTryTS + SIGN_MAX_WAITING_TIME < now)
|
||||||
{
|
{
|
||||||
|
std::cerr << "Pending signature grp=" << pit->second.mItem->meta.mGroupId << ", msg=" << pit->second.mItem->meta.mMsgId << ", has exceeded validation time limit. The author's key can probably not be obtained. This is unexpected." << std::endl;
|
||||||
|
|
||||||
mMsgPendingSign.erase(token);
|
mMsgPendingSign.erase(token);
|
||||||
tryLater = false;
|
tryLater = false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
++pit->second.mAttempts;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createOk = false;
|
createOk = false;
|
||||||
@ -2653,28 +2653,22 @@ void RsGenExchange::processRecvdMessages()
|
|||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mGenMtx) ;
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
|
time_t now = time(NULL);
|
||||||
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
if(!mMsgPendingValidate.empty())
|
if(!mMsgPendingValidate.empty())
|
||||||
std::cerr << "processing received messages" << std::endl;
|
std::cerr << "processing received messages" << std::endl;
|
||||||
#endif
|
#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
|
if(gpsi.mFirstTryTS + VALIDATE_MAX_WAITING_TIME < now)
|
||||||
std::cerr << " grp=" << gpsi.mId.first << ", msg=" << gpsi.mId.second << ", attempts=" << gpsi.mAttempts ;
|
|
||||||
#endif
|
|
||||||
if(gpsi.mAttempts == VALIDATE_MAX_ATTEMPTS)
|
|
||||||
{
|
{
|
||||||
#ifdef GEN_EXCH_DEBUG
|
std::cerr << "Pending validation grp=" << gpsi.mId.first << ", msg=" << gpsi.mId.second << ", has exceeded validation time limit. The author's key can probably not be obtained. This is unexpected." << std::endl;
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -2836,16 +2830,12 @@ void RsGenExchange::processRecvdMessages()
|
|||||||
|
|
||||||
// first check you haven't made too many attempts
|
// first check you haven't made too many attempts
|
||||||
|
|
||||||
NxsMsgPendingVect::iterator vit = std::find(
|
NxsMsgPendingVect::iterator vit = std::find(mMsgPendingValidate.begin(), mMsgPendingValidate.end(), id);
|
||||||
mMsgPendingValidate.begin(), mMsgPendingValidate.end(), id);
|
|
||||||
|
|
||||||
if(vit == mMsgPendingValidate.end())
|
if(vit == mMsgPendingValidate.end())
|
||||||
{
|
{
|
||||||
GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair> item(msg, id);
|
GxsPendingItem<RsNxsMsg*, RsGxsGrpMsgIdPair> item(msg, id,time(NULL));
|
||||||
mMsgPendingValidate.push_back(item);
|
mMsgPendingValidate.push_back(item);
|
||||||
}else
|
|
||||||
{
|
|
||||||
vit->mAttempts++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2978,18 +2968,16 @@ void RsGenExchange::processRecvdGroups()
|
|||||||
std::cerr << " failed to validate incoming grp, trying again. grpId: " << grp->grpId << std::endl;
|
std::cerr << " failed to validate incoming grp, trying again. grpId: " << grp->grpId << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(gpsi.mAttempts == VALIDATE_MAX_ATTEMPTS)
|
if(gpsi.mFirstTryTS + VALIDATE_MAX_WAITING_TIME < time(NULL))
|
||||||
{
|
{
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << " max attempts " << VALIDATE_MAX_ATTEMPTS << " reached. Will delete group " << grp->grpId << std::endl;
|
std::cerr << " validation time got group " << grp->grpId << " exceeded maximum. Will delete group " << std::endl;
|
||||||
#endif
|
#endif
|
||||||
delete grp;
|
delete grp;
|
||||||
erase = true;
|
erase = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
erase = false;
|
erase = false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -43,17 +43,10 @@ template<class GxsItem, typename Identity = std::string>
|
|||||||
class GxsPendingItem
|
class GxsPendingItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GxsPendingItem(GxsItem item, Identity id) :
|
GxsPendingItem(GxsItem item, Identity id,time_t ts) :
|
||||||
mItem(item), mId(id), mAttempts(0)
|
mItem(item), mId(id), mFirstTryTS(ts)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
GxsPendingItem(const GxsPendingItem& gpsi)
|
|
||||||
{
|
|
||||||
this->mItem = gpsi.mItem;
|
|
||||||
this->mId = gpsi.mId;
|
|
||||||
this->mAttempts = gpsi.mAttempts;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(const Identity& id)
|
bool operator==(const Identity& id)
|
||||||
{
|
{
|
||||||
return this->mId == id;
|
return this->mId == id;
|
||||||
@ -61,7 +54,7 @@ public:
|
|||||||
|
|
||||||
GxsItem mItem;
|
GxsItem mItem;
|
||||||
Identity mId;
|
Identity mId;
|
||||||
uint8_t mAttempts;
|
time_t mFirstTryTS;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GxsGrpPendingSign
|
class GxsGrpPendingSign
|
||||||
@ -883,9 +876,9 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const uint8_t CREATE_FAIL, CREATE_SUCCESS, CREATE_FAIL_TRY_LATER, SIGN_MAX_ATTEMPTS;
|
const uint8_t CREATE_FAIL, CREATE_SUCCESS, CREATE_FAIL_TRY_LATER, SIGN_MAX_WAITING_TIME;
|
||||||
const uint8_t SIGN_FAIL, SIGN_SUCCESS, SIGN_FAIL_TRY_LATER;
|
const uint8_t SIGN_FAIL, SIGN_SUCCESS, SIGN_FAIL_TRY_LATER;
|
||||||
const uint8_t VALIDATE_FAIL, VALIDATE_SUCCESS, VALIDATE_FAIL_TRY_LATER, VALIDATE_MAX_ATTEMPTS;
|
const uint8_t VALIDATE_FAIL, VALIDATE_SUCCESS, VALIDATE_FAIL_TRY_LATER, VALIDATE_MAX_WAITING_TIME;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user