use bytes::Bytes;
use std::sync::Arc;
use crate::transport::bootstrap_provider::bootstrap_provider::BootstrapProvider;
use crate::transport::transport::{TransportFactory, TransportServer};
#[derive(Clone)]
pub struct PartialHttpsTransportFactory {
bootstrap_provider: Arc<dyn BootstrapProvider>,
}
impl PartialHttpsTransportFactory {
pub fn new(bootstrap_provider: Arc<dyn BootstrapProvider>) -> Self {
Self { bootstrap_provider }
}
}
#[async_trait::async_trait]
impl TransportFactory for PartialHttpsTransportFactory {
async fn get_bootstrap_addresses(&self) -> Vec<String> {
self.bootstrap_provider.get_bootstrap_addresses().await
}
async fn create_server(&self, _base_path: &str, _port: u16, _force_local_network: bool) -> anyhow::Result<Arc<dyn TransportServer>> {
anyhow::bail!("HttpsTransportFactory is client-only and does not support create_server(). Use ServerHttpsTransportFactory from hashiverse-server-lib.")
}
async fn rpc(&self, address: &str, bytes: Bytes) -> anyhow::Result<Bytes> {
let url = format!("https://{}/", address);
let client = reqwest::ClientBuilder::new().danger_accept_invalid_certs(true).build()?;
let response = client.post(url).body(bytes).send().await?;
let response_bytes = response.bytes().await?;
Ok(response_bytes)
}
}