A rust implementation of skywatch-phash
README.md

PLC Module#

Purpose#

This module provides a resilient client for interacting with the PLC (Progressive Ledger Consensus) directory, which is the source of truth for DID (Decentralized Identifier) documents in the AT Protocol ecosystem. Its primary function is to resolve a DID into its corresponding DID Document, which contains essential metadata like service endpoints.

Key Components#

mod.rs#

  • DidDocument & ServiceEndpoint: Structs representing the deserialized JSON response from a PLC directory.
  • PlcClient: A client designed for resolving DIDs with built-in resiliency.
    • It is initialized with a primary PLC endpoint and a list of fallback endpoints from the application Config.
  • resolve_did(did): The main method for fetching a DID Document. It implements a failover mechanism, trying the primary endpoint first and then cycling through the fallback endpoints if the primary fails.
  • get_pds_endpoint(did): A convenience method that calls resolve_did and then parses the resulting document to find and return the URL for the AtprotoPersonalDataServer service.

Failover Logic#

The PlcClient is designed to be robust against PLC directory outages or network issues.

  1. Initialization: The client is created with an ordered list of PLC directory URLs (primary first, then fallbacks).
  2. Resolution Attempt: When resolve_did is called, it iterates through this list.
  3. On Failure: If a request to an endpoint fails (due to a network error, an HTTP error status, or invalid JSON), the client logs the issue and automatically retries the request with the next endpoint in the list.
  4. On Success: As soon as a request to any endpoint succeeds, the result is returned immediately.
  5. Total Failure: If all endpoints in the list fail, the function returns the error from the last-attempted endpoint.

This ensures that the service can continue to resolve DIDs as long as at least one configured PLC directory is accessible.

Configuration#

  • PLC_ENDPOINT: (Default: https://plc.directory) The primary PLC directory URL.
  • PLC_FALLBACK_ENDPOINTS: A comma-separated list of alternative PLC directory URLs.