zold 0.10.3 → 0.10.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cbd394e0db7a071badbe5c9562cd2b510cbe658
4
- data.tar.gz: 05423f08a285e4af622046bde0df729b2412d7b3
3
+ metadata.gz: 64a5fc8ee84ebe8ee31211bd472784f1634a7392
4
+ data.tar.gz: e016476f3c823b7dd433bc96531639906db64d38
5
5
  SHA512:
6
- metadata.gz: b09ceb26d024e501c01a9056427d6e62677dfb7916547e133b36feae4efd0c26980952874b205542d8cc09767addd66f289ea5ece65877b882f03f212d2f7856
7
- data.tar.gz: 5b81ac513bb61de72f0a4bdd039ba693cfccceb0c1dbbbb6470c55326fc53c8dc3b5ac8c7e1a734bf2d00552adfe6e55d35565a6d7b4a2f77a1e2c15512490bd
6
+ metadata.gz: b67567ae28c14b77c422f368e9996eac97ffa166b5d35328e7ed0c1cfa90bd237fc9ecefa6a8d6255fb1ed2efcc650dd2a6819a0c5798b8b11cf4bf179893d58
7
+ data.tar.gz: 9af5c4f63487be52e9a4fd7bca7ef7197811340ef6d109231160bf2faf49185e2ce66e3cf2c8f8b42d97e734280d8e43b393b6c9268459f752d0567258b0307d
data/html/map.html CHANGED
@@ -49,64 +49,79 @@ SOFTWARE.
49
49
  #remotes li { list-style: none; }
50
50
  </style>
51
51
  <script>
