[tor-commits] [atlas/master] Add support for handling bridges in addition to relays

phw at torproject.org phw at torproject.org
Mon Jul 21 17:47:29 UTC 2014


commit 89e0e18e6f1482796abfa18ebf6f2be8b2cfeff9
Author: Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>
Date:   Thu Jul 3 01:06:43 2014 +0400

    Add support for handling bridges in addition to relays
    
    Onionoo provides information about bridges in nearly the same way as it
    does for relays. So this commit extends relay model with two more
    properties and adds bridges to the list of relays for processing.
    
    Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov at gmail.com>
---
 js/collections/results.js |    7 ++++++-
 js/models/graph.js        |    4 ++++
 js/models/relay.js        |   20 +++++++++++++++++++-
 js/views/details/main.js  |   40 +++++++++++++++++++++-------------------
 4 files changed, 50 insertions(+), 21 deletions(-)

diff --git a/js/collections/results.js b/js/collections/results.js
index a588272..e618614 100644
--- a/js/collections/results.js
+++ b/js/collections/results.js
@@ -26,6 +26,11 @@ define([
                     crelay.fingerprint = relay.f;
                     relays.push(crelay);
                 });
+                _.each(response.bridges, function(relay, resultsC) {
+                    crelay = new relayModel;
+                    crelay.fingerprint = relay.h;
+                    relays.push(crelay);
+                });
                 if (relays.length == 0) {
                     error(0);
                     console.log('error');
@@ -37,7 +42,7 @@ define([
                 _.each(relays, function(relay) {
                     relay.lookup({
                         success: function(){
-                            if (relays.length == response.relays.length) {
+                            if (relays.length == response.relays.length + response.bridges.length) {
                                 collection[options.add ? 'add' : 'reset'](relays, options);
                                 success(collection, relays);
                                 return relays;
diff --git a/js/models/graph.js b/js/models/graph.js
index ed2601c..33afea9 100644
--- a/js/models/graph.js
+++ b/js/models/graph.js
@@ -98,6 +98,8 @@ define([
         parse_bw_data: function(data) {
             var model = this;
             var relay = data.relays[0];
+            if (!relay)
+                relay = data.bridges[0];
             this.fingerprint = relay.fingerprint;
             // Parse the read and write history of the relay
             var write_history = parseHistory(relay.write_history, model, relay, 'write');
@@ -125,6 +127,8 @@ define([
         parse_weights_data: function(data) {
             var model = this;
             var relay = data.relays[0];
+            if (!relay)
+                relay = data.bridges[0];
             this.fingerprint = relay.fingerprint;
 
             if ("advertised_bandwidth_fraction" in relay) {
diff --git a/js/models/relay.js b/js/models/relay.js
index d31f2ad..1cf7783 100644
--- a/js/models/relay.js
+++ b/js/models/relay.js
@@ -132,8 +132,15 @@ define([
             var model = this;
             console.log("doing query..");
             $.getJSON(this.baseurl+'/details?lookup='+this.fingerprint, function(data) {
+                var relay = null;
                 if (data.relays.length >= 1) {
-                    var relay = data.relays[0];
+                    relay = data.relays[0];
+                    relay.is_bridge = false;
+                } else if (data.bridges.length >= 1) {
+                    relay = data.bridges[0];
+                    relay.is_bridge = true;
+                }
+                if (relay) {
                     //console.log(data);
                     relay.contact = relay.contact ? relay.contact : 'undefined';
                     relay.platform = relay.platform ? relay.platform : null;
@@ -148,6 +155,15 @@ define([
                     relay.bandwidth = relay.advertised_bandwidth ? relay.advertised_bandwidth : null;
                     relay.bandwidth_hr = relay.advertised_bandwidth ? hrBandwidth(relay.advertised_bandwidth) : null;
                     relay.family = relay.family ? relay.family : null;
+                    if (relay.is_bridge) {
+                        var new_addresses = [];
+                        _.each(relay.or_addresses, function(or_addr) {
+                            var addr = or_addr[0] == '[' ? "IPv6" : "IPv4";
+                            addr += or_addr.slice(or_addr.lastIndexOf(":"));
+                            new_addresses.push(addr);
+                        });
+                        relay.or_addresses = new_addresses;
+                    }
                     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;
@@ -163,6 +179,8 @@ define([
                     relay.downtime = relay.last_seen ? model.parsedate(relay.last_seen).hrfull : null;
                     relay.as_no = relay.as_number ? relay.as_number : null;
                     relay.as_name = relay.as_name ? relay.as_name : null;
+                    relay.pool_assignment = relay.pool_assignment ? relay.pool_assignment : null;
+                    relay.fingerprint = relay.hashed_fingerprint ? relay.hashed_fingerprint : relay.fingerprint;
                     model.set({badexit: false});
                     var size = ['16x16', '14x16', '8x16'];
                     relay.flags = model.parseflags(relay.flags, size);
diff --git a/js/views/details/main.js b/js/views/details/main.js
index 36ba13d..1a0fbb2 100644
--- a/js/views/details/main.js
+++ b/js/views/details/main.js
@@ -195,25 +195,27 @@ define([
                 }
             });
 
-            this.graph.lookup_weights(this.model.fingerprint, {
-                success: function() {
-                    graph.parse_weights_data(graph.data);
-                    graphs = ['weights_week', 'weights_month',
-                            'weights_months', 'weights_year', 'weights_years'];
-                    _.each(graphs, function(g) {
-                        var data = [graph.get(g).advbw, graph.get(g).cw,
-                                    graph.get(g).guard, graph.get(g).exit];
-                        var labels = ["advertised bandwidth fraction",
-                                      "consensus weight fraction",
-                                      "guard probability",
-                                      "exit probability"];
-                        var legendPos = [[3, 0], [181, 0], [341, 0], [450, 0]];
-                        var colors = ["#edc240", "#afd8f8",
-                                      "#cb4b4b", "#4da74d"];
-                        plot(g, data, labels, legendPos, colors, ".4%", ".6%");
-                    });
-                }
-            });
+            if (!this.model.get('is_bridge')) {
+                this.graph.lookup_weights(this.model.fingerprint, {
+                    success: function() {
+                        graph.parse_weights_data(graph.data);
+                        graphs = ['weights_week', 'weights_month',
+                                'weights_months', 'weights_year', 'weights_years'];
+                        _.each(graphs, function(g) {
+                            var data = [graph.get(g).advbw, graph.get(g).cw,
+                                        graph.get(g).guard, graph.get(g).exit];
+                            var labels = ["advertised bandwidth fraction",
+                                          "consensus weight fraction",
+                                          "guard probability",
+                                          "exit probability"];
+                            var legendPos = [[3, 0], [181, 0], [341, 0], [450, 0]];
+                            var colors = ["#edc240", "#afd8f8",
+                                          "#cb4b4b", "#4da74d"];
+                            plot(g, data, labels, legendPos, colors, ".4%", ".6%");
+                        });
+                    }
+                });
+            };
 
             $("#loading").hide();
             $(".flag .tooltip").hide();





More information about the tor-commits mailing list