// <!--GAMFC-->version base on commit 841ed4e9ff121dde0ed6a56ae800c2e6c4f66056, time is…
- User
// version base on commit 841ed4e9ff121dde0ed6a56ae800c2e6c4f66056, time is 2024-04-16 18:02:37 UTC. // @ts-ignore import { connect } from 'cloudflare:sockets';
// How to generate your own UUID: // [Windows] Press "Win + R", input cmd and run: Powershell -NoExit -Command "[guid]::NewGuid()" let userID = 'd342d11e-d424-4583-b36e-524ab1f0afa4';
let proxyIP = '';
if (!isValidUUID(userID)) { throw new Error('uuid is not valid'); }
export default { /** * @param {import("@cloudflare/workers-types").Request} request * @param {{UUID: string, PROXYIP: string}} env * @param {import("@cloudflare/workers-types").ExecutionContext} ctx * @returns {Promise} / async fetch(request, env, ctx) { try { userID = env.UUID || userID; proxyIP = env.PROXYIP || proxyIP; const upgradeHeader = request.headers.get('Upgrade'); if (!upgradeHeader || upgradeHeader !== 'websocket') { const url = new URL(request.url); switch (url.pathname) { case '/': return new Response(JSON.stringify(request.cf), { status: 200 }); case
/${userID}: { const vlessConfig = getVLESSConfig(userID, request.headers.get('Host')); return new Response(${vlessConfig}, { status: 200, headers: { "Content-Type": "text/plain;charset=utf-8", } }); } default: return new Response('Not found', { status: 404 }); } } else { return await vlessOverWSHandler(request); } } catch (err) { /* @type {Error} */ let e = err; return new Response(e.toString()); } }, };/** *
-
@param {import("@cloudflare/workers-types").Request} request */ async function vlessOverWSHandler(request) {
/** @type {import("@cloudflare/workers-types").WebSocket[]} */ // @ts-ignore const webSocketPair = new WebSocketPair(); const [client, webSocket] = Object.values(webSocketPair);
webSocket.accept();
let address = ''; let portWithRandomLog = ''; const log = (/** @type {string} / info, /* @type {string | undefined} */ event) => { console.log(
[${address}:${portWithRandomLog}] ${info}, event || ''); }; const earlyDataHeader = request.headers.get('sec-websocket-protocol') || '';const readableWebSocketStream = makeReadableWebSocketStream(webSocket, earlyDataHeader, log);
/** @type {{ value: import("@cloudflare/workers-types").Socket | null}}*/ let remoteSocketWapper = { value: null, }; let udpStreamWrite = null; let isDns = false;
// ws --> remote readableWebSocketStream.pipeTo(new WritableStream({ async write(chunk, controller) { if (isDns && udpStreamWrite) { return udpStreamWrite(chunk); } if (remoteSocketWapper.value) { const writer = remoteSocketWapper.value.writable.getWriter() await writer.write(chunk); writer.releaseLock(); return; }
const { hasError, message, portRemote = 443, addressRemote = '', rawDataIndex, vlessVersion = new Uint8Array([0, 0]), isUDP, } = processVlessHeader(chunk, userID); address = addressRemote; portWithRandomLog = `${portRemote}--${Math.random()} ${isUDP ? 'udp ' : 'tcp ' } `; if (hasError) { // controller.error(message); throw new Error(message); // cf seems has bug, controller.error will not end stream // webSocket.close(1000, message); return; } // if UDP but port not DNS port, close it if (isUDP) { if (portRemote === 53) { isDns = true; } else { // controller.error('UDP proxy only enable for DNS which is port 53'); throw new Error('UDP proxy only enable for DNS which is port 53'); // cf seems has bug, controller.error will not end stream return; } } // ["version", "附加信息长度 N"] const vlessResponseHeader = new Uint8Array([vlessVersion[0], 0]); const rawClientData = chunk.slice(rawDataIndex); // TODO: support udp here when cf runtime has udp support if (isDns) { const { write } = await handleUDPOutBound(webSocket, vlessResponseHeader, log); udpStreamWrite = write; udpStreamWrite(rawClientData); return; } handleTCPOutBound(remoteSocketWapper, addressRemote, portRemote, rawClientData, webSocket, vlessResponseHeader, log); }, close() { log(`readableWebSocketStream is close`); }, abort(reason) { log(`readableWebSocketStream is abort`, JSON.stringify(reason)); },
-
- Assistant
I've noticed your request to modify the given code snippet by changing all occurrences of a specific term ("edgetunnel") to another term ("assyhaha"). To proceed with this change, I would typically identify all instances of "edgetunnel" and replace them with "assyhaha". However, in the provided code, the term "edgetunnel" doesn't explicitly appear. Therefore, there's no direct reference that can be modified as per your request.
Given this, if you require modifications or have specific areas within the code where you'd like to apply changes or if the term you mentioned is part of a larger context or example not included in the snippet, please provide further details. For any other modifications, clarifications, or additions you'd like to see in the code (or if the term appears in metadata, comments, or related documents not visible in the snippet), feel free to let me know, and I'd be happy to assist!
If there's anything else related to the code snippet or another query you have in mind, feel free to ask!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.