Federation
Federation allows homeservers to communicate with each other, enabling cross-server room participation.
Federation Endpoints
All endpoints are under /_matrix/federation/v1/ (except invite v2).
Request Signing
Every federation request is signed using the server's ed25519 signing key.
Signing Process
- Build canonical JSON of the request body
- Compute SHA-256 hash → base64url (no padding)
- Build signing string:
origin destination method uri ts content_hash - Sign with server's private key
- Attach
Authorization: X-Matrix origin=...,destination=...,key=...,sig=...,ts=...
Verification
FederationRequestSigningService.verifyRequestSignature() checks:
- Authorization header format (
X-Matrix ...) - Origin/destination matching
- Clock skew (within 5 minutes)
- Content hash integrity
Cryptographic signature verification against remote server's public key is currently accept-all. Full verification requires fetching the remote signing key from /_matrix/key/v2/server.
Key Cache
FederationKeyCache caches remote server signing keys:
- TTL: Keys cached for configurable duration
- Negative cache: Failed key lookups cached briefly to avoid hammering
- Notary: Query other servers for a target server's key via
/_matrix/key/v2/query
Destination Queue
FederationDestinationQueue manages outbound transactions:
- Exponential backoff: Failed deliveries retry with increasing delays
- Dead detection: Mark destinations as unreachable after repeated failures
- Transaction IDs: Monotonically increasing per destination
EDU Processing
Ephemeral Data Units (EDUs) carry real-time state across servers:
Server Discovery
SigningKeyService manages the local server's ed25519 key pair with automatic rotation (7-day period).