added explicit lifetime for session refs

This commit is contained in:
monica 2023-01-04 15:22:44 -05:00
parent b6e68d9e7c
commit 44d854e03a
3 changed files with 5 additions and 5 deletions

View file

@ -19,7 +19,7 @@ pub trait ApplicationLayer: Sized {
type Data;
/// Arbitrary object that dereferences to the session, such as Arc<Session<Self>>.
type SessionRef: Deref<Target = Session<Self>>;
type SessionRef<'a>: Deref<Target = Session<Self>>;
/// A buffer containing data read from the network that can be cached.
///
@ -57,7 +57,7 @@ pub trait ApplicationLayer: Sized {
fn extract_s_public_from_raw(static_public: &[u8]) -> Option<P384PublicKey>;
/// Look up a local session by local session ID or return None if not found.
fn lookup_session(&self, local_session_id: SessionId) -> Option<Self::SessionRef>;
fn lookup_session<'a>(&self, local_session_id: SessionId) -> Option<Self::SessionRef<'a>>;
/// Rate limit and check an attempted new session (called before accept_new_session).
fn check_new_session(&self, rc: &ReceiveContext<Self>, remote_address: &Self::RemoteAddress) -> bool;

View file

@ -45,7 +45,7 @@ mod tests {
impl ApplicationLayer for Box<TestHost> {
type Data = u32;
type SessionRef = Arc<Session<Box<TestHost>>>;
type SessionRef<'a> = Arc<Session<Box<TestHost>>>;
type IncomingPacketBuffer = Vec<u8>;
type RemoteAddress = u32;
@ -67,7 +67,7 @@ mod tests {
P384PublicKey::from_bytes(static_public)
}
fn lookup_session(&self, local_session_id: SessionId) -> Option<Self::SessionRef> {
fn lookup_session<'a>(&self, local_session_id: SessionId) -> Option<Self::SessionRef<'a>> {
self.session.lock().unwrap().as_ref().and_then(|s| {
if s.id == local_session_id {
Some(s.clone())

View file

@ -638,7 +638,7 @@ impl<Application: ApplicationLayer> ReceiveContext<Application> {
canonical_header_bytes: &[u8; 12],
fragments: &[Application::IncomingPacketBuffer],
packet_type: u8,
session: Option<Application::SessionRef>,
session: Option<Application::SessionRef<'a>>,
mtu: usize,
current_time: i64,
) -> Result<ReceiveResult<'a, Application>, Error> {