Function quiche::negotiate_version

source ·
pub fn negotiate_version(
    scid: &ConnectionId<'_>,
    dcid: &ConnectionId<'_>,
    out: &mut [u8]
) -> Result<usize>
Expand description

Writes a version negotiation packet.

The scid and dcid parameters are the source connection ID and the destination connection ID extracted from the received client’s Initial packet that advertises an unsupported version.


let (len, src) = socket.recv_from(&mut buf).unwrap();

let hdr =
    quiche::Header::from_slice(&mut buf[..len], quiche::MAX_CONN_ID_LEN)?;

if hdr.version != quiche::PROTOCOL_VERSION {
    let len = quiche::negotiate_version(&hdr.scid, &hdr.dcid, &mut out)?;
    socket.send_to(&out[..len], &src).unwrap();