diff --git a/app/config.json b/app/config.json index 1ee69a74b16aca185249e193a037f7496fb5ccc2..b75a208416963d76a844e6a7eefd6385c690d4c2 100644 --- a/app/config.json +++ b/app/config.json @@ -43,15 +43,15 @@ }, "fallbackNodes": [ { - "host": "g1.cgeek.fr", + "host": "g1.e-is.pro", "port": 443 }, { - "host": "g1.cloud-libre.eu", + "host": "vit.fdn.org", "port": 443 }, { - "host": "g1.e-is.pro", + "host": "g1.cgeek.fr", "port": 443 }, { @@ -59,15 +59,16 @@ "port": 443 }, { - "host": "vit.fdn.org", + "host": "g1.duniter.org", "port": 443 }, { - "host": "g1.duniter.org", - "port": 443 + "host": "duniter.moul.re", + "port": 443, + "path": "/bma" }, { - "host": "g1v1.p2p.legal", + "host": "duniter-v1-g1.axiom-team.fr", "port": 443 } ], diff --git a/www/js/config.js b/www/js/config.js index 111af0b15222be01197c5ee51cb94257d5f61ffe..0364af5a152e3ba715fe22afaba46706c823a744 100644 --- a/www/js/config.js +++ b/www/js/config.js @@ -51,34 +51,15 @@ angular.module("cesium.config", []) "maxContentLength": 1300 }, "fallbackNodes": [ - { - "host": "g1.cgeek.fr", - "port": 443 - }, - { - "host": "g1.cloud-libre.eu", - "port": 443 - }, - { - "host": "g1.e-is.pro", - "port": 443 - }, - { - "host": "g1.mithril.re", - "port": 443 - }, - { - "host": "vit.fdn.org", - "port": 443 - }, - { - "host": "g1.duniter.org", - "port": 443 - }, - { - "host": "g1v1.p2p.legal", - "port": 443 - } + { + "host": "g1v1.p2p.legal", + "port": 443 + }, + { + "host": "duniter.moul.re", + "port": 443, + "path": "/bma" + } ], "developers": [ { @@ -133,4 +114,4 @@ angular.module("cesium.config", []) "newIssueUrl": "https://git.duniter.org/clients/cesium-grp/cesium/issues/new" }) -; \ No newline at end of file +; diff --git a/www/js/entities/peer.js b/www/js/entities/peer.js index 0286e6b8f49857021d821f621c9546d6a5db6793..5604db5bca4ffff3a6f2a20739f9346403b4aaeb 100644 --- a/www/js/entities/peer.js +++ b/www/js/entities/peer.js @@ -66,8 +66,9 @@ Peer.prototype.getBMA = function() { if (this.bma) return this.bma; var bma = null; var path = null; + var that = this; this.endpoints.forEach(function(ep){ - var matches = !bma && this.regexp.BMA_REGEXP.exec(ep); + var matches = !bma && that.regexp.BMA_REGEXP.exec(ep); if (matches) { path = matches[10]; if (path && !path.startsWith('/')) path = '/' + path; // Fix path (add starting slash) @@ -81,7 +82,7 @@ Peer.prototype.getBMA = function() { "useBma": true }; } - matches = !bma && this.regexp.BMAS_REGEXP.exec(ep); + matches = !bma && that.regexp.BMAS_REGEXP.exec(ep); if (matches) { path = matches[10]; if (path && !path.startsWith('/')) path = '/' + path; // Fix path (add starting slash) diff --git a/www/js/platform.js b/www/js/platform.js index 3cb7b552d86a48214fd68f73c2073ac42456ee77..a095574bc689bc51aa5c5ad490dcad685b7bd5a7 100644 --- a/www/js/platform.js +++ b/www/js/platform.js @@ -159,10 +159,10 @@ angular.module('cesium.platform', ['ngIdle', 'cesium.config', 'cesium.services'] if (!fallbackNodes.length) throw 'ERROR.CHECK_NETWORK_CONNECTION'; return _.sample(fallbackNodes); // Random select }) - .then(function (fallbackNode) { + .then(function(fallbackNode) { // Ask user before using the fallback node - if (askUserConfirmation) { + if (fallbackNode && askUserConfirmation) { return askUseFallbackNode(fallbackNode); } @@ -176,7 +176,7 @@ angular.module('cesium.platform', ['ngIdle', 'cesium.config', 'cesium.services'] host: fallbackNode.host, port: fallbackNode.port, path: fallbackNode.path, - useSsl: fallbackNode.useSsl, + useSsl: fallbackNode.useSsl }; csSettings.data.node = node; csSettings.data.node.temporary = true; @@ -194,64 +194,77 @@ angular.module('cesium.platform', ['ngIdle', 'cesium.config', 'cesium.services'] if (!alive) return false; var now = Date.now(); - console.info("[platform] Checking if node is synchronized..."); + console.info("[platform] Checking peer [{0}] is well synchronized...".format(BMA.server)); api.start.raise.message('NETWORK.INFO.ANALYZING_NETWORK'); var askUserConfirmation = csSettings.data.expertMode; + var minConsensusPeerCount = csSettings.data.minPeerCountAtStartup || -1; return csNetwork.getSynchronizedBmaPeers(BMA) .then(function(peers) { var consensusBlockNumber = peers.length ? peers[0].currentNumber : undefined; + var consensusPeerCount = peers.length; - // Serialize to JSON Object - peers = peers.reduce(function(res, peer) { + // Filter compatible peers + peers = peers && peers.reduce(function(res, peer) { + if (!peer.compatible) return res; + // Serialize to JSON, then append return res.concat(peer.toJSON()); }, []); - if (!peers.length) return false; // No peer found: exit + console.info("[platform] Found {0}/{1} BMA peers, synchronized and compatible, in {2}ms".format(peers.length, consensusPeerCount, Date.now() - now)); - // Not enough peers in network (isolated node). Should never occur. Make sure at least one known node exists - if (peers.length < 10) { - console.warn("[platform] Network scanned in {0}ms, only {1} peers (UP and synchronized) found. To few peers. Will peek another peer...".format(Date.now() - now, peers.length)); - // Retry using another peer + // Not enough synchronized peers found (e.g. an isolated peer). Should never occur. + if (!consensusPeerCount || (minConsensusPeerCount > 0 && consensusPeerCount < minConsensusPeerCount)) { + console.warn("[platform] Not enough BMA peers on the main consensus block: {0} found. Will peek another peer...".format(consensusPeerCount)); + // Retry using another fallback peer return checkBmaNodeAlive(false) .then(checkBmaNodeSynchronized); // Loop } - console.info("[platform] Network scanned in {0}ms, {1} peers (UP and synchronized) found".format(Date.now() - now, peers.length)); - - - // Try to find the current peer in the list of synchronized peers - var otherPeers = _.filter(peers, function(peer) { - return !BMA.node.same(peer); + // Try to find the current peer in synchronized peers + var synchronizedIndex = _.findIndex(peers, function(peer) { + return BMA.url === peer.url; }); + if (synchronizedIndex !== -1) peers.splice(synchronizedIndex, 1); - // OK (current BMA node is sync): continue - var synchronized = otherPeers.length < peers.length; - if (synchronized) { - console.info("[platform] Default peer [{0}] is well synchronized.".format(BMA.server)); - - // Store sync peers in storage - console.debug("[platform] Saving {0} other synchronized BMA peers in settings".format(otherPeers.length)); - csSettings.data.network.peers = otherPeers; + // Saving other peers to settings + console.debug("[platform] Saving {0} BMA peers in settings, for a later use".format(peers.length)); + csSettings.data.network.peers = peers; + // OK (current BMA node is sync and compatible): continue + if (synchronizedIndex !== -1) { + console.info("[platform] Default peer [{0}{1}] is eligible.".format(BMA.server, BMA.path)); return true; } - // Peer is not well synchronized! - console.warn("[platform] Default peer [{0}] not synchronized with consensus block #{1}".format(BMA.server, consensusBlockNumber)); - + // Peer is not well synchronized: checking its current block + console.warn("[platform] Default peer [{0}{1}] is NOT on the consensus block #{2}. Checking its current block...".format( + BMA.server, + BMA.path, + consensusBlockNumber)); return csCurrency.blockchain.current() .then(function(block) { - // Only one block late: keep current node + // OK: only few blocks late, so we keep it if (Math.abs(block.number - consensusBlockNumber) <= 2) { - console.info("[platform] Keep BMA node [{0}], as current block #{1} is very closed to the consensus block #{2}".format(BMA.server, block.number, consensusBlockNumber)); + console.info("[platform] Keep default peer [{0}{1}] anyway, because current block #{2} closed to the consensus block".format( + BMA.server, + BMA.path, + block.number)); return true; } - // Peek another peer - var randomPeer = _.sample(otherPeers); + // No eligible peer to peek + if (!peers.length) { + console.warn("[platform] Not enough BMA peers compatible with Cesium: {0} found. Will peek another peer...".format(peers.length)); + // Retry using another fallback peer + return checkBmaNodeAlive(false) + .then(checkBmaNodeSynchronized); // Loop + } + + // KO: peek another peer + var randomPeer = _.sample(peers); var synchronizedNode = new Peer(randomPeer); // If Expert mode: ask user to select a node @@ -267,10 +280,16 @@ angular.module('cesium.platform', ['ngIdle', 'cesium.config', 'cesium.services'] return selectBmaNode(); } - console.info("[platform] Switching to synchronized fallback peer {{0}:{1}}".format(node.host, node.port)); + console.info("[platform] Switching to synchronized fallback peer [{0}:{1}]".format(node.host, node.port)); // Only change BMA node in settings - angular.merge(csSettings.data.node, node, {endpoints: undefined, temporary: true}); + angular.merge(csSettings.data.node, { + host: node.host, + port: node.port, + path: node.path, + useSsl: node.useSsl, + temporary: askUserConfirmation ? true : undefined // Mark as temporary + }); return BMA.copy(node); }); @@ -285,7 +304,8 @@ angular.module('cesium.platform', ['ngIdle', 'cesium.config', 'cesium.services'] */ function askUseFallbackNode(fallbackNode, messageKey) { - var confirmMsgParams = {old: BMA.url, new: fallbackNode.url}; + var newUrl = csHttp.getUrl(fallbackNode.host, fallbackNode.port, fallbackNode.path, fallbackNode.useSsl); + var confirmMsgParams = {old: BMA.url, new: newUrl}; messageKey = messageKey || 'CONFIRM.USE_FALLBACK_NODE'; diff --git a/www/js/services/bma-services.js b/www/js/services/bma-services.js index e187a09c359308ac32fb473591d85f7a4010a6d9..8a2ed97d796a9564391ee1b46b91850157425e4f 100644 --- a/www/js/services/bma-services.js +++ b/www/js/services/bma-services.js @@ -268,18 +268,26 @@ angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium. // Check duniter min version if (software === 'duniter' && json.duniter.version) { - isCompatible = csHttp.version.isCompatible(csSettings.data.minVersion, json.duniter.version); - // TODO check storage transaction ? + isCompatible = csHttp.version.isCompatible(csSettings.data.minVersion, json.duniter.version) && + // version < 1.8.7 (no storage) OR transaction storage enabled + (!json.duniter.storage || json.duniter.storage.transactions === true); + if (!isCompatible) { + console.error('[BMA] Incompatible Duniter peer [{0}{1}] (actual version {2}): min expected version is {3} with transactions storage enabled'.format( + csHttp.getServer(node.host, node.port), + node.path ||'', + json.duniter.version || '?', csSettings.data.minVersion)); + } } else { - console.debug('[BMA] Unknown node software [{0} v{1}]: could not check compatibility.'.format(software || '?', json.duniter.version || '?')); - } - if (!isCompatible && json && json.duniter) { - console.error('[BMA] Incompatible node [{0} v{1}]: expected at least v{2}'.format(software, json.duniter.version || '?', csSettings.data.minVersion)); + console.warn('[BMA] Unknown software [{0}] found in peer [{1}{2}] (version {3}): could not check compatibility.'.format( + software || '?', + csHttp.getServer(node.host, node.port), + node.path ||'', + json.duniter.version || '?')); } return isCompatible; }) - .catch(function() { + .catch(function(err) { return false; // Unreachable }); }; @@ -352,7 +360,7 @@ angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium. .then(function(alive) { that.alive = alive; if (!that.alive) { - console.error("[BMA] Could not start using peer [{0}{1}]: unreachable".format(that.server, that.path)); + console.error("[BMA] Could not start using peer [{0}{1}]: unreachable or incompatible".format(that.server, that.path)); that.started = true; delete that._startPromise; return false; // Not alive @@ -415,15 +423,21 @@ angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium. return !same; }); - - console.debug('[BMA] Getting alive fallback nodes... (temiout: {0}ms)'.format(timeout)); + console.debug('[BMA] Getting alive fallback nodes... {timeout: {0}}'.format(timeout)); var aliveNodes = []; return $q.all(_.map(fallbackNodes, function(node) { return that.isAlive(node, timeout) .then(function(alive) { if (alive) { - aliveNodes.push(node); + node.url = csHttp.getUrl(node); + node.server = csHttp.getUrl(node); + aliveNodes.push({ + host: node.host, + port: node.port, + useSsl: node.useSsl || node.port == 443, + path: node.path + }); } else { console.error('[BMA] Unreachable (or not compatible) fallback node [{0}]: skipping'.format(node.server)); diff --git a/www/js/services/http-services.js b/www/js/services/http-services.js index b0ff0b89b002039a69722a83138274607258841c..341bfb875ddf4aa018d32b5819f6bf4afc78b88d 100644 --- a/www/js/services/http-services.js +++ b/www/js/services/http-services.js @@ -570,12 +570,12 @@ angular.module('cesium.http.services', ['cesium.cache.services']) function isVersionCompatible(minVersion, actualVersion) { var result = compareVersionNumbers(minVersion, actualVersion) <= 0; - console.debug('[http] Is actual version [{0}] compatible with min expected version [{1}] ? => {2}'.format(actualVersion, minVersion, result)); + //console.debug('[http] Duniter version {0} is {1}compatible (min expected version {2})'.format(actualVersion, result ? '': 'NOT ', minVersion)); return result; } function clearCache(cachePrefix) { - cachePrefix = cachePrefix ||Â defaultCachePrefix; + cachePrefix = cachePrefix || defaultCachePrefix; console.debug("[http] Cleaning cache {prefix: '{0}'}...".format(cachePrefix)); csCache.clear(cachePrefix); } diff --git a/www/js/services/network-services.js b/www/js/services/network-services.js index c317755644dee6ce2f09e2296c8356c338b45c09..c4cb2b89d9c8f33b7eb8911dc4cf0f551a0d3b1b 100644 --- a/www/js/services/network-services.js +++ b/www/js/services/network-services.js @@ -15,7 +15,7 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.currency.services', startPromise, data = { - pid: 0, // Start PID + pid: 0, // = not started bma: null, listeners: [], loading: true, @@ -181,6 +181,7 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.currency.services', data.loading = true; data.bma = data.bma || BMA; var newPeers = []; + var pid = data.pid; if (interval) { $interval.cancel(interval); @@ -198,7 +199,7 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.currency.services', // The peer lookup end, we can make a clean final report sortPeers(true/*update main buid*/); - console.debug('[network] {0} peer(s) found.'.format(data.peers.length)); + console.debug('[network] [#{0}] {1} peer(s) found.'.format(pid, data.peers.length)); } }, 1000); @@ -239,7 +240,7 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.currency.services', // Exclude if too old peering document json.blockNumber = buidBlockNumber(json.block); if (json.blockNumber && json.blockNumber < data.minOnlineBlockNumber) { - console.debug("[network] Exclude a too old peering document, on pubkey {0}".format(json.pubkey.substring(0,6))); + console.debug("[network] [#{0}] Exclude a too old peering document, on pubkey {1}".format(pid, json.pubkey.substring(0,6))); return; } @@ -260,14 +261,14 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.currency.services', var privateWs2pHeads = _.values(data.ws2pHeads); if (privateWs2pHeads && privateWs2pHeads.length) { var privateEPCount = 0; - //console.debug("[http] Found WS2P endpoints without endpoint:", data.ws2pHeads); + //console.debug("[network] Found WS2P endpoints without endpoint:", data.ws2pHeads); _.forEach(privateWs2pHeads, function(head) { if (!head.hasEndPoint) { var currentNumber = buidBlockNumber(head.buid); // Exclude if on a too old block if (currentNumber && currentNumber < data.minOnlineBlockNumber) { - console.debug("[network] Exclude a too old WS2P message, on pubkey {0}".format(head.pubkey.substring(0,6))); + console.debug("[network] [#{0}] Exclude a too old WS2P message, on pubkey {1}".format(pid, head.pubkey.substring(0,6))); return; } @@ -301,7 +302,7 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.currency.services', }); if (privateEPCount) { - console.debug("[http] Found {0} WS2P endpoints without endpoint (private ?)".format(privateEPCount)); + console.debug("[network] [#{0}] Found {1} WS2P endpoints without endpoint (private ?)".format(pid, privateEPCount)); } } @@ -386,6 +387,7 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.currency.services', var peers = createPeerEntities(json); var hasUpdates = false; + var pid = data.pid; var jobs = peers.reduce(function(jobs, peer) { var existingPeer = _.findWhere(data.peers, {id: peer.id}); @@ -407,32 +409,36 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.currency.services', if (!refreshedPeer || (refreshedPeer.online !== data.filter.online && data.filter.online !== 'all')) { var existingIndex = data.peers.indexOf(existingPeer); if (existingIndex !== -1) { - console.debug('[network] Peer [{0}] removed (cause: {1})'.format(peer.server, !refreshedPeer ? 'filtered' : (refreshedPeer.online ? 'UP' : 'DOWN'))); + console.debug('[network] [#{0}] Peer [{1}] removed (cause: {2})'.format(pid, peer.server, !refreshedPeer ? 'filtered' : (refreshedPeer.online ? 'UP' : 'DOWN'))); data.peers.splice(existingIndex, 1); hasUpdates = true; } } else if (refreshedPeer.buid !== existingMainBuid){ - console.debug('[network] {0} endpoint [{1}] new current block'.format( + console.debug('[network] [#{0}] {1} endpoint [{2}] new current block'.format( + pid, api, refreshedPeer.server)); hasUpdates = true; } else if (existingOnline !== refreshedPeer.online){ - console.debug('[network] {0} endpoint [{1}] is now {2}'.format( + console.debug('[network] [#{0}] {1} endpoint [{2}] is now {3}'.format( + pid, api, refreshedPeer.server, refreshedPeer.online ? 'UP' : 'DOWN')); hasUpdates = true; } else { - console.debug("[network] {0} endpoint [{1}] unchanged".format( + console.debug("[network] [#{0}] {1} endpoint [{2}] unchanged".format( + pid, api, refreshedPeer.server)); } } else if (refreshedPeer && (refreshedPeer.online === data.filter.online || data.filter.online === 'all')) { - console.debug("[network] {0} endpoint [{1}] is {2}".format( + console.debug("[network] [#{0}] {1} endpoint [{2}] is {3}".format( + pid, api, refreshedPeer.server, refreshedPeer.online ? 'UP' : 'DOWN' @@ -851,12 +857,17 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.currency.services', options = options || {}; bma = bma || BMA; - var pid = data.pid; + var pid = 0; startPromise = bma.ready() .then(function() { - close(pid); - data.pid++; + // Stop previous network scan (if running) + close(data.pid); + + // Compute next PID + pid = ++data.pid; + + // Prepare data data.bma = bma; data.filter = options.filter ? angular.merge(data.filter, options.filter) : data.filter; data.sort = options.sort ? angular.merge(data.sort, options.sort) : data.sort; @@ -880,13 +891,16 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.currency.services', }) .then(function() { var now = Date.now(); - console.info('[network] Starting from [{0}{1}] {ssl: {2})'.format(bma.server, bma.path, bma.useSsl)); + console.info('[network] [#{0}] Starting from [{1}{2}] {ssl: {3}}'.format(pid, bma.server, bma.path, bma.useSsl)); addListeners(); return loadPeers() .then(function(peers){ - if (peers) console.debug('[network] Started in {0}ms, {1} peer(s) found'.format(Date.now() - now, peers.length)); + if (peers) console.debug('[network] [#{0}] Started - {1} peer(s) found, in {2}ms'.format( + pid, + peers.length, + Date.now() - now)); return data; }); }); @@ -894,11 +908,11 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.currency.services', }, close = function(pid) { - if (data.bma) { - console.info('[network] Stopping...'); - removeListeners(); - resetData(); - } + console.info(pid > 0 ? '[network] [#{0}] Stopping...'.format(pid) : '[network] Stopping...'); + if (data.bma) { + removeListeners(); + resetData(); + } if (interval && pid === data.pid && pid > 0) { $interval.cancel(interval); } @@ -922,7 +936,7 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.currency.services', getMainBlockUid = function(bma, options) { var wasStarted = isStarted(); - var pid = data.pid + 1; + var pid = wasStarted ? data.pid : data.pid + 1; return startIfNeed(bma, options) .then(function(data) { var buid = data.mainBlock && data.mainBlock.buid; @@ -930,7 +944,7 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.currency.services', return buid; }) .catch(function(err) { - console.error('[network] Failed to get main block'); + console.error('[network] [#{0}] Failed to get main block'.format(pid)); if (!wasStarted) close(pid); throw err; }); @@ -941,50 +955,57 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.currency.services', options = options || {}; options.filter = options.filter || {}; options.filter.bma = angular.isDefined(options.filter.bma) ? options.filter.bma : true; - options.filter.ssl = isHttpsMode ? true : undefined; + options.filter.ssl = isHttpsMode ? true : undefined /*= all */; options.filter.online = true; - options.filter.expertMode = false; + options.filter.expertMode = false; // Difficulties not need options.timeout = angular.isDefined(options.timeout) ? options.timeout : getDefaultTimeout(); + var wasStarted = isStarted(); + var pid = wasStarted ? data.pid : data.pid + 1; + var now = Date.now(); - console.info('[network] Getting synchronized BMA peers... (timeout: {0}ms)'.format(options.timeout)); + console.info('[network] [#{0}] Getting synchronized BMA peers... {timeout: {1}}'.format(pid, options.timeout)); - var wasStarted = isStarted(); - var pid = data.pid + 1; return startIfNeed(bma, options) .then(function(data){ - var peers = data && _.filter(data.peers, function(peer) { - // Keep if on the main consensus block, and compatible with Cesium - return peer && peer.hasMainConsensusBlock && peer.isBma(); - }); + var peerUrls = []; + var peers = data && data.peers.reduce(function(res, peer) { + // Exclude if not BMA or not on the main consensus block + if (!peer || !peer.isBma() || !peer.hasMainConsensusBlock) return res; + + // Fill some properties compatible + peer.compatible = isCompatible(peer); + peer.url = peer.getUrl(); + + // Clean unused properties (e.g. the API, created by BMA.lightInstance()) + delete peer.api; + + // Remove duplicate + if (peerUrls.includes(peer.url)) return res; + peerUrls.push(peer.url); + + return res.concat(peer); + }, []); // Log if (peers && peers.length > 0) { var mainConsensusBlock = peers[0] && peers[0].buid; - console.info('[network] Found {0}/{1} BMA peers on main consensus block #{2} - in {3}ms'.format( + console.info('[network] [#{0}] Found {0}/{1} BMA peers on main consensus block #{2} - in {3}ms'.format( peers.length, data.peers.length, mainConsensusBlock, Date.now() - now)); - - // Exclude peers that are not compatible with Cesium - peers = _.filter(peers, function(peer) { - return isCompatibleBMAPeer(peer); - }); } else { - console.warn('[network] No synchronized BMA peers found, in {0}ms'.format(Date.now() - now)); + console.warn('[network] [#{0}] No synchronized BMA peers found - in {1}ms'.format(pid, Date.now() - now)); } if (!wasStarted) close(pid); - return peers; }) .catch(function(err) { - console.error('[network] Error while getting synchronized BMA peers', err); - + console.error('[network] [#{0}] Error while getting synchronized BMA peers'.format(pid), err); if (!wasStarted) close(pid); - throw err; }); }, @@ -994,32 +1015,35 @@ angular.module('cesium.network.services', ['ngApi', 'cesium.currency.services', * @param peer * @returns {*} */ - isCompatibleBMAPeer = function(peer) { + isCompatible = function(peer) { if (!peer && !peer.isBma() || !peer.version) return false; - // Exclude beta versions (1.9.0, 1.9.0-dev and 1.8.7-rc4) - if (peer.version.startsWith('1.9.0') || peer.version.startsWith('1.8.7-rc')) { - console.debug('[network] BMA endpoint [{0}] is EXCLUDED (incompatible version {1})'.format(peer.getServer(), peer.version)); + // CHeck version compatible, from min version + if (!peer.version || !csHttp.version.isCompatible(csSettings.data.minVersionAtStartup || csSettings.data.minVersion, peer.version) || + // Exclude beta versions (1.9.0, 1.9.0-dev and 1.8.7-rc4) + peer.version.startsWith('1.9.0') || peer.version.startsWith('1.8.7-rc') + ) { + console.debug('[network] [#{0}] BMA endpoint [{1}] is EXCLUDED (incompatible version {2})'.format(data.pid, peer.getServer(), peer.version)); return false; } // Exclude if transactions not stored - if (!peer.storage && !peer.storage.transactions) { - console.debug('[network] BMA endpoint [{0}] is EXCLUDED (no transactions storage)'.format(peer.getServer())); + if (!peer.storage && peer.storage.transactions !== true) { + console.debug('[network] [#{0}] BMA endpoint [{1}] is EXCLUDED (no transactions storage)'.format(data.pid, peer.getServer())); return false; } // Exclude g1.duniter.org, because of fail-over config, that can switch node if (peer.host === 'g1.duniter.org') { - console.debug('[network] BMA endpoint [{0}] is EXCLUDED (fail-over config)'.format(peer.getServer())); + console.debug('[network] [#{0}] BMA endpoint [{1}] is EXCLUDED (load-balancing nightmare)'.format(data.pid, peer.getServer())); return false; } // Exclude if one sandbox is full - if (peer.sandboxes && peer.sandboxes.full) { - console.debug('[network] BMA endpoint [{0}] is EXCLUDED (one sandbox is full)'.format(peer.getServer())); - return false; - } + if (peer.sandboxes && peer.sandboxes.full) { + console.debug('[network] [#{0}] BMA endpoint [{1}] is EXCLUDED (one sandbox is full)'.format(data.pid, peer.getServer())); + return false; + } return true; }; diff --git a/www/js/services/settings-services.js b/www/js/services/settings-services.js index 54b7c1f516c2643c38bd920d1f73196e330aad82..53567f1c49023bbf5cc176ff9ad199a3fceb0084 100644 --- a/www/js/services/settings-services.js +++ b/www/js/services/settings-services.js @@ -72,7 +72,9 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) cacheTimeMs: 60000, /*1 min*/ timeWarningExpireMembership: 2592000 * 2 /*=2 mois*/, timeWarningExpire: 2592000 * 3 /*=3 mois*/, - minVersion: '1.1.0', // TODO change into 1.8.7 + minVersion: '1.8.0', + minVersionAtStartup: '1.8.7', // use for node auto-selection + minPeerCountAtStartup: 10, // use for node auto-selection sourceUrl: 'https://git.duniter.org/clients/cesium-grp/cesium', sourceLicenseUrl: 'https://git.duniter.org/clients/cesium-grp/cesium/-/raw/master/LICENSE', newIssueUrl: "https://git.duniter.org/clients/cesium-grp/cesium/issues/new", diff --git a/www/templates/settings/settings.html b/www/templates/settings/settings.html index c778bfced6b11e41d2b4bc2e8affb8e4c02417c8..553252628df14ae8517fbf24cbcbcc590fc13bfc 100644 --- a/www/templates/settings/settings.html +++ b/www/templates/settings/settings.html @@ -241,7 +241,7 @@ <span ng-bind-html="platform.loadingMessage | translate "></span> </h4> </ng-if> - <div class="badge badge-balanced" ng-class="{'badge-assertive': formData.node.temporary}">{{bma.server}}</div> + <div class="badge badge-balanced" ng-class="{'badge-assertive': formData.node.temporary}">{{bma.server}}{{bma.path||''}}</div> </ng-if> <!-- node selected automatically --> @@ -250,7 +250,7 @@ <span ng-bind-html="'SETTINGS.PEER_SELECTED_AUTOMATICALLY' | translate "></span> </h4> <ng-if ng-if="!platform.loading"> - <div class="badge badge-balanced">{{bma.server}}</div> + <div class="badge badge-balanced">{{bma.server}}{{bma.path||''}}</div> </ng-if> <ng-if ng-if="platform.loading"> <h4 class="gray text-italic">