outlinecaddy

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

README

Caddy Module

The Caddy module provides an app and handler for Caddy Server (https://caddyserver.com/) allowing it to turn any Caddy Server into an Outline Shadowsocks backend.

Prerequisites

Usage

From this directory, build and run a custom Caddy binary with this Go module plugged in using xcaddy:

xcaddy build \
  --with github.com/iamd3vil/caddy_yaml_adapter \
  --with github.com/mholt/caddy-l4 \
  --with github.com/Jigsaw-Code/outline-ss-server/outlinecaddy
./caddy run --config examples/simple.yaml --adapter yaml --watch

In a separate window, confirm you can fetch a page over Shadowsocks:

go run github.com/Jigsaw-Code/outline-sdk/x/examples/fetch \
  -transport "ss://chacha20-ietf-poly1305:Secret1@:9000" \
  http://ipinfo.io

Prometheus metrics are available on http://localhost:9091/metrics.

Development

From this directory, run the Caddy module directly from Go:

go run -tags nomysql ./cmd/caddy run \
  --adapter yaml \
  --config examples/simple.yml \
  --watch

Documentation

Index

Constants

View Source
const (
	StreamConnectionType = ConnectionType("stream")
	PacketConnectionType = ConnectionType("packet")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionHandler

type ConnectionHandler struct {
	// Name of the connection handler. This 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"`
	// contains filtered or unexported fields
}

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.

func (*ConnectionHandler) Handle

func (ch *ConnectionHandler) Handle(cx *layer4.Connection, next layer4.Handler) error

func (*ConnectionHandler) Provision

func (ch *ConnectionHandler) Provision(ctx caddy.Context) error

Provision sets up the connection handler.

type ConnectionHandlers

type ConnectionHandlers []*ConnectionHandler

func (ConnectionHandlers) Provision

func (ch ConnectionHandlers) Provision(ctx caddy.Context) error

Provision sets up all the connection handlers.

type ConnectionType

type ConnectionType string

type KeyConfig

type KeyConfig struct {
	ID     string
	Cipher string
	Secret string
}

type ModuleRegistration

type ModuleRegistration caddy.ModuleInfo

func (ModuleRegistration) CaddyModule

func (m ModuleRegistration) CaddyModule() caddy.ModuleInfo

CaddyModule implements the caddy.Module interface

type OutlineApp

type OutlineApp struct {
	ShadowsocksConfig *ShadowsocksConfig `json:"shadowsocks,omitempty"`
	Handlers          ConnectionHandlers `json:"connection_handlers,omitempty"`
	// contains filtered or unexported fields
}

func (OutlineApp) CaddyModule

func (OutlineApp) CaddyModule() caddy.ModuleInfo

func (*OutlineApp) Provision

func (app *OutlineApp) Provision(ctx caddy.Context) error

Provision sets up Outline.

func (*OutlineApp) Start

func (app *OutlineApp) Start() error

Start starts the App.

func (*OutlineApp) Stop

func (app *OutlineApp) Stop() error

Stop stops the App.

type OutlineHandler

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"`
	// contains filtered or unexported fields
}

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.

func (*OutlineHandler) CaddyModule

func (*OutlineHandler) CaddyModule() caddy.ModuleInfo

func (*OutlineHandler) Handle

func (h *OutlineHandler) Handle(cx *layer4.Connection, next layer4.Handler) error

Handle implements layer4.NextHandler.

func (*OutlineHandler) Provision

func (h *OutlineHandler) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner.

func (*OutlineHandler) Validate

func (h *OutlineHandler) Validate() error

Validate implements caddy.Validator.

type ShadowsocksConfig

type ShadowsocksConfig struct {
	ReplayHistory int `json:"replay_history,omitempty"`
}

type ShadowsocksHandler

type ShadowsocksHandler struct {
	Keys []KeyConfig `json:"keys,omitempty"`
	// contains filtered or unexported fields
}

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).

func (*ShadowsocksHandler) CaddyModule

func (*ShadowsocksHandler) CaddyModule() caddy.ModuleInfo

func (*ShadowsocksHandler) Handle

Handle implements layer4.NextHandler.

func (*ShadowsocksHandler) Provision

func (h *ShadowsocksHandler) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner.

type WebSocketHandler

type WebSocketHandler struct {
	// 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"`
	// contains filtered or unexported fields
}

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.

func (*WebSocketHandler) CaddyModule

func (*WebSocketHandler) CaddyModule() caddy.ModuleInfo

func (*WebSocketHandler) Provision

func (h *WebSocketHandler) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner.

func (WebSocketHandler) ServeHTTP

ServeHTTP implements caddyhttp.MiddlewareHandler.

func (*WebSocketHandler) Validate

func (h *WebSocketHandler) Validate() error

Validate implements caddy.Validator.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL