[epiphany/wip/google-safe-browsing: 16/18] gsb-service: Handle min wait duration in fullHashes:find requests
- From: Gabriel Ivașcu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/google-safe-browsing: 16/18] gsb-service: Handle min wait duration in fullHashes:find requests
- Date: Tue, 19 Sep 2017 16:31:49 +0000 (UTC)
commit b0b1492624f6d85ac0f9737b25a9003a795974ee
Author: Gabriel Ivascu <gabrielivascu gnome org>
Date: Tue Sep 19 14:05:00 2017 +0300
gsb-service: Handle min wait duration in fullHashes:find requests
lib/safe-browsing/ephy-gsb-service.c | 24 ++++++++++++++++++++----
1 files changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/lib/safe-browsing/ephy-gsb-service.c b/lib/safe-browsing/ephy-gsb-service.c
index d5b0579..1c2fad9 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -39,8 +39,12 @@ struct _EphyGSBService {
char *api_key;
EphyGSBStorage *storage;
+
gboolean is_updating;
guint source_id;
+
+ gint64 next_full_hashes_time;
+
SoupSession *session;
};
@@ -465,7 +469,7 @@ ephy_gsb_service_find_full_hashes_cb (SoupSession *session,
JsonArray *matches;
GList *hashes_lookup = NULL;
GError *error = NULL;
- const char *negative_duration;
+ const char *duration_str;
double duration;
if (msg->status_code != 200) {
@@ -519,15 +523,20 @@ ephy_gsb_service_find_full_hashes_cb (SoupSession *session,
}
/* Update negative cache duration. */
- negative_duration = json_object_get_string_member (body_obj, "negativeCacheDuration");
- sscanf (negative_duration, "%lfs", &duration);
+ duration_str = json_object_get_string_member (body_obj, "negativeCacheDuration");
+ sscanf (duration_str, "%lfs", &duration);
for (GList *l = data->matching_prefixes; l && l->data; l = l->next) {
ephy_gsb_storage_update_hash_prefix_expiration (data->service->storage,
l->data,
floor (duration));
}
- /* TODO: Handle minimumWaitDuration. */
+ /* Handle minimum wait duration. */
+ if (json_object_has_non_null_string_member (body_obj, "minimumWaitDuration")) {
+ duration_str = json_object_get_string_member (body_obj, "minimumWaitDuration");
+ sscanf (duration_str, "%lfs", &duration);
+ data->service->next_full_hashes_time = CURRENT_TIME + (gint64)ceil (duration);
+ }
/* Repeat the full hash verification. */
hashes_lookup = ephy_gsb_storage_lookup_full_hashes (data->service->storage,
@@ -577,6 +586,13 @@ ephy_gsb_service_find_full_hashes (EphyGSBService *self,
g_assert (matching_hashes);
g_assert (callback);
+ if (CURRENT_TIME < self->next_full_hashes_time) {
+ LOG ("Cannot send fullHashes:find request. Requests are restricted for %ld seconds",
+ self->next_full_hashes_time - CURRENT_TIME);
+ callback (threats, user_data);
+ return;
+ }
+
threat_lists = ephy_gsb_storage_get_threat_lists (self->storage);
if (!threat_lists) {
callback (threats, user_data);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]