ipfrs_network/protocol_negotiator/mod.rs
1//! Protocol version and feature negotiation between peers.
2//!
3//! When two IPFRS peers connect, they exchange [`ProtocolOffer`] messages to
4//! determine the best mutually supported configuration:
5//! - The highest protocol version both sides understand
6//! - The intersection of supported feature flags
7//! - A safe chunk size (minimum of both peers' preferences)
8//!
9//! ## Example
10//!
11//! ```rust
12//! use ipfrs_network::protocol_negotiator::{
13//! NegotiatorConfig, ProtocolFeature, ProtocolNegotiator, NegotiationResult,
14//! };
15//!
16//! let config = NegotiatorConfig::default();
17//! let negotiator = ProtocolNegotiator::new(config);
18//!
19//! let local = negotiator.config.local_offer(
20//! "local-peer".to_string(),
21//! vec![ProtocolFeature::Encryption, ProtocolFeature::Compression],
22//! );
23//! let remote = negotiator.config.local_offer(
24//! "remote-peer".to_string(),
25//! vec![ProtocolFeature::Encryption, ProtocolFeature::Multiplexing],
26//! );
27//!
28//! match negotiator.negotiate(&local, &remote) {
29//! NegotiationResult::Agreed { version, features, chunk_size } => {
30//! assert_eq!(version, 3);
31//! assert_eq!(features, vec![ProtocolFeature::Encryption]);
32//! assert_eq!(chunk_size, 65536);
33//! }
34//! other => panic!("unexpected result: {:?}", other),
35//! }
36//! ```
37
38pub mod constants;
39pub mod functions;
40pub mod negotiatorconfig_traits;
41pub mod peerprotocolnegotiator_traits;
42pub mod peerprotocolversion_traits;
43pub mod pnnegotiatorconfig_traits;
44pub mod pnprotocolnegotiator_traits;
45pub mod pnprotocolversion_traits;
46pub mod types;
47
48// Re-export all types
49pub use types::*;
50
51#[cfg(test)]
52mod tests;