diff --git a/ZelBack/src/services/benchmarkService.js b/ZelBack/src/services/benchmarkService.js index e9cc13711..b2576d5c2 100644 --- a/ZelBack/src/services/benchmarkService.js +++ b/ZelBack/src/services/benchmarkService.js @@ -149,6 +149,14 @@ async function getInfo(req, res) { return res ? res.json(response) : response; } +async function getPublicIp(req, res) { + const rpccall = 'getpublicip'; + + response = await executeCall(rpccall); + + return res ? res.json(response) : response; +} + module.exports = { // == Benchmarks == getStatus, @@ -163,4 +171,5 @@ module.exports = { // == Zelnode == getBenchmarks, getInfo, + getPublicIp, }; diff --git a/ZelBack/src/services/fluxCommunication.js b/ZelBack/src/services/fluxCommunication.js index e969e8247..e2d150aff 100644 --- a/ZelBack/src/services/fluxCommunication.js +++ b/ZelBack/src/services/fluxCommunication.js @@ -1055,7 +1055,7 @@ async function checkMyFluxAvailability(nodelist) { // run if at least 10 available nodes if (nodelist.length > 10) { let askingIP = await getRandomConnection(); - if (typeof askingIP !== 'string' || typeof myFluxIP !== 'string') { + if (typeof askingIP !== 'string' || typeof myFluxIP !== 'string' || myFluxIP === askingIP) { return; } if (askingIP.includes(':')) { @@ -1081,7 +1081,24 @@ async function checkMyFluxAvailability(nodelist) { } if (resMyAvailability.data.status === 'error' || resMyAvailability.data.data.message.includes('not')) { log.error(`My Flux unavailability detected from ${askingIP}`); - // Asked Flux cannot reach me + // Asked Flux cannot reach me lets check if ip changed + const benchIpResponse = await daemonService.getPublicIp(); + if (benchIpResponse.status === 'success') { + const benchMyIP = benchIpResponse.data.length > 5 ? benchIpResponse.data : null; + if (benchMyIP && benchMyIP !== myIP) { + myIP = benchMyIP; + const restartNodeResponse = await daemonService.restartNodeBenchmarks(); + if (restartNodeResponse.status !== 'success') { + dosMessage = benchIpResponse.data; + dosState += 10; + } + await serviceHelper.delay(2 * 60 * 1000); // lets wait two minutes + return; + } + } else { + dosMessage = benchIpResponse.data; + dosState += 10; + } dosState += 1.5; if (dosState > 10) { dosMessage = dosMessage || 'Flux is not available for outside communication'; @@ -1179,8 +1196,14 @@ async function checkDeterministicNodesCollisions() { log.error(dosMessage); } } + setTimeout(() => { + checkDeterministicNodesCollisions(); + }, 60 * 1000); } catch (error) { log.error(error); + setTimeout(() => { + checkDeterministicNodesCollisions(); + }, 120 * 1000); } } diff --git a/ZelBack/src/services/fluxService.js b/ZelBack/src/services/fluxService.js index 96b0e5a90..02e598c6b 100644 --- a/ZelBack/src/services/fluxService.js +++ b/ZelBack/src/services/fluxService.js @@ -2,7 +2,8 @@ const cmd = require('node-cmd'); const path = require('path'); const config = require('config'); const fullnode = require('fullnode'); -const fs = require('fs').promises; +const fs = require('fs'); +const fsPromises = fs.promises; const log = require('../lib/log'); const packageJson = require('../../../package.json'); @@ -266,7 +267,7 @@ async function daemonDebug(req, res) { return res.json(errMessage); } // check daemon datadir - const defaultDir = new fullnode.Config().defaultFolderPath(); + const defaultDir = new fullnode.Config().defaultFolder(); const datadir = daemonService.getConfigValue('datadir') || defaultDir; const filepath = `${datadir}/debug.log`; @@ -293,7 +294,7 @@ async function benchmarkDebug(req, res) { async function tailDaemonDebug(req, res) { const authorized = await serviceHelper.verifyAdminAndFluxTeamSession(req.headers); if (authorized === true) { - const defaultDir = new fullnode.Config().defaultFolderPath(); + const defaultDir = new fullnode.Config().defaultFolder(); const datadir = daemonService.getConfigValue('datadir') || defaultDir; const filepath = `${datadir}/debug.log`; const exec = `tail -n 100 ${filepath}`; @@ -613,7 +614,7 @@ async function adjustCruxID(req, res) { } }`; - await fs.writeFile(fluxDirPath, dataToWrite); + await fsPromises.writeFile(fluxDirPath, dataToWrite); const successMessage = serviceHelper.createSuccessMessage('CruxID adjusted'); res.json(successMessage); @@ -658,7 +659,7 @@ async function adjustKadenaAccount(req, res) { } }`; - await fs.writeFile(fluxDirPath, dataToWrite); + await fsPromises.writeFile(fluxDirPath, dataToWrite); const successMessage = serviceHelper.createSuccessMessage('Kadena account adjusted'); res.json(successMessage); diff --git a/ZelBack/src/services/serviceHelper.js b/ZelBack/src/services/serviceHelper.js index 0e4b7199a..a0050e38e 100644 --- a/ZelBack/src/services/serviceHelper.js +++ b/ZelBack/src/services/serviceHelper.js @@ -479,6 +479,10 @@ function verifyZelID(address) { throw new Error('Missing parameters for message verification'); } + if (!address.startsWith('1')) { + throw new Error('Invalid zelID'); + } + if (address.length > 36) { const btcPubKeyHash = '00'; zeltrezjs.address.pubKeyToAddr(address, btcPubKeyHash); @@ -491,7 +495,7 @@ function verifyZelID(address) { return isValid; } -function verifyMessage(message, address, signature) { +function verifyMessage(message, address, signature, strMessageMagic, checkSegwitAlways) { let isValid = false; let signingAddress = address; try { @@ -507,7 +511,7 @@ function verifyMessage(message, address, signature) { // const sigAddress = bitcoinjs.payments.p2pkh({ pubkey: publicKeyBuffer }).address); signingAddress = sigAddress; } - isValid = bitcoinMessage.verify(message, signingAddress, signature); + isValid = bitcoinMessage.verify(message, signingAddress, signature, strMessageMagic, checkSegwitAlways); } catch (e) { log.error(e); isValid = e; diff --git a/ZelBack/src/services/serviceManager.js b/ZelBack/src/services/serviceManager.js index 72a2f29f0..30bc4f8aa 100644 --- a/ZelBack/src/services/serviceManager.js +++ b/ZelBack/src/services/serviceManager.js @@ -44,9 +44,6 @@ async function startFluxFunctions() { daemonService.daemonBlockchainInfoService(); log.info('Flux Daemon Info Service Started'); fluxCommunication.checkDeterministicNodesCollisions(); - setInterval(() => { - fluxCommunication.checkDeterministicNodesCollisions(); - }, 60000); log.info('Flux checks operational'); fluxCommunication.fluxDiscovery(); log.info('Flux Discovery started'); diff --git a/ZelFront/src/components/Apps.vue b/ZelFront/src/components/Apps.vue index 1fd60d418..9a4b7c0ba 100644 --- a/ZelFront/src/components/Apps.vue +++ b/ZelFront/src/components/Apps.vue @@ -1610,7 +1610,7 @@
- Flux: {{ callResponse.data.zelback }} + Flux: {{ callResponse.data.zelback || callResponse.data.flux }}