use {
crate::{
discovery::Discovery,
groups::Groups,
primitives::{Digest, sealed::Sealed},
streams::Streams,
},
iroh::protocol::{Router, RouterBuilder},
};
mod builder;
pub mod error;
pub(crate) mod link;
mod local;
pub use {
builder::{NetworkBuilder, NetworkConfig},
error::{Error as NetworkError, *},
iroh::RelayMode,
local::LocalNode,
};
pub struct Network {
local: LocalNode,
discovery: Discovery,
streams: Streams,
groups: Groups,
#[allow(dead_code)]
router: Router,
}
pub type NetworkId = Digest;
pub type PeerId = iroh::EndpointId;
impl Network {
pub fn builder(network_id: NetworkId) -> NetworkBuilder {
NetworkBuilder::default().with_network_id(network_id)
}
pub async fn new(network_id: NetworkId) -> Result<Self, NetworkError> {
NetworkBuilder::default()
.with_network_id(network_id)
.build()
.await
}
}
impl Network {
pub fn network_id(&self) -> &NetworkId {
self.local.network_id()
}
pub const fn local(&self) -> &LocalNode {
&self.local
}
pub async fn online(&self) {
self.local.online().await;
}
pub const fn discovery(&self) -> &Discovery {
&self.discovery
}
pub const fn streams(&self) -> &Streams {
&self.streams
}
pub const fn groups(&self) -> &Groups {
&self.groups
}
}
impl Drop for Network {
fn drop(&mut self) {
self.local.termination().cancel();
}
}
pub(crate) trait ProtocolProvider {
fn install(&self, protocols: RouterBuilder) -> RouterBuilder;
}
impl Sealed for Network {}