pub mod message;
pub mod handshake;
pub mod channel;
pub use message::{Message, MessageType};
pub use handshake::Handshake;
pub use channel::{Channel, ChannelType};
use crate::{Error, Result};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProtocolVersion {
pub major: u8,
pub minor: u8,
pub patch: u8,
}
impl ProtocolVersion {
pub const BITCHAT: Self = Self {
major: 1,
minor: 0,
patch: 0,
};
pub const QCOMM: Self = Self {
major: 1,
minor: 0,
patch: 0,
};
pub fn is_compatible(&self, other: &Self) -> bool {
self.major == other.major
}
}
impl std::fmt::Display for ProtocolVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PeerCapabilities {
pub version: ProtocolVersion,
pub pq_ratchet: bool,
pub qrng: bool,
pub qkd: bool,
pub ai_agents: bool,
pub blockchain: bool,
pub transports: Vec<String>,
}
impl Default for PeerCapabilities {
fn default() -> Self {
Self {
version: ProtocolVersion::QCOMM,
pq_ratchet: true,
qrng: false,
qkd: false,
ai_agents: false,
blockchain: false,
transports: vec!["ble".into(), "nostr".into()],
}
}
}
impl PeerCapabilities {
pub fn bitchat() -> Self {
Self {
version: ProtocolVersion::BITCHAT,
pq_ratchet: false,
qrng: false,
qkd: false,
ai_agents: false,
blockchain: false,
transports: vec!["ble".into(), "nostr".into()],
}
}
pub fn supports_pqc(&self) -> bool {
self.pq_ratchet
}
pub fn negotiate(&self, other: &Self) -> NegotiatedCapabilities {
NegotiatedCapabilities {
use_pqc: self.pq_ratchet && other.pq_ratchet,
use_qrng: self.qrng && other.qrng,
use_qkd: self.qkd && other.qkd,
}
}
}
#[derive(Debug, Clone)]
pub struct NegotiatedCapabilities {
pub use_pqc: bool,
pub use_qrng: bool,
pub use_qkd: bool,
}