-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathtraits.rs
94 lines (81 loc) · 3.18 KB
/
traits.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
use crate::{crypto::tls::TlsSession, dc, stateless_reset, transport};
use alloc::vec::Vec;
/// The `dc::Endpoint` trait provides a way to support dc functionality
pub trait Endpoint: 'static + Send {
/// If enabled, a dc version will attempt to be negotiated and dc-specific frames
/// will be processed. Otherwise, no dc version will be negotiated and dc-specific
/// frames received will result in a connection error.
const ENABLED: bool = true;
type Path: Path;
/// Called when a dc version has been negotiated for the given `ConnectionInfo`
///
/// Return `None` if dc should not be used for this path
fn new_path(&mut self, connection_info: &dc::ConnectionInfo) -> Option<Self::Path>;
/// Called when a datagram arrives that cannot be decoded as a non-DC QUIC packet, and
/// thus may contain a secret control packet
///
/// Return `true` if a secret control packet was decoded from the datagram, `false` otherwise
fn on_possible_secret_control_packet(
&mut self,
datagram_info: &dc::DatagramInfo,
payload: &mut [u8],
) -> bool;
}
/// A dc path
pub trait Path: 'static + Send {
/// Called when path secrets are ready to be derived from the given `TlsSession`
///
/// Returns the stateless reset tokens to include in a `DC_STATELESS_RESET_TOKENS`
/// frame sent to the peer.
fn on_path_secrets_ready(
&mut self,
session: &impl TlsSession,
) -> Result<Vec<stateless_reset::Token>, transport::Error>;
/// Called when a `DC_STATELESS_RESET_TOKENS` frame has been received from the peer
fn on_peer_stateless_reset_tokens<'a>(
&mut self,
stateless_reset_tokens: impl Iterator<Item = &'a stateless_reset::Token>,
);
/// Called when the peer has confirmed receipt of `DC_STATELESS_RESET_TOKENS`, either
/// by the server sending back its own `DC_STATELESS_RESET_TOKENS` or by the client
/// acknowledging the `DC_STATELESS_RESET_TOKENS` frame was received.
fn on_dc_handshake_complete(&mut self);
/// Called when the MTU has been updated for the path
fn on_mtu_updated(&mut self, mtu: u16);
}
impl<P: Path> Path for Option<P> {
#[inline]
fn on_path_secrets_ready(
&mut self,
session: &impl TlsSession,
) -> Result<Vec<stateless_reset::Token>, transport::Error> {
if let Some(path) = self {
path.on_path_secrets_ready(session)
} else {
Ok(Vec::default())
}
}
#[inline]
fn on_peer_stateless_reset_tokens<'a>(
&mut self,
stateless_reset_tokens: impl Iterator<Item = &'a stateless_reset::Token>,
) {
if let Some(path) = self {
path.on_peer_stateless_reset_tokens(stateless_reset_tokens)
}
}
#[inline]
fn on_dc_handshake_complete(&mut self) {
if let Some(path) = self {
path.on_dc_handshake_complete()
}
}
#[inline]
fn on_mtu_updated(&mut self, max_datagram_size: u16) {
if let Some(path) = self {
path.on_mtu_updated(max_datagram_size)
}
}
}