mirror of
https://github.com/LemmyNet/activitypub-federation-rust.git
synced 2025-05-20 01:18:52 +00:00
parent
43b51d79ce
commit
3a065b268c
7 changed files with 47 additions and 45 deletions
62
Cargo.toml
62
Cargo.toml
|
@ -32,70 +32,70 @@ redundant_closure_for_method_calls = "deny"
|
||||||
unwrap_used = "deny"
|
unwrap_used = "deny"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = { version = "0.4.38", features = ["clock"], default-features = false }
|
chrono = { version = "0.4.39", features = ["clock"], default-features = false }
|
||||||
serde = { version = "1.0.204", features = ["derive"] }
|
serde = { version = "1.0.217", features = ["derive"] }
|
||||||
async-trait = "0.1.81"
|
async-trait = "0.1.84"
|
||||||
url = { version = "2.5.2", features = ["serde"] }
|
url = { version = "2.5.4", features = ["serde"] }
|
||||||
serde_json = { version = "1.0.120", features = ["preserve_order"] }
|
serde_json = { version = "1.0.134", features = ["preserve_order"] }
|
||||||
reqwest = { version = "0.12.5", default-features = false, features = [
|
reqwest = { version = "0.12.12", default-features = false, features = [
|
||||||
"json",
|
"json",
|
||||||
"stream",
|
"stream",
|
||||||
"rustls-tls",
|
"rustls-tls",
|
||||||
] }
|
] }
|
||||||
reqwest-middleware = "0.3.2"
|
reqwest-middleware = "0.4.0"
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.41"
|
||||||
base64 = "0.22.1"
|
base64 = "0.22.1"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
rsa = "0.9.6"
|
rsa = "0.9.7"
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.20.2"
|
||||||
http = "1.1.0"
|
http = "1.2.0"
|
||||||
sha2 = { version = "0.10.8", features = ["oid"] }
|
sha2 = { version = "0.10.8", features = ["oid"] }
|
||||||
thiserror = "1.0.62"
|
thiserror = "2.0.9"
|
||||||
derive_builder = "0.20.0"
|
derive_builder = "0.20.2"
|
||||||
itertools = "0.13.0"
|
itertools = "0.14.0"
|
||||||
dyn-clone = "1.0.17"
|
dyn-clone = "1.0.17"
|
||||||
enum_delegate = "0.2.0"
|
enum_delegate = "0.2.0"
|
||||||
httpdate = "1.0.3"
|
httpdate = "1.0.3"
|
||||||
http-signature-normalization-reqwest = { version = "0.12.0", default-features = false, features = [
|
http-signature-normalization-reqwest = { version = "0.13.0", default-features = false, features = [
|
||||||
"sha-2",
|
"sha-2",
|
||||||
"middleware",
|
"middleware",
|
||||||
"default-spawner",
|
"default-spawner",
|
||||||
] }
|
] }
|
||||||
http-signature-normalization = "0.7.0"
|
http-signature-normalization = "0.7.0"
|
||||||
bytes = "1.6.1"
|
bytes = "1.9.0"
|
||||||
futures-core = { version = "0.3.30", default-features = false }
|
futures-core = { version = "0.3.31", default-features = false }
|
||||||
pin-project-lite = "0.2.14"
|
pin-project-lite = "0.2.15"
|
||||||
activitystreams-kinds = "0.3.0"
|
activitystreams-kinds = "0.3.0"
|
||||||
regex = { version = "1.10.5", default-features = false, features = [
|
regex = { version = "1.11.1", default-features = false, features = [
|
||||||
"std",
|
"std",
|
||||||
"unicode",
|
"unicode",
|
||||||
] }
|
] }
|
||||||
tokio = { version = "1.38.0", features = [
|
tokio = { version = "1.42.0", features = [
|
||||||
"sync",
|
"sync",
|
||||||
"rt",
|
"rt",
|
||||||
"rt-multi-thread",
|
"rt-multi-thread",
|
||||||
"time",
|
"time",
|
||||||
] }
|
] }
|
||||||
diesel = { version = "2.2.1", features = [
|
diesel = { version = "2.2.6", features = [
|
||||||
"postgres",
|
"postgres",
|
||||||
], default-features = false, optional = true }
|
], default-features = false, optional = true }
|
||||||
futures = "0.3.30"
|
futures = "0.3.31"
|
||||||
moka = { version = "0.12.8", features = ["future"] }
|
moka = { version = "0.12.9", features = ["future"] }
|
||||||
|
|
||||||
# Actix-web
|
# Actix-web
|
||||||
actix-web = { version = "4.8.0", default-features = false, optional = true }
|
actix-web = { version = "4.9.0", default-features = false, optional = true }
|
||||||
http02 = { package = "http", version = "0.2.12", optional = true }
|
http02 = { package = "http", version = "0.2.12", optional = true }
|
||||||
|
|
||||||
# Axum
|
# Axum
|
||||||
axum = { version = "0.7.5", features = ["json"], default-features = false, optional = true }
|
axum = { version = "0.8.1", features = ["json"], default-features = false, optional = true }
|
||||||
tower = { version = "0.4.13", optional = true }
|
tower = { version = "0.5.2", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
anyhow = "1.0.86"
|
anyhow = "1.0.95"
|
||||||
axum = { version = "0.7.5", features = ["macros"] }
|
axum = { version = "0.8.1", features = ["macros"] }
|
||||||
axum-extra = { version = "0.9.3", features = ["typed-header"] }
|
axum-extra = { version = "0.10.0", features = ["typed-header"] }
|
||||||
env_logger = "0.11.3"
|
env_logger = "0.11.6"
|
||||||
tokio = { version = "1.38.0", features = ["full"] }
|
tokio = { version = "1.42.0", features = ["full"] }
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
strip = "symbols"
|
strip = "symbols"
|
||||||
|
|
|
@ -30,8 +30,8 @@ pub fn listen(config: &FederationConfig<DatabaseHandle>) -> Result<(), Error> {
|
||||||
info!("Listening with axum on {hostname}");
|
info!("Listening with axum on {hostname}");
|
||||||
let config = config.clone();
|
let config = config.clone();
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/:user/inbox", post(http_post_user_inbox))
|
.route("/{user}/inbox", post(http_post_user_inbox))
|
||||||
.route("/:user", get(http_get_user))
|
.route("/{user}", get(http_get_user))
|
||||||
.route("/.well-known/webfinger", get(webfinger))
|
.route("/.well-known/webfinger", get(webfinger))
|
||||||
.layer(FederationMiddleware::new(config));
|
.layer(FederationMiddleware::new(config));
|
||||||
|
|
||||||
|
|
|
@ -122,14 +122,14 @@ mod test {
|
||||||
let (_, _, config) = setup_receive_test().await;
|
let (_, _, config) = setup_receive_test().await;
|
||||||
|
|
||||||
let actor = Url::parse("http://ds9.lemmy.ml/u/lemmy_alpha").unwrap();
|
let actor = Url::parse("http://ds9.lemmy.ml/u/lemmy_alpha").unwrap();
|
||||||
let id = "http://localhost:123/1";
|
let activity_id = "http://localhost:123/1";
|
||||||
let activity = json!({
|
let activity = json!({
|
||||||
"actor": actor.as_str(),
|
"actor": actor.as_str(),
|
||||||
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
"to": ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
"object": "http://ds9.lemmy.ml/post/1",
|
"object": "http://ds9.lemmy.ml/post/1",
|
||||||
"cc": ["http://enterprise.lemmy.ml/c/main"],
|
"cc": ["http://enterprise.lemmy.ml/c/main"],
|
||||||
"type": "Delete",
|
"type": "Delete",
|
||||||
"id": id
|
"id": activity_id
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
let body: Bytes = serde_json::to_vec(&activity).unwrap().into();
|
let body: Bytes = serde_json::to_vec(&activity).unwrap().into();
|
||||||
|
@ -144,8 +144,8 @@ mod test {
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
Err(Error::ParseReceivedActivity(_, url)) => {
|
Err(Error::ParseReceivedActivity { err: _, id }) => {
|
||||||
assert_eq!(id, url.expect("has url").as_str());
|
assert_eq!(activity_id, id.expect("has url").as_str());
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ use crate::{
|
||||||
traits::{ActivityHandler, Actor, Object},
|
traits::{ActivityHandler, Actor, Object},
|
||||||
};
|
};
|
||||||
use axum::{
|
use axum::{
|
||||||
async_trait,
|
|
||||||
body::Body,
|
body::Body,
|
||||||
extract::FromRequest,
|
extract::FromRequest,
|
||||||
http::{Request, StatusCode},
|
http::{Request, StatusCode},
|
||||||
|
@ -58,7 +57,6 @@ pub struct ActivityData {
|
||||||
body: Vec<u8>,
|
body: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl<S> FromRequest<S> for ActivityData
|
impl<S> FromRequest<S> for ActivityData
|
||||||
where
|
where
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::config::{Data, FederationConfig, FederationMiddleware};
|
use crate::config::{Data, FederationConfig, FederationMiddleware};
|
||||||
use axum::{async_trait, body::Body, extract::FromRequestParts, http::Request, response::Response};
|
use axum::{body::Body, extract::FromRequestParts, http::Request, response::Response};
|
||||||
use http::{request::Parts, StatusCode};
|
use http::{request::Parts, StatusCode};
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use tower::{Layer, Service};
|
use tower::{Layer, Service};
|
||||||
|
@ -43,7 +43,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl<S, T: Clone + 'static> FromRequestParts<S> for Data<T>
|
impl<S, T: Clone + 'static> FromRequestParts<S> for Data<T>
|
||||||
where
|
where
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
|
|
|
@ -44,11 +44,16 @@ pub enum Error {
|
||||||
#[error("Failed to parse object {1} with content {2}: {0}")]
|
#[error("Failed to parse object {1} with content {2}: {0}")]
|
||||||
ParseFetchedObject(serde_json::Error, Url, String),
|
ParseFetchedObject(serde_json::Error, Url, String),
|
||||||
/// Failed to parse an activity received from another instance
|
/// Failed to parse an activity received from another instance
|
||||||
#[error("Failed to parse incoming activity {}: {0}", match .1 {
|
#[error("Failed to parse incoming activity {}: {0}", match .id {
|
||||||
Some(t) => format!("with id {t}"),
|
Some(t) => format!("with id {t}"),
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
})]
|
})]
|
||||||
ParseReceivedActivity(serde_json::Error, Option<Url>),
|
ParseReceivedActivity {
|
||||||
|
/// The parse error
|
||||||
|
err: serde_json::Error,
|
||||||
|
/// ID of the Activitypub object which caused this error
|
||||||
|
id: Option<Url>,
|
||||||
|
},
|
||||||
/// Reqwest Middleware Error
|
/// Reqwest Middleware Error
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
ReqwestMiddleware(#[from] reqwest_middleware::Error),
|
ReqwestMiddleware(#[from] reqwest_middleware::Error),
|
||||||
|
|
|
@ -52,10 +52,10 @@ where
|
||||||
<ActorT as Object>::Error: From<Error>,
|
<ActorT as Object>::Error: From<Error>,
|
||||||
Datatype: Clone,
|
Datatype: Clone,
|
||||||
{
|
{
|
||||||
let activity: Activity = serde_json::from_slice(body).map_err(|e| {
|
let activity: Activity = serde_json::from_slice(body).map_err(|err| {
|
||||||
// Attempt to include activity id in error message
|
// Attempt to include activity id in error message
|
||||||
let id = extract_id(body).ok();
|
let id = extract_id(body).ok();
|
||||||
Error::ParseReceivedActivity(e, id)
|
Error::ParseReceivedActivity { err, id }
|
||||||
})?;
|
})?;
|
||||||
data.config.verify_url_and_domain(&activity).await?;
|
data.config.verify_url_and_domain(&activity).await?;
|
||||||
let actor = ObjectId::<ActorT>::from(activity.actor().clone())
|
let actor = ObjectId::<ActorT>::from(activity.actor().clone())
|
||||||
|
|
Loading…
Reference in a new issue