update
This commit is contained in:
parent
a5102d0633
commit
5b955f2302
5 changed files with 29 additions and 40 deletions
24
Cargo.toml
24
Cargo.toml
|
|
@ -25,11 +25,12 @@ http = "0.2.9"
|
||||||
sha2 = "0.10.6"
|
sha2 = "0.10.6"
|
||||||
thiserror = "1.0.40"
|
thiserror = "1.0.40"
|
||||||
derive_builder = "0.12.0"
|
derive_builder = "0.12.0"
|
||||||
itertools = "0.10.5"
|
itertools = "0.11.0"
|
||||||
dyn-clone = "1.0.11"
|
dyn-clone = "1.0.11"
|
||||||
enum_delegate = "0.2.0"
|
enum_delegate = "0.2.0"
|
||||||
httpdate = "1.0.2"
|
httpdate = "1.0.2"
|
||||||
http-signature-normalization-reqwest = { version = "0.8.0", default-features = false, features = [
|
http-signature-normalization-reqwest = { version = "0.10.0", default-features = false, features = [
|
||||||
|
"default-spawner",
|
||||||
"sha-2",
|
"sha-2",
|
||||||
"middleware",
|
"middleware",
|
||||||
] }
|
] }
|
||||||
|
|
@ -50,14 +51,13 @@ tokio = { version = "1.21.2", features = [
|
||||||
actix-web = { version = "4.3.1", default-features = false, optional = true }
|
actix-web = { version = "4.3.1", default-features = false, optional = true }
|
||||||
|
|
||||||
# Axum
|
# Axum
|
||||||
axum = { version = "0.6.18", features = [
|
axum = { git = "https://github.com/tokio-rs/axum.git", features = [
|
||||||
"json",
|
"json",
|
||||||
"headers",
|
|
||||||
], default-features = false, optional = true }
|
], default-features = false, optional = true }
|
||||||
tower = { version = "0.4.13", optional = true }
|
tower = { version = "*", optional = true }
|
||||||
hyper = { version = "0.14", optional = true }
|
hyper = { version = "*", optional = true }
|
||||||
futures = "0.3.28"
|
futures = "*"
|
||||||
moka = { version = "0.11.2", features = ["future"] }
|
moka = { version = "0.12.1", features = ["future"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["actix-web", "axum"]
|
default = ["actix-web", "axum"]
|
||||||
|
|
@ -67,14 +67,14 @@ axum = ["dep:axum", "dep:tower", "dep:hyper"]
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
tower-http = { version = "0.4.0", features = ["map-request-body", "util"] }
|
tower-http = { version = "*", features = ["map-request-body", "util"] }
|
||||||
axum = { version = "0.6.18", features = [
|
axum = { git = "https://github.com/tokio-rs/axum.git", features = [
|
||||||
"http1",
|
"http1",
|
||||||
"tokio",
|
"tokio",
|
||||||
"query",
|
"query",
|
||||||
], default-features = false }
|
], default-features = false }
|
||||||
axum-macros = "0.3.7"
|
axum-macros = { git = "https://github.com/tokio-rs/axum.git" }
|
||||||
tokio = { version = "1.21.2", features = ["full"] }
|
tokio = { version = "*", features = ["full"] }
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
strip = "symbols"
|
strip = "symbols"
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,8 @@ use axum::{
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use std::{
|
use std::sync::{Arc, Mutex};
|
||||||
net::ToSocketAddrs,
|
use tokio::net::TcpListener;
|
||||||
sync::{Arc, Mutex},
|
|
||||||
};
|
|
||||||
use tracing::log::{info, LevelFilter};
|
use tracing::log::{info, LevelFilter};
|
||||||
|
|
||||||
mod activities;
|
mod activities;
|
||||||
|
|
@ -58,13 +56,8 @@ async fn main() -> Result<(), Error> {
|
||||||
.route("/.well-known/webfinger", get(webfinger))
|
.route("/.well-known/webfinger", get(webfinger))
|
||||||
.layer(FederationMiddleware::new(config));
|
.layer(FederationMiddleware::new(config));
|
||||||
|
|
||||||
let addr = BIND_ADDRESS
|
let addr = TcpListener::bind(BIND_ADDRESS).await?;
|
||||||
.to_socket_addrs()?
|
axum::serve(addr, app.into_make_service()).await?;
|
||||||
.next()
|
|
||||||
.expect("Failed to lookup domain name");
|
|
||||||
axum::Server::bind(&addr)
|
|
||||||
.serve(app.into_make_service())
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ use axum::{
|
||||||
};
|
};
|
||||||
use axum_macros::debug_handler;
|
use axum_macros::debug_handler;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::net::ToSocketAddrs;
|
use std::net::TcpListener;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
pub fn listen(config: &FederationConfig<DatabaseHandle>) -> Result<(), Error> {
|
pub fn listen(config: &FederationConfig<DatabaseHandle>) -> Result<(), Error> {
|
||||||
|
|
@ -35,11 +35,8 @@ pub fn listen(config: &FederationConfig<DatabaseHandle>) -> Result<(), Error> {
|
||||||
.route("/.well-known/webfinger", get(webfinger))
|
.route("/.well-known/webfinger", get(webfinger))
|
||||||
.layer(FederationMiddleware::new(config));
|
.layer(FederationMiddleware::new(config));
|
||||||
|
|
||||||
let addr = hostname
|
let addr = tokio::net::TcpListener::from_std(TcpListener::bind(hostname)?)?;
|
||||||
.to_socket_addrs()?
|
let server = axum::serve(addr, app.into_make_service());
|
||||||
.next()
|
|
||||||
.expect("Failed to lookup domain name");
|
|
||||||
let server = axum::Server::bind(&addr).serve(app.into_make_service());
|
|
||||||
|
|
||||||
tokio::spawn(server);
|
tokio::spawn(server);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -215,6 +215,7 @@ mod tests {
|
||||||
sync::{atomic::AtomicUsize, Arc},
|
sync::{atomic::AtomicUsize, Arc},
|
||||||
time::Instant,
|
time::Instant,
|
||||||
};
|
};
|
||||||
|
use tokio::net::TcpListener;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
use crate::{config::FederationConfig, http_signatures::generate_actor_keypair};
|
use crate::{config::FederationConfig, http_signatures::generate_actor_keypair};
|
||||||
|
|
@ -247,8 +248,10 @@ mod tests {
|
||||||
.route("/", post(dodgy_handler))
|
.route("/", post(dodgy_handler))
|
||||||
.with_state(state);
|
.with_state(state);
|
||||||
|
|
||||||
axum::Server::bind(&"0.0.0.0:8001".parse().unwrap())
|
axum::serve(
|
||||||
.serve(app.into_make_service())
|
TcpListener::bind("0.0.0.0:8001").await.unwrap(),
|
||||||
|
app.into_make_service(),
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use axum::{
|
use axum::{
|
||||||
async_trait,
|
async_trait,
|
||||||
body::{Bytes, HttpBody},
|
body::Body,
|
||||||
extract::FromRequest,
|
extract::FromRequest,
|
||||||
http::{Request, StatusCode},
|
http::{Request, StatusCode},
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Response},
|
||||||
|
|
@ -67,17 +67,13 @@ pub struct ActivityData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<S, B> FromRequest<S, B> for ActivityData
|
impl<S> FromRequest<S> for ActivityData
|
||||||
where
|
where
|
||||||
Bytes: FromRequest<S, B>,
|
|
||||||
B: HttpBody + Send + 'static,
|
|
||||||
S: Send + Sync,
|
S: Send + Sync,
|
||||||
<B as HttpBody>::Error: std::fmt::Display,
|
|
||||||
<B as HttpBody>::Data: Send,
|
|
||||||
{
|
{
|
||||||
type Rejection = Response;
|
type Rejection = Response;
|
||||||
|
|
||||||
async fn from_request(req: Request<B>, _state: &S) -> Result<Self, Self::Rejection> {
|
async fn from_request(req: Request<Body>, _state: &S) -> Result<Self, Self::Rejection> {
|
||||||
let (parts, body) = req.into_parts();
|
let (parts, body) = req.into_parts();
|
||||||
|
|
||||||
// this wont work if the body is an long running stream
|
// this wont work if the body is an long running stream
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue