engine

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 50 Imported by: 0

Documentation

Overview

Package engine assembles lfr: it opens the data directory, wires the services together, runs the SMTP and HTTP servers, the delivery queue and the scheduler, and answers the CLI over the control socket.

Index

Constants

View Source
const (
	DBFile    = "lfr.db"
	Socket    = "lfr.sock"
	BlobDir   = "msg"
	SiteDir   = "sites"
	CertDir   = "certs"
	SocketEnv = "LFR_SOCKET"
)

Paths inside the data directory.

View Source
const BackupDone = "BACKUP-COMPLETE"

BackupDone marks a complete backup.

Variables

This section is empty.

Functions

func DetectIPv4

func DetectIPv4() string

DetectIPv4 finds the first public IPv4 address on a local interface, as cloud servers like DigitalOcean droplets have.

func SocketPath

func SocketPath(data string) string

SocketPath is exported for the CLI.

func SystemdUnit

func SystemdUnit(binary, data, user string) string

SystemdUnit is the service definition `lfr setup --systemd` installs.

Types

type Engine

type Engine struct {
	Opts     Options
	DB       *store.DB
	Blobs    *blob.Store
	Config   config.Config
	Tokens   *token.Signer
	Events   *events.Bus
	Domains  *domains.Service
	Mailbox  *mailbox.Service
	Lists    *lists.Service
	Issues   *issues.Service
	Renderer *issues.Renderer
	Queue    *outbound.Queue
	Spam     *spam.Classifier
	Sites    *web.Sites
	Web      *web.Server
	Inbound  *inbound.Server
	Certs    *certs.Manager
	Ctl      *ctl.Server
	DNS      dnsx.Resolver
	Log      *slog.Logger
	// contains filtered or unexported fields
}

Engine is a running lfr.

func Open

func Open(ctx context.Context, o Options) (*Engine, error)

Open prepares an engine on an initialized data directory.

func (*Engine) Backup

func (e *Engine) Backup(ctx context.Context, dir string) (api.BackupResult, error)

Backup copies the database and every message into dir.

func (*Engine) BaseURL

func (e *Engine) BaseURL(l *lists.List) string

BaseURL is where a list's token links (confirm, unsubscribe, tracking) live.

func (*Engine) Close

func (e *Engine) Close() error

Close releases the database.

func (*Engine) Doctor

func (e *Engine) Doctor(ctx context.Context) []api.Check

Doctor runs every check an operator needs before trusting the setup.

func (*Engine) Hostname

func (e *Engine) Hostname(ctx context.Context) string

Hostname is the mail host name.

func (*Engine) Instance

func (e *Engine) Instance(ctx context.Context) domains.Instance

Instance is what DNS records point at.

func (*Engine) ListURL

func (e *Engine) ListURL(l *lists.List) string

ListURL is the base URL of a list's site.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context) error

Run serves until ctx ends.

func (*Engine) Signup

func (e *Engine) Signup(ctx context.Context, l *lists.List, email string, s lists.Signup) error

Signup records a web signup and sends the confirmation, within the per-list hourly limit that keeps lfr from being used to bomb inboxes.

func (*Engine) Status

func (e *Engine) Status(ctx context.Context) (api.Status, error)

Status is the overview of the running server.

type Options

type Options struct {
	Data      string
	SMTPAddr  string // ":25"
	HTTPAddr  string // ":80"
	HTTPSAddr string // ":443"
	Version   string
	Log       *slog.Logger
	// For tests and special setups.
	DNS        dnsx.Resolver
	Transport  outbound.Transport
	Now        func() time.Time
	SocketMode os.FileMode
}

Options are process-level settings of `lfr serve`.

type SetupOptions

type SetupOptions struct {
	Data      string
	Hostname  string
	IPv4      string // detected when empty
	IPv6      string
	ACMEEmail string
	Now       func() int64
}

SetupOptions are the first settings of a data directory.

type SetupResult

type SetupResult struct {
	Data     string `json:"data"`
	Hostname string `json:"hostname"`
	IPv4     string `json:"ipv4,omitempty"`
	IPv6     string `json:"ipv6,omitempty"`
	Existing bool   `json:"existing"`
}

SetupResult reports what Setup did.

func Setup

func Setup(ctx context.Context, o SetupOptions) (SetupResult, error)

Setup creates or updates a data directory. Running it again keeps all data and only changes the settings given.

Jump to

Keyboard shortcuts

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