Skip to main content

negotiate_server

Function negotiate_server 

Source
pub fn negotiate_server(
    offered: ProtocolVersion,
    supported: &SupportedVersions,
) -> ServerDecision
Expand description

Server-side version negotiation.

Echoes the offered version when the server supports it, and otherwise answers with the server’s latest. Never fails: the specification says a client asking for 2099-01-01 gets the server’s latest back, and a server that errors instead stops working the day a new revision is published.

§Examples

use protocol_droid::domain::{ProtocolVersion, ServerDecision, SupportedVersions, negotiate_server};

let all = SupportedVersions::all().unwrap();
// The echo branch, which is the one that gets missed.
assert_eq!(
    negotiate_server(ProtocolVersion::V2025_03_26, &all),
    ServerDecision::Echoed(ProtocolVersion::V2025_03_26),
);
// An unknown future version is answered, not rejected.
let decision = negotiate_server(ProtocolVersion::unknown_after_known("2099-01-01".parse().unwrap()).unwrap(), &all);
assert!(decision.is_counter_offer());