From 16be3409bbc2be039c50e8c4db30c4504b35c5ae Mon Sep 17 00:00:00 2001 From: RunOnFlux Date: Tue, 14 Nov 2023 10:00:39 +0000 Subject: [PATCH] Update from https://github.com/RunOnFlux/flux/commit/4eb8b9f67afba44a3d1a670d7cf6d4eca9b5bb64 --- services/fluxCommunication.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/services/fluxCommunication.js b/services/fluxCommunication.js index 4763ce3c..46ba6c1f 100644 --- a/services/fluxCommunication.js +++ b/services/fluxCommunication.js @@ -1,3 +1,4 @@ +/* global userconfig */ /* eslint-disable no-underscore-dangle */ const config = require('config'); const { LRUCache } = require('lru-cache'); @@ -466,7 +467,15 @@ async function initiateAndHandleConnection(connection) { socketPortsInformationActive = true; } } - if (socketPortsInformationActive) { + const development = userconfig.initial.development || false; + let devNode = false; + if (development) { + const developmentNodes = ['94.16.104.218', '46.38.251.26', '45.129.182.59', '89.58.37.73', '37.221.197.179', '89.58.42.201', '185.16.61.122', '37.120.175.86', '46.38.236.130', '5.45.111.210']; + if (developmentNodes.indexOf(connection) > -1) { + devNode = true; + } + } + if (socketPortsInformationActive || devNode) { const myIP = await fluxNetworkHelper.getMyFluxIPandPort(); const myPort = myIP.split(':')[1] || 16127; wsuri = `ws://${ip}:${port}/ws/flux/${myPort}`; @@ -809,6 +818,24 @@ async function fluxDiscovery() { await serviceHelper.delay(500); } index = 0; + const development = userconfig.initial.development || false; + while (development && incomingConnections.length < 4 && index < 20) { + index += 1; + const developmentNodes = ['94.16.104.218', '46.38.251.26', '45.129.182.59', '89.58.37.73', '37.221.197.179', '89.58.42.201', '185.16.61.122', '37.120.175.86', '46.38.236.130', '5.45.111.210']; + const devConnection = developmentNodes[Math.floor(Math.random() * developmentNodes.length)]; + const ipInc = devConnection.split(':')[0]; + const portInc = devConnection.split(':')[1] || 16127; + const sameConnectedIp = currentIpsConnTried.find((connectedIP) => connectedIP === ipInc); + const clientExists = outgoingConnections.find((client) => client._socket.remoteAddress === ipInc && client.port === portInc); + const clientIncomingExists = incomingConnections.find((client) => client._socket.remoteAddress.replace('::ffff:', '') === ipInc && client.port === portInc); + if (!sameConnectedIp && !clientExists && !clientIncomingExists) { + log.info(`Asking development Flux ${devConnection} to add us as a peer`); + currentIpsConnTried.push(devConnection); + // eslint-disable-next-line no-await-in-loop + await serviceHelper.axiosGet(`http://${ipInc}:${portInc}/flux/addoutgoingpeer/${myIP}`).catch((error) => log.error(error)); + } + } + index = 0; while ((incomingConnections.length < 10 || [...new Set(incomingConnections.map((client) => client._socket.remoteAddress))].length < 5) && index < 100) { // Max of 14 outgoing connections - 12 possible deterministic + min. 2 random (we will get more random as others nodes have more random outgoing connections) index += 1; // eslint-disable-next-line no-await-in-loop