//! # peat-mesh
//!
//! Mesh networking library for the Peat ecosystem: pluggable transport,
//! peer discovery, topology management, and optional Automerge/Iroh sync
//! over a service broker.
//!
//! ## Cargo features
//!
//! | Feature | Default | Purpose |
//! |---------|---------|---------|
//! | `automerge-backend` | yes | Automerge CRDT storage with Iroh P2P sync and redb persistence. |
//! | `bluetooth` | no | BLE mesh transport via `peat-btle`. |
//! | `broker` | no | HTTP/WebSocket service broker (Axum). |
//! | `kubernetes` | no | Kubernetes peer discovery via EndpointSlice API. |
//! | `node` | no | All-in-one feature for the `peat-mesh-node` binary. |
//! | `lite-bridge` | no | UDP bridge for Peat-Lite embedded devices. |
//! | `relay-n0-hosted` | **no** | Opt-in to n0's hosted iroh relay pool and DNS pkarr discovery. **See the security note below.** |
//!
//! ### Relay policy (`relay-n0-hosted`)
//!
//! By default, peat-mesh's iroh endpoint construction (see
//! [`storage::iroh_blob_store`]) uses [`iroh::Endpoint::empty_builder`] —
//! **no third-party relay servers, no DNS pkarr discovery via n0-hosted
//! infrastructure**. When [`config::IrohConfig::relay_urls`] is empty,
//! relays are disabled outright; when it is non-empty, those URLs are
//! applied as `RelayMode::Custom`. This is the correct posture for
//! tactical, edge, and air-gapped deployments where peer traffic must not
//! transit a third-party CDN.
//!
//! Enabling the `relay-n0-hosted` feature switches the default builder to
//! `iroh::Endpoint::builder(iroh::endpoint::presets::N0)`, restoring n0's
//! hosted relay pool (`*.iroh.network`, `*.iroh-canary.iroh.link`) and
//! DNS pkarr discovery. An empty `relay_urls` then falls through to n0's
//! defaults instead of being treated as "disabled". Use this only when
//! you have explicit authorization to route peer traffic through n0's
//! infrastructure.
//!
//! ```toml
//! # Default — no n0 phone-home (lands in 0.9.0-rc.8 or later):
//! peat-mesh = { version = ">=0.9.0-rc.8", features = ["automerge-backend"] }
//!
//! # Opt-in — restores n0 hosted relay/DNS:
//! peat-mesh = { version = ">=0.9.0-rc.8", features = ["automerge-backend", "relay-n0-hosted"] }
//! ```
//!
//! See [defenseunicorns/peat#833](https://github.com/defenseunicorns/peat/issues/833)
//! for context.

#![cfg_attr(docsrs, feature(doc_auto_cfg))]

#[cfg(feature = "broker")]
pub mod broker;

pub mod beacon;
pub mod config;
pub mod discovery;
pub mod flat_mesh;
pub mod geohash;
pub mod hierarchy;
pub mod mesh;
#[cfg(feature = "automerge-backend")]
pub mod network;
pub mod node;
#[cfg(feature = "automerge-backend")]
pub mod peer_connector;
pub mod qos;
pub mod routing;
pub mod security;
pub mod storage;
pub mod sync;
pub mod topology;
pub mod transport;

// Re-export main types
pub use beacon::{
    BeaconBroadcaster, BeaconJanitor, BeaconObserver, GeoPosition, GeographicBeacon, HierarchyLevel,
};
pub use flat_mesh::FlatMeshCoordinator;
pub use hierarchy::{
    DynamicHierarchyStrategy, ElectionConfig, ElectionWeights, HierarchyStrategy,
    HybridHierarchyStrategy, NodeRole, StaticHierarchyStrategy,
};
pub use routing::{
    AggregationError, Aggregator, DataDirection, DataPacket, DataType, DeduplicationConfig,
    MeshRouter, NoOpAggregator, RoutingDecision, SelectiveRouter,
};
pub use topology::{
    AutonomousOperationHandler, AutonomousState, InMemoryMetricsCollector, MetricsCollector,
    NoOpMetricsCollector, PartitionConfig, PartitionDetector, PartitionEvent, PartitionHandler,
    PeerCandidate, PeerSelector, SelectedPeer, SelectionConfig, TopologyBuilder, TopologyConfig,
    TopologyEvent, TopologyMetricsSnapshot, TopologyState,
};
pub use transport::{
    ConnectionHealth, ConnectionState, DisconnectReason, MeshConnection, MeshTransport, NodeId,
    PeerEvent, PeerEventReceiver, TransportError, TransportManager, TransportManagerConfig,
};

// Sync backend re-exports
pub use sync::InMemoryBackend;

// Application-level mesh document layer
pub use node::Node;

// Phase 7 facade re-exports
pub use config::{CompactionConfig, IrohConfig, MeshConfig, MeshDiscoveryConfig, SecurityConfig};
pub use mesh::{MeshError, MeshState, MeshStatus, PeatMesh, PeatMeshBuilder, PeatMeshEvent};
