mirror of
https://github.com/zizifn/edgetunnel
synced 2024-11-22 18:07:07 +00:00
refactor code
This commit is contained in:
parent
990f001d1b
commit
3b9737b7ba
@ -61,8 +61,7 @@ async function vlessOverWSHandler(request) {
|
||||
const earlyDataHeader = request.headers.get('sec-websocket-protocol') || '';
|
||||
|
||||
// only try to get client ip as redirect ip when client is not in China
|
||||
const isCN = request.headers.get('cf-ipcountry')?.toUpperCase() !== 'CN';
|
||||
const clientIP = isCN ? request.headers.get('cf-connecting-ip') || '' : '';
|
||||
const clientIP = getClientIp(request);
|
||||
|
||||
const readableWebSocketStream = makeReadableWebSocketStream(webSocket, earlyDataHeader, log);
|
||||
|
||||
@ -148,6 +147,7 @@ async function vlessOverWSHandler(request) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import("@cloudflare/workers-types").WebSocket} webSocketServer
|
||||
@ -382,7 +382,6 @@ function remoteSocketToWS(remoteSocket, webSocket, log, vlessResponseHeader) {
|
||||
await delay(1);
|
||||
}
|
||||
webSocket.send(chunk);
|
||||
console.log(chunk.byteLength);
|
||||
} else {
|
||||
controller.error(
|
||||
'webSocket.readyState is not open, maybe close'
|
||||
@ -427,6 +426,17 @@ function base64ToArrayBuffer(base64Str) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import("@cloudflare/workers-types").Request} request
|
||||
* @returns
|
||||
*/
|
||||
function getClientIp(request) {
|
||||
const isCN = request.headers.get('cf-ipcountry')?.toUpperCase() !== 'CN';
|
||||
const clientIP = isCN ? request.headers.get('cf-connecting-ip') || '' : '';
|
||||
return clientIP;
|
||||
}
|
||||
|
||||
/**
|
||||
* // 1--> ipv4 addressLength =4
|
||||
* // 2--> domain name addressLength=addressBuffer[1]
|
||||
@ -450,7 +460,7 @@ async function isCloudFlareIP(addressType, addressRemote) {
|
||||
if(addressType === 2)
|
||||
{
|
||||
const domainIP = await doh(addressRemote);
|
||||
console.log(' domainIP ', domainIP);
|
||||
// console.log(' domainIP ', domainIP);
|
||||
return isIPv4InCFCIDR(domainIP);
|
||||
}
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user