torrentdht 0.1.1

DHT discovery with mTLS handshake handoff; optional BitTorrent when the host opts in
Documentation
//! Message Stream Encryption / Protocol Encryption (BEP-adjacent MSE/PE).
//!
//! Selectable via `swarm-security "mse"` with `swarm-transport "tcp"`.
//! Provides Diffie–Hellman + RC4 (or plaintext) negotiation before the
//! BitTorrent handshake. Default production path remains mTLS.

mod carrier;
mod dh;
mod handshake;
mod rc4;
mod stream;

pub use handshake::{
    accept_mse, accept_mse_carrier, accept_mse_utp, dial_mse, dial_mse_carrier, dial_mse_utp,
    CryptoSelect,
};
pub use stream::MseStream;

use crate::swarm::SwarmStack;

/// MSE/PE over TCP is implemented.
pub const IMPLEMENTED: bool = true;

pub fn is_implemented() -> bool {
    IMPLEMENTED
}

pub fn dial_not_implemented<T>(stack: SwarmStack) -> crate::error::Result<T> {
    Err(crate::error::Error::Config(format!(
        "swarm stack {} cannot use MSE (need swarm-transport \"tcp\")",
        stack.describe()
    )))
}

pub fn accept_not_implemented<T>(stack: SwarmStack) -> crate::error::Result<T> {
    dial_not_implemented(stack)
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::config::SwarmSecurity;

    #[test]
    fn mse_security_is_implemented() {
        assert!(is_implemented());
        assert!(SwarmSecurity::Mse.is_implemented());
    }
}