make plc resolver location configurable

main
Charlotte Som 2024-11-27 16:35:46 +02:00
parent 9415d90b9f
commit 06f4ebf47f
3 changed files with 15 additions and 5 deletions

View File

@ -1,4 +1,4 @@
use std::collections::BTreeSet; use std::{borrow::Cow, collections::BTreeSet};
use anyhow::Result; use anyhow::Result;
use bytes::Bytes; use bytes::Bytes;
@ -11,6 +11,7 @@ pub struct RelayServer {
pub db_users: sled::Tree, pub db_users: sled::Tree,
pub db_index_cursors: sled::Tree, pub db_index_cursors: sled::Tree,
pub plc_resolver: Cow<'static, str>,
pub known_good_hosts: Mutex<BTreeSet<String>>, pub known_good_hosts: Mutex<BTreeSet<String>>,
pub active_indexers: Mutex<BTreeSet<String>>, pub active_indexers: Mutex<BTreeSet<String>>,
@ -32,6 +33,7 @@ impl RelayServer {
event_tx, event_tx,
raw_block_tx, raw_block_tx,
plc_resolver: Cow::Borrowed("plc.directory"),
known_good_hosts: Mutex::new(hosts.into_iter().collect()), known_good_hosts: Mutex::new(hosts.into_iter().collect()),
active_indexers: Default::default(), active_indexers: Default::default(),

View File

@ -1,6 +1,6 @@
use anyhow::Result; use anyhow::Result;
use clap::Parser; 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 tokio::sync::mpsc;
use tracing_subscriber::{fmt, prelude::*, EnvFilter}; use tracing_subscriber::{fmt, prelude::*, EnvFilter};
@ -21,6 +21,10 @@ struct Args {
/// Database RAM cache capacity in megabytes /// Database RAM cache capacity in megabytes
#[arg(long, default_value_t = 1024)] #[arg(long, default_value_t = 1024)]
cache_capacity: u64, cache_capacity: u64,
/// did:plc directory HTTPS host. defaults to plc.directory if unset
#[arg(long)]
plc_resolver: Option<String>,
} }
#[tokio::main] #[tokio::main]
@ -41,7 +45,12 @@ async fn main() -> Result<()> {
let (event_tx, event_rx) = mpsc::channel(128); 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<String> = { let initial_hosts: Vec<String> = {
let hosts = server.known_good_hosts.lock().await; let hosts = server.known_good_hosts.lock().await;
hosts.iter().cloned().collect() hosts.iter().cloned().collect()

View File

@ -47,8 +47,7 @@ fn create_user_from_did_doc(did_doc: DidDocument) -> Result<User> {
pub async fn fetch_user(server: &RelayServer, did: &str) -> Result<User> { pub async fn fetch_user(server: &RelayServer, did: &str) -> Result<User> {
tracing::debug!(%did, "fetching user"); tracing::debug!(%did, "fetching user");
if did.starts_with("did:plc:") { if did.starts_with("did:plc:") {
// TODO: configurable plc resolver location let domain: &str = &server.plc_resolver;
let domain = "plc.directory";
let tcp_stream = TcpStream::connect((domain, 443)).await?; let tcp_stream = TcpStream::connect((domain, 443)).await?;
let domain_tls: ServerName<'_> = ServerName::try_from(domain.to_string())?; let domain_tls: ServerName<'_> = ServerName::try_from(domain.to_string())?;