lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

configure_transport.rs (1152B)


      1 use radroots_transport::{EventSink, EventSource, EventSubscriber};
      2 use radroots_transport_nostr::{
      3     Config, NostrTransport, RelayAccess, RelayEndpoint, RelayProfile, RelayProfileKind,
      4     RelayUrlPolicy,
      5 };
      6 
      7 pub fn configure_transport(
      8     host: std::sync::Arc<dyn radroots_transport::host::websocket::Connector>,
      9 ) -> Result<(), Box<dyn std::error::Error>> {
     10     let endpoint = RelayEndpoint::new(
     11         "wss://relay.example.com",
     12         RelayUrlPolicy::Public,
     13         RelayAccess::ReadWrite,
     14     )?;
     15     let profile = RelayProfile::explicit(RelayProfileKind::Public, [endpoint])?;
     16     let config = Config::from_profile(profile).with_timeouts(5_000, 20_000, 2_000)?;
     17     let transport = NostrTransport::new(config, host);
     18 
     19     let source: &dyn EventSource = &transport;
     20     let subscriber: &dyn EventSubscriber = &transport;
     21     let sink: &dyn EventSink = &transport;
     22     drop(source.status());
     23     let _ = subscriber;
     24     drop(sink.status());
     25 
     26     println!("configured a Nostr source, subscriber, and sink without opening a relay connection");
     27     Ok(())
     28 }
     29 
     30 fn main() {
     31     println!("call configure_transport with an explicit socket host");
     32 }