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 138 forks source link

optimization proposal #144

Closed Jimmy-Z closed 8 months ago

Jimmy-Z commented 11 months ago

Upon reading the code, I noticed each fake tcp packet will cost an alloc and copy https://github.com/dndx/phantun/blob/main/fake-tcp/src/packet.rs#L50 https://github.com/dndx/phantun/blob/main/fake-tcp/src/packet.rs#L97

I think we could eliminate this by mimicing linux sk_buf: leaving 64 bytes (IP + TCP header) ahead the buf passed to udp.recv, then construct the headers in-place, with no need to touch the payload.

I have no idea how much this would impact performance though.

dndx commented 8 months ago

Could you send me a PR? I can run some benchmarks on my AWS testing environment.

Jimmy-Z commented 8 months ago

Sorry, I lost interest after this: https://github.com/dndx/phantun/issues/145#issuecomment-1869748633