[tor-commits] [atlas/master] Don't pretend to be busy forever if a relay doesn't exist.

karsten at torproject.org karsten at torproject.org
Fri Jan 11 10:09:47 UTC 2013


commit 341032e6df12ec75b3ff490bda8ed16f8746f62d
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Tue Dec 4 15:37:33 2012 +0100

    Don't pretend to be busy forever if a relay doesn't exist.
    
    Fixes #5832.
---
 js/models/relay.js          |   50 +++++++++++++++++++++++-------------------
 js/router.js                |    5 ++++
 js/views/details/main.js    |    5 ++++
 templates/details/main.html |    7 ++++++
 4 files changed, 44 insertions(+), 23 deletions(-)

diff --git a/js/models/relay.js b/js/models/relay.js
index 326e378..3c686fd 100644
--- a/js/models/relay.js
+++ b/js/models/relay.js
@@ -132,29 +132,33 @@ define([
             var model = this;
             console.log("doing query..");
             $.getJSON(this.baseurl+'/details?lookup='+this.fingerprint, function(data) {
-                var relay = data.relays[0];
-                //console.log(data);
-                var bw = relay.advertised_bandwidth;
-                relay.bandwidth = bw;
-                relay.family = relay.family ? relay.family : null;
-                relay.bandwidth_hr = hrBandwidth(bw);
-                relay.or_address = relay.or_addresses ? relay.or_addresses[0].split(":")[0] : null;
-                relay.or_port = relay.or_addresses ? relay.or_addresses[0].split(":")[1] : 0;
-                relay.dir_port = relay.dir_address ? relay.dir_address.split(":")[1] : 0;
-                relay.country = relay.country ? relay.country.toLowerCase() : null;
-                relay.countryname = relay.country ? CountryCodes[relay.country] : null;
-                relay.uptime = model.parsedate(relay.last_restarted);
-                relay.uptime_hr = relay.uptime.hr;
-                relay.as_no = relay.as_number;
-                relay.as_name = relay.as_name;
-                model.set({badexit: false});
-                //console.log(relay.uptime.hrfull);
-                relay.uptime_hrfull = relay.uptime.hrfull;
-                relay.uptime = relay.uptime.millisecs;
-                var size = ['16x16', '14x16', '8x16'];
-                relay.flags = model.parseflags(relay.flags, size);
-                model.set(relay, options);
-                success(model, relay);
+                if (data.relays.length >= 1) {
+                    var relay = data.relays[0];
+                    //console.log(data);
+                    var bw = relay.advertised_bandwidth;
+                    relay.bandwidth = bw;
+                    relay.family = relay.family ? relay.family : null;
+                    relay.bandwidth_hr = hrBandwidth(bw);
+                    relay.or_address = relay.or_addresses ? relay.or_addresses[0].split(":")[0] : null;
+                    relay.or_port = relay.or_addresses ? relay.or_addresses[0].split(":")[1] : 0;
+                    relay.dir_port = relay.dir_address ? relay.dir_address.split(":")[1] : 0;
+                    relay.country = relay.country ? relay.country.toLowerCase() : null;
+                    relay.countryname = relay.country ? CountryCodes[relay.country] : null;
+                    relay.uptime = model.parsedate(relay.last_restarted);
+                    relay.uptime_hr = relay.uptime.hr;
+                    relay.as_no = relay.as_number;
+                    relay.as_name = relay.as_name;
+                    model.set({badexit: false});
+                    //console.log(relay.uptime.hrfull);
+                    relay.uptime_hrfull = relay.uptime.hrfull;
+                    relay.uptime = relay.uptime.millisecs;
+                    var size = ['16x16', '14x16', '8x16'];
+                    relay.flags = model.parseflags(relay.flags, size);
+                    model.set(relay, options);
+                    success(model, relay);
+                } else {
+                    error(model)
+                }
             }).error(function() {console.log("error...");error();});
         }
 
diff --git a/js/router.js b/js/router.js
index 3fd4a8b..feb97ed 100644
--- a/js/router.js
+++ b/js/router.js
@@ -33,6 +33,11 @@ define([
     	        mainDetailsView.render();
                 $("#loading").hide();
 
+            },
+            error: function() {
+                $("#content").show();
+                mainDetailsView.error();
+                $("#loading").hide();
             }
         });
     },
diff --git a/js/views/details/main.js b/js/views/details/main.js
index e09da3e..c1c0b11 100644
--- a/js/views/details/main.js
+++ b/js/views/details/main.js
@@ -180,6 +180,11 @@ define([
                 $(this).children(".tooltip").hide();
 
             });
+        },
+        error: function() {
+            var compiledTemplate = _.template(mainDetailsTemplate, {relay: null});
+            $("#loading").hide();
+            this.el.html(compiledTemplate);
         }
     });
     return new mainDetailsView;
diff --git a/templates/details/main.html b/templates/details/main.html
index b8b5421..38f890f 100644
--- a/templates/details/main.html
+++ b/templates/details/main.html
@@ -1,3 +1,9 @@
+<% if(relay == null) {%>
+    <div class="alert">
+        <strong>No Results found!</strong><p>
+    No Tor bridges or relays matched your query :(</p>
+    </div>
+<% } else { %>
 <h1>Details for: <span id="relay_name"><%= relay.get('nickname') %></span></h1>
 <!-- div class="subnav">
     <ul class="nav nav-pills">
@@ -286,5 +292,6 @@
 <hr/>
 </div>
 -->
+<% } %>
 
 





More information about the tor-commits mailing list