Merge pull request #2137 from PhenomRetroShare/Add_HandleTokenStatus

Add ability to manage canceled token in Gxs.
This commit is contained in:
csoler 2021-01-14 19:50:55 +01:00 committed by GitHub
commit 3decd2b768
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 154 additions and 128 deletions

View File

@ -50,9 +50,10 @@ void GxsTokenQueue::checkRequests()
for(it = mQueue.begin(); it != mQueue.end();)
{
uint32_t token = it->mToken;
uint32_t status = mGenExchange->getTokenService()->requestStatus(token);
it->mStatus = mGenExchange->getTokenService()->requestStatus(token);
if (status == RsTokenService::COMPLETE)
if ( it->mStatus == RsTokenService::COMPLETE
|| it->mStatus == RsTokenService::CANCELLED )
{
toload.push_back(*it);
it = mQueue.erase(it);
@ -64,7 +65,7 @@ void GxsTokenQueue::checkRequests()
#endif
++it;
}
else if (status == RsTokenService::FAILED)
else if (it->mStatus == RsTokenService::FAILED)
{
// maybe we should do alternative callback?
std::cerr << __PRETTY_FUNCTION__ << " ERROR Request Failed! "
@ -87,7 +88,7 @@ void GxsTokenQueue::checkRequests()
{
for(it = toload.begin(); it != toload.end(); ++it)
{
handleResponse(it->mToken, it->mReqType);
handleResponse(it->mToken, it->mReqType, it->mStatus);
}
}
}

View File

@ -23,19 +23,22 @@
#define R_GXS_TOKEN_QUEUE_H
#include "gxs/rsgenexchange.h"
#include "retroshare/rsservicecontrol.h"
#include "util/rsthreads.h"
struct GxsTokenQueueItem
{
public:
GxsTokenQueueItem(const uint32_t token, const uint32_t req_type) :
mToken(token), mReqType(req_type) {}
mToken(token), mReqType(req_type), mStatus(RsTokenService::PENDING) {}
GxsTokenQueueItem(): mToken(0), mReqType(0) {}
GxsTokenQueueItem(): mToken(0), mReqType(0), mStatus(RsTokenService::PENDING) {}
uint32_t mToken;
uint32_t mReqType;
RsTokenService::GxsRequestStatus mStatus;
};
@ -54,7 +57,8 @@ public:
protected:
/// This must be overloaded to complete the functionality.
virtual void handleResponse(uint32_t token, uint32_t req_type) = 0;
virtual void handleResponse(uint32_t token, uint32_t req_type
, RsTokenService::GxsRequestStatus status) = 0;
private:
RsGenExchange *mGenExchange;

View File

@ -720,6 +720,7 @@ void RsGxsDataAccess::processRequests()
{
if(now > mRequestQueue.begin()->second->reqTime + MAX_REQUEST_AGE)
{
mPublicToken[mRequestQueue.begin()->second->token] = CANCELLED;
delete mRequestQueue.begin()->second;
mRequestQueue.erase(mRequestQueue.begin());
continue;
@ -1024,7 +1025,7 @@ bool RsGxsDataAccess::getMsgMetaDataList( const GxsMsgReq& msgIds, const RsTokRe
for(meta_it = result.begin(); meta_it != result.end(); ++meta_it)
{
const RsGxsGroupId& grpId = meta_it->first;
//const RsGxsGroupId& grpId = meta_it->first;
//auto& filter( metaFilter[grpId] ); // does the initialization of metaFilter[grpId] and avoids further O(log(n)) calls
@ -1123,7 +1124,6 @@ bool RsGxsDataAccess::getMsgMetaDataList( const GxsMsgReq& msgIds, const RsTokRe
if(metaV[i] != nullptr)
{
const auto& msgMeta = metaV[i];
bool add = false;
/* if we are grabbing thread Head... then parentId == empty. */
if (onlyThreadHeadMsgs && !msgMeta->mParentId.isNull())

View File

@ -137,11 +137,15 @@ void p3GxsTrans::registerGxsTransClient(
mServClients[serviceType] = service;
}
void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type)
void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type
, RsTokenService::GxsRequestStatus status)
{
#ifdef DEBUG_GXSTRANS
std::cout << "p3GxsTrans::handleResponse(" << token << ", " << req_type << ")" << std::endl;
std::cout << "p3GxsTrans::handleResponse(" << token << ", " << req_type << ", " << status << ")" << std::endl;
#endif
if (status != RsTokenService::COMPLETE)
return; //For now, only manage Complete request
bool changed = false ;
switch (req_type)

View File

@ -159,7 +159,7 @@ public:
GxsTransClient* service );
/// @see RsGenExchange::getServiceInfo()
virtual RsServiceInfo getServiceInfo() { return RsServiceInfo( RS_SERVICE_TYPE_GXS_TRANS, "GXS Mails", 0, 1, 0, 1 ); }
virtual RsServiceInfo getServiceInfo() override { return RsServiceInfo( RS_SERVICE_TYPE_GXS_TRANS, "GXS Mails", 0, 1, 0, 1 ); }
static const uint32_t GXS_STORAGE_PERIOD = 15*86400; // 15 days.
static const uint32_t GXS_SYNC_PERIOD = 15*86400;
@ -230,30 +230,32 @@ private:
inMap mIncomingQueue;
RsMutex mIngoingMutex;
/// @see GxsTokenQueue::handleResponse(uint32_t token, uint32_t req_type)
virtual void handleResponse(uint32_t token, uint32_t req_type);
/// @see GxsTokenQueue::handleResponse(uint32_t token, uint32_t req_type
/// , RsTokenService::GxsRequestStatus status)
virtual void handleResponse(uint32_t token, uint32_t req_type
, RsTokenService::GxsRequestStatus status) override;
/// @see RsGenExchange::service_tick()
virtual void service_tick();
virtual void service_tick() override;
/// @see RsGenExchange::service_CreateGroup(...)
RsGenExchange::ServiceCreate_Return service_CreateGroup(
RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& );
RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& ) override;
/// @see RsGenExchange::notifyChanges(std::vector<RsGxsNotify *> &changes)
void notifyChanges(std::vector<RsGxsNotify *> &changes);
void notifyChanges(std::vector<RsGxsNotify *> &changes) override;
/// @see p3Config::setupSerialiser()
virtual RsSerialiser* setupSerialiser();
virtual RsSerialiser* setupSerialiser() override;
/// @see p3Config::saveList(bool &cleanup, std::list<RsItem *>&)
virtual bool saveList(bool &cleanup, std::list<RsItem *>&saveList);
virtual bool saveList(bool &cleanup, std::list<RsItem *>&saveList) override;
/// @see p3Config::saveDone()
void saveDone();
void saveDone() override;
/// @see p3Config::loadList(std::list<RsItem *>&)
virtual bool loadList(std::list<RsItem *>& loadList);
virtual bool loadList(std::list<RsItem *>& loadList) override;
/// Request groups list to GXS backend. Async method.
bool requestGroupsData(const std::list<RsGxsGroupId>* groupIds = NULL);
@ -325,7 +327,7 @@ private:
// Overloaded from RsGenExchange.
bool acceptNewMessage(const RsGxsMsgMetaData *msgMeta, uint32_t size) ;
bool acceptNewMessage(const RsGxsMsgMetaData *msgMeta, uint32_t size) override;
GxsTransIntegrityCleanupThread *mCleanupThread ;

View File

@ -1130,12 +1130,14 @@ void p3GxsChannels::handleUnprocessedPost(const RsGxsChannelPost &msg)
// Overloaded from GxsTokenQueue for Request callbacks.
void p3GxsChannels::handleResponse(uint32_t token, uint32_t req_type)
void p3GxsChannels::handleResponse(uint32_t token, uint32_t req_type
, RsTokenService::GxsRequestStatus status)
{
#ifdef GXSCHANNELS_DEBUG
std::cerr << "p3GxsChannels::handleResponse(" << token << "," << req_type << ")";
std::cerr << std::endl;
std::cerr << "p3GxsChannels::handleResponse(" << token << "," << req_type << "," << status << ")" << std::endl;
#endif // GXSCHANNELS_DEBUG
if (status != RsTokenService::COMPLETE)
return; //For now, only manage Complete request
// stuff.
switch(req_type)

View File

@ -178,15 +178,15 @@ virtual bool getChannelDownloadDirectory(const RsGxsGroupId &groupId, std::strin
// Overloaded from RsGxsIface.
virtual bool subscribeToGroup(uint32_t &token, const RsGxsGroupId &groupId, bool subscribe);
virtual bool subscribeToGroup(uint32_t &token, const RsGxsGroupId &groupId, bool subscribe) override;
// Set Statuses.
virtual void setMessageProcessedStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool processed);
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read);
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) override;
// File Interface
virtual bool ExtraFileHash(const std::string& path);
virtual bool ExtraFileRemove(const RsFileHash &hash);
virtual bool ExtraFileHash(const std::string& path) override;
virtual bool ExtraFileRemove(const RsFileHash &hash) override;
/// Implementation of @see RsGxsChannels::getChannelsSummaries
@ -277,7 +277,7 @@ virtual bool ExtraFileRemove(const RsFileHash &hash);
bool subscribe ) override;
/// @see RsGxsChannels
virtual bool markRead(const RsGxsGrpMsgIdPair& msgId, bool read);
virtual bool markRead(const RsGxsGrpMsgIdPair& msgId, bool read) override;
/// @see RsGxsChannels
bool exportChannelLink(
@ -295,7 +295,7 @@ virtual bool ExtraFileRemove(const RsFileHash &hash);
) override;
virtual bool shareChannelKeys(
const RsGxsGroupId& channelId, const std::set<RsPeerId>& peers );
const RsGxsGroupId& channelId, const std::set<RsPeerId>& peers ) override;
/// Implementation of @see RsGxsChannels::createChannel
RS_DEPRECATED_FOR(createChannelV2)
@ -316,7 +316,8 @@ virtual bool ExtraFileRemove(const RsFileHash &hash);
protected:
// Overloaded from GxsTokenQueue for Request callbacks.
virtual void handleResponse(uint32_t token, uint32_t req_type);
virtual void handleResponse(uint32_t token, uint32_t req_type
, RsTokenService::GxsRequestStatus status) override;
private:

View File

@ -585,7 +585,7 @@ void p3GxsCircles::notifyChanges(std::vector<RsGxsNotify *> &changes)
std::cerr << std::endl;
#endif
p3Notify *notify = RsServer::notify();
//p3Notify *notify = RsServer::notify();
std::set<RsGxsCircleId> circles_to_reload;
for(auto it = changes.begin(); it != changes.end(); ++it)
@ -1702,12 +1702,15 @@ bool p3GxsCircles::service_checkIfGroupIsStillUsed(const RsGxsGrpMetaData& meta)
//====================================================================================//
// 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
, RsTokenService::GxsRequestStatus status)
{
#ifdef DEBUG_CIRCLES
std::cerr << "p3GxsCircles::handleResponse(" << token << "," << req_type << ")";
std::cerr << std::endl;
std::cerr << "p3GxsCircles::handleResponse(" << token << "," << req_type << "," << status << ")" << std::endl;
#endif // DEBUG_CIRCLES
if (status != RsTokenService::COMPLETE)
return; //For now, only manage Complete request
// stuff.
switch(req_type)

View File

@ -318,7 +318,8 @@ protected:
virtual ServiceCreate_Return service_CreateGroup(RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& keySet) override;
// Overloaded from GxsTokenQueue for Request callbacks.
virtual void handleResponse(uint32_t token, uint32_t req_type) override;
virtual void handleResponse(uint32_t token, uint32_t req_type
, RsTokenService::GxsRequestStatus status) override;
// Overloaded from RsTickEvent.
virtual void handle_event(uint32_t event_type, const std::string &elabel) override;

View File

@ -199,7 +199,7 @@ bool p3GxsCommentService::getGxsCommentData(const uint32_t &token, std::vector<R
for(; mit != msgData.end(); ++mit)
{
RsGxsGroupId grpId = mit->first;
//RsGxsGroupId grpId = mit->first;
std::vector<RsGxsMsgItem*>& msgItems = mit->second;
std::vector<RsGxsMsgItem*>::iterator vit = msgItems.begin();
@ -697,12 +697,15 @@ bool p3GxsCommentService::acknowledgeVote(const uint32_t& token, RsGxsGrpMsgIdPa
// Overloaded from GxsTokenQueue for Request callbacks.
void p3GxsCommentService::handleResponse(uint32_t token, uint32_t req_type)
void p3GxsCommentService::handleResponse(uint32_t token, uint32_t req_type
, RsTokenService::GxsRequestStatus status)
{
#ifdef DEBUG_GXSCOMMON
std::cerr << "p3GxsCommentService::handleResponse(" << token << "," << req_type << ")";
std::cerr << std::endl;
std::cerr << "p3GxsCommentService::handleResponse(" << token << "," << req_type << "," << status << ")" << std::endl;
#endif
if (status != RsTokenService::COMPLETE)
return; //For now, only manage Complete request
// stuff.
switch(req_type)

View File

@ -82,7 +82,8 @@ static double calculateBestScore(int upVotes, int downVotes);
protected:
// Overloaded from GxsTokenQueue for Request callbacks.
virtual void handleResponse(uint32_t token, uint32_t req_type);
virtual void handleResponse(uint32_t token, uint32_t req_type
, RsTokenService::GxsRequestStatus status) override;
private:

View File

@ -151,27 +151,26 @@ RsIdentity* rsIdentity = nullptr;
/******************* Startup / Tick ******************************************/
/********************************************************************************/
p3IdService::p3IdService(
RsGeneralDataService *gds, RsNetworkExchangeService *nes,
PgpAuxUtils *pgpUtils ) :
RsGxsIdExchange( gds, nes, new RsGxsIdSerialiser(),
RS_SERVICE_GXS_TYPE_GXSID, idAuthenPolicy() ),
RsIdentity(static_cast<RsGxsIface&>(*this)), GxsTokenQueue(this),
RsTickEvent(), mKeyCache(GXSID_MAX_CACHE_SIZE, "GxsIdKeyCache"),
mIdMtx("p3IdService"), mNes(nes), mPgpUtils(pgpUtils)
p3IdService::p3IdService( RsGeneralDataService *gds
, RsNetworkExchangeService *nes
, PgpAuxUtils *pgpUtils )
: RsGxsIdExchange( gds, nes, new RsGxsIdSerialiser(),
RS_SERVICE_GXS_TYPE_GXSID, idAuthenPolicy() )
, RsIdentity(static_cast<RsGxsIface&>(*this))
, GxsTokenQueue(this), RsTickEvent(), p3Config()
, mKeyCache(GXSID_MAX_CACHE_SIZE, "GxsIdKeyCache")
, mBgSchedule_Active(false), mBgSchedule_Mode(0)
, mIdMtx("p3IdService"), mNes(nes), mPgpUtils(pgpUtils)
, mLastConfigUpdate(0), mOwnIdsLoaded(false)
, mAutoAddFriendsIdentitiesAsContacts(true) /*default*/
, mMaxKeepKeysBanned(MAX_KEEP_KEYS_BANNED_DEFAULT)
{
mBgSchedule_Mode = 0;
mBgSchedule_Active = false;
mLastKeyCleaningTime = time(NULL) - int(MAX_DELAY_BEFORE_CLEANING * 0.9) ;
mLastConfigUpdate = 0 ;
mOwnIdsLoaded = false ;
mAutoAddFriendsIdentitiesAsContacts = true; // default
mMaxKeepKeysBanned = MAX_KEEP_KEYS_BANNED_DEFAULT;
// Kick off Cache Testing, + Others.
RsTickEvent::schedule_now(GXSID_EVENT_CACHEOWNIDS);//First Thing to do
RsTickEvent::schedule_in(GXSID_EVENT_PGPHASH, PGPHASH_PERIOD);
RsTickEvent::schedule_in(GXSID_EVENT_REPUTATION, REPUTATION_PERIOD);
RsTickEvent::schedule_now(GXSID_EVENT_CACHEOWNIDS);
//RsTickEvent::schedule_in(GXSID_EVENT_CACHETEST, CACHETEST_PERIOD);
@ -4427,7 +4426,7 @@ void p3IdService::generateDummy_OwnIds()
/* grab all the gpg ids... and make some ids */
RsPgpId ownId = mPgpUtils->getPGPOwnId();
/*RsPgpId ownId = */mPgpUtils->getPGPOwnId();
#if 0
// generate some ownIds.
@ -4643,36 +4642,37 @@ void p3IdService::checkPeerForIdentities()
// 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
, RsTokenService::GxsRequestStatus status)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::handleResponse(" << token << "," << req_type << ")";
std::cerr << std::endl;
std::cerr << "p3IdService::handleResponse(" << token << "," << req_type << "," << status << ")" << std::endl;
#endif // DEBUG_IDS
// stuff.
switch(req_type)
{
case GXSIDREQ_CACHEOWNIDS:
cache_load_ownids(token);
if (status == RsTokenService::COMPLETE) cache_load_ownids(token);
if (status == RsTokenService::CANCELLED) RsTickEvent::schedule_now(GXSID_EVENT_CACHEOWNIDS);//Cancelled by time-out so ask a new time
break;
case GXSIDREQ_CACHELOAD:
cache_load_for_token(token);
if (status == RsTokenService::COMPLETE) cache_load_for_token(token);
break;
case GXSIDREQ_PGPHASH:
pgphash_handlerequest(token);
if (status == RsTokenService::COMPLETE) pgphash_handlerequest(token);
break;
case GXSIDREQ_RECOGN:
recogn_handlerequest(token);
if (status == RsTokenService::COMPLETE) recogn_handlerequest(token);
break;
case GXSIDREQ_CACHETEST:
cachetest_handlerequest(token);
if (status == RsTokenService::COMPLETE) cachetest_handlerequest(token);
break;
case GXSIDREQ_OPINION:
opinion_handlerequest(token);
if (status == RsTokenService::COMPLETE) opinion_handlerequest(token);
break;
case GXSIDREQ_SERIALIZE_TO_MEMORY:
handle_get_serialized_grp(token);
if (status == RsTokenService::COMPLETE) handle_get_serialized_grp(token);
break;
default:
std::cerr << "p3IdService::handleResponse() Unknown Request Type: "

View File

@ -408,7 +408,8 @@ protected:
virtual bool acceptNewGroup(const RsGxsGrpMetaData *grpMeta) override ;
// Overloaded from GxsTokenQueue for Request callbacks.
virtual void handleResponse(uint32_t token, uint32_t req_type) override;
virtual void handleResponse(uint32_t token, uint32_t req_type
, RsTokenService::GxsRequestStatus status) override;
// Overloaded from RsTickEvent.
virtual void handle_event(uint32_t event_type, const std::string &elabel) override;
@ -561,7 +562,7 @@ private:
void cleanUnusedKeys() ;
void slowIndicateConfigChanged() ;
virtual void timeStampKey(const RsGxsId& id, const RsIdentityUsage& reason) ;
virtual void timeStampKey(const RsGxsId& id, const RsIdentityUsage& reason) override;
rstime_t locked_getLastUsageTS(const RsGxsId& gxs_id);
std::string genRandomId(int len = 20);

View File

@ -849,12 +849,14 @@ bool p3PostBase::background_cleanup()
// Overloaded from GxsTokenQueue for Request callbacks.
void p3PostBase::handleResponse(uint32_t token, uint32_t req_type)
void p3PostBase::handleResponse(uint32_t token, uint32_t req_type
, RsTokenService::GxsRequestStatus status)
{
#ifdef POSTBASE_DEBUG
std::cerr << "p3PostBase::handleResponse(" << token << "," << req_type << ")";
std::cerr << std::endl;
std::cerr << "p3PostBase::handleResponse(" << token << "," << req_type << "," << status << ")" << std::endl;
#endif
if (status != RsTokenService::COMPLETE)
return; //For now, only manage Complete request
// stuff.
switch(req_type)

View File

@ -77,7 +77,8 @@ protected:
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes) override;
// Overloaded from GxsTokenQueue for Request callbacks.
virtual void handleResponse(uint32_t token, uint32_t req_type) override;
virtual void handleResponse(uint32_t token, uint32_t req_type
, RsTokenService::GxsRequestStatus status) override;
// Overloaded from RsTickEvent.
virtual void handle_event(uint32_t event_type, const std::string &elabel) override;