forked from byteball/obyte-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.js
43 lines (38 loc) · 1.13 KB
/
start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*jslint node: true */
"use strict";
require('byteball-relay');
var conf = require('./conf');
var network = require('byteballcore/network');
var eventBus = require('byteballcore/event_bus.js');
var push = require('./push');
eventBus.on('peer_version', function (ws, body) {
if (body.program == conf.clientName) {
if (conf.minClientVersion && compareVersions(body.program_version, conf.minClientVersion) == '<')
network.sendJustsaying(ws, 'new_version', {version: conf.minClientVersion});
if (compareVersions(body.program_version, '1.5.1') == '<')
ws.close(1000, "mandatory upgrade");
}
});
function compareVersions(currentVersion, minVersion) {
if (currentVersion === minVersion) return '==';
var cV = currentVersion.match(/([0-9])+/g);
var mV = minVersion.match(/([0-9])+/g);
var l = Math.min(cV.length, mV.length);
var diff;
for (var i = 0; i < l; i++) {
diff = parseInt(cV[i], 10) - parseInt(mV[i], 10);
if (diff > 0) {
return '>';
} else if (diff < 0) {
return '<'
}
}
diff = cV.length - mV.length;
if (diff == 0) {
return '==';
} else if (diff > 0) {
return '>';
} else if (diff < 0) {
return '<';
}
}