JavaScript is disabled, refresh for a better experience. ambee/giterated-api

ambee/giterated-api

Git repository hosting, collaboration, and discovery for the Fediverse.

Optional nativetls, defined versions and update deadpool.

erremilia - ⁨2⁩ years ago

parent: tbd commit: ⁨6a2b9bb

⁨src/lib.rs⁩ - ⁨1476⁩ bytes
Raw
1 pub use giterated_models as model;
2
3 use std::{fmt::Debug, net::SocketAddr};
4
5 use deadpool::managed::{BuildError, Pool};
6 use giterated_models::instance::Instance;
7 use pool::GiteratedConnectionPool;
8 use tokio::net::TcpStream;
9 use tokio_tungstenite::{MaybeTlsStream, WebSocketStream};
10
11 pub mod daemon_backend;
12 mod handshake;
13 mod pool;
14
15 type Socket = WebSocketStream<MaybeTlsStream<TcpStream>>;
16
17 #[macro_use]
18 extern crate tracing;
19
20 #[derive(Clone)]
21 pub struct DaemonConnectionPool(Pool<GiteratedConnectionPool>);
22
23 impl Debug for DaemonConnectionPool {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 f.debug_tuple("DaemonConnectionPool").finish()
26 }
27 }
28
29 impl DaemonConnectionPool {
30 pub fn connect(
31 instance: impl ToOwned<Owned = Instance>,
32 ) -> Result<Self, BuildError> {
33 let instance = instance.to_owned();
34 Ok(Self(
35 Pool::builder(GiteratedConnectionPool {
36 socket_addr: None,
37 target_instance: instance.to_owned(),
38 })
39 .build()?,
40 ))
41 }
42
43 pub fn connect_other(
44 instance_identity: impl ToOwned<Owned = Instance>,
45 connection_addr: SocketAddr,
46 ) -> Result<Self, BuildError> {
47 Ok(Self(
48 Pool::builder(GiteratedConnectionPool {
49 target_instance: instance_identity.to_owned(),
50 socket_addr: Some(connection_addr),
51 })
52 .build()?,
53 ))
54 }
55 }
56