arete_sdk/
lib.rs

1mod cache;
2mod client;
3mod consumer;
4mod context;
5mod error;
6mod node;
7mod provider;
8mod stats;
9mod system;
10
11pub use cache::Cache;
12pub use client::{Client, DEFAULT_TIMEOUT_SECS};
13pub use consumer::Consumer;
14pub use context::Context;
15pub use error::Error;
16pub use node::Node;
17pub use provider::Provider;
18pub use stats::Stats;
19use std::sync::{Arc, Mutex};
20pub use system::System;
21use tungstenite::{handshake::client::Response, stream::MaybeTlsStream};
22
23pub fn connect(url: &str) -> Result<(Client, Response), Error> {
24    // Connect
25    let (mut socket, res) = tungstenite::connect(url)?;
26
27    // Configure non-blocking reads
28    match socket.get_mut() {
29        MaybeTlsStream::Plain(stream) => stream.set_nonblocking(true)?,
30        MaybeTlsStream::Rustls(stream) => stream.get_mut().set_nonblocking(true)?,
31        _ => {}
32    }
33
34    // Respond
35    let client = Client::new(Arc::new(Mutex::new(socket)));
36    Ok((client, res))
37}