全球主机交流论坛

标题: [开源][C++]TCP转发工具 [打印本页]

作者: dunce    时间: 2021-5-29 13:40
标题: [开源][C++]TCP转发工具
本帖最后由 dunce 于 2021-6-1 19:34 编辑

仓库地址: https://github.com/zephyrchien/ZTUN

6/1 UPDATE: 已经支持了DNS和超时,顺便支持了ipv6,可以做到ipv4->ipv6 & ipv6->ipv4

写这个程序的起因是realm不支持零拷贝,当初想着如果要给realm实现零拷贝,不如用C++重新写一个。于是我就尝试着写了一下。。(目前仍处于重度施工中,还没实现timer和dns resolver),感兴趣的同学可以来测个速

本地iperf3简单测速结果:
使用buffer时速度跟realm相当(15G/s)
使用pipe时(零拷贝)速度跟Go程序差不多(40G/s)

快速开始:
本程序没有外部依赖(EDIT: 除了glibc),直接把代码下载下来编译就行了:
  1. git clone https://github.com/zephyrchien/ZTUN
  2. cd ZTUN && mkdir build && cd build
  3. cmake ..
  4. make
复制代码

用命令行参数输入一对地址,或者指定配置文件:
  1. ztun -l :5000 -r 1.1.1.1:443 # 省略本地ip,默认为0.0.0.0
  2. ztun -c ztun.conf
复制代码

配置文件格式:
  1. # comment, starting with #

  2. # set log level and output path
  3. # level = none|warn|info|debug, default is info
  4. # file = filename, default is stderr
  5. log_level = info
  6. log_file = ztun.log

  7. # set the precision of timer and operation timeout
  8. # value: 1~2147483647(INT_MAX) ms
  9. # timer_intv = xxx, default is 500
  10. # connect_timeout = xxx, default is 2000
  11. # resolve_intv = xxx, default is 60000
  12. # resolve_timeout = xxx, default is 2000
  13. timer_intv = 500
  14. connect_timeout = 2000
  15. resolve_intv = 60000
  16. resolve_timeout = 2000

  17. # group1
  18. local = 127.0.0.1:5000
  19. remote = 1.1.1.1:443

  20. # group2 (use ipv6)
  21. local = ::1:10000
  22. remote = 2.2.2.2:8080

  23. # group3 (use domain name)
  24. local = :15000
  25. remote = www.google.com:80

  26. # and more...
复制代码

       
作者: h20    时间: 2021-5-29 13:47
提示: 作者被禁止或删除 内容自动屏蔽
作者: dunce    时间: 2021-5-29 13:49
h20 发表于 2021-5-29 13:47
没有外部依赖?glibc不算?

= =也就glibc了,毕竟不用特地去装
作者: xuliliang    时间: 2021-5-29 13:49
前排占位出售啤酒花生瓜子饮料
作者: fatal    时间: 2021-5-29 13:51
还是socat吧。。。
作者: lovecan    时间: 2021-5-29 13:56
支持下
作者: POMAH    时间: 2021-5-29 13:57
提示: 作者被禁止或删除 内容自动屏蔽
作者: 110e    时间: 2021-5-29 13:59
mark一下
作者: 6700    时间: 2021-5-29 14:03
proxy protocol支持吗
作者: tomcb    时间: 2021-5-29 14:05
支持百家争鸣,但是
15G/s
还是@几个机场主来吧,一般用户感觉也用不到
作者: dunce    时间: 2021-5-29 14:13
6700 发表于 2021-5-29 14:03
proxy protocol支持吗

不难支持,连接成功以后发送一下header就行了(这一步不能零拷贝
不过目前最优先事项是实现定时器和DNS解析
作者: dunce    时间: 2021-5-29 14:14
tomcb 发表于 2021-5-29 14:05
支持百家争鸣,但是
15G/s
还是@几个机场主来吧,一般用户感觉也用不到

嘛,测速也就图个乐
作者: 溜溜球    时间: 2021-5-29 14:18
提示: 作者被禁止或删除 内容自动屏蔽
作者: dunce    时间: 2021-5-29 14:27
溜溜球 发表于 2021-5-29 14:18
https://github.com/X-Crack/libuv-evpp

大佬可以用我开发的这套库来做,很容易

=-=感谢大佬推荐,不过我这项目用不上那么高级的抽象(只是转发个端口,而且不打算跨平台
作者: tianzi1981    时间: 2021-5-29 14:56
转发是不是没有办法获取用户真实IP
作者: lijihede    时间: 2021-5-29 15:19
支持创作精神~
作者: oooohhhh    时间: 2021-5-29 15:36
何必自己造轮子,直接boost nio
作者: yeshang    时间: 2021-5-29 22:12
目前在用socat 只一个:支持v6吗?
作者: dunce    时间: 2021-5-30 16:13
已经实现定时器了,晚上写dns resolver
作者: darknoll    时间: 2021-5-30 16:16
提示: 作者被禁止或删除 内容自动屏蔽
作者: 1652291305    时间: 2021-5-30 16:24
darknoll 发表于 2021-5-30 16:16
都这年头了,还用C++呢

底层语言效率高啊
作者: qfdk    时间: 2021-5-30 16:25
还有这么高端的玩儿法 ?

作者: darknoll    时间: 2021-5-30 16:33
提示: 作者被禁止或删除 内容自动屏蔽
作者: 没有的    时间: 2021-5-30 16:35
老程序员啊!
作者: sushe555    时间: 2021-5-30 16:43
懒人不喜欢用 嘿嘿
作者: dunce    时间: 2021-6-1 19:37
已更新(打算跑路了)
作者: xiaoz    时间: 2021-6-1 20:08
fatal 发表于 2021-5-29 13:51
还是socat吧。。。

socat一般使用没问题,但高并发就不行了。之前对比了下socat和brook:https://www.xiaoz.me/archives/15631
作者: xiaoz    时间: 2021-6-1 20:10
感谢分享,回头试一下。
作者: tomcb    时间: 2021-6-1 20:27
多条路子总是好,能否把配置文件各个参数加个注释说明含义,看着方便点。
作者: arrr    时间: 2021-6-1 21:31
楼主可以发Solidot.org试试。




欢迎光临 全球主机交流论坛 (https://fd.vvwvv.eu.org/) Powered by Discuz! X3.4