Skip to content

Commit 8a63c5b

Browse files
committed
Rewrite to support DNS TXT
1 parent 6710ac1 commit 8a63c5b

33 files changed

+5709
-5438
lines changed

README.md

Lines changed: 129 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,23 @@ encryption_algorithm=AES-GCM
102102

103103
| 名称 | 可设置值 | 必填 |备注|
104104
| ---- | ---- | ---- | ---- |
105-
| mode | client<br>server ||客户端<br>服务端|
105+
| mode | client<br />server<br />relay ||客户端<br />服务端<br />中继模式|
106106
| listen_on | 域名或 IP 地址 ||只能填写域名或 IP 地址。多个地址请用逗号分隔|
107107
| listen_port | 1 - 65535 ||以服务端运行时可以指定端口范围|
108108
| destination_port | 1 - 65535 ||以客户端运行时可以指定端口范围|
109109
| destination_address | IP地址、域名 ||填入 IPv6 地址时不需要中括号。多个地址请用逗号分隔|
110+
| destination_dnstxt | 域名 ||仅接受单个地址,仅限客户端使用。从DNS TXT记录当中获取IP地址及端口号。使用该参数时,不必填写destination_address及destination_port|
110111
| dport_refresh | 20 - 65535 ||单位“秒”。预设值 60 秒,小于20秒按20秒算,大于65535时按65536秒算|
111112
| encryption_algorithm | XOR<br>AES-GCM<br>AES-OCB<br>chacha20<br>xchacha20<br>none ||单纯异或运算<br>AES-256-GCM-AEAD<br>AES-256-OCB-AEAD<br>ChaCha20-Poly1305<br>XChaCha20-Poly1305<br>不加密 |
112113
| encryption_password | 任意字符 |视情况|设置了 encryption_algorithm 使用加密时必填,none与XOR除外|
113114
| timeout | 0 - 65535 ||单位“秒”。预设值为 1800,设为 0 则使用预设值<br>该选项表示的是,UDP 应用程序 ↔ udphop 之间的超时设置 |
114115
| keep_alive | 0 - 65535 ||预设值为 0,等于停用 Keep Alive |
115116
| stun_server | STUN 服务器地址 ||listen_port 为端口范围模式时不可使用|
117+
| update_ipv4 | 可执行文件的路径 ||用于保存stun获得的信息,请往后阅读|
118+
| update_ipv6 | 可执行文件的路径 ||用于保存stun获得的信息,请往后阅读|
116119
| log_path | 存放 Log 的目录 ||不能指向文件本身|
117-
| ipv4_only | yes<br>true<br>1<br>no<br>false<br>0 ||若系统禁用了 IPv6,须启用该选项并设为 yes 或 true 或 1|
118-
| ipv6_only | yes<br>true<br>1<br>no<br>false<br>0 ||忽略 IPv4 地址|
120+
| ipv4_only | yes<br>true<br>1<br>no<br>false<br>0 ||纯 IPv4 模式|
121+
| ipv6_only | yes<br>true<br>1<br>no<br>false<br>0 ||纯 IPv6 模式|
119122
| fec | uint8:uint8 ||格式为 `fec=D:R`,例如可以填入 `fec=20:3`。<br>注意:D + R 的总数最大值为 255,不能超过这个数。<br>冒号两侧任意一个值为 0 表示不使用该选项。两端的设置必须相同。|
120123
| \[listener\] | N/A |是<br>(仅限中继模式)|中继模式的标签,用于指定监听模式的 UDPHop 设置<br>该标签表示与客户端交互数据|
121124
| \[forwarder\] | N/A |是<br>(仅限中继模式)|中继模式的标签,用于指定转运模式的 UDPHop 设置<br>该标签表示与服务端交互数据|
@@ -139,7 +142,33 @@ FEC 格式为 `fec=D:R`,其中 D 表示原始数据量,R 表示冗余数据
139142

140143
如果不需要写入 Log 文件,那就删除 `log_path` 这一行。
141144

