Skip to content

Commit

Permalink
change location where we broadcast to the network ip changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Cabecinha84 committed Oct 29, 2023
1 parent 2483d05 commit 81a8fae
Showing 1 changed file with 35 additions and 30 deletions.
65 changes: 35 additions & 30 deletions ZelBack/src/services/fluxNetworkHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,33 +730,6 @@ async function checkMyFluxAvailability(retryNumber = 0) {
await serviceHelper.delay(2 * 1000); // await two seconds
const newIP = await getMyFluxIPandPort(); // to update node Ip on FluxOs;
if (newIP && newIP !== oldIP) { // double check
log.info(`New public Ip detected: ${newIP}, old Ip:${oldIP} , updating the FluxNode info in the network`);
// eslint-disable-next-line global-require
const dockerService = require('./dockerService');
let apps = await dockerService.dockerListContainers(true);
if (apps.length > 0) {
apps = apps.filter((app) => ((app.Names[0].slice(1, 4) === 'zel' || app.Names[0].slice(1, 5) === 'flux') && app.Names[0] !== '/flux_watchtower'));
}
if (apps.length > 0) {
const broadcastedAt = new Date().getTime();
const newIpChangedMessage = {
type: 'fluxipchanged',
version: 1,
oldIP,
newIP,
broadcastedAt,
};
// broadcast messages about ip changed to all peers
// eslint-disable-next-line global-require
const fluxCommunicationMessagesSender = require('./fluxCommunicationMessagesSender');
await fluxCommunicationMessagesSender.broadcastMessageToOutgoing(newIpChangedMessage);
await serviceHelper.delay(500);
await fluxCommunicationMessagesSender.broadcastMessageToIncoming(newIpChangedMessage);
await serviceHelper.delay(1 * 60 * 1000); // lets wait 1 minute to give time for message being propagated on the network before we try to update the ip on blockchain
}
const result = await daemonServiceWalletRpcs.createConfirmationTransaction();
log.info(`createConfirmationTransaction: ${result}`);
await serviceHelper.delay(4 * 60 * 1000); // lets wait 2 blocks time for the transaction to be mined
return true;
}
} if (benchMyIP && benchMyIP.split(':')[0] === myIP.split(':')[0]) {
Expand Down Expand Up @@ -833,6 +806,38 @@ async function adjustExternalIP(ip) {
if (ip === userconfig.initial.ipaddress) {
return;
}
if (userconfig.initial.ipaddress && v4exact.test(userconfig.initial.ipaddress)) {
const newIP = `${ip}:${userconfig.initial.apiport}`;
const oldIP = `${userconfig.initial.ipaddress}:${userconfig.initial.apiport}`;
log.info(`New public Ip detected: ${newIP}, old Ip:${oldIP} , updating the FluxNode info in the network`);
// eslint-disable-next-line global-require
const dockerService = require('./dockerService');
let apps = await dockerService.dockerListContainers(true);
if (apps.length > 0) {
apps = apps.filter((app) => ((app.Names[0].slice(1, 4) === 'zel' || app.Names[0].slice(1, 5) === 'flux') && app.Names[0] !== '/flux_watchtower'));
}
if (apps.length > 0) {
const broadcastedAt = new Date().getTime();
const newIpChangedMessage = {
type: 'fluxipchanged',
version: 1,
oldIP,
newIP,
broadcastedAt,
};
// broadcast messages about ip changed to all peers
// eslint-disable-next-line global-require
const fluxCommunicationMessagesSender = require('./fluxCommunicationMessagesSender');
await fluxCommunicationMessagesSender.broadcastMessageToOutgoing(newIpChangedMessage);
await serviceHelper.delay(500);
await fluxCommunicationMessagesSender.broadcastMessageToIncoming(newIpChangedMessage);
await serviceHelper.delay(1 * 60 * 1000); // lets wait 1 minute to give time for message being propagated on the network before we try to update the ip on blockchain
}
const result = await daemonServiceWalletRpcs.createConfirmationTransaction();
log.info(`createConfirmationTransaction: ${result}`);
await serviceHelper.delay(4 * 60 * 1000); // lets wait 2 blocks time for the transaction to be mined
}

log.info(`Adjusting External IP from ${userconfig.initial.ipaddress} to ${ip}`);
const dataToWrite = `module.exports = {
initial: {
Expand Down Expand Up @@ -914,20 +919,20 @@ async function checkDeterministicNodesCollisions() {
if (nodeList.length > config.fluxapps.minIncoming + config.fluxapps.minOutgoing) {
const availabilityOk = await checkMyFluxAvailability();
if (availabilityOk) {
adjustExternalIP(myIP.split(':')[0]);
await adjustExternalIP(myIP.split(':')[0]);
}
} else { // sufficient amount of nodes has to appear on the network within 6 hours
const measuredUptime = fluxUptime();
if (measuredUptime.status === 'success' && measuredUptime.data > (config.fluxapps.minUpTime * 12)) {
const availabilityOk = await checkMyFluxAvailability();
if (availabilityOk) {
adjustExternalIP(myIP.split(':')[0]);
await adjustExternalIP(myIP.split(':')[0]);
}
} else if (measuredUptime.status === 'error') {
log.error('Flux uptime unavailable');
const availabilityOk = await checkMyFluxAvailability();
if (availabilityOk) {
adjustExternalIP(myIP.split(':')[0]);
await adjustExternalIP(myIP.split(':')[0]);
}
}
}
Expand Down

0 comments on commit 81a8fae

Please sign in to comment.