1
0
Fork 0
forked from svrjs/svrjs

Simplify ES6-style functions

This commit is contained in:
Dorian Niemiec 2024-08-29 19:27:04 +02:00
parent 57d988831f
commit 9f51366515
9 changed files with 37 additions and 74 deletions

View file

@ -32,9 +32,8 @@ function proxyHandler(req, socket, head) {
// SVR.JS configuration object (modified) // SVR.JS configuration object (modified)
const config = deepClone(process.serverConfig); const config = deepClone(process.serverConfig);
config.generateServerString = () => { config.generateServerString = () =>
return generateServerString(config.exposeServerVersion); generateServerString(config.exposeServerVersion);
};
const reqip = socket.remoteAddress; const reqip = socket.remoteAddress;
const reqport = socket.remotePort; const reqport = socket.remotePort;

View file

@ -34,9 +34,8 @@ function requestHandler(req, res) {
// SVR.JS configuration object (modified) // SVR.JS configuration object (modified)
const config = deepClone(process.serverConfig); const config = deepClone(process.serverConfig);
config.generateServerString = () => { config.generateServerString = () =>
return generateServerString(config.exposeServerVersion); generateServerString(config.exposeServerVersion);
};
// getCustomHeaders() in SVR.JS 3.x // getCustomHeaders() in SVR.JS 3.x
config.getCustomHeaders = () => { config.getCustomHeaders = () => {

View file

@ -1719,9 +1719,7 @@ function start(init) {
/^(?:0\.|1\.0\.|1\.1\.[0-9](?![0-9])|1\.1\.1[0-2](?![0-9]))/, /^(?:0\.|1\.0\.|1\.1\.[0-9](?![0-9])|1\.1\.1[0-2](?![0-9]))/,
) )
) && ) &&
process.serverConfig.users.some((entry) => { process.serverConfig.users.some((entry) => entry.pbkdf2)
return entry.pbkdf2;
})
) )
serverconsole.locwarnmessage( serverconsole.locwarnmessage(
"PBKDF2 password hashing function in Bun versions older than v1.1.13 blocks the event loop, which may result in denial of service.", "PBKDF2 password hashing function in Bun versions older than v1.1.13 blocks the event loop, which may result in denial of service.",

View file

@ -42,12 +42,12 @@ process.serverConfig.nonStandardCodes.forEach((nonStandardCodeRaw) => {
if (!cluster.isPrimary) { if (!cluster.isPrimary) {
passwordHashCacheIntervalId = setInterval(() => { passwordHashCacheIntervalId = setInterval(() => {
pbkdf2Cache = pbkdf2Cache.filter((entry) => { pbkdf2Cache = pbkdf2Cache.filter(
return entry.addDate > new Date() - 3600000; (entry) => entry.addDate > new Date() - 3600000,
}); );
scryptCache = scryptCache.filter((entry) => { scryptCache = scryptCache.filter(
return entry.addDate > new Date() - 3600000; (entry) => entry.addDate > new Date() - 3600000,
}); );
}, 1800000); }, 1800000);
} }
@ -192,11 +192,10 @@ module.exports = (req, res, logFacilities, config, next) => {
); );
return; return;
} else { } else {
cacheEntry = scryptCache.find((entry) => { cacheEntry = scryptCache.find(
return ( (entry) =>
entry.password == hashedPassword && entry.salt == list[_i].salt entry.password == hashedPassword && entry.salt == list[_i].salt,
); );
});
if (cacheEntry) { if (cacheEntry) {
cb(cacheEntry.hash); cb(cacheEntry.hash);
} else { } else {
@ -226,11 +225,10 @@ module.exports = (req, res, logFacilities, config, next) => {
); );
return; return;
} else { } else {
cacheEntry = pbkdf2Cache.find((entry) => { cacheEntry = pbkdf2Cache.find(
return ( (entry) =>
entry.password == hashedPassword && entry.salt == list[_i].salt entry.password == hashedPassword && entry.salt == list[_i].salt,
); );
});
if (cacheEntry) { if (cacheEntry) {
cb(cacheEntry.hash); cb(cacheEntry.hash);
} else { } else {

View file

@ -26,9 +26,7 @@ if (!process.singleThreaded) {
cluster.worker = { cluster.worker = {
id: parseInt(process.env.NODE_UNIQUE_ID), id: parseInt(process.env.NODE_UNIQUE_ID),
process: process, process: process,
isDead: () => { isDead: () => false,
return false;
},
send: (message, ...params) => { send: (message, ...params) => {
process.send(message, ...params); process.send(message, ...params);
}, },
@ -98,9 +96,7 @@ if (!process.singleThreaded) {
}); });
newWorker.process = newWorker; newWorker.process = newWorker;
newWorker.isDead = () => { newWorker.isDead = () => newWorker.exitCode !== null || newWorker.killed;
return newWorker.exitCode !== null || newWorker.killed;
};
newWorker.id = newEnvironment.NODE_UNIQUE_ID; newWorker.id = newEnvironment.NODE_UNIQUE_ID;
function checkSendImplementation(worker) { function checkSendImplementation(worker) {

View file

@ -5,9 +5,9 @@ function generateErrorStack(errorObject) {
// If the error stack starts with the error name, return the original stack (it is V8-style then). // If the error stack starts with the error name, return the original stack (it is V8-style then).
if ( if (
errorStack.some((errorStackLine) => { errorStack.some(
return errorStackLine.indexOf(errorObject.name) == 0; (errorStackLine) => errorStackLine.indexOf(errorObject.name) == 0,
}) )
) { ) {
return errorObject.stack; return errorObject.stack;
} }

View file

@ -10,9 +10,8 @@ function ipBlockList(rawBlockList) {
}; };
// Function to normalize IPv4 address (remove leading zeros) // Function to normalize IPv4 address (remove leading zeros)
const normalizeIPv4Address = (address) => { const normalizeIPv4Address = (address) =>
return address.replace(/(^|\.)(?:0(?!\.|$))+/g, "$1"); address.replace(/(^|\.)(?:0(?!\.|$))+/g, "$1");
};
// Function to expand IPv6 address to full format // Function to expand IPv6 address to full format
const expandIPv6Address = (address) => { const expandIPv6Address = (address) => {
@ -236,9 +235,7 @@ function ipBlockList(rawBlockList) {
? checkIfIPv4CIDRMatches ? checkIfIPv4CIDRMatches
: checkIfIPv6CIDRMatches; : checkIfIPv6CIDRMatches;
return instance.cidrs.some((iCidr) => { return instance.cidrs.some((iCidr) => checkMethod(ipParsedObject, iCidr));
return checkMethod(ipParsedObject, iCidr);
});
}; };
// Add initial raw block list values to the instance // Add initial raw block list values to the instance

View file

@ -4,9 +4,8 @@ function ipMatch(IP1, IP2) {
if (!IP2) return false; if (!IP2) return false;
// Function to normalize IPv4 address (remove leading zeros) // Function to normalize IPv4 address (remove leading zeros)
const normalizeIPv4Address = (address) => { const normalizeIPv4Address = (address) =>
return address.replace(/(^|\.)(?:0(?!\.|$))+/g, "$1"); address.replace(/(^|\.)(?:0(?!\.|$))+/g, "$1");
};
// Function to expand IPv6 address to full format // Function to expand IPv6 address to full format
const expandIPv6Address = (address) => { const expandIPv6Address = (address) => {

View file

@ -22,37 +22,14 @@ function sha256(s) {
return (msw << 16) | (lsw & 0xffff); return (msw << 16) | (lsw & 0xffff);
}; };
const S = (X, n) => { const S = (X, n) => (X >>> n) | (X << (32 - n));
return (X >>> n) | (X << (32 - n)); const R = (X, n) => X >>> n;
}; const Ch = (x, y, z) => (x & y) ^ (~x & z);
const Maj = (x, y, z) => (x & y) ^ (x & z) ^ (y & z);
const R = (X, n) => { const Sigma0256 = (x) => S(x, 2) ^ S(x, 13) ^ S(x, 22);
return X >>> n; const Sigma1256 = (x) => S(x, 6) ^ S(x, 11) ^ S(x, 25);
}; const Gamma0256 = (x) => S(x, 7) ^ S(x, 18) ^ R(x, 3);
const Gamma1256 = (x) => S(x, 17) ^ S(x, 19) ^ R(x, 10);
const Ch = (x, y, z) => {
return (x & y) ^ (~x & z);
};
const Maj = (x, y, z) => {
return (x & y) ^ (x & z) ^ (y & z);
};
const Sigma0256 = (x) => {
return S(x, 2) ^ S(x, 13) ^ S(x, 22);
};
const Sigma1256 = (x) => {
return S(x, 6) ^ S(x, 11) ^ S(x, 25);
};
const Gamma0256 = (x) => {
return S(x, 7) ^ S(x, 18) ^ R(x, 3);
};
const Gamma1256 = (x) => {
return S(x, 17) ^ S(x, 19) ^ R(x, 10);
};
function coreSha256(m, l) { function coreSha256(m, l) {
const K = new Array( const K = new Array(