mirror of
https://github.com/lush2020/edgetunnel.git
synced 2026-03-21 17:12:33 +08:00
remove the websocket package send limit.
This commit is contained in:
@@ -113,7 +113,7 @@ async function vlessOverWSHandler(request) {
|
||||
const isCFIp = await isCloudFlareIP(addressType, addressRemote);
|
||||
if(isCFIp) {
|
||||
redirectIp = proxyIP || clientIP;
|
||||
console.log(`is cf ip ${addressRemote} redirect to ${redirectIp}`);
|
||||
console.log(`is cf ip ${addressRemote} redirect to ${redirectIp || '<not found any redirectIp>'}`);
|
||||
}
|
||||
const tcpSocket = connect({
|
||||
hostname: redirectIp || addressRemote,
|
||||
@@ -215,7 +215,6 @@ function makeReadableWebSocketStream(webSocketServer, earlyDataHeader, log) {
|
||||
}
|
||||
|
||||
//https://github.com/v2ray/v2ray-core/issues/2636
|
||||
// protocol doc https://www.v2fly.org/chapter_02/protocols/vless.html
|
||||
// https://github.com/zizifn/excalidraw-backup/blob/main/v2ray-protocol.excalidraw
|
||||
|
||||
/**
|
||||
@@ -229,8 +228,6 @@ function processVlessHeader(
|
||||
userID
|
||||
) {
|
||||
if (vlessBuffer.byteLength < 24) {
|
||||
// console.log('invalid data');
|
||||
// controller.error('invalid data');
|
||||
return {
|
||||
hasError: true,
|
||||
message: 'invalid data',
|
||||
@@ -362,7 +359,7 @@ function remoteSocketToWS(remoteSocket, webSocket, log, vlessResponseHeader) {
|
||||
* @param {*} controller
|
||||
*/
|
||||
async write(chunk, controller) {
|
||||
remoteChunkCount++;
|
||||
// remoteChunkCount++;
|
||||
if (webSocket.readyState === WS_READY_STATE_OPEN) {
|
||||
|
||||
// if (remoteChunkCount < 20) {
|
||||
@@ -377,10 +374,12 @@ function remoteSocketToWS(remoteSocket, webSocket, log, vlessResponseHeader) {
|
||||
// await delay(500); // 4kb * 1000 = 4m/s
|
||||
// }
|
||||
// }
|
||||
if (remoteChunkCount > 20000) {
|
||||
// cf one package is 4096 byte(4kb), 4096 * 20000 = 80M
|
||||
await delay(1);
|
||||
}
|
||||
|
||||
// seems no need rate limit this, CF seems fix this..
|
||||
// if (remoteChunkCount > 20000) {
|
||||
// // cf one package is 4096 byte(4kb), 4096 * 20000 = 80M
|
||||
// await delay(1);
|
||||
// }
|
||||
webSocket.send(chunk);
|
||||
} else {
|
||||
controller.error(
|
||||
|
||||
@@ -30,4 +30,64 @@ function delay(ms) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks if an IPv4 address is within a CIDR range.
|
||||
*
|
||||
* @param {string} address The IPv4 address to check.
|
||||
* @param {string} cidr The CIDR range to check against.
|
||||
* @returns {boolean} `true` if the address is within the CIDR range, `false` otherwise.
|
||||
*/
|
||||
function isIPv4InRange(address, cidr) {
|
||||
// Parse the address and CIDR range
|
||||
const addressParts = address.split('.').map(part => parseInt(part, 10));
|
||||
const [rangeAddress, rangePrefix] = cidr.split('/');
|
||||
const rangeParts = rangeAddress.split('.').map(part => parseInt(part, 10));
|
||||
const prefix = parseInt(rangePrefix, 10);
|
||||
|
||||
// Convert the address and range to binary format
|
||||
const addressBinary = addressParts.reduce((acc, part) => acc + part.toString(2).padStart(8, '0'), '');
|
||||
const rangeBinary = rangeParts.reduce((acc, part) => acc + part.toString(2).padStart(8, '0'), '');
|
||||
|
||||
// Compare the bits up to the prefix length
|
||||
for (let i = 0; i < prefix; i++) {
|
||||
if (addressBinary[i] !== rangeBinary[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an IPv6 address is within a CIDR range.
|
||||
*
|
||||
* @param {string} address The IPv6 address to check.
|
||||
* @param {string} cidr The CIDR range to check against.
|
||||
* @returns {boolean} `true` if the address is within the CIDR range, `false` otherwise.
|
||||
*/
|
||||
function isIPv6InRange(address, cidr) {
|
||||
// Parse the address and CIDR range
|
||||
const addressParts = address.split(':').map(part => parseInt(part, 16));
|
||||
const [rangeAddress, rangePrefix] = cidr.split('/');
|
||||
const rangeParts = rangeAddress.split(':').map(part => parseInt(part, 16));
|
||||
const prefix = parseInt(rangePrefix, 10);
|
||||
|
||||
// Convert the address and range to binary format
|
||||
const addressBinary = addressParts.reduce((acc, part) => acc + part.toString(2).padStart(16, '0'), '');
|
||||
const rangeBinary = rangeParts.reduce((acc, part) => acc + part.toString(2).padStart(16, '0'), '');
|
||||
|
||||
// Compare the bits up to the prefix length
|
||||
for (let i = 0; i < prefix; i++) {
|
||||
if (addressBinary[i] !== rangeBinary[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user