#![allow(clippy::disallowed_types)]
use std::sync::Arc;
pub(in crate::endpoint) mod bind;
mod dns_nameservers;
pub(in crate::endpoint) mod ffi_bridge;
pub(in crate::endpoint) mod http_runtime;
pub(in crate::endpoint) mod lifecycle;
pub(in crate::endpoint) mod observe;
mod scoped_dns_compat;
pub(in crate::endpoint) mod session_runtime;
mod source_scoped_lookup;
pub(in crate::endpoint) mod transport;
pub mod config;
pub mod stats;
pub use bind::parse_direct_addrs;
pub use config::{DiscoveryOptions, NetworkingOptions, NodeOptions, PoolOptions, StreamingOptions};
pub use http::server::stack::CompressionOptions;
pub use source_scoped_lookup::{
AddressLookupRemoval, AddressLookupSource, AddressLookupUpsert, AddressLookupUpsertError,
SourceScopedAddressLookup,
};
pub use stats::{ConnectionEvent, EndpointStats, NodeAddrInfo, PathInfo, PeerStats};
use crate::ffi::handles::HandleStore;
use crate::http;
use crate::http::transport::pool::ConnectionPool;
use ffi_bridge::FfiBridge;
use http_runtime::HttpRuntime;
use transport::Transport;
#[derive(Clone)]
pub struct IrohEndpoint {
pub(in crate::endpoint) inner: Arc<EndpointInner>,
}
pub(in crate::endpoint) struct EndpointInner {
pub(in crate::endpoint) transport: Transport,
pub(in crate::endpoint) http: HttpRuntime,
pub(in crate::endpoint) session: session_runtime::SessionRuntime,
pub(in crate::endpoint) ffi: FfiBridge,
}
impl IrohEndpoint {
pub fn node_id(&self) -> &str {
&self.inner.transport.node_id_str
}
pub fn handles(&self) -> &HandleStore {
&self.inner.ffi.handles
}
pub fn sweep_now(&self) {
let ttl = self.inner.ffi.handles.config.ttl;
if !ttl.is_zero() {
self.inner.ffi.handles.sweep(ttl);
}
}
pub(crate) fn next_serve_token(&self) -> crate::http::server::handle::ServeToken {
self.inner.session.next_serve_token()
}
pub(crate) fn set_local_service_for(
&self,
handle: &crate::http::server::ServeHandle,
svc: &crate::ffi::dispatcher::IrohHttpService,
) {
let serve_guard = self
.inner
.session
.serve_handle
.lock()
.unwrap_or_else(|e| e.into_inner());
let is_current = serve_guard
.as_ref()
.is_some_and(|current| current.is_same_cycle(handle));
if is_current && !handle.is_shutdown_requested() {
*self
.inner
.ffi
.local_service
.lock()
.unwrap_or_else(|e| e.into_inner()) = Some(svc.downgrade());
}
}
pub(crate) fn clear_local_service(&self) {
*self
.inner
.ffi
.local_service
.lock()
.unwrap_or_else(|e| e.into_inner()) = None;
}
pub(crate) fn local_service(&self) -> Option<crate::ffi::dispatcher::IrohHttpService> {
self.inner
.ffi
.local_service
.lock()
.unwrap_or_else(|e| e.into_inner())
.as_ref()
.and_then(crate::ffi::dispatcher::IrohHttpService::upgrade)
}
pub fn max_header_size(&self) -> usize {
self.inner.http.max_header_size
}
pub fn max_response_body_bytes(&self) -> usize {
self.inner.http.max_response_body_bytes
}
pub fn compression(&self) -> Option<&CompressionOptions> {
self.inner.http.compression.as_ref()
}
pub(crate) fn pool(&self) -> &ConnectionPool {
&self.inner.http.pool
}
pub(crate) fn active_connections_arc(&self) -> Arc<std::sync::atomic::AtomicUsize> {
self.inner.http.active_connections.clone()
}
pub(crate) fn active_requests_arc(&self) -> Arc<std::sync::atomic::AtomicUsize> {
self.inner.http.active_requests.clone()
}
pub(crate) fn connection_closed_tx(&self) -> tokio::sync::watch::Sender<bool> {
self.inner.session.closed_tx.clone()
}
pub fn raw(&self) -> &iroh::Endpoint {
&self.inner.transport.ep
}
}