PeerServer
A class in fastatp.server.peer_server (source).
PeerServer(
peer: Peer,
repo: Repo,
backfill_window: int = 512,
*,
identity_resolver: CallerResolver | None = None,
warn_on_proxy: bool = True,
proxy_warn_threshold: int = 8,
)
Hosts a peer's repos; exposes the firehose and checkpoint routes.
Attributes
peerbackfill_windowidentity_resolver: CallerResolverapprepo: Reposeq: int
Methods
create
async create(
peer: Peer,
repo: Repo | None = None,
*,
repo_store: BlockStore | None = None,
storage: Storage | None = None,
backfill_window: int = 512,
**kwargs: Any,
) -> PeerServer
A server for peer, announced on its firehose. Over repo if
given, else over a fresh one whose genesis the peer's signer signs, in
storage (one database for blocks, heads and blobs) or over a bare
repo_store for its blocks. PeerServer(peer, repo) builds one
without announcing; it announces on the first emit or subscriber.
register
async register(
repo: Repo,
*,
public: bool = False,
owner_pull: bool | OwnerRule = False,
backfill_window: int | None = None,
ttl: float | None = None,
expires_at: datetime | None = None,
) -> RepoHandle
Host repo (routed by its DID) and return its write handle.
public=False (the default — gated) marks the repo for the doorman;
public=True opts it into open reads (a board). Writes go only
through the returned handle — there is no string-DID write API (see
RepoHandle).
owner_pull lets the pen that writes a gated repo, and the identity
itself through a delegated device, read it back with no capability
record: a host serving a repo to its own pen is that peer reaching
its own storage, not a subscriber. Off by default, so a host must
choose it per repo. True uses the default rule — the
caller is a did:key whose key verifies the head commit — which
admits a rotated-out pen until the new one pushes; pass an
OwnerRule when the host knows the current pen (its chain
head). The caller still has to prove the pen (WireGuard identity or
the browser gate's signed knock); the capability rule applies to
everyone else exactly as before.
Owner pull decides who reads; frozen decides that this host cannot
write. An owner_pull registration requires a frozen repo
(Repo(did, None, ...), see Repo.frozen): a repo served to
its own pen is one whose pen lives elsewhere, and a host holding a
pen for it is the custody shape the philosophy forbids, so the
package says so at registration. The rule is one-way: a frozen repo
may be registered without owner pull (a public mirror), and a penned
repo without owner pull is this peer's own. Pushes land through
repo.import_car with the owner's key, and RepoHandle.emit_sync
announces the new head to subscribers.
What keeps a hosted repo honest is the owner's signature, verified by every consumer, as on any atproto host; that is not FastATP's rule but atproto's. Frozen makes the same rule hold inside this host's code: with no pen there is no path here that makes a commit.
A whole-repo TTL retires the repo automatically: pass ttl (seconds
from now) or expires_at (an aware datetime). Past its expiry the
repo is unroutable (RepoNotFound) and its subscribers are cut — the
lifecycle of an ephemeral channel. Reaping is lazy (on the next
access) and eager (reap_expired); the block store is released
when the last reference to the retired repo drops.
unregister
async unregister(did: str) -> None
Stop hosting did's repo and poison its live subscribers.
The primary repo cannot be unregistered (it is the peer's own repo). Unknown DIDs are a no-op.
reap_expired
async reap_expired(now: datetime | None = None) -> list[str]
Retire every expired hosted repo now; returns the reaped DIDs.
Lazy reaping already keeps expired repos unroutable, but a long-lived ephemeral repo with no further reads would otherwise linger until touched; call this periodically to reclaim eagerly.
hosts
hosts() -> list[str]
DIDs of every currently hosted repo (primary first is not implied).
hosted_repo
hosted_repo(did: str) -> Repo | None
Read access to a hosted repo by DID; None if unknown or expired.
The host-side RepoSource for delegation walks: a DID
whose repo this server does not hold simply cannot be presence-checked
here — fail closed falls out.
put_record
async put_record(collection: str, rkey: str, record: RecordLike) -> CommitEvent | None
delete_record
async delete_record(collection: str, rkey: str) -> CommitEvent | None
apply_writes
async apply_writes(writes: list[WriteOp]) -> CommitEvent | None
emit_account
async emit_account(*, active: bool = True, status: str | None = None) -> None
Re-announce the primary repo's hosting status (#account).
emit_identity
async emit_identity(*, handle: str | None = None) -> None
Prod subscribers to refresh the primary DID's identity (#identity).
run
run(host: str = '127.0.0.1', port: int = 8001, **kwargs: Any) -> None
Run standalone under uvicorn (blocking).
serve
async serve(host: str = '127.0.0.1', port: int = 8001, **kwargs: Any) -> None
Serve on the running event loop; run starts its own.
The write path is async, so a program whose main awaits
Repo.create or Identity.bootstrap serves with this.