pub fn retry(
scid: &ConnectionId<'_>,
dcid: &ConnectionId<'_>,
new_scid: &ConnectionId<'_>,
token: &[u8],
version: u32,
out: &mut [u8],
) -> Result<usize>
Expand description
Writes a stateless retry packet.
The scid
and dcid
parameters are the source connection ID and the
destination connection ID extracted from the received client’s Initial
packet, while new_scid
is the server’s new source connection ID and
token
is the address validation token the client needs to echo back.
The application is responsible for generating the address validation
token to be sent to the client, and verifying tokens sent back by the
client. The generated token should include the dcid
parameter, such
that it can be later extracted from the token and passed to the
accept()
function as its odcid
parameter.
§Examples:
let (len, peer) = socket.recv_from(&mut buf).unwrap();
let hdr = quiche::Header::from_slice(&mut buf[..len], quiche::MAX_CONN_ID_LEN)?;
let token = hdr.token.as_ref().unwrap();
// No token sent by client, create a new one.
if token.is_empty() {
let new_token = mint_token(&hdr, &peer);
let len = quiche::retry(
&hdr.scid, &hdr.dcid, &scid, &new_token, hdr.version, &mut out,
)?;
socket.send_to(&out[..len], &peer).unwrap();
return Ok(());
}
// Client sent token, validate it.
let odcid = validate_token(&peer, token);
if odcid.is_none() {
// Invalid address validation token.
return Ok(());
}
let conn = quiche::accept(&scid, odcid.as_ref(), local, peer, &mut config)?;