bug 1441391 - TRR: restart failed NS confirms in TRR-only mode r=valentin

MozReview-Commit-ID: FHw3Zx07iFG

--HG--
extra : rebase_source : 55a09920127aa54e542ed736b92ca6fda63f889c
This commit is contained in:
Daniel Stenberg 2018-03-09 09:05:48 +01:00
parent 52b78d5be4
commit f0caae2f7c
3 changed files with 44 additions and 2 deletions

View File

@ -46,7 +46,6 @@ NS_IMETHODIMP
TRR::Notify(nsITimer *aTimer)
{
if (aTimer == mTimeout) {
LOG(("TRR request for %s timed out\n", mHost.get()));
mTimeout = nullptr;
Cancel();
} else {

View File

@ -44,6 +44,7 @@ TRRService::TRRService()
, mUseGET(false)
, mClearTRRBLStorage(false)
, mConfirmationState(CONFIRM_INIT)
, mRetryConfirmInterval(1000)
{
MOZ_ASSERT(NS_IsMainThread(), "wrong thread");
}
@ -83,13 +84,19 @@ bool
TRRService::Enabled()
{
if (mConfirmationState == CONFIRM_INIT && !mWaitForCaptive) {
LOG(("TRRService::Enabled => CONFIRM_TRYING\n"));
mConfirmationState = CONFIRM_TRYING;
}
if (mConfirmationState == CONFIRM_TRYING) {
LOG(("TRRService::Enabled MaybeConfirm()\n"));
MaybeConfirm();
}
if (mConfirmationState != CONFIRM_OK) {
LOG(("TRRService::Enabled mConfirmationState=%d\n", (int)mConfirmationState));
}
return (mConfirmationState == CONFIRM_OK);
}
@ -290,6 +297,8 @@ TRRService::MaybeConfirm()
{
if ((mMode == MODE_NATIVEONLY) || mConfirmer ||
mConfirmationState != CONFIRM_TRYING) {
LOG(("TRRService:MaybeConfirm mode=%d, mConfirmer=%p mConfirmationState=%d\n",
(int)mMode, (void *)mConfirmer, (int)mConfirmationState));
return;
}
nsAutoCString host;
@ -478,6 +487,24 @@ TRRService::TRRBlacklist(const nsACString &aHost, bool privateBrowsing, bool aPa
}
}
NS_IMETHODIMP
TRRService::Notify(nsITimer *aTimer)
{
if (aTimer == mRetryConfirmTimer) {
mRetryConfirmTimer = nullptr;
if (mConfirmationState == CONFIRM_FAILED) {
LOG(("TRRService retry NS of %s\n", mConfirmationNS.get()));
mConfirmationState = CONFIRM_TRYING;
MaybeConfirm();
}
} else {
MOZ_CRASH("Unknown timer");
}
return NS_OK;
}
AHostResolver::LookupStatus
TRRService::CompleteLookup(nsHostRecord *rec, nsresult status, AddrInfo *aNewRRSet, bool pb)
{
@ -496,6 +523,18 @@ TRRService::CompleteLookup(nsHostRecord *rec, nsresult status, AddrInfo *aNewRRS
LOG(("TRRService finishing confirmation test %s %d %X\n",
mPrivateURI.get(), (int)mConfirmationState, (unsigned int)status));
mConfirmer = nullptr;
if ((mConfirmationState == CONFIRM_FAILED) && (mMode == MODE_TRRONLY)) {
// in TRR-only mode; retry failed confirmations
NS_NewTimerWithCallback(getter_AddRefs(mRetryConfirmTimer),
this, mRetryConfirmInterval,
nsITimer::TYPE_ONE_SHOT);
if (mRetryConfirmInterval < 64000) {
// double the interval up to this point
mRetryConfirmInterval *= 2;
}
} else {
mRetryConfirmInterval = 1000;
}
return LOOKUP_OK;
}

View File

@ -19,12 +19,14 @@ namespace net {
class TRRService
: public nsIObserver
, public nsITimerCallback
, public nsSupportsWeakReference
, public AHostResolver
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_NSITIMERCALLBACK
TRRService();
nsresult Init();
@ -79,7 +81,9 @@ private:
CONFIRM_FAILED = 3
};
Atomic<ConfirmationState, Relaxed> mConfirmationState;
RefPtr<TRR> mConfirmer;
RefPtr<TRR> mConfirmer;
nsCOMPtr<nsITimer> mRetryConfirmTimer;
uint32_t mRetryConfirmInterval; // milliseconds until retry
};
extern TRRService *gTRRService;