Skip to main content

ossa_core/network/
mod.rs

1pub mod multiplexer;
2pub mod protocol;
3
4use std::fmt::Debug;
5
6use crate::network::protocol::{receive, send};
7use crate::util::Stream;
8
9// Manage a connection with a peer.
10// TODO: Delete ConnectionManager.
11pub struct ConnectionManager<S> {
12    // }:Stream> {
13    connection: S,
14}
15
16impl<S> ConnectionManager<S> {
17    pub fn new(connection: S) -> ConnectionManager<S> {
18        ConnectionManager { connection }
19    }
20    /// Retrieve the connection status.
21    pub async fn connection_status(&self) -> ConnectionStatus {
22        ConnectionStatus::Active
23    }
24
25    pub async fn send<T, U>(&mut self, val: U)
26    where
27        S: Stream<T>,
28        U: Into<T>,
29    {
30        send(&mut self.connection, val).await.expect("TODO")
31    }
32
33    pub async fn receive<T, U>(&mut self) -> U
34    where
35        S: Stream<T>,
36        T: TryInto<U>,
37        U: Debug,
38    {
39        receive(&mut self.connection).await.expect("TODO")
40    }
41}
42
43#[derive(PartialEq)]
44pub enum ConnectionStatus {
45    Active,
46    Done,
47}