Skip to content

Commit

Permalink
Add Godoc comments to all the handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbruens committed Feb 8, 2025
1 parent bd7db92 commit 94b68dd
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 10 deletions.
22 changes: 21 additions & 1 deletion outlinecaddy/connection_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,30 @@ import (
"github.com/mholt/caddy-l4/layer4"
)

// ConnectionHandler represents a named, reusable connection handler.
//
// These handlers are configured within the Outline app and can be shared
// across different applications. A ConnectionHandler compiles and wraps a layer4
// handler, allowing it to be referenced and reused by name. This enables sharing
// configurations and services between different protocol stacks.
//
// For example, you might have a Shadowsocks handler (TCP or UDP) in the layer4
// app and a Shadowsocks-over-WebSockets handler in the HTTP app. Using
// ConnectionHandler, you can wrap a single Shadowsocks handler and reference
// it by name in both the layer4 and HTTP app configurations, ensuring they
// share the same Shadowsocks service configuration.
type ConnectionHandler struct {
Name string `json:"name,omitempty"`
// Name of the connection handlerThis is used to reference the
// handler within the Outline app configuration.
Name string `json:"name,omitempty"`

// WrappedHandlerRaw is the raw JSON configuration for the wrapped
// layer4.NextHandler. It is unmarshalled and used to create the
// actual handler instance.
WrappedHandlerRaw json.RawMessage `json:"handle,omitempty" caddy:"namespace=layer4.handlers inline_key=handler"`

// compiled is the compiled instance of the wrapped layer4.NextHandler.
// It is populated during the Provision step.
compiled layer4.NextHandler
}

Expand Down
16 changes: 14 additions & 2 deletions outlinecaddy/outline_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,22 @@ const (
PacketConnectionType = ConnectionType("packet")
)

// OutlineHandler implements a Caddy layer4 plugin for Outline connections.
// OutlineHandler implements a Caddy layer4 plugin for handling Outline
// connections.
//
// It acts as a bridge between the Caddy layer4 framework and the Outline app's
// configured connection handlers. It selects the appropriate handler based
// on the `connection_handler` configuration and the connection type (stream or
// packet). This allows different processing logic to be applied depending on
// the underlying protocol.
type OutlineHandler struct {
// ConnectionHandler specifies the name of the connection handler to use.
// This name must match a handler configured within the Outline app.
ConnectionHandler string `json:"connection_handler,omitempty"`
compiledHandler layer4.NextHandler

// compiledHandler is the compiled instance of the named connection
// handler. It is populated during the Provision step.
compiledHandler layer4.NextHandler

logger *slog.Logger
}
Expand Down
8 changes: 7 additions & 1 deletion outlinecaddy/shadowsocks_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ type KeyConfig struct {
Secret string
}

// ShadowsocksHandler implements a Caddy plugin for Shadowsocks connections.
// ShadowsocksHandler implements a Caddy plugin for handling Outline Shadowsocks
// connections.
//
// It manages Shadowsocks encryption keys, creates the necessary
// [outline.StreamHandler] or [outline.AssociationHandler], and dispatches
// connections to the appropriate handler based on the connection type (stream
// or packet).
type ShadowsocksHandler struct {
Keys []KeyConfig `json:"keys,omitempty"`

Expand Down
23 changes: 17 additions & 6 deletions outlinecaddy/ws2outline_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,24 @@ func init() {
})
}

// WebSocketHandler implements a middleware Caddy web handler that proxies
// WebSockets Outline connections.
// WebSocketHandler implements a Caddy HTTP middleware handler that proxies
// WebSocket connections for Outline.
//
// It upgrades HTTP WebSocket requests to a raw connection that can be handled
// by an Outline connection handler. This allows using Outline's connection
// handling logic over WebSockets.
type WebSocketHandler struct {
// The type of connection.
Type ConnectionType `json:"type,omitempty"`
ConnectionHandler string `json:"connection_handler,omitempty"`
compiledHandler layer4.NextHandler
// Type specifies the type of connection being proxied (stream or packet).
// If not provided, it defaults to StreamConnectionType.
Type ConnectionType `json:"type,omitempty"`

// ConnectionHandler specifies the name of the connection handler to use.
// This name must match a handler configured within the Outline app.
ConnectionHandler string `json:"connection_handler,omitempty"`

// compiledHandler is the compiled instance of the named connection
// handler. It is populated during the Provision step.
compiledHandler layer4.NextHandler

logger *slog.Logger
zlogger *zap.Logger
Expand Down

0 comments on commit 94b68dd

Please sign in to comment.