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

feat: add WebSocket support to the existing outline-ss-server #225

Open
wants to merge 7 commits into
base: sbruens/udp-split-serving
Choose a base branch
from

Conversation

sbruens
Copy link

@sbruens sbruens commented Nov 28, 2024

This PR enables Shadowsocks-over-WebSockets functionality in the existing v1 server, allowing clients to connect to Shadowsocks via WebSockets.

This is the counterpart to the Caddy-backed v2 version introduced in #216.

@sbruens sbruens marked this pull request as ready for review December 3, 2024 06:07
@sbruens sbruens requested a review from a team as a code owner December 3, 2024 06:07
@sbruens sbruens requested a review from fortuna December 3, 2024 06:07
Comment on lines 23 to 31
- type: websocket
address: "[::]:8000"
options:
# TCP over WebSocket
- path: "/tcp"
connection_type: "stream"
# UDP over WebSocket
- path: "/udp"
connection_type: "packet"
Copy link

Choose a reason for hiding this comment

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

I think something like this would be cleaner:

Suggested change
- type: websocket
address: "[::]:8000"
options:
# TCP over WebSocket
- path: "/tcp"
connection_type: "stream"
# UDP over WebSocket
- path: "/udp"
connection_type: "packet"
- type: websocket-stream
web_server: main_web_server
path: "/tcp"
- type: websocket-packet
web_server: main_web_server
path: "/udp"
...
web_servers:
- id: main_web_server
listen:
- "[::]:8000"

Also, this gives us a way to configure the web server as needed.

BTW, we can also add a way to configure the metrics to be exposed on one of the configured web_servers.

Copy link
Author

Choose a reason for hiding this comment

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

I was playing around with this after we brainstormed about this offline. I was going to add another layer here though, so that we leave room to add configuration that applies to all web servers.

web:
  servers:
    - id: my_web_server
      listen: ...

@@ -339,6 +408,30 @@ func RunOutlineServer(filename string, natTimeout time.Duration, serverMetrics *
return server, nil
}

// wrappedConn overrides [websocket.Conn]'s remote address handling.
type wrappedConn struct {
Copy link

Choose a reason for hiding this comment

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

I think it will be beneficial to get rid of this kind of wrapping and create some sort of ClientConnection struct with ClientAddr and Conn. The handler could take that instead. The way we do wrapping is a pain and potentially remove ReadFrom/WriteTo optimizations.

Copy link
Author

Choose a reason for hiding this comment

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

Ack. If it's ok with you I'd like to do that in a follow-up PR to keep the changes smaller. I've added add a TODO here.

@sbruens sbruens requested a review from fortuna December 10, 2024 18:09
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