dndx / phantun

Transforms UDP stream into (fake) TCP streams that can go through Layer 3 & Layer 4 (NAPT) firewalls/NATs.
Apache License 2.0
1.71k stars 137 forks source link

Multi-stream TCP and UDP connections, encryption and performance #89

Closed sabify closed 1 year ago

sabify commented 2 years ago

What's the PR:

dndx commented 1 year ago

Hello,

Thanks for your contribution. However, I am a bit concerned about the introduction of unsafe code into Phantun. One of the huge advantage of Phantun is that it is written in 100% safe Rust and I am not willing to give it up easily without some good reasoning.

Have you ran any performance benchmark of this change? What is the improvement?

Handsome1080P commented 1 year ago

Hello,The multiple udp/tcp connections not compatible single stream tunnel,need set tcp/udp connection to 1.So the default can set to 1.

sabify commented 1 year ago

I'd used unsafe to bypass vectors' boundary check where both vectors' index and size were deterministic, but I just removed them to make it 100% safe code. And for the benchmark, this repository doesn't contain any test suite to benchmark the code and evaluate improvements and regressions. The tests are on yours to get these results, but it is expected that these changes will make it faster. The server code wasn't written to be bidirectional and it could just send or receive one at a time. Also, using faster data structures and removing some unnecessary locks can make huge difference on load.