mirror of
https://github.com/TeamPiped/piped-proxy.git
synced 2024-08-14 23:50:45 +00:00
Make the hashing run on spawn_blocking.
This commit is contained in:
parent
faafbcb737
commit
2abd43bfb2
1 changed files with 24 additions and 17 deletions
27
src/main.rs
27
src/main.rs
|
@ -151,32 +151,39 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
|
||||||
|
|
||||||
let qhash = qhash.unwrap();
|
let qhash = qhash.unwrap();
|
||||||
|
|
||||||
// check that qhash is valid
|
|
||||||
if qhash.len() != 8 {
|
if qhash.len() != 8 {
|
||||||
return Err("Invalid qhash provided".into());
|
return Err("Invalid qhash provided".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// store sorted key-value pairs
|
// Store sorted key-value pairs
|
||||||
let mut set = BTreeSet::new();
|
let mut set = BTreeSet::new();
|
||||||
|
{
|
||||||
query.to_pairs().iter().for_each(|(key, value)| {
|
let pairs = query.to_pairs();
|
||||||
|
for (key, value) in &pairs {
|
||||||
if matches!(*key, "qhash" | "range" | "rewrite") {
|
if matches!(*key, "qhash" | "range" | "rewrite") {
|
||||||
return;
|
continue;
|
||||||
|
}
|
||||||
|
set.insert((key.as_bytes().to_owned(), value.as_bytes().to_owned()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
set.insert((key.as_bytes(), value.as_bytes()));
|
|
||||||
});
|
|
||||||
|
|
||||||
|
let (tx, rx) = oneshot::channel::<String>();
|
||||||
|
spawn_blocking(move || {
|
||||||
let mut hasher = blake3::Hasher::new();
|
let mut hasher = blake3::Hasher::new();
|
||||||
|
|
||||||
for (key, value) in set {
|
for (key, value) in set {
|
||||||
hasher.update(key);
|
hasher.update(&key);
|
||||||
hasher.update(value);
|
hasher.update(&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
hasher.update(secret.as_bytes());
|
hasher.update(secret.as_bytes());
|
||||||
|
|
||||||
let hash = hasher.finalize().to_hex();
|
let hash = hasher.finalize().to_hex();
|
||||||
let hash = &hash[..8];
|
let hash = hash[..8].to_owned();
|
||||||
|
tx.send(hash).unwrap();
|
||||||
|
});
|
||||||
|
|
||||||
|
let hash = rx.await.unwrap();
|
||||||
|
|
||||||
if hash != qhash {
|
if hash != qhash {
|
||||||
return Err("Invalid qhash provided".into());
|
return Err("Invalid qhash provided".into());
|
||||||
|
|
Loading…
Reference in a new issue