Expand description
Protocol handshake negotiation between peers.
When two peers connect, they exchange HandshakeOffer messages to negotiate:
- A mutually compatible protocol version (same major version required)
- The intersection of supported feature flags
- The minimum supported frame size
§Example
use ipfrs_network::protocol_handshake::{
FeatureFlag, HandshakeOffer, ProtocolHandshaker, ProtocolVersion,
};
let local_offer = HandshakeOffer {
peer_id: "local-peer".to_string(),
protocol_version: ProtocolVersion::new(1, 0, 0),
supported_features: vec![FeatureFlag::Encryption, FeatureFlag::Compression],
max_frame_size: HandshakeOffer::DEFAULT_MAX_FRAME_SIZE,
timestamp_ms: 0,
};
let handshaker = ProtocolHandshaker::new(local_offer);
let remote_offer = HandshakeOffer {
peer_id: "remote-peer".to_string(),
protocol_version: ProtocolVersion::new(1, 2, 0),
supported_features: vec![FeatureFlag::Encryption, FeatureFlag::VectorSearch],
max_frame_size: HandshakeOffer::DEFAULT_MAX_FRAME_SIZE,
timestamp_ms: 1000,
};
let result = handshaker.negotiate(&remote_offer).expect("handshake failed");
assert_eq!(result.negotiated_features.len(), 1); // only EncryptionStructs§
- Handshake
Offer - The packet a peer sends at the start of a connection to advertise its capabilities.
- Handshake
Result - The outcome of a successful protocol negotiation.
- Handshake
Stats - Live atomic counters tracking handshake outcomes.
- Handshake
Stats Snapshot - Point-in-time copy of
HandshakeStats. - Protocol
Handshaker - Drives the protocol negotiation for a single local peer.
- Protocol
Version - Semantic protocol version used during handshake.
Enums§
- Feature
Flag - Optional capabilities that a peer may support.
- Handshake
Error - Errors that can occur during the protocol handshake.
Constants§
- DEFAULT_
MAX_ FRAME_ SIZE - 4 MiB — the default maximum frame size used when no override is configured.