implement session update on certificate change in runtime

This commit is contained in:
yggverse 2024-11-29 17:54:37 +02:00
parent f4cb0c3bcc
commit c4c173f6cf
3 changed files with 113 additions and 36 deletions

View file

@ -10,9 +10,10 @@ pub use meta::Meta;
use super::Connection;
use gio::Cancellable;
use glib::Priority;
use std::rc::Rc;
pub struct Response {
pub connection: Connection,
pub connection: Rc<Connection>,
pub meta: Meta,
}
@ -20,7 +21,7 @@ impl Response {
// Constructors
pub fn from_request_async(
connection: Connection,
connection: Rc<Connection>,
priority: Option<Priority>,
cancellable: Option<Cancellable>,
callback: impl FnOnce(Result<Self, Error>) + 'static,

24
src/client/session.rs Normal file
View file

@ -0,0 +1,24 @@
use super::Connection;
use std::{cell::RefCell, collections::HashMap, rc::Rc};
/// Request sessions holder for `Client` object
/// * useful to keep connections open and / or validate TLS certificate updates in runtime
pub struct Session {
index: RefCell<HashMap<String, Rc<Connection>>>,
}
impl Session {
pub fn new() -> Self {
Self {
index: RefCell::new(HashMap::new()),
}
}
pub fn get(&self, request: &str) -> Option<Rc<Connection>> {
self.index.borrow().get(request).cloned()
}
pub fn update(&self, request: String, connection: Rc<Connection>) -> Option<Rc<Connection>> {
self.index.borrow_mut().insert(request, connection)
}
}