GithubHelp home page GithubHelp logo

udp-over-tcp's Introduction

udp-over-tcp

A library (and binaries) for tunneling UDP datagrams over a TCP stream.

Some programs/protocols only work over UDP. And some networks only allow TCP. This is where udp-over-tcp comes in handy. This library comes in two parts:

  • udp2tcp - Forwards incoming UDP datagrams over a TCP stream. The return stream is translated back to datagrams and sent back out over UDP again. This part can be easily used as both a library and a binary. So it can be run standalone, but can also easily be included in other Rust programs. The UDP socket is connected to the peer address of the first incoming datagram. So one [Udp2Tcp] instance can handle traffic from a single peer only.
  • tcp2udp - Accepts connections over TCP and translates + forwards the incoming stream as UDP datagrams to the destination specified during setup / on the command line. Designed mostly to be a standalone executable to run on servers. But can be consumed as a Rust library as well. tcp2udp continues to accept new incoming TCP connections, and creates a new UDP socket for each. So a single tcp2udp server can be used to service many udp2tcp clients.

Protocol

The format of the data inside the TCP stream is very simple. Each datagram is preceded with a 16 bit unsigned integer in big endian byte order, specifying the length of the datagram.

tcp2udp server example

Make the server listen for TCP connections that it can then forward to a local UDP service. This will listen on 10.0.0.1:5001/TCP and forward anything that comes in to 127.0.0.1:51820/UDP:

user@server $ RUST_LOG=debug tcp2udp \
    --tcp-listen 10.0.0.0:5001 \
    --udp-forward 127.0.0.1:51820

RUST_LOG can be used to set logging level. See documentation for env_logger for information. The crate must be built with the env_logger feature for this to be active.

REDACT_LOGS=1 can be set to redact the IPs of the peers using the service from the logs. Allows having logging turned on but without storing potentially user sensitive data to disk.

udp2tcp example

This is one way you could integrate udp2tcp into your Rust program. This will connect a TCP socket to 1.2.3.4:9000 and bind a UDP socket to a random port on the loopback interface. It will then connect the UDP socket to the socket addr of the first incoming datagram and start forwarding all traffic to (and from) the TCP socket.

let udp_listen_addr = "127.0.0.1:0".parse().unwrap();
let tcp_forward_addr = "1.2.3.4:9000".parse().unwrap();

// Create a UDP -> TCP forwarder. This will connect the TCP socket
// to `tcp_forward_addr`
let udp2tcp = udp_over_tcp::Udp2Tcp::new(
    udp_listen_addr,
    tcp_forward_addr,
    udp_over_tcp::TcpOptions::default(),
)
.await?;

// Read out which address the UDP actually bound to. Useful if you specified port
// zero to get a random port from the OS.
let local_udp_addr = udp2tcp.local_udp_addr()?;

spin_up_some_udp_thing(local_udp_addr);

// Run the forwarder until the TCP socket disconnects or an error happens.
udp2tcp.run().await?;

udp-over-tcp's People

Contributors

dlon avatar faern avatar gregoire-mullvad avatar hamirmahal avatar mvd-ows avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

udp-over-tcp's Issues

使用wireguard的时候google都可以访问,但是github不行,请问这个怎么解决?

RT

我用一台linux当软路由
在这个linux上使用UDP2TCP

然后国外的一台服务器使用TCP2UDP

然后使用wireguard 默认所有流量都走wiregurad

然后谷歌等国外网站都能正常访问
但是唯独github不行 这个可能是什么原因?

我实测用windows的wireguard客户端是没问题的
但是windows的wireguard客户端有个问题,我想实现[国内的正常走 国外的走wireguard]这个需求 需要在wireguard里面填写大量的AllowedIPs段

May I ask if a Windows version is available

May I ask if a Windows version is available
请问可以出windows版本的吗

My UDP is unstable here, and my client is on Windows
Hope to produce a Windows version
我这里udp不稳定,然后我的客户端是windows的
希望能出一个windows版本的

Make structopt an optional dependency

Currently you get structopt (+ clap etc) pulled into your dependency tree when just consuming this as a library. Structopt is only needed when built as binaries with a CLI. It should be possible to make it optional and get rid of that dependency.

Doesn't work with ENET Server in Docker Container

I'm trying to use this so that I can tunnel an ENET service over TCP. https://github.com/lsalzman/enet

I'm building and running in a docker container.

My service runs with no issue while tcp2udp is not running, but when it is running I get an error, my error appears to originate from not being able to create a host/server. I'm guessing this is some sort of binding conflict. However, I've forced my server to use a completely different port than one below.

I've tried invoking tcp2udp in the following two ways.

/usr/local/bin/tcp2udp --threads=2 --tcp-listen 0.0.0.0:7446 --udp-bind=127.0.0.1 --udp-forward 127.0.0.1:6446 --tcp-recv-timeout=130 --nodelay

and

/usr/local/bin/tcp2udp --threads=2 --tcp-listen 0.0.0.0:7446 --udp-forward 127.0.0.1:6446  --nodelay

I do not have this issue on my local workstation.

Is there some sort of start-up or ordering condition of which to be aware? Namely, if I do not start tcp2udp allow my app to start, then exec inside the docker and run the above command, then I don't seem to have an issue.

Please provide a license

Firstly, thanks for making this great piece of software!

Secondly, could you please provide a license, because apart from this one line below in the Cargo.toml file, it is ambiguous if anyone else is able to rebuild, redistribute, copy, modify etc.

license = "MIT OR Apache-2.0"

Thanks in advance!

使用真tcp协议传输udp数据包,实测支持wireguard

https://github.com/mullvad/udp-over-tcp
适用于UDP被限速,TCP不限速,且udp2raw无效果,并且需要全局的真V-P-N。用wireguard是因为轻量且快速。

Ubuntu下编译
git clone https://github.com/mullvad/udp-over-tcp.git
cd udp-over-tcp
apt install cargo -y
./build-static-bins.sh
编译好之后,拿走所需的可执行文件,其余可删除
mv target/x86_64-unknown-linux-gnu/release/tcp2udp /usr/local/bin/tcp2udp
mv target/x86_64-unknown-linux-gnu/release/udp2tcp /usr/local/bin/udp2tcp

在安装wireguard的vps(vps的公网IP为128.1.2.3)上运行tcp2udp,监听tcp端口4567,转发到wireguard的udp端口55555,命令如下。(后台运行使用systemd、supervisor、screen之类自己搞。)
tcp2udp --tcp-listen 0.0.0.0:4567 --udp-bind=127.0.0.1 --udp-forward 127.0.0.1:55555 --tcp-recv-timeout=130 --nodelay

在中转的vps(例:本地VMware开Ubuntu虚拟机,IP为192.168.9.9)上运行udp2tcp,监听udp端口8910,转发到安装wireguard的vps端口4567
udp2tcp --udp-listen 0.0.0.0:8910 --tcp-forward 128.1.2.3:4567 --tcp-recv-timeout=130 --nodelay

wireguard客户端连接到192.168.9.9端口8910即可

或许可以搭配https://github.com/cbeuw/Cloak 使用,尚未实测。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.