mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
removed waitToken from GxsTokenService since it was only used directly by rsGenExchange to export keys
This commit is contained in:
parent
5408427ea8
commit
676ddfbfb5
@ -3461,20 +3461,32 @@ bool RsGenExchange::exportGroupBase64(
|
|||||||
|
|
||||||
if(groupId.isNull()) return failure("groupId cannot be null");
|
if(groupId.isNull()) return failure("groupId cannot be null");
|
||||||
|
|
||||||
|
// We have no blocking API here, so we need to
|
||||||
const std::list<RsGxsGroupId> groupIds({groupId});
|
const std::list<RsGxsGroupId> groupIds({groupId});
|
||||||
RsTokReqOptions opts;
|
RsTokReqOptions opts;
|
||||||
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
|
||||||
uint32_t token;
|
uint32_t token;
|
||||||
mDataAccess->requestGroupInfo(
|
mDataAccess->requestGroupInfo( token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds);
|
||||||
token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds);
|
|
||||||
RsTokenService::GxsRequestStatus wtStatus = mDataAccess->waitToken(token);
|
// provide a sync response: actually wait for the token.
|
||||||
if(wtStatus != RsTokenService::COMPLETE)
|
std::chrono::milliseconds maxWait = std::chrono::milliseconds(10000);
|
||||||
return failure( "waitToken(...) failed with: " +
|
std::chrono::milliseconds checkEvery = std::chrono::milliseconds(100);
|
||||||
std::to_string(wtStatus) );
|
|
||||||
|
auto timeout = std::chrono::steady_clock::now() + maxWait; // wait for 10 secs at most
|
||||||
|
auto st = mDataAccess->requestStatus(token);
|
||||||
|
|
||||||
|
while( !(st == RsTokenService::FAILED || st >= RsTokenService::COMPLETE) && std::chrono::steady_clock::now() < timeout )
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(checkEvery);
|
||||||
|
st = mDataAccess->requestStatus(token);
|
||||||
|
}
|
||||||
|
if(st != RsTokenService::COMPLETE)
|
||||||
|
return failure( "waitToken(...) failed with: " + std::to_string(st) );
|
||||||
|
|
||||||
uint8_t* buf = nullptr;
|
uint8_t* buf = nullptr;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
RsGxsGroupId grpId;
|
RsGxsGroupId grpId;
|
||||||
|
|
||||||
if(!getSerializedGroupData(token, grpId, buf, size))
|
if(!getSerializedGroupData(token, grpId, buf, size))
|
||||||
return failure("failed retrieving GXS data");
|
return failure("failed retrieving GXS data");
|
||||||
|
|
||||||
|
@ -390,20 +390,55 @@ protected:
|
|||||||
RsTokenService::GxsRequestStatus waitToken(
|
RsTokenService::GxsRequestStatus waitToken(
|
||||||
uint32_t token,
|
uint32_t token,
|
||||||
std::chrono::milliseconds maxWait = std::chrono::milliseconds(10000),
|
std::chrono::milliseconds maxWait = std::chrono::milliseconds(10000),
|
||||||
std::chrono::milliseconds checkEvery = std::chrono::milliseconds(20),
|
std::chrono::milliseconds checkEvery = std::chrono::milliseconds(100),
|
||||||
bool auto_delete_if_unsuccessful=true)
|
bool auto_delete_if_unsuccessful=true)
|
||||||
{
|
{
|
||||||
RsTokenService::GxsRequestStatus res = mTokenService.waitToken(token, maxWait, checkEvery);
|
#if defined(__ANDROID__) && (__ANDROID_API__ < 24)
|
||||||
|
auto wkStartime = std::chrono::steady_clock::now();
|
||||||
|
int maxWorkAroundCnt = 10;
|
||||||
|
LLwaitTokenBeginLabel:
|
||||||
|
#endif
|
||||||
|
auto timeout = std::chrono::steady_clock::now() + maxWait;
|
||||||
|
auto st = requestStatus(token);
|
||||||
|
|
||||||
if(res != RsTokenService::COMPLETE && auto_delete_if_unsuccessful)
|
while( !(st == RsTokenService::FAILED || st >= RsTokenService::COMPLETE) && std::chrono::steady_clock::now() < timeout )
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(checkEvery);
|
||||||
|
st = requestStatus(token);
|
||||||
|
}
|
||||||
|
if(st != RsTokenService::COMPLETE && auto_delete_if_unsuccessful)
|
||||||
cancelRequest(token);
|
cancelRequest(token);
|
||||||
else
|
|
||||||
{
|
#if defined(__ANDROID__) && (__ANDROID_API__ < 24)
|
||||||
|
/* Work around for very slow/old android devices, we don't expect this
|
||||||
|
* to be necessary on newer devices. If it take unreasonably long
|
||||||
|
* something worser is already happening elsewere and we return anyway.
|
||||||
|
*/
|
||||||
|
if( st > RsTokenService::FAILED && st < RsTokenService::COMPLETE
|
||||||
|
&& maxWorkAroundCnt-- > 0 )
|
||||||
|
{
|
||||||
|
maxWait *= 10;
|
||||||
|
checkEvery *= 3;
|
||||||
|
Dbg3() << __PRETTY_FUNCTION__ << " Slow Android device "
|
||||||
|
<< " workaround st: " << st
|
||||||
|
<< " maxWorkAroundCnt: " << maxWorkAroundCnt
|
||||||
|
<< " maxWait: " << maxWait.count()
|
||||||
|
<< " checkEvery: " << checkEvery.count() << std::endl;
|
||||||
|
goto LLwaitTokenBeginLabel;
|
||||||
|
}
|
||||||
|
Dbg3() << __PRETTY_FUNCTION__ << " lasted: "
|
||||||
|
<< std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||||
|
std::chrono::steady_clock::now() - wkStartime ).count()
|
||||||
|
<< "ms" << std::endl;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
{
|
||||||
RS_STACK_MUTEX(mMtx);
|
RS_STACK_MUTEX(mMtx);
|
||||||
mActiveTokens.erase(token);
|
mActiveTokens.erase(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -222,6 +222,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual bool cancelRequest(const uint32_t &token) = 0;
|
virtual bool cancelRequest(const uint32_t &token) = 0;
|
||||||
|
|
||||||
|
#ifdef TO_REMOVE
|
||||||
/**
|
/**
|
||||||
* Block caller while request is being processed.
|
* Block caller while request is being processed.
|
||||||
* Useful for blocking API implementation.
|
* Useful for blocking API implementation.
|
||||||
@ -231,8 +232,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
RsTokenService::GxsRequestStatus waitToken(
|
RsTokenService::GxsRequestStatus waitToken(
|
||||||
uint32_t token,
|
uint32_t token,
|
||||||
std::chrono::milliseconds maxWait = std::chrono::milliseconds(500),
|
std::chrono::milliseconds maxWait = std::chrono::milliseconds(10000),
|
||||||
std::chrono::milliseconds checkEvery = std::chrono::milliseconds(2),
|
std::chrono::milliseconds checkEvery = std::chrono::milliseconds(20),
|
||||||
bool auto_delete_if_unsuccessful=true)
|
bool auto_delete_if_unsuccessful=true)
|
||||||
{
|
{
|
||||||
#if defined(__ANDROID__) && (__ANDROID_API__ < 24)
|
#if defined(__ANDROID__) && (__ANDROID_API__ < 24)
|
||||||
@ -276,6 +277,7 @@ LLwaitTokenBeginLabel:
|
|||||||
|
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
RS_SET_CONTEXT_DEBUG_LEVEL(2)
|
RS_SET_CONTEXT_DEBUG_LEVEL(2)
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user