Skip to content

Commit bdbcc81

Browse files
committed
Showing latency in the visualizer now.
1 parent 58c3b68 commit bdbcc81

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

index.html

+5-3
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ <h1>time between each block</h1>
193193
.size([this.width,this.height])
194194
.nodes([]) // no nodes
195195
.friction(0.5)
196-
.linkDistance(this.linkDistance)
196+
.linkDistance(function(link) {
197+
return link.linkDistance;
198+
})
197199
.charge(this.charge)
198200
.gravity(this.gravity);
199201

@@ -278,14 +280,14 @@ <h1>time between each block</h1>
278280
return this.nindex-1;
279281
},
280282

281-
connect: function(a, b) {
283+
connect: function(a, b, latency) {
282284
if (this.edges.hasOwnProperty(a + '-' + b) || this.edges.hasOwnProperty(b + '-' + a))
283285
return false; // we're already connected
284286

285287
if (a==b)
286288
return false; // can't connect to ourself silly!
287289

288-
this.edges[a + '-' + b] = {source:this.nodes[this.getKeyForID(a)],target:this.nodes[this.getKeyForID(b)]};
290+
this.edges[a + '-' + b] = {source:this.nodes[this.getKeyForID(a)],target:this.nodes[this.getKeyForID(b)],linkDistance:latency};
289291
this.links.push(this.edges[a + '-' + b]);
290292

291293
this.updated = true;

network.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ Network.prototype = {
461461
// connects two nodes in the visualizer
462462
connect: function (a, b) {
463463
if (this.visualizer) {
464-
this.visualizer.connect(this.nodes[a]._vid, this.nodes[b]._vid);
464+
this.visualizer.connect(this.nodes[a]._vid, this.nodes[b]._vid, latency(this.nodes[a].id, this.nodes[b].id));
465465
}
466466
},
467467

sim.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ client.init(function() {
1919
var self = this;
2020

2121
// mincen client specific stuff
22-
var mapMasters = {};
22+
this.mapMasters = {};
23+
var mapMasters = this.mapMasters;
2324
mapMasters[this.id] = {num:10, last:-1};
2425
var shares = [];
2526
var shareh = -1;
@@ -92,6 +93,13 @@ client.init(function() {
9293
self.inventory.relay(b.id, true);
9394

9495
self.blockchain.chainstate.enter(b);
96+
97+
if (!(self.id in mapMasters)) {
98+
mapMasters[self.id] = {num:0,last:0};
99+
}
100+
101+
mapMasters[self.id].num++;
102+
mapMasters[self.id].last = b.h;
95103
} else {
96104
// ship off an unsignedblock to get it signed by the master
97105
self.inventory.createObj("unsignedblock", {id:"unsigned_" + b.id, b:b})
@@ -206,9 +214,9 @@ client.init(function() {
206214
return true;
207215
})
208216
this.tick(100 * 1000, function() {
209-
if (this.peermgr.numActive() != this.peermgr.maxpeers) {
210-
return true;
211-
}
217+
//if (this.peermgr.numActive() != this.peermgr.maxpeers) {
218+
// return true;
219+
//}
212220
// every 100 seconds boot off a poorly performing peer
213221
var worst_n = Infinity;
214222
var worst = null;

0 commit comments

Comments
 (0)