diff --git a/README.md b/README.md index 2d2dbfc..f18deb1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -
-

+
+

bepass-worker

@@ -15,7 +15,7 @@ bepass-worker - [Manual Deployment](#manual-deployment) - [🗺 Roadmap](#-roadmap) - [🤝 Contributing](#-contributing) -- [نسخه فارسی](https://github.com/ErfanTech/bepass-worker/blob/main/README-FA.md) +- [نسخه فارسی](https://github.com/uoosef/bepass-worker/blob/main/README-FA.md) --- @@ -26,17 +26,17 @@ This repository contains a new worker.js that aims for better solutions in terms As you know, Cloudflare workers are currently unable to connect to hosts that have Cloudflare IPs (this is considered a loopback).This worker uses relay nodes to work around that limitation. -The worker also implements a simple DNS proxy by forwarding DNS queries to a custom DNS server specified in the dnsHost variable. +The worker also implements an advanced DNS DOH client/proxy for dns routing/serving purposes. --- ## ⚙️ Features - Supports IPv6 -- Supports UDP -- More reliable loopback connections to Cloudflare IPs +- Supports UDP through relays +- More reliable loopback connection handling and routing +- Embedded DOH DNS Client/Proxy - Overall improved performance and stability -- DNS --- @@ -57,13 +57,7 @@ The worker also implements a simple DNS proxy by forwarding DNS queries to a cus ## 🚀 Deploying a Worker -### One-Click Deploy - -You can deploy this worker to your Cloudflare account automatically with one click using the button below. - -[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/user/bepass-worker) - -### Manual Deployment +### Manual Deployment (recommended) To manually deploy the worker: @@ -78,7 +72,15 @@ To manually deploy the worker: 9. Click the **Save and Deploy** button 10. Write down the newly created worker address, it should be something like **[name].[username].workers.dev** 11. Change your Bepass configuration to **https://[name].[username].workers.dev/dns-query** - --- + +### One-Click Deploy (experienced users only) + +You can deploy this worker to your Cloudflare account automatically with one click using the button below. + +[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/user/bepass-worker) + +--- + ### Add your own relay **1. Follow the [relay set-up instructions](https://github.com/uoosef/cf-bepass#how-to-share-my-node-becoming-a-volunteer-maintainer) to run your own relay server.** diff --git a/dist/worker.js b/dist/worker.js index f99579b..637232c 100644 --- a/dist/worker.js +++ b/dist/worker.js @@ -4647,7 +4647,7 @@ var Message = class { // src/worker.ts var proxyIPs = ["relay1.bepass.org", "relay2.bepass.org", "relay3.bepass.org"]; var proxyPort = 6666; -var proxyIP = proxyIPs[Math.floor(Math.random() * proxyIPs.length)]; +var proxyIP = proxyIPs[0]; var dnsHost = "1.1.1.1"; var WS_READY_STATE_OPEN = 1; var WS_READY_STATE_CLOSING = 2; @@ -4708,6 +4708,7 @@ async function bepassOverWs(request) { }); const destinationHost = params["host"]; const destinationPort = params["port"]; + proxyIP = params["session"] ? proxyIPs[parseInt(params["session"]) % proxyIPs.length] : proxyIPs[Math.floor(Math.random() * proxyIPs.length)]; const destinationNetwork = params["net"] ? params["net"].toString().toLowerCase() : "tcp"; const webSocketPair = new WebSocketPair(); const [client, webSocket] = Object.values(webSocketPair); @@ -4787,6 +4788,7 @@ function makeReadableWebSocketStream(webSocketServer, log) { } async function handleTCPOutBound(remoteSocket, destinationNetwork, addressRemote, portRemote, rawClientData, webSocket, log) { async function connectAndWrite(address, port, rawHeaderEnabled) { + address = address.replace("[", "").replace("]", ""); const mmd = destinationNetwork + "@" + addressRemote + "$" + portRemote; if (!isIP(address)) { const ip = await lookup(address); @@ -4799,6 +4801,9 @@ async function handleTCPOutBound(remoteSocket, destinationNetwork, addressRemote port = proxyPort; rawHeaderEnabled = true; } + if (address.includes(":")) { + address = "[" + address + "]"; + } const tcpSocket2 = connect({ hostname: address, port diff --git a/src/worker.ts b/src/worker.ts index fed85b1..caa5f98 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -7,7 +7,7 @@ import Message from './dns'; const proxyIPs = ["relay1.bepass.org", "relay2.bepass.org", "relay3.bepass.org"]; const proxyPort = 6666; -let proxyIP = proxyIPs[Math.floor(Math.random() * proxyIPs.length)]; +let proxyIP = proxyIPs[0]; const dnsHost = "1.1.1.1" const WS_READY_STATE_OPEN = 1; const WS_READY_STATE_CLOSING = 2; @@ -73,6 +73,7 @@ async function bepassOverWs(request: Request) { const destinationHost = params["host"] const destinationPort = params["port"] + proxyIP = params["session"] ? proxyIPs[parseInt(params["session"])%proxyIPs.length] : proxyIPs[Math.floor(Math.random() * proxyIPs.length)] const destinationNetwork = params["net"] ? params["net"].toString().toLowerCase() : "tcp" const webSocketPair = new WebSocketPair(); @@ -182,6 +183,7 @@ function longToByteArray(long: number) { async function handleTCPOutBound(remoteSocket: any, destinationNetwork: any, addressRemote: any, portRemote: any, rawClientData: any, webSocket: any, log: any) { async function connectAndWrite(address: string, port: number, rawHeaderEnabled: boolean) { + address = address.replace("[", "").replace("]", "") const mmd = destinationNetwork + "@" + addressRemote + "$" + portRemote if(!isIP(address)){ const ip = await lookup(address) @@ -194,6 +196,9 @@ async function handleTCPOutBound(remoteSocket: any, destinationNetwork: any, add port = proxyPort rawHeaderEnabled = true; } + if(address.includes(":")){ + address = "[" + address + "]" + } const tcpSocket = connect({ hostname: address, port: port,