Skip to content

Commit

Permalink
Merge pull request #1061 from RunOnFlux/development
Browse files Browse the repository at this point in the history
v4.4.0
  • Loading branch information
TheTrunk authored Jul 18, 2023
2 parents 3289298 + ba226ab commit 83b9036
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 12 deletions.
3 changes: 0 additions & 3 deletions ZelBack/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,6 @@ module.exports = (app, expressWs) => {
app.get('/syncthing/system/error/:message?', cache('30 seconds'), (req, res) => {
syncthingService.systemError(req, res);
});
app.get('/syncthing/system/error/:message?', cache('30 seconds'), (req, res) => {
syncthingService.systemError(req, res);
});
app.get('/syncthing/system/log/:since?', cache('30 seconds'), (req, res) => {
syncthingService.systemLog(req, res);
});
Expand Down
4 changes: 3 additions & 1 deletion ZelBack/src/services/appsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -9246,7 +9246,8 @@ async function forceAppRemovals() {
});

// array of unique main app names
const dockerAppsTrueNameB = [...new Set(dockerAppsTrueNames)];
let dockerAppsTrueNameB = [...new Set(dockerAppsTrueNames)];
dockerAppsTrueNameB = dockerAppsTrueNameB.filter((appName) => appName !== 'watchtower');
// eslint-disable-next-line no-restricted-syntax
for (const dApp of dockerAppsTrueNameB) {
// check if app is in installedApps
Expand Down Expand Up @@ -9597,6 +9598,7 @@ async function checkMyAppsAvailability() {
const min = minPort;
const max = maxPort;
testingPort = failedPort || Math.floor(Math.random() * (max - min) + min);
log.info(`checkMyAppsAvailability testing port ${testingPort}.`);
const iBP = fluxNetworkHelper.isPortBanned(testingPort);
if (iBP) {
failedPort = null;
Expand Down
19 changes: 14 additions & 5 deletions ZelBack/src/services/explorerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ async function processInsight(blockDataVerbose, database) {
};
// Unique hash - If we already have a hash of this app in our database, do not insert it!
try {
// 5501c7dd6516c3fc2e68dee8d4fdd20d92f57f8cfcdc7b4fcbad46499e43ed6f
// 5501c7dd6516c3fc2e68dee8d4fdd20d92f57f8cfcdc7b4fcbad46499e43ed6f
const querySearch = {
hash: message,
};
Expand Down Expand Up @@ -574,7 +574,7 @@ async function processStandard(blockDataVerbose, database) {
};
// Unique hash - If we already have a hash of this app in our database, do not insert it!
try {
// 5501c7dd6516c3fc2e68dee8d4fdd20d92f57f8cfcdc7b4fcbad46499e43ed6f
// 5501c7dd6516c3fc2e68dee8d4fdd20d92f57f8cfcdc7b4fcbad46499e43ed6f
const querySearch = {
hash: message,
};
Expand Down Expand Up @@ -1401,7 +1401,7 @@ async function getAddressTransactions(req, res) {
query: {},
};
const insightResult = await daemonServiceAddressRpcs.getSingleAddresssTxids(daemonRequest);
const txids = insightResult.data.reverse();
const txids = insightResult.data.reverse(); // from newest txid to lastest [{txid:'abc'}, {txid: 'efg'}]
const txidsOK = [];
txids.forEach((txid) => {
txidsOK.push({
Expand All @@ -1416,8 +1416,17 @@ async function getAddressTransactions(req, res) {
const query = { address };
const distinct = 'transactions';
const results = await dbHelper.distinctDatabase(database, addressTransactionIndexCollection, distinct, query);
// TODO FIX documentation. UPDATE for an amount of last txs needed.
// now we have array of transactions [{txid, height}, {}...]
// sort by height, newest first
// only return txids
results.sort((a, b) => {
if (a.height > b.height) return -1;
if (a.height < b.height) return 1;
return 0;
});
// eslint-disable-next-line no-param-reassign
results.map((tx) => delete tx.height);
// TODO FIX documentation.
// now we have array of transactions txids only sorted from newest to latest [{txid}, {}...]
const resMessage = messageHelper.createDataMessage(results);
res.json(resMessage);
}
Expand Down
8 changes: 6 additions & 2 deletions ZelBack/src/services/fluxCommunication.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,14 +592,15 @@ async function fluxDiscovery() {
log.info(`Current number of incoming connections:${incomingConnections.length}`);
// always try to connect to deterministic nodes
// established deterministic outgoing connections
let deterministicPeerConnections = false;
for (let i = 1; i <= minDeterministicOutPeers; i += 1) {
const fixedIndex = fluxNodeIndex + i < sortedNodeList.length ? fluxNodeIndex + i : fluxNodeIndex + i - sortedNodeList.length;
const { ip } = sortedNodeList[fixedIndex];
// additional precaution
const clientExists = outgoingConnections.find((client) => client._socket.remoteAddress === ip);
const clientIncomingExists = incomingConnections.find((client) => client._socket.remoteAddress.replace('::ffff:', '') === ip);
if (!clientExists && !clientIncomingExists) {
log.info(`Adding Flux peer: ${ip}`);
deterministicPeerConnections = true;
initiateAndHandleConnection(ip);
// eslint-disable-next-line no-await-in-loop
await serviceHelper.delay(500);
Expand All @@ -612,13 +613,16 @@ async function fluxDiscovery() {
// additional precaution
const clientIncomingExists = incomingConnections.find((client) => client._socket.remoteAddress.replace('::ffff:', '') === ip);
if (!clientIncomingExists) {
log.info(`Asking Flux ${ip} to add us as a peer`);
deterministicPeerConnections = true;
const ipInc = ip.split(':')[0];
const portInc = ip.split(':')[1] || 16127;
// eslint-disable-next-line no-await-in-loop
await serviceHelper.axiosGet(`http://${ipInc}:${portInc}/flux/addoutgoingpeer/${myIP}`).catch((error) => log.error(error));
}
}
if (deterministicPeerConnections) {
log.info('Connections to deterministic peers established');
}

await serviceHelper.delay(500);
let index = 0;
Expand Down
14 changes: 14 additions & 0 deletions ZelBack/src/services/fluxNetworkHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,19 @@ function lruRateLimit(ip, limitPerSecond = 20) {
return true;
}

/**
* Allow Node to bind to privileged without sudo
*/
async function allowNodeToBindPrivilegedPorts() {
try {
const exec = "sudo setcap 'cap_net_bind_service=+ep' `which node`";
const cmdAsync = util.promisify(nodecmd.get);
await cmdAsync(exec);
} catch (error) {
log.error(error);
}
}

module.exports = {
minVersionSatisfy,
isFluxAvailable,
Expand Down Expand Up @@ -1391,4 +1404,5 @@ module.exports = {
isPortEnterprise,
isPortBanned,
isPortUserBlocked,
allowNodeToBindPrivilegedPorts,
};
2 changes: 2 additions & 0 deletions ZelBack/src/services/serviceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ async function startFluxFunctions() {
log.info('Flux Apps locations prepared');
fluxNetworkHelper.adjustFirewall();
log.info('Firewalls checked');
fluxNetworkHelper.allowNodeToBindPrivilegedPorts();
log.info('Node allowed to bind privileged ports');
fluxCommunication.keepConnectionsAlive();
log.info('Connections polling prepared');
daemonServiceMiscRpcs.daemonBlockchainInfoService();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flux",
"version": "4.3.0",
"version": "4.4.0",
"description": "Flux, Your Gateway to a Decentralized World",
"repository": {
"type": "git",
Expand Down

0 comments on commit 83b9036

Please sign in to comment.