[tor-commits] [atlas/master] Show a warning message if Onionoo serves outdated data

irl at torproject.org irl at torproject.org
Wed Mar 1 17:06:04 UTC 2017


commit daf6bea6453901e47f3d9d98241ceb79af165f22
Author: Raphael Bergmann <raphael at cc-ltd.net>
Date:   Wed Feb 1 14:04:34 2017 +0100

    Show a warning message if Onionoo serves outdated data
---
 css/style.css             |  5 +++++
 js/collections/results.js |  1 +
 js/helpers.js             | 10 ++++++++++
 js/models/graph.js        |  9 ++++++---
 js/models/relay.js        |  3 ++-
 5 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/css/style.css b/css/style.css
index 3c67c24..c458f86 100644
--- a/css/style.css
+++ b/css/style.css
@@ -66,3 +66,8 @@ span.flags img {
 .tooltip * {
     text-align:left;
 }
+
+#outdatedData > div {
+    position:relative;
+    top:60px;
+}
diff --git a/js/collections/results.js b/js/collections/results.js
index 4473e1a..13cf7ac 100644
--- a/js/collections/results.js
+++ b/js/collections/results.js
@@ -15,6 +15,7 @@ define([
             var err = 0;
             var collection = this;
             options.success = $.getJSON(this.url, function(response) {
+                checkIfDataIsUpToDate(options.success.getResponseHeader("Last-Modified"));
                 this.fresh_until = response.fresh_until;
                 this.valid_after = response.valid_after;
                 var relays = [];
diff --git a/js/helpers.js b/js/helpers.js
index 48e1102..8838db8 100644
--- a/js/helpers.js
+++ b/js/helpers.js
@@ -262,3 +262,13 @@ function hrBandwidth(bw) {
     }
     return bw;
 }
+
+function checkIfDataIsUpToDate(lastModifiedHeader) {
+    // check if onionoo document is up to date:
+    var lastModified = new Date(Date.parse(lastModifiedHeader));
+    var currentTime = new Date();
+    var hoursSinceLastUpdate =  (currentTime.getTime() - lastModified.getTime()) / (1000 * 60 * 60);
+    if (hoursSinceLastUpdate > 24 && $("#outdatedData").length==0) {
+        $('<div class="container" id="outdatedData"><div class="alert"><strong>Outdated data!</strong><p>Onionoo seems to serve outdated data :( Last update was: '+lastModified+'</p></div></div>').insertAfter("body > .navbar");
+    }
+}
diff --git a/js/models/graph.js b/js/models/graph.js
index d4368a4..ca36d48 100644
--- a/js/models/graph.js
+++ b/js/models/graph.js
@@ -114,7 +114,8 @@ define([
                 bw_years: {write: [], read: []}
             });
 
-            $.getJSON(this.baseurl+'/bandwidth?lookup='+fingerprint, function(data) {
+            var xhr = $.getJSON(this.baseurl+'/bandwidth?lookup='+fingerprint, function(data) {
+                checkIfDataIsUpToDate(xhr.getResponseHeader("Last-Modified"));
                 model.data = data;
                 success(model, data);
             });
@@ -143,7 +144,8 @@ define([
                 weights_years: {cw: [], guard: [], middle: [], exit: []}
             });
 
-            $.getJSON(this.baseurl+'/weights?lookup='+fingerprint, function(data) {
+            var xhr = $.getJSON(this.baseurl+'/weights?lookup='+fingerprint, function(data) {
+                checkIfDataIsUpToDate(xhr.getResponseHeader("Last-Modified"));
                 model.data = data;
                 success(model, data);
             });
@@ -187,7 +189,8 @@ define([
                 clients_years: {average: []}
             });
 
-            $.getJSON(this.baseurl+'/clients?lookup='+fingerprint, function(data) {
+            var xhr = $.getJSON(this.baseurl+'/clients?lookup='+fingerprint, function(data) {
+                checkIfDataIsUpToDate(xhr.getResponseHeader("Last-Modified"));
                 model.data = data;
                 success(model, data);
             });
diff --git a/js/models/relay.js b/js/models/relay.js
index e374ae4..c0c1a84 100644
--- a/js/models/relay.js
+++ b/js/models/relay.js
@@ -136,7 +136,8 @@ define([
             var error = options.error;
             var model = this;
             console.log("doing query..");
-            $.getJSON(this.baseurl+'/details?lookup='+this.fingerprint, function(data) {
+            var xhr = $.getJSON(this.baseurl+'/details?lookup='+this.fingerprint, function(data) {
+                checkIfDataIsUpToDate(xhr.getResponseHeader("Last-Modified"));
                 var relay = null;
                 if (data.relays.length >= 1) {
                     relay = data.relays[0];





More information about the tor-commits mailing list