mirror of
https://github.com/astro/buzzrelay.git
synced 2024-11-22 04:00:59 +00:00
relay: concurrentize
This commit is contained in:
parent
970f8e8d1b
commit
7399f9c631
2 changed files with 16 additions and 11 deletions
17
src/relay.rs
17
src/relay.rs
|
@ -67,6 +67,8 @@ pub fn spawn(
|
|||
private_key: PrivateKey,
|
||||
mut stream_rx: Receiver<String>
|
||||
) {
|
||||
let private_key = Arc::new(private_key);
|
||||
|
||||
tokio::spawn(async move {
|
||||
while let Some(data) = stream_rx.recv().await {
|
||||
// dbg!(&data);
|
||||
|
@ -84,7 +86,6 @@ pub fn spawn(
|
|||
// skip reposts
|
||||
None => continue,
|
||||
};
|
||||
// TODO: queue by target?
|
||||
let mut seen_actors = HashSet::new();
|
||||
let mut seen_inboxes = HashSet::new();
|
||||
for actor in post.relay_targets(hostname.clone()) {
|
||||
|
@ -109,16 +110,20 @@ pub fn spawn(
|
|||
if seen_inboxes.contains(&inbox) {
|
||||
continue;
|
||||
}
|
||||
|
||||
seen_inboxes.insert(inbox.clone());
|
||||
let client_ = client.clone();
|
||||
let body_ = body.clone();
|
||||
let key_id = actor.key_id();
|
||||
let private_key_ = private_key.clone();
|
||||
tracing::debug!("relay {} to {}", actor_id, inbox);
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = send::send_raw(
|
||||
&client, &inbox,
|
||||
&actor.key_id(), &private_key, body.clone()
|
||||
&client_, &inbox,
|
||||
&key_id, &private_key_, body_
|
||||
).await {
|
||||
tracing::error!("relay::send {:?}", e);
|
||||
}
|
||||
|
||||
seen_inboxes.insert(inbox);
|
||||
});
|
||||
}
|
||||
|
||||
seen_actors.insert(actor);
|
||||
|
|
|
@ -71,7 +71,7 @@ pub async fn send_raw(
|
|||
.header("digest", digest_header)
|
||||
.body(body.as_ref().clone())
|
||||
.map_err(SendError::HttpReq)?;
|
||||
SigningConfig::new(RsaSha256, private_key, key_id)
|
||||
SigningConfig::new(RsaSha256, &private_key, key_id)
|
||||
.sign(&mut req)?;
|
||||
let req: reqwest::Request = req.try_into()?;
|
||||
let res = client.execute(req)
|
||||
|
|
Loading…
Reference in a new issue