diff --git a/plume-common/src/activity_pub/mod.rs b/plume-common/src/activity_pub/mod.rs index 615ed322..6f81528c 100644 --- a/plume-common/src/activity_pub/mod.rs +++ b/plume-common/src/activity_pub/mod.rs @@ -120,10 +120,9 @@ impl<'a, 'r> FromRequestAsync<'a, 'r> for ApRequest { }) } } -pub fn broadcast(sender: &'static S, act: A, to: Vec) +pub fn broadcast(sender: &S, act: A, to: Vec) where S: sign::Signer, - S: std::marker::Sync, A: Activity, T: inbox::AsActor, { @@ -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 diff --git a/plume-models/src/follows.rs b/plume-models/src/follows.rs index 4dd0c58e..d371e04e 100644 --- a/plume-models/src/follows.rs +++ b/plume-models/src/follows.rs @@ -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 + IntoId, T>( + pub fn accept_follow + IntoId, T>( conn: &Connection, from: &B, - target: &'static A, + target: &A, follow: FollowAct, from_id: i32, target_id: i32, diff --git a/src/inbox.rs b/src/inbox.rs index f5d84a27..652da310 100644 --- a/src/inbox.rs +++ b/src/inbox.rs @@ -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 { 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 { 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))), } })