From 06f4ebf47f88cd79cb9d9a13753552bc61e579e4 Mon Sep 17 00:00:00 2001 From: Charlotte Som Date: Wed, 27 Nov 2024 16:35:46 +0200 Subject: [PATCH] make plc resolver location configurable --- src/lib.rs | 4 +++- src/main.rs | 13 +++++++++++-- src/user.rs | 3 +-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e3a0706..94a4f75 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -use std::collections::BTreeSet; +use std::{borrow::Cow, collections::BTreeSet}; use anyhow::Result; use bytes::Bytes; @@ -11,6 +11,7 @@ pub struct RelayServer { pub db_users: sled::Tree, pub db_index_cursors: sled::Tree, + pub plc_resolver: Cow<'static, str>, pub known_good_hosts: Mutex>, pub active_indexers: Mutex>, @@ -32,6 +33,7 @@ impl RelayServer { event_tx, raw_block_tx, + plc_resolver: Cow::Borrowed("plc.directory"), known_good_hosts: Mutex::new(hosts.into_iter().collect()), active_indexers: Default::default(), diff --git a/src/main.rs b/src/main.rs index fface0c..eb1fc5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use anyhow::Result; use clap::Parser; -use std::{net::SocketAddr, str::FromStr, sync::Arc}; +use std::{borrow::Cow, net::SocketAddr, str::FromStr, sync::Arc}; use tokio::sync::mpsc; use tracing_subscriber::{fmt, prelude::*, EnvFilter}; @@ -21,6 +21,10 @@ struct Args { /// Database RAM cache capacity in megabytes #[arg(long, default_value_t = 1024)] cache_capacity: u64, + + /// did:plc directory HTTPS host. defaults to plc.directory if unset + #[arg(long)] + plc_resolver: Option, } #[tokio::main] @@ -41,7 +45,12 @@ async fn main() -> Result<()> { let (event_tx, event_rx) = mpsc::channel(128); - let server = Arc::new(RelayServer::new(db, event_tx)); + let mut server = RelayServer::new(db, event_tx); + if let Some(plc_directory) = args.plc_resolver { + server.plc_resolver = Cow::Owned(plc_directory); + } + + let server = Arc::new(server); let initial_hosts: Vec = { let hosts = server.known_good_hosts.lock().await; hosts.iter().cloned().collect() diff --git a/src/user.rs b/src/user.rs index fe9ec25..9956a32 100644 --- a/src/user.rs +++ b/src/user.rs @@ -47,8 +47,7 @@ fn create_user_from_did_doc(did_doc: DidDocument) -> Result { pub async fn fetch_user(server: &RelayServer, did: &str) -> Result { tracing::debug!(%did, "fetching user"); if did.starts_with("did:plc:") { - // TODO: configurable plc resolver location - let domain = "plc.directory"; + let domain: &str = &server.plc_resolver; let tcp_stream = TcpStream::connect((domain, 443)).await?; let domain_tls: ServerName<'_> = ServerName::try_from(domain.to_string())?;