Skip to main content

Module protocol_handshake

Module protocol_handshake 

Source
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 Encryption

Structs§

HandshakeOffer
The packet a peer sends at the start of a connection to advertise its capabilities.
HandshakeResult
The outcome of a successful protocol negotiation.
HandshakeStats
Live atomic counters tracking handshake outcomes.
HandshakeStatsSnapshot
Point-in-time copy of HandshakeStats.
ProtocolHandshaker
Drives the protocol negotiation for a single local peer.
ProtocolVersion
Semantic protocol version used during handshake.

Enums§

FeatureFlag
Optional capabilities that a peer may support.
HandshakeError
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.