use std::collections::HashSet;
use futures::{AsyncRead, AsyncWrite, Stream, future::BoxFuture};
use super::{Health, NetworkEvent};
use crate::{Multiaddr, PeerId};
pub type BoxedProcessFn = Box<dyn FnOnce() -> BoxFuture<'static, ()> + Send>;
#[auto_impl::auto_impl(&, Arc)]
pub trait NetworkView {
fn listening_as(&self) -> HashSet<Multiaddr>;
fn multiaddress_of(&self, peer: &PeerId) -> Option<HashSet<Multiaddr>>;
fn discovered_peers(&self) -> HashSet<PeerId>;
fn connected_peers(&self) -> HashSet<PeerId>;
fn is_connected(&self, peer: &PeerId) -> bool;
fn health(&self) -> Health;
fn subscribe_network_events(&self) -> impl Stream<Item = NetworkEvent> + Send + 'static;
}
#[async_trait::async_trait]
pub trait NetworkStreamControl: std::fmt::Debug {
fn accept(
self,
) -> Result<impl Stream<Item = (PeerId, impl AsyncRead + AsyncWrite + Send)> + Send, impl std::error::Error>;
async fn open(self, peer: PeerId) -> Result<impl AsyncRead + AsyncWrite + Send, impl std::error::Error>;
}