Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: split out UDP association handling from serving #221

Merged
merged 75 commits into from
Jan 24, 2025

Conversation

sbruens
Copy link

@sbruens sbruens commented Nov 15, 2024

This allows us to re-use the association handling logic in the Caddy server, where the NAT is handled by Caddy.

The NAT handling for the legacy server is split out into its own PacketServe function (to handle PacketConn types) that is similar to our StreamServe function (to handle StreamConn types).

@sbruens sbruens force-pushed the sbruens/udp-split-serving branch 5 times, most recently from 56aa501 to 37414f9 Compare November 19, 2024 15:18
This will allow us to re-use the handling of packets in the Caddy
server where serving is handled separately.
@sbruens sbruens force-pushed the sbruens/udp-split-serving branch from 37414f9 to b2aa859 Compare November 19, 2024 16:50
@sbruens sbruens force-pushed the sbruens/udp-split-serving branch from c830973 to 8d95309 Compare November 21, 2024 17:19
@sbruens sbruens marked this pull request as ready for review November 22, 2024 18:05
@sbruens sbruens requested a review from a team as a code owner November 22, 2024 18:05
@sbruens sbruens requested a review from fortuna November 22, 2024 18:05
service/udp.go Outdated Show resolved Hide resolved
Copy link

@fortuna fortuna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this needs a redesign. We can make the shared abstraction be an association handler, not a packet handler. It significantly simplifies things because the handler has the association context, rather than having the context of an individual packet only.

And it will likely use less memory, since the handler can call read directly to the buffer it uses.

We will need to extract a NAT component for outline-ss-server.
Note that the handler is still the one to dictate the lifetime of an association, by closing the writes. You can't do that with a packet handler.

service/shadowsocks.go Outdated Show resolved Hide resolved
service/udp.go Outdated Show resolved Hide resolved
service/shadowsocks.go Outdated Show resolved Hide resolved
service/udp.go Outdated Show resolved Hide resolved
@sbruens sbruens changed the title refactor: split UDP serving from packet handling refactor: introduce a handler that handles a single association Nov 28, 2024
@sbruens sbruens changed the title refactor: introduce a handler that handles a single association refactor: create a handler that handles a single association Nov 28, 2024
@sbruens sbruens force-pushed the sbruens/udp-split-serving branch 3 times, most recently from 50f739c to 6c5c99f Compare January 21, 2025 21:41
@sbruens sbruens force-pushed the sbruens/udp-split-serving branch from 6c5c99f to bcac22b Compare January 21, 2025 22:05
@sbruens sbruens changed the title refactor: split out association handling in packet handler refactor: split out UDP association handling from serving Jan 21, 2025
@sbruens sbruens force-pushed the sbruens/udp-split-serving branch from dd03e45 to d81f128 Compare January 21, 2025 22:20
Copy link
Author

@sbruens sbruens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the changes to move from a PacketHandler to an AssociationHandler as we discussed earlier. PTAL.

cmd/outline-ss-server/main.go Outdated Show resolved Hide resolved
@sbruens sbruens requested a review from fortuna January 21, 2025 22:22
service/shadowsocks.go Outdated Show resolved Hide resolved
service/udp.go Show resolved Hide resolved
service/udp.go Outdated Show resolved Hide resolved
service/udp.go Show resolved Hide resolved
service/udp.go Outdated Show resolved Hide resolved
service/udp.go Show resolved Hide resolved
service/udp.go Outdated Show resolved Hide resolved
service/udp.go Outdated Show resolved Hide resolved
service/udp.go Show resolved Hide resolved
@sbruens sbruens force-pushed the sbruens/udp-split-serving branch from dd6eb06 to 09e471f Compare January 22, 2025 21:12
@sbruens sbruens requested a review from fortuna January 22, 2025 21:24
service/udp.go Outdated Show resolved Hide resolved
service/udp.go Outdated Show resolved Hide resolved
service/udp.go Outdated Show resolved Hide resolved
service/udp.go Outdated Show resolved Hide resolved
@sbruens sbruens force-pushed the sbruens/udp-split-serving branch from c39d84f to 2427670 Compare January 24, 2025 19:24
@sbruens sbruens requested a review from fortuna January 24, 2025 19:24
Copy link

@fortuna fortuna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change. The code is definitely more reusable and composable now!

We should keep an eye on memory consumption. It's not super clear to me if this will have a significant impact on memory usage and allocations. Any ideas on how to ensure it's doing fine?

@sbruens
Copy link
Author

sbruens commented Jan 24, 2025

We should keep an eye on memory consumption. It's not super clear to me if this will have a significant impact on memory usage and allocations. Any ideas on how to ensure it's doing fine?

The benchmark analysis of the PR looks good. However, I too want to get more confident it performs well under real-world conditions. I'd like to see it deployed and tested in a production-like environment with significant traffic with one of our providers to see what it looks like.

@sbruens sbruens merged commit 6a15c34 into master Jan 24, 2025
5 checks passed
@sbruens sbruens deleted the sbruens/udp-split-serving branch January 24, 2025 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants