Skip to content

Commit

Permalink
ip6 fix and fixed relays
Browse files Browse the repository at this point in the history
  • Loading branch information
uoosef committed Sep 10, 2023
1 parent dac1a86 commit 0cdb46f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div align="center">
<h1 align="center">
<div>
<h1 style='text-align: center'>
bepass-worker
</h1>
</div>
Expand All @@ -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)

---

Expand All @@ -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

---

Expand All @@ -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:

Expand All @@ -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.**
Expand Down
7 changes: 6 additions & 1 deletion dist/worker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 0cdb46f

Please sign in to comment.