move signature outside the spawning

this allows us to actually move stuff into the async block
and we can drop the 'static life-time.
pull/730/merge^2
Jeb Rosen 4 years ago committed by Igor Galić
parent a010025074
commit 8aa99cea35
Signed by: igalic
GPG Key ID: ACFEFF7F6A123A86

@ -120,10 +120,9 @@ impl<'a, 'r> FromRequestAsync<'a, 'r> for ApRequest {
})
}
}
pub fn broadcast<S, A, T, C>(sender: &'static S, act: A, to: Vec<T>)
pub fn broadcast<S, A, T, C>(sender: &S, act: A, to: Vec<T>)
where
S: sign::Signer,
S: std::marker::Sync,
A: Activity,
T: inbox::AsActor<C>,
{
@ -151,6 +150,8 @@ where
let body = signed.to_string();
let mut headers = request::headers();
headers.insert("Digest", request::Digest::digest(&body));
let sig = request::signature(sender, &headers)
.expect("activity_pub::broadcast: request signature error");
rt.spawn(async move {
let client = ClientBuilder::new()
.connect_timeout(std::time::Duration::from_secs(5))
@ -159,11 +160,7 @@ where
client
.post(&inbox)
.headers(headers.clone())
.header(
"Signature",
request::signature(sender, &headers)
.expect("activity_pub::broadcast: request signature error"),
)
.header("Signature", sig)
.body(body)
.send()
.await

@ -81,10 +81,10 @@ impl Follow {
/// from -> The one sending the follow request
/// target -> The target of the request, responding with Accept
pub fn accept_follow<A: Signer + IntoId + Clone + Sync, B: Clone + AsActor<T> + IntoId, T>(
pub fn accept_follow<A: Signer + IntoId + Clone, B: Clone + AsActor<T> + IntoId, T>(
conn: &Connection,
from: &B,
target: &'static A,
target: &A,
follow: FollowAct,
from_id: i32,
target_id: i32,

@ -10,6 +10,7 @@ use rocket::{data::*, http::Status, response::status, Outcome::*, Request};
use rocket_contrib::json::*;
use serde::Deserialize;
use std::io::Read;
use tokio::io::AsyncReadExt;
pub fn handle_incoming(
rockets: PlumeRocket,
@ -73,10 +74,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for SignedJson<T> {
type Owned = String;
type Borrowed = str;
fn transform<'r>(
r: &'r Request,
d: Data
) -> TransformFuture<'r, Self::Owned, Self::Error> {
fn transform<'r>(r: &'r Request, d: Data) -> TransformFuture<'r, Self::Owned, Self::Error> {
Box::pin(async move {
let size_limit = r.limits().get("json").unwrap_or(JSON_LIMIT);
let mut s = String::with_capacity(512);
@ -96,7 +94,9 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for SignedJson<T> {
let string = try_outcome!(o.borrowed());
match serde_json::from_str(&string) {
Ok(v) => Success(SignedJson(Digest::from_body(&string), Json(v))),
Err(e) if e.is_data() => return Failure((Status::UnprocessableEntity, JsonError::Parse(string, e))),
Err(e) if e.is_data() => {
return Failure((Status::UnprocessableEntity, JsonError::Parse(string, e)))
}
Err(e) => Failure((Status::BadRequest, JsonError::Parse(string, e))),
}
})

Loading…
Cancel
Save