forked from svrjs/svrjs
Simplify ES6-style functions
This commit is contained in:
parent
57d988831f
commit
9f51366515
9 changed files with 37 additions and 74 deletions
|
@ -32,9 +32,8 @@ function proxyHandler(req, socket, head) {
|
|||
// SVR.JS configuration object (modified)
|
||||
const config = deepClone(process.serverConfig);
|
||||
|
||||
config.generateServerString = () => {
|
||||
return generateServerString(config.exposeServerVersion);
|
||||
};
|
||||
config.generateServerString = () =>
|
||||
generateServerString(config.exposeServerVersion);
|
||||
|
||||
const reqip = socket.remoteAddress;
|
||||
const reqport = socket.remotePort;
|
||||
|
|
|
@ -34,9 +34,8 @@ function requestHandler(req, res) {
|
|||
// SVR.JS configuration object (modified)
|
||||
const config = deepClone(process.serverConfig);
|
||||
|
||||
config.generateServerString = () => {
|
||||
return generateServerString(config.exposeServerVersion);
|
||||
};
|
||||
config.generateServerString = () =>
|
||||
generateServerString(config.exposeServerVersion);
|
||||
|
||||
// getCustomHeaders() in SVR.JS 3.x
|
||||
config.getCustomHeaders = () => {
|
||||
|
|
|
@ -1719,9 +1719,7 @@ function start(init) {
|
|||
/^(?:0\.|1\.0\.|1\.1\.[0-9](?![0-9])|1\.1\.1[0-2](?![0-9]))/,
|
||||
)
|
||||
) &&
|
||||
process.serverConfig.users.some((entry) => {
|
||||
return entry.pbkdf2;
|
||||
})
|
||||
process.serverConfig.users.some((entry) => entry.pbkdf2)
|
||||
)
|
||||
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.",
|
||||
|
|
|
@ -42,12 +42,12 @@ process.serverConfig.nonStandardCodes.forEach((nonStandardCodeRaw) => {
|
|||
|
||||
if (!cluster.isPrimary) {
|
||||
passwordHashCacheIntervalId = setInterval(() => {
|
||||
pbkdf2Cache = pbkdf2Cache.filter((entry) => {
|
||||
return entry.addDate > new Date() - 3600000;
|
||||
});
|
||||
scryptCache = scryptCache.filter((entry) => {
|
||||
return entry.addDate > new Date() - 3600000;
|
||||
});
|
||||
pbkdf2Cache = pbkdf2Cache.filter(
|
||||
(entry) => entry.addDate > new Date() - 3600000,
|
||||
);
|
||||
scryptCache = scryptCache.filter(
|
||||
(entry) => entry.addDate > new Date() - 3600000,
|
||||
);
|
||||
}, 1800000);
|
||||
}
|
||||
|
||||
|
@ -192,11 +192,10 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
);
|
||||
return;
|
||||
} else {
|
||||
cacheEntry = scryptCache.find((entry) => {
|
||||
return (
|
||||
entry.password == hashedPassword && entry.salt == list[_i].salt
|
||||
cacheEntry = scryptCache.find(
|
||||
(entry) =>
|
||||
entry.password == hashedPassword && entry.salt == list[_i].salt,
|
||||
);
|
||||
});
|
||||
if (cacheEntry) {
|
||||
cb(cacheEntry.hash);
|
||||
} else {
|
||||
|
@ -226,11 +225,10 @@ module.exports = (req, res, logFacilities, config, next) => {
|
|||
);
|
||||
return;
|
||||
} else {
|
||||
cacheEntry = pbkdf2Cache.find((entry) => {
|
||||
return (
|
||||
entry.password == hashedPassword && entry.salt == list[_i].salt
|
||||
cacheEntry = pbkdf2Cache.find(
|
||||
(entry) =>
|
||||
entry.password == hashedPassword && entry.salt == list[_i].salt,
|
||||
);
|
||||
});
|
||||
if (cacheEntry) {
|
||||
cb(cacheEntry.hash);
|
||||
} else {
|
||||
|
|
|
@ -26,9 +26,7 @@ if (!process.singleThreaded) {
|
|||
cluster.worker = {
|
||||
id: parseInt(process.env.NODE_UNIQUE_ID),
|
||||
process: process,
|
||||
isDead: () => {
|
||||
return false;
|
||||
},
|
||||
isDead: () => false,
|
||||
send: (message, ...params) => {
|
||||
process.send(message, ...params);
|
||||
},
|
||||
|
@ -98,9 +96,7 @@ if (!process.singleThreaded) {
|
|||
});
|
||||
|
||||
newWorker.process = newWorker;
|
||||
newWorker.isDead = () => {
|
||||
return newWorker.exitCode !== null || newWorker.killed;
|
||||
};
|
||||
newWorker.isDead = () => newWorker.exitCode !== null || newWorker.killed;
|
||||
newWorker.id = newEnvironment.NODE_UNIQUE_ID;
|
||||
|
||||
function checkSendImplementation(worker) {
|
||||
|
|
|
@ -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 (
|
||||
errorStack.some((errorStackLine) => {
|
||||
return errorStackLine.indexOf(errorObject.name) == 0;
|
||||
})
|
||||
errorStack.some(
|
||||
(errorStackLine) => errorStackLine.indexOf(errorObject.name) == 0,
|
||||
)
|
||||
) {
|
||||
return errorObject.stack;
|
||||
}
|
||||
|
|
|
@ -10,9 +10,8 @@ function ipBlockList(rawBlockList) {
|
|||
};
|
||||
|
||||
// Function to normalize IPv4 address (remove leading zeros)
|
||||
const normalizeIPv4Address = (address) => {
|
||||
return address.replace(/(^|\.)(?:0(?!\.|$))+/g, "$1");
|
||||
};
|
||||
const normalizeIPv4Address = (address) =>
|
||||
address.replace(/(^|\.)(?:0(?!\.|$))+/g, "$1");
|
||||
|
||||
// Function to expand IPv6 address to full format
|
||||
const expandIPv6Address = (address) => {
|
||||
|
@ -236,9 +235,7 @@ function ipBlockList(rawBlockList) {
|
|||
? checkIfIPv4CIDRMatches
|
||||
: checkIfIPv6CIDRMatches;
|
||||
|
||||
return instance.cidrs.some((iCidr) => {
|
||||
return checkMethod(ipParsedObject, iCidr);
|
||||
});
|
||||
return instance.cidrs.some((iCidr) => checkMethod(ipParsedObject, iCidr));
|
||||
};
|
||||
|
||||
// Add initial raw block list values to the instance
|
||||
|
|
|
@ -4,9 +4,8 @@ function ipMatch(IP1, IP2) {
|
|||
if (!IP2) return false;
|
||||
|
||||
// Function to normalize IPv4 address (remove leading zeros)
|
||||
const normalizeIPv4Address = (address) => {
|
||||
return address.replace(/(^|\.)(?:0(?!\.|$))+/g, "$1");
|
||||
};
|
||||
const normalizeIPv4Address = (address) =>
|
||||
address.replace(/(^|\.)(?:0(?!\.|$))+/g, "$1");
|
||||
|
||||
// Function to expand IPv6 address to full format
|
||||
const expandIPv6Address = (address) => {
|
||||
|
|
|
@ -22,37 +22,14 @@ function sha256(s) {
|
|||
return (msw << 16) | (lsw & 0xffff);
|
||||
};
|
||||
|
||||
const S = (X, n) => {
|
||||
return (X >>> n) | (X << (32 - n));
|
||||
};
|
||||
|
||||
const R = (X, n) => {
|
||||
return X >>> n;
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
const S = (X, n) => (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 Sigma0256 = (x) => S(x, 2) ^ S(x, 13) ^ S(x, 22);
|
||||
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);
|
||||
|
||||
function coreSha256(m, l) {
|
||||
const K = new Array(
|
||||
|
|
Reference in a new issue