core: generic spawn_crypto helper; offload all slow KDF hashing (OPER pbkdf2 too, and MKPASSWD) off the core thread

This commit is contained in:
Jean Chevronnet 2026-08-12 13:05:29 +00:00
parent e246699fef
commit 7cb58586b4
4 changed files with 83 additions and 17 deletions

View file

@ -53,13 +53,19 @@ pub enum Event {
uid: Uid,
ident: Option<String>,
},
/// A background OPER password verify finished. bcrypt is deliberately slow, so it
/// runs on a worker thread (see `Server::spawn_auth`) instead of freezing the core.
/// A background OPER password verify finished. KDF hashes are deliberately slow,
/// so they run on a worker thread (see `Server::spawn_crypto`), not on the core.
OperAuth {
uid: Uid,
ok: bool,
level: u32,
},
/// A background MKPASSWD hash finished (KDFs run off the core thread).
MkpasswdResult {
uid: Uid,
algo: String,
hash: Option<String>,
},
/// A module's async HTTP request finished. `tag` is `"<module>:<detail>"`
/// so the core can route the reply back to the module that issued it (e.g.
/// account registration, captcha verification). `status` is 0 on transport
@ -219,6 +225,22 @@ impl Ircd {
.numeric(uid, ERR_PASSWDMISMATCH, ":Password incorrect");
}
}
Event::MkpasswdResult { uid, algo, hash } => {
let nick = self
.server
.users
.get(&uid)
.map(|u| u.nick.clone())
.unwrap_or_default();
let line = match hash {
Some(h) => format!(
":{} NOTICE {nick} :{algo} hashed password: {h}",
self.server.name
),
None => format!(":{} NOTICE {nick} :Could not hash with '{algo}'", self.server.name),
};
self.server.send(uid, line);
}
Event::HttpResult {
uid,
tag,