Skip to content

Commit

Permalink
refactor: update dependencies (#2)
Browse files Browse the repository at this point in the history
* chore(deps): bump reqwest

* chore(deps): bump http

* chore(deps): bump http-signature-normalization-reqwest

* chore(deps): bump hyper

* chore(deps): bump axum

* chore(deps): use axum-extra

* refactor(tests): use axum::serve

* fix: axum inbox

Co-Authored-By: j0 <[email protected]>

* fix(examples): use axum::serve

* chore(ci): add doc test

* fix: docs test

* fix(tests): fix port

* fix(examples): use tokio::spawn

* chore(examples): remove actix-web code

---------

Co-authored-by: j0 <[email protected]>
  • Loading branch information
kwaa and j0lol authored Jul 25, 2024
1 parent 03569d5 commit 5fc5546
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 163 deletions.
1 change: 1 addition & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ jobs:
# - run: cargo fmt -- --check
- run: cargo clippy --all-targets --all-features
- run: cargo test --all-features --no-fail-fast
- run: cargo doc --all-features
- run: cargo run --example local_federation axum
26 changes: 16 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ documentation = "https://docs.rs/activitypub_federation/"

[features]
default = ["axum"]
axum = ["dep:axum", "dep:tower", "dep:hyper", "dep:http-body-util"]
axum = [
"dep:axum",
"dep:axum-extra",
"dep:tower",
"dep:hyper",
"dep:http-body-util",
]
diesel = ["dep:diesel"]

[lints.rust]
Expand All @@ -36,26 +42,26 @@ serde = { version = "1.0.204", features = ["derive"] }
async-trait = "0.1.81"
url = { version = "2.5.2", features = ["serde"] }
serde_json = { version = "1.0.120", features = ["preserve_order"] }
reqwest = { version = "0.11.27", default-features = false, features = [
reqwest = { version = "0.12.5", default-features = false, features = [
"json",
"stream",
"rustls-tls",
] }
reqwest-middleware = "0.2.5"
reqwest-middleware = "0.3.2"
tracing = "0.1.40"
base64 = "0.22.1"
rand = "0.8.5"
rsa = "0.9.6"
once_cell = "1.19.0"
http = "0.2.12"
http = "1.1.0"
sha2 = { version = "0.10.8", features = ["oid"] }
thiserror = "1.0.62"
derive_builder = "0.20.0"
itertools = "0.13.0"
dyn-clone = "1.0.17"
enum_delegate = "0.2.0"
httpdate = "1.0.3"
http-signature-normalization-reqwest = { version = "0.10.0", default-features = false, features = [
http-signature-normalization-reqwest = { version = "0.12.0", default-features = false, features = [
"sha-2",
"middleware",
"default-spawner",
Expand All @@ -82,24 +88,24 @@ futures = "0.3.30"
moka = { version = "0.12.8", features = ["future"] }

# Axum
axum = { version = "0.6.20", features = [
axum = { version = "0.7.5", features = [
"json",
"headers",
], default-features = false, optional = true }
axum-extra = { version = "0.9.3", features = ["typed-header"], optional = true }
tower = { version = "0.4.13", optional = true }
hyper = { version = "0.14", optional = true }
hyper = { version = "1.4.1", optional = true }
http-body-util = { version = "0.1.2", optional = true }

[dev-dependencies]
anyhow = "1.0.86"
env_logger = "0.11.3"
tower-http = { version = "0.5.2", features = ["map-request-body", "util"] }
axum = { version = "0.6.20", features = [
axum = { version = "0.7.5", features = [
"http1",
"tokio",
"query",
], default-features = false }
axum-macros = "0.3.8"
axum-macros = "0.4.1"
tokio = { version = "1.38.0", features = ["full"] }

[profile.dev]
Expand Down
14 changes: 7 additions & 7 deletions docs/06_http_endpoints_axum.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ The next step is to allow other servers to fetch our actors and objects. For thi
# use activitypub_federation::config::FederationMiddleware;
# use axum::routing::get;
# use crate::activitypub_federation::traits::Object;
# use axum::headers::ContentType;
# use axum_extra::headers::ContentType;
# use activitypub_federation::FEDERATION_CONTENT_TYPE;
# use axum::TypedHeader;
# use axum_extra::TypedHeader;
# use axum::response::IntoResponse;
# use http::HeaderMap;
# async fn generate_user_html(_: String, _: Data<DbConnection>) -> axum::response::Response { todo!() }
Expand All @@ -33,11 +33,11 @@ async fn main() -> Result<(), Error> {
.route("/user/:name", get(http_get_user))
.layer(FederationMiddleware::new(data));
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await?;
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
.await
.unwrap();
tracing::debug!("listening on {}", listener.local_addr().unwrap());
axum::serve(listener, app).await.unwrap();
Ok(())
}
Expand Down
20 changes: 9 additions & 11 deletions examples/live_federation/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ use axum::{
Router,
};
use error::Error;
use std::{
net::ToSocketAddrs,
sync::{Arc, Mutex},
};
use std::sync::{Arc, Mutex};
use tokio::net::TcpListener;
use tracing::log::{info, LevelFilter};

mod activities;
Expand Down Expand Up @@ -60,13 +58,13 @@ async fn main() -> Result<(), Error> {
.route("/.well-known/webfinger", get(webfinger))
.layer(FederationMiddleware::new(config));

let addr = BIND_ADDRESS
.to_socket_addrs()?
.next()
.expect("Failed to lookup domain name");
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await?;
axum::serve(
TcpListener::bind(BIND_ADDRESS)
.await
.expect("Failed to lookup domain name"),
app.into_make_service(),
)
.await?;

Ok(())
}
97 changes: 0 additions & 97 deletions examples/local_federation/actix_web/http.rs

This file was deleted.

6 changes: 0 additions & 6 deletions examples/local_federation/actix_web/mod.rs

This file was deleted.

23 changes: 13 additions & 10 deletions examples/local_federation/axum/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ use axum::{
extract::{Path, Query},
response::IntoResponse,
routing::{get, post},
Json,
Router,
Json, Router,
};
use axum_macros::debug_handler;
use serde::Deserialize;
use std::net::ToSocketAddrs;
use tokio::net::TcpListener;
use tracing::info;

pub fn listen(config: &FederationConfig<DatabaseHandle>) -> Result<(), Error> {
pub async fn listen(config: &FederationConfig<DatabaseHandle>) -> Result<(), Error> {
let hostname = config.domain();
info!("Listening with axum on {hostname}");
let config = config.clone();
Expand All @@ -35,13 +34,17 @@ pub fn listen(config: &FederationConfig<DatabaseHandle>) -> Result<(), Error> {
.route("/.well-known/webfinger", get(webfinger))
.layer(FederationMiddleware::new(config));

let addr = hostname
.to_socket_addrs()?
.next()
.expect("Failed to lookup domain name");
let server = axum::Server::bind(&addr).serve(app.into_make_service());
let server = axum::serve(
TcpListener::bind(hostname)
.await
.expect("Failed to lookup domain name"),
app.into_make_service(),
);

tokio::spawn(async move {
server.await.expect("Failed to start server");
});

tokio::spawn(server);
Ok(())
}

Expand Down
5 changes: 2 additions & 3 deletions examples/local_federation/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,12 @@ impl FromStr for Webserver {
}
}

pub fn listen(
pub async fn listen(
config: &FederationConfig<DatabaseHandle>,
webserver: &Webserver,
) -> Result<(), Error> {
match webserver {
Webserver::Axum => crate::axum::http::listen(config)?,
// Webserver::ActixWeb => crate::actix_web::http::listen(config)?,
Webserver::Axum => crate::axum::http::listen(config).await?,
}
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions examples/local_federation/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ async fn main() -> Result<(), Error> {

let alpha = new_instance("localhost:8001", "alpha".to_string()).await?;
let beta = new_instance("localhost:8002", "beta".to_string()).await?;
listen(&alpha, &webserver)?;
listen(&beta, &webserver)?;
listen(&alpha, &webserver).await?;
listen(&beta, &webserver).await?;
info!("Local instances started");

info!("Alpha user follows beta user via webfinger");
Expand Down
11 changes: 7 additions & 4 deletions src/activity_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ mod tests {
use bytes::Bytes;
use http::{HeaderMap, StatusCode};
use std::time::Instant;
use tokio::net::TcpListener;
use tracing::debug;

// This will periodically send back internal errors to test the retry
Expand Down Expand Up @@ -451,10 +452,12 @@ mod tests {
.route("/", post(dodgy_handler))
.with_state(state);

axum::Server::bind(&"0.0.0.0:8002".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
axum::serve(
TcpListener::bind("0.0.0.0:8002").await.unwrap(),
app.into_make_service(),
)
.await
.unwrap();
}

#[tokio::test(flavor = "multi_thread")]
Expand Down
11 changes: 7 additions & 4 deletions src/activity_sending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ mod tests {
sync::{atomic::AtomicUsize, Arc},
time::Instant,
};
use tokio::net::TcpListener;
use tracing::info;

// This will periodically send back internal errors to test the retry
Expand All @@ -251,10 +252,12 @@ mod tests {
.route("/", post(dodgy_handler))
.with_state(state);

axum::Server::bind(&"0.0.0.0:8001".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
axum::serve(
TcpListener::bind("0.0.0.0:8001").await.unwrap(),
app.into_make_service(),
)
.await
.unwrap();
}

#[tokio::test(flavor = "multi_thread")]
Expand Down
Loading

0 comments on commit 5fc5546

Please sign in to comment.