Closed Bug 1329558 Opened 4 years ago Closed 4 years ago

Implement Minimum wait duration for V4 gethash


(Toolkit :: Safe Browsing, defect, P2)




Tracking Status
firefox54 --- fixed


(Reporter: dimi, Assigned: tnguyen)



(Whiteboard: #sbv4-m5)


(1 file, 1 obsolete file)

Minimum wait duration is described in

This value specifies how long update or gethash request should wait until next request could be made.
Hi Henry,
I just checked the code and i guess we have not yet implemented this for v4 update, is it correct ?
If we haven't implement this for update, do you think we should do it before "Enable update v4 on nightly" ?
Flags: needinfo?(hchang)
offline checked with henry, this is already implemented for update.
So the only thing left here is to also support it in gethash
Flags: needinfo?(hchang)
Whiteboard: #sbv4-m5
Priority: -- → P2
Summary: Implement Minimum wait duration for V4 → Implement Minimum wait duration for V4 gethash
Blocks: 1276826
No longer blocks: safebrowsingv4
Blocks: 1329808
No longer blocks: 1276826
Assignee: nobody → tnguyen
I am looking at this. I think we will not care about the case that we are going to restart FF (the minimum wait duration we get in the last running FF will be reset to 0). 
Otherwise, we may need to save the last gethash time, min wait duration (probably to Prefs or database). Taking a glance at chromium code and they ignored that. The minimum wait duration normally is rather small and may not have to many effects.
Attached patch WIP (obsolete) — Splinter Review
Comment on attachment 8834757 [details]
Bug 1329558 - Implement Minimum wait duration for V4 gethash

::: toolkit/components/url-classifier/tests/unit/test_hashcompleter_v4.js:57
(Diff revision 1)
>  // Handles request for TEST_TABLE_DATA_V4.
>  let gHttpServV4 = null;
> -let gExpectedGetHashQueryV4 = "";
> -const NEW_CLIENT_STATE = 'sta\0te';
> -const CHECKSUM = '\x30\x67\xc7\x2c\x5e\x50\x1c\x31\xe3\xfe\xca\x73\xf0\x47\xdc\x34\x1a\x95\x63\x99\xec\x70\x5e\x0a\xee\x9e\xfb\x17\xa1\x55\x35\x78';
> +const NEW_CLIENT_STATE = "sta\0te";
> +const CHECKSUM = "\x30\x67\xc7\x2c\x5e\x50\x1c\x31\xe3\xfe\xca\x73\xf0\x47\xdc\x34\x1a\x95\x63\x99\xec\x70\x5e\x0a\xee\x9e\xfb\x17\xa1\x55\x35\x78";

Eliminate warning from eslint

::: toolkit/components/url-classifier/tests/unit/test_hashcompleter_v4.js:93
(Diff revision 1)
> -  gExpectedGetHashQueryV4 = '&$req=' + request;
> +  registerHandlerGethashV4("&$req=" + request);
> -
>    let completeFinishedCnt = 0;
>    gCompleter.complete("0123", TEST_TABLE_DATA_V4.gethashUrl, TEST_TABLE_DATA_V4.tableName, {
> -    completion: function (hash, table, chunkId) {
> +    completion(hash, table, chunkId) {

Attachment #8827836 - Attachment is obsolete: true
Comment on attachment 8834757 [details]
Bug 1329558 - Implement Minimum wait duration for V4 gethash

Good patch. I've got a few comments around validation of the results from Google and making the units clearer.

::: toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js:169
(Diff revision 1)
>    // Whether we have been informed of a shutdown by the shutdown event.
>    this._shuttingDown = false;
> +  // A map of getHash URLs to next gethash time
> +  this._nextGethashTimes = {};

This is in milliseconds, right?

Let's call this `_nextGethashTimeMs` to make the unit explicit.

::: toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js:270
(Diff revision 1)
>    },
>    // Returns true if we can make a request from the given url, false otherwise.
>    canMakeRequest: function(aGethashUrl) {
> -    return this._backoffs[aGethashUrl].canMakeRequest();
> +    return this._backoffs[aGethashUrl].canMakeRequest() &&
> +  > this._nextGethashTimes[aGethashUrl];

This should probably be `>=`.

::: toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js:571
(Diff revision 1)
>          log("V4 fullhash response parsed callback: " +
>              "MinWaitDuration(" + aMinWaitDuration + "), " +
>              "NegativeCacheDuration(" + aNegCacheDuration + ")");
> +        this._completer._nextGethashTimes[this.gethashUrl] =
> + + aMinWaitDuration;

We should put a limit on how big `aMinWaitDuration` could be. Maybe a maximum of 24 hours [like for updates](

Also, we should make sure `aMinWaitDuration >= 0` too in case we receive a negative number.
Attachment #8834757 - Flags: review?(francois) → review-
Thanks for your review
Comment on attachment 8834757 [details]
Bug 1329558 - Implement Minimum wait duration for V4 gethash

Could you also please add the following fix to your patch: [DurationToMs() incorrectly converts nanoseconds to microseconds instead of milliseconds](

We can fix it by just looking at the seconds and ignoring the nanoseconds.

We should also have the following comment above that line:

    // Seconds precision is good enough. Ignore nanoseconds like Chrome does.

After that, we should make sure the tests still pass because we might be relying on this buggy behaviour.
Attachment #8834757 - Flags: review?(francois) → review-
Comment on attachment 8834757 [details]
Bug 1329558 - Implement Minimum wait duration for V4 gethash
Attachment #8834757 - Flags: review?(francois) → review+
Keywords: checkin-needed
Pushed by
Implement Minimum wait duration for V4 gethash r=francois
Keywords: checkin-needed
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla54
You need to log in before you can comment on or make changes to this bug.