52
- function init() {
53
- var options = {
54
- center: new google.maps.LatLng(55.751244, 37.618423),
55
- mapTypeId: google.maps.MapTypeId.ROADMAP,
56
- zoom: 3
57
- };
58
- var remotes = {};
59
- var map = new google.maps.Map(document.getElementById("map"), options);
60
- $.getJSON('/', function(data) {
52
+ function put_marker_by_ip(map, coords, ip, port) {
53
+ $.getJSON('http://www.geoplugin.net/json.gp?ip=' + ip, function(json) {
54
+ var lat = parseFloat(json['geoplugin_latitude']), lon = parseFloat(json['geoplugin_longitude']);
55
+ console.log(ip + ' located at ' + lat + '/' + lon);
56
+ new google.maps.Marker({
57
+ position: { lat: lat, lng: lon },
58
+ map: map,
59
+ title: ''
60
+ });
61
+ console.log('Marker set for ' + coords + ' at ' + lat + '/' + lon);
62
+ }).fail(function() { console.log('Failed to find geo-location for ' + ip) });
63
+ }
64
+ function put_marker_by_host(map, coords, host, port) {
65
+ $.getJSON('https://api.exana.io/dns/' + host + '/a', function(json) {
66
+ ip = $.grep(json['answer'], function (a, i) { return a['type'] == 'A'; })[0]['rdata'];
67
+ console.log('Host ' + host + ' resolved to ' + ip);
68
+ put_marker_by_ip(map, coords, ip, port);
69
+ }).fail(function() { console.log('Failed to find IP for ' + host) });
70
+ }
71
+ function put_markers(map, remotes) {
72
+ $.each(remotes, function (i, r) {
73
+ var host = r['host'], port = r['port'];
74
+ var coords = host + ':' + port;
75
+ var items = $('#remotes li[data-coords="' + coords + '"]');
76
+ if (items.length) {
77
+ var li = items.first();
78
+ $.getJSON('http://' + coords + '/', function(json) {
79
+ li.html(coords + ': ' + json['score']['value'] + '/' + json['wallets'] + ' (' + json['version'] + ')');
80
+ if (host.match(/^[0-9\.]+$/)) {
81
+ put_marker_by_ip(map, host + ':' + port, host, port);
82
+ } else {
83
+ put_marker_by_host(map, host + ':' + port, host, port);
84
+ }
85
+ }).done(function() { li.css('color', 'darkgreen'); }).fail(function() { li.css('color', 'red'); });
86
+ } else {
87
+ $('#remotes').append('<li data-coords="' + coords + '">' + coords + '</li>')
88
+ }
89
+ });
90
+ }
91
+ function refresh_list(map) {
92
+ $.getJSON('http://b1.zold.io/remotes', function(data) {
93
+ var remotes = data['all'];
94
+ console.log(remotes.length + ' remote nodes found');
95
+ put_markers(map, remotes);
96
+ });
97
+ }
98
+ function refresh(map) {
99
+ $.getJSON('http://b1.zold.io/', function(data) {
61
100
  $('#header').html(
62
101
  'Version: ' + data['version'] + '<br/>' +
63
102
  'Host: ' + data['score']['host'] + ':' + data['score']['port'] + '<br/>' +
64
103
  'Score: ' + data['score']['value'] + '<br/>' +
65
104
  'Wallets: ' + data['wallets']
66
105
  );
106
+ refresh_list(map);
107
+ window.setTimeout(refresh, 10000);
67
108
  });
68
- window.setInterval(function() {
69
- $.getJSON('/remotes', function(data) { remotes = data['all']; });
70
- }, 10000);
71
- window.setInterval(function() {
72
- $('#remotes li').each(function (li) {
73
- found = $.grep(remotes, function (r, i) { return r['host'] + ':' + r['port'] == $(li).attr('data-coords'); });
74
- if (!found.length) {
75
- li.remove();
76
- }
77
- });
78
- }, 10000);
79
- window.setInterval(function() {
80
- $.each(remotes, function (idx, remote) {
81
- var host = remote['host'], port = remote['port'];
82
- var coords = host + ':' + port;
83
- var items = $('#remotes li[data-coords="' + coords + '"]');
84
- if (items.length) {
85
- var li = items.first();
86
- $.getJSON('http://' + coords + '/', function(data) {
87
- li.html(coords + ': ' + data['score']['value'] + '/' + data['wallets'] + ' (' + data['version'] + ')');
88
- })
89
- .done(function() { li.css('color', 'darkgreen'); })
90
- .fail(function() { li.css('color', 'red'); });
91
- var ip = host;
92
- if (!ip.match(/[0-9\.]+/)) {
93
- $.get('http://api.konvert.me/forward-dns/' + host, function(data) {
94
- ip = data
95
- });
96
- }
97
- li.attr('title', ip);
98
- $.getJSON('http://ip-api.com/json/' + ip, function(data) {
99
- new google.maps.Marker({
100
- position: { lat: data['lat'], lng: data['lon'] },
101
- map: map,
102
- title: coords
103
- }).setMap(map);
104
- });
105
- } else {
106
- $('#remotes').append('<li data-coords="' + coords + '">' + coords + '</li>')
107
- }
108
- });
109
- }, 10000);
109
+ }
110
+ function init() {
111
+ var map = new google.maps.Map(
112
+ document.getElementById("map"),
113
+ {
114
+ center: new google.maps.LatLng(55.751244, 37.618423),
115
+ mapTypeId: google.maps.MapTypeId.ROADMAP,
116
+ zoom: 3
117
+ }
118
+ );
119
+ var marker = new google.maps.Marker({
120
+ position: { lat: 55, lng: 37 },
121
+ map: map,
122
+ title: 'Hello'
123
+ });
124
+ refresh(map);
110
125
  };
111
126
  </script>
112
127
  </head>
@@ -56,8 +56,8 @@ module Zold
56
56
  "The strength of the score (default: #{Score::STRENGTH})",
57
57
  default: Score::STRENGTH
58
58
  o.integer '--threads',
59
- 'How many threads to use for scores finding (default: 8)',
60
- default: 8
59
+ 'How many threads to use for scores finding (default: 4)',
60
+ default: 4
61
61
  o.bool '--standalone',
62
62
  'Never communicate with other nodes (mostly for testing)',
63
63
  default: false
data/lib/zold/copies.rb CHANGED
@@ -63,7 +63,10 @@ module Zold
63
63
  raise "Score can't be negative: #{score}" if score < 0
64
64
  FileUtils.mkdir_p(@dir)
65
65
  list = load
66
- target = list.find { |s| File.read(File.join(@dir, s[:name])) == content }
66
+ target = list.find do |s|
67
+ f = File.join(@dir, s[:name])
68
+ File.exist?(f) && File.read(f) == content
69
+ end
67
70
  if target.nil?
68
71
  max = Dir.new(@dir)
69
72
  .select { |f| f =~ /^[0-9]+$/ }
data/lib/zold/version.rb CHANGED
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2018 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Zold
26
- VERSION = '0.10.3'.freeze
26
+ VERSION = '0.10.4'.freeze
27
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.10.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko