use std::collections::HashSet;
use futures::{AsyncRead, AsyncWrite, Stream, future::BoxFuture};
use hopr_types::crypto::keypairs::OffchainKeypair;
use super::Health;
use crate::{Multiaddr, PeerId};
pub type BoxedProcessFn = Box<dyn FnOnce() -> BoxFuture<'static, ()> + Send>;
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;
}
#[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>;
}
#[async_trait::async_trait]
pub trait NetworkBuilder {
type Network: NetworkView + NetworkStreamControl + Send + Sync + Clone + 'static;
async fn build(
self,
identity: &OffchainKeypair,
my_multiaddresses: Vec<Multiaddr>,
protocol: &'static str,
allow_private_addresses: bool,
) -> Result<(Self::Network, BoxedProcessFn), impl std::error::Error>;
}