Skip to content

feat(caddy): add a WebSockets handler that connects to Shadowsocks handler#216

Merged
sbruens merged 146 commits into
masterfrom
sbruens/caddy-ws
Feb 19, 2025
Merged

feat(caddy): add a WebSockets handler that connects to Shadowsocks handler#216
sbruens merged 146 commits into
masterfrom
sbruens/caddy-ws

Conversation

@sbruens

@sbruens sbruens commented Sep 23, 2024

Copy link
Copy Markdown

This PR enables Shadowsocks-over-WebSockets functionality in the Caddy server, allowing clients to connect to Shadowsocks servers via WebSockets. This is achieved by introducing three new modules:

  1. Named Connection Handlers: These reusable handlers can be shared by different applications and are configured within the Outline app.

  2. WebSocket-to-Outline Handler: An HTTP app handler which bridges WebSocket requests to a designated named connection handler, enabling Shadowsocks connections over WebSockets.

  3. Layer4 Outline Handler: A layer 4 handler which bridges TCP/UDP connections to a designated named connection handler.

Example Configuration:

This example demonstrates how to configure a Shadowsocks handler with access keys and utilize it for both WebSocket and TCP connections:

  outline:
    ...
    connection_handlers:
    - name: ss1
      handle:
        handler: shadowsocks
        keys:
        - id: user-0
          cipher: chacha20-ietf-poly1305
          secret: Secret0

apps:
  http:
    servers:
      '1':
        listen:
        - ":8000"
        routes:
        - match:
          - path:
            - "/tcp"
          handle:
          - handler: websocket2layer4
            type: stream
            connection_handler: ss1
  layer4:
    servers:
      '1':
        listen:
        - tcp/[::]:9000
        routes:
        - handle:
          - handler: outline
            connection_handler: ss1

Comment thread caddy/config_example.json Outdated
Comment thread caddy/config_example.json Outdated
Comment thread caddy/websocket_handler.go Outdated
@sbruens sbruens requested a review from fortuna October 7, 2024 21:47
@sbruens sbruens changed the title feat(caddy): add a WebSockets handler feat(caddy): add a Layer4 WebSockets handler Oct 7, 2024
Comment thread .github/workflows/license.yml Outdated
Comment thread .github/workflows/license.yml Outdated
Comment thread .github/workflows/license.yml Outdated
Comment thread caddy/README.md
Comment thread caddy/examples/config_example.json Outdated
Comment thread caddy/examples/config_example.json Outdated
Comment thread caddy/shadowsocks_handler.go Outdated
Comment thread caddy/websocket_handler.go Outdated
Base automatically changed from sbruens/udp-split-serving to master January 24, 2025 22:31
Comment thread .github/workflows/license.yml
Comment thread caddy/connection_handler.go
Comment thread caddy/examples/simple.yml Outdated
Comment thread go.mod Outdated
Comment thread cmd/caddy/main.go
Comment thread caddy/module.go
Comment thread caddy/ws2outline_handler.go
Comment thread caddy/ws2outline_handler.go Outdated
@sbruens sbruens requested a review from fortuna February 8, 2025 05:46
Comment thread caddy/ws2outline_handler.go
Comment thread outlinecaddy/examples/websocket.yml
Comment thread cmd/outline-ss-server/main.go
Comment thread cmd/outline-ss-server/main.go
Comment thread outlinecaddy/examples/websocket.yml Outdated
Comment thread outlinecaddy/examples/websocket.yml
Comment thread outlinecaddy/examples/websocket.yml
Comment thread outlinecaddy/ws2outline_handler.go Outdated
Comment thread outlinecaddy/ws2outline_handler.go Outdated
Comment thread outlinecaddy/ws2outline_handler.go Outdated
Comment thread outlinecaddy/ws2outline_handler.go
Comment thread outlinecaddy/ws2outline_handler.go Outdated
@sbruens sbruens requested a review from fortuna February 12, 2025 03:01
Comment thread outlinecaddy/examples/websocket.yml
}
}
}
cx := layer4.WrapConnection(conn, []byte{}, h.zlogger)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WrapConnection seems to potentially add significant overhead with the rewind logic. It will be helpful to understand the impact later, and we can consider moving away from the layer4 module.

@sbruens sbruens merged commit 0905960 into master Feb 19, 2025
@sbruens sbruens deleted the sbruens/caddy-ws branch February 19, 2025 19:48
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