145+
### STUN 选项
146+
147+
这三个参数仅限服务器模式、中继模式时使用:
148+
- stun_server
149+
- update_ipv4
150+
- update_ipv6
151+
152+
设置好 `update_ipv4``update_ipv4` 之后,程序会运行对应程序,把 stun 获取到的IP地址及端口传递过去。
153+
154+
例如,设置了
155+
```
156+
update_ipv4=/home/test/update_to_dnsv4
157+
update_ipv6=/home/test/update_to_dnsv6
158+
```
159+
160+
从 stun 获取到的地址、端口号分别是130.131.132.133、23456,那么运行的文件及传递的参数是:
161+
162+
```
163+
/home/test/update_to_dnsv4 130.131.132.133:23456
164+
```
165+
如果获取到的地址、端口号分别是2409:ABCD:FEDC:3210::1、23456,那么运行的文件及传递的参数是:
166+
```
167+
/home/test/update_to_dnsv6 [2409:ABCD:FEDC:3210::1]:23456
168+
```
169+
142170
### STUN Servers
171+
143172
[NatTypeTeste](https://github.com/HMBSbige/NatTypeTester)找到的普通 STUN 服务器:
144173
- stun.syncthing.net
145174
- stun.qq.com
@@ -162,6 +191,35 @@ FEC 格式为 `fec=D:R`,其中 D 表示原始数据量,R 表示冗余数据
162191

163192
其它 STUN 服务器:[public-stun-list.txt](https://gist.github.com/mondain/b0ec1cf5f60ae726202e)
164193

194+
### DNS TXT
195+
从TXT类型的域名当中获取一段文字内容,该文字内容包含**单个**IP地址及端口号。
196+
197+
文字内容的格式示例(IPv4地址):
198+
```
199+
192.168.0.1:65001
200+
```
201+
202+
文字内容的格式示例(IPv6地址):
203+
```
204+
[::1]:65001
205+
```
206+
207+
无效格式示例:
208+
```
209+
192.168.0.1:65001,[::1]:65001
210+
```
211+
不可以同时提供多个地址
212+
213+
```
214+
[192.168.0.1]:65001
215+
```
216+
IPv4不需要使用中括号
217+
218+
```
219+
2409:abcd:dcba::1:65001
220+
```
221+
IPv6必须使用中括号
222+
165223
---
166224

167225
## 预编译二进制
@@ -218,11 +276,11 @@ chmod +x /usr/local/bin/udphop
218276
- [botan3](https://github.com/randombit/botan)
219277

220278
### Windows
221-
请事先使用 vcpkg 安装依赖包 `asio`,一句命令即可:
279+
请事先使用 vcpkg 安装依赖包 `asio` 及 botan3,一句命令即可:
222280

223281
```
224-
vcpkg install asio:x64-windows asio:x64-windows-static
225-
vcpkg install botan:x64-windows botan:x64-windows-static
282+
vcpkg install asio:x64-windows asio:x64-windows-static botan:x64-windows botan:x64-windows-static
283+
vcpkg install botan:x64-windows botan:x64-windows-static botan:x64-windows botan:x64-windows-static
226284
```
227285
(如果需要 ARM 或者 32 位 x86 版本,请自行调整选项)
228286

@@ -242,19 +300,75 @@ cmake ..
242300
make
243301
```
244302

245-
### 其它 BSD
246-
步骤与 FreeBSD 类似,NetBSD 请使用 [pkgin](https://www.netbsd.org/docs/pkgsrc/using.html) 安装依赖项与 cmake:
303+
### NetBSD
304+
请使用 [pkgin](https://www.netbsd.org/docs/pkgsrc/using.html) 安装依赖项与 cmake:
305+
```
306+
pkgin install asio botan3 cmake
307+
```
308+
309+
由于系统内置的GCC版本较低,须额外安装新版GCC:
310+
311+
```
312+
pkgin install gcc13
313+
```
314+
接着在 build 目录当中构建
315+
```
316+
mkdir build
317+
cd build
318+
cmake -D CMAKE_CXX_COMPILER=/usr/pkg/gcc13/bin/c++ -D CMAKE_C_COMPILER=/usr/pkg/gcc13/bin/cc ..
319+
make
320+
```
321+
322+
### OpenBSD
323+
324+
OpenBSD 请使用 `pkg_add` 安装依赖项与 cmake:
325+
326+
```
327+
pkg_add asio
328+
pkg_add cmake
329+
```
330+
331+
目前 botan-3 仍未被 OpenBSD 收录,须自行编译 botan-3。建议编译完成后放入 `/usr/local/include/`,完整路径为 `/usr/local/include/botan-3/`,就像FreeBSD那样。
332+
333+
由于系统内置的Clang版本较低,须额外安装新版Clang:
334+
335+
```
336+
pkg_add llvm
337+
```
338+
339+
请选择最新版本。
340+
341+
接着在 build 目录当中构建:
342+
```
343+
mkdir build
344+
cd build
345+
cmake -D CMAKE_CXX_COMPILER=/usr/local/bin/clang++-19 -D CMAKE_C_COMPILER=/usr/local/bin/clang-19 ..
346+
make
347+
```
348+
349+
### DragonflyBSD
350+
351+
与 FreeBSD 一样,使用 `pkg` 安装依赖项与 cmake:
352+
247353
```
248-
pkgin install asio
249-
pkgin install cmake
354+
pkg install asio cmake
250355
```
251-
OpenBSD 请使用 `pkg_add` 安装上述两个依赖性。DragonflyBSD 请使用 `pkg`,用法与 FreeBSD 相同。
252356

253-
由于 botan-3 仍未被这几个 BSD 系统收录,须自行编译 botan-3。
357+
目前 botan-3 仍未被 DragonflyBSD 收录,须自行编译 botan-3。建议编译完成后放入 `/usr/local/include/`,完整路径为 `/usr/local/include/botan-3/`,就像FreeBSD那样
254358

255-
剩余的构建步骤请参考上述的 FreeBSD。
359+
由于系统内置的GCC版本较低,须额外安装新版GCC:
256360

257-
注意,由于这几个 BSD 自带的编译器版本较低,请事先额外安装高版本 GCC。
361+
```
362+
pkg install gcc14
363+
```
364+
365+
接着在 build 目录当中构建
366+
```
367+
mkdir build
368+
cd build
369+
cmake -D CMAKE_CXX_COMPILER=/usr/local/bin/c++14 -D CMAKE_C_COMPILER=/usr/local/bin/gcc14 -D CMAKE_INSTALL_RPATH=/usr/local/lib/gcc14 -D CMAKE_BUILD_WITH_INSTALL_RPATH=ON ..
370+
make
371+
```
258372

259373
### Linux
260374
步骤与 FreeBSD 类似,请用发行版自带的包管理器安装 asio 与 botan3 以及 cmake。
@@ -400,7 +514,7 @@ root soft nofile 300000
400514
## 关于代码
401515
402516
### 线程池
403-
udphop 使用的线程池来自于 [BS::thread_pool](https://github.com/bshoshany/thread-pool),另外再做了些许修改,用于多连接时的并行加解密处理。
517+
udphop 使用的线程池来自于 [task-thread-pool](https://github.com/alugowski/task-thread-pool),用于多连接时的并行加解密处理。
404518
405519
### FEC
406520

README_EN.md

Lines changed: 122 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,15 @@ encryption_algorithm=AES-GCM
105105
| listen_port | 1 - 65535 | Yes | Specify the port range when running as a server |
106106
| destination_port | 1 - 65535 | Yes | Specify the port range when running as a client |
107107
| destination_address | IP address, domain name | Yes | When inputting an IPv6 address, no need for square brackets. Multiple addresses should be comma-separated.|
108+
| destination_dnstxt | Domain name | No |Accepts a single domain name, for client use only. Retrieves the IP address and port from a DNS TXT record. When this parameter is used, destination_address and destination_port are not required.|
108109
| dport_refresh | 20 - 65535 | No | Unit: seconds. Default value is 60 seconds. If less than 20 seconds, it will be considered as 20 seconds; if greater than 65535, it will be considered as 65536 seconds |
109110
| encryption_algorithm | XOR<br>AES-GCM<br>AES-OCB<br>chacha20<br>xchacha20<br>none |No |XOR Only<br>AES-256-GCM-AEAD<br>AES-256-OCB-AEAD<br>ChaCha20-Poly1305<br>XChaCha20-Poly1305<br>No Encryption |
110111
| encryption_password | Any character |Depends…|…on the setting of encryption_algorithm, if the value is set and it is neither `none` nor `XOR`, it is required|
111112
| timeout | 0 - 65535 | No | Unit: seconds. Default value is 1800. Set to 0 to use the default value. Represents the timeout setting between the UDP application and udphop |
112113
| keep_alive | 0 - 65535 | No | Default value is 0, which means Keep Alive is disabled |
113114
| stun_server | STUN server address | No | Cannot be used when listen_port is in port range mode |
115+
| update_ipv4 | Path to an executable file | No |Used for processing the public IPv4 address obtained from STUN. See documentation below for details.|
116+
| update_ipv6 | Path to an executable file | No |Used for processing the public IPv6 address obtained from STUN. See documentation below for details.|
114117
| log_path | Directory for storing logs | No | Should point to a directory, not a file itself. If not needed, remove this line |
115118
| ipv4_only | yes<br>true<br>1<br>no<br>false<br>0 | No | If IPv6 is disabled on the system, enable this option and set to yes, true, or 1 |
116119
| ipv6_only | yes<br>true<br>1<br>no<br>false<br>0 |No|Ignore IPv4 address|
@@ -125,7 +128,7 @@ For example, you can input `fec=20:4`, which means for every 20 data packets sen
125128

126129
**Reminder**: It is not recommended for OpenVPN using AEAD encryption mode to use this feature, because OpenVPN's tolerance for out-of-order packets is very poor under this circumstance, and UDPHop is not responsible for reordering packets, even for FEC-recovered data.
127130

128-
#### 中继模式
131+
#### Relay Mode
129132
Please refer to [The Usage of Relay Mode](docs/relay_mode_en.md).
130133

131134
### Log Files
@@ -137,6 +140,32 @@ The obtained punched address will also be displayed in the console.
137140

138141
If log writing is not needed, then remove the `log_path` line.
139142

143+
### STUN Options
144+
145+
These three parameters are limited to server and relay modes:
146+
- `stun_server`
147+
- `update_ipv4`
148+
- `update_ipv6`
149+
150+
Once `update_ipv4` or `update_ipv6` is set, the program will execute the corresponding script, passing the IP address and port obtained from STUN to it.
151+
152+
For example, given the following settings:
153+
```
154+
update_ipv4=/home/test/update_to_dnsv4
155+
update_ipv6=/home/test/update_to_dnsv6
156+
```
157+
158+
If the address and port obtained from STUN are `130.131.132.133` and `23456` respectively, the file executed and the arguments passed will be:
159+
160+
```
161+
/home/test/update_to_dnsv4 130.131.132.133:23456
162+
```
163+
164+
If the address and port obtained are `2409:ABCD:FEDC:3210::1` and `23456` respectively, the file executed and the arguments passed will be:
165+
```
166+
/home/test/update_to_dnsv6 [2409:ABCD:FEDC:3210::1]:23456
167+
```
168+
140169
### STUN Servers
141170
STUN Servers found in [NatTypeTeste](https://github.com/HMBSbige/NatTypeTester):
142171
- stun.syncthing.net
@@ -160,6 +189,35 @@ STUN Servers found in [Natter](https://github.com/MikeWang000000/Natter):
160189

161190
Other STUN Servers: [public-stun-list.txt](https://gist.github.com/mondain/b0ec1cf5f60ae726202e)
162191

192+
### DNS TXT
193+
Retrieve a text string from the domain's TXT record. This text string contains **a single** IP address and port number.
194+
195+
Example format for the text content (IPv4 address):
196+
```
197+
192.168.0.1:65001
198+
```
199+
200+
Example format for the text content (IPv6 address):
201+
```
202+
[::1]:65001
203+
```
204+
205+
Invalid format examples:
206+
```
207+
192.168.0.1:65001,[::1]:65001
208+
```
209+
Multiple addresses are not allowed.
210+
211+
```
212+
[192.168.0.1]:65001
213+
```
214+
Square brackets are not required for IPv4 addresses.
215+
216+
```
217+
2409:abcd:dcba::1:65001
218+
```
219+
Square brackets must be used for IPv6 addresses.
220+
163221
---
164222

165223
## Pre-compiled binaries
@@ -241,19 +299,74 @@ make
241299
```
242300

243301
### NetBSD
244-
The steps are similar to FreeBSD. For NetBSD, use [pkgin](https://www.netbsd.org/docs/pkgsrc/using.html) to install dependencies and cmake:
302+
Please install dependencies and cmake by running [pkgin](https://www.netbsd.org/docs/pkgsrc/using.html):
303+
```
304+
pkgin install asio botan3 cmake
305+
```
306+
307+
Since the system's built-in GCC version is too low, you must install a newer version of GCC:
308+
309+
```
310+
pkgin install gcc13
245311
```
246-
pkgin install asio
247-
pkgin install cmake
312+
Then, build in the `build` directory:
313+
```
314+
mkdir build
315+
cd build
316+
cmake -D CMAKE_CXX_COMPILER=/usr/pkg/gcc13/bin/c++ -D CMAKE_C_COMPILER=/usr/pkg/gcc13/bin/cc ..
317+
make
318+
```
319+
320+
### OpenBSD
321+
322+
For OpenBSD, Please install dependencies and cmake by running `pkg_add`:
323+
324+
```
325+
pkg_add asio
326+
pkg_add cmake
327+
```
328+
329+
Currently, botan-3 has not been included in OpenBSD, so you must compile botan-3 yourself. It is recommended to place it in `/usr/local/include/` after compilation, with the full path being `/usr/local/include/botan-3/`, just like on FreeBSD.
330+
331+
Since the system's built-in Clang version is too low, you must install a newer version of Clang:
332+
333+
```
334+
pkg_add llvm
335+
```
336+
337+
Choose the latest version.
338+
339+
Then, build in the `build` directory:
340+
```
341+
mkdir build
342+
cd build
343+
cmake -D CMAKE_CXX_COMPILER=/usr/local/llvm19/bin/clang++ -D CMAKE_C_COMPILER=/usr/local/llvm19/bin/clang ..
344+
make
248345
```
249346

250-
Please use `pkg_add` on OpenBSD to install the two dependencies mentioned above. On DragonflyBSD, please use `pkg`, the usage is the same as FreeBSD.
347+
### DragonflyBSD
348+
349+
Like FreeBSD, use `pkg` to install dependencies and cmake:
350+
351+
```
352+
pkg install asio cmake
353+
```
251354

252-
Since botan-3 is not yet included in these BSD systems, it needs to be compiled manually.
355+
Currently, botan-3 has not been included in DragonflyBSD, so you must compile botan-3 yourself. It is recommended to place it in `/usr/local/include/` after compilation, with the full path being `/usr/local/include/botan-3/`, just like on FreeBSD.
253356

254-
Please refer to the aforementioned FreeBSD for the remaining build steps.
357+
Since the system's built-in GCC version is too low, you must install a newer version of GCC:
255358

256-
Note that due to the lower versions of the compilers included in these BSD systems, please install a higher version of GCC in advance.
359+
```
360+
pkg install gcc14
361+
```
362+
363+
Then, build in the `build` directory:
364+
```
365+
mkdir build
366+
cd build
367+
cmake -D CMAKE_CXX_COMPILER=/usr/local/bin/c++14 -D CMAKE_C_COMPILER=/usr/local/bin/gcc14 -D CMAKE_INSTALL_RPATH=/usr/local/lib/gcc14 -D CMAKE_BUILD_WITH_INSTALL_RPATH=ON ..
368+
make
369+
```
257370

258371
### Linux
259372
The steps are similar to FreeBSD. Install asio and botan3 as well as cmake using the package manager provided by the distribution.
@@ -399,7 +512,7 @@ root soft nofile 300000
399512
## About the Code
400513
401514
### Thread Pool
402-
The thread pool used by UDPHop comes from [BS::thread_pool](https://github.com/bshoshany/thread-pool), with some modifications made for parallel encryption and decryption processing in multiple connections.
515+
The thread pool used by UDPHop comes from [task-thread-pool](https://github.com/alugowski/task-thread-pool), uses for parallel encryption and decryption processing in multiple connections.
403516
404517
### FEC
405518

0 commit comments

Comments
 (0)