hashiverse_lib/transport/
partial_https_transport.rs1use bytes::Bytes;
15use std::sync::Arc;
16use crate::transport::bootstrap_provider::bootstrap_provider::BootstrapProvider;
17use crate::transport::transport::{TransportFactory, TransportServer};
18
19#[derive(Clone)]
25pub struct PartialHttpsTransportFactory {
26 bootstrap_provider: Arc<dyn BootstrapProvider>,
27}
28
29impl PartialHttpsTransportFactory {
30 pub fn new(bootstrap_provider: Arc<dyn BootstrapProvider>) -> Self {
31 Self { bootstrap_provider }
32 }
33}
34
35#[async_trait::async_trait]
36impl TransportFactory for PartialHttpsTransportFactory {
37 async fn get_bootstrap_addresses(&self) -> Vec<String> {
38 self.bootstrap_provider.get_bootstrap_addresses().await
39 }
40
41 async fn create_server(&self, _base_path: &str, _port: u16, _force_local_network: bool) -> anyhow::Result<Arc<dyn TransportServer>> {
42 anyhow::bail!("HttpsTransportFactory is client-only and does not support create_server(). Use ServerHttpsTransportFactory from hashiverse-server-lib.")
43 }
44
45 async fn rpc(&self, address: &str, bytes: Bytes) -> anyhow::Result<Bytes> {
46 let url = format!("https://{}/", address);
47 let client = reqwest::ClientBuilder::new().danger_accept_invalid_certs(true).build()?;
50 let response = client.post(url).body(bytes).send().await?;
51 let response_bytes = response.bytes().await?;
52 Ok(response_bytes)
53 }
54}