CI / Test (ubuntu-latest) (push) Canceled after 0s
CI / Test (windows-latest) (push) Canceled after 0s
CI / Storage tests on PostgreSQL (push) Canceled after 0s
CI / Complement (federation off) (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
CI / Smoke test the binary (push) Canceled after 0s
Implements PLAN.md Phase 3: the roomserver, the room half of storage, the Client-Server room endpoints and the admin room endpoints. A client can now create a room, invite, join, leave, kick, ban, send messages and state, redact, name a room with an alias and find one in the public directory. Nothing talks to another server; every operation that would need to is refused with a message that says so rather than a bare M_FORBIDDEN. roomserver: one input pipeline every event goes through, whatever sent it — validate, authorise, resolve, persist, emit. The rules are not reimplemented here; internal/matrix is pure library code and this is what connects it to a database and to a room's history. The Client-Server handlers do no authorisation of their own, deliberately: whether Alice may kick Bob is a question about the room's power levels, and the one place that is answered correctly is the authorisation rules inside the pipeline. A mutex per room serialises writers. Two events racing into one room would each read the same forward extremities, both become one, and fork the room for no reason — which would then need state resolution to put back together. State resolution is wired in anyway for the multi-extremity case. It is unreachable from outside in this phase, and the alternative is a pipeline that authorises against one arbitrary branch of a fork without saying so. Room versions 3 to 12 all work and are each tested end to end. Version 12 earns that coverage: its room ID is the create event's own ID, its create event carries no room_id, and the create event is excluded from every other event's auth_events — so the state auth.Check is given is the event's auth_events plus the create event, which that version identifies by room ID rather than citing. createRoom sends the spec's events in the spec's order, each authorised against what the ones before it produced. A failure part-way leaves an incomplete room, which is the lesser evil: the alternative is holding every event of a new room in memory and writing them in one transaction, making the pipeline that authorises them a special case. The one failure a second client can cause at any time, an alias clash, takes the room row back out. Redactions stay two decisions, as the spec keeps them. The rules let almost any redaction into the room; whether it applies to its target is a separate test, run inside the same transaction as the redaction itself so that a client holding an event ID can always read the stripped event. storage: events keyed by event ID rather than by a surrogate, since an event ID appears in prev_events, auth_events, state snapshots and client requests alike. Stream ordering comes from a counter row bumped inside the write transaction, because a PostgreSQL sequence is explicitly not transactional and a rolled-back write would leave a hole in the stream that /sync would have to be taught to skip. State snapshots are stored per event and deduplicated by content hash, so the table grows with state changes rather than with traffic — and that is what makes "the state after a forward extremity" answerable at all. The room's listing columns are denormalised onto its row because the public directory orders every published room by member count and pages the result, which cannot be done by reading each room's state in turn. Federation-disabled behaviour from PLAN.md section 3 is enforced here. Restricted joins are the exception that works: the rule needs a signature from the authorising user's server verified, and while federation is off that server is always this one. adminapi: room list and detail, purge, force-leave, and room and event counters on the dashboard. clientapi gains its own rate-limit buckets for createRoom and for joining, both of which write events rather than read them. Tested against the real event core and a real database rather than fakes: what is under test is whether an event this server signs is one the authorisation rules accept, and a fake of either would only prove that the pipeline calls what the fake expects. The storage tests run against both SQL drivers. docs/rooms.md describes the pipeline, the storage decisions and the known gaps — chief among them that history visibility is room-level rather than per-event, and that /sync still reports no rooms, both of which belong with the event stream in Phase 4. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
150 lines
5.9 KiB
Plaintext
150 lines
5.9 KiB
Plaintext
# Warp homeserver configuration.
|
|
#
|
|
# Copy to warp.yaml and edit. Every field below is optional except
|
|
# global.server_name; the values shown are the defaults.
|
|
#
|
|
# Any field can also be set from the environment, which wins over this
|
|
# file. The variable name is on the right of each line below, e.g.
|
|
# WARP_SERVER_NAME=warp.example WARP_FEDERATION_ENABLED=true warp serve
|
|
# List values are comma-separated; a single "-" clears a list.
|
|
|
|
version: 1
|
|
|
|
global:
|
|
# The Matrix server name. It appears in every user, room and event ID
|
|
# and CANNOT be changed after the first event is written. WARP_SERVER_NAME
|
|
server_name: warp.example
|
|
|
|
# ed25519 signing key, created by `warp generate-keys`. WARP_PRIVATE_KEY
|
|
private_key: ./keys/signing.key
|
|
|
|
well_known:
|
|
# Advertised to clients as m.homeserver.base_url.
|
|
# Defaults to https://<server_name>. WARP_WELL_KNOWN_CLIENT_BASE_URL
|
|
client_base_url: ""
|
|
|
|
# Optional identity server. WARP_WELL_KNOWN_IDENTITY_SERVER_BASE_URL
|
|
identity_server_base_url: ""
|
|
|
|
# Advertised to other homeservers as m.server, e.g. "warp.example:8448".
|
|
# Only served while federation is enabled; empty means other servers
|
|
# fall back to SRV/A resolution. WARP_WELL_KNOWN_SERVER_ADDRESS
|
|
server_address: ""
|
|
|
|
listen:
|
|
address: ":8008" # WARP_LISTEN_ADDRESS
|
|
read_header_timeout: 10s # WARP_READ_HEADER_TIMEOUT
|
|
read_timeout: 60s # WARP_READ_TIMEOUT
|
|
write_timeout: 120s # WARP_WRITE_TIMEOUT
|
|
idle_timeout: 120s # WARP_IDLE_TIMEOUT
|
|
max_header_bytes: 1048576 # WARP_MAX_HEADER_BYTES
|
|
shutdown_timeout: 30s # WARP_SHUTDOWN_TIMEOUT
|
|
|
|
database:
|
|
# sqlite (dev, single user), postgres (production) or pocketbase
|
|
# (appliance; not implemented yet). WARP_DB_DRIVER
|
|
driver: sqlite
|
|
|
|
# sqlite: file:warp.db?_pragma=journal_mode(WAL)
|
|
# postgres: postgres://warp:secret@localhost/warp?sslmode=disable
|
|
# WARP_DB_CONNECTION_STRING
|
|
connection_string: "file:warp.db?_pragma=journal_mode(WAL)&_pragma=busy_timeout(10000)&_pragma=foreign_keys(1)"
|
|
|
|
max_open_conns: 10 # WARP_DB_MAX_OPEN_CONNS (ignored by sqlite:
|
|
max_idle_conns: 5 # WARP_DB_MAX_IDLE_CONNS one writer only)
|
|
conn_max_lifetime: 1h # WARP_DB_CONN_MAX_LIFETIME
|
|
|
|
# Apply pending migrations on startup. Set false to gate schema changes
|
|
# behind an explicit `warp migrate`. WARP_DB_AUTO_MIGRATE
|
|
auto_migrate: true
|
|
|
|
client_api:
|
|
# The Matrix spec expects a homeserver to allow any origin. Narrow this
|
|
# if only your own web client talks to it. WARP_CORS_ALLOWED_ORIGINS
|
|
cors_allowed_origins: ["*"]
|
|
|
|
# Take the client address from X-Forwarded-For instead of the socket.
|
|
# Turn this on ONLY behind a reverse proxy that overwrites the header:
|
|
# anyone can send it, and the rate limiter keys on the result.
|
|
# WARP_TRUST_X_FORWARDED_FOR
|
|
trust_x_forwarded_for: false
|
|
|
|
# Expire access tokens after this long. 0 (the default) issues tokens
|
|
# that never expire, which is what clients without refresh-token
|
|
# support need. With a lifetime set, clients that ask for
|
|
# refresh_token on login get one. WARP_ACCESS_TOKEN_LIFETIME
|
|
access_token_lifetime: 0s
|
|
|
|
# How long a refresh token may be exchanged for a new access token.
|
|
# 0 means no expiry. WARP_REFRESH_TOKEN_LIFETIME
|
|
refresh_token_lifetime: 0s
|
|
|
|
# Per-endpoint rate limiting. Each bucket allows `burst` requests back
|
|
# to back and returns one slot every `interval`, per client address.
|
|
# Login and registration get their own, tighter, buckets because they
|
|
# are the two endpoints worth brute-forcing.
|
|
#
|
|
# Only `enabled` has an environment override (the three buckets share a
|
|
# type, so per-bucket variables would collide): set
|
|
# WARP_RATE_LIMIT_ENABLED=false to turn the whole thing off, which is
|
|
# what a test harness such as Complement wants.
|
|
rate_limit:
|
|
enabled: true # WARP_RATE_LIMIT_ENABLED
|
|
default:
|
|
burst: 30
|
|
interval: 100ms
|
|
login:
|
|
burst: 10
|
|
interval: 1s
|
|
register:
|
|
burst: 5
|
|
interval: 2s
|
|
# Creating a room writes a dozen events and joining one writes a
|
|
# membership event that everybody in the room then sees, so both are
|
|
# deliberately slower than a read.
|
|
room_create:
|
|
burst: 10
|
|
interval: 1s
|
|
join:
|
|
burst: 10
|
|
interval: 1s
|
|
|
|
federation:
|
|
# Off by default: a new install is a private homeserver until you say
|
|
# otherwise. WARP_FEDERATION_ENABLED
|
|
enabled: false
|
|
|
|
# Non-empty = federate ONLY with these servers.
|
|
# WARP_FEDERATION_ALLOWLIST
|
|
allowlist: []
|
|
|
|
# Always blocked, even if listed above. WARP_FEDERATION_DENYLIST
|
|
denylist: []
|
|
|
|
# Let the admin API flip `enabled` without a restart. When true, the
|
|
# stored setting overrides the value above on boot.
|
|
# WARP_FEDERATION_ALLOW_RUNTIME_TOGGLE
|
|
allow_runtime_toggle: true
|
|
|
|
registration:
|
|
# Off by default. Make the first account with
|
|
# `warp create-account --username you --admin`, then turn registration
|
|
# on from the admin API if you want others to sign up.
|
|
enabled: false # WARP_REGISTRATION_ENABLED
|
|
allow_runtime_toggle: true # WARP_REGISTRATION_ALLOW_RUNTIME_TOGGLE
|
|
|
|
# Non-empty = registration also requires one of these tokens, as the
|
|
# m.login.registration_token stage of the sign-up flow. Per-token use
|
|
# counts and expiry arrive with admin token management in Phase 9.
|
|
# WARP_REGISTRATION_TOKENS
|
|
tokens: []
|
|
|
|
logging:
|
|
level: info # debug, info, warn, error WARP_LOG_LEVEL
|
|
format: text # text or json WARP_LOG_FORMAT
|
|
add_source: false # WARP_LOG_ADD_SOURCE
|
|
|
|
metrics:
|
|
enabled: true # WARP_METRICS_ENABLED
|
|
path: /metrics # WARP_METRICS_PATH
|